List of usage examples for android.app AlertDialog setOnShowListener
public void setOnShowListener(@Nullable OnShowListener listener)
From source file:org.akvo.caddisfly.ui.activity.MainActivity.java
@Override public void onLoadCalibration(final Handler.Callback callback) { final Context context = this; final MainApp mainApp = (MainApp) this.getApplicationContext(); try {/*www . j a v a2 s.co m*/ AlertDialog.Builder builderSingle = new AlertDialog.Builder(context); builderSingle.setIcon(R.drawable.ic_launcher); builderSingle.setTitle(R.string.loadCalibration); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(context, android.R.layout.select_dialog_singlechoice); File external = Environment.getExternalStorageDirectory(); final String folderName = Config.CALIBRATE_FOLDER_NAME; String path = external.getPath() + folderName; File folder = new File(path); if (folder.exists()) { final File[] listFiles = folder.listFiles(); for (File listFile : listFiles) { arrayAdapter.add(listFile.getName()); } builderSingle.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String fileName = listFiles[which].getName(); final ArrayList<Integer> swatchList = new ArrayList<Integer>(); final ArrayList<String> rgbList = FileUtils.loadFromFile(fileName); if (rgbList != null) { for (String rgb : rgbList) { swatchList.add(ColorUtils.getColorFromRgb(rgb)); } (new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { mainApp.saveCalibratedSwatches(mainApp.currentTestInfo.getCode(), swatchList); mainApp.setSwatches(mainApp.currentTestInfo.getCode()); SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context); SharedPreferences.Editor editor = sharedPreferences.edit(); for (int i = 0; i < mainApp.rangeIntervals.size(); i++) { int index = i * mainApp.rangeIncrementStep; ColorUtils.autoGenerateColors(index, mainApp.currentTestInfo.getCode(), mainApp.colorList, mainApp.rangeIncrementStep, editor, 0); } editor.apply(); return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); callback.handleMessage(null); } }).execute(); } } }); final AlertDialog alert = builderSingle.create(); alert.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { final ListView listView = alert.getListView(); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { final int position = i; AlertUtils.askQuestion(context, R.string.delete, R.string.selectedWillBeDeleted, new DialogInterface.OnClickListener() { @SuppressWarnings("unchecked") @Override public void onClick(DialogInterface dialogInterface, int i) { String fileName = listFiles[position].getName(); FileUtils.deleteFile(folderName, fileName); ArrayAdapter listAdapter = (ArrayAdapter) listView.getAdapter(); listAdapter.remove(listAdapter.getItem(position)); } }); return true; } }); } }); alert.show(); } else { AlertUtils.showMessage(context, R.string.notFound, R.string.noSavedCalibrations); } } catch (ActivityNotFoundException e) { AlertUtils.showMessage(context, R.string.error, R.string.updateRequired); } callback.handleMessage(null); }
From source file:com.example.emachine.FXcalcActivity.java
private void textDialog(String title, String dialogtext) { // get prompts.xml view String returnString = ""; hideKeyboard();/*from www .ja v a 2 s .c o m*/ LayoutInflater li = LayoutInflater.from(getBaseContext()); View promptsView = li.inflate(R.layout.alertdialog_sysmsg_dialog, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); // set prompts.xml to alertdialog builder alertDialogBuilder.setView(promptsView); final EditText userInput = (EditText) promptsView.findViewById(R.id.editTextDialogUserInput); TextView tv_custom_dialog_title = (TextView) promptsView.findViewById(R.id.tv_custom_dialog_title); TextView tv_text_dialog = (TextView) promptsView.findViewById(R.id.tv_text_dialog); // ImageView iv_image = (ImageView) promptsView.findViewById(R.id.iv_image); tv_custom_dialog_title.setText(title); tv_text_dialog.setText(dialogtext); // set dialog message alertDialogBuilder.setCancelable(true).setPositiveButton("Good one", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // EspressoMachine_AlertDialogButtonClicked("Good one", TAG); alert("You have chosen, Wisely. "); Intent intent = new Intent(getBaseContext(), FieldOfFieldsActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { startActivity(intent); } dialog.cancel(); } }) // public void onClick(DialogInterface dialog, int id) { EspressoAlertDialogButtonClicked(); // // get user input and set it to result // // edit text // if (!userInput.getText().toString().equals("demo") && userInput.getText().toString().equals(getprefPassword(getBaseContext()))) { // // } else { alert("Password incorrect");} // // } // }) // .setNeutralButton("Gallery", new DialogInterface.OnClickListener() { // public void onClick(DialogInterface dialog, int id) { EspressoAlertDialogButtonClicked(); // // get user input and set it to result // // edit text // if (!userInput.getText().toString().equals("demo") && userInput.getText().toString().equals(getprefPassword(getBaseContext()))) { // // } else { alert("Password incorrect");} // // } // }) .setNegativeButton("BAD QA", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // EspressoMachine_AlertDialogButtonClicked("Bad QA", TAG); alert("You have chosen, Poorly! "); dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(final DialogInterface dialog) { Button negativeButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEGATIVE); Button positiveButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE); Button neutralButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEUTRAL); // this not working because multiplying white background (e.g. Holo Light) has no effect //negativeButton.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY); // final Drawable negativeButtonDrawable = getResources().getDrawable(R.color.btn_background); final Drawable positiveButtonDrawable = getResources().getDrawable(R.color.btn_background); // final Drawable neutralButtonDrawable = getResources().getDrawable(R.color.btn_background); // negativeButton.setBackground(negativeButtonDrawable); // positiveButton.setBackground(positiveButtonDrawable); // neutralButton.setBackground(neutralButtonDrawable); } }); }
From source file:org.cloudfoundry.android.cfdroid.services.ServiceEditDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { LayoutInflater inflater = LayoutInflater.from(getActivity()); final View v = inflater.inflate(R.layout.service_edit, null); choices = (Spinner) v.findViewById(R.id.type); name = (EditText) v.findViewById(R.id.name); getLoaderManager().initLoader(0, null, this); name.setOnEditorActionListener(new OnEditorActionListener() { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == IME_ACTION_DONE && ready()) { createService();/*from w w w.ja v a 2 s .co m*/ return true; } return false; } }); name.addTextChangedListener(new BaseTextWatcher() { @Override public void afterTextChanged(Editable s) { updateEnablement(); } }); final AlertDialog dialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.edit_service_dialog_title).setView(v).setCancelable(true) .setPositiveButton(R.string.create, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); createService(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).create(); // workaround for http://code.google.com/p/android/issues/detail?id=6360 // ... dialog.setOnShowListener(new OnShowListener() { @Override public void onShow(DialogInterface di) { okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE); updateEnablement(); } }); return dialog; }
From source file:ar.rulosoft.mimanganu.PreferencesFragment.java
@Override public void onCreatePreferences(Bundle bundle, String s) { addPreferencesFromResource(R.xml.fragment_preferences); ColorListDialogPref primaryColor = (ColorListDialogPref) getPreferenceManager().findPreference("primario"); primaryColor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override/*w w w . j a v a 2 s . c o m*/ public boolean onPreferenceChange(Preference preference, Object o) { ((MainActivity) getActivity()).setColorToBars(); return false; } }); PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference("account"); ServerBase[] servers = ServerBase.getServers(getContext()); for (final ServerBase sb : servers) { if (sb.needLogin()) { SwitchPreferenceCompat preference = new SwitchPreferenceCompat(getContext()); preference.setTitle(sb.getServerName()); preference.setSelectable(true); preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { new LoginDialog(getContext(), sb).show(); return false; } }); preferenceGroup.addPreference(preference); } } /** Once, create necessary Data */ prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); final String current_filepath = prefs.getString("directorio", Environment.getExternalStorageDirectory().getAbsolutePath()) + "/MiMangaNu/"; /** This enables to hide downloaded images from gallery, just a toggle */ final SwitchPreferenceCompat cBoxPref = (SwitchPreferenceCompat) getPreferenceManager() .findPreference("mostrar_en_galeria"); cBoxPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { boolean have_noMedia = (Boolean) newValue; if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) { File mimaFolder = new File(current_filepath, ".nomedia"); if (have_noMedia) { try { mimaFolder.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } else { if (mimaFolder.exists()) { mimaFolder.delete(); } } } return true; } }); /** Set summary for Reader preference + seamless chapter transitions summary **/ // true: Paged Reader; false: Continuous Reader Boolean readType = prefs.getBoolean("reader_type", false); Preference reader_type = getPreferenceManager().findPreference("reader_type"); Preference seamlessChapterTransitionsPref = getPreferenceManager() .findPreference("seamless_chapter_transitions"); if (readType) { reader_type.setTitle(getString(R.string.paged_reader)); seamlessChapterTransitionsPref .setSummary(getString(R.string.seamless_chapter_transitions_paged_reader_subtitle)); } else { reader_type.setTitle(getString(R.string.continuous_reader)); seamlessChapterTransitionsPref .setSummary(getString(R.string.seamless_chapter_transitions_continuous_reader_subtitle)); } final SwitchPreferenceCompat readerTypePref = (SwitchPreferenceCompat) getPreferenceManager() .findPreference("reader_type"); readerTypePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); Boolean readType = prefs.getBoolean("reader_type", false); Preference reader_type = getPreferenceManager().findPreference("reader_type"); Preference seamlessChapterTransitions = getPreferenceManager() .findPreference("seamless_chapter_transitions"); if (!readType) { reader_type.setTitle(getString(R.string.paged_reader)); seamlessChapterTransitions .setSummary(getString(R.string.seamless_chapter_transitions_paged_reader_subtitle)); } else { reader_type.setTitle(getString(R.string.continuous_reader)); seamlessChapterTransitions.setSummary( getString(R.string.seamless_chapter_transitions_continuous_reader_subtitle)); } return true; } }); /** enable / disable seamless_chapter_transitions_delete_read depending on the state of seamless_chapter_transitions **/ Preference seamlessChapterTransitionsDeleteReadPreference = getPreferenceManager() .findPreference("seamless_chapter_transitions_delete_read"); if (prefs.getBoolean("seamless_chapter_transitions", false)) { seamlessChapterTransitionsDeleteReadPreference.setEnabled(true); } else { seamlessChapterTransitionsDeleteReadPreference.setEnabled(false); } final SwitchPreferenceCompat seamlessChapterTransitionsSPC = (SwitchPreferenceCompat) getPreferenceManager() .findPreference("seamless_chapter_transitions"); seamlessChapterTransitionsSPC.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); Preference seamlessChapterTransitionsDeleteReadPreference = getPreferenceManager() .findPreference("seamless_chapter_transitions_delete_read"); if (!prefs.getBoolean("seamless_chapter_transitions", false)) { seamlessChapterTransitionsDeleteReadPreference.setEnabled(true); } else { seamlessChapterTransitionsDeleteReadPreference.setEnabled(false); SharedPreferences.Editor prefEdit = prefs.edit(); prefEdit.putBoolean("seamless_chapter_transitions_delete_read", false); prefEdit.apply(); } return true; } }); Preference autoImportPath = getPreferenceManager().findPreference("auto_import_path"); /** enable / disable auto_import_path depending on the state of auto_import **/ if (prefs.getBoolean("auto_import", false)) { autoImportPath.setEnabled(true); } else { autoImportPath.setEnabled(false); } final SwitchPreferenceCompat autoImportSPC = (SwitchPreferenceCompat) getPreferenceManager() .findPreference("auto_import"); autoImportSPC.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); Preference autoImportPath = getPreferenceManager().findPreference("auto_import_path"); if (!prefs.getBoolean("auto_import", false)) { autoImportPath.setEnabled(true); } else { autoImportPath.setEnabled(false); } return true; } }); /** This sets the download threads (parallel downloads) */ final SeekBarCustomPreference listPreferenceDT = (SeekBarCustomPreference) getPreferenceManager() .findPreference("download_threads"); listPreferenceDT.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int threads = (int) newValue; int antes = DownloadPoolService.SLOTS; DownloadPoolService.SLOTS = threads; if (DownloadPoolService.actual != null) DownloadPoolService.actual.slots += (threads - antes); return true; } }); /** This sets the maximum number of errors to tolerate */ final SeekBarCustomPreference listPrefET = (SeekBarCustomPreference) getPreferenceManager() .findPreference("error_tolerancia"); listPrefET.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { ChapterDownload.MAX_ERRORS = (int) newValue; return true; } }); /** This sets the number of retries to fetch images */ SeekBarCustomPreference listPrefRT = (SeekBarCustomPreference) getPreferenceManager() .findPreference("reintentos"); listPrefRT.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { SingleDownload.RETRY = (int) newValue; return true; } }); /** This sets the Update Interval of the mangas (i.e. once per week) */ final ListPreference listPrefCU = (ListPreference) getPreferenceManager().findPreference("update_interval"); listPrefCU.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { long time = Long.parseLong((String) newValue); if (time > 0) { AlarmReceiver.setAlarms(getActivity().getApplicationContext(), System.currentTimeMillis() + time, time); } else { AlarmReceiver.stopAlarms(getActivity().getApplicationContext()); } if (time < 0) MainActivity.coldStart = false; return true; } }); /** This is for Custom language selection */ final ListPreference listPrefBatotoLang = (ListPreference) getPreferenceManager() .findPreference("batoto_lang_selection"); listPrefBatotoLang.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (newValue.equals("Custom")) { LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rootView = inflater.inflate(R.layout.batoto_custom_lang_dialog, null); final EditText CustomLang = (EditText) rootView.findViewById(R.id.txtCustomLang); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext()); dialogBuilder.setTitle("Custom language"); dialogBuilder.setView(rootView); dialogBuilder.setPositiveButton("Ok", null); dialogBuilder.setNegativeButton("Cancel", null); AlertDialog dialog = dialogBuilder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(final DialogInterface dialog) { Button accept = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); accept.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { prefs.edit().putString("batoto_custom_lang", CustomLang.getText().toString()) .apply(); Util.getInstance().toast(getContext(), "Custom Language: " + CustomLang.getText().toString()); dialog.dismiss(); } }); Button cancel = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); } }); } }); dialog.show(); } return true; } }); /** This sets the Version Number, that's all */ final Preference prefAbout = getPreferenceManager().findPreference("about_text"); prefAbout.setSummary("v" + BuildConfig.VERSION_NAME); /** This will check how much storage is taken by the mangas */ new calcStorage().execute(current_filepath); final Preference prefLicense = getPreferenceManager().findPreference("license_view"); prefLicense.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { ((MainActivity) getActivity()).replaceFragment(new LicenseFragment(), "licence_fragment"); return false; } }); final SwitchPreferenceCompat onlyWifiUpdateSwitch = (SwitchPreferenceCompat) getPreferenceManager() .findPreference("update_only_wifi"); SwitchPreferenceCompat onlyWifiSwitch = (SwitchPreferenceCompat) getPreferenceManager() .findPreference("only_wifi"); onlyWifiSwitch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object o) { NetworkUtilsAndReceiver.ONLY_WIFI = (Boolean) o; NetworkUtilsAndReceiver.connectionStatus = NetworkUtilsAndReceiver.ConnectionStatus.UNCHECKED; onlyWifiUpdateSwitch.setEnabled(!(Boolean) o); return true; } }); if (onlyWifiSwitch.isChecked()) { onlyWifiUpdateSwitch.setEnabled(false); } else { onlyWifiUpdateSwitch.setEnabled(true); } final SeekBarCustomPreference seekBarConnectionTimeout = (SeekBarCustomPreference) getPreferenceManager() .findPreference("connection_timeout"); seekBarConnectionTimeout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Navigator.connectionTimeout = Integer.parseInt(prefs.getString("connection_timeout", "10")); return true; } }); final SeekBarCustomPreference seekBarWriteTimeout = (SeekBarCustomPreference) getPreferenceManager() .findPreference("write_timeout"); seekBarWriteTimeout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Navigator.writeTimeout = Integer.parseInt(prefs.getString("write_timeout", "10")); return true; } }); final SeekBarCustomPreference seekBarReadTimeout = (SeekBarCustomPreference) getPreferenceManager() .findPreference("read_timeout"); seekBarReadTimeout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Navigator.readTimeout = Integer.parseInt(prefs.getString("read_timeout", "30")); return true; } }); Preference gridColumnsPref = getPreferenceManager().findPreference("grid_columns"); if (prefs.getBoolean("grid_columns_automatic_detection", true)) { gridColumnsPref.setEnabled(false); } else { gridColumnsPref.setEnabled(true); } final SwitchPreferenceCompat gridColumnsAutomaticDetectionSPC = (SwitchPreferenceCompat) getPreferenceManager() .findPreference("grid_columns_automatic_detection"); gridColumnsAutomaticDetectionSPC.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); Preference gridColumns = getPreferenceManager().findPreference("grid_columns"); if (prefs.getBoolean("grid_columns_automatic_detection", true)) { gridColumns.setEnabled(true); } else { gridColumns.setEnabled(false); } return true; } }); final Preference prefClearCache = getPreferenceManager().findPreference("clear_cache"); prefClearCache.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Preference clearCache = getPreferenceManager().findPreference("clear_cache"); clearCache.setEnabled(false); Thread t0 = new Thread(new Runnable() { @Override public void run() { new FileCache(getActivity()).clearCache(); } }); Thread t1 = new Thread(new Runnable() { @Override public void run() { Util.getInstance().createNotificationWithProgressbar(getContext(), 69, getString(R.string.deleting_empty_directories), ""); Util.getInstance().deleteEmptyDirectoriesRecursive(new File(current_filepath)); Util.getInstance().cancelNotification(69); } }); t0.start(); t1.start(); return true; } }); final Preference prefResetServersToDefaults = getPreferenceManager() .findPreference("reset_server_list_to_defaults"); prefResetServersToDefaults.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Preference resetServerListToDefaults = getPreferenceManager() .findPreference("reset_server_list_to_defaults"); resetServerListToDefaults.setEnabled(false); prefs.edit().putString("unused_servers", "").apply(); return true; } }); final Preference prefVacuumDatabase = getPreferenceManager().findPreference("vacuum_database"); prefVacuumDatabase.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Preference vacuumDatabase = getPreferenceManager().findPreference("vacuum_database"); vacuumDatabase.setEnabled(false); Thread t0 = new Thread(new Runnable() { @Override public void run() { Util.getInstance().createNotificationWithProgressbar(getContext(), 70, getString(R.string.vacuum_database_notification_text), ""); Database.vacuumDatabase(getContext()); Util.getInstance().cancelNotification(70); } }); t0.start(); return true; } }); setFirstRunDefaults(); }
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/*w w w . ja v a 2s . c om*/ 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:org.mitre.svmp.activities.SvmpActivity.java
protected void passwordChangePrompt(final ConnectionInfo connectionInfo) { // if this connection uses password authentication, proceed if ((connectionInfo.getAuthType() & PasswordModule.AUTH_MODULE_ID) == PasswordModule.AUTH_MODULE_ID) { // the service is running for this connection, stop it so we can re-authenticate if (SessionService.isRunningForConn(connectionInfo.getConnectionID())) stopService(new Intent(SvmpActivity.this, SessionService.class)); // create the input container final LinearLayout inputContainer = (LinearLayout) getLayoutInflater().inflate(R.layout.auth_prompt, null);//from ww w .j ava 2s .com // set the message TextView message = (TextView) inputContainer.findViewById(R.id.authPrompt_textView_message); message.setText(connectionInfo.getUsername()); final HashMap<IAuthModule, View> moduleViewMap = new HashMap<IAuthModule, View>(); // populate module view map, add input views for each required auth module // (we know at least password input is required) addAuthModuleViews(connectionInfo, moduleViewMap, inputContainer); // loop through the Auth module(s) to find the View for the old password input (needed for validation) View oldPasswordView = null; for (Map.Entry<IAuthModule, View> entry : moduleViewMap.entrySet()) { if (entry.getKey().getID() == PasswordModule.AUTH_MODULE_ID) { oldPasswordView = entry.getValue(); break; } } // add "new password" and "confirm new password" views final PasswordChangeModule module = new PasswordChangeModule(oldPasswordView); View moduleView = module.generateUI(this); moduleViewMap.put(module, moduleView); inputContainer.addView(moduleView); // create a dialog final AlertDialog dialog = new AlertDialog.Builder(SvmpActivity.this).setCancelable(false) .setTitle(R.string.authPrompt_title_passwordChange).setView(inputContainer) .setPositiveButton(R.string.authPrompt_button_positive_text, null).setNegativeButton( R.string.authPrompt_button_negative_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { busy = false; } }) .create(); // override positive button dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface d) { Button positive = dialog.getButton(AlertDialog.BUTTON_POSITIVE); if (positive != null) { positive.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // before continuing, validate the new password inputs int resId = module.areInputsValid(); if (resId == 0) { dialog.dismiss(); // inputs are valid, dismiss the dialog startAppRTCWithAuth(connectionInfo, moduleViewMap); } else { // tell the user that the new password is not valid toastShort(resId); } } }); } } }); // show the dialog dialog.show(); // request keyboard dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } }
From source file:com.abhijitvalluri.android.fitnotifications.TimePickerFragment.java
@Override @NonNull/* w w w. j a va 2 s. co m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { int hour = getArguments().getInt(ARG_HOUR); int minute = getArguments().getInt(ARG_MINUTE); mOtherHour = getArguments().getInt(ARG_OTHER_HOUR); mOtherMinute = getArguments().getInt(ARG_OTHER_MINUTE); mOtherTimeFormatted = DateFormat.getTimeFormat(getActivity()) .format(Func.convertHourMinute2Date(mOtherHour, mOtherMinute)); mRequestCode = getArguments().getInt(ARG_REQUEST_CODE); View v = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_time, null); mTimePicker = (TimePicker) v.findViewById(R.id.dialog_time_time_picker); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { mTimePicker.setHour(hour); mTimePicker.setMinute(minute); } else { //noinspection deprecation mTimePicker.setCurrentHour(hour); //noinspection deprecation mTimePicker.setCurrentMinute(minute); } mTimePicker.setIs24HourView(DateFormat.is24HourFormat(getActivity())); @StringRes int titleStringId = mRequestCode == AppSettingsActivity.START_TIME_REQUEST ? R.string.start_time_heading : R.string.stop_time_heading; final AlertDialog dialog = new AlertDialog.Builder(getActivity()).setView(v).setTitle(titleStringId) .setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int hour, minute; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { hour = mTimePicker.getHour(); minute = mTimePicker.getMinute(); } else { //noinspection deprecation hour = mTimePicker.getCurrentHour(); //noinspection deprecation minute = mTimePicker.getCurrentMinute(); } sendResult(mRequestCode, hour, minute); } }).create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { int hour, minute; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { hour = mTimePicker.getHour(); minute = mTimePicker.getMinute(); } else { //noinspection deprecation hour = mTimePicker.getCurrentHour(); //noinspection deprecation minute = mTimePicker.getCurrentMinute(); } Button positiveButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE); sanityCheckTimeChoice(positiveButton, hour, minute); } }); mTimePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Override public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE); sanityCheckTimeChoice(positiveButton, hourOfDay, minute); } }); return dialog; }
From source file:nkarasch.repeatingreminder.gui.AlertView.java
@OnClick(R.id.text_label_display) public void labelOnClick() { final EditText input = new EditText(mContext); input.setSingleLine();/*from ww w. j a v a 2s . co m*/ final int accentColor = getResources().getColor(R.color.accent); final int textColor = Color.WHITE; final AlertDialog labelDialog = new DialogBuilder(mContext).setTitle("Set Label").setTitleColor(accentColor) .setDividerColor(accentColor).setView(input) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mAlert.setLabel(input.getText().toString()); textLabel.setText(mAlert.getLabel()); stopAlert(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).create(); labelDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { labelDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(textColor); labelDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(textColor); } }); labelDialog.show(); }
From source file:me.panpf.tool4a.app.MessageDialogFragment.java
/** * ?//from w w w . ja va 2 s. c o m * * @param messageDialog ? */ private void applyParams(AlertDialog messageDialog) { if (builder == null) throw new IllegalArgumentException("builder null ?setBuilder()Builder"); if (builder.message == null) throw new IllegalArgumentException("Builder.setMessage()?"); messageDialog.setTitle(builder.title); messageDialog.setMessage(builder.message); if (builder.confirmButtonName != null) { messageDialog.setButton(AlertDialog.BUTTON_POSITIVE, builder.confirmButtonName, builder.confirmButtonClickListener); } if (builder.cancelButtonName != null) { messageDialog.setButton(AlertDialog.BUTTON_NEGATIVE, builder.cancelButtonName, builder.cancelButtonClickListener); } if (builder.neutralButtonName != null) { messageDialog.setButton(AlertDialog.BUTTON_NEUTRAL, builder.neutralButtonName, builder.neutralButtonClickListener); } messageDialog.setOnKeyListener(builder.onKeyListener); messageDialog.setOnShowListener(builder.onShowListener); setCancelable(builder.cancelable); }
From source file:no.digipost.android.gui.content.UploadActivity.java
private void promtUpload(final File file) { final AlertDialog dialog = DialogUtitities .getAlertDialogBuilderWithMessageAndTitle(this, getString(R.string.upload_dialog) + file.getName() + "?", getString(R.string.upload)) .setPositiveButton(R.string.upload, new DialogInterface.OnClickListener() { @Override/* www .j av a2 s.com*/ public void onClick(DialogInterface dialogInterface, int i) { executeUploadTask(file); dialogInterface.dismiss(); } }).setNegativeButton(R.string.abort, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }).create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { Button b = dialog.getButton(AlertDialog.BUTTON_NEUTRAL); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { previewFile(file); } }); } }); dialog.show(); }