Example usage for android.widget LinearLayout setGravity

List of usage examples for android.widget LinearLayout setGravity

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setGravity(int gravity) 

Source Link

Document

Describes how the child views are positioned.

Usage

From source file:org.alfresco.mobile.android.application.fragments.workflow.task.TaskDetailsFragment.java

private void diplayAttachment() {
    vRoot.findViewById(R.id.attachments_waiting).setVisibility(View.GONE);
    LinearLayout ll = (LinearLayout) vRoot.findViewById(R.id.attachments);
    if (items == null || items.isEmpty()) {
        ImageView iv = new ImageView(getActivity());
        iv.setScaleType(ScaleType.FIT_CENTER);
        iv.setImageResource(R.drawable.mime_empty_doc);
        ll.addView(iv, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        TextView tv = new TextView(getActivity());
        tv.setText(R.string.process_no_attachments);
        tv.setGravity(Gravity.CENTER);//from   w w w .j ava  2s  .c o  m
        ll.addView(tv, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

        ll.setGravity(Gravity.CENTER);
        return;
    }

    LayoutInflater li = LayoutInflater.from(getActivity());
    View vr = null;
    TextView tv = null;
    for (Node node : items) {
        vr = li.inflate(R.layout.app_task_item_row, ll, false);
        tv = (TextView) vr.findViewById(R.id.toptext);
        tv.setText(node.getName());
        tv = (TextView) vr.findViewById(R.id.bottomtext);
        tv.setText(createContentBottomText(getActivity(), node));
        ll.addView(vr, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        ImageView iv = (ImageView) vr.findViewById(R.id.icon);
        RenditionManager.with(getActivity()).loadNode(node)
                .placeHolder(MimeTypeManager.getInstance(getActivity()).getIcon(node.getName(), true)).into(iv);
        vr.setTag(node);
        vr.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Node item = (Node) v.getTag();
                NodeDetailsFragment.with(getActivity()).nodeId(item.getIdentifier()).back(true).display();
            }
        });
    }
}

From source file:com.wit.and.dialog.LoginDialog.java

/**
 * //from  w  w w  .  j a  v  a  2 s.  co m
 */
@Override
protected View onCreateBodyView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = inflater.getContext();

    RelativeLayout layout = new RelativeLayout(context);
    // Apply neutral layout params.
    layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    // Do not allow to apply style to body view.
    // layout.setId(R.id.Dialog_Layout_Body);

    // Create layout for loading view.
    LinearLayout loadingLayout = new LinearLayout(context);
    loadingLayout.setOrientation(LinearLayout.HORIZONTAL);
    loadingLayout.setGravity(Gravity.CENTER_VERTICAL);
    // Allow styling of loading layout as body layout.
    loadingLayout.setId(R.id.And_Dialog_Layout_Body);

    // Create text view for message.
    TextView msgTextView = new TextView(context);
    msgTextView.setId(R.id.And_Dialog_TextView_Message);

    // Create circle progress bar.
    ProgressBar circleProgressBar = new ProgressBar(context);
    circleProgressBar.setId(R.id.And_Dialog_ProgressBar);

    // Build loading view.
    loadingLayout.addView(circleProgressBar, new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
    loadingLayout.addView(msgTextView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    loadingLayout.setVisibility(View.GONE);

    // Insert loading layout into main body layout.
    RelativeLayout.LayoutParams loadingLayoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    loadingLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    layout.addView(loadingLayout, loadingLayoutParams);

    // Create layout for edit texts.
    LinearLayout editLayout = new LinearLayout(context);
    editLayout.setOrientation(LinearLayout.VERTICAL);
    editLayout.setId(R.id.And_Dialog_Layout_LoginDialog_EditView);

    // Create edit texts for username and password.
    EditText userEdit = new EditText(context);
    userEdit.setId(R.id.And_Dialog_EditText_Username);
    userEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
    EditText passEdit = new EditText(context);
    passEdit.setId(R.id.And_Dialog_EditText_Password);
    passEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

    // Create edit texts divider.
    DialogDivider divider = new DialogDivider(context);
    divider.setId(R.id.And_Dialog_Divider_LoginDialog_EditTexts);

    // Build edit layout.
    editLayout.addView(userEdit, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    editLayout.addView(divider, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    editLayout.addView(passEdit, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    // Add custom layout.
    View customView = onCreateCustomView(inflater, editLayout, savedInstanceState);
    if (customView != null) {
        editLayout.addView(this.mCustomView = customView);
    }

    // Insert edit layout into main body layout.
    RelativeLayout.LayoutParams editLayoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    editLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    layout.addView(editLayout, editLayoutParams);

    return layout;
}

From source file:com.coolerfall.uiart.PagerSlidingTabStrip.java

/** add one number indicator tab */
private void addNumTab(final int position, String title, int num) {
    LinearLayout tab = new LinearLayout(getContext());
    TextView titleText = new TextView(getContext());
    TextView numText = new TextView(getContext());

    titleText.setText(title);/*from  w  w w.j  av a 2s .c  om*/
    titleText.setGravity(Gravity.CENTER);
    titleText.setSingleLine();

    numText.setText(Integer.toString(num));
    numText.setGravity(Gravity.CENTER);
    numText.setPadding(mNumPadding, 1, mNumPadding, 1);
    numText.setSingleLine();

    /* if the number is 0, set invisible */
    if (num == 0) {
        numText.setVisibility(View.GONE);
    } else {
        numText.setVisibility(View.VISIBLE);
    }

    tab.addView(titleText, 0, mDefaultTabLayoutParams);
    tab.addView(numText, 1, mNumLayoutParams);
    tab.setGravity(Gravity.CENTER);

    addTab(position, tab);
}

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

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(false);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override/*from   w  ww. java  2s .c  om*/
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                processDone();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));

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

    scrollView = new ScrollView(context);
    scrollView.setFillViewport(true);
    frameLayout.addView(scrollView);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) scrollView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    scrollView.setLayoutParams(layoutParams);

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    scrollView.addView(linearLayout);
    ScrollView.LayoutParams layoutParams2 = (ScrollView.LayoutParams) linearLayout.getLayoutParams();
    layoutParams2.width = ScrollView.LayoutParams.MATCH_PARENT;
    layoutParams2.height = ScrollView.LayoutParams.WRAP_CONTENT;
    linearLayout.setLayoutParams(layoutParams2);

    titleTextView = new TextView(context);
    //titleTextView.setTextColor(0xff757575);
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
    linearLayout.addView(titleTextView);
    LinearLayout.LayoutParams layoutParams3 = (LinearLayout.LayoutParams) titleTextView.getLayoutParams();
    layoutParams3.width = LayoutHelper.WRAP_CONTENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.gravity = Gravity.CENTER_HORIZONTAL;
    layoutParams3.topMargin = AndroidUtilities.dp(38);
    titleTextView.setLayoutParams(layoutParams3);

    passwordEditText = new EditText(context);
    passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    //passwordEditText.setTextColor(0xff000000);
    passwordEditText.setMaxLines(1);
    passwordEditText.setLines(1);
    passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
    passwordEditText.setSingleLine(true);
    passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
    passwordEditText.setTypeface(Typeface.DEFAULT);
    AndroidUtilities.clearCursorDrawable(passwordEditText);
    linearLayout.addView(passwordEditText);
    layoutParams3 = (LinearLayout.LayoutParams) passwordEditText.getLayoutParams();
    layoutParams3.topMargin = AndroidUtilities.dp(32);
    layoutParams3.height = AndroidUtilities.dp(36);
    layoutParams3.leftMargin = AndroidUtilities.dp(40);
    layoutParams3.rightMargin = AndroidUtilities.dp(40);
    layoutParams3.gravity = Gravity.TOP | Gravity.LEFT;
    layoutParams3.width = LayoutHelper.MATCH_PARENT;
    passwordEditText.setLayoutParams(layoutParams3);
    passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_NEXT || i == EditorInfo.IME_ACTION_DONE) {
                processDone();
                return true;
            }
            return false;
        }
    });
    passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public void onDestroyActionMode(ActionMode mode) {
        }

        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }
    });

    bottomTextView = new TextView(context);
    //bottomTextView.setTextColor(0xff757575);
    bottomTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    bottomTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    bottomTextView.setText(LocaleController.getString("YourEmailInfo", R.string.YourEmailInfo));
    linearLayout.addView(bottomTextView);
    layoutParams3 = (LinearLayout.LayoutParams) bottomTextView.getLayoutParams();
    layoutParams3.width = LayoutHelper.WRAP_CONTENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP;
    layoutParams3.topMargin = AndroidUtilities.dp(30);
    layoutParams3.leftMargin = AndroidUtilities.dp(40);
    layoutParams3.rightMargin = AndroidUtilities.dp(40);
    bottomTextView.setLayoutParams(layoutParams3);

    LinearLayout linearLayout2 = new LinearLayout(context);
    linearLayout2.setGravity(Gravity.BOTTOM | Gravity.CENTER_VERTICAL);
    linearLayout.addView(linearLayout2);
    layoutParams3 = (LinearLayout.LayoutParams) linearLayout2.getLayoutParams();
    layoutParams3.width = LayoutHelper.MATCH_PARENT;
    layoutParams3.height = LayoutHelper.MATCH_PARENT;
    linearLayout2.setLayoutParams(layoutParams3);

    bottomButton = new TextView(context);
    bottomButton.setTextColor(0xff4d83b3);
    bottomButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    bottomButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM);
    bottomButton.setText(LocaleController.getString("YourEmailSkip", R.string.YourEmailSkip));
    bottomButton.setPadding(0, AndroidUtilities.dp(10), 0, 0);
    linearLayout2.addView(bottomButton);
    layoutParams3 = (LinearLayout.LayoutParams) bottomButton.getLayoutParams();
    layoutParams3.width = LayoutHelper.WRAP_CONTENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM;
    layoutParams3.bottomMargin = AndroidUtilities.dp(14);
    layoutParams3.leftMargin = AndroidUtilities.dp(40);
    layoutParams3.rightMargin = AndroidUtilities.dp(40);
    bottomButton.setLayoutParams(layoutParams3);
    bottomButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (type == 0) {
                if (currentPassword.has_recovery) {
                    needShowProgress();
                    TLRPC.TL_auth_requestPasswordRecovery req = new TLRPC.TL_auth_requestPasswordRecovery();
                    ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                        @Override
                        public void run(final TLObject response, final TLRPC.TL_error error) {
                            AndroidUtilities.runOnUIThread(new Runnable() {
                                @Override
                                public void run() {
                                    needHideProgress();
                                    if (error == null) {
                                        final TLRPC.TL_auth_passwordRecovery res = (TLRPC.TL_auth_passwordRecovery) response;
                                        AlertDialog.Builder builder = new AlertDialog.Builder(
                                                getParentActivity());
                                        builder.setMessage(LocaleController.formatString("RestoreEmailSent",
                                                R.string.RestoreEmailSent, res.email_pattern));
                                        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) {
                                                        TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(
                                                                1);
                                                        fragment.currentPassword = currentPassword;
                                                        fragment.currentPassword.email_unconfirmed_pattern = res.email_pattern;
                                                        fragment.passwordSetState = 4;
                                                        presentFragment(fragment);
                                                    }
                                                });
                                        Dialog dialog = showDialog(builder.create());
                                        if (dialog != null) {
                                            dialog.setCanceledOnTouchOutside(false);
                                            dialog.setCancelable(false);
                                        }
                                    } else {
                                        if (error.text.startsWith("FLOOD_WAIT")) {
                                            int time = Utilities.parseInt(error.text);
                                            String timeString;
                                            if (time < 60) {
                                                timeString = LocaleController.formatPluralString("Seconds",
                                                        time);
                                            } else {
                                                timeString = LocaleController.formatPluralString("Minutes",
                                                        time / 60);
                                            }
                                            showAlertWithText(
                                                    LocaleController.getString("AppName", R.string.AppName),
                                                    LocaleController.formatString("FloodWaitTime",
                                                            R.string.FloodWaitTime, timeString));
                                        } else {
                                            showAlertWithText(
                                                    LocaleController.getString("AppName", R.string.AppName),
                                                    error.text);
                                        }
                                    }
                                }
                            });
                        }
                    }, ConnectionsManager.RequestFlagFailOnServerErrors
                            | ConnectionsManager.RequestFlagWithoutLogin);
                } else {
                    showAlertWithText(
                            LocaleController.getString("RestorePasswordNoEmailTitle",
                                    R.string.RestorePasswordNoEmailTitle),
                            LocaleController.getString("RestorePasswordNoEmailText",
                                    R.string.RestorePasswordNoEmailText));
                }
            } else {
                if (passwordSetState == 4) {
                    showAlertWithText(
                            LocaleController.getString("RestorePasswordNoEmailTitle",
                                    R.string.RestorePasswordNoEmailTitle),
                            LocaleController.getString("RestoreEmailTroubleText",
                                    R.string.RestoreEmailTroubleText));
                } else {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setMessage(LocaleController.getString("YourEmailSkipWarningText",
                            R.string.YourEmailSkipWarningText));
                    builder.setTitle(
                            LocaleController.getString("YourEmailSkipWarning", R.string.YourEmailSkipWarning));
                    builder.setPositiveButton(
                            LocaleController.getString("YourEmailSkip", R.string.YourEmailSkip),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    email = "";
                                    setNewPassword(false);
                                }
                            });
                    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                    showDialog(builder.create());
                }
            }
        }
    });

    if (type == 0) {
        progressView = new FrameLayout(context);
        frameLayout.addView(progressView);
        layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        progressView.setLayoutParams(layoutParams);
        progressView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });

        ProgressBar progressBar = new ProgressBar(context);
        progressView.addView(progressBar);
        layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
        layoutParams.width = LayoutHelper.WRAP_CONTENT;
        layoutParams.height = LayoutHelper.WRAP_CONTENT;
        layoutParams.gravity = Gravity.CENTER;
        progressView.setLayoutParams(layoutParams);

        listView = new ListView(context);
        listView.setDivider(null);
        listView.setEmptyView(progressView);
        listView.setDividerHeight(0);
        listView.setVerticalScrollBarEnabled(false);
        listView.setDrawSelectorOnTop(true);
        frameLayout.addView(listView);
        layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
        layoutParams.width = LayoutHelper.MATCH_PARENT;
        layoutParams.height = LayoutHelper.MATCH_PARENT;
        layoutParams.gravity = Gravity.TOP;
        listView.setLayoutParams(layoutParams);
        listView.setAdapter(listAdapter = new ListAdapter(context));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                if (i == setPasswordRow || i == changePasswordRow) {
                    TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(1);
                    fragment.currentPasswordHash = currentPasswordHash;
                    fragment.currentPassword = currentPassword;
                    presentFragment(fragment);
                } else if (i == setRecoveryEmailRow || i == changeRecoveryEmailRow) {
                    TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(1);
                    fragment.currentPasswordHash = currentPasswordHash;
                    fragment.currentPassword = currentPassword;
                    fragment.emailOnly = true;
                    fragment.passwordSetState = 3;
                    presentFragment(fragment);
                } else if (i == turnPasswordOffRow || i == abortPasswordRow) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setMessage(LocaleController.getString("TurnPasswordOffQuestion",
                            R.string.TurnPasswordOffQuestion));
                    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) {
                                    setNewPassword(true);
                                }
                            });
                    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                    showDialog(builder.create());
                }
            }
        });

        updateRows();

        actionBar.setTitle(LocaleController.getString("TwoStepVerification", R.string.TwoStepVerification));
        titleTextView.setText(
                LocaleController.getString("PleaseEnterCurrentPassword", R.string.PleaseEnterCurrentPassword));
    } else if (type == 1) {
        setPasswordSetState(passwordSetState);
    }

    return fragmentView;
}

From source file:com.asksven.betterbatterystats.StatsActivity.java

public Dialog getShareDialog() {

    final ArrayList<Integer> selectedSaveActions = new ArrayList<Integer>();

    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean saveDumpfile = sharedPrefs.getBoolean("save_dumpfile", true);
    boolean saveLogcat = sharedPrefs.getBoolean("save_logcat", false);
    boolean saveDmesg = sharedPrefs.getBoolean("save_dmesg", false);

    if (saveDumpfile) {
        selectedSaveActions.add(0);/*w  w w .j a v  a 2 s  .  c om*/
    }
    if (saveLogcat) {
        selectedSaveActions.add(1);
    }
    if (saveDmesg) {
        selectedSaveActions.add(2);
    }

    //----
    LinearLayout layout = new LinearLayout(this);
    LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(parms);

    layout.setGravity(Gravity.CLIP_VERTICAL);
    layout.setPadding(2, 2, 2, 2);

    final TextView editTitle = new TextView(StatsActivity.this);
    editTitle.setText(R.string.share_dialog_edit_title);
    editTitle.setPadding(40, 40, 40, 40);
    editTitle.setGravity(Gravity.LEFT);
    editTitle.setTextSize(20);

    final EditText editDescription = new EditText(StatsActivity.this);

    LinearLayout.LayoutParams tv1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    tv1Params.bottomMargin = 5;
    layout.addView(editTitle, tv1Params);
    layout.addView(editDescription, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    //----

    // Set the dialog title
    builder.setTitle(R.string.title_share_dialog)
            .setMultiChoiceItems(R.array.saveAsLabels, new boolean[] { saveDumpfile, saveLogcat, saveDmesg },
                    new DialogInterface.OnMultiChoiceClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                            if (isChecked) {
                                // If the user checked the item, add it to the
                                // selected items
                                selectedSaveActions.add(which);
                            } else if (selectedSaveActions.contains(which)) {
                                // Else, if the item is already in the array,
                                // remove it
                                selectedSaveActions.remove(Integer.valueOf(which));
                            }
                        }
                    })
            .setView(layout)
            // Set the action buttons
            .setPositiveButton(R.string.label_button_share, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    ArrayList<Uri> attachements = new ArrayList<Uri>();

                    Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName,
                            StatsActivity.this);
                    Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName,
                            StatsActivity.this);

                    Reading reading = new Reading(StatsActivity.this, myReferenceFrom, myReferenceTo);

                    // save as text is selected
                    if (selectedSaveActions.contains(0)) {
                        attachements.add(reading.writeDumpfile(StatsActivity.this,
                                editDescription.getText().toString()));
                    }
                    // save logcat if selected
                    if (selectedSaveActions.contains(1)) {
                        attachements.add(StatsProvider.getInstance().writeLogcatToFile());
                    }
                    // save dmesg if selected
                    if (selectedSaveActions.contains(2)) {
                        attachements.add(StatsProvider.getInstance().writeDmesgToFile());
                    }

                    if (!attachements.isEmpty()) {
                        Intent shareIntent = new Intent();
                        shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
                        shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachements);
                        shareIntent.setType("text/*");
                        startActivity(Intent.createChooser(shareIntent, "Share info to.."));
                    }
                }
            }).setNeutralButton(R.string.label_button_save, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {

                    try {
                        Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName,
                                StatsActivity.this);
                        Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName,
                                StatsActivity.this);

                        Reading reading = new Reading(StatsActivity.this, myReferenceFrom, myReferenceTo);

                        // save as text is selected
                        if (selectedSaveActions.contains(0)) {
                            reading.writeDumpfile(StatsActivity.this, editDescription.getText().toString());
                        }
                        // save logcat if selected
                        if (selectedSaveActions.contains(1)) {
                            StatsProvider.getInstance().writeLogcatToFile();
                        }
                        // save dmesg if selected
                        if (selectedSaveActions.contains(2)) {
                            StatsProvider.getInstance().writeDmesgToFile();
                        }

                        Snackbar.make(findViewById(android.R.id.content), getString(R.string.info_files_written)
                                + ": " + StatsProvider.getWritableFilePath(), Snackbar.LENGTH_LONG).show();
                    } catch (Exception e) {
                        Log.e(TAG, "an error occured writing files: " + e.getMessage());
                        Snackbar.make(findViewById(android.R.id.content), R.string.info_files_write_error,
                                Snackbar.LENGTH_LONG).show();
                    }

                }
            }).setNegativeButton(R.string.label_button_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    // do nothing
                }
            });

    return builder.create();
}

From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java

public void excecutePositiveButtonClick() {
    for (final ButtonTO button : mCurrentMessage.buttons) {
        if (Message.POSITIVE.equals(button.id)) {
            final LinearLayout container = (LinearLayout) getLayoutInflater()
                    .inflate(R.layout.message_button_detail, null);
            container.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);

            executeButtonClick(button, container, true);
            break;
        }/*from   www .  j  av  a  2s .c o m*/
    }
}

From source file:com.mishiranu.dashchan.ui.navigator.NavigatorActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void showThemeDialog() {
    final int checkedItem = Arrays.asList(Preferences.VALUES_THEME).indexOf(Preferences.getTheme());
    Resources resources = getResources();
    float density = ResourceUtils.obtainDensity(resources);
    ScrollView scrollView = new ScrollView(this);
    LinearLayout outer = new LinearLayout(this);
    outer.setOrientation(LinearLayout.VERTICAL);
    int outerPadding = (int) (16f * density);
    outer.setPadding(outerPadding, outerPadding, outerPadding, outerPadding);
    scrollView.addView(outer, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.action_change_theme)
            .setView(scrollView).setNegativeButton(android.R.string.cancel, null).create();
    View.OnClickListener listener = v -> {
        int index = (int) v.getTag();
        if (index != checkedItem) {
            Preferences.setTheme(Preferences.VALUES_THEME[index]);
            recreate();/*  w  w  w .  j ava 2s  .  c o m*/
        }
        dialog.dismiss();
    };
    int circleSize = (int) (56f * density);
    int itemPadding = (int) (12f * density);
    LinearLayout inner = null;
    for (int i = 0; i < Preferences.ENTRIES_THEME.length; i++) {
        if (i % 3 == 0) {
            inner = new LinearLayout(this);
            inner.setOrientation(LinearLayout.HORIZONTAL);
            outer.addView(inner, LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
        }
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setGravity(Gravity.CENTER);
        layout.setBackgroundResource(
                ResourceUtils.getResourceId(this, android.R.attr.selectableItemBackground, 0));
        layout.setPadding(0, itemPadding, 0, itemPadding);
        layout.setOnClickListener(listener);
        layout.setTag(i);
        inner.addView(layout, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
        View view = new View(this);
        int colorBackgroundAttr = Preferences.VALUES_THEME_COLORS[i][0];
        int colorPrimaryAttr = Preferences.VALUES_THEME_COLORS[i][1];
        int colorAccentAttr = Preferences.VALUES_THEME_COLORS[i][2];
        Resources.Theme theme = getResources().newTheme();
        theme.applyStyle(Preferences.VALUES_THEME_IDS[i], true);
        TypedArray typedArray = theme
                .obtainStyledAttributes(new int[] { colorBackgroundAttr, colorPrimaryAttr, colorAccentAttr });
        view.setBackground(new ThemeChoiceDrawable(typedArray.getColor(0, 0), typedArray.getColor(1, 0),
                typedArray.getColor(2, 0)));
        typedArray.recycle();
        if (C.API_LOLLIPOP) {
            view.setElevation(6f * density);
        }
        layout.addView(view, circleSize, circleSize);
        TextView textView = new TextView(this, null, android.R.attr.textAppearanceListItem);
        textView.setSingleLine(true);
        textView.setEllipsize(TextUtils.TruncateAt.END);
        textView.setText(Preferences.ENTRIES_THEME[i]);
        if (C.API_LOLLIPOP) {
            textView.setAllCaps(true);
            textView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f);
        } else {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f);
        }
        textView.setGravity(Gravity.CENTER_HORIZONTAL);
        textView.setPadding(0, (int) (8f * density), 0, 0);
        layout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        if (i + 1 == Preferences.ENTRIES_THEME.length && Preferences.ENTRIES_THEME.length % 3 != 0) {
            if (Preferences.ENTRIES_THEME.length % 3 == 1) {
                inner.addView(new View(this), 0,
                        new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f));
            }
            inner.addView(new View(this),
                    new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f));
        }
    }
    dialog.show();
}

From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java

public DrawerForm(Context context, Context unstyledContext, Callback callback,
        WatcherService.Client watcherServiceClient) {
    this.context = context;
    this.unstyledContext = unstyledContext;
    this.callback = callback;
    this.watcherServiceClient = watcherServiceClient;
    float density = ResourceUtils.obtainDensity(context);
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setLayoutParams(new SortableListView.LayoutParams(SortableListView.LayoutParams.MATCH_PARENT,
            SortableListView.LayoutParams.WRAP_CONTENT));
    LinearLayout editTextContainer = new LinearLayout(context);
    editTextContainer.setGravity(Gravity.CENTER_VERTICAL);
    linearLayout.addView(editTextContainer);
    searchEdit = new SafePasteEditText(context);
    searchEdit.setOnKeyListener((v, keyCode, event) -> {
        if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
            v.clearFocus();//  w ww  .  j av  a 2 s .c o m
        }
        return false;
    });
    searchEdit.setHint(context.getString(R.string.text_code_number_address));
    searchEdit.setOnEditorActionListener(this);
    searchEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    searchEdit.setImeOptions(EditorInfo.IME_ACTION_GO | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    ImageView searchIcon = new ImageView(context, null, android.R.attr.buttonBarButtonStyle);
    searchIcon.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonForward, 0));
    searchIcon.setScaleType(ImageView.ScaleType.CENTER);
    searchIcon.setOnClickListener(this);
    editTextContainer.addView(searchEdit,
            new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
    editTextContainer.addView(searchIcon, (int) (40f * density), (int) (40f * density));
    if (C.API_LOLLIPOP) {
        editTextContainer.setPadding((int) (12f * density), (int) (8f * density), (int) (8f * density), 0);
    } else {
        editTextContainer.setPadding(0, (int) (2f * density), (int) (4f * density), (int) (2f * density));
    }
    LinearLayout selectorContainer = new LinearLayout(context);
    selectorContainer.setBackgroundResource(
            ResourceUtils.getResourceId(context, android.R.attr.selectableItemBackground, 0));
    selectorContainer.setOrientation(LinearLayout.HORIZONTAL);
    selectorContainer.setGravity(Gravity.CENTER_VERTICAL);
    selectorContainer.setOnClickListener(v -> {
        hideKeyboard();
        setChanSelectMode(!chanSelectMode);
    });
    linearLayout.addView(selectorContainer);
    selectorContainer.setMinimumHeight((int) (40f * density));
    if (C.API_LOLLIPOP) {
        selectorContainer.setPadding((int) (16f * density), 0, (int) (16f * density), 0);
        ((LinearLayout.LayoutParams) selectorContainer.getLayoutParams()).topMargin = (int) (4f * density);
    } else {
        selectorContainer.setPadding((int) (8f * density), 0, (int) (12f * density), 0);
    }
    chanNameView = new TextView(context, null, android.R.attr.textAppearanceListItem);
    chanNameView.setTextSize(TypedValue.COMPLEX_UNIT_SP, C.API_LOLLIPOP ? 14f : 16f);
    if (C.API_LOLLIPOP) {
        chanNameView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM);
    } else {
        chanNameView.setFilters(new InputFilter[] { new InputFilter.AllCaps() });
    }
    selectorContainer.addView(chanNameView,
            new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
    chanSelectorIcon = new ImageView(context);
    chanSelectorIcon.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonDropDownDrawer, 0));
    selectorContainer.addView(chanSelectorIcon, (int) (24f * density), (int) (24f * density));
    ((LinearLayout.LayoutParams) chanSelectorIcon.getLayoutParams()).gravity = Gravity.CENTER_VERTICAL
            | Gravity.END;
    headerView = linearLayout;
    inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    chans.add(new ListItem(ListItem.ITEM_DIVIDER, 0, 0, null));
    int color = ResourceUtils.getColor(context, R.attr.drawerIconColor);
    ChanManager manager = ChanManager.getInstance();
    Collection<String> availableChans = manager.getAvailableChanNames();
    for (String chanName : availableChans) {
        ChanConfiguration configuration = ChanConfiguration.get(chanName);
        if (configuration.getOption(ChanConfiguration.OPTION_READ_POSTS_COUNT)) {
            watcherSupportSet.add(chanName);
        }
        Drawable drawable = manager.getIcon(chanName, color);
        chanIcons.put(chanName, drawable);
        chans.add(
                new ListItem(ListItem.ITEM_CHAN, chanName, null, null, configuration.getTitle(), 0, drawable));
    }
    if (availableChans.size() == 1) {
        selectorContainer.setVisibility(View.GONE);
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java

private void addButton(final String senderName, String myEmail, boolean somebodyAnswered, boolean canEdit,
        TableLayout tableLayout, final ButtonTO button) {
    TableRow row = new TableRow(this);
    tableLayout.addView(row);//from   w  w w  . j  ava2s . com
    row.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,
            TableLayout.LayoutParams.WRAP_CONTENT, 1));

    // XXX: inconsistent margin between 2 rows

    final Button buttonView = new Button(this);
    buttonView.setMinWidth(UIUtils.convertDipToPixels(this, 100));
    buttonView.setText(button.caption);
    buttonView.setTextColor(getResources().getColor(android.R.color.primary_text_dark));
    if (somebodyAnswered)
        buttonView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
    else {
        buttonView.setWidth(mDisplayWidth - UIUtils.convertDipToPixels(this, 12));
    }
    buttonView.setTextSize(19);
    row.addView(buttonView);

    final LinearLayout container = (LinearLayout) getLayoutInflater().inflate(R.layout.message_button_detail,
            null);
    container.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);

    boolean buttonSelectedByMe = false;
    for (MemberStatusTO status : mCurrentMessage.members) {
        if ((status.status & MessagingPlugin.STATUS_ACKED) == MessagingPlugin.STATUS_ACKED
                && ((button.id == null && status.button_id == null)
                        || (button.id != null && button.id.equals(status.button_id)))) {

            getLayoutInflater().inflate(R.layout.avatar, container);
            ImageView avatar = (ImageView) container.getChildAt(container.getChildCount() - 1);

            setAvatar(avatar, status.member);
            if (status.member.equals(myEmail))
                buttonSelectedByMe = true;

            int dp42 = UIUtils.convertDipToPixels(this, 42);
            int dp2 = UIUtils.convertDipToPixels(this, 1);
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) avatar.getLayoutParams();
            lp.setMargins(0, dp2, 0, 0);
            lp.width = dp42;
            lp.height = dp42;
        }
    }

    row.addView(container);

    boolean hasAction = button.action != null && !"".equals(button.action);
    final boolean buttonIsEnabled = canEdit
            && (mCurrentMessage.form != null || !buttonSelectedByMe || hasAction);
    buttonView.setEnabled(buttonIsEnabled);

    int color;
    if (button.id == null || mCurrentMessage.form != null && Message.POSITIVE.equals(button.id)) {
        color = buttonIsEnabled ? Message.GREEN_BUTTON_COLOR : Message.GREENGRAY_BUTTON_COLOR;
    } else if (mCurrentMessage.form != null && Message.NEGATIVE.equals(button.id)) {
        color = buttonIsEnabled ? Message.RED_BUTTON_COLOR : Message.REDGRAY_BUTTON_COLOR;
    } else {
        color = buttonIsEnabled ? Message.BLUE_BUTTON_COLOR : Message.BLUEGRAY_BUTTON_COLOR;
    }
    buttonView.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY);

    buttonView.setOnClickListener(new SafeViewOnClickListener() {

        @Override
        public void safeOnClick(View v) {
            T.UI();
            executeButtonClick(button, container, true);
        }
    });

    final HorizontalScrollView scroller = (HorizontalScrollView) findViewById(R.id.button_scroller);
    scroller.post(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            scroller.fullScroll(ScrollView.FOCUS_RIGHT);
        }
    });
}

From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java

private View makeView(boolean icon, boolean watcher, boolean closeable, float density) {
    int size = (int) (48f * density);
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    linearLayout.setGravity(Gravity.CENTER_VERTICAL);
    ImageView iconView = null;// w  w  w  .j av  a2  s  .c o  m
    if (icon) {
        iconView = new ImageView(context);
        iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        linearLayout.addView(iconView, (int) (24f * density), size);
    }
    TextView textView = makeCommonTextView(false);
    linearLayout.addView(textView, new LinearLayout.LayoutParams(0, size, 1));
    WatcherView watcherView = null;
    if (watcher) {
        watcherView = new WatcherView(context);
        linearLayout.addView(watcherView, size, size);
    }
    ImageView closeView = null;
    if (!watcher && closeable) {
        closeView = new ImageView(context);
        closeView.setScaleType(ImageView.ScaleType.CENTER);
        closeView.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonCancel, 0));
        closeView.setBackgroundResource(ResourceUtils.getResourceId(context,
                android.R.attr.borderlessButtonStyle, android.R.attr.background, 0));
        linearLayout.addView(closeView, size, size);
        closeView.setOnClickListener(closeButtonListener);
    }
    ViewHolder holder = new ViewHolder();
    holder.icon = iconView;
    holder.text = textView;
    holder.extra = watcherView != null ? watcherView : closeView;
    linearLayout.setTag(holder);
    int layoutLeftDp = 0;
    int layoutRightDp = 0;
    int textLeftDp;
    int textRightDp;
    if (C.API_LOLLIPOP) {
        textLeftDp = 16;
        textRightDp = 16;
        if (icon) {
            layoutLeftDp = 16;
            textLeftDp = 32;
        }
        if (watcher || closeable) {
            layoutRightDp = 4;
            textRightDp = 8;
        }
    } else {
        textLeftDp = 8;
        textRightDp = 8;
        if (icon) {
            layoutLeftDp = 8;
            textLeftDp = 6;
            textView.setAllCaps(true);
        }
        if (watcher || closeable) {
            layoutRightDp = 0;
            textRightDp = 0;
        }
    }
    linearLayout.setPadding((int) (layoutLeftDp * density), 0, (int) (layoutRightDp * density), 0);
    textView.setPadding((int) (textLeftDp * density), 0, (int) (textRightDp * density), 0);
    return linearLayout;
}