List of usage examples for android.app AlertDialog getButton
public Button getButton(int whichButton)
From source file:com.cloudant.todo.TodoActivity.java
public Dialog createNewTaskDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); View v = this.getLayoutInflater().inflate(R.layout.dialog_new_task, null); final EditText description = (EditText) v.findViewById(R.id.new_task_desc); // Check description is present, if so add a task otherwise show an error DialogInterface.OnClickListener positiveClick = new DialogInterface.OnClickListener() { @Override//from ww w . j a va 2s . co m public void onClick(DialogInterface dialog, int id) { if (description.getText().length() > 0) { createNewTask(description.getText().toString()); description.getText().clear(); } else { Toast.makeText(getApplicationContext(), R.string.task_not_created, Toast.LENGTH_LONG).show(); } } }; DialogInterface.OnClickListener negativeClick = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }; builder.setView(v).setTitle(R.string.new_task).setPositiveButton(R.string.create, positiveClick) .setNegativeButton(R.string.cancel, negativeClick); final AlertDialog d = builder.create(); // Enable "Create" button when the description has some characters final TextWatcher textWatcher = new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { final Button b = d.getButton(DialogInterface.BUTTON_POSITIVE); b.setEnabled(description.getText().length() > 0); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }; d.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { final Button b = d.getButton(DialogInterface.BUTTON_POSITIVE); b.setEnabled(description.getText().length() > 0); description.addTextChangedListener(textWatcher); } }); return d; }
From source file:com.tnc.android.graphite.activities.GraphActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // TODO move to controller switch (item.getItemId()) { case R.id.graph_menu_reload: controller.handleMessage(GraphController.MESSAGE_RELOAD); break;/*from w w w.j a v a 2 s .c o m*/ case R.id.graph_menu_auto_refresh: controller.handleMessage(GraphController.MESSAGE_AUTO_REFRESH_DIALOG); break; case R.id.graph_menu_edit: layout.closeDrawers(); Intent editIntent = new Intent(this, EditActivity.class); startActivityForResult(editIntent, GraphController.ACTIVITY_EDIT_GRAPHS); break; case R.id.graph_menu_save: final EditText input = new EditText(this); final AlertDialog saveDialog = new AlertDialog.Builder(this).setTitle(R.string.save_dialog_title) .setView(input).setPositiveButton(R.string.dialog_positive, null) .setNegativeButton(R.string.dialog_negative, null).create(); saveDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button b = saveDialog.getButton(AlertDialog.BUTTON_POSITIVE); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String value = input.getText().toString(); if (!value.equals("")) { controller.handleMessage(GraphController.MESSAGE_SAVE_GRAPH, value); saveDialog.dismiss(); } } }); } }); saveDialog.show(); break; default: return super.onOptionsItemSelected(item); } return true; }
From source file:edu.rutgers.winlab.crowdpp.ui.MainActivity.java
public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // exit the app case R.id.exit: Toast.makeText(this, "Closing...", Toast.LENGTH_SHORT).show(); //System.exit(0); this.finish(); break;/* w ww. ja va2 s . c om*/ // show the FAQ case R.id.help: AlertDialog dialog = new AlertDialog.Builder(this).create(); dialog.setTitle("FAQ"); dialog.setMessage(Constants.FAQ); dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Close", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.show(); dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextSize(20); break; default: return super.onOptionsItemSelected(item); } return true; }
From source file:id.satusatudua.sigap.ui.EmergencyActivity.java
@OnClick(R.id.button_i_am_save) public void iAmSave() { AlertDialog alertDialog = new AlertDialog.Builder(this).setIcon(R.mipmap.ic_launcher) .setTitle("Klarifikasi").setMessage("Apakah kamu yakin kamu telah selamat?") .setPositiveButton("YA, Saya Selamat", (dialog, which) -> { startActivity(/*from w w w. ja va 2 s . c o m*/ CloseCaseActivity.generateIntent(this, presenter.getTheCase(), presenter.getHelpers())); dialog.dismiss(); }).setNegativeButton("TIDAK", (dialog, which1) -> { dialog.dismiss(); }).show(); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(this, R.color.colorPrimary)); alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE) .setTextColor(ContextCompat.getColor(this, R.color.primary_text)); alertDialog.show(); }
From source file:de.spiritcroc.ownlog.ui.fragment.ExportDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { View progressView = getActivity().getLayoutInflater().inflate(R.layout.dialog_progess_indeterminate, null); mMessage = progressView.findViewById(R.id.progress_message); mMessage.setText(R.string.export_dialog_message); mProgressBar = progressView.findViewById(R.id.progress_bar); mProgressBar.setVisibility(View.GONE); setCancelable(false);/*from w w w .j a v a 2 s .c om*/ final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.export_dialog_title).setView(progressView) .setPositiveButton(R.string.dialog_ok, null) .setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Only close dialog } }).create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PasswdHelper.getWritableDatabase(getActivity(), ExportDialog.this, DB_REQUEST_EXPORT); } }); } }); return alertDialog; }
From source file:edu.rutgers.winlab.crowdpp.ui.MainActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity_layout); // Create the adapter that will return a fragment for each of the three primary sections of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); // Set up the action bar. final ActionBar actionBar = getActionBar(); // Specify that the Home/Up button should not be enabled, since there is no hierarchical parent. actionBar.setHomeButtonEnabled(false); // Specify that we will be displaying tabs in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Set up the ViewPager, attaching the adapter and setting up a listener for when the user swipes between sections. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override/* w w w . j a v a 2 s . co m*/ public void onPageSelected(int position) { // When swiping between different app sections, select the corresponding tab. // We can also use ActionBar.Tab#select() to do this if we have a reference to the Tab. actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) { // Create a tab with text corresponding to the page title defined by the adapter. // Also specify this Activity object, which implements the TabListener interface, as the listener for when this tab is selected. actionBar.addTab( actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } SharedPreferences settings = this.getSharedPreferences("config", Context.MODE_PRIVATE); ; SharedPreferences.Editor editor = settings.edit(); // load the default parameters into SharedPreferences for the first time launch int ct = settings.getInt("count", 0); if (ct == 0) { editor.putString("start", "9"); editor.putString("end", "21"); editor.putString("interval", "15"); editor.putString("duration", "5"); editor.putString("location", "On"); editor.putString("upload", "On"); TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); editor.putString("IMEI", tm.getDeviceId()); editor.putString("brand", Build.BRAND); editor.putString("model", Build.MODEL); String phone_type = Build.BRAND + "_" + Build.MODEL; // motoX if (phone_type.equals("motorola_XT1058")) { editor.putString("mfcc_dist_same_semi", "13"); editor.putString("mfcc_dist_diff_semi", "18"); editor.putString("mfcc_dist_same_un", "13"); editor.putString("mfcc_dist_diff_un", "18"); } // nexus 4 else if (phone_type.equals("google_Nexus 4")) { editor.putString("mfcc_dist_same_semi", "17"); editor.putString("mfcc_dist_diff_semi", "22"); editor.putString("mfcc_dist_same_un", "17"); editor.putString("mfcc_dist_diff_un", "22"); } // s2 else if (phone_type.equals("samsung_SAMSUNG-SGH-I727")) { editor.putString("mfcc_dist_same_semi", "18"); editor.putString("mfcc_dist_diff_semi", "25"); editor.putString("mfcc_dist_same_un", "18"); editor.putString("mfcc_dist_diff_un", "25"); } // s3 else if (phone_type.equals("samsung_SAMSUNG-SGH-I747")) { editor.putString("mfcc_dist_same_semi", "16"); editor.putString("mfcc_dist_diff_semi", "21"); editor.putString("mfcc_dist_same_un", "16"); editor.putString("mfcc_dist_diff_un", "21"); } // s4 else if (phone_type.equals("samsung_SAMSUNG-SGH-I337")) { editor.putString("mfcc_dist_same_semi", "14"); editor.putString("mfcc_dist_diff_semi", "24"); editor.putString("mfcc_dist_same_un", "14"); editor.putString("mfcc_dist_diff_un", "24"); } // other devices else { editor.putString("mfcc_dist_same_semi", "15.6"); editor.putString("mfcc_dist_diff_semi", "21.6"); editor.putString("mfcc_dist_same_un", "15.6"); editor.putString("mfcc_dist_diff_un", "21.6"); Toast.makeText(this, "Your device is not recognized and the result might not be accurate...", Toast.LENGTH_SHORT).show(); } Log.i("Crowd++", "First time launched"); AlertDialog dialog = new AlertDialog.Builder(this).create(); dialog.setTitle("Welcome to Crowd++"); dialog.setMessage(Constants.hello_msg); dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Close", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); dialog.show(); dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextSize(20); } editor.putInt("count", ++ct); editor.commit(); Log.i("Launched Count", Integer.toString(ct)); mConst = new Constants(this); if (!Constants.calibration()) Toast.makeText(this, "You haven't calibrated the system.", Toast.LENGTH_SHORT).show(); }
From source file:com.brewcrewfoo.performance.fragments.Tools.java
@Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { final String key = preference.getKey(); if (key.equals(PREF_SH)) { Resources res = context.getResources(); String cancel = res.getString(R.string.cancel); String ok = res.getString(R.string.ps_volt_save); LayoutInflater factory = LayoutInflater.from(context); final View alphaDialog = factory.inflate(R.layout.sh_dialog, null); settingText = (EditText) alphaDialog.findViewById(R.id.shText); settingText.setHint(R.string.sh_msg); settingText.setText(mPreferences.getString(key, "")); settingText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override//www.j a v a 2 s . c o m public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { return true; } }); new AlertDialog.Builder(context).setTitle(getString(R.string.sh_title)).setView(alphaDialog) .setNegativeButton(cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { /* nothing */ } }).setPositiveButton(ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final SharedPreferences.Editor editor = mPreferences.edit(); editor.putString(key, settingText.getText().toString()).commit(); } }).create().show(); } else if (key.equals(PREF_WIPE_CACHE)) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(getString(R.string.wipe_cache_title)).setMessage(getString(R.string.wipe_cache_msg)) .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); //alertDialog.setCancelable(false); Button theButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); theButton.setOnClickListener(new opListener(alertDialog, 0)); } else if (key.equals(FLASH_KERNEL)) { Intent flash = new Intent(context, FlasherActivity.class); flash.putExtra("mod", "kernel"); startActivity(flash); } else if (key.equals(RESIDUAL_FILES)) { Intent intent = new Intent(context, ResidualsActivity.class); startActivity(intent); } else if (key.equals(PREF_FIX_PERMS)) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(getString(R.string.fix_perms_title)).setMessage(getString(R.string.fix_perms_msg)) .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); //alertDialog.setCancelable(false); Button theButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); theButton.setOnClickListener(new opListener(alertDialog, 1)); } else if (key.equals(PREF_OPTIM_DB)) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(getString(R.string.optim_db_title)) .setMessage(getString(R.string.ps_optim_db) + "\n\n" + getString(R.string.fix_perms_msg)) .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); //alertDialog.setCancelable(false); Button theButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); theButton.setOnClickListener(new opListener(alertDialog, 2)); } else if (key.equals(PREF_FRREZE)) { Intent intent = new Intent(context, FreezerActivity.class); intent.putExtra("freeze", true); intent.putExtra("packs", "usr"); startActivity(intent); } else if (key.equals(PREF_UNFRREZE)) { Intent intent = new Intent(context, FreezerActivity.class); intent.putExtra("freeze", false); startActivity(intent); } else if (key.equals("pref_build_prop")) { Intent intent = new Intent(context, BuildPropEditor.class); startActivity(intent); } else if (key.equals("pref_sysctl")) { Intent intent = new Intent(context, SysctlEditor.class); startActivity(intent); } else if (key.equals("pref_logcat")) { Date now = new Date(); nf = "/logcat_" + formatter.format(now) + ".txt"; AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(getString(R.string.logcat_title)).setMessage(getString(R.string.logcat_msg, dn + nf)) .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); //alertDialog.setCancelable(false); Button theButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); theButton.setOnClickListener(new opListener(alertDialog, 3)); } else if (key.equals("pref_dmesg")) { Date now = new Date(); nf = "/dmesg_" + formatter.format(now) + ".txt"; AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(getString(R.string.dmesg_title)).setMessage(getString(R.string.dmesg_msg, dn + nf)) .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); //alertDialog.setCancelable(false); Button theButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE); theButton.setOnClickListener(new opListener(alertDialog, 4)); } return super.onPreferenceTreeClick(preferenceScreen, preference); }
From source file:id.satusatudua.sigap.ui.fragment.SettingFragment.java
@OnClick(R.id.feedback) public void onFeedbackClick() { EditText editText = new EditText(getActivity()); editText.setHint("Feedback"); editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE); AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setIcon(R.mipmap.ic_launcher) .setTitle("Kirim Feedback").setView(editText).setPositiveButton("Kirim", (dialog, which) -> { if (!editText.getText().toString().isEmpty()) { sendFeedBack(editText.getText().toString()); KeyboardUtil.hideKeyboard(getActivity(), editText); dialog.dismiss();//from w w w. j a va2 s .c o m } }).setNegativeButton("Batal", (dialog, which1) -> { dialog.dismiss(); }).show(); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary)); alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE) .setTextColor(ContextCompat.getColor(getActivity(), R.color.primary_text)); alertDialog.show(); }
From source file:id.satusatudua.sigap.ui.AddTrustedUserActivity.java
private void removeTrustedUser(UserTrusted userTrusted) { AlertDialog alertDialog = new AlertDialog.Builder(this).setIcon(R.mipmap.ic_launcher) .setTitle(R.string.app_name) .setMessage("Apakah anda ingin menghapus " + userTrusted.getUser().getName() + " dari daftar kontak terpercaya anda?") .setPositiveButton("YA, Hapus Dia", (dialog, which) -> { presenter.removeTrustedUser(userTrusted); dialog.dismiss();//w w w . j av a 2 s . c om }).setNegativeButton("TIDAK", (dialog, which1) -> { dialog.dismiss(); }).show(); alertDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(this, R.color.colorPrimary)); alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE) .setTextColor(ContextCompat.getColor(this, R.color.primary_text)); alertDialog.show(); }
From source file:de.spiritcroc.ownlog.ui.fragment.LogFilterEditFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); AlertDialog.Builder builder = new AlertDialog.Builder(activity); final View view = activity.getLayoutInflater().inflate(R.layout.log_filter_edit_item, null); mEditName = (EditText) view.findViewById(R.id.name_edit); mSpinSortOrder = (Spinner) view.findViewById(R.id.sort_order_spin); mCheckStrictFilterTags = (CheckBox) view.findViewById(R.id.tags_strict_check); mStrictFilterTagsInfoNoTags = view.findViewById(R.id.text_view_tags_strict_no_tags); mStrictFilterTagsInfoTags = view.findViewById(R.id.text_view_tags_strict_tags); mEditTagsView = (EditTagsView) view.findViewById(R.id.edit_tags_view); mEditTagsView.setTagsProvider(mTagsProvider); mEditTagsView.setAvailableTagsFilter(mAvailableTagsFilter); mEditExcludedTagsView = (EditTagsView) view.findViewById(R.id.edit_excluded_tags_view); mEditExcludedTagsView.setTagsProvider(mExcludedTagsProvider); mEditExcludedTagsView.setAvailableTagsFilter(mAvailableTagsFilter); View.OnClickListener strictFilterInfoClickListener = new View.OnClickListener() { @Override// w ww . j ava 2s . com public void onClick(View view) { mCheckStrictFilterTags.toggle(); } }; mStrictFilterTagsInfoNoTags.setOnClickListener(strictFilterInfoClickListener); mStrictFilterTagsInfoTags.setOnClickListener(strictFilterInfoClickListener); mSortOrderValues = getResources().getStringArray(R.array.edit_log_filter_sort_order_values); mSpinSortOrder.setAdapter(ArrayAdapter.createFromResource(activity, R.array.edit_log_filter_sort_order_entries, R.layout.support_simple_spinner_dropdown_item)); mSpinSortOrder.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { mSortOrder = i; } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); mInitName = getString(R.string.log_filter_default_new_name); mInitSortOrder = mSortOrderValues[0]; boolean restoredValues = restoreValues(savedInstanceState); builder.setTitle(mAddItem ? R.string.title_log_filter_add : R.string.title_log_filter_edit).setView(view) .setPositiveButton(R.string.dialog_ok, null) .setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Only dismiss } }); if (!mAddItem) { builder.setNeutralButton(R.string.dialog_delete, null); } final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { saveChanges(); } }); if (!mAddItem) { alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { promptDelete(); } }); } } }); if (!restoredValues) { loadContent(); if (mAddItem) { initValues(alertDialog); } } return alertDialog; }