List of usage examples for android.app AlertDialog dismiss
@Override public void dismiss()
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 *//*from w w w . j a va 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:org.projectbuendia.client.ui.dialogs.AddNewUserDialogFragment.java
@NonNull @Override//w w w .jav a 2 s. com public Dialog onCreateDialog(Bundle savedInstanceState) { View fragment = mInflater.inflate(R.layout.dialog_fragment_add_new_user, null); ButterKnife.inject(this, fragment); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity()).setCancelable(false) // Disable auto-cancel. .setTitle(getResources().getString(R.string.title_add_new_user)) .setPositiveButton(getResources().getString(R.string.ok), null) .setNegativeButton(getResources().getString(R.string.cancel), null).setView(fragment); final AlertDialog dialog = dialogBuilder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Validate the user. String givenName = mGivenName.getText() == null ? "" : mGivenName.getText().toString().trim(); String familyName = mFamilyName.getText() == null ? "" : mFamilyName.getText().toString().trim(); boolean valid = true; if (givenName.isEmpty()) { setError(mGivenName, R.string.given_name_cannot_be_null); valid = false; } if (familyName.isEmpty()) { setError(mFamilyName, R.string.family_name_cannot_be_null); valid = false; } Utils.logUserAction("add_user_submitted", "valid", "" + valid, "given_name", givenName, "family_name", familyName); if (!valid) { return; } App.getUserManager().addUser(new NewUser(givenName, familyName)); if (mActivityUi != null) { mActivityUi.showSpinner(true); } dialog.dismiss(); } }); } }); return dialog; }
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 . ja va 2s.c om*/ // 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:de.bogutzky.psychophysiocollector.app.MainActivity.java
private void checkBtEnabled() { bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null) { Toast.makeText(this, getString(R.string.bluetooth_not_supported), Toast.LENGTH_LONG).show(); } else if (!bluetoothAdapter.isEnabled()) { AlertDialog dialog; AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setCancelable(true);/*from w w w .j av a 2s. com*/ builder.setTitle(getString(R.string.activate_bluetooth)); builder.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } }); builder.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog = builder.create(); dialog.show(); } }
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. j a v a 2 s . c om*/ 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.agustinprats.myhrv.fragment.MonitorFragment.java
/** Shows the connect dialog displaying a list of available devices to connect */ private void showConnectDialog() { LayoutInflater inflater = getMainActivity().getLayoutInflater(); // Init view//w ww . j av a 2s. c om RelativeLayout devicesDialogView = (RelativeLayout) inflater.inflate(R.layout.devices_dialog, null); AlertDialog.Builder devicesDialogBuilder = new AlertDialog.Builder(getMainActivity()); devicesDialogBuilder.setTitle(R.string.devices_available); devicesDialogBuilder.setView(devicesDialogView); final AlertDialog devicesDialog = devicesDialogBuilder.create(); _searchingDevicesText = (TextView) devicesDialogView.findViewById(R.id.searchingText); ListView listView = (ListView) devicesDialogView.findViewById(R.id.listView); listView.setEmptyView(_searchingDevicesText); final HeartRateDeviceListAdapter mHeartRateDeviceListAdapter = new HeartRateDeviceListAdapter(inflater); _heartRateDeviceListAdapter = mHeartRateDeviceListAdapter; final HeartRateService service = getMainActivity().getHeartRateService(); service.startScanningDevices(); listView.setAdapter(mHeartRateDeviceListAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final HeartRateDevice device = mHeartRateDeviceListAdapter.getDevice(position); if (device != null) { if (service.isScanning()) service.stopScanningDevices(); Log.d(TAG, "connecting from devices dialog"); service.connect(device.getAddress()); } devicesDialog.dismiss(); } }); devicesDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { service.stopScanningDevices(); _heartRateDeviceListAdapter = null; } }); devicesDialog.show(); }
From source file:no.barentswatch.fiskinfo.BaseActivity.java
public void createConfirmLogoutDialog(Context activityContext, int rPathToTitleOfPopup, int rPathToTextInTheBodyOfThePopup) { AlertDialog.Builder builder = new AlertDialog.Builder(activityContext); AlertDialog dialog; builder.setTitle(rPathToTitleOfPopup); builder.setMessage(rPathToTextInTheBodyOfThePopup); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override/* w w w . j ava 2s . c o m*/ public void onClick(DialogInterface dialog, int which) { invalidateAuthenticationData(); dialog.dismiss(); loadView(MainActivity.class); } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog = builder.create(); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { actionBar.setSelectedNavigationItem(adapter.getCount()); } }); dialog.show(); dialog.setCanceledOnTouchOutside(false); TextView messageView = (TextView) dialog.findViewById(android.R.id.message); messageView.setGravity(Gravity.CENTER); }
From source file:no.barentswatch.fiskinfo.BaseActivity.java
/** * This function creates a dialog which gives a description of the symbols * that populate the map./*from w w w.j a v a2 s . co m*/ * * @param ActivityContext * The context of the current activity. */ public void displaySymbolExplanation(Context ActivityContext) { LayoutInflater layoutInflater = getLayoutInflater(); View view = layoutInflater.inflate(R.layout.symbol_explanation, (null)); final AlertDialog builder = new AlertDialog.Builder(ActivityContext).create(); builder.setTitle(R.string.map_symbol_explanation); builder.setCanceledOnTouchOutside(false); builder.setView(view); Button okButton = (Button) view.findViewById(R.id.symbolOkButton); okButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { builder.dismiss(); } }); builder.show(); }
From source file:com.mishiranu.dashchan.ui.navigator.NavigatorActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void showThemeDialog() { final int checkedItem = Arrays.asList(Preferences.VALUES_THEME).indexOf(Preferences.getTheme()); Resources resources = getResources(); float density = ResourceUtils.obtainDensity(resources); ScrollView scrollView = new ScrollView(this); LinearLayout outer = new LinearLayout(this); outer.setOrientation(LinearLayout.VERTICAL); int outerPadding = (int) (16f * density); outer.setPadding(outerPadding, outerPadding, outerPadding, outerPadding); scrollView.addView(outer, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); final AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.action_change_theme) .setView(scrollView).setNegativeButton(android.R.string.cancel, null).create(); View.OnClickListener listener = v -> { int index = (int) v.getTag(); if (index != checkedItem) { Preferences.setTheme(Preferences.VALUES_THEME[index]); recreate();/*from ww w .j a v a 2 s .c o m*/ } dialog.dismiss(); }; int circleSize = (int) (56f * density); int itemPadding = (int) (12f * density); LinearLayout inner = null; for (int i = 0; i < Preferences.ENTRIES_THEME.length; i++) { if (i % 3 == 0) { inner = new LinearLayout(this); inner.setOrientation(LinearLayout.HORIZONTAL); outer.addView(inner, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); } LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); layout.setGravity(Gravity.CENTER); layout.setBackgroundResource( ResourceUtils.getResourceId(this, android.R.attr.selectableItemBackground, 0)); layout.setPadding(0, itemPadding, 0, itemPadding); layout.setOnClickListener(listener); layout.setTag(i); inner.addView(layout, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); View view = new View(this); int colorBackgroundAttr = Preferences.VALUES_THEME_COLORS[i][0]; int colorPrimaryAttr = Preferences.VALUES_THEME_COLORS[i][1]; int colorAccentAttr = Preferences.VALUES_THEME_COLORS[i][2]; Resources.Theme theme = getResources().newTheme(); theme.applyStyle(Preferences.VALUES_THEME_IDS[i], true); TypedArray typedArray = theme .obtainStyledAttributes(new int[] { colorBackgroundAttr, colorPrimaryAttr, colorAccentAttr }); view.setBackground(new ThemeChoiceDrawable(typedArray.getColor(0, 0), typedArray.getColor(1, 0), typedArray.getColor(2, 0))); typedArray.recycle(); if (C.API_LOLLIPOP) { view.setElevation(6f * density); } layout.addView(view, circleSize, circleSize); TextView textView = new TextView(this, null, android.R.attr.textAppearanceListItem); textView.setSingleLine(true); textView.setEllipsize(TextUtils.TruncateAt.END); textView.setText(Preferences.ENTRIES_THEME[i]); if (C.API_LOLLIPOP) { textView.setAllCaps(true); textView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f); } else { textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f); } textView.setGravity(Gravity.CENTER_HORIZONTAL); textView.setPadding(0, (int) (8f * density), 0, 0); layout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); if (i + 1 == Preferences.ENTRIES_THEME.length && Preferences.ENTRIES_THEME.length % 3 != 0) { if (Preferences.ENTRIES_THEME.length % 3 == 1) { inner.addView(new View(this), 0, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); } inner.addView(new View(this), new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); } } dialog.show(); }
From source file:com.df.app.procedures.CarRecogniseLayout.java
/** * //ww w.j av a 2s . com * @param arrayId * @param editViewId */ private void choose(final int arrayId, final int editViewId) { View view1 = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.popup_layout, null); final AlertDialog dialog = new AlertDialog.Builder(getContext()).setView(view1).create(); TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea); final ListView listView = new ListView(view1.getContext()); listView.setAdapter(new ArrayAdapter<String>(view1.getContext(), android.R.layout.simple_list_item_1, view1.getResources().getStringArray(arrayId))); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { dialog.dismiss(); String temp = (String) listView.getItemAtPosition(i); setEditViewText(rootView, editViewId, temp); } }); contentArea.addView(listView); setTextView(view1, R.id.title, getResources().getString(R.string.alert)); dialog.show(); }