Search in sources :

Example 46 with TwoStatePreference

use of android.support.v7.preference.TwoStatePreference in project android_packages_apps_Settings by DirtyUnicorns.

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(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference) TwoStatePreference(android.support.v7.preference.TwoStatePreference) DropDownPreference(android.support.v7.preference.DropDownPreference) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener) DropDownPreference(android.support.v7.preference.DropDownPreference)

Example 47 with TwoStatePreference

use of android.support.v7.preference.TwoStatePreference in project vlc-android by GeoffreyMetais.

the class PreferencesExtensionFragment method onPreferenceTreeClick.

@Override
public boolean onPreferenceTreeClick(Preference preference) {
    String key = preference.getKey();
    if (key == null || !key.startsWith(mExtensionKey))
        return false;
    if (key.equals(mExtensionKey)) {
        SwitchPreferenceCompat switchPreference = (SwitchPreferenceCompat) preference;
        mSettings.edit().putBoolean(key, switchPreference.isChecked()).apply();
        if (switchPreference.isChecked()) {
            for (Preference checkbox : preferences) checkbox.setEnabled(true);
        } else {
            for (Preference checkbox : preferences) {
                ((CheckBoxPreference) checkbox).setChecked(false);
                mSettings.edit().putBoolean(checkbox.getKey(), false).apply();
                checkbox.setEnabled(false);
            }
        }
    } else if (key.endsWith("_" + ExtensionsManager.ANDROID_AUTO_SUFFIX)) {
        mSettings.edit().putBoolean(preference.getKey(), ((TwoStatePreference) preference).isChecked()).apply();
    }
    return super.onPreferenceTreeClick(preference);
}
Also used : SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) TwoStatePreference(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference)

Example 48 with TwoStatePreference

use of android.support.v7.preference.TwoStatePreference in project platform_packages_apps_Settings by BlissRoms.

the class AssistFlashScreenPreferenceController method updatePreference.

private void updatePreference() {
    if (mPreference == null || !(mPreference instanceof TwoStatePreference)) {
        return;
    }
    if (isAvailable()) {
        if (mScreen.findPreference(getPreferenceKey()) == null) {
            // add it if it's not on scree
            mScreen.addPreference(mPreference);
        }
    } else {
        mScreen.removePreference(mPreference);
    }
    ComponentName assistant = getCurrentAssist();
    boolean isContextChecked = AssistContextPreferenceController.isChecked(mContext);
    mPreference.setEnabled(isContextChecked && isPreInstalledAssistant(assistant));
    ((TwoStatePreference) mPreference).setChecked(willShowFlash(assistant));
}
Also used : TwoStatePreference(android.support.v7.preference.TwoStatePreference) ComponentName(android.content.ComponentName)

Example 49 with TwoStatePreference

use of android.support.v7.preference.TwoStatePreference in project platform_packages_apps_Settings by BlissRoms.

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(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference) TwoStatePreference(android.support.v7.preference.TwoStatePreference) DropDownPreference(android.support.v7.preference.DropDownPreference) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener) DropDownPreference(android.support.v7.preference.DropDownPreference)

Example 50 with TwoStatePreference

use of android.support.v7.preference.TwoStatePreference in project platform_packages_apps_Settings by BlissRoms.

the class TimeFormatPreferenceController method updateState.

@Override
public void updateState(Preference preference) {
    if (!(preference instanceof TwoStatePreference)) {
        return;
    }
    ((TwoStatePreference) preference).setChecked(is24Hour());
    final Calendar now = Calendar.getInstance();
    mDummyDate.setTimeZone(now.getTimeZone());
    // We use December 31st because it's unambiguous when demonstrating the date format.
    // We use 13:00 so we can demonstrate the 12/24 hour options.
    mDummyDate.set(now.get(Calendar.YEAR), 11, 31, 13, 0, 0);
    final Date dummyDate = mDummyDate.getTime();
    preference.setSummary(DateFormat.getTimeFormat(mContext).format(dummyDate));
}
Also used : TwoStatePreference(android.support.v7.preference.TwoStatePreference) Calendar(java.util.Calendar) Date(java.util.Date)

Aggregations

TwoStatePreference (android.support.v7.preference.TwoStatePreference)94 Context (android.content.Context)50 Test (org.junit.Test)48 Preference (android.support.v7.preference.Preference)26 ComponentName (android.content.ComponentName)7 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)7 DropDownPreference (android.support.v7.preference.DropDownPreference)6 DefaultRingtonePreference (com.android.settings.DefaultRingtonePreference)6 Calendar (java.util.Calendar)6 Date (java.util.Date)6 InputMethodInfo (android.view.inputmethod.InputMethodInfo)5 ConfigKey (cx.ring.model.ConfigKey)5 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)4 EditTextPreference (android.support.v7.preference.EditTextPreference)3 PreferenceScreen (android.support.v7.preference.PreferenceScreen)3 File (java.io.File)3 PackageManager (android.content.pm.PackageManager)2 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)2 ListPreference (android.support.v7.preference.ListPreference)2 SwitchPreferenceCompat (android.support.v7.preference.SwitchPreferenceCompat)2