List of usage examples for android.app AlertDialog.Builder setView
public void setView(View view)
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/*from ww w. ja va 2 s . co 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:br.com.thinkti.android.filechooserfrag.fragFileChooser.java
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); View v = info.targetView;/*from ww w . j av a 2s . c o m*/ final Option o = adapter.getItem((int) info.id); switch (item.getItemId()) { case R.id.mnuDelete: String msg = String.format(getString(R.string.txtReallyDelete), o.getName()); if (lib.ShowMessageYesNo(_main, msg, _main.getString(R.string.question)) == lib.yesnoundefined.yes) { try { File F = new File(o.getPath()); boolean delete = false; if (F.exists()) { if (F.isDirectory()) { String[] deleteCmd = { "rm", "-r", F.getPath() }; Runtime runtime = Runtime.getRuntime(); runtime.exec(deleteCmd); delete = true; } else { delete = F.delete(); } } if (delete) adapter.remove(o); } catch (Exception ex) { lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error))); } } //lib.ShowToast(_main,"delete " + t1.getText().toString() + " " + t2.getText().toString() + " " + o.getData() + " " + o.getPath() + " " + o.getName()); //editNote(info.id); return true; case R.id.mnuRename: String msg2 = String.format(getString(R.string.txtRenameFile), o.getName()); AlertDialog.Builder A = new AlertDialog.Builder(_main); final EditText inputRename = new EditText(_main); A.setMessage(msg2); A.setTitle(getString(R.string.rename)); // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text inputRename.setInputType(InputType.TYPE_CLASS_TEXT); inputRename.setText(o.getName()); A.setView(inputRename); A.setPositiveButton(_main.getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String name = inputRename.getText().toString(); final String pattern = ".+\\.(((?i)v.{2})|((?i)k.{2})|((?i)dic))$"; Pattern vok = Pattern.compile(pattern); if (lib.libString.IsNullOrEmpty(name)) return; if (vok.matcher(name).matches()) { try { File F = new File(o.getPath()); File F2 = new File(F.getParent(), name); if (!F2.exists()) { final boolean b = F.renameTo(F2); if (b) { o.setName(name); o.setPath(F2.getPath()); adapter.notifyDataSetChanged(); } } else { lib.ShowMessage(_main, getString(R.string.msgFileExists), ""); } } catch (Exception ex) { lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error))); } } else { AlertDialog.Builder A = new AlertDialog.Builder(_main); A.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); A.setMessage(getString(R.string.msgWrongExt2)); A.setTitle(getString(R.string.message)); AlertDialog dlg = A.create(); dlg.show(); } } }); A.setNegativeButton(_main.getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); AlertDialog dlg = A.create(); dlg.show(); return true; case R.id.mnuCopy: _copiedFile = (o.getPath()); _cutFile = null; return true; case R.id.mnuCut: _cutFile = (o.getPath()); _cutOption = o; _copiedFile = null; return true; case R.id.mnuPaste: if (_cutFile != null && _copiedFile != null) return true; String path; File F = new File(o.getPath()); if (F.isDirectory()) { path = F.getPath(); } else { path = F.getParent(); } if (_copiedFile != null) { File source = new File(_copiedFile); File dest = new File(path, source.getName()); if (dest.exists()) { lib.ShowMessage(_main, getString(R.string.msgFileExists), ""); return true; } String[] copyCmd; if (source.isDirectory()) { copyCmd = new String[] { "cp", "-r", _copiedFile, path }; } else { copyCmd = new String[] { "cp", _copiedFile, path }; } Runtime runtime = Runtime.getRuntime(); try { runtime.exec(copyCmd); Option newOption; if (dest.getParent().equalsIgnoreCase(currentDir.getPath())) { if (dest.isDirectory() && !dest.isHidden()) { adapter.add(new Option(dest.getName(), getString(R.string.folder), dest.getAbsolutePath(), true, false, false)); } else { if (!dest.isHidden()) adapter.add(new Option(dest.getName(), getString(R.string.fileSize) + ": " + dest.length(), dest.getAbsolutePath(), false, false, false)); } } } catch (Exception ex) { lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error))); } } else if (_cutFile != null) { File source = new File(_cutFile); File dest = new File(path, source.getName()); if (dest.exists()) { lib.ShowMessage(_main, getString(R.string.msgFileExists), ""); return true; } String[] copyCmd; if (source.isDirectory()) { copyCmd = new String[] { "mv", "-r", _cutFile, path }; } else { copyCmd = new String[] { "mv", _cutFile, path }; } Runtime runtime = Runtime.getRuntime(); _cutFile = null; try { runtime.exec(copyCmd); Option newOption; try { adapter.remove(_cutOption); _cutOption = null; } catch (Exception e) { } if (dest.getParent().equalsIgnoreCase(currentDir.getPath())) { if (dest.isDirectory() && !dest.isHidden()) { adapter.add(new Option(dest.getName(), getString(R.string.folder), dest.getAbsolutePath(), true, false, false)); } else { if (!dest.isHidden()) adapter.add(new Option(dest.getName(), getString(R.string.fileSize) + ": " + dest.length(), dest.getAbsolutePath(), false, false, false)); } } } catch (Exception ex) { lib.ShowMessage(_main, ex.getMessage(), getString((R.string.Error))); } } return true; case R.id.mnuNewFolder: A = new AlertDialog.Builder(_main); //final EditText input = new EditText(_main); final EditText inputNF = new EditText(_main); A.setMessage(getString(R.string.msgEnterNewFolderName)); A.setTitle(getString(R.string.cmnuNewFolder)); // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text inputNF.setInputType(InputType.TYPE_CLASS_TEXT); inputNF.setText(""); A.setView(inputNF); A.setPositiveButton(_main.getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String name = inputNF.getText().toString(); if (lib.libString.IsNullOrEmpty(name)) return; String NFpath; File NF = new File(o.getPath()); if (NF.isDirectory()) { NFpath = NF.getPath(); } else { NFpath = NF.getParent(); } try { File NewFolder = new File(NFpath, name); NewFolder.mkdir(); adapter.add(new Option(NewFolder.getName(), getString(R.string.folder), NewFolder.getAbsolutePath(), true, false, false)); } catch (Exception ex) { lib.ShowException(_main, ex); } } }); A.setNegativeButton(_main.getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); dlg = A.create(); dlg.show(); return true; default: return super.onContextItemSelected(item); } }
From source file:com.code.android.vibevault.ShowDetailsScreen.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.nowPlaying: //Open playlist activity Intent i = new Intent(ShowDetailsScreen.this, NowPlayingScreen.class); startActivity(i);//from w w w . jav a2 s .com break; case R.id.recentShows: Intent rs = new Intent(ShowDetailsScreen.this, RecentShowsScreen.class); startActivity(rs); break; case R.id.scrollableDialog: AlertDialog.Builder ad = new AlertDialog.Builder(this); ad.setTitle("Help!"); View v = LayoutInflater.from(this).inflate(R.layout.scrollable_dialog, null); ((TextView) v.findViewById(R.id.DialogText)).setText(R.string.show_details_screen_help); ad.setPositiveButton("Okay.", new android.content.DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { } }); ad.setView(v); ad.show(); break; case R.id.emailLink: final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Great show on archive.org: " + show.getArtistAndTitle()); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hey,\n\nYou should listen to " + show.getArtistAndTitle() + ". You can find it here: " + show.getShowURL() + "\n\nSent using VibeVault for Android."); startActivity(Intent.createChooser(emailIntent, "Send mail...")); break; case R.id.downloadShow: for (int j = 0; j < downloadLinks.size(); j++) { downloadLinks.get(j).setDownloadShow(show); dService.addSong(downloadLinks.get(j)); } break; default: break; } return true; }
From source file:com.example.cody.tapwater.activities.MainActivity.java
/** * Creates the dialog for a user to register with the application. *///www . j a va2 s . c o m public void register() { // Instantiate dialog. AlertDialog.Builder b = new AlertDialog.Builder(this); b.setTitle("Register"); // Get register dialog layout LayoutInflater inflater = this.getLayoutInflater(); View v = inflater.inflate(R.layout.register, null); // Instantiate EditTexts for username, password, and password confirmation. final EditText u = (EditText) v.findViewById(R.id.username); final EditText p = (EditText) v.findViewById(R.id.password); final EditText cp = (EditText) v.findViewById(R.id.confirm_password); b.setView(v); b.setPositiveButton("Register", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); alert = b.create(); alert.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button register = alert.getButton(DialogInterface.BUTTON_POSITIVE); register.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Make sure EditTexts are not empty if (u.getText().toString().equals("")) { Toast.makeText(getBaseContext(), "Please enter email address", Toast.LENGTH_SHORT) .show(); } else if (p.getText().toString().equals("") || cp.getText().toString().equals("")) { Toast.makeText(getBaseContext(), "Please enter license number", Toast.LENGTH_SHORT) .show(); } else { // Create User object and set fields needed for async Gson gson = new Gson(); User us = new User(); us.setUsername(u.getText().toString()); us.setPassword(p.getText().toString()); us.setPasswordConfirmation(cp.getText().toString()); // Create object fit to satisfy json transfer to server. ServerUser s = new ServerUser(us); // Create json string of ServerUser object String json = gson.toJson(s, ServerUser.class); // Begin async to authenticate the user's credentials CreateUserAsync async = new CreateUserAsync(context, new CallBack()); // If internet connection exists, DO IT, else, tell user they need to connect if (helper.haveNetworkConnection()) { async.execute(json); } else { Toast.makeText(getBaseContext(), "No Network Connection", Toast.LENGTH_LONG).show(); } } } }); } }); // Show the prompt, if the user cancels, close the application alert.show(); alert.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { login(); } }); }
From source file:tr.com.turkcellteknoloji.turkcellupdater.UpdaterDialogManager.java
@Override public void onUpdateCheckCompleted(UpdateManager manager, final Update update) { final AlertDialog.Builder builder = new AlertDialog.Builder(activity); if (update.forceExit) { builder.setTitle(R.string.service_is_not_available); } else if (update.forceUpdate) { builder.setTitle(R.string.update_required); } else {/* ww w . j a v a 2 s.c om*/ builder.setTitle(R.string.update_found); } final View dialogContentsView = createUpdatesFoundDialogContentsView(update); builder.setView(dialogContentsView); initializeUpdatesFoundDialogButtons(builder, update); builder.setCancelable(false); final AlertDialog alertDialog = builder.create(); alertDialog.show(); }
From source file:com.example.alyshia.customsimplelauncher.MainActivity.java
void inflateDialog(int type) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("PASSWORD"); LayoutInflater inflater = LayoutInflater.from(this); final View view = inflater.inflate(R.layout.dialoglayout, null); EditText edittext = (EditText) view.findViewById(R.id.pswEditText); alert.setView(R.layout.dialoglayout); if (type == TYPE_EXIT) { alert.setPositiveButton("Enter", new DialogInterface.OnClickListener() { @Override/* ww w . ja v a 2 s . c o m*/ public void onClick(DialogInterface dialog, int which) { Dialog d = (Dialog) dialog; EditText et = (EditText) d.findViewById(R.id.pswEditText); Log.d(TAG, "TEXT is " + et.getText().toString()); if (et.getText().toString().equals("")) { dialog.dismiss(); Toast.makeText(MainActivity.this, "wrong password", Toast.LENGTH_SHORT).show(); } else if (et.getText().toString().equals(getPW())) { setkioskReceiver(); if (km == null) { km = KioskMode.getInstance(getApplicationContext()); } if (km.isKioskModeEnabled()) { Log.d(TAG, "Kioskmode being disabled bc it is enabled"); km.disableKioskMode(); } } } }); } else if (type == TYPE_ADMIN) { alert.setPositiveButton("Enter", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Dialog d = (Dialog) dialog; EditText et = (EditText) d.findViewById(R.id.pswEditText); Log.d(TAG, "TEXT is " + et.getText().toString()); if (et.getText().toString().equals("")) { dialog.dismiss(); } else if (et.getText().toString().equals(getPW())) { Intent intent = new Intent(MainActivity.this, AdminActivity.class); startActivity(intent); } } }); } alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); alert.setCancelable(true); AlertDialog cdialog = alert.create(); cdialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); cdialog.show(); }
From source file:com.example.drugsformarinemammals.Combined_Search.java
private void displayMessage(String messageTitle, String message) { AlertDialog.Builder myalert = new AlertDialog.Builder(this); TextView title = new TextView(this); title.setTypeface(Typeface.SANS_SERIF); title.setTextSize(20);//w ww. j a va 2 s .c o m title.setTextColor(getResources().getColor(R.color.blue)); title.setPadding(8, 8, 8, 8); title.setText(messageTitle); title.setGravity(Gravity.CENTER_VERTICAL); LinearLayout layout = new LinearLayout(this); TextView text = new TextView(this); text.setTypeface(Typeface.SANS_SERIF); text.setTextSize(20); text.setPadding(10, 10, 10, 10); text.setText(message); layout.addView(text); myalert.setView(layout); myalert.setCustomTitle(title); myalert.setCancelable(true); myalert.show(); }
From source file:com.lovejoy777sarootool.rootool.dialogs.FilePropertiesDialog.java
@Override public Dialog onCreateDialog(Bundle state) { activity = getActivity();/*from www.j av a 2s . c o m*/ final AlertDialog.Builder builder = new AlertDialog.Builder(activity); mAdapter = new PropertiesAdapter(activity, mFile); builder.setTitle(mFile.getName()); builder.setNeutralButton(R.string.cancel, null); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final FilePermissionsPagerItem fragment = (FilePermissionsPagerItem) mAdapter.getItem(1); fragment.applyPermissions(activity); } }); final View content = activity.getLayoutInflater().inflate(R.layout.dialog_properties_container, null); this.initView(content); builder.setView(content); return builder.create(); }
From source file:com.mdlive.sav.MDLiveSearchProvider.java
/** * Instantiating array adapter to populate the listView * The layout android.R.layout.simple_list_item_single_choice creates radio button for each listview item * * @param list : Dependent users array list *//* w w w.jav a 2 s . c o m*/ private void showListViewDialog(final ArrayList<String> list, final TextView selectedText, final String key, final ArrayList<HashMap<String, String>> typeList) { /*We need to get the instance of the LayoutInflater*/ final AlertDialog.Builder alertDialog = new AlertDialog.Builder(MDLiveSearchProvider.this); LayoutInflater inflater = getLayoutInflater(); View convertView = inflater.inflate(R.layout.mdlive_screen_popup, null); alertDialog.setView(convertView); ListView lv = (ListView) convertView.findViewById(R.id.popupListview); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list); lv.setAdapter(adapter); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); final AlertDialog dialog = alertDialog.create(); dialog.show(); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String SelectedText = list.get(position); HashMap<String, String> localMap = typeList.get(position); for (Map.Entry entry : localMap.entrySet()) { if (SelectedText.equals(entry.getValue().toString())) { postParams.put(key, entry.getKey().toString()); break; //breaking because its one to one map } } specialityBasedOnProvider(SelectedText, key); String oldChoice = selectedText.getText().toString(); selectedText.setText(SelectedText); dialog.dismiss(); // if user selects a different Provider type, then reload this screen if (!oldChoice.equals(SelectedText)) { SharedPreferences sharedpreferences = getSharedPreferences( PreferenceConstants.MDLIVE_USER_PREFERENCES, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PreferenceConstants.PROVIDER_MODE, SelectedText); int providerType = MDLiveConfig.PROVIDERTYPE_MAP.get(SelectedText) == null ? MDLiveConfig.UNMAPPED : MDLiveConfig.PROVIDERTYPE_MAP.get(SelectedText); if (providerType == MDLiveConfig.UNMAPPED) editor.putString(PreferenceConstants.PROVIDERTYPE_ID, ""); else editor.putString(PreferenceConstants.PROVIDERTYPE_ID, String.valueOf(providerType)); editor.commit(); // now reload the screen //recreate(); } } }); }
From source file:com.balakrish.gpstracker.WaypointsListActivity.java
/** * Export waypoints to external file/*from w w w . j ava 2s . c o m*/ */ private void exportWaypoints() { Context mContext = this; LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.filename_dialog, (ViewGroup) findViewById(R.id.filename_dialog_layout_root)); AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setTitle(R.string.export_waypoints); builder.setView(layout); // final String defaultFilename = "wp_" + (new SimpleDateFormat("yyyy-MM-dd", Locale.US)).format((new // Date()).getTime()); final String defaultFilename = "wp_" + (DateFormat.format("yyyy-MM-dd", (new Date()).getTime())); // creating references to input fields in order to use them in // onClick handler final EditText filenameEditText = (EditText) layout.findViewById(R.id.filenameInputText); filenameEditText.setText(defaultFilename); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // waypoint title from input dialog String filenameStr = filenameEditText.getText().toString().trim(); if (filenameStr.equals("")) { filenameStr = defaultFilename; } waypointToGpx = new WaypointGpxExportTask(WaypointsListActivity.this, filenameStr); waypointToGpx.setApp(app); waypointToGpx.execute(0L); dialog.dismiss(); } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // dialog.dismiss(); } }); AlertDialog dialog = builder.create(); dialog.show(); }