Example usage for android.widget EditText EditText

List of usage examples for android.widget EditText EditText

Introduction

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

Prototype

public EditText(Context context) 

Source Link

Usage

From source file:onion.chat.MainActivity.java

void changePassword() {
    final FrameLayout view = new FrameLayout(this);
    final EditText editText = new EditText(this);
    editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(32) });
    editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    editText.setSingleLine();//w  w w  .j  av  a 2s  .  c  om
    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PERSON_NAME
            | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
    view.addView(editText);
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());
    ;
    view.setPadding(padding, padding, padding, padding);
    editText.setText("");
    new AlertDialog.Builder(this).setTitle(R.string.password).setView(view)
            .setPositiveButton(R.string.apply, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    db.setPassword(editText.getText().toString().trim());
                    update();
                    //snack(getString(R.string.snack_alias_changed));
                    String toSpeak = "password changed successfully";
                    Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();

                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).show();
}

From source file:uk.co.senab.photoview.sample.ViewPagerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.item1:
        ////  w w w  . ja v a  2 s.co  m
        //
        //mViewPager.setCurrentItem((new PageProvider().getPageCount()-1));
        // 1. Instantiate an AlertDialog.Builder with its constructor

        String[] pages = new String[850];
        for (int i = 0; i < 850; i++) {
            pages[i] = i + 1 + "";
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(ViewPagerActivity.this);

        // 2. Chain together various setter methods to set the dialog characteristics
        builder.setTitle("Go To Page").setItems(pages, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                mViewPager.setCurrentItem(849 - which);

                // The 'which' argument contains the index position
                // of the selected item
            }
        });

        // 3. Get the AlertDialog from create()
        AlertDialog dialog = builder.create();
        dialog.show();
        return true;
    case R.id.item2:
        //
        //
        //mViewPager.setCurrentItem((new PageProvider().getPageCount()-1));
        // 1. Instantiate an AlertDialog.Builder with its constructor
        AlertDialog.Builder builder2 = new AlertDialog.Builder(ViewPagerActivity.this);

        String[] juz = getResources().getStringArray(R.array.juz);

        // 2. Chain together various setter methods to set the dialog characteristics
        builder2.setTitle("Go To Juz (Parah)").setItems(juz, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                if (which == 0) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 1);

                }
                if (which == 1) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 31);

                }
                if (which == 2) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 59);

                }
                if (which == 3) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 87);

                }
                if (which == 4) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 115);

                }
                if (which == 5) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 143);

                }
                if (which == 6) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 171);

                }
                if (which == 7) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 199);

                }
                if (which == 8) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 227);

                }
                if (which == 9) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 255);

                }
                if (which == 10) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 283);

                }
                if (which == 11) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 311);

                }
                if (which == 12) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 339);

                }
                if (which == 13) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 367);

                }
                if (which == 14) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 395);

                }
                if (which == 15) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 423);

                }
                if (which == 16) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 451);

                }
                if (which == 17) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 479);

                }
                if (which == 18) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 507);

                }
                if (which == 19) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 535);

                }
                if (which == 20) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 561);

                }
                if (which == 21) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 589);

                }
                if (which == 22) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 615);

                }
                if (which == 23) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 643);

                }
                if (which == 24) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 669);

                }
                if (which == 25) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 699);

                }
                if (which == 26) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 729);

                }
                if (which == 27) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 759);

                }
                if (which == 28) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 789);

                }
                if (which == 29) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 821);

                }

                // The 'which' argument contains the index position
                // of the selected item
            }
        });

        // 3. Get the AlertDialog from create()
        AlertDialog dialog2 = builder2.create();
        dialog2.show();
        return true;
    case R.id.item3:
        //
        //
        //mViewPager.setCurrentItem((new PageProvider().getPageCount()-1));
        // 1. Instantiate an AlertDialog.Builder with its constructor
        AlertDialog.Builder builder3 = new AlertDialog.Builder(ViewPagerActivity.this);

        String[] surah = getResources().getStringArray(R.array.surah);

        // 2. Chain together various setter methods to set the dialog characteristics
        builder3.setTitle("Go To Surah").setItems(surah, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                if (which == 0) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(620 - 4);
                }
                if (which == 1) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(620 - 5);
                }
                if (which == 2) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 70);
                }
                if (which == 3) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 108);
                }
                if (which == 4) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 149);
                }
                if (which == 5) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 179);
                }
                if (which == 6) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 211);
                }
                if (which == 7) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 247);
                }
                if (which == 8) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 262);
                }
                if (which == 9) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 290);
                }
                if (which == 10) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 310);
                }
                if (which == 11) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 330);
                }
                if (which == 12) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 348);
                }
                if (which == 13) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 357);
                }
                if (which == 14) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 366);
                }
                if (which == 15) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 374);
                }
                if (which == 16) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 390);
                }
                if (which == 17) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 410);
                }
                if (which == 18) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 427);
                }
                if (which == 19) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 437);
                }
                if (which == 20) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 451);
                }
                if (which == 21) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 464);
                }
                if (which == 22) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 479);
                }
                if (which == 23) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 489);
                }
                if (which == 24) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 503);
                }
                if (which == 25) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 513);
                }
                if (which == 26) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 527);
                }
                if (which == 27) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 539);
                }
                if (which == 28) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 554);
                }
                if (which == 29) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 564);
                }
                if (which == 30) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 573);
                }
                if (which == 31) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 579);
                }
                if (which == 32) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 583);
                }
                if (which == 33) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 597);
                }
                if (which == 34) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 605);
                }
                if (which == 35) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 613);
                }
                if (which == 36) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 620);
                }
                if (which == 37) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 630);
                }
                if (which == 38) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 637);
                }
                if (which == 39) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 649);
                }
                if (which == 40) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 661);
                }
                if (which == 41) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 670);
                }
                if (which == 42) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 679);
                }
                if (which == 43) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 688);
                }
                if (which == 44) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 693);
                }
                if (which == 45) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 699);
                }
                if (which == 46) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 706);
                }
                if (which == 47) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 712);
                }
                if (which == 48) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 718);
                }
                if (which == 49) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 723);
                }
                if (which == 50) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 728);
                }
                if (which == 51) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 731);
                }
                if (which == 52) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 734);
                }
                if (which == 53) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 738);
                }
                if (which == 54) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 742);
                }
                if (which == 55) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 747);
                }
                if (which == 56) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 752);
                }
                if (which == 57) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 759);
                }
                if (which == 58) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 763);
                }
                if (which == 59) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 768);
                }
                if (which == 60) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 772);
                }
                if (which == 61) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 775);
                }
                if (which == 62) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 777);
                }
                if (which == 63) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 779);
                }
                if (which == 64) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 782);
                }
                if (which == 65) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 785);
                }
                if (which == 66) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 789);
                }
                if (which == 67) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 792);
                }
                if (which == 68) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 796);
                }
                if (which == 69) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 799);
                }
                if (which == 70) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 802);
                }
                if (which == 71) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 805);
                }
                if (which == 72) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 808);
                }
                if (which == 73) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 810);
                }
                if (which == 74) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 813);
                }
                if (which == 75) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 815);
                }
                if (which == 76) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 818);
                }
                if (which == 77) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 821);
                }
                if (which == 78) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 822);
                }
                if (which == 79) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 824);
                }
                if (which == 80) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 826);
                }
                if (which == 81) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 827);
                }
                if (which == 82) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 828);
                }
                if (which == 83) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 830);
                }
                if (which == 84) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 831);
                }
                if (which == 85) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 832);
                }
                if (which == 86) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 833);
                }
                if (which == 87) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 834);
                }
                if (which == 88) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 835);
                }
                if (which == 89) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 837);
                }
                if (which == 90) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 838);
                }
                if (which == 91) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 839);
                }
                if (which == 92) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 840);
                }
                if (which == 93) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 840);
                }
                if (which == 94) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 841);
                }
                if (which == 95) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 841);
                }
                if (which == 96) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 842);
                }
                if (which == 97) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 842);
                }
                if (which == 98) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 843);
                }
                if (which == 99) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 844);
                }
                if (which == 100) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 845);
                }
                if (which == 101) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 845);
                }
                if (which == 102) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 846);
                }
                if (which == 103) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 846);
                }
                if (which == 104) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 846);
                }
                if (which == 105) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 847);
                }
                if (which == 106) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 847);
                }
                if (which == 107) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 848);
                }
                if (which == 108) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 848);
                }
                if (which == 109) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 848);
                }
                if (which == 110) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 849);
                }
                if (which == 111) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 849);
                }
                if (which == 112) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 849);
                }
                if (which == 113) {
                    dialog.dismiss();

                    mViewPager.setCurrentItem(850 - 850);
                }

                // The 'which' argument contains the index position
                // of the selected item
            }
        });

        // 3. Get the AlertDialog from create()
        AlertDialog dialog3 = builder3.create();
        dialog3.show();
        return true;
    case R.id.item4:
        Builder builderr = new Builder(this);
        Date cDate = new Date();
        final String fDate = new SimpleDateFormat("MM/dd/yy").format(cDate);
        Date dt = new Date();
        int hours = dt.getHours();
        int minutes = dt.getMinutes();

        SimpleDateFormat sdf = new SimpleDateFormat("hh:mmaa");
        String time1 = sdf.format(dt);

        final EditText input = new EditText(this);
        InputFilter[] FilterArray = new InputFilter[1];
        FilterArray[0] = new InputFilter.LengthFilter(18);
        input.setFilters(FilterArray);

        input.setText(fDate + " " + time1.toLowerCase());
        builderr.setTitle("Bookmark").setMessage("Name your Bookmark").setView(input)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {

                        if (!input.getText().toString().equals(""))
                            saveState(input.getText().toString());
                        else
                            saveState(fDate);
                        setResult(RESULT_OK);
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                    }

                });

        builderr.show();

        return true;
    case R.id.item5:
        Intent i = new Intent(ViewPagerActivity.this, Notepadv3.class);

        startActivity(i);
        return true;
    case R.id.item6:
        try {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:Qazi+Musab")));
        } catch (android.content.ActivityNotFoundException anfe) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://play.google.com/store/apps/developer?id=Qazi+Musab")));
        }
        return true;
    case R.id.item7:
        String appName2 = "com.qaziconsultancy.13linequran";
        try {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appName2)));
        } catch (android.content.ActivityNotFoundException anfe) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://play.google.com/store/apps/details?id=" + appName2)));
        }
        return true;
    case R.id.item8:
        mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1);
        return true;
    case R.id.item9:
        mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1);
        return true;
    case R.id.item10:
        String[] items = new String[9];
        items[0] = "$1";
        items[1] = "$2";
        items[2] = "$3";
        items[3] = "$4";
        items[4] = "$5";
        items[5] = "$10";
        items[6] = "$20";
        items[7] = "$50";
        items[8] = "$100";

        AlertDialog.Builder chooser = new AlertDialog.Builder(ViewPagerActivity.this);
        chooser.setTitle("Contribute").setItems(items, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                case 0:
                    contributeOneDollar();
                    break;
                case 1:
                    contributetwoDollars();
                    break;
                case 2:
                    contributeThreeDollars();
                    break;
                case 3:
                    contributeFourDollars();
                    break;
                case 4:
                    contributeFiveDollars();
                    break;
                case 5:
                    contributeTenDollars();
                    break;
                case 6:
                    contributeTwentyDollars();
                    break;
                case 7:
                    contributeFiftyDollars();
                    break;
                case 8:
                    contributeHundredDollars();
                    break;

                }
            }
        });

        // 3. Get the AlertDialog from create()
        AlertDialog myChooser = chooser.create();
        myChooser.show();
        return true;
    default:
        return true;
    }
}

From source file:nl.mpcjanssen.simpletask.Simpletask.java

private void renameSavedFilter(String prefsName) {
    final SharedPreferences filter_pref = getSharedPreferences(prefsName, MODE_PRIVATE);
    ActiveFilter old_filter = new ActiveFilter();
    old_filter.initFromPrefs(filter_pref);
    String filterName = old_filter.getName();
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle(R.string.rename_filter);
    alert.setMessage(R.string.rename_filter_message);

    // Set an EditText view to get user input
    final EditText input = new EditText(this);
    alert.setView(input);//from   w w w  . java 2s .c  o  m
    input.setText(filterName);

    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            Editable text = input.getText();
            String value;
            if (text == null) {
                value = "";
            } else {
                value = text.toString();
            }
            if (value.equals("")) {
                Util.showToastShort(getApplicationContext(), R.string.filter_name_empty);
            } else {
                mFilter.setName(value);
                mFilter.saveInPrefs(filter_pref);
                updateRightDrawer();
            }
        }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // Canceled.
        }
    });

    alert.show();
}

From source file:onion.chat.MainActivity.java

void changeName() {
    final FrameLayout view = new FrameLayout(this);
    final EditText editText = new EditText(this);
    editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(32) });
    editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    editText.setSingleLine();/*from w  ww. j a va  2 s.co m*/
    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PERSON_NAME
            | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
    view.addView(editText);
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());
    ;
    view.setPadding(padding, padding, padding, padding);
    editText.setText(db.getName());
    new AlertDialog.Builder(this).setTitle(R.string.title_change_alias).setView(view)
            .setPositiveButton(R.string.apply, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    db.setName(editText.getText().toString().trim());
                    update();
                    snack(getString(R.string.snack_alias_changed));
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).show();
}

From source file:com.piusvelte.taplock.client.core.TapLockSettings.java

protected void setPassphrase(final int deviceIdx) {
    final EditText fld_passphrase = new EditText(TapLockSettings.this);
    // parse the existing passphrase
    JSONObject deviceJObj = mDevices.get(deviceIdx);
    try {//from  w  ww . j a  v  a  2 s.c o m
        fld_passphrase.setText(deviceJObj.getString(KEY_PASSPHRASE));
    } catch (JSONException e) {
        Log.e(TAG, e.getMessage());
    }
    mDialog = new AlertDialog.Builder(TapLockSettings.this).setTitle("set passphrase").setView(fld_passphrase)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                    String passphrase = fld_passphrase.getText().toString();
                    JSONObject deviceJObj = mDevices.remove(deviceIdx);
                    try {
                        deviceJObj.put(KEY_PASSPHRASE, passphrase);
                    } catch (JSONException e) {
                        Log.e(TAG, e.getMessage());
                    }
                    mDevices.add(deviceIdx, deviceJObj);
                    if (mServiceInterface != null) {
                        try {
                            mServiceInterface.write(deviceJObj.getString(KEY_ADDRESS), ACTION_PASSPHRASE,
                                    passphrase);
                        } catch (RemoteException e) {
                            Log.e(TAG, e.getMessage());
                        } catch (JSONException e) {
                            Log.e(TAG, e.getMessage());
                        }
                    } else
                        storeDevices();
                }

            }).create();
    mDialog.show();
}

From source file:im.getsocial.testapp.MainActivity.java

private void loadCustomUiFromUrl() {
    final EditText urlTextView = new EditText(this);
    urlTextView.setHint("http://www.getsocial.im/ui.json");
    if (!DEFAULT_CUSTOM_UI_CONFIGURATION_URL.isEmpty()) {
        urlTextView.setText(DEFAULT_CUSTOM_UI_CONFIGURATION_URL);
    }/*from  ww w . java  2 s.c o m*/

    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
    builder.setTitle(R.string.ui_configuration_url);
    builder.setPositiveButton(R.string.load, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            String url = urlTextView.getText().toString();
            if (url != null && !url.isEmpty()) {
                getSocialUiConfiguration = url;
                GetSocial.getConfiguration().setConfiguration(url);
            }
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.setView(urlTextView);
    builder.show();
}

From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java

private void showMultiRenameDialog(final String multiPath) {
    AlertDialog.Builder builder = new AlertDialog.Builder(SubredditSelectActivity.this);
    final EditText nameInput = new EditText(SubredditSelectActivity.this);
    nameInput.setHint("new multi name");
    builder.setTitle("Rename Multi").setView(nameInput)
            .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override//from  w ww  .  java2s. c o m
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            }).setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                    new SubscriptionEditTask(SubscriptionEditTask.ACTION_MULTI_RENAME).execute(multiPath,
                            nameInput.getText().toString().replaceAll("\\s+", ""));
                }
            }).show();
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

@SuppressLint("InflateParams")
private void optionTemplate() {
    final int userId = Util.getUserId(Process.myUid());

    // Build view
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.template, null);
    final Spinner spTemplate = (Spinner) view.findViewById(R.id.spTemplate);
    Button btnRename = (Button) view.findViewById(R.id.btnRename);
    ExpandableListView elvTemplate = (ExpandableListView) view.findViewById(R.id.elvTemplate);

    // Template selector
    final SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item);
    spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    String defaultName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, "0",
            getString(R.string.title_default));
    spAdapter.add(defaultName);/*ww w . j a  v a  2  s  .c  o  m*/
    for (int i = 1; i <= 4; i++) {
        String alternateName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, Integer.toString(i),
                getString(R.string.title_alternate) + " " + i);
        spAdapter.add(alternateName);
    }
    spTemplate.setAdapter(spAdapter);

    // Template definition
    final TemplateListAdapter templateAdapter = new TemplateListAdapter(this, view, R.layout.templateentry);
    elvTemplate.setAdapter(templateAdapter);
    elvTemplate.setGroupIndicator(null);

    spTemplate.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            templateAdapter.notifyDataSetChanged();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            templateAdapter.notifyDataSetChanged();
        }
    });

    btnRename.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (Util.hasProLicense(ActivityMain.this) == null) {
                // Redirect to pro page
                Util.viewUri(ActivityMain.this, cProUri);
                return;
            }

            final int templateId = spTemplate.getSelectedItemPosition();
            if (templateId == AdapterView.INVALID_POSITION)
                return;

            AlertDialog.Builder dlgRename = new AlertDialog.Builder(spTemplate.getContext());
            dlgRename.setTitle(R.string.title_rename);

            final String original = (templateId == 0 ? getString(R.string.title_default)
                    : getString(R.string.title_alternate) + " " + templateId);
            dlgRename.setMessage(original);

            final EditText input = new EditText(spTemplate.getContext());
            dlgRename.setView(input);

            dlgRename.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String name = input.getText().toString();
                    if (TextUtils.isEmpty(name)) {
                        PrivacyManager.setSetting(userId, Meta.cTypeTemplateName, Integer.toString(templateId),
                                null);
                        name = original;
                    } else {
                        PrivacyManager.setSetting(userId, Meta.cTypeTemplateName, Integer.toString(templateId),
                                name);
                    }
                    spAdapter.remove(spAdapter.getItem(templateId));
                    spAdapter.insert(name, templateId);
                    spAdapter.notifyDataSetChanged();
                }
            });

            dlgRename.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing
                }
            });

            dlgRename.create().show();
        }
    });

    // Build dialog
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle(R.string.menu_template);
    alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
    alertDialogBuilder.setView(view);
    alertDialogBuilder.setPositiveButton(getString(R.string.msg_done), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Do nothing
        }
    });

    // Show dialog
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

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);/*  ww  w.  j  a v  a 2  s.  com*/
    }
    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:im.getsocial.testapp.MainActivity.java

private void submitValueToLb(final String leaderboardId) {
    final EditText dataTextView = new EditText(this);
    dataTextView.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
    dataTextView.setText(new Random().nextInt(1000) + "");

    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
    builder.setTitle(R.string.enter_your_score);
    builder.setPositiveButton(R.string.submit, new DialogInterface.OnClickListener() {
        @Override/* w w  w .  ja  v  a  2  s.co m*/
        public void onClick(DialogInterface dialogInterface, int i) {
            String data = dataTextView.getText().toString();
            if (data != null && !data.isEmpty()) {
                try {
                    final int value = Integer.valueOf(data);
                    getSocial.submitLeaderboardScore(leaderboardId, value,
                            new GetSocial.OnOperationResultListener<Integer>() {
                                @Override
                                public void onSuccess(Integer newRank) {
                                    logInfoAndToast(String.format("Submitted score %s to LB '%s', new rank: %s",
                                            value, leaderboardId, newRank));
                                }

                                @Override
                                public void onFailure(Exception exception) {
                                    logErrorAndToast(
                                            String.format("Failed to submit score %s to LB '%s', error: %s",
                                                    value, leaderboardId, exception.getMessage()));
                                }
                            });
                } catch (Exception e) {
                    logErrorAndToast("Failed to submit score, error: " + e.getMessage());
                }
            }
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.setView(dataTextView);
    builder.show();
}