Example usage for android.view Gravity CLIP_VERTICAL

List of usage examples for android.view Gravity CLIP_VERTICAL

Introduction

In this page you can find the example usage for android.view Gravity CLIP_VERTICAL.

Prototype

int CLIP_VERTICAL

To view the source code for android.view Gravity CLIP_VERTICAL.

Click Source Link

Document

Flag to clip the edges of the object to its container along the vertical axis.

Usage

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);/*from   www . java 2s .co m*/
    }
    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();
}