Search in sources :

Example 6 with DropDownPreference

use of androidx.preference.DropDownPreference in project android_packages_apps_Settings by omnirom.

the class WifiMeteredPreferenceController2 method updateState.

@Override
public void updateState(Preference preference) {
    final DropDownPreference dropDownPreference = (DropDownPreference) preference;
    final int meteredOverride = getMeteredOverride();
    preference.setSelectable(mWifiEntry.canSetMeteredChoice());
    dropDownPreference.setValue(Integer.toString(meteredOverride));
    updateSummary(dropDownPreference, meteredOverride);
}
Also used : DropDownPreference(androidx.preference.DropDownPreference)

Example 7 with DropDownPreference

use of androidx.preference.DropDownPreference in project android_packages_apps_Settings by omnirom.

the class WifiMeteredPreferenceController2Test method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = RuntimeEnvironment.application;
    mPreferenceController = spy(new WifiMeteredPreferenceController2(mContext, mWifiEntry));
    mDropDownPreference = new DropDownPreference(mContext);
    mDropDownPreference.setEntries(R.array.wifi_metered_entries);
    mDropDownPreference.setEntryValues(R.array.wifi_metered_values);
}
Also used : DropDownPreference(androidx.preference.DropDownPreference) Before(org.junit.Before)

Example 8 with DropDownPreference

use of androidx.preference.DropDownPreference in project android_packages_apps_Settings by omnirom.

the class WifiPrivacyPreferenceController2Test method setUp.

@Before
public void setUp() {
    mContext = RuntimeEnvironment.application;
    mMockWifiEntry = mock(WifiEntry.class);
    WifiPrivacyPreferenceController2 preferenceController = new WifiPrivacyPreferenceController2(mContext);
    preferenceController.setWifiEntry(mMockWifiEntry);
    mPreferenceController = spy(preferenceController);
    mDropDownPreference = new DropDownPreference(mContext);
    mDropDownPreference.setEntries(R.array.wifi_privacy_entries);
    mDropDownPreference.setEntryValues(R.array.wifi_privacy_values);
    mPerferenceStrings = mContext.getResources().getStringArray(R.array.wifi_privacy_entries);
}
Also used : WifiEntry(com.android.wifitrackerlib.WifiEntry) DropDownPreference(androidx.preference.DropDownPreference) Before(org.junit.Before)

Example 9 with DropDownPreference

use of androidx.preference.DropDownPreference in project android_packages_apps_Settings by omnirom.

the class WifiPrivacyPreferenceController2 method updateState.

@Override
public void updateState(Preference preference) {
    final DropDownPreference dropDownPreference = (DropDownPreference) preference;
    final int randomizationLevel = getRandomizationValue();
    final boolean isSelectable = mWifiEntry.canSetPrivacy();
    preference.setSelectable(isSelectable);
    dropDownPreference.setValue(Integer.toString(randomizationLevel));
    updateSummary(dropDownPreference, randomizationLevel);
    // If the preference cannot be selectable, display a temporary network in the summary.
    if (!isSelectable) {
        dropDownPreference.setSummary(R.string.wifi_privacy_settings_ephemeral_summary);
    }
}
Also used : DropDownPreference(androidx.preference.DropDownPreference)

Example 10 with DropDownPreference

use of androidx.preference.DropDownPreference in project android_packages_apps_Settings by omnirom.

the class SettingPref method init.

public Preference init(SettingsPreferenceFragment settings) {
    final Context context = settings.getActivity();
    Preference p = settings.getPreferenceScreen().findPreference(mKey);
    if (p != null && !isApplicable(context)) {
        settings.getPreferenceScreen().removePreference(p);
        p = null;
    }
    if (p instanceof TwoStatePreference) {
        mTwoState = (TwoStatePreference) p;
    } else if (p instanceof DropDownPreference) {
        mDropDown = (DropDownPreference) p;
        CharSequence[] entries = new CharSequence[mValues.length];
        CharSequence[] values = new CharSequence[mValues.length];
        for (int i = 0; i < mValues.length; i++) {
            entries[i] = getCaption(context.getResources(), mValues[i]);
            values[i] = Integer.toString(mValues[i]);
        }
        mDropDown.setEntries(entries);
        mDropDown.setEntryValues(values);
    }
    update(context);
    if (mTwoState != null) {
        p.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                setSetting(context, (Boolean) newValue ? 1 : 0);
                return true;
            }
        });
        return mTwoState;
    }
    if (mDropDown != null) {
        p.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                return setSetting(context, Integer.parseInt((String) newValue));
            }
        });
        return mDropDown;
    }
    return null;
}
Also used : Context(android.content.Context) TwoStatePreference(androidx.preference.TwoStatePreference) TwoStatePreference(androidx.preference.TwoStatePreference) DropDownPreference(androidx.preference.DropDownPreference) Preference(androidx.preference.Preference) OnPreferenceChangeListener(androidx.preference.Preference.OnPreferenceChangeListener) DropDownPreference(androidx.preference.DropDownPreference)

Aggregations

DropDownPreference (androidx.preference.DropDownPreference)20 Before (org.junit.Before)10 Context (android.content.Context)4 Preference (androidx.preference.Preference)4 OnPreferenceChangeListener (androidx.preference.Preference.OnPreferenceChangeListener)4 PreferenceScreen (androidx.preference.PreferenceScreen)2 TwoStatePreference (androidx.preference.TwoStatePreference)2 WifiEntry (com.android.wifitrackerlib.WifiEntry)1