Example usage for android.widget ScrollView ScrollView

List of usage examples for android.widget ScrollView ScrollView

Introduction

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

Prototype

public ScrollView(Context context) 

Source Link

Usage

From source file:edu.cnu.PowerTutor.ui.PowerViewer.java

public void refreshView() {
    if (counterService == null) {
        TextView loadingText = new TextView(this);
        loadingText.setText("Waiting for profiler service...");
        loadingText.setGravity(Gravity.CENTER);
        setContentView(loadingText);/*www  .ja va  2 s  .c  o  m*/
        return;
    }

    chartLayout = new LinearLayout(this);
    chartLayout.setOrientation(LinearLayout.VERTICAL);

    if (uid == SystemInfo.AID_ALL) {
        /*
         * If we are reporting global power usage then just set noUidMask to
         * 0 so that all components get displayed.
         */
        noUidMask = 0;
    }
    components = 0;
    for (int i = 0; i < componentNames.length; i++) {
        if ((noUidMask & 1 << i) == 0) {
            components++;
        }
    }
    boolean showTotal = prefs.getBoolean("showTotalPower", false);
    collectors = new ValueCollector[(showTotal ? 1 : 0) + components];

    int pos = 0;
    for (int i = showTotal ? -1 : 0; i < componentNames.length; i++) {
        if (i != -1 && (noUidMask & 1 << i) != 0) {
            continue;
        }
        String name = i == -1 ? "Total" : componentNames[i];
        double mxPower = (i == -1 ? 2100.0 : componentsMaxPower[i]) * 1.05;

        XYSeries series = new XYSeries(name);
        XYMultipleSeriesDataset mseries = new XYMultipleSeriesDataset();
        mseries.addSeries(series);

        XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
        XYSeriesRenderer srenderer = new XYSeriesRenderer();
        renderer.setYAxisMin(0.0);
        renderer.setYAxisMax(mxPower);
        renderer.setYTitle(name + "(mW)");

        int clr = PowerPie.COLORS[(PowerPie.COLORS.length + i) % PowerPie.COLORS.length];
        srenderer.setColor(clr);
        srenderer.setFillBelowLine(true);
        srenderer.setFillBelowLineColor(((clr >> 1) & 0x7F7F7F) | (clr & 0xFF000000));
        renderer.addSeriesRenderer(srenderer);

        View chartView = new GraphicalView(this, new CubicLineChart(mseries, renderer, 0.5f));
        chartView.setMinimumHeight(100);
        chartLayout.addView(chartView);

        collectors[pos] = new ValueCollector(series, renderer, chartView, i);
        if (handler != null) {
            // Main Handler?   . (debug)
            handler.post(collectors[pos]);
        }
        pos++;
    }

    /*
     * We're giving 100 pixels per graph of vertical space for the chart
     * view. If we don't specify a minimum height the chart view ends up
     * having a height of 0 so this is important.
     */
    chartLayout.setMinimumHeight(100 * components);

    ScrollView scrollView = new ScrollView(this);
    scrollView.addView(chartLayout);
    setContentView(scrollView);
}

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 .  j  av  a  2s.  co  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);
}

From source file:com.ryan.ryanreader.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. j av 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);
                    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;
                    }

                    new Handler(Looper.getMainLooper()).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);
            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);
}

From source file:org.quantumbadger.redreader.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   ww w . j a v  a 2 s. c om

    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;
                    }

                    new Handler(Looper.getMainLooper()).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);
}

From source file:org.telegram.ui.ChannelEditTypeActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override//from  w  w  w.  j ava2  s  .  co m
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (donePressed) {
                    return;
                }

                if (!isPrivate && ((currentChat.username == null && nameTextView.length() != 0)
                        || (currentChat.username != null && !currentChat.username
                                .equalsIgnoreCase(nameTextView.getText().toString())))) {
                    if (nameTextView.length() != 0 && !lastNameAvailable) {
                        Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
                        if (v != null) {
                            v.vibrate(200);
                        }
                        AndroidUtilities.shakeView(checkTextView, 2, 0);
                        return;
                    }
                }
                donePressed = true;

                String oldUserName = currentChat.username != null ? currentChat.username : "";
                String newUserName = isPrivate ? "" : nameTextView.getText().toString();
                if (!oldUserName.equals(newUserName)) {
                    MessagesController.getInstance().updateChannelUserName(chatId, newUserName);
                }
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    fragmentView = new ScrollView(context);
    fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));
    ScrollView scrollView = (ScrollView) fragmentView;
    scrollView.setFillViewport(true);
    linearLayout = new LinearLayout(context);
    scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    linearLayout.setOrientation(LinearLayout.VERTICAL);

    if (currentChat.megagroup) {
        actionBar.setTitle(LocaleController.getString("GroupType", R.string.GroupType));
    } else {
        actionBar.setTitle(LocaleController.getString("ChannelType", R.string.ChannelType));
    }

    LinearLayout linearLayout2 = new LinearLayout(context);
    linearLayout2.setOrientation(LinearLayout.VERTICAL);
    linearLayout2.setElevation(AndroidUtilities.dp(2));
    linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
    linearLayout.addView(linearLayout2,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    radioButtonCell1 = new RadioButtonCell(context);
    radioButtonCell1.setElevation(0);
    radioButtonCell1.setBackgroundResource(R.drawable.list_selector);
    if (currentChat.megagroup) {
        radioButtonCell1.setTextAndValue(LocaleController.getString("MegaPublic", R.string.MegaPublic),
                LocaleController.getString("MegaPublicInfo", R.string.MegaPublicInfo), !isPrivate, false);
    } else {
        radioButtonCell1.setTextAndValue(LocaleController.getString("ChannelPublic", R.string.ChannelPublic),
                LocaleController.getString("ChannelPublicInfo", R.string.ChannelPublicInfo), !isPrivate, false);
    }
    linearLayout2.addView(radioButtonCell1,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    radioButtonCell1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!isPrivate) {
                return;
            }
            isPrivate = false;
            updatePrivatePublic();
        }
    });

    radioButtonCell2 = new RadioButtonCell(context);
    radioButtonCell2.setElevation(0);
    radioButtonCell2.setForeground(R.drawable.list_selector);
    if (currentChat.megagroup) {
        radioButtonCell2.setTextAndValue(LocaleController.getString("MegaPrivate", R.string.MegaPrivate),
                LocaleController.getString("MegaPrivateInfo", R.string.MegaPrivateInfo), isPrivate, false);
    } else {
        radioButtonCell2.setTextAndValue(LocaleController.getString("ChannelPrivate", R.string.ChannelPrivate),
                LocaleController.getString("ChannelPrivateInfo", R.string.ChannelPrivateInfo), isPrivate,
                false);
    }
    linearLayout2.addView(radioButtonCell2,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    radioButtonCell2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isPrivate) {
                return;
            }
            isPrivate = true;
            updatePrivatePublic();
        }
    });

    sectionCell = new ShadowSectionCell(context);
    linearLayout.addView(sectionCell,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    linkContainer = new LinearLayout(context);
    linkContainer.setOrientation(LinearLayout.VERTICAL);
    linkContainer.setElevation(AndroidUtilities.dp(2));
    linkContainer.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
    linearLayout.addView(linkContainer,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    headerCell = new HeaderCell(context);
    headerCell.setElevation(0);
    headerCell.setBackground(null);
    linkContainer.addView(headerCell);

    publicContainer = new LinearLayout(context);
    publicContainer.setOrientation(LinearLayout.HORIZONTAL);
    linkContainer.addView(publicContainer,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 17, 7, 17, 0));

    EditText editText = new EditText(context);
    editText.setText("telegram.me/");
    editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    //editText.setHintTextColor(0xff979797);
    editText.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    editText.setMaxLines(1);
    editText.setLines(1);
    editText.setEnabled(false);
    editText.setBackgroundDrawable(null);
    editText.setPadding(0, 0, 0, 0);
    editText.setSingleLine(true);
    editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    publicContainer.addView(editText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 36));

    nameTextView = new EditText(context);
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    if (!isPrivate) {
        nameTextView.setText(currentChat.username);
    }
    //nameTextView.setHintTextColor(0xff979797);
    nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    nameTextView.setMaxLines(1);
    nameTextView.setLines(1);
    nameTextView.setBackgroundDrawable(null);
    nameTextView.setPadding(0, 0, 0, 0);
    nameTextView.setSingleLine(true);
    nameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE
            | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    nameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
    nameTextView.setHint(
            LocaleController.getString("ChannelUsernamePlaceholder", R.string.ChannelUsernamePlaceholder));
    AndroidUtilities.clearCursorDrawable(nameTextView);
    publicContainer.addView(nameTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36));
    nameTextView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            checkUserName(nameTextView.getText().toString());
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

    privateContainer = new TextBlockCell(context);
    privateContainer.setForeground(R.drawable.list_selector);
    linkContainer.addView(privateContainer);
    privateContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (invite == null) {
                return;
            }
            try {
                android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                android.content.ClipData clip = android.content.ClipData.newPlainText("label", invite.link);
                clipboard.setPrimaryClip(clip);
                Toast.makeText(getParentActivity(),
                        LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT)
                        .show();
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
        }
    });

    checkTextView = new TextView(context);
    checkTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    checkTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    checkTextView.setVisibility(View.GONE);
    linkContainer.addView(checkTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 17, 3, 17, 7));

    typeInfoCell = new TextInfoPrivacyCell(context);
    //typeInfoCell.setBackgroundResource(R.drawable.greydivider_bottom);
    linearLayout.addView(typeInfoCell,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    loadingAdminedCell = new LoadingCell(context);
    linearLayout.addView(loadingAdminedCell,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    adminedInfoCell = new TextInfoPrivacyCell(context);
    //adminedInfoCell.setBackgroundResource(R.drawable.greydivider_bottom);
    linearLayout.addView(adminedInfoCell,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    updatePrivatePublic();

    return fragmentView;
}

From source file:org.adblockplus.android.AdvancedPreferences.java

@Override
protected Dialog onCreateDialog(final int id) {
    Dialog dialog = null;/*from  w  w  w  . j a  va2s  . c o  m*/
    switch (id) {
    case CONFIGURATION_DIALOG:
        final List<String> items = new ArrayList<String>();
        items.add(AdblockPlus.getDeviceName());
        items.add(String.format("API: %d Build: %d", Build.VERSION.SDK_INT,
                AdblockPlus.getApplication().getBuildNumber()));

        final ProxyService proxyService = this.serviceBinder.get();

        if (proxyService != null) {
            items.add(String.format("Local port: %d", proxyService.port));
            if (proxyService.isIptables()) {
                items.add("Running in root mode");
                items.add("iptables output:");
                final List<String> output = IptablesProxyConfigurator
                        .getIptablesOutput(getApplicationContext());
                if (output != null) {
                    for (final String line : output) {
                        if (StringUtils.isNotEmpty(line))
                            items.add(line);
                    }
                }
            }
            if (proxyService.isNativeProxyAutoConfigured()) {
                items.add("Has native proxy auto configured");
            }
            if (ProxyService.GLOBAL_PROXY_USER_CONFIGURABLE) {
                final ProxyProperties pp = ProxyProperties.fromContext(getApplicationContext());
                if (pp != null) {
                    items.add("System settings:");
                    items.add(String.format("Host: [%s] Port: [%d] Excl: [%s]", pp.getHost(), pp.getPort(),
                            pp.getExclusionList()));
                }
            }
            items.add("Proxy settings:");
            items.add(String.format("Host: [%s] Port: [%s] Excl: [%s]",
                    proxyService.proxy.props.getProperty("adblock.proxyHost"),
                    proxyService.proxy.props.getProperty("adblock.proxyPort"),
                    proxyService.proxy.props.getProperty("adblock.proxyExcl")));
            if (proxyService.proxy.props.getProperty("adblock.auth") != null)
                items.add("Auth: yes");
        } else {
            items.add("Service not running");
        }

        final ScrollView scrollPane = new ScrollView(this);
        final TextView messageText = new TextView(this);
        messageText.setPadding(12, 6, 12, 6);
        messageText.setText(TextUtils.join("\n", items));
        messageText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                final ClipboardManager manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                final TextView showTextParam = (TextView) v;
                manager.setText(showTextParam.getText());
                Toast.makeText(v.getContext(), R.string.msg_clipboard, Toast.LENGTH_SHORT).show();
            }
        });
        scrollPane.addView(messageText);

        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setView(scrollPane).setTitle(R.string.configuration_name)
                .setIcon(android.R.drawable.ic_dialog_info).setCancelable(false)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int id) {
                        dialog.cancel();
                    }
                });
        dialog = builder.create();
        break;
    }
    return dialog;
}

From source file:com.thomasokken.free42.Free42Activity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    instance = this;

    int init_mode;
    IntHolder version = new IntHolder();
    try {/*from w  ww.  j  a va2 s  .  c  o  m*/
        stateFileInputStream = openFileInput("state");
    } catch (FileNotFoundException e) {
        stateFileInputStream = null;
    }
    if (stateFileInputStream != null) {
        if (read_shell_state(version))
            init_mode = 1;
        else {
            init_shell_state(-1);
            init_mode = 2;
        }
    } else {
        init_shell_state(-1);
        init_mode = 0;
    }
    setAlwaysRepaintFullDisplay(alwaysRepaintFullDisplay);
    if (alwaysOn)
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    if (style == 1)
        setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
    else if (style == 2) {
        try {
            Method m = View.class.getMethod("setSystemUiVisibility", int.class);
            m.invoke(getWindow().getDecorView(), PreferencesDialog.immersiveModeFlags);
        } catch (Exception e) {
        }
    }

    Configuration conf = getResources().getConfiguration();
    orientation = conf.orientation == Configuration.ORIENTATION_LANDSCAPE ? 1 : 0;

    mainHandler = new Handler();
    calcView = new CalcView(this);
    setContentView(calcView);
    printView = new PrintView(this);
    printScrollView = new ScrollView(this);
    printScrollView.setBackgroundColor(PRINT_BACKGROUND_COLOR);
    printScrollView.addView(printView);

    skin = null;
    if (skinName[orientation].length() == 0 && externalSkinName[orientation].length() > 0) {
        try {
            skin = new SkinLayout(externalSkinName[orientation], skinSmoothing[orientation],
                    displaySmoothing[orientation]);
        } catch (IllegalArgumentException e) {
        }
    }
    if (skin == null) {
        try {
            skin = new SkinLayout(skinName[orientation], skinSmoothing[orientation],
                    displaySmoothing[orientation]);
        } catch (IllegalArgumentException e) {
        }
    }
    if (skin == null) {
        try {
            skin = new SkinLayout(builtinSkinNames[0], skinSmoothing[orientation],
                    displaySmoothing[orientation]);
        } catch (IllegalArgumentException e) {
            // This one should never fail; we're loading a built-in skin.
        }
    }

    nativeInit();
    core_init(init_mode, version.value);
    if (stateFileInputStream != null) {
        try {
            stateFileInputStream.close();
        } catch (IOException e) {
        }
        stateFileInputStream = null;
    }

    lowBatteryReceiver = new BroadcastReceiver() {
        public void onReceive(Context ctx, Intent intent) {
            low_battery = intent.getAction().equals(Intent.ACTION_BATTERY_LOW);
            Rect inval = skin.update_annunciators(-1, -1, -1, -1, low_battery ? 1 : 0, -1, -1);
            if (inval != null)
                calcView.postInvalidateScaled(inval.left, inval.top, inval.right, inval.bottom);
        }
    };
    IntentFilter iff = new IntentFilter();
    iff.addAction(Intent.ACTION_BATTERY_LOW);
    iff.addAction(Intent.ACTION_BATTERY_OKAY);
    registerReceiver(lowBatteryReceiver, iff);

    if (preferredOrientation != this.getRequestedOrientation())
        setRequestedOrientation(preferredOrientation);

    soundPool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0);
    int[] soundResourceIds = { R.raw.tone0, R.raw.tone1, R.raw.tone2, R.raw.tone3, R.raw.tone4, R.raw.tone5,
            R.raw.tone6, R.raw.tone7, R.raw.tone8, R.raw.tone9, R.raw.squeak, R.raw.click };
    soundIds = new int[soundResourceIds.length];
    for (int i = 0; i < soundResourceIds.length; i++)
        soundIds[i] = soundPool.load(this, soundResourceIds[i], 1);
}

From source file:org.telegram.ui.ChannelEditActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override/*w  ww  . j  a v a  2  s.  c  o  m*/
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (donePressed) {
                    return;
                }
                if (nameTextView.length() == 0) {
                    Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
                    if (v != null) {
                        v.vibrate(200);
                    }
                    AndroidUtilities.shakeView(nameTextView, 2, 0);
                    return;
                }
                donePressed = true;

                if (avatarUpdater.uploadingAvatar != null) {
                    createAfterUpload = true;
                    progressDialog = new ProgressDialog(getParentActivity());
                    progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
                    progressDialog.setCanceledOnTouchOutside(false);
                    progressDialog.setCancelable(false);
                    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                            LocaleController.getString("Cancel", R.string.Cancel),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    createAfterUpload = false;
                                    progressDialog = null;
                                    donePressed = false;
                                    try {
                                        dialog.dismiss();
                                    } catch (Exception e) {
                                        FileLog.e("tmessages", e);
                                    }
                                }
                            });
                    progressDialog.show();
                    return;
                }
                if (!currentChat.title.equals(nameTextView.getText().toString())) {
                    MessagesController.getInstance().changeChatTitle(chatId, nameTextView.getText().toString());
                }
                if (info != null && !info.about.equals(descriptionTextView.getText().toString())) {
                    MessagesController.getInstance().updateChannelAbout(chatId,
                            descriptionTextView.getText().toString(), info);
                }
                if (signMessages != currentChat.signatures) {
                    currentChat.signatures = true;
                    MessagesController.getInstance().toogleChannelSignatures(chatId, signMessages);
                }
                if (uploadedAvatar != null) {
                    MessagesController.getInstance().changeChatAvatar(chatId, uploadedAvatar);
                } else if (avatar == null && currentChat.photo instanceof TLRPC.TL_chatPhoto) {
                    MessagesController.getInstance().changeChatAvatar(chatId, null);
                }
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    LinearLayout linearLayout;

    fragmentView = new ScrollView(context);
    fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));
    ScrollView scrollView = (ScrollView) fragmentView;
    scrollView.setFillViewport(true);
    linearLayout = new LinearLayout(context);
    scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    linearLayout.setOrientation(LinearLayout.VERTICAL);

    actionBar.setTitle(LocaleController.getString("ChannelEdit", R.string.ChannelEdit));

    LinearLayout linearLayout2 = new LinearLayout(context);
    linearLayout2.setOrientation(LinearLayout.VERTICAL);
    linearLayout2.setElevation(AndroidUtilities.dp(2));
    linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
    linearLayout.addView(linearLayout2,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    FrameLayout frameLayout = new FrameLayout(context);
    linearLayout2.addView(frameLayout,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    avatarImage = new BackupImageView(context);
    avatarImage.setRoundRadius(AndroidUtilities.dp(32));
    avatarDrawable.setInfo(5, null, null, false);
    avatarDrawable.setDrawPhoto(true);
    frameLayout.addView(avatarImage,
            LayoutHelper.createFrame(64, 64,
                    Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT),
                    LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12));
    avatarImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (getParentActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());

            CharSequence[] items;

            if (avatar != null) {
                items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera),
                        LocaleController.getString("FromGalley", R.string.FromGalley),
                        LocaleController.getString("DeletePhoto", R.string.DeletePhoto) };
            } else {
                items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera),
                        LocaleController.getString("FromGalley", R.string.FromGalley) };
            }

            builder.setItems(items, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (i == 0) {
                        avatarUpdater.openCamera();
                    } else if (i == 1) {
                        avatarUpdater.openGallery();
                    } else if (i == 2) {
                        avatar = null;
                        uploadedAvatar = null;
                        avatarImage.setImage(avatar, "50_50", avatarDrawable);
                    }
                }
            });
            showDialog(builder.create());
        }
    });

    nameTextView = new EditText(context);
    if (currentChat.megagroup) {
        nameTextView.setHint(LocaleController.getString("GroupName", R.string.GroupName));
    } else {
        nameTextView.setHint(LocaleController.getString("EnterChannelName", R.string.EnterChannelName));
    }
    nameTextView.setMaxLines(4);
    nameTextView.setGravity(Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    //nameTextView.setHintTextColor(0xff979797);
    nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    nameTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    nameTextView.setPadding(0, 0, 0, AndroidUtilities.dp(8));
    InputFilter[] inputFilters = new InputFilter[1];
    inputFilters[0] = new InputFilter.LengthFilter(100);
    nameTextView.setFilters(inputFilters);
    AndroidUtilities.clearCursorDrawable(nameTextView);
    nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    frameLayout.addView(nameTextView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT,
                    Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 16 : 96, 0,
                    LocaleController.isRTL ? 96 : 16, 0));
    nameTextView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            avatarDrawable.setInfo(5, nameTextView.length() > 0 ? nameTextView.getText().toString() : null,
                    null, false);
            avatarImage.invalidate();
        }
    });

    View lineView = new View(context);
    lineView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_divider));
    linearLayout.addView(lineView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));

    linearLayout2 = new LinearLayout(context);
    linearLayout2.setOrientation(LinearLayout.VERTICAL);
    linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
    linearLayout2.setElevation(AndroidUtilities.dp(2));
    linearLayout.addView(linearLayout2,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    descriptionTextView = new EditText(context);
    descriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    //descriptionTextView.setHintTextColor(0xff979797);
    descriptionTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    descriptionTextView.setPadding(0, 0, 0, AndroidUtilities.dp(6));
    descriptionTextView.setBackgroundDrawable(null);
    descriptionTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    descriptionTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
            | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    descriptionTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
    inputFilters = new InputFilter[1];
    inputFilters[0] = new InputFilter.LengthFilter(255);
    descriptionTextView.setFilters(inputFilters);
    descriptionTextView.setHint(LocaleController.getString("DescriptionOptionalPlaceholder",
            R.string.DescriptionOptionalPlaceholder));
    AndroidUtilities.clearCursorDrawable(descriptionTextView);
    linearLayout2.addView(descriptionTextView,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 17, 12, 17, 6));
    descriptionTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
                doneButton.performClick();
                return true;
            }
            return false;
        }
    });
    descriptionTextView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

    ShadowSectionCell sectionCell = new ShadowSectionCell(context);
    sectionCell.setSize(20);
    linearLayout.addView(sectionCell,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    if (currentChat.megagroup || !currentChat.megagroup) {
        frameLayout = new FrameLayout(context);
        frameLayout.setElevation(AndroidUtilities.dp(2));
        frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        linearLayout.addView(frameLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        typeCell = new TextSettingsCell(context);
        updateTypeCell();
        typeCell.setForeground(R.drawable.list_selector);
        frameLayout.addView(typeCell,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        lineView = new View(context);
        lineView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_divider));
        linearLayout.addView(lineView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));

        frameLayout = new FrameLayout(context);
        frameLayout.setElevation(AndroidUtilities.dp(2));
        frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        linearLayout.addView(frameLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        if (!currentChat.megagroup) {
            TextCheckCell textCheckCell = new TextCheckCell(context);
            textCheckCell.setForeground(R.drawable.list_selector);
            textCheckCell.setTextAndCheck(
                    LocaleController.getString("ChannelSignMessages", R.string.ChannelSignMessages),
                    signMessages, false);
            frameLayout.addView(textCheckCell,
                    LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            textCheckCell.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    signMessages = !signMessages;
                    ((TextCheckCell) v).setChecked(signMessages);
                }
            });

            TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(context);
            //infoCell.setBackgroundResource(R.drawable.greydivider);
            infoCell.setText(
                    LocaleController.getString("ChannelSignMessagesInfo", R.string.ChannelSignMessagesInfo));
            linearLayout.addView(infoCell,
                    LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        } else {
            adminCell = new TextSettingsCell(context);
            updateAdminCell();
            adminCell.setForeground(R.drawable.list_selector);
            frameLayout.addView(adminCell,
                    LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            adminCell.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle args = new Bundle();
                    args.putInt("chat_id", chatId);
                    args.putInt("type", 1);
                    presentFragment(new ChannelUsersActivity(args));
                }
            });

            sectionCell = new ShadowSectionCell(context);
            sectionCell.setSize(20);
            linearLayout.addView(sectionCell,
                    LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            /*if (!currentChat.creator) {
            sectionCell.setBackgroundResource(R.drawable.greydivider_bottom);
            }*/
        }
    }

    if (currentChat.creator) {
        frameLayout = new FrameLayout(context);
        frameLayout.setElevation(AndroidUtilities.dp(2));
        frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        linearLayout.addView(frameLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        TextSettingsCell textCell = new TextSettingsCell(context);
        textCell.setTextColor(0xffed3d39);
        textCell.setBackgroundResource(R.drawable.list_selector);
        if (currentChat.megagroup) {
            textCell.setText(LocaleController.getString("DeleteMega", R.string.DeleteMega), false);
        } else {
            textCell.setText(LocaleController.getString("ChannelDelete", R.string.ChannelDelete), false);
        }
        frameLayout.addView(textCell,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        textCell.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                if (currentChat.megagroup) {
                    builder.setMessage(LocaleController.getString("MegaDeleteAlert", R.string.MegaDeleteAlert));
                } else {
                    builder.setMessage(
                            LocaleController.getString("ChannelDeleteAlert", R.string.ChannelDeleteAlert));
                }
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                NotificationCenter.getInstance().removeObserver(this,
                                        NotificationCenter.closeChats);
                                if (AndroidUtilities.isTablet()) {
                                    NotificationCenter.getInstance().postNotificationName(
                                            NotificationCenter.closeChats, -(long) chatId);
                                } else {
                                    NotificationCenter.getInstance()
                                            .postNotificationName(NotificationCenter.closeChats);
                                }
                                MessagesController.getInstance().deleteUserFromChat(chatId,
                                        MessagesController.getInstance().getUser(UserConfig.getClientUserId()),
                                        info);
                                finishFragment();
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            }
        });

        TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(context);
        //infoCell.setBackgroundResource(R.drawable.greydivider_bottom);
        if (currentChat.megagroup) {
            infoCell.setText(LocaleController.getString("MegaDeleteInfo", R.string.MegaDeleteInfo));
        } else {
            infoCell.setText(LocaleController.getString("ChannelDeleteInfo", R.string.ChannelDeleteInfo));
        }
        linearLayout.addView(infoCell,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    }

    nameTextView.setText(currentChat.title);
    nameTextView.setSelection(nameTextView.length());
    if (info != null) {
        descriptionTextView.setText(info.about);
    }
    if (currentChat.photo != null) {
        avatar = currentChat.photo.photo_small;
        avatarImage.setImage(avatar, "50_50", avatarDrawable);
    } else {
        avatarImage.setImageDrawable(avatarDrawable);
    }

    return fragmentView;
}

From source file:com.glacialsoftware.googolplex.LicenseDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new Builder(getActivity());

    ScrollView scrollView = new ScrollView(getActivity());
    TextView textView = new TextView(getActivity());

    builder.setTitle("Apache License, Version 2.0");
    textView.setText(apache2kolavar);//from  w w w.  ja  va 2 s  . c o  m

    scrollView.addView(textView);

    builder.setView(scrollView);
    return builder.create();
}