Java Code Examples for android.preference.PreferenceScreen#findPreference()

The following examples show how to use android.preference.PreferenceScreen#findPreference() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwitchAccessPreferenceActivity.java    From talkback with Apache License 2.0 6 votes vote down vote up
private void updateStartScanDelayPrefs() {
  String startScanDelaySeconds =
      Float.toString(SwitchAccessPreferenceUtils.getFirstItemScanDelaySeconds(getActivity()));

  PreferenceScreen autoScanScreen =
      (PreferenceScreen) findPreference(R.string.pref_category_auto_scan_key);
  EditTextPreference autoScanStartDelayPreference =
      (EditTextPreference)
          autoScanScreen.findPreference(getString(R.string.pref_key_start_scan_delay));
  updatePreferenceValue(autoScanStartDelayPreference, startScanDelaySeconds);

  if (VERSION.SDK_INT >= VERSION_CODES.N) {
    PreferenceScreen pointScanScreen =
        (PreferenceScreen) findPreference(R.string.pref_category_point_scan_key);
    EditTextPreference pointScanStartDelayPreference =
        (EditTextPreference)
            pointScanScreen.findPreference(getString(R.string.pref_key_start_scan_delay));
    updatePreferenceValue(pointScanStartDelayPreference, startScanDelaySeconds);
  }
}
 
Example 2
Source File: UsbDevicePreferences.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void resetList() {
    getPreferenceScreen().removeAll();
    addPreferencesFromResource(R.xml.usb_device_preferences);

    PreferenceScreen preferenceScreen = getPreferenceScreen();
    Preference header = preferenceScreen.findPreference(PREF_OBJECT_NAME);
    header.setTitle(mUsbInfo.getName());
    header.setOnPreferenceClickListener(this);

    for (int i = 0; i < mSites.size(); ++i) {
        Website site = mSites.get(i);
        Preference preference = new WebsitePreference(getActivity(), site, mCategory);
        preference.getExtras().putSerializable(SingleWebsitePreferences.EXTRA_SITE, site);
        preference.setFragment(SingleWebsitePreferences.class.getCanonicalName());
        preferenceScreen.addPreference(preference);
    }

    // Force this list to be reloaded if the activity is resumed.
    mSites = null;
}
 
Example 3
Source File: SwitchAccessPreferenceActivity.java    From talkback with Apache License 2.0 6 votes vote down vote up
private void updateLoopCountPrefs() {
  String loopCount =
      Integer.toString(SwitchAccessPreferenceUtils.getNumberOfScanningLoops(getActivity()));

  PreferenceScreen autoScanScreen =
      (PreferenceScreen) findPreference(R.string.pref_category_auto_scan_key);
  EditTextPreference autoScanLoopCountPreference =
      (EditTextPreference)
          autoScanScreen.findPreference(
              getString(R.string.pref_key_point_scan_and_autoscan_loop_count));
  updatePreferenceValue(autoScanLoopCountPreference, loopCount);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    PreferenceScreen pointScanScreen =
        (PreferenceScreen) findPreference(R.string.pref_category_point_scan_key);
    EditTextPreference pointScanLoopCountPreference =
        (EditTextPreference)
            pointScanScreen.findPreference(
                getString(R.string.pref_key_point_scan_and_autoscan_loop_count));
    updatePreferenceValue(pointScanLoopCountPreference, loopCount);
  }
}
 
Example 4
Source File: SettingsFragment.java    From NewsPushMonitor with Apache License 2.0 5 votes vote down vote up
private void addMonitorApp(String pkg) {
    if (TextUtils.isEmpty(pkg)) {
        return;
    }

    PreferenceManager manager = getPreferenceManager();
    try {
        PreferenceScreen screen = (PreferenceScreen) RefUtil.callDeclaredMethod(manager,
                "inflateFromResource",
                new Class[]{Context.class, int.class, PreferenceScreen.class},
                getActivity(), R.xml.prefs_monitor_apps, null);
        screen.setKey(pkg);
        screen.setTitle(pkg);
        screen.setSummary(getMonitorAppSummary(pkg, null));

        PreferenceGroup appConfigPref = (PreferenceGroup) screen.findPreference("monitor_app_config_pref");
        appConfigPref.setTitle(pkg);

        Preference titleViewIdPref = appConfigPref.findPreference("title_view_id_pref");
        titleViewIdPref.setKey(GlobalConfig.getSharedPrefKeyForTitleId(pkg));
        titleViewIdPref.getExtras().putString(KEY_PREF_EXTRA, pkg);
        titleViewIdPref.setOnPreferenceChangeListener(mOnPreferenceChangeListener);

        Preference contentViewIdPref = appConfigPref.findPreference("content_view_id_pref");
        contentViewIdPref.setKey(GlobalConfig.getSharedPrefKeyForContentId(pkg));
        contentViewIdPref.getExtras().putString(KEY_PREF_EXTRA, pkg);
        contentViewIdPref.setOnPreferenceChangeListener(mOnPreferenceChangeListener);

        PreferenceCategory container = (PreferenceCategory)
                getPreferenceManager().findPreference("monitor_apps_pref");
        container.addPreference(screen);
    } catch (Exception e) {
        LogWriter.e(TAG, "Add monitor ppp to preference error!", e);
    }
}
 
Example 5
Source File: PreferencesFragment.java    From ZXing-Standalone-library with Apache License 2.0 5 votes vote down vote up
private static CheckBoxPreference[] findDecodePrefs(PreferenceScreen preferences, String... keys) {
  CheckBoxPreference[] prefs = new CheckBoxPreference[keys.length];
  for (int i = 0; i < keys.length; i++) {
    prefs[i] = (CheckBoxPreference) preferences.findPreference(keys[i]);
  }
  return prefs;
}
 
Example 6
Source File: PreferencesFragment.java    From weex with Apache License 2.0 5 votes vote down vote up
private static CheckBoxPreference[] findDecodePrefs(PreferenceScreen preferences, String... keys) {
  CheckBoxPreference[] prefs = new CheckBoxPreference[keys.length];
  for (int i = 0; i < keys.length; i++) {
    prefs[i] = (CheckBoxPreference) preferences.findPreference(keys[i]);
  }
  return prefs;
}
 
Example 7
Source File: SettingsActivity.java    From mosmetro-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(getString(R.string.pref_category_notifications));
    addPreferencesFromResource(R.xml.pref_notify);

    PreferenceScreen screen = getPreferenceScreen();

    // Link pref_notify_foreground and pref_notify_success_lock
    final CheckBoxPreference foreground = (CheckBoxPreference)
            screen.findPreference("pref_notify_foreground");
    final CheckBoxPreference success = (CheckBoxPreference)
            screen.findPreference("pref_notify_success");
    final CheckBoxPreference success_lock = (CheckBoxPreference)
            screen.findPreference("pref_notify_success_lock");
    foreground.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            success.setEnabled(!((Boolean) newValue));
            success_lock.setEnabled(!((Boolean) newValue));
            return true;
        }
    });
    foreground
            .getOnPreferenceChangeListener()
            .onPreferenceChange(foreground, foreground.isChecked());
}
 
Example 8
Source File: GenericPrefs.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set summary of a list field If empty will display default summary If one
 * item selected will display item name
 * 
 * @param fieldName the preference key name
 */
public void setListFieldSummary(String fieldName) {
    PreferenceScreen pfs = getPreferenceScreen();
    ListPreference pref = (ListPreference) pfs.findPreference(fieldName);
    if (pref == null) {
        Log.w(THIS_FILE, "Unable to find preference " + fieldName);
        return;
    }

    CharSequence val = pref.getEntry();
    if (TextUtils.isEmpty(val)) {
        val = getDefaultFieldSummary(fieldName);
    }
    setPreferenceSummary(pref, val);
}
 
Example 9
Source File: PrefsLoaderFragment.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setStringFieldSummary(String fieldName) {
    PreferenceScreen pfs = getPreferenceScreen();
    SharedPreferences sp = pfs.getSharedPreferences();
    Preference pref = pfs.findPreference(fieldName);

    String val = sp.getString(fieldName, null);
    if (TextUtils.isEmpty(val)) {
        val = getDefaultFieldSummary(fieldName);
    }
    setPreferenceSummary(pref, val);
}
 
Example 10
Source File: SettingsActivity.java    From identity-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.pref_main);

    PreferenceScreen screen = getPreferenceScreen();
    AppSignatureHelper signatureHelper = new AppSignatureHelper(getActivity());

    ArrayList<String> appSignatures = signatureHelper.getAppSignatures();
    Preference pref = screen.findPreference("app_signature");
    if (!appSignatures.isEmpty() && pref != null) {
        pref.setSummary(appSignatures.get(0));
    }
}
 
Example 11
Source File: PreferencesFragment.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
private static CheckBoxPreference[] findDecodePrefs(PreferenceScreen preferences, String... keys) {
  CheckBoxPreference[] prefs = new CheckBoxPreference[keys.length];
  for (int i = 0; i < keys.length; i++) {
    prefs[i] = (CheckBoxPreference) preferences.findPreference(keys[i]);
  }
  return prefs;
}
 
Example 12
Source File: Preferences.java    From Plumble with GNU General Public License v3.0 5 votes vote down vote up
private static void configureAboutPreferences(Context context, PreferenceScreen screen) {
    String version = "Unknown";
    try {
        PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        version = info.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    Preference versionPreference = screen.findPreference(VERSION_KEY);
    versionPreference.setSummary(version);
}
 
Example 13
Source File: SingleWebsitePreferences.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private boolean hasPermissionsPreferences() {
    if (mUsbPermissionCount > 0) return true;
    PreferenceScreen screen = getPreferenceScreen();
    for (String key : PERMISSION_PREFERENCE_KEYS) {
        if (screen.findPreference(key) != null) return true;
    }
    return false;
}
 
Example 14
Source File: SingleWebsitePreferences.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPreferenceClick(Preference preference) {
    Bundle extras = preference.peekExtras();
    if (extras != null) {
        UsbInfo usbInfo = (UsbInfo) extras.getSerializable(EXTRA_USB_INFO);
        if (usbInfo != null) {
            usbInfo.revoke();

            PreferenceScreen preferenceScreen = getPreferenceScreen();
            preferenceScreen.removePreference(preference);
            mUsbPermissionCount--;
            if (!hasPermissionsPreferences()) {
                Preference heading = preferenceScreen.findPreference(PREF_PERMISSIONS);
                preferenceScreen.removePreference(heading);
            }
            return true;
        }
    }

    // Handle the Clear & Reset preference click by showing a confirmation.
    new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme)
            .setTitle(R.string.website_reset)
            .setMessage(R.string.website_reset_confirmation)
            .setPositiveButton(R.string.website_reset, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    resetSite();
                }
            })
            .setNegativeButton(R.string.cancel, null)
            .show();
    return true;
}
 
Example 15
Source File: PreferencesFragment.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
private static CheckBoxPreference[] findDecodePrefs(PreferenceScreen preferences, String... keys) {
  CheckBoxPreference[] prefs = new CheckBoxPreference[keys.length];
  for (int i = 0; i < keys.length; i++) {
    prefs[i] = (CheckBoxPreference) preferences.findPreference(keys[i]);
  }
  return prefs;
}
 
Example 16
Source File: SubScreenFragment.java    From LokiBoard-Android-Keylogger with Apache License 2.0 4 votes vote down vote up
static void removePreference(final String prefKey, final PreferenceScreen screen) {
    final Preference preference = screen.findPreference(prefKey);
    if (preference != null) {
        screen.removePreference(preference);
    }
}
 
Example 17
Source File: Preferences.java    From Plumble with GNU General Public License v3.0 4 votes vote down vote up
private static void configureOrbotPreferences(PreferenceScreen screen) {
    Preference useOrbotPreference = screen.findPreference(USE_TOR_KEY);
    useOrbotPreference.setEnabled(OrbotHelper.isOrbotInstalled(screen.getContext()));
}
 
Example 18
Source File: SubScreenFragment.java    From Android-Keyboard with Apache License 2.0 4 votes vote down vote up
static void removePreference(final String prefKey, final PreferenceScreen screen) {
    final Preference preference = screen.findPreference(prefKey);
    if (preference != null) {
        screen.removePreference(preference);
    }
}
 
Example 19
Source File: SubScreenFragment.java    From simple-keyboard with Apache License 2.0 4 votes vote down vote up
static void removePreference(final String prefKey, final PreferenceScreen screen) {
    final Preference preference = screen.findPreference(prefKey);
    if (preference != null) {
        screen.removePreference(preference);
    }
}
 
Example 20
Source File: SingleWebsitePreferences.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Resets the current site, clearing all permissions and storage used (inc. cookies).
 */
@VisibleForTesting
protected void resetSite() {
    if (getActivity() == null) return;
    // Clear the screen.
    // TODO(mvanouwerkerk): Refactor this class so that it does not depend on the screen state
    // for its logic. This class should maintain its own data model, and only update the screen
    // after a change is made.
    PreferenceScreen screen = getPreferenceScreen();
    for (String key : PERMISSION_PREFERENCE_KEYS) {
        Preference preference = screen.findPreference(key);
        if (preference != null) screen.removePreference(preference);
    }

    String origin = mSite.getAddress().getOrigin();
    WebsitePreferenceBridge.nativeClearCookieData(origin);
    WebsitePreferenceBridge.nativeClearBannerData(origin);

    // Clear the permissions.
    mSite.setAutoplayPermission(ContentSetting.DEFAULT);
    mSite.setBackgroundSyncPermission(ContentSetting.DEFAULT);
    mSite.setCameraPermission(ContentSetting.DEFAULT);
    mSite.setCookiePermission(ContentSetting.DEFAULT);
    mSite.setGeolocationPermission(ContentSetting.DEFAULT);
    mSite.setJavaScriptPermission(ContentSetting.DEFAULT);
    mSite.setMicrophonePermission(ContentSetting.DEFAULT);
    mSite.setMidiPermission(ContentSetting.DEFAULT);
    mSite.setNotificationPermission(ContentSetting.DEFAULT);
    mSite.setPopupPermission(ContentSetting.DEFAULT);
    mSite.setProtectedMediaIdentifierPermission(ContentSetting.DEFAULT);
    mSite.setSubresourceFilterPermission(ContentSetting.DEFAULT);

    for (UsbInfo info : mSite.getUsbInfo()) info.revoke();

    // Clear the storage and finish the activity if necessary.
    if (mSite.getTotalUsage() > 0) {
        clearStoredData();
    } else {
        // Clearing stored data implies popping back to parent menu if there
        // is nothing left to show. Therefore, we only need to explicitly
        // close the activity if there's no stored data to begin with.
        getActivity().finish();
    }
}