List of usage examples for android.preference PreferenceCategory removePreference
public boolean removePreference(Preference preference)
From source file:github.popeen.dsub.fragments.SettingsFragment.java
@Override public void onCreate(Bundle bundle) { super.onCreate(bundle); if (Build.VERSION.SDK_INT >= 21) { CheckBoxPreference mediaButtons = (CheckBoxPreference) findPreference("mediaButtons"); if (mediaButtons != null) { PreferenceCategory otherCategory = (PreferenceCategory) findPreference("otherSettings"); otherCategory.removePreference(mediaButtons); }/*from w w w. j a va 2s . c om*/ } int instance = this.getArguments().getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, -1); if (instance != -1) { PreferenceScreen preferenceScreen = expandServer(instance); setPreferenceScreen(preferenceScreen); serverSettings.put(Integer.toString(instance), new ServerSettings(instance)); onInitPreferences(preferenceScreen); } }
From source file:com.irccloud.android.activity.PreferencesActivity.java
@SuppressWarnings("deprecation") @Override/*www . jav a 2s . c o m*/ public void onCreate(Bundle icicle) { requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); super.onCreate(icicle); getDelegate().installViewFactory(); getDelegate().onCreate(icicle); if (Build.VERSION.SDK_INT >= 21) { Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name), cloud, 0xFFF2F7FC)); cloud.recycle(); } getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.actionbar_prefs); Toolbar toolbar = (Toolbar) findViewById(R.id.actionbar); toolbar.setTitle(getTitle()); toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); toolbar.setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar)); if (Build.VERSION.SDK_INT >= 21) toolbar.setElevation(0); conn = NetworkConnection.getInstance(); addPreferencesFromResource(R.xml.preferences_account); addPreferencesFromResource(R.xml.preferences_display); addPreferencesFromResource(R.xml.preferences_device); addPreferencesFromResource(R.xml.preferences_photos); addPreferencesFromResource(R.xml.preferences_notifications); addPreferencesFromResource(R.xml.preferences_dashclock); findPreference("dashclock_showmsgs").setOnPreferenceChangeListener(dashclocktoggle); try { int pebbleVersion = getPackageManager().getPackageInfo("com.getpebble.android", 0).versionCode; if (pebbleVersion < 553) addPreferencesFromResource(R.xml.preferences_pebble); } catch (Exception e) { } boolean foundSony = false; try { getPackageManager().getPackageInfo("com.sonyericsson.extras.liveware", 0); addPreferencesFromResource(R.xml.preferences_sony); foundSony = true; } catch (Exception e) { } if (!foundSony) { try { getPackageManager().getPackageInfo("com.sonyericsson.extras.smartwatch", 0); addPreferencesFromResource(R.xml.preferences_sony); foundSony = true; } catch (Exception e) { } } if (!foundSony) { try { getPackageManager().getPackageInfo("com.sonyericsson.extras.liveview", 0); addPreferencesFromResource(R.xml.preferences_sony); foundSony = true; } catch (Exception e) { } } if (foundSony) findPreference("notify_sony").setOnPreferenceChangeListener(sonytoggle); if (BuildConfig.DEBUG) addPreferencesFromResource(R.xml.preferences_debug); addPreferencesFromResource(R.xml.preferences_about); findPreference("name").setOnPreferenceChangeListener(settingstoggle); findPreference("autoaway").setOnPreferenceChangeListener(settingstoggle); findPreference("time-24hr").setOnPreferenceChangeListener(prefstoggle); findPreference("time-seconds").setOnPreferenceChangeListener(prefstoggle); findPreference("mode-showsymbol").setOnPreferenceChangeListener(prefstoggle); findPreference("pastebin-disableprompt").setOnPreferenceChangeListener(prefstoggle); if (findPreference("emoji-disableconvert") != null) { findPreference("emoji-disableconvert").setOnPreferenceChangeListener(prefstoggle); findPreference("emoji-disableconvert").setSummary(":thumbsup: \uD83D\uDC4D"); } findPreference("nick-colors").setOnPreferenceChangeListener(prefstoggle); findPreference("faq").setOnPreferenceClickListener(urlClick); findPreference("feedback").setOnPreferenceClickListener(urlClick); findPreference("licenses").setOnPreferenceClickListener(licensesClick); findPreference("imageviewer").setOnPreferenceChangeListener(imageviewertoggle); findPreference("imgur_account_username").setOnPreferenceClickListener(imgurClick); //findPreference("subscriptions").setOnPreferenceClickListener(urlClick); //findPreference("changes").setOnPreferenceClickListener(urlClick); findPreference("notify_type").setOnPreferenceChangeListener(notificationstoggle); findPreference("notify_led_color").setOnPreferenceChangeListener(ledtoggle); findPreference("photo_size").setOnPreferenceChangeListener(photosizetoggle); imgurPreference = findPreference("imgur_account_username"); if (NetworkConnection.getInstance().uploadsAvailable()) { if (!PreferenceManager.getDefaultSharedPreferences(this).getString("image_service", "IRCCloud") .equals("imgur")) { PreferenceCategory c = (PreferenceCategory) findPreference("photos"); c.removePreference(imgurPreference); } findPreference("image_service").setOnPreferenceChangeListener(imageservicetoggle); } else { PreferenceCategory c = (PreferenceCategory) findPreference("photos"); c.removePreference(findPreference("image_service")); } try { final String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; findPreference("version").setSummary(version); findPreference("version").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService( CLIPBOARD_SERVICE); clipboard.setText(version); } else { @SuppressLint("ServiceCast") android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService( CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("IRCCloud Version", version); clipboard.setPrimaryClip(clip); } Toast.makeText(PreferencesActivity.this, "Version number copied to clipboard", Toast.LENGTH_SHORT).show(); return false; } }); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.ichi2.anki.PreferenceContext.java
private void removeUnnecessaryAdvancedPrefs(PreferenceScreen screen) { PreferenceCategory plugins = (PreferenceCategory) screen.findPreference("category_plugins"); // Disable the emoji/kana buttons to scroll preference if those keys don't exist if (!CompatHelper.hasKanaAndEmojiKeys()) { CheckBoxPreference emojiScrolling = (CheckBoxPreference) screen.findPreference("scrolling_buttons"); if (emojiScrolling != null && plugins != null) { plugins.removePreference(emojiScrolling); }/*from w ww. j ava 2 s. c om*/ } // Disable the double scroll preference if no scrolling keys if (!CompatHelper.hasScrollKeys() && !CompatHelper.hasKanaAndEmojiKeys()) { CheckBoxPreference doubleScrolling = (CheckBoxPreference) screen.findPreference("double_scrolling"); if (doubleScrolling != null && plugins != null) { plugins.removePreference(doubleScrolling); } } PreferenceCategory workarounds = (PreferenceCategory) screen.findPreference("category_workarounds"); if (workarounds != null) { CheckBoxPreference writeAnswersDisable = (CheckBoxPreference) screen .findPreference("writeAnswersDisable"); CheckBoxPreference useInputTag = (CheckBoxPreference) screen.findPreference("useInputTag"); CheckBoxPreference inputWorkaround = (CheckBoxPreference) screen.findPreference("inputWorkaround"); CheckBoxPreference longclickWorkaround = (CheckBoxPreference) screen .findPreference("textSelectionLongclickWorkaround"); CheckBoxPreference fixHebrewText = (CheckBoxPreference) screen.findPreference("fixHebrewText"); CheckBoxPreference safeDisplayMode = (CheckBoxPreference) screen.findPreference("safeDisplay"); CompatHelper.removeHiddenPreferences(this.getApplicationContext()); if (CompatHelper.isHoneycomb()) { workarounds.removePreference(longclickWorkaround); } if (CompatHelper.getSdkVersion() >= 13) { workarounds.removePreference(safeDisplayMode); } if (CompatHelper.getSdkVersion() >= 15) { workarounds.removePreference(writeAnswersDisable); workarounds.removePreference(inputWorkaround); } else { // For older Androids we never use the input tag anyway. workarounds.removePreference(useInputTag); } if (CompatHelper.getSdkVersion() >= 16) { workarounds.removePreference(fixHebrewText); } } }
From source file:mx.klozz.xperience.tweaker.fragments.CPUAdvanced.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = getActivity();/*from w w w .ja v a2 s . c o m*/ setHasOptionsMenu(true); mPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); mPreferences.registerOnSharedPreferenceChangeListener(this); addPreferencesFromResource(R.layout.cpu_advanced); mSOmax = (ListPreference) findPreference("pref_so_max"); mSOmin = (ListPreference) findPreference("pref_so_min"); mOClow = (ListPreference) findPreference("pref_oc_low"); mOChigh = (ListPreference) findPreference("pref_oc_high"); mOCval = findPreference("pref_oc_val"); mMpdecision = (SwitchPreference) findPreference("pref_mpdecision"); mMsmHotplug = (SwitchPreference) findPreference("pref_msmhotplug"); mIntelliplug = (SwitchPreference) findPreference("pref_intelliplug"); mIntelliprofiles = (ListPreference) findPreference("pref_intelliprof"); mEcomode = (SwitchPreference) findPreference("pref_ecomode"); lmcps = (ListPreference) findPreference("pref_mcps"); lcpuq = (ListPreference) findPreference("pref_cpuquiet"); mHotplugset = findPreference("pref_hotplug"); mGenHP = (SwitchPreference) findPreference("pref_hp"); lgpufmax = (ListPreference) findPreference("pref_gpu_fmax"); mGpuGovset = findPreference("pref_gpugov_set"); mKraitThres = (ListPreference) findPreference("pref_krait_thres"); mKraitBoost = (SwitchPreference) findPreference("pref_krait_boost"); mKraitHi = findPreference("pref_krait_hi"); mKraitLo = findPreference("pref_krait_lo"); ps = getString(R.string.ps_so_minmax); ps_cpuquiet = getString(R.string.ps_cpuquiet); ps_mc_ps = getString(R.string.ps_mc_ps); intelliprof = getString(R.string.intelli_plugprof_sum); app = getString(R.string.app_name); final CharSequence[] entries = MainActivity.mAvailableFrequencies; if (!new File(SO_MAX_FREQ).exists() || !new File(SO_MIN_FREQ).exists()) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("so_min_max"); getPreferenceScreen().removePreference(hideCat); } else { mSOmax.setEntries(entries); mSOmax.setEntryValues(entries); mSOmin.setEntries(entries); mSOmin.setEntryValues(entries); final String readsomax = Helpers.LeerUnaLinea(SO_MAX_FREQ); final String readsomin = Helpers.LeerUnaLinea(SO_MIN_FREQ); mSOmax.setValue(readsomax); mSOmin.setValue(readsomin); mSOmax.setSummary(ps + readsomax + " kHz"); mSOmin.setSummary(ps + readsomin + " kHz"); } //live OC if (!new File(OC_VALUE_PATH).exists()) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("oc_live"); getPreferenceScreen().removePreference(hideCat); } else { final String voc = Helpers.LeerUnaLinea(OC_VALUE_PATH); mOCval.setSummary(ps + voc); if (!new File(OC_HIGH_PATH).exists()) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("oc_live"); hideCat.removePreference(mOChigh); } else { mOChigh.setEntries(entries); mOChigh.setEntryValues(entries); final String readsomax = Helpers.LeerUnaLinea(OC_HIGH_PATH); mOChigh.setValue(readsomax); mOChigh.setSummary(ps + readsomax + " kHz"); } if (!new File(OC_LOW_PATH).exists()) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("oc_live"); hideCat.removePreference(mOClow); } else { mOClow.setEntries(entries); mOClow.setEntryValues(entries); final String readsomin = Helpers.LeerUnaLinea(OC_LOW_PATH); mOClow.setValue(readsomin); mOClow.setSummary(ps + readsomin + " kHz"); } } //---- if (Helpers.BinExist("mpdecision") == null) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("mpdecision"); getPreferenceScreen().removePreference(hideCat); } else { Boolean mpdon = Helpers.ModuleisActive("mpdecision"); mMpdecision.setChecked(mpdon); mPreferences.edit().putBoolean("mpdecision", mpdon).apply(); } if (!new File(MSM_HOTPLUG).exists()) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("msmhotplug"); getPreferenceScreen().removePreference(hideCat); } else { mMsmHotplug.setChecked(Helpers.LeerUnaLinea(MSM_HOTPLUG).equals("1")); } if (!new File(INTELLI_PLUG).exists()) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("intelliplug"); getPreferenceScreen().removePreference(hideCat); } else { mIntelliplug.setChecked(Helpers.LeerUnaLinea(INTELLI_PLUG).equals("1")); } if (!new File(INTELLI_PROFILES).exists()) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("intelli_prof"); getPreferenceScreen().removePreference(hideCat); } else { mIntelliprofiles.setEntries(getResources().getStringArray(R.array.intelli_profiles)); mIntelliprofiles.setEntryValues(getResources().getStringArray(R.array.intelli_profiles_values)); mIntelliprofiles.setValue(Helpers.LeerUnaLinea(INTELLI_PROFILES)); mIntelliprofiles.setSummary(intelliprof + mIntelliprofiles.getEntry().toString()); } if (hotpath == null) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("hotplugset"); getPreferenceScreen().removePreference(hideCat); } if (!new File(ECO_MODE).exists()) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("ecomode"); getPreferenceScreen().removePreference(hideCat); } else { mEcomode.setChecked(Helpers.LeerUnaLinea(ECO_MODE).equals("1")); } if (!new File(MC_PS).exists()) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("mc_ps"); getPreferenceScreen().removePreference(hideCat); } else { lmcps.setEntries(getResources().getStringArray(R.array.mc_ps_array)); lmcps.setEntryValues(vmcps); lmcps.setValue(Helpers.LeerUnaLinea(MC_PS)); lmcps.setSummary(ps_mc_ps + lmcps.getEntry().toString()); } if (!new File(GEN_HP).exists()) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("hp"); getPreferenceScreen().removePreference(hideCat); } else { mGenHP.setChecked(Helpers.LeerUnaLinea(GEN_HP).equals("1")); mGenHP.setSummary(getString(R.string.ps_hp) + " | " + getString(R.string.ps_dsync)); } if (!new File(CPU_QUIET_GOV).exists()) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("cpuq"); getPreferenceScreen().removePreference(hideCat); } else { final String cur_cpuq_gov = Helpers.LeerUnaLinea(CPU_QUIET_GOV); final String s = Helpers.LeerUnaLinea(CPU_QUIET_CUR); final CharSequence[] govs = cur_cpuq_gov.split(" "); lcpuq.setEntries(govs); lcpuq.setEntryValues(govs); lcpuq.setValue(s); lcpuq.setSummary(ps_cpuquiet + s); } gpu = new GPUClass(); if (gpu.gpuclk_path() == null) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("gpu_max_clk"); getPreferenceScreen().removePreference(hideCat); } else { lgpufmax.setEntries(gpu.gpuclk_names()); lgpufmax.setEntryValues(gpu.gpuclk_values()); final String s = Helpers.LeerUnaLinea(gpu.gpuclk_path()); lgpufmax.setValue(s); lgpufmax.setSummary(ps + lgpufmax.getEntry()); } if (gpu.gpugovset_path() == null) { PreferenceCategory hideCat = (PreferenceCategory) findPreference("gpugovset"); getPreferenceScreen().removePreference(hideCat); } PreferenceCategory Cat = (PreferenceCategory) findPreference("uv_krait"); if (!new File(KRAIT_ON_PATH).exists()) { getPreferenceScreen().removePreference(Cat); } else { mKraitBoost.setChecked(Helpers.LeerUnaLinea(KRAIT_ON_PATH).equalsIgnoreCase("N")); if (!new File(KRAIT_THRES_PATH).exists()) { Cat.removePreference(mKraitThres); } else { mKraitThres.setEntries(entries); mKraitThres.setEntryValues(entries); final String readthres = Helpers.LeerUnaLinea(KRAIT_THRES_PATH); mKraitThres.setValue(readthres); mKraitThres.setSummary(ps + readthres + " kHz"); } if (!new File(KRAIT_HIGH_PATH).exists()) { Cat.removePreference(mKraitHi); } else { final String s = Helpers.LeerUnaLinea(KRAIT_HIGH_PATH); mKraitHi.setSummary(getString(R.string.ps_krait_hi, s)); mPreferences.edit().putString("pref_krait_hi", s).commit(); } if (!new File(KRAIT_LOWER_PATH).exists()) { Cat.removePreference(mKraitLo); } else { final String s = Helpers.LeerUnaLinea(KRAIT_LOWER_PATH); mKraitLo.setSummary(getString(R.string.ps_krait_lo, s)); mPreferences.edit().putString("pref_krait_lo", s).commit(); } } }
From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java
@Override public void onPreferenceCreate(PreferenceFragment pf) { if (pf != null && !ApplicationScreen.getCameraController().isVideoStabilizationSupported()) { PreferenceCategory cat = (PreferenceCategory) pf.findPreference("Pref_VideoCapture_Category"); CheckBoxPreference cp = (CheckBoxPreference) pf.findPreference("videoStabilizationPref"); if (cp != null && cat != null) cat.removePreference(cp); }/* www. java2s.c o m*/ }
From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java
/** * Refresh the notification privacy setting *//* w w w. j av a 2s . co m*/ private void refreshNotificationPrivacy() { EditTextPreference notificationPrivacyPreference = (EditTextPreference) findPreference( PreferencesManager.SETTINGS_NOTIFICATION_PRIVACY_PREFERENCE_KEY); if (notificationPrivacyPreference != null) { GcmRegistrationManager gcmRegistrationManager = Matrix.getInstance(getActivity()) .getSharedGCMRegistrationManager(); // this setting apply only with GCM for the moment if (gcmRegistrationManager.useGCM()) { String notificationPrivacyString = NotificationPrivacyActivity.getNotificationPrivacyString( getActivity().getApplicationContext(), gcmRegistrationManager.getNotificationPrivacy()); notificationPrivacyPreference.setSummary(notificationPrivacyString); } else { PreferenceCategory notificationsSettingsCategory = (PreferenceCategory) findPreference( PreferencesManager.SETTINGS_NOTIFICATIONS_KEY); notificationsSettingsCategory.removePreference(notificationPrivacyPreference); } } }
From source file:org.exobel.routerkeygen.ui.Preferences.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); getActionBar().setDisplayHomeAsUpEnabled(true); findPreference("download").setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { if (isDictionaryServiceRunning()) { Toast.makeText(getBaseContext(), getString(R.string.pref_msg_download_running), Toast.LENGTH_SHORT).show(); return true; }/*from w w w. ja v a2s. c o m*/ ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo == null || !netInfo.isConnectedOrConnecting()) { Toast.makeText(getBaseContext(), getString(R.string.pref_msg_no_network), Toast.LENGTH_SHORT) .show(); return true; } // Don't complain about dictionary size if user is on a // wifi connection if ((((WifiManager) getBaseContext().getSystemService(Context.WIFI_SERVICE))).getConnectionInfo() .getSSID() != null) { try { checkCurrentDictionary(); } catch (FileNotFoundException e) { e.printStackTrace(); } } else showDialog(DIALOG_ASK_DOWNLOAD); return true; } }); // boolean app_installed = AdsUtils.checkDonation(this); final PreferenceCategory mCategory = (PreferenceCategory) findPreference("2section"); // if (!app_installed) { // mCategory.removePreference(findPreference("analytics_enabled")); // // If you haven't the donate app installed remove the paypal donate // // link. // mCategory.removePreference(findPreference("donate_paypal")); // findPreference("donate_playstore").setOnPreferenceClickListener( // new OnPreferenceClickListener() { // public boolean onPreferenceClick(Preference preference) { // try { // startActivity(new Intent(Intent.ACTION_VIEW, // Uri.parse("market://details?id=" // + GOOGLE_PLAY_DOWNLOADER))); // } catch (android.content.ActivityNotFoundException anfe) { // startActivity(new Intent( // Intent.ACTION_VIEW, // Uri.parse("http://play.google.com/store/apps/details?id=" // + GOOGLE_PLAY_DOWNLOADER))); // } // Toast.makeText(getApplicationContext(), // R.string.msg_donation, Toast.LENGTH_LONG) // .show(); // return true; // } // }); // } else { // // If you have the donate app installed no need to link to it. // mCategory.removePreference(findPreference("donate_playstore")); // if (BuildConfig.APPLICATION_ID.equals("io.github.routerkeygen")) { // //Play Store is quite restrictive nowadays // mCategory.removePreference(findPreference("donate_paypal")); // } else { // findPreference("donate_paypal").setOnPreferenceClickListener( // new OnPreferenceClickListener() { // public boolean onPreferenceClick(Preference preference) { // final String donateLink = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=V3FFBTRTTV5DN"; // Uri uri = Uri.parse(donateLink); // startActivity(new Intent(Intent.ACTION_VIEW, uri)); // // return true; // } // }); // } // } if (BuildConfig.APPLICATION_ID.equals("io.github.routerkeygen")) { mCategory.removePreference(findPreference("update")); } else { findPreference("update").setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { protected void onPreExecute() { showDialog(DIALOG_WAIT); } protected Void doInBackground(Void... params) { lastVersion = UpdateCheckerService.getLatestVersion(); return null; } protected void onPostExecute(Void result) { removeDialog(DIALOG_WAIT); if (isFinishing()) return; if (lastVersion == null) { showDialog(DIALOG_ERROR); return; } if (!Preferences.VERSION.equals(lastVersion.version)) { showDialog(DIALOG_UPDATE_NEEDED); } else { Toast.makeText(Preferences.this, R.string.msg_app_updated, Toast.LENGTH_SHORT) .show(); } } }; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { task.execute(); } else { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } // Checking for updates every week startService(new Intent(getApplicationContext(), UpdateCheckerService.class)); return true; } }); } findPreference("changelog").setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { showDialog(DIALOG_CHANGELOG); return true; } }); findPreference("about").setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { showDialog(DIALOG_ABOUT); return true; } }); findPreference(dicLocalPref).setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { startActivityForResult(new Intent(getApplicationContext(), FileChooserActivity.class), 0); return true; } }); final CheckBoxPreference autoScan = (CheckBoxPreference) findPreference("autoScan"); autoScan.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { findPreference("autoScanInterval").setEnabled(autoScan.isChecked()); return true; } }); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); findPreference("autoScanInterval").setEnabled( prefs.getBoolean(Preferences.autoScanPref, getResources().getBoolean(R.bool.autoScanDefault))); }
From source file:com.owncloud.android.ui.activity.Preferences.java
@SuppressWarnings("deprecation") @Override/* w w w.j av a 2 s . co 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:com.master.metehan.filtereagle.ActivitySettings.java
@Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); final PreferenceScreen screen = getPreferenceScreen(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); PreferenceCategory cat_options = (PreferenceCategory) screen.findPreference("category_options"); PreferenceCategory cat_advanced = (PreferenceCategory) screen.findPreference("category_advanced_options"); PreferenceCategory cat_backup = (PreferenceCategory) screen.findPreference("category_backup"); PreferenceCategory cat_development = (PreferenceCategory) screen.findPreference("category_development"); // Handle auto enable Preference pref_auto_enable = screen.findPreference("auto_enable"); pref_auto_enable.setTitle(getString(R.string.setting_auto, prefs.getString("auto_enable", "0"))); // Handle screen delay Preference pref_screen_delay = screen.findPreference("screen_delay"); pref_screen_delay.setTitle(getString(R.string.setting_delay, prefs.getString("screen_delay", "0"))); // Handle theme Preference pref_screen_theme = screen.findPreference("theme"); String theme = prefs.getString("theme", "teal"); String[] themeNames = getResources().getStringArray(R.array.themeNames); String[] themeValues = getResources().getStringArray(R.array.themeValues); for (int i = 0; i < themeNames.length; i++) if (theme.equals(themeValues[i])) { pref_screen_theme.setTitle(getString(R.string.setting_theme, themeNames[i])); break; }/* ww w.j a v a2 s .c om*/ // Wi-Fi home MultiSelectListPreference pref_wifi_homes = (MultiSelectListPreference) screen.findPreference("wifi_homes"); Set<String> ssid = prefs.getStringSet("wifi_homes", new HashSet<String>()); if (ssid.size() > 0) pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, TextUtils.join(", ", ssid))); else pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, "-")); WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); List<CharSequence> listSSID = new ArrayList<>(); List<WifiConfiguration> configs = wm.getConfiguredNetworks(); if (configs != null) for (WifiConfiguration config : configs) listSSID.add(config.SSID == null ? "NULL" : config.SSID); pref_wifi_homes.setEntries(listSSID.toArray(new CharSequence[0])); pref_wifi_homes.setEntryValues(listSSID.toArray(new CharSequence[0])); // Filtering always enabled if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) cat_advanced.removePreference(screen.findPreference("filter")); Preference pref_reset_usage = screen.findPreference("reset_usage"); pref_reset_usage.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Util.areYouSure(ActivitySettings.this, R.string.setting_reset_usage, new Util.DoubtListener() { @Override public void onSure() { new AsyncTask<Object, Object, Throwable>() { @Override protected Throwable doInBackground(Object... objects) { try { DatabaseHelper.getInstance(ActivitySettings.this).resetUsage(-1); return null; } catch (Throwable ex) { return ex; } } @Override protected void onPostExecute(Throwable ex) { if (ex == null) Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG) .show(); else Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } }.execute(); } }); return false; } }); // Handle port forwarding Preference pref_forwarding = screen.findPreference("forwarding"); pref_forwarding.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivity(new Intent(ActivitySettings.this, ActivityForwarding.class)); return true; } }); // VPN parameters screen.findPreference("vpn4") .setTitle(getString(R.string.setting_vpn4, prefs.getString("vpn4", "10.1.10.1"))); screen.findPreference("vpn6") .setTitle(getString(R.string.setting_vpn6, prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1"))); EditTextPreference pref_dns = (EditTextPreference) screen.findPreference("dns"); List<String> def_dns = Util.getDefaultDNS(this); pref_dns.getEditText().setHint(def_dns.get(0)); pref_dns.setTitle(getString(R.string.setting_dns, prefs.getString("dns", def_dns.get(0)))); // PCAP parameters screen.findPreference("pcap_record_size") .setTitle(getString(R.string.setting_pcap_record_size, prefs.getString("pcap_record_size", "64"))); screen.findPreference("pcap_file_size") .setTitle(getString(R.string.setting_pcap_file_size, prefs.getString("pcap_file_size", "2"))); // Handle stats EditTextPreference pref_stats_frequency = (EditTextPreference) screen.findPreference("stats_frequency"); EditTextPreference pref_stats_samples = (EditTextPreference) screen.findPreference("stats_samples"); pref_stats_frequency .setTitle(getString(R.string.setting_stats_frequency, prefs.getString("stats_frequency", "1000"))); pref_stats_samples .setTitle(getString(R.string.setting_stats_samples, prefs.getString("stats_samples", "90"))); // Handle export Preference pref_export = screen.findPreference("export"); pref_export.setEnabled(getIntentCreateExport().resolveActivity(getPackageManager()) != null); pref_export.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivityForResult(getIntentCreateExport(), ActivitySettings.REQUEST_EXPORT); return true; } }); // Handle import Preference pref_import = screen.findPreference("import"); pref_import.setEnabled(getIntentOpenExport().resolveActivity(getPackageManager()) != null); pref_import.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivityForResult(getIntentOpenExport(), ActivitySettings.REQUEST_IMPORT); return true; } }); // Hosts file settings Preference pref_block_domains = screen.findPreference("use_hosts"); Preference pref_hosts_import = screen.findPreference("hosts_import"); EditTextPreference pref_hosts_url = (EditTextPreference) screen.findPreference("hosts_url"); final Preference pref_hosts_download = screen.findPreference("hosts_download"); if (Util.isPlayStoreInstall(this)) { cat_options.removePreference(screen.findPreference("update_check")); cat_advanced.removePreference(pref_block_domains); cat_advanced.removePreference(pref_forwarding); cat_backup.removePreference(pref_hosts_import); cat_backup.removePreference(pref_hosts_url); cat_backup.removePreference(pref_hosts_download); } else { pref_block_domains.setEnabled(new File(getFilesDir(), "hosts.txt").exists()); String last_import = prefs.getString("hosts_last_import", null); String last_download = prefs.getString("hosts_last_download", null); if (last_import != null) pref_hosts_import.setSummary(getString(R.string.msg_import_last, last_import)); if (last_download != null) pref_hosts_download.setSummary(getString(R.string.msg_download_last, last_download)); // Handle hosts import // https://github.com/Free-Software-for-Android/AdAway/wiki/HostsSources pref_hosts_import.setEnabled(getIntentOpenHosts().resolveActivity(getPackageManager()) != null); pref_hosts_import.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivityForResult(getIntentOpenHosts(), ActivitySettings.REQUEST_HOSTS); return true; } }); // Handle hosts file download pref_hosts_url.setSummary(pref_hosts_url.getText()); pref_hosts_download.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { final File tmp = new File(getFilesDir(), "hosts.tmp"); final File hosts = new File(getFilesDir(), "hosts.txt"); EditTextPreference pref_hosts_url = (EditTextPreference) screen.findPreference("hosts_url"); try { new DownloadTask(ActivitySettings.this, new URL(pref_hosts_url.getText()), tmp, new DownloadTask.Listener() { @Override public void onCompleted() { if (hosts.exists()) hosts.delete(); tmp.renameTo(hosts); String last = SimpleDateFormat.getDateTimeInstance() .format(new Date().getTime()); prefs.edit().putString("hosts_last_download", last).apply(); if (running) { getPreferenceScreen().findPreference("use_hosts").setEnabled(true); pref_hosts_download .setSummary(getString(R.string.msg_download_last, last)); Toast.makeText(ActivitySettings.this, R.string.msg_downloaded, Toast.LENGTH_LONG).show(); } ServiceSinkhole.reload("hosts file download", ActivitySettings.this); } @Override public void onCancelled() { if (tmp.exists()) tmp.delete(); } @Override public void onException(Throwable ex) { if (tmp.exists()) tmp.delete(); if (running) Toast.makeText(ActivitySettings.this, ex.getMessage(), Toast.LENGTH_LONG).show(); } }).execute(); } catch (MalformedURLException ex) { Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } return true; } }); } // Development Preference pref_show_resolved = screen.findPreference("show_resolved"); if (!(Util.isDebuggable(this) || Util.getSelfVersionName(this).contains("beta"))) { screen.removePreference(cat_development); prefs.edit().remove("loglevel").apply(); } else if (!Util.isDebuggable(this)) cat_development.removePreference(pref_show_resolved); // Show resolved pref_show_resolved.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { startActivity(new Intent(ActivitySettings.this, ActivityDns.class)); return true; } }); // Handle technical info Preference.OnPreferenceClickListener listener = new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { updateTechnicalInfo(); return true; } }; // Technical info Preference pref_technical_info = screen.findPreference("technical_info"); Preference pref_technical_network = screen.findPreference("technical_network"); Preference pref_technical_subscription = screen.findPreference("technical_subscription"); pref_technical_info.setEnabled(INTENT_VPN_SETTINGS.resolveActivity(this.getPackageManager()) != null); pref_technical_info.setIntent(INTENT_VPN_SETTINGS); pref_technical_info.setOnPreferenceClickListener(listener); pref_technical_network.setOnPreferenceClickListener(listener); pref_technical_subscription.setOnPreferenceClickListener(listener); updateTechnicalInfo(); }
From source file:cw.kop.autobackground.settings.AppSettingsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("title_app_settings"); Preference clearPref = findPreference("clear_pref"); clearPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override// w ww . j a va2s . c o m public boolean onPreferenceClick(Preference preference) { if (appContext != null) { DialogFactory.ActionDialogListener listener = new DialogFactory.ActionDialogListener() { @Override public void onClickMiddle(View v) { // AppSettings.debugVer2_00(); AppSettings.setUseTutorial(true); this.dismissDialog(); } @Override public void onClickRight(View v) { AppSettings.clearPrefs(appContext); if (AppSettings.useToast()) { Toast.makeText(appContext, "Resetting settings to default", Toast.LENGTH_SHORT) .show(); } this.dismissDialog(); restartActivity(); } }; DialogFactory.showActionDialog(appContext, "Reset All Settings?", "This cannot be undone.", listener, -1, R.string.cancel_button, R.string.ok_button); } return true; } }); findPreference("export_sources").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (appContext != null) { DialogFactory.ActionDialogListener listener = new DialogFactory.ActionDialogListener() { @Override public void onClickMiddle(View v) { AppSettings.setUseTutorial(true); this.dismissDialog(); } @Override public void onClickRight(View v) { final File outputFile = new File(AppSettings.getDownloadPath() + "/Exported/SourceData" + System.currentTimeMillis() + ".txt"); new Thread(new Runnable() { @Override public void run() { exportSources(outputFile); } }).start(); if (AppSettings.useToast()) { Toast.makeText(appContext, "Exporting to " + outputFile.getAbsolutePath(), Toast.LENGTH_SHORT).show(); } this.dismissDialog(); } }; DialogFactory.showActionDialog(appContext, "Export sources?", "", listener, -1, R.string.cancel_button, R.string.ok_button); } return true; } }); findPreference("import_sources").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("file/*"); startActivityForResult(intent, IMPORT_SOURCES_REQUEST_CODE); return true; } }); themePref = findPreference("change_theme"); themePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { showThemeDialogMenu(); return true; } }); setThemePrefSummary(); Preference tutorialPref = findPreference("show_tutorial_source"); tutorialPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Toast.makeText(appContext, "Showing tutorial...", Toast.LENGTH_SHORT).show(); Intent tutorialIntent = new Intent(appContext, TutorialActivity.class); startActivityForResult(tutorialIntent, TutorialActivity.TUTORIAL_REQUEST); return true; } }); toastPref = (SwitchPreference) findPreference("use_toast"); if (!AppSettings.useAdvanced()) { preferenceCategory.removePreference(toastPref); preferenceCategory.removePreference(findPreference("force_multi_pane")); } return inflater.inflate(R.layout.fragment_list, container, false); }