Example usage for android.preference PreferenceScreen findPreference

List of usage examples for android.preference PreferenceScreen findPreference

Introduction

In this page you can find the example usage for android.preference PreferenceScreen findPreference.

Prototype

public Preference findPreference(CharSequence key) 

Source Link

Document

Finds a Preference based on its key.

Usage

From source file:com.droidvnteam.romstats.PreviewActivity.java

@SuppressWarnings("deprecation")
@Override//from   ww  w . j  a  va2s  .c  o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.preview_data);

    final PreferenceScreen prefSet = getPreferenceScreen();
    final Context context = getApplicationContext();

    prefSet.findPreference(UNIQUE_ID).setSummary(Utilities.getUniqueID(context));
    prefSet.findPreference(DEVICE).setSummary(Utilities.getDevice());
    prefSet.findPreference(VERSION).setSummary(Utilities.getModVersion());
    prefSet.findPreference(BUILDTYPE).setSummary(Utilities.getBuildType());
    prefSet.findPreference(COUNTRY).setSummary(Utilities.getCountryCode(context));
    prefSet.findPreference(CARRIER).setSummary(Utilities.getCarrier(context));
    prefSet.findPreference(ROMNAME).setSummary(Utilities.getRomName());
    prefSet.findPreference(ROMVERSION).setSummary(Utilities.getRomVersion());

}

From source file:com.Candy.ota.settings.Settings.java

@SuppressWarnings("deprecation")
@Override/*from w  ww  .j  a v  a 2s  . c  o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    addPreferencesFromResource(R.xml.candy_ota_settings);

    PreferenceScreen prefs = getPreferenceScreen();

    mUpdateInterval = (ListPreference) prefs.findPreference(KEY_UPDATE_INTERVAL);
    mUpdateInterval.setValueIndex(getUpdateInterval());
    mUpdateInterval.setSummary(mUpdateInterval.getEntry());
    mUpdateInterval.setOnPreferenceChangeListener(this);

}

From source file:com.slim.ota.settings.Settings.java

@SuppressWarnings("deprecation")
@Override/*from ww  w.j av a  2  s.  co  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    addPreferencesFromResource(R.xml.slim_ota_settings);

    PreferenceScreen prefs = getPreferenceScreen();

    mUpdateInterval = (ListPreference) prefs.findPreference(KEY_UPDATE_INTERVAL);
    mUpdateInterval.setValueIndex(getUpdateInterval());
    mUpdateInterval.setSummary(mUpdateInterval.getEntry());
    mUpdateInterval.setOnPreferenceChangeListener(this);

}

From source file:org.chromium.chrome.browser.preferences.website.UsbDevicePreferences.java

private void resetList() {
    getPreferenceScreen().removeAll();//  w w  w  . ja v  a2 s . co m
    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;
}

From source file:ru.orangesoftware.financisto2.activity.PreferencesActivity.java

private void linkToDropbox() {
    boolean dropboxAuthorized = MyPreferences.isDropboxAuthorized(this);
    PreferenceScreen preferenceScreen = getPreferenceScreen();
    preferenceScreen.findPreference("dropbox_unlink").setEnabled(dropboxAuthorized);
    preferenceScreen.findPreference("dropbox_upload_backup").setEnabled(dropboxAuthorized);
    preferenceScreen.findPreference("dropbox_upload_autobackup").setEnabled(dropboxAuthorized);
}

From source file:ru.orangesoftware.financisto2.activity.PreferencesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    getActionBar().setHomeButtonEnabled(true);

    PreferenceScreen preferenceScreen = getPreferenceScreen();
    Preference pLocale = preferenceScreen.findPreference("ui_language");
    pLocale.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override//from   ww  w .  jav a 2s.  c o m
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            String locale = (String) newValue;
            MyPreferences.switchLocale(PreferencesActivity.this, locale);
            return true;
        }
    });
    Preference pNewTransactionShortcut = preferenceScreen.findPreference("shortcut_new_transaction");
    pNewTransactionShortcut.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference arg0) {
            addShortcut(".activity.TransactionActivity", R.string.transaction, R.drawable.icon_transaction);
            return true;
        }

    });
    Preference pNewTransferShortcut = preferenceScreen.findPreference("shortcut_new_transfer");
    pNewTransferShortcut.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference arg0) {
            addShortcut(".activity.TransferActivity", R.string.transfer, R.drawable.icon_transfer);
            return true;
        }
    });
    Preference pDatabaseBackupFolder = preferenceScreen.findPreference("database_backup_folder");
    pDatabaseBackupFolder.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference arg0) {
            selectDatabaseBackupFolder();
            return true;
        }
    });
    Preference pAuthDropbox = preferenceScreen.findPreference("dropbox_authorize");
    pAuthDropbox.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference arg0) {
            authDropbox();
            return true;
        }
    });
    Preference pDeauthDropbox = preferenceScreen.findPreference("dropbox_unlink");
    pDeauthDropbox.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference arg0) {
            deAuthDropbox();
            return true;
        }
    });
    Preference pExchangeProvider = preferenceScreen.findPreference("exchange_rate_provider");
    pOpenExchangeRatesAppId = preferenceScreen.findPreference("openexchangerates_app_id");
    pExchangeProvider.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            pOpenExchangeRatesAppId.setEnabled(isOpenExchangeRatesProvider((String) newValue));
            return true;
        }

        private boolean isOpenExchangeRatesProvider(String provider) {
            return ExchangeRateProviderFactory.openexchangerates.name().equals(provider);
        }
    });
    Preference pDriveAccount = preferenceScreen.findPreference("google_drive_backup_account");
    pDriveAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference arg0) {
            chooseAccount();
            return true;
        }
    });
    linkToDropbox();
    setCurrentDatabaseBackupFolder();
    enableOpenExchangeApp();
    selectAccount();
}

From source file:net.openfiretechnologies.veloxcontrol.fragments.ActiveDisplaySettings.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.active_display_settings);

    mContext = getActivity();/*from  www.  j  a  v a  2s .c  om*/
    resolver = mContext.getContentResolver();
    preferenceHelper = new PreferenceHelper(getActivity());
    mDebug = preferenceHelper.getBoolean(VC_EXTENSIVE_LOGGING);

    if (preferenceHelper.getBoolean(PREF_AUTOBACKUP_ENABLED)) {
        String[] backup = preferenceHelper.getString(PREF_AUTOBACKUP_LIST).split("\\|");
        for (String s : backup) {
            if (s.equals(BackupTool.BACKUP_ADVANCED_DISPLAY) || s.equals(BackupTool.BACKUP_ALL))
                mAutoBackup = true;
        }
    }
    logDebug("ActiveDisplay - AutoBackup: " + (mAutoBackup ? "true" : "false"));

    mEnabledPref = (SwitchPreference) findPreference(KEY_ENABLED);
    mEnabledPref.setChecked((Settings.System.getInt(resolver, Settings.System.ENABLE_ACTIVE_DISPLAY, 0) == 1));
    mEnabledPref.setOnPreferenceChangeListener(this);

    mShowTextPref = (CheckBoxPreference) findPreference(KEY_SHOW_TEXT);
    mShowTextPref.setChecked((Settings.System.getInt(resolver, Settings.System.ACTIVE_DISPLAY_TEXT, 0) == 1));

    mAllNotificationsPref = (CheckBoxPreference) findPreference(KEY_ALL_NOTIFICATIONS);
    mAllNotificationsPref.setChecked(
            (Settings.System.getInt(resolver, Settings.System.ACTIVE_DISPLAY_ALL_NOTIFICATIONS, 0) == 1));

    mHideLowPriorityPref = (CheckBoxPreference) findPreference(KEY_HIDE_LOW_PRIORITY);
    mHideLowPriorityPref.setChecked((Settings.System.getInt(resolver,
            Settings.System.ACTIVE_DISPLAY_HIDE_LOW_PRIORITY_NOTIFICATIONS, 0) == 1));

    mPocketModePref = (ListPreference) findPreference(KEY_POCKET_MODE);
    mPocketModePref.setOnPreferenceChangeListener(this);
    int mode = Settings.System.getInt(resolver, Settings.System.ACTIVE_DISPLAY_POCKET_MODE, 0);
    updatePocketModeSummary(mode);

    if (!hasProximitySensor()) {
        getPreferenceScreen().removePreference(mPocketModePref);
    }

    mSunlightModePref = (CheckBoxPreference) findPreference(KEY_SUNLIGHT_MODE);
    mSunlightModePref.setChecked(
            (Settings.System.getInt(resolver, Settings.System.ACTIVE_DISPLAY_SUNLIGHT_MODE, 0) == 1));
    if (!hasLightSensor()) {
        getPreferenceScreen().removePreference(mSunlightModePref);
    }

    PreferenceScreen prefSet = getPreferenceScreen();
    mRedisplayPref = (ListPreference) prefSet.findPreference(KEY_REDISPLAY);
    mRedisplayPref.setOnPreferenceChangeListener(this);
    long timeout = Settings.System.getLong(resolver, Settings.System.ACTIVE_DISPLAY_REDISPLAY, 0);
    mRedisplayPref.setValue(String.valueOf(timeout));
    updateRedisplaySummary(timeout);

    mShowDatePref = (CheckBoxPreference) findPreference(KEY_SHOW_DATE);
    mShowDatePref
            .setChecked((Settings.System.getInt(resolver, Settings.System.ACTIVE_DISPLAY_SHOW_DATE, 0) == 1));

    mShowAmPmPref = (CheckBoxPreference) findPreference(KEY_SHOW_AMPM);
    mShowAmPmPref
            .setChecked((Settings.System.getInt(resolver, Settings.System.ACTIVE_DISPLAY_SHOW_AMPM, 0) == 1));

    int brightness;
    try {
        brightness = Settings.System.getInt(resolver, Settings.System.ACTIVE_DISPLAY_BRIGHTNESS);
    } catch (Exception e) {
        brightness = 100;
        Settings.System.putInt(resolver, Settings.System.ACTIVE_DISPLAY_BRIGHTNESS, 100);
    }
    mBrightnessLevel = (IntSeekBarPreference) findPreference(KEY_BRIGHTNESS);
    mBrightnessLevel.setInitValue(brightness);
    mBrightnessLevel.setProperty(Settings.System.ACTIVE_DISPLAY_BRIGHTNESS);
    mBrightnessLevel.setOnPreferenceChangeListener(this);

    mDisplayTimeout = (ListPreference) prefSet.findPreference(KEY_TIMEOUT);
    mDisplayTimeout.setOnPreferenceChangeListener(this);
    timeout = Settings.System.getLong(resolver, Settings.System.ACTIVE_DISPLAY_TIMEOUT, 8000L);
    mDisplayTimeout.setValue(String.valueOf(timeout));
    updateTimeoutSummary(timeout);

    mExcludedAppsPref = (AppMultiSelectListPreference) findPreference(KEY_EXCLUDED_APPS);
    Set<String> excludedApps = getExcludedApps();
    if (excludedApps != null)
        mExcludedAppsPref.setValues(excludedApps);
    mExcludedAppsPref.setOnPreferenceChangeListener(this);
}

From source file:com.jmstudios.redmoon.fragment.ShadesFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.preferences);

    String darkThemePrefKey = getString(R.string.pref_key_dark_theme);
    String lowerBrightnessPrefKey = getString(R.string.pref_key_control_brightness);
    String automaticFilterPrefKey = getString(R.string.pref_key_automatic_filter);
    String automaticTurnOnPrefKey = getString(R.string.pref_key_custom_start_time);
    String automaticTurnOffPrefKey = getString(R.string.pref_key_custom_end_time);
    String locationPrefKey = getString(R.string.pref_key_location);
    String otherCategoryPrefKey = getString(R.string.pref_key_other);

    PreferenceScreen prefScreen = getPreferenceScreen();
    darkThemePref = (SwitchPreference) prefScreen.findPreference(darkThemePrefKey);
    lowerBrightnessPref = (SwitchPreference) prefScreen.findPreference(lowerBrightnessPrefKey);
    automaticFilterPref = (ListPreference) prefScreen.findPreference(automaticFilterPrefKey);
    automaticTurnOnPref = (FilterTimePreference) prefScreen.findPreference(automaticTurnOnPrefKey);
    automaticTurnOffPref = (FilterTimePreference) prefScreen.findPreference(automaticTurnOffPrefKey);
    locationPref = (LocationPreference) prefScreen.findPreference(locationPrefKey);
    otherPrefCategory = prefScreen.findPreference(otherCategoryPrefKey);

    darkThemePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override//from   w  w  w .  j a  va 2s. c o  m
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            getActivity().recreate();
            return true;
        }
    });

    if (android.os.Build.VERSION.SDK_INT >= 23 && !Settings.System.canWrite(getContext()))
        lowerBrightnessPref.setChecked(false);

    lowerBrightnessPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean checked = (Boolean) newValue;
            if (checked && android.os.Build.VERSION.SDK_INT >= 23 && !Settings.System.canWrite(getContext())) {
                Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS,
                        Uri.parse("package:" + getContext().getPackageName()));
                startActivityForResult(intent, -1);
                return false;
            }

            return true;
        }
    });

    boolean custom = automaticFilterPref.getValue().toString().equals("custom");
    automaticTurnOnPref.setEnabled(custom);
    automaticTurnOffPref.setEnabled(custom);
    boolean sun = automaticFilterPref.getValue().toString().equals("sun");
    locationPref.setEnabled(sun);

    automaticFilterPref.setSummary(automaticFilterPref.getEntry());

    onAutomaticFilterPreferenceChange(automaticFilterPref, automaticFilterPref.getValue().toString());

    automaticFilterPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            return onAutomaticFilterPreferenceChange(preference, newValue);
        }
    });

    locationPref.setOnLocationChangedListener(new LocationPreference.OnLocationChangedListener() {
        @Override
        public void onLocationChange() {
            if (automaticFilterPref.getValue().equals("sun")) {
                updateFilterTimesFromSun();
            }
        }
    });

}

From source file:eu.funceptionapps.convertitall.ui.SettingsInterface.java

@SuppressWarnings("deprecation")
@Override// www .j av a  2 s  . c  o  m
public void onCreate(Bundle savedInstanceState) {

    InitView.setTheme(prefs, this);

    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);

    PreferenceScreen prefSet = getPreferenceScreen();

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }

    mSelectedCurrencies = prefSet.findPreference(SELECTED_CURRENCIES_PREF);
    mSelectedLengths = prefSet.findPreference(SELECTED_LENGTHS_PREF);
    mSelectedTemperatures = prefSet.findPreference(SELECTED_TEMPERATURES_PREF);
    mSelectedBytes = prefSet.findPreference(SELECTED_BYTES_PREF);
    mSelectedNumSys = prefSet.findPreference(SELECTED_NUMSYS_PREF);
    mSelectedForces = prefSet.findPreference(SELECTED_FORCES_PREF);

    mThemeSetting = (ListPreference) prefSet.findPreference(THEME_SETTING_PREF);
    mChangelog = prefSet.findPreference(CHANGELOG_PREF);
    mVersionPreference = prefSet.findPreference(VERSION_PREF);
    //mXDAThread = prefSet.findPreference(XDA_THREAD_PREF);

    mThemeSetting.setSummary(themeSum);

    mThemeSetting.setValueIndex(Integer.valueOf(prefs.getString(THEME_SETTING_PREF, "0")));

    mThemeSetting.setOnPreferenceChangeListener(this);

    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        mVersionPreference.setSummary(pInfo.versionName);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    setResult(Activity.RESULT_CANCELED);
}