Example usage for android.widget ScrollView addView

List of usage examples for android.widget ScrollView addView

Introduction

In this page you can find the example usage for android.widget ScrollView addView.

Prototype

@Override
    public void addView(View child) 

Source Link

Usage

From source file:com.ubergeek42.WeechatAndroid.utils.UntrustedCertificateDialog.java

@NonNull
@Override//  ww  w  .  j a va  2s  .  c o  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final int padding = (int) getResources().getDimension(R.dimen.dialog_padding_full);

    final ScrollView scrollView = new ScrollView(getContext());
    final TextView textView = new AppCompatTextView(getContext());
    textView.setText(Html.fromHtml(getCertificateDescription()));
    scrollView.addView(textView);

    return new AlertDialog.Builder(getContext()).setTitle(getString(R.string.ssl_cert_dialog_title))
            .setView(scrollView, padding, padding / 2, padding, 0)
            .setPositiveButton(getString(R.string.ssl_cert_dialog_accept_button),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            SSLHandler.getInstance(getContext()).trustCertificate(certificate);
                            ((WeechatActivity) getActivity()).connect();
                        }
                    })
            .setNegativeButton(getString(R.string.ssl_cert_dialog_reject_button), null).create();
}

From source file:org.telegram.ui.Components.BotKeyboardView.java

public BotKeyboardView(Context context) {
    super(context);

    setOrientation(VERTICAL);// w ww.  j a v a2s  .  c o m

    ScrollView scrollView = new ScrollView(context);
    addView(scrollView);
    container = new LinearLayout(context);
    container.setOrientation(VERTICAL);
    scrollView.addView(container);

    setBackgroundColor(ContextCompat.getColor(context, R.color.sticker_select_background));
}

From source file:com.ryan.ryanreader.activities.CommentReplyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);

    super.onCreate(savedInstanceState);

    final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.comment_reply);

    usernameSpinner = (Spinner) layout.findViewById(R.id.comment_reply_username);
    textEdit = (EditText) layout.findViewById(R.id.comment_reply_text);

    if (getIntent() != null && getIntent().hasExtra("parentIdAndType")) {
        parentIdAndType = getIntent().getStringExtra("parentIdAndType");

    } else if (savedInstanceState != null && savedInstanceState.containsKey("comment_text")) {
        textEdit.setText(savedInstanceState.getString("comment_text"));
        parentIdAndType = savedInstanceState.getString("parentIdAndType");

    } else if (lastText != null) {
        textEdit.setText(lastText);/*from   w  ww .  j  a v  a2s  .c o m*/
        parentIdAndType = lastParentIdAndType;
    }

    final ArrayList<RedditAccount> accounts = RedditAccountManager.getInstance(this).getAccounts();
    final ArrayList<String> usernames = new ArrayList<String>();

    for (RedditAccount account : accounts) {
        if (!account.isAnonymous()) {
            usernames.add(account.username);
        }
    }

    if (usernames.size() == 0) {
        General.quickToast(this, "You must be logged in to do that.");
        finish();
    }

    usernameSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usernames));

    final ScrollView sv = new ScrollView(this);
    sv.addView(layout);
    setContentView(sv);
}

From source file:com.google.adsensequickstart.DisplayInventoryFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ScrollView sv = new ScrollView(getActivity());
    TableLayout tl = new TableLayout(getActivity());
    tl.setBackgroundColor(Color.rgb(242, 239, 233));
    sv.addView(tl);

    if (displayInventoryController == null) {
        return sv;
    }/*from   ww w  .j  av  a 2 s  . co  m*/
    Inventory inventory = displayInventoryController.getInventory();

    TableLayout.LayoutParams tableRowParams = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    tableRowParams.setMargins(1, 1, 1, 1);

    TableRow.LayoutParams accountLayoutParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    accountLayoutParams.setMargins(2, 1, 2, 1);

    TableRow.LayoutParams adCLientLayoutParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    adCLientLayoutParams.setMargins(12, 1, 2, 1);

    TableRow.LayoutParams adUnitChannelLayoutParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    adUnitChannelLayoutParams.setMargins(24, 1, 2, 1);

    for (String accountId : inventory.getAccounts()) {
        TableRow trow = new TableRow(getActivity());
        tl.addView(trow);
        TextView tv = new TextView(getActivity());
        tv.setText(accountId);
        trow.addView(tv);
        tv.setLayoutParams(accountLayoutParams);

        for (String adClient : inventory.getAdClients(accountId)) {
            TableRow trow2 = new TableRow(getActivity());
            trow2.setBackgroundColor(Color.rgb(214, 204, 181));
            tl.addView(trow2);
            TextView tv2 = new TextView(getActivity());
            tv2.setText(adClient);
            trow2.addView(tv2);
            tv2.setLayoutParams(adCLientLayoutParams);
            for (String adUnit : inventory.getAdUnits(adClient)) {
                TableRow trow3 = new TableRow(getActivity());
                trow3.setBackgroundColor(Color.rgb(251, 145, 57));
                tl.addView(trow3);
                TextView tv3 = new TextView(getActivity());
                tv3.setText(adUnit);
                trow3.addView(tv3);
                tv3.setLayoutParams(adUnitChannelLayoutParams);
            }
            for (String customChannel : inventory.getCustomChannels(adClient)) {
                TableRow trow3 = new TableRow(getActivity());
                trow3.setBackgroundColor(Color.rgb(255, 195, 69));
                tl.addView(trow3);
                TextView tv3 = new TextView(getActivity());
                tv3.setText(customChannel);
                trow3.addView(tv3);
                tv3.setLayoutParams(adUnitChannelLayoutParams);
            }
        }
    }
    return sv;
}

From source file:com.github.wakhub.monodict.activity.bean.ActivityHelper.java

public AlertDialog.Builder buildNoticeDialog(CharSequence text) {
    TextView textView = new TextView(activity);
    textView.setAutoLinkMask(Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
    textView.setPadding((int) spaceSuperRelax, (int) spaceSuperRelax, (int) spaceSuperRelax,
            (int) spaceSuperRelax);
    textView.setText(text);//  w w w.ja va  2s  . c  o m
    ScrollView scrollView = new ScrollView(activity);
    scrollView.addView(textView);
    return new AlertDialog.Builder(activity).setView(scrollView).setPositiveButton(android.R.string.ok, null);
}

From source file:li.klass.fhem.fragments.core.DeviceDetailFragment.java

@Override
public void update(boolean doUpdate) {
    hideEmptyView();//from  w  w  w  .j ava2 s .  co m

    if (doUpdate)
        getActivity().sendBroadcast(new Intent(Actions.SHOW_EXECUTING_DIALOG));

    Intent intent = new Intent(Actions.GET_DEVICE_FOR_NAME);
    intent.setClass(getActivity(), RoomListIntentService.class);
    intent.putExtra(BundleExtraKeys.DO_REFRESH, doUpdate);
    intent.putExtra(BundleExtraKeys.DEVICE_NAME, deviceName);
    intent.putExtra(BundleExtraKeys.RESULT_RECEIVER, new ResultReceiver(new Handler()) {
        @Override
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            super.onReceiveResult(resultCode, resultData);

            FragmentActivity activity = getActivity();
            if (activity == null)
                return;

            activity.sendBroadcast(new Intent(Actions.DISMISS_EXECUTING_DIALOG));

            if (resultCode == ResultCodes.SUCCESS && getView() != null) {
                FhemDevice device = (FhemDevice) resultData.getSerializable(BundleExtraKeys.DEVICE);
                long lastUpdate = resultData.getLong(BundleExtraKeys.LAST_UPDATE);

                if (device == null)
                    return;

                DeviceAdapter adapter = DeviceType.getAdapterFor(device);
                if (adapter == null) {
                    return;
                }
                adapter.attach(DeviceDetailFragment.this.getActivity());
                ScrollView scrollView = (ScrollView) getView().findViewById(R.id.deviceDetailView);
                if (scrollView != null) {
                    scrollView.removeAllViews();
                    scrollView.addView(adapter.createDetailView(activity, device, lastUpdate));
                }
            }
        }
    });
    getActivity().startService(intent);
}

From source file:com.ryan.ryanreader.activities.PostSubmitActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);

    super.onCreate(savedInstanceState);

    final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.post_submit);

    typeSpinner = (Spinner) layout.findViewById(R.id.post_submit_type);
    usernameSpinner = (Spinner) layout.findViewById(R.id.post_submit_username);
    subredditEdit = (EditText) layout.findViewById(R.id.post_submit_subreddit);
    titleEdit = (EditText) layout.findViewById(R.id.post_submit_title);
    textEdit = (EditText) layout.findViewById(R.id.post_submit_body);

    if (getIntent() != null && getIntent().hasExtra("subreddit")) {
        final String subreddit = getIntent().getStringExtra("subreddit");
        if (subreddit != null && subreddit.length() > 0 && !subreddit.equals("all")
                && subreddit.matches("\\w+")) {
            subredditEdit.setText(subreddit);
        }/*www. j ava2 s  .com*/

    } else if (savedInstanceState != null && savedInstanceState.containsKey("post_title")) {
        titleEdit.setText(savedInstanceState.getString("post_title"));
        textEdit.setText(savedInstanceState.getString("post_body"));
        subredditEdit.setText(savedInstanceState.getString("subreddit"));
        typeSpinner.setSelection(savedInstanceState.getInt("post_type"));
    }

    final ArrayList<RedditAccount> accounts = RedditAccountManager.getInstance(this).getAccounts();
    final ArrayList<String> usernames = new ArrayList<String>();

    for (RedditAccount account : accounts) {
        if (!account.isAnonymous()) {
            usernames.add(account.username);
        }
    }

    if (usernames.size() == 0) {
        General.quickToast(this, R.string.error_toast_notloggedin);
        finish();
    }

    usernameSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usernames));
    typeSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, postTypes));

    // TODO remove the duplicate code here
    if (typeSpinner.getSelectedItem().equals("Link")) {
        textEdit.setHint("URL"); // TODO string
        textEdit.setInputType(android.text.InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
        textEdit.setSingleLine(true);
    } else {
        textEdit.setHint("Self Text"); // TODO string
        textEdit.setInputType(android.text.InputType.TYPE_CLASS_TEXT
                | InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
        textEdit.setSingleLine(false);
    }

    typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (typeSpinner.getSelectedItem().equals("Link")) {
                textEdit.setHint("URL"); // TODO string
                textEdit.setInputType(
                        android.text.InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
                textEdit.setSingleLine(true);
            } else {
                textEdit.setHint("Self Text"); // TODO string
                textEdit.setInputType(android.text.InputType.TYPE_CLASS_TEXT
                        | InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
                textEdit.setSingleLine(false);
            }
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    final ScrollView sv = new ScrollView(this);
    sv.addView(layout);
    setContentView(sv);
}

From source file:org.lol.reddit.activities.PostSubmitActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);

    super.onCreate(savedInstanceState);

    final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.post_submit);

    typeSpinner = (Spinner) layout.findViewById(R.id.post_submit_type);
    usernameSpinner = (Spinner) layout.findViewById(R.id.post_submit_username);
    subredditEdit = (EditText) layout.findViewById(R.id.post_submit_subreddit);
    titleEdit = (EditText) layout.findViewById(R.id.post_submit_title);
    textEdit = (EditText) layout.findViewById(R.id.post_submit_body);

    final Intent intent = getIntent();
    if (intent != null) {

        if (intent.hasExtra("subreddit")) {

            final String subreddit = intent.getStringExtra("subreddit");

            if (subreddit != null && subreddit.length() > 0 && !subreddit.matches("/?(r/)?all/?")
                    && subreddit.matches("/?(r/)?\\w+/?")) {
                subredditEdit.setText(subreddit);
            }//from w w w  . j a va 2s  .co  m

        } else if (Intent.ACTION_SEND.equalsIgnoreCase(intent.getAction())
                && intent.hasExtra(Intent.EXTRA_TEXT)) {
            final String url = intent.getStringExtra(Intent.EXTRA_TEXT);
            textEdit.setText(url);
        }

    } else if (savedInstanceState != null && savedInstanceState.containsKey("post_title")) {
        titleEdit.setText(savedInstanceState.getString("post_title"));
        textEdit.setText(savedInstanceState.getString("post_body"));
        subredditEdit.setText(savedInstanceState.getString("subreddit"));
        typeSpinner.setSelection(savedInstanceState.getInt("post_type"));
    }

    final ArrayList<RedditAccount> accounts = RedditAccountManager.getInstance(this).getAccounts();
    final ArrayList<String> usernames = new ArrayList<String>();

    for (RedditAccount account : accounts) {
        if (!account.isAnonymous()) {
            usernames.add(account.username);
        }
    }

    if (usernames.size() == 0) {
        General.quickToast(this, R.string.error_toast_notloggedin);
        finish();
    }

    usernameSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usernames));
    typeSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, postTypes));

    // TODO remove the duplicate code here
    setHint();

    typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            setHint();
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    final ScrollView sv = new ScrollView(this);
    sv.addView(layout);
    setContentView(sv);
}

From source file:org.quantumbadger.redreader.activities.PostSubmitActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);

    super.onCreate(savedInstanceState);

    final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.post_submit);

    typeSpinner = (Spinner) layout.findViewById(R.id.post_submit_type);
    usernameSpinner = (Spinner) layout.findViewById(R.id.post_submit_username);
    subredditEdit = (EditText) layout.findViewById(R.id.post_submit_subreddit);
    titleEdit = (EditText) layout.findViewById(R.id.post_submit_title);
    textEdit = (EditText) layout.findViewById(R.id.post_submit_body);

    final Intent intent = getIntent();
    if (intent != null) {

        if (intent.hasExtra("subreddit")) {

            final String subreddit = intent.getStringExtra("subreddit");

            if (subreddit != null && subreddit.length() > 0 && !subreddit.matches("/?(r/)?all/?")
                    && subreddit.matches("/?(r/)?\\w+/?")) {
                subredditEdit.setText(subreddit);
            }/*from ww w. j  a  v  a 2  s. c o m*/

        } else if (intent.getAction().equalsIgnoreCase(Intent.ACTION_SEND)
                && intent.hasExtra(Intent.EXTRA_TEXT)) {
            final String url = intent.getStringExtra(Intent.EXTRA_TEXT);
            textEdit.setText(url);
        }

    } else if (savedInstanceState != null && savedInstanceState.containsKey("post_title")) {
        titleEdit.setText(savedInstanceState.getString("post_title"));
        textEdit.setText(savedInstanceState.getString("post_body"));
        subredditEdit.setText(savedInstanceState.getString("subreddit"));
        typeSpinner.setSelection(savedInstanceState.getInt("post_type"));
    }

    final ArrayList<RedditAccount> accounts = RedditAccountManager.getInstance(this).getAccounts();
    final ArrayList<String> usernames = new ArrayList<String>();

    for (RedditAccount account : accounts) {
        if (!account.isAnonymous()) {
            usernames.add(account.username);
        }
    }

    if (usernames.size() == 0) {
        General.quickToast(this, R.string.error_toast_notloggedin);
        finish();
    }

    usernameSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usernames));
    typeSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, postTypes));

    // TODO remove the duplicate code here
    setHint();

    typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            setHint();
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    final ScrollView sv = new ScrollView(this);
    sv.addView(layout);
    setContentView(sv);
}

From source file:org.lol.reddit.activities.CaptchaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);
    getSupportActionBar().setTitle(R.string.post_captcha_title);

    super.onCreate(savedInstanceState);

    final LoadingView loadingView = new LoadingView(this, R.string.download_waiting, true, true);
    setContentView(loadingView);/*from w  w w.jav a2 s  .  c o m*/

    final RedditAccount selectedAccount = RedditAccountManager.getInstance(this)
            .getAccount(getIntent().getStringExtra("username"));

    final CacheManager cm = CacheManager.getInstance(this);

    RedditAPI.newCaptcha(cm, new APIResponseHandler.NewCaptchaResponseHandler(this) {
        @Override
        protected void onSuccess(final String captchaId) {

            final URI captchaUrl = Constants.Reddit.getUri("/captcha/" + captchaId);

            cm.makeRequest(new CacheRequest(captchaUrl, RedditAccountManager.getAnon(), null,
                    Constants.Priority.CAPTCHA, 0, CacheRequest.DownloadType.FORCE, Constants.FileType.CAPTCHA,
                    false, false, true, CaptchaActivity.this) {
                @Override
                protected void onCallbackException(Throwable t) {
                    BugReportActivity.handleGlobalError(CaptchaActivity.this, t);
                }

                @Override
                protected void onDownloadNecessary() {
                }

                @Override
                protected void onDownloadStarted() {
                    loadingView.setIndeterminate(R.string.download_downloading);
                }

                @Override
                protected void onFailure(RequestFailureType type, Throwable t, StatusLine status,
                        String readableMessage) {
                    final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type, t,
                            status, url.toString());
                    General.showResultDialog(CaptchaActivity.this, error);
                    finish();
                }

                @Override
                protected void onProgress(long bytesRead, long totalBytes) {
                    loadingView.setProgress(R.string.download_downloading,
                            (float) ((double) bytesRead / (double) totalBytes));
                }

                @Override
                protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, long timestamp,
                        UUID session, boolean fromCache, String mimetype) {

                    final Bitmap image;
                    try {
                        image = BitmapFactory.decodeStream(cacheFile.getInputStream());
                    } catch (IOException e) {
                        BugReportActivity.handleGlobalError(CaptchaActivity.this, e);
                        return;
                    }

                    General.UI_THREAD_HANDLER.post(new Runnable() {
                        public void run() {

                            final LinearLayout ll = new LinearLayout(CaptchaActivity.this);
                            ll.setOrientation(LinearLayout.VERTICAL);

                            final ImageView captchaImg = new ImageView(CaptchaActivity.this);
                            ll.addView(captchaImg);
                            final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) captchaImg
                                    .getLayoutParams();
                            layoutParams.setMargins(20, 20, 20, 20);
                            layoutParams.height = General.dpToPixels(context, 100);
                            captchaImg.setScaleType(ImageView.ScaleType.FIT_CENTER);

                            final EditText captchaText = new EditText(CaptchaActivity.this);
                            ll.addView(captchaText);
                            ((LinearLayout.LayoutParams) captchaText.getLayoutParams()).setMargins(20, 0, 20,
                                    20);
                            captchaText.setInputType(android.text.InputType.TYPE_CLASS_TEXT
                                    | android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
                                    | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);

                            captchaImg.setImageBitmap(image);

                            final Button submitButton = new Button(CaptchaActivity.this);
                            submitButton.setText(R.string.post_captcha_submit_button);
                            ll.addView(submitButton);
                            ((LinearLayout.LayoutParams) submitButton.getLayoutParams()).setMargins(20, 0, 20,
                                    20);
                            ((LinearLayout.LayoutParams) submitButton
                                    .getLayoutParams()).gravity = Gravity.RIGHT;
                            ((LinearLayout.LayoutParams) submitButton
                                    .getLayoutParams()).width = LinearLayout.LayoutParams.WRAP_CONTENT;

                            submitButton.setOnClickListener(new View.OnClickListener() {
                                public void onClick(View v) {
                                    final Intent result = new Intent();
                                    result.putExtra("captchaId", captchaId);
                                    result.putExtra("captchaText", captchaText.getText().toString());
                                    setResult(RESULT_OK, result);
                                    finish();
                                }
                            });

                            final ScrollView sv = new ScrollView(CaptchaActivity.this);
                            sv.addView(ll);
                            setContentView(sv);
                        }
                    });

                }
            });
        }

        @Override
        protected void onCallbackException(Throwable t) {
            BugReportActivity.handleGlobalError(CaptchaActivity.this, t);
        }

        @Override
        protected void onFailure(RequestFailureType type, Throwable t, StatusLine status,
                String readableMessage) {
            final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type, t, status,
                    null);
            General.showResultDialog(CaptchaActivity.this, error);
            finish();
        }

        @Override
        protected void onFailure(APIFailureType type) {
            final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type);
            General.showResultDialog(CaptchaActivity.this, error);
            finish();
        }
    }, selectedAccount, this);
}