Search in sources :

Example 56 with TwoStatePreference

use of android.support.v7.preference.TwoStatePreference in project ring-client-android by savoirfairelinux.

the class GeneralAccountFragment method setPreferenceDetails.

private void setPreferenceDetails(AccountConfig details) {
    for (ConfigKey confKey : details.getKeys()) {
        Preference pref = findPreference(confKey.key());
        if (pref == null) {
            continue;
        }
        if (!confKey.isTwoState()) {
            String val = details.get(confKey);
            ((EditTextPreference) pref).setText(val);
            if (pref instanceof PasswordPreference) {
                StringBuilder tmp = new StringBuilder();
                for (int i = 0; i < val.length(); ++i) {
                    tmp.append("*");
                }
                pref.setSummary(tmp.toString());
            } else {
                pref.setSummary(val);
            }
        } else {
            ((TwoStatePreference) pref).setChecked(details.getBool(confKey));
        }
    }
}
Also used : ConfigKey(cx.ring.model.ConfigKey) TwoStatePreference(android.support.v7.preference.TwoStatePreference) TwoStatePreference(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference) EditTextPreference(android.support.v7.preference.EditTextPreference) EditTextIntegerPreference(cx.ring.views.EditTextIntegerPreference) PasswordPreference(cx.ring.views.PasswordPreference) PasswordPreference(cx.ring.views.PasswordPreference) EditTextPreference(android.support.v7.preference.EditTextPreference)

Example 57 with TwoStatePreference

use of android.support.v7.preference.TwoStatePreference in project ring-client-android by savoirfairelinux.

the class AdvancedAccountFragment method onPreferenceChange.

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    final ConfigKey key = ConfigKey.fromString(preference.getKey());
    presenter.preferenceChanged(key, newValue);
    if (preference instanceof TwoStatePreference) {
        presenter.twoStatePreferenceChanged(key, newValue);
    } else if (preference instanceof PasswordPreference) {
        presenter.passwordPreferenceChanged(key, newValue);
        preference.setSummary(TextUtils.isEmpty(newValue.toString()) ? "" : "******");
    } else {
        presenter.preferenceChanged(key, newValue);
        preference.setSummary(newValue.toString());
    }
    return true;
}
Also used : ConfigKey(cx.ring.model.ConfigKey) TwoStatePreference(android.support.v7.preference.TwoStatePreference) PasswordPreference(cx.ring.views.PasswordPreference)

Example 58 with TwoStatePreference

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

the class GesturePreferenceControllerTest method updateState_preferenceSetCheckedWhenSettingIsOn.

@Test
public void updateState_preferenceSetCheckedWhenSettingIsOn() {
    // Mock a TwoStatePreference
    final TwoStatePreference preference = mock(TwoStatePreference.class);
    // Set the setting to be enabled.
    mController.mIsPrefEnabled = true;
    // Run through updateState
    mController.updateState(preference);
    // Verify pref is checked (as setting is enabled).
    verify(preference).setChecked(true);
}
Also used : TwoStatePreference(android.support.v7.preference.TwoStatePreference) Test(org.junit.Test)

Example 59 with TwoStatePreference

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

the class BadgingNotificationPreferenceControllerTest method updateState_preferenceSetUncheckedWhenSettingIsOff.

@Test
public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
    final TwoStatePreference preference = mock(TwoStatePreference.class);
    final Context context = ShadowApplication.getInstance().getApplicationContext();
    Settings.Secure.putInt(context.getContentResolver(), NOTIFICATION_BADGING, 0);
    mController = new BadgingNotificationPreferenceController(context);
    mController.updateState(preference);
    verify(preference).setChecked(false);
}
Also used : Context(android.content.Context) TwoStatePreference(android.support.v7.preference.TwoStatePreference) Test(org.junit.Test)

Example 60 with TwoStatePreference

use of android.support.v7.preference.TwoStatePreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ConfigureNotificationSettings method initPulse.

// === Pulse notification light ===
private void initPulse() {
    final NotificationManager nm = mContext.getSystemService(NotificationManager.class);
    final PreferenceCategory category = (PreferenceCategory) findPreference("lights");
    mNotificationPulse = (TwoStatePreference) category.findPreference(KEY_NOTIFICATION_PULSE);
    if (mNotificationPulse == null) {
        Log.i(TAG, "Preference not found: " + KEY_NOTIFICATION_PULSE);
        return;
    }
    if (!getResources().getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed) || !nm.doLightsSupport(NotificationManager.LIGHTS_PULSATING_LED)) {
        category.removePreference(mNotificationPulse);
    } else {
        updatePulse();
        mNotificationPulse.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                final boolean val = (Boolean) newValue;
                return Settings.System.putInt(getContentResolver(), Settings.System.NOTIFICATION_LIGHT_PULSE, val ? 1 : 0);
            }
        });
    }
}
Also used : NotificationManager(android.app.NotificationManager) PreferenceCategory(android.support.v7.preference.PreferenceCategory) TwoStatePreference(android.support.v7.preference.TwoStatePreference) Preference(android.support.v7.preference.Preference) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener)

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