List of usage examples for android.preference PreferenceCategory setTitle
public void setTitle(CharSequence title)
From source file:com.rareventure.gps2.reviewer.SettingsActivity.java
private void createPreferenceHierarchy() { PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this); this.setPreferenceScreen(root); isCollectData = new CheckBoxPreference(this); isCollectData.setTitle(R.string.collect_gps_data); isCollectData.setSummary(R.string.collect_gps_data_desc); root.addPreference(isCollectData);/*from w w w .ja va2 s . c om*/ isCollectData.setOnPreferenceClickListener(this); percTimeGpsOn = new SeekBarDialogPreference(this, getText(R.string.title_perc_time_gps_on), getText(R.string.desc_perc_time_gps_on), getResources().getInteger(R.dimen.perc_time_gps_on_min_value), getResources().getInteger(R.dimen.perc_time_gps_on_max_value), getResources().getInteger(R.dimen.perc_time_gps_on_steps), getResources().getInteger(R.dimen.perc_time_gps_on_log_scale), getText(R.string.seekbar_perc_printf_format).toString(), null); percTimeGpsOn.setOnPreferenceChangeListener(this); root.addPreference(percTimeGpsOn); minBatteryLife = new SeekBarDialogPreference(this, getText(R.string.title_min_battery_life_perc), getText(R.string.desc_min_battery_life_perc), getResources().getInteger(R.dimen.min_battery_level_min_value), getResources().getInteger(R.dimen.min_battery_level_max_value), getResources().getInteger(R.dimen.min_battery_level_steps), getResources().getInteger(R.dimen.min_battery_level_log_scale), getText(R.string.seekbar_perc_printf_format).toString(), null); minBatteryLife.setOnPreferenceChangeListener(this); root.addPreference(minBatteryLife); enableToolTips = new CheckBoxPreference(this); enableToolTips.setTitle(R.string.enable_tooltips); enableToolTips.setKey("enable_tooltips"); root.addPreference(enableToolTips); enableToolTips.setOnPreferenceClickListener(this); useMetricUnits = new CheckBoxPreference(this); useMetricUnits.setTitle(R.string.use_metric_units); useMetricUnits.setChecked(GTG.prefs.useMetric); root.addPreference(useMetricUnits); //note that we can't use setIntent() for these preferences, since that would // be interpreted as an outside action causing us to lose the password is set flag colorblindSettings = getPreferenceManager().createPreferenceScreen(this); // screenPref.setKey("screen_preference"); // colorblindSettings.setIntent(new Intent(this, ChooseColorsScreen.class)); colorblindSettings.setTitle(R.string.colorblind_title); colorblindSettings.setSummary(R.string.colorblind_summary); colorblindSettings.setOnPreferenceClickListener(this); root.addPreference(colorblindSettings); mapFontSize = new SeekBarDialogPreference(this, getText(R.string.title_map_font_size), getText(R.string.desc_map_font_size), getResources().getInteger(R.dimen.map_font_size_min_value), getResources().getInteger(R.dimen.map_font_size_max_value), getResources().getInteger(R.dimen.map_font_size_steps), getResources().getInteger(R.dimen.map_font_size_log_scale), "%1.0f", null); mapFontSize.setOnPreferenceChangeListener(this); root.addPreference(mapFontSize); enablePassword = new CheckBoxPreference(this); enablePassword.setTitle(R.string.enable_password); enablePassword.setKey("enable_password"); root.addPreference(enablePassword); enablePassword.setOnPreferenceClickListener(this); changePassword = new Preference(this); changePassword.setTitle(R.string.change_password); root.addPreference(changePassword); changePassword.setDependency("enable_password"); changePassword.setOnPreferenceClickListener(this); passwordTimeout = new SeekBarDialogPreference(this, getText(R.string.title_password_timeout), getText(R.string.desc_password_timeout), 0, passwordTimeoutStrs.length - 1, passwordTimeoutStrs.length, 0, null, new SeekBarWithText.CustomUpdateTextView() { @Override public String updateText(float value) { return passwordTimeoutStrs[(int) value]; } }); passwordTimeout.setOnPreferenceChangeListener(this); root.addPreference(passwordTimeout); createBackupFilePref = getPreferenceManager().createPreferenceScreen(this); createBackupFilePref.setTitle(R.string.create_backup_pref); root.addPreference(createBackupFilePref); createBackupFilePref.setOnPreferenceClickListener(this); restoreBackupFilePref = getPreferenceManager().createPreferenceScreen(this); restoreBackupFilePref.setTitle(R.string.restore_backup_pref); root.addPreference(restoreBackupFilePref); restoreBackupFilePref.setOnPreferenceClickListener(this); allowErrorReporting = new CheckBoxPreference(this); allowErrorReporting.setTitle(R.string.allow_error_reporting); allowErrorReporting.setSummary(R.string.allow_error_reporting_summary); allowErrorReporting.setChecked(GTG.isAcraEnabled(this)); root.addPreference(allowErrorReporting); aboutPref = getPreferenceManager().createPreferenceScreen(this); aboutPref.setOnPreferenceClickListener(this); aboutPref.setTitle(R.string.about); root.addPreference(aboutPref); PreferenceCategory advancedCategory = new PreferenceCategory(this); advancedCategory.setTitle("Advanced"); root.addPreference(advancedCategory); writeGpsWakeLockDebugFile = new CheckBoxPreference(this); writeGpsWakeLockDebugFile.setTitle(R.string.write_to_gps_wake_lock_log); writeGpsWakeLockDebugFile.setSummary(String.format(getString(R.string.write_to_gps_wake_lock_log_summary), getString(R.string.gps_wake_lock_filename))); writeGpsWakeLockDebugFile.setChecked(GTG.prefs.writeGpsWakeLockDebug); writeGpsWakeLockDebugFile.setOnPreferenceClickListener(this); advancedCategory.addPreference(writeGpsWakeLockDebugFile); }
From source file:com.quarterfull.newsAndroid.SettingsActivity.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 ww w .j av a 2 s.c o m */ @SuppressWarnings("deprecation") private void setupSimplePreferencesScreen() { if (!isSimplePreferences(this)) { return; } // In the simplified UI, fragments are not used at all and we instead // use the older PreferenceActivity APIs. // Add 'general' preferences. addPreferencesFromResource(R.xml.pref_general); PreferenceCategory header = new PreferenceCategory(this); header.setTitle(R.string.pref_header_display); getPreferenceScreen().addPreference(header); addPreferencesFromResource(R.xml.pref_display); header = new PreferenceCategory(this); header.setTitle(R.string.pref_header_data_sync); getPreferenceScreen().addPreference(header); addPreferencesFromResource(R.xml.pref_data_sync); header = new PreferenceCategory(this); header.setTitle(R.string.pref_header_notifications); getPreferenceScreen().addPreference(header); addPreferencesFromResource(R.xml.pref_notification); /* header = new PreferenceCategory(this); header.setTitle(R.string.pref_header_podcast); getPreferenceScreen().addPreference(header); addPreferencesFromResource(R.xml.pref_podcast); */ bindGeneralPreferences(null, this); bindDisplayPreferences(null, this); bindDataSyncPreferences(null, this); bindNotificationPreferences(null, this); //bindPodcastPreferences(null, 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 a v a 2s. 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:com.aokp.romcontrol.github.tasks.DisplayProjectsListTask.java
private void addPropertiesToPreference(PreferenceCategory mProject, JSONObject projectsObject) { try {//from ww w . j a va 2s. c om // extract info about each project final String projectName = projectsObject.getString("name"); String projectDescription = projectsObject.getString("description"); int githubProjectId = projectsObject.getInt("id"); // apply info to our preference screen mProject.setKey(projectName); if (projectDescription.contains("") || projectDescription == null) { mProject.setTitle(projectName); mProject.setSummary(projectDescription); } else { mProject.setTitle(projectDescription); mProject.setSummary(projectName); } mProject.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference p) { FragmentTransaction transaction = mFragmentManager.beginTransaction(); CommitsFragment commitFragment = new CommitsFragment(mAlertDialog, projectName); transaction.addToBackStack(null); transaction.replace(mId, commitFragment, projectName); transaction.commit(); return true; } }); } catch (JSONException badJsonRequest) { Log.e(TAG, "failed to parse required info about project", badJsonRequest); } }
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 w w. j a v a 2 s .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:tw.idv.palatis.danboorugallery.SettingsActivity.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 a v a2 s . c om*/ */ private void setupSimplePreferencesScreen() { if (!isSimplePreferences(this)) return; // Add a empty preference screen so we can insert headers... addPreferencesFromResource(R.xml.pref_empty); // In the simplified UI, fragments are not used at all and we instead // use the older PreferenceActivity APIs. PreferenceCategory fakeHeader; // Add 'screen layout' preferences, and a corresponding header. fakeHeader = new PreferenceCategory(this); fakeHeader.setTitle(R.string.pref_header_screen_layout); getPreferenceScreen().addPreference(fakeHeader); addPreferencesFromResource(R.xml.pref_screen_layout); // Add 'detail view' preference, and a corresponding header. fakeHeader = new PreferenceCategory(this); fakeHeader.setTitle(R.string.pref_header_detail_view); getPreferenceScreen().addPreference(fakeHeader); addPreferencesFromResource(R.xml.pref_detail); // Add 'network policy' preferences, and a corresponding header. fakeHeader = new PreferenceCategory(this); fakeHeader.setTitle(R.string.pref_header_network_policy); getPreferenceScreen().addPreference(fakeHeader); addPreferencesFromResource(R.xml.pref_network_policy); // Add 'debug' preferences, and a corresponding header. fakeHeader = new PreferenceCategory(this); fakeHeader.setTitle(R.string.pref_header_advanced); getPreferenceScreen().addPreference(fakeHeader); addPreferencesFromResource(R.xml.pref_advanced); // Add 'about' preferences, and a corresponding header. fakeHeader = new PreferenceCategory(this); fakeHeader.setTitle(R.string.pref_header_about); getPreferenceScreen().addPreference(fakeHeader); addPreferencesFromResource(R.xml.pref_about); // Bind the summaries of EditText/List/Dialog/Ringtone preferences to // their values. When their values change, their summaries are updated // to reflect the new value, per the Android Design guidelines. bindPreferenceSummaryToValue(findPreference(DanbooruGallerySettings.KEY_PREF_COLUMNS_PORTRAIT), 3); bindPreferenceSummaryToValue(findPreference(DanbooruGallerySettings.KEY_PREF_COLUMNS_LANDSCAPE), 5); bindPreferenceSummaryToValue(findPreference(DanbooruGallerySettings.KEY_PREF_STICKY_GRID_HEADER), true); bindPreferenceSummaryToValue(findPreference(DanbooruGallerySettings.KEY_PREF_SHOW_POST_ID), true); bindPreferenceSummaryToValue(findPreference(DanbooruGallerySettings.KEY_PREF_SHOW_IMAGE_RESOLUTION), true); bindPreferenceSummaryToValue(findPreference(DanbooruGallerySettings.KEY_PREF_DOWNLOAD_FULLSIZE), false); bindPreferenceSummaryToValue(findPreference(DanbooruGallerySettings.KEY_PREF_AUTOPLAY_DELAY), 5000); bindPreferenceSummaryToValue(findPreference(DanbooruGallerySettings.KEY_PREF_STRICT_BANDWIDTH_USAGE), true); bindPreferenceSummaryToValue(findPreference(DanbooruGallerySettings.KEY_PREF_AGGRESSIVE_PREFETCH_PREVIEW), false); bindPreferenceSummaryToValue(findPreference(DanbooruGallerySettings.KEY_PREF_ASYNC_IMAGE_LOADER_INDICATOR), false); Preference preference; preference = findPreference(DanbooruGallerySettings.KEY_PREF_CLEAR_CACHE); assert preference != null; preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(final Preference preference) { setProgressBarIndeterminate(true); setProgressBarIndeterminateVisibility(true); preference.setEnabled(false); DanbooruGalleryApplication.clearCacheWithThread(SettingsActivity.this, new DanbooruGalleryApplication.OnCacheClearedCallback() { @Override public void onCacheCleared() { mCacheSizeCalculated = false; new Thread(new CalculateDiskUsageRunnable(preference, new CalculateDiskUsageRunnable.Callbacks() { @Override public void onCalculationDone(double disk_size, double disk_size_max, double mem_size, double mem_size_max, int post_count) { mCacheSizeCalculated = true; mCacheSize = disk_size; mMaxCacheSize = disk_size_max; mMemCacheSize = mem_size; mMaxMemCacheSize = mem_size_max; mPostCount = post_count; setProgressBarIndeterminateVisibility(false); } }, getResources().getString(R.string.pref_description_clear_cache_calculating), getResources().getString(R.string.pref_description_clear_cache_done))) .start(); runOnUiThread(new Runnable() { @Override public void run() { preference.setEnabled(true); } }); } }); return true; } }); if (mCacheSizeCalculated) { preference.setSummary(getResources().getString(R.string.pref_description_clear_cache_done, mCacheSize, mMaxCacheSize, mMemCacheSize, mMaxMemCacheSize, mPostCount)); } else { new Thread(new CalculateDiskUsageRunnable(preference, new CalculateDiskUsageRunnable.Callbacks() { @Override public void onCalculationDone(double disk_size, double disk_size_max, double mem_size, double mem_size_max, int post_count) { mCacheSizeCalculated = true; mCacheSize = disk_size; mMaxCacheSize = disk_size_max; mMemCacheSize = mem_size; mMaxMemCacheSize = mem_size_max; mPostCount = post_count; } }, getResources().getString(R.string.pref_description_clear_cache_calculating), getResources().getString(R.string.pref_description_clear_cache_done))).start(); } if (getResources().getString(R.string.pref_title_translator).trim().isEmpty()) { preference = findPreference(DanbooruGallerySettings.KEY_PREF_TRANSLATOR); getPreferenceScreen().removePreference(preference); } preference = findPreference(DanbooruGallerySettings.KEY_PREF_VERSION); try { PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0); preference.setTitle( getResources().getString(R.string.pref_title_version, pinfo.versionCode, pinfo.versionName)); preference.setSummary(getResources().getString(R.string.pref_description_version, pinfo.versionCode, pinfo.versionName)); } catch (PackageManager.NameNotFoundException ignored) { preference.setTitle(getResources().getString(R.string.pref_title_version, 99999999, "????????")); preference .setSummary(getResources().getString(R.string.pref_description_version, 99999999, "????????")); } }
From source file:org.mozilla.gecko.fxa.activities.FxAccountStatusFragment.java
/** * Iterate through debug buttons, adding a special debug preference click * listener to each of them.//from w ww .ja va2 s . co m */ protected void connectDebugButtons() { // Separate listener to really separate debug logic from main code paths. final OnPreferenceClickListener listener = new DebugPreferenceClickListener(); // We don't want to use Android resource strings for debug UI, so we just // use the keys throughout. final PreferenceCategory debugCategory = (PreferenceCategory) ensureFindPreference("debug_category"); debugCategory.setTitle(debugCategory.getKey()); for (int i = 0; i < debugCategory.getPreferenceCount(); i++) { final Preference button = debugCategory.getPreference(i); button.setTitle(button.getKey()); // Not very friendly, but this is for debugging only! button.setOnPreferenceClickListener(listener); } }
From source file:com.owncloud.android.ui.activity.Preferences.java
@SuppressWarnings("deprecation") @Override//from w ww . j av a 2s . c o m public void onCreate(Bundle savedInstanceState) { if (ThemeUtils.themingEnabled()) { setTheme(R.style.FallbackThemingTheme); } getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); ActionBar actionBar = getDelegate().getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); ThemeUtils.setColoredTitle(actionBar, getString(R.string.actionbar_settings)); actionBar.setBackgroundDrawable(new ColorDrawable(ThemeUtils.primaryColor())); getWindow().getDecorView().setBackgroundDrawable( new ColorDrawable(ResourcesCompat.getColor(getResources(), R.color.background_color, null))); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getWindow().setStatusBarColor(ThemeUtils.primaryDarkColor()); } Drawable backArrow = getResources().getDrawable(R.drawable.ic_arrow_back); actionBar.setHomeAsUpIndicator(ThemeUtils.tintDrawable(backArrow, ThemeUtils.fontColor())); int accentColor = ThemeUtils.primaryAccentColor(); // retrieve user's base uri setupBaseUri(); // For adding content description tag to a title field in the action bar int actionBarTitleId = getResources().getIdentifier("action_bar_title", "id", "android"); View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId); if (actionBarTitleView != null) { // it's null in Android 2.x getWindow().getDecorView().findViewById(actionBarTitleId) .setContentDescription(getString(R.string.actionbar_settings)); } // Load package info String temp; try { PackageInfo pkg = getPackageManager().getPackageInfo(getPackageName(), 0); temp = pkg.versionName; } catch (NameNotFoundException e) { temp = ""; Log_OC.e(TAG, "Error while showing about dialog", e); } final String appVersion = temp; // Register context menu for list of preferences. registerForContextMenu(getListView()); // General PreferenceCategory preferenceCategoryGeneral = (PreferenceCategory) findPreference("general"); preferenceCategoryGeneral .setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_general), accentColor)); // Synced folders PreferenceCategory preferenceCategorySyncedFolders = (PreferenceCategory) findPreference( "synced_folders_category"); preferenceCategorySyncedFolders .setTitle(ThemeUtils.getColoredTitle(getString(R.string.drawer_synced_folders), accentColor)); PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference("preference_screen"); if (!getResources().getBoolean(R.bool.syncedFolder_light)) { preferenceScreen.removePreference(preferenceCategorySyncedFolders); } else { // Upload on WiFi final ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver()); final Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext()); final SwitchPreference pUploadOnWifiCheckbox = (SwitchPreference) findPreference( "synced_folder_on_wifi"); pUploadOnWifiCheckbox .setChecked(arbitraryDataProvider.getBooleanValue(account, SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI)); pUploadOnWifiCheckbox.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { arbitraryDataProvider.storeOrUpdateKeyValue(account.name, SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI, String.valueOf(pUploadOnWifiCheckbox.isChecked())); return true; } }); Preference pSyncedFolder = findPreference("synced_folders_configure_folders"); if (pSyncedFolder != null) { if (getResources().getBoolean(R.bool.syncedFolder_light) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { pSyncedFolder.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent syncedFoldersIntent = new Intent(getApplicationContext(), SyncedFoldersActivity.class); syncedFoldersIntent.putExtra(SyncedFoldersActivity.EXTRA_SHOW_SIDEBAR, false); startActivity(syncedFoldersIntent); return true; } }); } else { preferenceCategorySyncedFolders.removePreference(pSyncedFolder); } } } PreferenceCategory preferenceCategoryDetails = (PreferenceCategory) findPreference("details"); preferenceCategoryDetails .setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_details), accentColor)); boolean fPassCodeEnabled = getResources().getBoolean(R.bool.passcode_enabled); pCode = (SwitchPreference) findPreference(PassCodeActivity.PREFERENCE_SET_PASSCODE); if (pCode != null && fPassCodeEnabled) { pCode.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Intent i = new Intent(getApplicationContext(), PassCodeActivity.class); Boolean incoming = (Boolean) newValue; i.setAction(incoming ? PassCodeActivity.ACTION_REQUEST_WITH_RESULT : PassCodeActivity.ACTION_CHECK_WITH_RESULT); startActivityForResult(i, incoming ? ACTION_REQUEST_PASSCODE : ACTION_CONFIRM_PASSCODE); // Don't update just yet, we will decide on it in onActivityResult return false; } }); } else { preferenceCategoryDetails.removePreference(pCode); } boolean fPrintEnabled = getResources().getBoolean(R.bool.fingerprint_enabled); fPrint = (SwitchPreference) findPreference(PREFERENCE_USE_FINGERPRINT); if (fPrint != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (FingerprintActivity.isFingerprintCapable(MainApp.getAppContext()) && fPrintEnabled) { fPrint.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Boolean incoming = (Boolean) newValue; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (FingerprintActivity.isFingerprintReady(MainApp.getAppContext())) { SharedPreferences appPrefs = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = appPrefs.edit(); editor.putBoolean("use_fingerprint", incoming); editor.apply(); return true; } else { if (incoming) { Toast.makeText(MainApp.getAppContext(), R.string.prefs_fingerprint_notsetup, Toast.LENGTH_LONG).show(); fPrint.setChecked(false); } SharedPreferences appPrefs = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = appPrefs.edit(); editor.putBoolean("use_fingerprint", false); editor.apply(); return false; } } else { return false; } } }); if (!FingerprintActivity.isFingerprintReady(MainApp.getAppContext())) { fPrint.setChecked(false); } } else { preferenceCategoryDetails.removePreference(fPrint); } } else { preferenceCategoryDetails.removePreference(fPrint); } } boolean fShowHiddenFilesEnabled = getResources().getBoolean(R.bool.show_hidden_files_enabled); mShowHiddenFiles = (SwitchPreference) findPreference("show_hidden_files"); if (fShowHiddenFilesEnabled) { mShowHiddenFiles.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { SharedPreferences appPrefs = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = appPrefs.edit(); editor.putBoolean("show_hidden_files_pref", mShowHiddenFiles.isChecked()); editor.apply(); return true; } }); } else { preferenceCategoryDetails.removePreference(mShowHiddenFiles); } mExpertMode = (SwitchPreference) findPreference(EXPERT_MODE); if (getResources().getBoolean(R.bool.syncedFolder_light)) { preferenceCategoryDetails.removePreference(mExpertMode); } else { mExpertMode = (SwitchPreference) findPreference(EXPERT_MODE); mExpertMode.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { SharedPreferences appPrefs = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = appPrefs.edit(); editor.putBoolean(EXPERT_MODE, mExpertMode.isChecked()); editor.apply(); if (mExpertMode.isChecked()) { Log_OC.startLogging(getApplicationContext()); } else { if (!BuildConfig.DEBUG && !getApplicationContext().getResources().getBoolean(R.bool.logger_enabled)) { Log_OC.stopLogging(); } } return true; } }); } PreferenceCategory preferenceCategoryMore = (PreferenceCategory) findPreference("more"); preferenceCategoryMore .setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_more), accentColor)); boolean calendarContactsEnabled = getResources().getBoolean(R.bool.davdroid_integration_enabled); Preference pCalendarContacts = findPreference("calendar_contacts"); if (pCalendarContacts != null) { if (calendarContactsEnabled) { pCalendarContacts.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { try { launchDavDroidLogin(); } catch (Throwable t) { Log_OC.e(TAG, "Base Uri for account could not be resolved to call DAVdroid!", t); Toast.makeText(MainApp.getAppContext(), R.string.prefs_calendar_contacts_address_resolve_error, Toast.LENGTH_SHORT) .show(); } return true; } }); } else { preferenceCategoryMore.removePreference(pCalendarContacts); } } boolean contactsBackupEnabled = !getResources().getBoolean(R.bool.show_drawer_contacts_backup) && getResources().getBoolean(R.bool.contacts_backup); Preference pContactsBackup = findPreference("contacts"); if (pCalendarContacts != null) { if (contactsBackupEnabled) { pContactsBackup.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent contactsIntent = new Intent(getApplicationContext(), ContactsPreferenceActivity.class); contactsIntent.putExtra(ContactsPreferenceActivity.EXTRA_SHOW_SIDEBAR, false); startActivity(contactsIntent); return true; } }); } else { preferenceCategoryMore.removePreference(pContactsBackup); } } if (!fShowHiddenFilesEnabled && !fPrintEnabled && !fPassCodeEnabled) { preferenceScreen.removePreference(preferenceCategoryDetails); } boolean helpEnabled = getResources().getBoolean(R.bool.help_enabled); Preference pHelp = findPreference("help"); if (pHelp != null) { if (helpEnabled) { pHelp.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { String helpWeb = getString(R.string.url_help); if (helpWeb != null && helpWeb.length() > 0) { Uri uriUrl = Uri.parse(helpWeb); Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl); startActivity(intent); } return true; } }); } else { preferenceCategoryMore.removePreference(pHelp); } } boolean recommendEnabled = getResources().getBoolean(R.bool.recommend_enabled); Preference pRecommend = findPreference("recommend"); if (pRecommend != null) { if (recommendEnabled) { pRecommend.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); String appName = getString(R.string.app_name); String downloadUrlGooglePlayStore = getString(R.string.url_app_download); String downloadUrlFDroid = getString(R.string.fdroid_link); String downloadUrls = String.format(getString(R.string.recommend_urls), downloadUrlGooglePlayStore, downloadUrlFDroid); String recommendSubject = String.format(getString(R.string.recommend_subject), appName); String recommendText = String.format(getString(R.string.recommend_text), appName, downloadUrls); intent.putExtra(Intent.EXTRA_SUBJECT, recommendSubject); intent.putExtra(Intent.EXTRA_TEXT, recommendText); startActivity(intent); return true; } }); } else { preferenceCategoryMore.removePreference(pRecommend); } } boolean feedbackEnabled = getResources().getBoolean(R.bool.feedback_enabled); Preference pFeedback = findPreference("feedback"); if (pFeedback != null) { if (feedbackEnabled) { pFeedback.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { String feedbackMail = getString(R.string.mail_feedback); String feedback = getText(R.string.prefs_feedback) + " - android v" + appVersion; Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, feedback); intent.setData(Uri.parse(feedbackMail)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); return true; } }); } else { preferenceCategoryMore.removePreference(pFeedback); } } SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); boolean loggerEnabled = getResources().getBoolean(R.bool.logger_enabled) || BuildConfig.DEBUG || appPrefs.getBoolean(EXPERT_MODE, false); Preference pLogger = findPreference("logger"); if (pLogger != null) { if (loggerEnabled) { pLogger.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent loggerIntent = new Intent(getApplicationContext(), LogHistoryActivity.class); startActivity(loggerIntent); return true; } }); } else { preferenceCategoryMore.removePreference(pLogger); } } boolean imprintEnabled = getResources().getBoolean(R.bool.imprint_enabled); Preference pImprint = findPreference("imprint"); if (pImprint != null) { if (imprintEnabled) { pImprint.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { String imprintWeb = getString(R.string.url_imprint); if (imprintWeb != null && imprintWeb.length() > 0) { Uri uriUrl = Uri.parse(imprintWeb); Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl); startActivity(intent); } //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG"); return true; } }); } else { preferenceCategoryMore.removePreference(pImprint); } } mPrefStoragePath = (ListPreference) findPreference(PreferenceKeys.STORAGE_PATH); if (mPrefStoragePath != null) { StoragePoint[] storageOptions = DataStorageProvider.getInstance().getAvailableStoragePoints(); String[] entries = new String[storageOptions.length]; String[] values = new String[storageOptions.length]; for (int i = 0; i < storageOptions.length; ++i) { entries[i] = storageOptions[i].getDescription(); values[i] = storageOptions[i].getPath(); } mPrefStoragePath.setEntries(entries); mPrefStoragePath.setEntryValues(values); mPrefStoragePath.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String newPath = (String) newValue; if (mStoragePath.equals(newPath)) { return true; } StorageMigration storageMigration = new StorageMigration(Preferences.this, mStoragePath, newPath); storageMigration.setStorageMigrationProgressListener(Preferences.this); storageMigration.migrate(); return false; } }); } // About category PreferenceCategory preferenceCategoryAbout = (PreferenceCategory) findPreference("about"); preferenceCategoryAbout .setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_about), accentColor)); /* About App */ pAboutApp = findPreference("about_app"); if (pAboutApp != null) { pAboutApp.setTitle(String.format(getString(R.string.about_android), getString(R.string.app_name))); pAboutApp.setSummary(String.format(getString(R.string.about_version), appVersion)); } // source code boolean sourcecodeEnabled = getResources().getBoolean(R.bool.sourcecode_enabled); Preference sourcecodePreference = findPreference("sourcecode"); if (sourcecodePreference != null) { String sourcecodeUrl = getString(R.string.sourcecode_url); if (sourcecodeEnabled && !sourcecodeUrl.isEmpty()) { sourcecodePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Uri uriUrl = Uri.parse(sourcecodeUrl); Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl); startActivity(intent); return true; } }); } else { preferenceCategoryAbout.removePreference(sourcecodePreference); } } // license boolean licenseEnabled = getResources().getBoolean(R.bool.license_enabled); Preference licensePreference = findPreference("license"); if (licensePreference != null) { String licenseUrl = getString(R.string.license_url); if (licenseEnabled && !licenseUrl.isEmpty()) { licensePreference.setSummary(R.string.prefs_gpl_v2); licensePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Uri uriUrl = Uri.parse(licenseUrl); Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl); startActivity(intent); return true; } }); } else { preferenceCategoryAbout.removePreference(licensePreference); } } // privacy boolean privacyEnabled = getResources().getBoolean(R.bool.privacy_enabled); Preference privacyPreference = findPreference("privacy"); if (privacyPreference != null) { if (privacyEnabled) { privacyPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { String privacyUrl = getString(R.string.privacy_url); if (privacyUrl.length() > 0) { Intent externalWebViewIntent = new Intent(getApplicationContext(), ExternalSiteWebView.class); externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, getResources().getString(R.string.privacy)); externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_URL, privacyUrl); externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, false); externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_MENU_ITEM_ID, -1); startActivity(externalWebViewIntent); } return true; } }); } else { preferenceCategoryAbout.removePreference(privacyPreference); } } loadExternalSettingLinks(preferenceCategoryMore); loadStoragePath(); }
From source file:org.opendatakit.services.preferences.fragments.DeviceSettingsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PropertiesSingleton props = ((IOdkAppPropertiesActivity) this.getActivity()).getProps(); addPreferencesFromResource(R.xml.device_preferences); // not super safe, but we're just putting in this mode to help // administrate // would require code to access it boolean adminMode; adminMode = (this.getArguments() == null) ? false : (this.getArguments().containsKey(IntentConsts.INTENT_KEY_SETTINGS_IN_ADMIN_MODE) ? this.getArguments().getBoolean(IntentConsts.INTENT_KEY_SETTINGS_IN_ADMIN_MODE) : false);/* w ww . j av a 2 s . c o m*/ String adminPwd = props.getProperty(CommonToolProperties.KEY_ADMIN_PW); boolean adminConfigured = (adminPwd != null && adminPwd.length() != 0); PreferenceCategory deviceCategory = (PreferenceCategory) findPreference( CommonToolProperties.GROUPING_DEVICE_CATEGORY); boolean fontAvailable = !adminConfigured || props.getBooleanProperty(CommonToolProperties.KEY_CHANGE_FONT_SIZE); mFontSizePreference = (ListPreference) findPreference(CommonToolProperties.KEY_FONT_SIZE); if (props.containsKey(CommonToolProperties.KEY_FONT_SIZE)) { String chosenFontSize = props.getProperty(CommonToolProperties.KEY_FONT_SIZE); CharSequence entryValues[] = mFontSizePreference.getEntryValues(); for (int i = 0; i < entryValues.length; i++) { String entry = entryValues[i].toString(); if (entry.equals(chosenFontSize)) { mFontSizePreference.setValue(entry); mFontSizePreference.setSummary(mFontSizePreference.getEntries()[i]); } } } mFontSizePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int index = ((ListPreference) preference).findIndexOfValue(newValue.toString()); String entry = (String) ((ListPreference) preference).getEntries()[index]; preference.setSummary(entry); PropertiesSingleton props = ((IOdkAppPropertiesActivity) DeviceSettingsFragment.this.getActivity()) .getProps(); props.setProperty(CommonToolProperties.KEY_FONT_SIZE, newValue.toString()); return true; } }); mFontSizePreference.setEnabled(fontAvailable || adminMode); boolean splashAvailable = !adminConfigured || props.getBooleanProperty(CommonToolProperties.KEY_CHANGE_SPLASH_SETTINGS); mShowSplashPreference = (CheckBoxPreference) findPreference(CommonToolProperties.KEY_SHOW_SPLASH); if (props.containsKey(CommonToolProperties.KEY_SHOW_SPLASH)) { boolean checked = props.getBooleanProperty(CommonToolProperties.KEY_SHOW_SPLASH); mShowSplashPreference.setChecked(checked); } mShowSplashPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { PropertiesSingleton props = ((IOdkAppPropertiesActivity) DeviceSettingsFragment.this.getActivity()) .getProps(); props.setProperty(CommonToolProperties.KEY_SHOW_SPLASH, newValue.toString()); return true; } }); mShowSplashPreference.setEnabled(adminMode || splashAvailable); mSplashPathPreference = (PreferenceScreen) findPreference(CommonToolProperties.KEY_SPLASH_PATH); if (props.containsKey(CommonToolProperties.KEY_SPLASH_PATH)) { mSplashPathPreference.setSummary(props.getProperty(CommonToolProperties.KEY_SPLASH_PATH)); } mSplashPathPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { private void launchImageChooser() { Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.setType("image/*"); DeviceSettingsFragment.this.startActivityForResult(i, AppPropertiesActivity.SPLASH_IMAGE_CHOOSER); } @Override public boolean onPreferenceClick(Preference preference) { // if you have a value, you can clear it or select new. CharSequence cs = mSplashPathPreference.getSummary(); if (cs != null && cs.toString().contains("/")) { final CharSequence[] items = { getString(R.string.select_another_image), getString(R.string.use_odk_default) }; AlertDialog.Builder builder = new AlertDialog.Builder( DeviceSettingsFragment.this.getActivity()); builder.setTitle(getString(R.string.change_splash_path)); builder.setNeutralButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (items[item].equals(getString(R.string.select_another_image))) { launchImageChooser(); } else { PropertiesSingleton props = ((IOdkAppPropertiesActivity) DeviceSettingsFragment.this .getActivity()).getProps(); String path = getString(R.string.default_splash_path); props.setProperty(CommonToolProperties.KEY_SPLASH_PATH, path); mSplashPathPreference.setSummary(path); } } }); AlertDialog alert = builder.create(); alert.show(); } else { launchImageChooser(); } return true; } }); mSplashPathPreference.setEnabled(adminMode || splashAvailable); if (!adminMode && (!fontAvailable || !splashAvailable)) { deviceCategory.setTitle(R.string.device_restrictions_apply); } }