List of usage examples for android.preference EditTextPreference setOnPreferenceChangeListener
public void setOnPreferenceChangeListener(OnPreferenceChangeListener onPreferenceChangeListener)
From source file:nya.miku.wishmaster.chans.krautchan.KrautModule.java
public void addKompturcodePreference(PreferenceGroup preferenceGroup) { Context context = preferenceGroup.getContext(); EditTextPreference kompturcodePreference = new EditTextPreference(context); kompturcodePreference.setTitle(R.string.kraut_prefs_kompturcode); kompturcodePreference.setDialogTitle(R.string.kraut_prefs_kompturcode); kompturcodePreference.setSummary(R.string.kraut_prefs_kompturcode_summary); kompturcodePreference.setKey(getSharedKey(PREF_KEY_KOMPTURCODE_COOKIE)); kompturcodePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override/*from ww w . j a v a2s . c o m*/ public boolean onPreferenceChange(Preference preference, Object newValue) { setKompturcodeCookie((String) newValue); return true; } }); preferenceGroup.addPreference(kompturcodePreference); }
From source file:nya.miku.wishmaster.api.AbstractChanModule.java
/** * ( ?/ ) ? ?-?/*from w w w . jav a 2 s .com*/ * @param group , ??? */ protected void addProxyPreferences(PreferenceGroup group) { final Context context = group.getContext(); PreferenceCategory proxyCat = new PreferenceCategory(context); //? ? ? proxyCat.setTitle(R.string.pref_cat_proxy); group.addPreference(proxyCat); CheckBoxPreference useProxyPref = new CheckBoxPreference(context); //? "? ? " useProxyPref.setTitle(R.string.pref_use_proxy); useProxyPref.setSummary(R.string.pref_use_proxy_summary); useProxyPref.setKey(getSharedKey(PREF_KEY_USE_PROXY)); useProxyPref.setDefaultValue(false); useProxyPref.setOnPreferenceChangeListener(updateHttpListener); proxyCat.addPreference(useProxyPref); EditTextPreference proxyHostPref = new EditTextPreference(context); // ? ?-? proxyHostPref.setTitle(R.string.pref_proxy_host); proxyHostPref.setDialogTitle(R.string.pref_proxy_host); proxyHostPref.setSummary(R.string.pref_proxy_host_summary); proxyHostPref.setKey(getSharedKey(PREF_KEY_PROXY_HOST)); proxyHostPref.setDefaultValue(DEFAULT_PROXY_HOST); proxyHostPref.getEditText().setSingleLine(); proxyHostPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); proxyHostPref.setOnPreferenceChangeListener(updateHttpListener); proxyCat.addPreference(proxyHostPref); proxyHostPref.setDependency(getSharedKey(PREF_KEY_USE_PROXY)); EditTextPreference proxyHostPort = new EditTextPreference(context); // ?-? proxyHostPort.setTitle(R.string.pref_proxy_port); proxyHostPort.setDialogTitle(R.string.pref_proxy_port); proxyHostPort.setSummary(R.string.pref_proxy_port_summary); proxyHostPort.setKey(getSharedKey(PREF_KEY_PROXY_PORT)); proxyHostPort.setDefaultValue(DEFAULT_PROXY_PORT); proxyHostPort.getEditText().setSingleLine(); proxyHostPort.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER); proxyHostPort.setOnPreferenceChangeListener(updateHttpListener); proxyCat.addPreference(proxyHostPort); proxyHostPort.setDependency(getSharedKey(PREF_KEY_USE_PROXY)); }
From source file:com.nttec.everychan.chans.ponyach.PonyachModule.java
@Override public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) { final Context context = preferenceGroup.getContext(); ListPreference captchaLevel = new LazyPreferences.ListPreference(context); captchaLevel.setTitle(R.string.ponyach_prefs_captcha); captchaLevel.setDialogTitle(R.string.ponyach_prefs_captcha); captchaLevel.setKey(getSharedKey(PREF_KEY_CAPTCHA_LEVEL)); captchaLevel.setEntryValues(new String[] { "3", "2", "1" }); captchaLevel.setEntries(new String[] { "Easy", "Easy++", "Medium" }); captchaLevel.setDefaultValue("1"); preferenceGroup.addPreference(captchaLevel); EditTextPreference passcodePref = new EditTextPreference(context); passcodePref.setTitle(R.string.ponyach_prefs_passcode); passcodePref.setDialogTitle(R.string.ponyach_prefs_passcode); passcodePref.getEditText().setFilters(new InputFilter[] { new InputFilter.LengthFilter(6) }); passcodePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override// w ww . j a v a2 s . c o m public boolean onPreferenceChange(Preference preference, Object newValue) { final String newPasscode = (String) newValue; final CancellableTask passAuthTask = new CancellableTask.BaseCancellableTask(); final ProgressDialog passAuthProgressDialog = new ProgressDialog(context); passAuthProgressDialog.setMessage("Logging in"); passAuthProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { passAuthTask.cancel(); } }); passAuthProgressDialog.setCanceledOnTouchOutside(false); passAuthProgressDialog.show(); Async.runAsync(new Runnable() { @Override public void run() { try { if (passAuthTask.isCancelled()) return; String url = getUsingUrl() + "passcode.php"; List<BasicNameValuePair> pairs = Collections .singletonList(new BasicNameValuePair("passcode_just_set", newPasscode)); HttpRequestModel request = HttpRequestModel.builder() .setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")).build(); HttpStreamer.getInstance().getStringFromUrl(url, request, httpClient, null, passAuthTask, false); savePhpCookies(); } catch (final Exception e) { if (context instanceof Activity) { ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { String message = e.getMessage() == null ? resources.getString(R.string.error_unknown) : e.getMessage(); Toast.makeText(context, message, Toast.LENGTH_LONG).show(); } }); } } finally { passAuthProgressDialog.dismiss(); } } }); return false; } }); preferenceGroup.addPreference(passcodePref); ListPreference domainPref = new LazyPreferences.ListPreference(context); domainPref.setTitle(R.string.pref_domain); domainPref.setDialogTitle(R.string.pref_domain); domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN)); domainPref.setEntryValues(DOMAINS); domainPref.setEntries(DOMAINS); domainPref.setDefaultValue(DEFAULT_DOMAIN); domainPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { loadPhpCookies((String) newValue); return true; } }); preferenceGroup.addPreference(domainPref); addHttpsPreference(preferenceGroup, useHttpsDefaultValue()); addProxyPreferences(preferenceGroup); captchaLevel.setSummary(captchaLevel.getEntry()); domainPref.setSummary(domainPref.getEntry()); }
From source file:com.nttec.everychan.chans.dobrochan.DobroModule.java
private void addDomainPreferences(PreferenceGroup group) { Context context = group.getContext(); Preference.OnPreferenceChangeListener updateDomainListener = new Preference.OnPreferenceChangeListener() { @Override/*from w w w . ja v a2 s . co m*/ public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference.getKey().equals(getSharedKey(PREF_KEY_DOMAIN))) { domain = (String) newValue; if (domain.length() == 0) domain = DEFAULT_DOMAIN; loadHanabiraCookie(); return true; } return false; } }; EditTextPreference domainPref = new EditTextPreference(context); domainPref.setTitle(R.string.pref_domain); domainPref.setDialogTitle(R.string.pref_domain); domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT)); domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN)); domainPref.getEditText().setHint(DEFAULT_DOMAIN); domainPref.getEditText().setSingleLine(); domainPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); domainPref.setOnPreferenceChangeListener(updateDomainListener); group.addPreference(domainPref); }
From source file:com.almalence.opencam.Fragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); thiz = this;//from w ww . ja v a 2s .c o m String settings = getArguments().getString("type"); ApplicationScreen.getPluginManager().loadHeaderContent(settings, this); if (null == getPreferenceScreen()) return; for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) { initSummary(getPreferenceScreen().getPreference(i)); } Preference nightPreference = findPreference("night"); if (nightPreference != null) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); if (prefs.getBoolean("useCamera2Pref", false)) { getPreferenceScreen().removePreference(nightPreference); } else { Preference superPreference = findPreference("super"); getPreferenceScreen().removePreference(superPreference); } } final SeekBarPreference brightnessPref = (SeekBarPreference) this.findPreference("brightnessPref"); if (brightnessPref != null) { // Set seekbar summary : float gamma = PreferenceManager.getDefaultSharedPreferences(getActivity()).getFloat("gammaPref", 0.5f); brightnessPref.setSummary( this.getString(R.string.Pref_Super_BrightnessEnhancementValue).replace("$1", "" + gamma)); brightnessPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { private final Map<Integer, Float> gamma_map = new HashMap<Integer, Float>() { { put(0, 0.5f); put(1, 0.55f); put(2, 0.6f); put(3, 0.65f); put(4, 0.7f); } }; @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int radius = (Integer) newValue; float gamma = gamma_map.get(radius); PreferenceManager .getDefaultSharedPreferences(Fragment.thiz.getActivity().getApplicationContext()).edit() .putFloat("gammaPref", gamma).commit(); brightnessPref.setSummary(getActivity() .getString(R.string.Pref_Super_BrightnessEnhancementValue).replace("$1", "" + gamma)); return true; } }); } final CheckBoxPreference upscalePref = (CheckBoxPreference) this.findPreference("upscaleResult"); if (upscalePref != null) { Size size = CameraController.getMaxCameraImageSize(CameraController.YUV); long resMpx = 0; float mpix = 0.0f; if (size != null) { resMpx = (long) ((long) size.getWidth() * (long) size.getHeight() * 2.25); mpix = (float) resMpx / 1000000.f; } String name = String.format("%3.1f Mpix ", mpix); upscalePref.setSummary( getActivity().getString(R.string.Pref_Super_SummaryUpscale).replace("$1", "" + name)); } Preference cameraParameters = findPreference("camera_parameters"); if (cameraParameters != null) { cameraParameters.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { try { showCameraParameters(); } catch (Exception e) { e.printStackTrace(); } return true; } }); } CheckBoxPreference helpPref = (CheckBoxPreference) findPreference("showHelpPrefCommon"); if (helpPref != null) helpPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { if (((CheckBoxPreference) preference).isChecked()) { SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(MainScreen.getMainContext()); Editor prefsEditor = prefs.edit(); prefsEditor.putBoolean("droShowHelp", true); prefsEditor.putBoolean("sequenceRemovalShowHelp", true); prefsEditor.putBoolean("panoramaShowHelp", true); prefsEditor.putBoolean("superShowHelp", true); prefsEditor.putBoolean("groupshotRemovalShowHelp", true); prefsEditor.putBoolean("objectRemovalShowHelp", true); prefsEditor.putBoolean("bestShotShowHelp", true); prefsEditor.commit(); } return true; } }); EditTextPreference prefix = (EditTextPreference) this .findPreference(getResources().getString(R.string.Preference_SavePathPrefixValue)); EditTextPreference postfix = (EditTextPreference) this .findPreference(getResources().getString(R.string.Preference_SavePathPostfixValue)); initExportName(null, null); if (prefix != null) { prefix.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { initExportName(preference, newValue); return true; } }); } if (postfix != null) { postfix.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { initExportName(preference, newValue); return true; } }); } Preference sonyPreference = findPreference(MainScreen.sSonyCamerasPref); if (sonyPreference != null) { sonyPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { boolean sonyCamerasAvailable = (Boolean) newValue; if (sonyCamerasAvailable) { Toast.makeText(getActivity(), getActivity().getString(R.string.pref_general_more_sonyCamera_available), Toast.LENGTH_SHORT).show(); } return true; } }); } ListPreference saveToPreference = (ListPreference) this .findPreference(getResources().getString(R.string.Preference_SaveToValue)); // if android 5+, then remove "save to SD card" option. Because it's // equals to "save to custom folder" option. if (saveToPreference != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { CharSequence[] entries = saveToPreference.getEntries(); CharSequence[] entriyValues = saveToPreference.getEntryValues(); CharSequence[] newEntries = new String[2]; CharSequence[] newEntriyValues = new String[2]; newEntries[0] = entries[0]; newEntries[1] = entries[2]; newEntriyValues[0] = entriyValues[0]; newEntriyValues[1] = entriyValues[2]; saveToPreference.setEntries(newEntries); saveToPreference.setEntryValues(newEntriyValues); } if (saveToPreference != null) { saveToPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int v = -1; int v_old = 0; try { v = Integer.parseInt(newValue.toString()); v_old = Integer.parseInt(((ListPreference) preference).getValue()); } catch (NumberFormatException e) { } if ((v == 2 || v == 1) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Toast.makeText(MainScreen.getInstance(), MainScreen.getAppResources() .getString(R.string.pref_advanced_saving_saveToPref_CantSaveToSD), Toast.LENGTH_LONG).show(); if (isDeviceRooted()) { Intent intent = new Intent(Preferences.thiz, FolderPicker.class); intent.putExtra(MainScreen.sSavePathPref, v_old); Preferences.thiz.startActivity(intent); return true; } else return false; } } if (v == 2 || v == 1) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, CHOOSE_FOLDER_CODE); } else if (v != 1) { Intent intent = new Intent(Preferences.thiz, FolderPicker.class); intent.putExtra(MainScreen.sSavePathPref, v_old); Preferences.thiz.startActivity(intent); } } return true; } }); } PreferenceCategory cat = (PreferenceCategory) this.findPreference("Pref_VFCommon_Preference_Category"); if (cat != null) { CheckBoxPreference cp = (CheckBoxPreference) cat.findPreference("maxScreenBrightnessPref"); if (cp != null) { cp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { boolean value = Boolean.parseBoolean(newValue.toString()); setScreenBrightness(value); return true; } }); } } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity()); boolean MaxScreenBrightnessPreference = prefs.getBoolean("maxScreenBrightnessPref", false); setScreenBrightness(MaxScreenBrightnessPreference); }
From source file:com.nttec.everychan.chans.makaba.MakabaModule.java
/** ? ( .. https) */ private void addDomainPreferences(PreferenceGroup group) { Context context = group.getContext(); Preference.OnPreferenceChangeListener updateDomainListener = new Preference.OnPreferenceChangeListener() { @Override//from w ww. j ava 2s. c om public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference.getKey().equals(getSharedKey(PREF_KEY_DOMAIN))) { updateDomain((String) newValue, preferences.getBoolean(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA), true)); return true; } else if (preference.getKey().equals(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA))) { updateDomain(preferences.getString(getSharedKey(PREF_KEY_DOMAIN), DEFAULT_DOMAIN), (boolean) newValue); return true; } return false; } }; PreferenceCategory domainCat = new PreferenceCategory(context); domainCat.setTitle(R.string.makaba_prefs_domain_category); group.addPreference(domainCat); EditTextPreference domainPref = new EditTextPreference(context); // domainPref.setTitle(R.string.pref_domain); domainPref.setDialogTitle(R.string.pref_domain); domainPref.setSummary(resources.getString(R.string.pref_domain_summary, DOMAINS_HINT)); domainPref.setKey(getSharedKey(PREF_KEY_DOMAIN)); domainPref.getEditText().setHint(DEFAULT_DOMAIN); domainPref.getEditText().setSingleLine(); domainPref.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); domainPref.setOnPreferenceChangeListener(updateDomainListener); domainCat.addPreference(domainPref); CheckBoxPreference httpsPref = new LazyPreferences.CheckBoxPreference(context); //? "? https" httpsPref.setTitle(R.string.pref_use_https); httpsPref.setSummary(R.string.pref_use_https_summary); httpsPref.setKey(getSharedKey(PREF_KEY_USE_HTTPS_MAKABA)); httpsPref.setDefaultValue(true); httpsPref.setOnPreferenceChangeListener(updateDomainListener); domainCat.addPreference(httpsPref); }
From source file:it.feio.android.omninotes.SettingsFragment.java
@SuppressWarnings("deprecation") @Override/*from w w w . j av a 2 s . com*/ public void onResume() { super.onResume(); // Export notes Preference export = findPreference("settings_export_data"); if (export != null) { export.setOnPreferenceClickListener(arg0 -> { // Inflate layout LayoutInflater inflater = getActivity().getLayoutInflater(); View v = inflater.inflate(R.layout.dialog_backup_layout, null); // Finds actually saved backups names PermissionsHelper.requestPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, R.string.permission_external_storage, activity.findViewById(R.id.crouton_handle), () -> export(v)); return false; }); } // Import notes Preference importData = findPreference("settings_import_data"); if (importData != null) { importData.setOnPreferenceClickListener(arg0 -> { // Finds actually saved backups names PermissionsHelper.requestPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE, R.string.permission_external_storage, activity.findViewById(R.id.crouton_handle), this::importNotes); return false; }); } // Import notes from Springpad export zip file Preference importFromSpringpad = findPreference("settings_import_from_springpad"); if (importFromSpringpad != null) { importFromSpringpad.setOnPreferenceClickListener(arg0 -> { Intent intent; intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("application/zip"); if (!IntentChecker.isAvailable(getActivity(), intent, null)) { Toast.makeText(getActivity(), R.string.feature_not_available_on_this_device, Toast.LENGTH_SHORT) .show(); return false; } startActivityForResult(intent, SPRINGPAD_IMPORT); return false; }); } // Preference syncWithDrive = findPreference("settings_backup_drive"); // importFromSpringpad.setOnPreferenceClickListener(new OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference arg0) { // Intent intent; // intent = new Intent(Intent.ACTION_GET_CONTENT); // intent.addCategory(Intent.CATEGORY_OPENABLE); // intent.setType("application/zip"); // if (!IntentChecker.isAvailable(getActivity(), intent, null)) { // Crouton.makeText(getActivity(), R.string.feature_not_available_on_this_device, // ONStyle.ALERT).show(); // return false; // } // startActivityForResult(intent, SPRINGPAD_IMPORT); // return false; // } // }); // Swiping action final SwitchPreference swipeToTrash = (SwitchPreference) findPreference("settings_swipe_to_trash"); if (swipeToTrash != null) { if (prefs.getBoolean("settings_swipe_to_trash", false)) { swipeToTrash.setChecked(true); swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_2)); } else { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_1)); swipeToTrash.setChecked(false); } swipeToTrash.setOnPreferenceChangeListener((preference, newValue) -> { if ((Boolean) newValue) { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_2)); } else { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_1)); } swipeToTrash.setChecked((Boolean) newValue); return false; }); } // Show uncategorized notes in menu final SwitchPreference showUncategorized = (SwitchPreference) findPreference( Constants.PREF_SHOW_UNCATEGORIZED); if (showUncategorized != null) { showUncategorized.setOnPreferenceChangeListener((preference, newValue) -> { showUncategorized.setChecked((Boolean) newValue); return false; }); } // Show Automatically adds location to new notes final SwitchPreference autoLocation = (SwitchPreference) findPreference(Constants.PREF_AUTO_LOCATION); if (autoLocation != null) { autoLocation.setOnPreferenceChangeListener((preference, newValue) -> { autoLocation.setChecked((Boolean) newValue); return false; }); } // Maximum video attachment size final EditTextPreference maxVideoSize = (EditTextPreference) findPreference("settings_max_video_size"); if (maxVideoSize != null) { String maxVideoSizeValue = prefs.getString("settings_max_video_size", getString(R.string.not_set)); maxVideoSize.setSummary( getString(R.string.settings_max_video_size_summary) + ": " + String.valueOf(maxVideoSizeValue)); maxVideoSize.setOnPreferenceChangeListener((preference, newValue) -> { maxVideoSize.setSummary( getString(R.string.settings_max_video_size_summary) + ": " + String.valueOf(newValue)); prefs.edit().putString("settings_max_video_size", newValue.toString()).commit(); return false; }); } // Set notes' protection password Preference password = findPreference("settings_password"); if (password != null) { password.setOnPreferenceClickListener(preference -> { Intent passwordIntent = new Intent(getActivity(), PasswordActivity.class); startActivity(passwordIntent); return false; }); } // Use password to grant application access final SwitchPreference passwordAccess = (SwitchPreference) findPreference("settings_password_access"); if (passwordAccess != null) { if (prefs.getString(Constants.PREF_PASSWORD, null) == null) { passwordAccess.setEnabled(false); passwordAccess.setChecked(false); } else { passwordAccess.setEnabled(true); } passwordAccess.setOnPreferenceChangeListener((preference, newValue) -> { BaseActivity.requestPassword(getActivity(), passwordConfirmed -> { if (passwordConfirmed) { passwordAccess.setChecked((Boolean) newValue); } }); return false; }); } // Languages ListPreference lang = (ListPreference) findPreference("settings_language"); if (lang != null) { String languageName = getResources().getConfiguration().locale.getDisplayName(); lang.setSummary(languageName.substring(0, 1).toUpperCase(getResources().getConfiguration().locale) + languageName.substring(1, languageName.length())); lang.setOnPreferenceChangeListener((preference, value) -> { OmniNotes.updateLanguage(getActivity(), value.toString()); MiscUtils.restartApp(getActivity().getApplicationContext(), MainActivity.class); return false; }); } // Text size final ListPreference textSize = (ListPreference) findPreference("settings_text_size"); if (textSize != null) { int textSizeIndex = textSize.findIndexOfValue(prefs.getString("settings_text_size", "default")); String textSizeString = getResources().getStringArray(R.array.text_size)[textSizeIndex]; textSize.setSummary(textSizeString); textSize.setOnPreferenceChangeListener((preference, newValue) -> { int textSizeIndex1 = textSize.findIndexOfValue(newValue.toString()); String checklistString = getResources().getStringArray(R.array.text_size)[textSizeIndex1]; textSize.setSummary(checklistString); prefs.edit().putString("settings_text_size", newValue.toString()).commit(); textSize.setValueIndex(textSizeIndex1); return false; }); } // Application's colors final ListPreference colorsApp = (ListPreference) findPreference("settings_colors_app"); if (colorsApp != null) { int colorsAppIndex = colorsApp .findIndexOfValue(prefs.getString("settings_colors_app", Constants.PREF_COLORS_APP_DEFAULT)); String colorsAppString = getResources().getStringArray(R.array.colors_app)[colorsAppIndex]; colorsApp.setSummary(colorsAppString); colorsApp.setOnPreferenceChangeListener((preference, newValue) -> { int colorsAppIndex1 = colorsApp.findIndexOfValue(newValue.toString()); String colorsAppString1 = getResources().getStringArray(R.array.colors_app)[colorsAppIndex1]; colorsApp.setSummary(colorsAppString1); prefs.edit().putString("settings_colors_app", newValue.toString()).commit(); colorsApp.setValueIndex(colorsAppIndex1); return false; }); } // Checklists final ListPreference checklist = (ListPreference) findPreference("settings_checked_items_behavior"); if (checklist != null) { int checklistIndex = checklist .findIndexOfValue(prefs.getString("settings_checked_items_behavior", "0")); String checklistString = getResources().getStringArray(R.array.checked_items_behavior)[checklistIndex]; checklist.setSummary(checklistString); checklist.setOnPreferenceChangeListener((preference, newValue) -> { int checklistIndex1 = checklist.findIndexOfValue(newValue.toString()); String checklistString1 = getResources() .getStringArray(R.array.checked_items_behavior)[checklistIndex1]; checklist.setSummary(checklistString1); prefs.edit().putString("settings_checked_items_behavior", newValue.toString()).commit(); checklist.setValueIndex(checklistIndex1); return false; }); } // Widget's colors final ListPreference colorsWidget = (ListPreference) findPreference("settings_colors_widget"); if (colorsWidget != null) { int colorsWidgetIndex = colorsWidget .findIndexOfValue(prefs.getString("settings_colors_widget", Constants.PREF_COLORS_APP_DEFAULT)); String colorsWidgetString = getResources().getStringArray(R.array.colors_widget)[colorsWidgetIndex]; colorsWidget.setSummary(colorsWidgetString); colorsWidget.setOnPreferenceChangeListener((preference, newValue) -> { int colorsWidgetIndex1 = colorsWidget.findIndexOfValue(newValue.toString()); String colorsWidgetString1 = getResources() .getStringArray(R.array.colors_widget)[colorsWidgetIndex1]; colorsWidget.setSummary(colorsWidgetString1); prefs.edit().putString("settings_colors_widget", newValue.toString()).commit(); colorsWidget.setValueIndex(colorsWidgetIndex1); return false; }); } // Notification snooze delay final EditTextPreference snoozeDelay = (EditTextPreference) findPreference( "settings_notification_snooze_delay"); if (snoozeDelay != null) { String snooze = prefs.getString("settings_notification_snooze_delay", Constants.PREF_SNOOZE_DEFAULT); snooze = TextUtils.isEmpty(snooze) ? Constants.PREF_SNOOZE_DEFAULT : snooze; snoozeDelay.setSummary(String.valueOf(snooze) + " " + getString(R.string.minutes)); snoozeDelay.setOnPreferenceChangeListener((preference, newValue) -> { String snoozeUpdated = TextUtils.isEmpty(String.valueOf(newValue)) ? Constants.PREF_SNOOZE_DEFAULT : String.valueOf(newValue); snoozeDelay.setSummary(snoozeUpdated + " " + getString(R.string.minutes)); prefs.edit().putString("settings_notification_snooze_delay", snoozeUpdated).apply(); return false; }); } // NotificationServiceListener shortcut final Preference norificationServiceListenerPreference = findPreference( "settings_notification_service_listener"); if (norificationServiceListenerPreference != null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { getPreferenceScreen().removePreference(norificationServiceListenerPreference); } } // Changelog Preference changelog = findPreference("settings_changelog"); if (changelog != null) { changelog.setOnPreferenceClickListener(arg0 -> { AnalyticsHelper.trackEvent(AnalyticsHelper.CATEGORIES.SETTING, "settings_changelog"); new MaterialDialog.Builder(activity).customView(R.layout.activity_changelog, false) .positiveText(R.string.ok).build().show(); return false; }); // Retrieval of installed app version to write it as summary PackageInfo pInfo; String versionString = ""; try { pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0); versionString = pInfo.versionName; } catch (NameNotFoundException e) { Log.e(Constants.TAG, "Error retrieving version", e); } changelog.setSummary(versionString); } // Settings reset Preference resetData = findPreference("reset_all_data"); if (resetData != null) { resetData.setOnPreferenceClickListener(arg0 -> { new MaterialDialog.Builder(activity).content(R.string.reset_all_data_confirmation) .positiveText(R.string.confirm).callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { prefs.edit().clear().commit(); File db = getActivity().getDatabasePath(Constants.DATABASE_NAME); StorageHelper.delete(getActivity(), db.getAbsolutePath()); File attachmentsDir = StorageHelper.getAttachmentDir(getActivity()); StorageHelper.delete(getActivity(), attachmentsDir.getAbsolutePath()); File cacheDir = StorageHelper.getCacheDir(getActivity()); StorageHelper.delete(getActivity(), cacheDir.getAbsolutePath()); MiscUtils.restartApp(getActivity().getApplicationContext(), MainActivity.class); } }).build().show(); return false; }); } // Instructions Preference instructions = findPreference("settings_tour_show_again"); if (instructions != null) { instructions.setOnPreferenceClickListener(arg0 -> { new MaterialDialog.Builder(getActivity()) .content(getString(R.string.settings_tour_show_again_summary) + "?") .positiveText(R.string.confirm).callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog materialDialog) { AnalyticsHelper.trackEvent(AnalyticsHelper.CATEGORIES.SETTING, "settings_tour_show_again"); prefs.edit().putBoolean(Constants.PREF_TOUR_COMPLETE, false).commit(); MiscUtils.restartApp(getActivity().getApplicationContext(), MainActivity.class); } }).build().show(); return false; }); } // Donations // Preference donation = findPreference("settings_donation"); // if (donation != null) { // donation.setOnPreferenceClickListener(new OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference preference) { // AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // // ArrayList<ImageAndTextItem> options = new ArrayList<ImageAndTextItem>(); // options.add(new ImageAndTextItem(R.drawable.ic_paypal, getString(R.string.paypal))); // options.add(new ImageAndTextItem(R.drawable.ic_bitcoin, getString(R.string.bitcoin))); // // alertDialogBuilder // .setAdapter(new ImageAndTextAdapter(getActivity(), options), // new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // switch (which) { // case 0: // Intent intentPaypal = new Intent(Intent.ACTION_VIEW); // intentPaypal.setData(Uri.parse(getString(R.string.paypal_url))); // startActivity(intentPaypal); // break; // case 1: // Intent intentBitcoin = new Intent(Intent.ACTION_VIEW); // intentBitcoin.setData(Uri.parse(getString(R.string.bitcoin_url))); // startActivity(intentBitcoin); // break; // } // } // }); // // // // create alert dialog // AlertDialog alertDialog = alertDialogBuilder.create(); // // show it // alertDialog.show(); // return false; // } // }); // } }
From source file:com.dycody.android.idealnote.SettingsFragment.java
@SuppressWarnings("deprecation") @Override//from w w w. j a v a2 s . co m public void onResume() { super.onResume(); // Export notes Preference export = findPreference("settings_export_data"); if (export != null) { export.setOnPreferenceClickListener(arg0 -> { // Inflate layout LayoutInflater inflater = getActivity().getLayoutInflater(); View v = inflater.inflate(R.layout.dialog_backup_layout, null); // Finds actually saved backups names PermissionsHelper.requestPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, R.string.permission_external_storage, activity.findViewById(R.id.crouton_handle), () -> export(v)); return false; }); } // Import notes Preference importData = findPreference("settings_import_data"); if (importData != null) { importData.setOnPreferenceClickListener(arg0 -> { importNotes(); return false; }); } // Import notes from Springpad export zip file Preference importFromSpringpad = findPreference("settings_import_from_springpad"); if (importFromSpringpad != null) { importFromSpringpad.setOnPreferenceClickListener(arg0 -> { Intent intent; intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("application/zip"); if (!IntentChecker.isAvailable(getActivity(), intent, null)) { Toast.makeText(getActivity(), R.string.feature_not_available_on_this_device, Toast.LENGTH_SHORT) .show(); return false; } startActivityForResult(intent, SPRINGPAD_IMPORT); return false; }); } // Preference syncWithDrive = findPreference("settings_backup_drive"); // importFromSpringpad.setOnPreferenceClickListener(new OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference arg0) { // Intent intent; // intent = new Intent(Intent.ACTION_GET_CONTENT); // intent.addCategory(Intent.CATEGORY_OPENABLE); // intent.setType("application/zip"); // if (!IntentChecker.isAvailable(getActivity(), intent, null)) { // Crouton.makeText(getActivity(), R.string.feature_not_available_on_this_device, // ONStyle.ALERT).show(); // return false; // } // startActivityForResult(intent, SPRINGPAD_IMPORT); // return false; // } // }); // Swiping action final SwitchPreference swipeToTrash = (SwitchPreference) findPreference("settings_swipe_to_trash"); if (swipeToTrash != null) { if (prefs.getBoolean("settings_swipe_to_trash", false)) { swipeToTrash.setChecked(true); swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_2)); } else { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_1)); swipeToTrash.setChecked(false); } swipeToTrash.setOnPreferenceChangeListener((preference, newValue) -> { if ((Boolean) newValue) { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_2)); } else { swipeToTrash.setSummary(getResources().getString(R.string.settings_swipe_to_trash_summary_1)); } swipeToTrash.setChecked((Boolean) newValue); return false; }); } // Show uncategorized notes in menu final SwitchPreference showUncategorized = (SwitchPreference) findPreference( Constants.PREF_SHOW_UNCATEGORIZED); if (showUncategorized != null) { showUncategorized.setOnPreferenceChangeListener((preference, newValue) -> { showUncategorized.setChecked((Boolean) newValue); return false; }); } // Show Automatically adds location to new notes final SwitchPreference autoLocation = (SwitchPreference) findPreference(Constants.PREF_AUTO_LOCATION); if (autoLocation != null) { autoLocation.setOnPreferenceChangeListener((preference, newValue) -> { autoLocation.setChecked((Boolean) newValue); return false; }); } // Maximum video attachment size final EditTextPreference maxVideoSize = (EditTextPreference) findPreference("settings_max_video_size"); if (maxVideoSize != null) { String maxVideoSizeValue = prefs.getString("settings_max_video_size", getString(R.string.not_set)); maxVideoSize.setSummary( getString(R.string.settings_max_video_size_summary) + ": " + String.valueOf(maxVideoSizeValue)); maxVideoSize.setOnPreferenceChangeListener((preference, newValue) -> { maxVideoSize.setSummary( getString(R.string.settings_max_video_size_summary) + ": " + String.valueOf(newValue)); prefs.edit().putString("settings_max_video_size", newValue.toString()).commit(); return false; }); } // Set notes' protection password Preference password = findPreference("settings_password"); if (password != null) { password.setOnPreferenceClickListener(preference -> { Intent passwordIntent = new Intent(getActivity(), PasswordActivity.class); startActivity(passwordIntent); return false; }); } // Use password to grant application access final SwitchPreference passwordAccess = (SwitchPreference) findPreference("settings_password_access"); if (passwordAccess != null) { if (prefs.getString(Constants.PREF_PASSWORD, null) == null) { passwordAccess.setEnabled(false); passwordAccess.setChecked(false); } else { passwordAccess.setEnabled(true); } passwordAccess.setOnPreferenceChangeListener((preference, newValue) -> { PasswordHelper.requestPassword(getActivity(), passwordConfirmed -> { if (passwordConfirmed) { passwordAccess.setChecked((Boolean) newValue); } }); return false; }); } // Languages ListPreference lang = (ListPreference) findPreference("settings_language"); if (lang != null) { String languageName = getResources().getConfiguration().locale.getDisplayName(); lang.setSummary(languageName.substring(0, 1).toUpperCase(getResources().getConfiguration().locale) + languageName.substring(1, languageName.length())); lang.setOnPreferenceChangeListener((preference, value) -> { IdealNote.updateLanguage(getActivity(), value.toString()); SystemHelper.restartApp(getActivity().getApplicationContext(), MainActivity.class); return false; }); } // Text size final ListPreference textSize = (ListPreference) findPreference("settings_text_size"); if (textSize != null) { int textSizeIndex = textSize.findIndexOfValue(prefs.getString("settings_text_size", "default")); String textSizeString = getResources().getStringArray(R.array.text_size)[textSizeIndex]; textSize.setSummary(textSizeString); textSize.setOnPreferenceChangeListener((preference, newValue) -> { int textSizeIndex1 = textSize.findIndexOfValue(newValue.toString()); String checklistString = getResources().getStringArray(R.array.text_size)[textSizeIndex1]; textSize.setSummary(checklistString); prefs.edit().putString("settings_text_size", newValue.toString()).commit(); textSize.setValueIndex(textSizeIndex1); return false; }); } // Application's colors final ListPreference colorsApp = (ListPreference) findPreference("settings_colors_app"); if (colorsApp != null) { int colorsAppIndex = colorsApp .findIndexOfValue(prefs.getString("settings_colors_app", Constants.PREF_COLORS_APP_DEFAULT)); String colorsAppString = getResources().getStringArray(R.array.colors_app)[colorsAppIndex]; colorsApp.setSummary(colorsAppString); colorsApp.setOnPreferenceChangeListener((preference, newValue) -> { int colorsAppIndex1 = colorsApp.findIndexOfValue(newValue.toString()); String colorsAppString1 = getResources().getStringArray(R.array.colors_app)[colorsAppIndex1]; colorsApp.setSummary(colorsAppString1); prefs.edit().putString("settings_colors_app", newValue.toString()).commit(); colorsApp.setValueIndex(colorsAppIndex1); return false; }); } // Checklists final ListPreference checklist = (ListPreference) findPreference("settings_checked_items_behavior"); if (checklist != null) { int checklistIndex = checklist .findIndexOfValue(prefs.getString("settings_checked_items_behavior", "0")); String checklistString = getResources().getStringArray(R.array.checked_items_behavior)[checklistIndex]; checklist.setSummary(checklistString); checklist.setOnPreferenceChangeListener((preference, newValue) -> { int checklistIndex1 = checklist.findIndexOfValue(newValue.toString()); String checklistString1 = getResources() .getStringArray(R.array.checked_items_behavior)[checklistIndex1]; checklist.setSummary(checklistString1); prefs.edit().putString("settings_checked_items_behavior", newValue.toString()).commit(); checklist.setValueIndex(checklistIndex1); return false; }); } // Widget's colors final ListPreference colorsWidget = (ListPreference) findPreference("settings_colors_widget"); if (colorsWidget != null) { int colorsWidgetIndex = colorsWidget .findIndexOfValue(prefs.getString("settings_colors_widget", Constants.PREF_COLORS_APP_DEFAULT)); String colorsWidgetString = getResources().getStringArray(R.array.colors_widget)[colorsWidgetIndex]; colorsWidget.setSummary(colorsWidgetString); colorsWidget.setOnPreferenceChangeListener((preference, newValue) -> { int colorsWidgetIndex1 = colorsWidget.findIndexOfValue(newValue.toString()); String colorsWidgetString1 = getResources() .getStringArray(R.array.colors_widget)[colorsWidgetIndex1]; colorsWidget.setSummary(colorsWidgetString1); prefs.edit().putString("settings_colors_widget", newValue.toString()).commit(); colorsWidget.setValueIndex(colorsWidgetIndex1); return false; }); } // Notification snooze delay final EditTextPreference snoozeDelay = (EditTextPreference) findPreference( "settings_notification_snooze_delay"); if (snoozeDelay != null) { String snooze = prefs.getString("settings_notification_snooze_delay", Constants.PREF_SNOOZE_DEFAULT); snooze = TextUtils.isEmpty(snooze) ? Constants.PREF_SNOOZE_DEFAULT : snooze; snoozeDelay.setSummary(String.valueOf(snooze) + " " + getString(R.string.minutes)); snoozeDelay.setOnPreferenceChangeListener((preference, newValue) -> { String snoozeUpdated = TextUtils.isEmpty(String.valueOf(newValue)) ? Constants.PREF_SNOOZE_DEFAULT : String.valueOf(newValue); snoozeDelay.setSummary(snoozeUpdated + " " + getString(R.string.minutes)); prefs.edit().putString("settings_notification_snooze_delay", snoozeUpdated).apply(); return false; }); } // NotificationServiceListener shortcut final Preference norificationServiceListenerPreference = findPreference( "settings_notification_service_listener"); if (norificationServiceListenerPreference != null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { getPreferenceScreen().removePreference(norificationServiceListenerPreference); } } // Changelog Preference changelog = findPreference("settings_changelog"); if (changelog != null) { changelog.setOnPreferenceClickListener(arg0 -> { ((IdealNote) getActivity().getApplication()).getAnalyticsHelper() .trackEvent(AnalyticsHelper.CATEGORIES.SETTING, "settings_changelog"); new MaterialDialog.Builder(activity).customView(R.layout.activity_changelog, false) .positiveText(R.string.ok).build().show(); return false; }); // Retrieval of installed app version to write it as summary PackageInfo pInfo; String versionString = ""; try { pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0); versionString = pInfo.versionName + getString(R.string.version_postfix); } catch (NameNotFoundException e) { Log.e(Constants.TAG, "Error retrieving version", e); } changelog.setSummary(versionString); } // Settings reset Preference resetData = findPreference("reset_all_data"); if (resetData != null) { resetData.setOnPreferenceClickListener(arg0 -> { new MaterialDialog.Builder(activity).content(R.string.reset_all_data_confirmation) .positiveText(R.string.confirm).callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { prefs.edit().clear().commit(); File db = getActivity().getDatabasePath(Constants.DATABASE_NAME); StorageHelper.delete(getActivity(), db.getAbsolutePath()); File attachmentsDir = StorageHelper.getAttachmentDir(getActivity()); StorageHelper.delete(getActivity(), attachmentsDir.getAbsolutePath()); File cacheDir = StorageHelper.getCacheDir(getActivity()); StorageHelper.delete(getActivity(), cacheDir.getAbsolutePath()); SystemHelper.restartApp(getActivity().getApplicationContext(), MainActivity.class); } }).build().show(); return false; }); } // Instructions Preference instructions = findPreference("settings_tour_show_again"); if (instructions != null) { instructions.setOnPreferenceClickListener(arg0 -> { new MaterialDialog.Builder(getActivity()) .content(getString(R.string.settings_tour_show_again_summary) + "?") .positiveText(R.string.confirm).callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog materialDialog) { ((IdealNote) getActivity().getApplication()).getAnalyticsHelper() .trackEvent(AnalyticsHelper.CATEGORIES.SETTING, "settings_tour_show_again"); prefs.edit().putBoolean(Constants.PREF_TOUR_COMPLETE, false).commit(); SystemHelper.restartApp(getActivity().getApplicationContext(), MainActivity.class); } }).build().show(); return false; }); } // Donations // Preference donation = findPreference("settings_donation"); // if (donation != null) { // donation.setOnPreferenceClickListener(new OnPreferenceClickListener() { // @Override // public boolean onPreferenceClick(Preference preference) { // AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); // // ArrayList<ImageAndTextItem> options = new ArrayList<ImageAndTextItem>(); // options.add(new ImageAndTextItem(R.drawable.ic_paypal, getString(R.string.paypal))); // options.add(new ImageAndTextItem(R.drawable.ic_bitcoin, getString(R.string.bitcoin))); // // alertDialogBuilder // .setAdapter(new ImageAndTextAdapter(getActivity(), options), // new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // switch (which) { // case 0: // Intent intentPaypal = new Intent(Intent.ACTION_VIEW); // intentPaypal.setData(Uri.parse(getString(R.string.paypal_url))); // startActivity(intentPaypal); // break; // case 1: // Intent intentBitcoin = new Intent(Intent.ACTION_VIEW); // intentBitcoin.setData(Uri.parse(getString(R.string.bitcoin_url))); // startActivity(intentBitcoin); // break; // } // } // }); // // // // create alert dialog // AlertDialog alertDialog = alertDialogBuilder.create(); // // show it // alertDialog.show(); // return false; // } // }); // } }