List of usage examples for android.preference SwitchPreference setOnPreferenceChangeListener
public void setOnPreferenceChangeListener(OnPreferenceChangeListener onPreferenceChangeListener)
From source file:com.oakesville.mythling.prefs.PlaybackPrefs.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getActivity().getActionBar().setTitle(R.string.title_playback_settings); addPreferencesFromResource(R.xml.playback_prefs); // none of these prefs trigger cache refresh AppSettings appSettings = new AppSettings(getPreferenceScreen().getContext()); SwitchPreference swPref = (SwitchPreference) getPreferenceScreen() .findPreference(AppSettings.FRONTEND_PLAYBACK); swPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { doCategoryEnablement(!Boolean.valueOf(newValue.toString())); return true; }/*from w w w.java 2s . c om*/ }); doCategoryEnablement(appSettings.isDevicePlayback()); Preference pref = getPreferenceScreen().findPreference(AppSettings.ALWAYS_PROMPT_FOR_PLAYBACK_OPTIONS); pref.setOnPreferenceChangeListener(new PrefChangeListener(false, false) { public boolean onPreferenceChange(Preference preference, Object newValue) { boolean update = super.onPreferenceChange(preference, newValue); if (Boolean.parseBoolean(newValue.toString())) { AppSettings settings = new AppSettings(getPreferenceScreen().getContext()); try { settings.getPlaybackOptions().clearAlwaysDoThisSettings(); } catch (JSONException ex) { Log.e(TAG, ex.getMessage(), ex); if (settings.isErrorReportingEnabled()) new Reporter(ex).send(); settings.getPlaybackOptions().clearAll(); } } return update; } }); pref = getPreferenceScreen().findPreference(AppSettings.SKIP_BACK_INTERVAL); pref.setOnPreferenceChangeListener(new PrefChangeListener(true, false, getString(R.string.seconds))); pref.setSummary("" + appSettings.getSkipBackInterval() + " " + getString(R.string.seconds)); pref = getPreferenceScreen().findPreference(AppSettings.SKIP_FORWARD_INTERVAL); pref.setOnPreferenceChangeListener(new PrefChangeListener(true, false, getString(R.string.seconds))); pref.setSummary("" + appSettings.getSkipForwardInterval() + " " + getString(R.string.seconds)); pref = getPreferenceScreen().findPreference(AppSettings.JUMP_INTERVAL); pref.setOnPreferenceChangeListener(new PrefChangeListener(true, false, getString(R.string.seconds))); pref.setSummary("" + appSettings.getJumpInterval() + " " + getString(R.string.seconds)); pref = getPreferenceScreen().findPreference(AppSettings.AUTO_SKIP); pref.setOnPreferenceChangeListener( new PrefChangeListener(true, false, R.array.auto_skip_values, R.array.auto_skip_entries) { public boolean onPreferenceChange(Preference preference, Object newValue) { super.onPreferenceChange(preference, newValue); if (!AppSettings.AUTO_SKIP_OFF.equals(newValue.toString())) { AppSettings settings = new AppSettings(getPreferenceScreen().getContext()); int scTol = settings.getSeekCorrectionTolerance(); if (scTol == 0) { settings.setSeekCorrectionTolerance(3); getPreferenceScreen().findPreference(AppSettings.SEEK_CORRECTION_TOLERANCE) .setSummary("3"); ; } } return true; } }); pref.setSummary(Localizer.getStringArrayEntry(R.array.auto_skip_values, R.array.auto_skip_entries, appSettings.getAutoSkip())); pref = getPreferenceScreen().findPreference(AppSettings.SEEK_CORRECTION_TOLERANCE); pref.setOnPreferenceChangeListener(new PrefChangeListener(true, false, getString(R.string.seconds))); pref.setSummary("" + appSettings.getSeekCorrectionTolerance() + " " + getString(R.string.seconds)); pref = getPreferenceScreen().findPreference(AppSettings.LIBVLC_PARAMETERS); pref.setOnPreferenceChangeListener(new PrefChangeListener(true, false)); pref.setSummary(appSettings.getLibVlcParameters()); swPref = (SwitchPreference) getPreferenceScreen().findPreference(AppSettings.INTERNAL_MUSIC_PLAYER); swPref.setOnPreferenceChangeListener(new PrefChangeListener(false, false)); pref = getPreferenceScreen().findPreference(AppSettings.MYTH_FRONTEND_HOST); pref.setOnPreferenceChangeListener(new PrefChangeListener(true, false)); pref.setSummary(appSettings.getFrontendHost()); pref = getPreferenceScreen().findPreference(AppSettings.MYTH_FRONTEND_SOCKET_PORT); pref.setOnPreferenceChangeListener(new PrefChangeListener(true, false)); pref.setSummary("" + appSettings.getFrontendSocketPort()); pref = getPreferenceScreen().findPreference(AppSettings.MYTH_FRONTEND_SERVICE_PORT); pref.setOnPreferenceChangeListener(new PrefChangeListener(true, false)); pref.setSummary("" + appSettings.getFrontendServicePort()); }
From source file:com.wolkabout.hexiwear.fragment.HexiwearSettingsFragment.java
@AfterPreferences void initPrefs() { SettingsActivity settingsActivity = (SettingsActivity) getActivity(); device = settingsActivity.device;//from w w w .j ava 2s .co m displayPreferences = hexiwearDevices.getDisplayPreferences(device.getDeviceAddress()); for (Map.Entry<String, Boolean> entry : displayPreferences.entrySet()) { Log.d(TAG, "Key: " + entry.getKey() + " value " + entry.getValue()); final SwitchPreference displayPref = (SwitchPreference) findPreference(entry.getKey()); if (displayPref != null) { displayPref.setChecked(entry.getValue()); displayPref.setOnPreferenceChangeListener(this); } } final String interval = String.format(getActivity().getString(R.string.preferences_publish_interval_value), hexiwearDevices.getPublishInterval(device)); publishInterval.setSummary(interval); publishInterval.setOnPreferenceChangeListener(this); keepAlive.setChecked(hexiwearDevices.shouldKeepAlive(device)); keepAlive.setOnPreferenceChangeListener(this); publish.setChecked(hexiwearDevices.shouldTransmit(device)); publish.setOnPreferenceChangeListener(this); manufacturerInfo.setSummary(settingsActivity.manufacturerInfo.manufacturer); fwVersion.setSummary(settingsActivity.manufacturerInfo.firmwareRevision); getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); }
From source file:com.juegoteca.actividades.Opciones.java
/** * Shows the simplified settings UI if the device configuration if the * device configuration dictates that a simplified, single-pane UI should be * shown.//from w w w. j av a 2 s . c o m */ @SuppressWarnings("deprecation") private void setupSimplePreferencesScreen() { if (!isSimplePreferences(this)) { return; } final SharedPreferences settings = getSharedPreferences("UserInfo", 0); // In the simplified UI, fragments are not used at all and we instead // use the older PreferenceActivity APIs. addPreferencesFromResource(R.xml.pref_container); // Add 'general' preferences. PreferenceCategory fakeHeader = new PreferenceCategory(this); fakeHeader.setTitle(R.string.pref_header_general); getPreferenceScreen().addPreference(fakeHeader); addPreferencesFromResource(R.xml.pref_general); CheckBoxPreference preferenciaOrden = (CheckBoxPreference) findPreference("orden_ultimos_anadidos"); preferenciaOrden.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { if (newValue.toString().equals("true")) { SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("orden_ultimos_fecha_compra", true); editor.commit(); } else { SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("orden_ultimos_fecha_compra", false); editor.commit(); } return true; } }); ListPreference preferenciaModeda = (ListPreference) findPreference("currencys"); preferenciaModeda.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { SharedPreferences.Editor editor = settings.edit(); editor.putString("currency", newValue.toString()); editor.commit(); return true; } }); CheckBoxPreference preferenciaDetalle = (CheckBoxPreference) findPreference("detalle_imagen"); preferenciaDetalle.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { if (newValue.toString().equals("true")) { SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("detalle_imagen", true); editor.commit(); } else { SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("detalle_imagen", false); editor.commit(); } return true; } }); SwitchPreference preferenciaTwitter = (SwitchPreference) findPreference("twitter"); preferenciaTwitter.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (newValue instanceof Boolean) { boolean isChecked = (boolean) newValue; if (isChecked) { Intent intent = new Intent(getApplicationContext(), TwitterActivity.class); startActivity(intent); return true; } } return true; } }); // Add 'data and sync' preferences, and a corresponding header. PreferenceCategory fakeHeader2 = new PreferenceCategory(this); fakeHeader2.setTitle(R.string.pref_header_data); getPreferenceScreen().addPreference(fakeHeader2); addPreferencesFromResource(R.xml.pref_datos_seguridad); // Establece las acciones al hacer click en las preferencias Preference preferenciaCopiaExportar = findPreference("exportar_copia_seguridad"); preferenciaCopiaExportar.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Toast t; if (!utilidades.baseDatosEsVacia()) { new CopiaSeguridadFichero().execute(); } else { t = Toast.makeText(getApplicationContext(), getString(R.string.no_data_backup), Toast.LENGTH_SHORT); t.show(); } return true; } }); Preference preferenciaCopiaImportar = findPreference("importar_restaurar_seguridad"); preferenciaCopiaImportar.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { AlertDialog.Builder builder = new AlertDialog.Builder(Opciones.this); builder.setMessage(R.string.alerta_restaurar_texto).setTitle(R.string.alerta_restaurar_titulo); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("application/zip"); intent.addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(Intent.createChooser(intent, "Escoja el fichero de copia..."), FILE_SELECT_CODE); } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // User cancelled the dialog return; } }); AlertDialog dialog = builder.create(); dialog.show(); return true; } }); Preference preferenciaBorrar = findPreference("borrar_todo"); preferenciaBorrar.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { utilidades.borrarTodosDatos(true); return true; } }); // Add 'otros' preferences. PreferenceCategory fakeHeader3 = new PreferenceCategory(this); fakeHeader3.setTitle(R.string.pref_header_otros); getPreferenceScreen().addPreference(fakeHeader3); addPreferencesFromResource(R.xml.pref_otros); Resources res = getResources(); // String versionName = res.getString(R.string.app_version); String versionName = ""; try { versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; } catch (NameNotFoundException e) { // versionName = res.getString(R.string.app_version); } String version = res.getString(R.string.pref_title_version, versionName); Preference preferenciaInicioSesion = findPreference("about"); preferenciaInicioSesion.setTitle(version); Preference preferenciaLicencia = findPreference("licenses"); preferenciaLicencia.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(getApplicationContext(), AcercaDe.class); startActivity(intent); return true; } }); }
From source file:it.feio.android.omninotes.SettingsFragment.java
@SuppressWarnings("deprecation") @Override/* ww w .java2s . c o 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 -> { // 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// ww w. j a v a2s. 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; // } // }); // } }
From source file:nl.hnogames.domoticz.Preference.Preference.java
private void setPreferences() { final android.preference.SwitchPreference MultiServerPreference = (android.preference.SwitchPreference) findPreference( "enableMultiServers"); android.preference.Preference ServerSettings = findPreference("server_settings"); android.preference.Preference PermissionsSettings = findPreference("permissionssettings"); android.preference.Preference NotificationLogged = findPreference("notification_show_logs"); android.preference.Preference fetchServerConfig = findPreference("server_force_fetch_config"); android.preference.Preference resetApplication = findPreference("reset_settings"); android.preference.ListPreference displayLanguage = (ListPreference) findPreference("displayLanguage"); final android.preference.Preference registrationId = findPreference("notification_registration_id"); android.preference.Preference GeoSettings = findPreference("geo_settings"); android.preference.SwitchPreference WearPreference = (android.preference.SwitchPreference) findPreference( "enableWearItems"); android.preference.Preference NFCPreference = findPreference("nfc_settings"); android.preference.Preference QRCodePreference = findPreference("qrcode_settings"); android.preference.Preference SpeechPreference = findPreference("speech_settings"); android.preference.SwitchPreference EnableNFCPreference = (android.preference.SwitchPreference) findPreference( "enableNFC"); android.preference.SwitchPreference EnableQRCodePreference = (android.preference.SwitchPreference) findPreference( "enableQRCode"); android.preference.SwitchPreference EnableSpeechPreference = (android.preference.SwitchPreference) findPreference( "enableSpeech"); android.preference.SwitchPreference EnableTalkBackPreference = (android.preference.SwitchPreference) findPreference( "talkBack"); MultiSelectListPreference drawerItems = (MultiSelectListPreference) findPreference("enable_menu_items"); @SuppressWarnings("SpellCheckingInspection") android.preference.SwitchPreference AlwaysOnPreference = (android.preference.SwitchPreference) findPreference( "alwayson"); @SuppressWarnings("SpellCheckingInspection") android.preference.PreferenceScreen preferenceScreen = (android.preference.PreferenceScreen) findPreference( "settingsscreen"); android.preference.PreferenceCategory premiumCategory = (android.preference.PreferenceCategory) findPreference( "premium_category"); android.preference.Preference premiumPreference = findPreference("premium_settings"); NotificationsMultiSelectListPreference notificationsMultiSelectListPreference = (NotificationsMultiSelectListPreference) findPreference( "suppressNotifications"); NotificationsMultiSelectListPreference alarmMultiSelectListPreference = (NotificationsMultiSelectListPreference) findPreference( "alarmNotifications"); android.preference.SwitchPreference ThemePreference = (android.preference.SwitchPreference) findPreference( "darkTheme"); android.preference.Preference FingerPrintSettingsPreference = findPreference("SecuritySettings"); android.preference.SwitchPreference FingerPrintPreference = (android.preference.SwitchPreference) findPreference( "enableSecurity"); if (!BuildConfig.DEBUG) { PreferenceCategory oAndroidAutoCategory = (android.preference.PreferenceCategory) findPreference( "androidautocategory"); PreferenceScreen oNotificationScreen = (android.preference.PreferenceScreen) findPreference( "notificationscreen"); oNotificationScreen.removePreference(oAndroidAutoCategory); }/* w ww . j a v a2 s .com*/ List<String> notifications = mSharedPrefs.getReceivedNotifications(); if (notifications == null || notifications.size() <= 0) { notificationsMultiSelectListPreference.setEnabled(false); alarmMultiSelectListPreference.setEnabled(false); } else { notificationsMultiSelectListPreference.setEnabled(true); alarmMultiSelectListPreference.setEnabled(true); } PermissionsSettings .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { permissionHelper.openSettingsScreen(); return true; } }); drawerItems.setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { try { final HashSet selectedDrawerItems = (HashSet) newValue; if (selectedDrawerItems.size() < 1) { showSnackbar(mContext.getString(R.string.error_atLeastOneItemInDrawer)); return false; } } catch (Exception ex) { ex.printStackTrace(); return false; } return true; } }); ThemePreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_theme)); return false; } else { ((SettingsActivity) getActivity()).reloadSettings(); return true; } } }); MultiServerPreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.multi_server)); return false; } return true; } }); ServerSettings.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { if (!MultiServerPreference.isChecked()) { Intent intent = new Intent(mContext, ServerSettingsActivity.class); startActivity(intent); } else { Intent intent = new Intent(mContext, ServerListSettingsActivity.class); startActivity(intent); } return true; } }); FingerPrintSettingsPreference .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { mContext.startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS)); return true; } }); fetchServerConfig .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { UsefulBits.getServerConfigForActiveServer(mContext, true, new ConfigReceiver() { @Override public void onReceiveConfig(ConfigInfo settings) { showSnackbar(mContext.getString(R.string.fetched_server_config_success)); } @Override public void onError(Exception error) { showSnackbar(mContext.getString(R.string.fetched_server_config_failed)); } }, null); return true; } }); displayLanguage .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { showRestartMessage(); return true; } }); registrationId.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!PermissionsUtil.canAccessDeviceState(mContext)) { permissionHelper.request(PermissionsUtil.INITIAL_DEVICE_PERMS); } else { pushGCMRegistrationIds(); } } else { pushGCMRegistrationIds(); } return true; } }); GeoSettings.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.geofence)); return false; } else { Intent intent = new Intent(mContext, GeoSettingsActivity.class); startActivity(intent); return true; } } }); EnableNFCPreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_nfc)); return false; } if (NfcAdapter.getDefaultAdapter(mContext) == null) { showSnackbar(mContext.getString(R.string.nfc_not_supported)); return false; } return true; } }); EnableQRCodePreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_QRCode)); return false; } return true; } }); EnableSpeechPreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_Speech)); return false; } return true; } }); EnableTalkBackPreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_talk_back)); return false; } return true; } }); NFCPreference.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_nfc)); return false; } else { Intent intent = new Intent(mContext, NFCSettingsActivity.class); startActivity(intent); return true; } } }); QRCodePreference .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_QRCode)); return false; } else { Intent intent = new Intent(mContext, QRCodeSettingsActivity.class); startActivity(intent); return true; } } }); SpeechPreference .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_Speech)); return false; } else { Intent intent = new Intent(mContext, SpeechSettingsActivity.class); startActivity(intent); return true; } } }); WearPreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_wear)); return false; } return true; } }); AlwaysOnPreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.always_on_title)); return false; } return true; } }); NotificationLogged .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { //show dialog List<String> logs = mSharedPrefs.getLoggedNotifications(); if (logs != null && logs.size() > 0) { Collections.reverse(logs); new MaterialDialog.Builder(mContext) .title(mContext.getString(R.string.notification_show_title)) .items((CharSequence[]) logs.toArray(new String[0])).show(); } else UsefulBits.showSimpleToast(mContext, getString(R.string.notification_show_nothing), Toast.LENGTH_LONG); return true; } }); //noinspection PointlessBooleanExpression if (!BuildConfig.LITE_VERSION) { preferenceScreen.removePreference(premiumCategory); } else { premiumPreference .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { String packageID = mContext.getPackageName() + ".premium"; try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageID))); } catch (android.content.ActivityNotFoundException ignored) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageID))); } return true; } }); } resetApplication .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { new MaterialDialog.Builder(mContext).title(R.string.category_Reset) .content(R.string.are_you_sure).positiveText(R.string.ok) .negativeText(R.string.cancel) .onPositive(new MaterialDialog.SingleButtonCallback() { @SuppressLint("NewApi") @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { ((ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE)) .clearApplicationUserData(); } }).show(); } else { startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0); } return true; } }); FingerPrintPreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @SuppressLint("NewApi") @Override public boolean onPreferenceChange(android.preference.Preference preference, Object o) { if (mSharedPrefs.isStartupSecurityEnabled()) return true; if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_startup_security)); return false; } else { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { UsefulBits.showSimpleToast(mContext, getString(R.string.fingerprint_not_supported), Toast.LENGTH_LONG); return false; } if (!PermissionsUtil.canAccessFingerprint(mContext)) { permissionHelper.request(PermissionsUtil.INITIAL_FINGERPRINT_PERMS); } else { FingerprintManager fingerprintManager = (FingerprintManager) mContext .getSystemService(Context.FINGERPRINT_SERVICE); if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) { return false; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!fingerprintManager.isHardwareDetected()) { return false; } else if (!fingerprintManager.hasEnrolledFingerprints()) { UsefulBits.showSimpleToast(mContext, getString(R.string.fingerprint_not_setup_in_android), Toast.LENGTH_LONG); return false; } else { new MaterialDialog.Builder(mContext) .title(R.string.category_startup_security) .content(R.string.fingerprint_sure).positiveText(R.string.ok) .negativeText(R.string.cancel) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { mSharedPrefs.setStartupSecurityEnabled(true); ((SettingsActivity) getActivity()).reloadSettings(); } }).show(); return false; } } } } return false; } }); }