Search in sources :

Example 31 with TwoStatePreference

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

the class PulseNotificationPreferenceControllerTest method updateState_preferenceSetCheckedWhenSettingIsOn.

@Test
public void updateState_preferenceSetCheckedWhenSettingIsOn() {
    final TwoStatePreference preference = mock(TwoStatePreference.class);
    final Context context = ShadowApplication.getInstance().getApplicationContext();
    Settings.System.putInt(context.getContentResolver(), NOTIFICATION_LIGHT_PULSE, 1);
    mController = new PulseNotificationPreferenceController(context);
    mController.updateState(preference);
    verify(preference).setChecked(true);
}
Also used : Context(android.content.Context) TwoStatePreference(android.support.v7.preference.TwoStatePreference) Test(org.junit.Test)

Example 32 with TwoStatePreference

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

the class PulseNotificationPreferenceControllerTest method updateState_preferenceSetUncheckedWhenSettingIsOff.

@Test
public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
    final TwoStatePreference preference = mock(TwoStatePreference.class);
    final Context context = ShadowApplication.getInstance().getApplicationContext();
    Settings.System.putInt(context.getContentResolver(), NOTIFICATION_LIGHT_PULSE, 0);
    mController = new PulseNotificationPreferenceController(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 33 with TwoStatePreference

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

the class WorkSoundPreferenceController method updateWorkPreferences.

private void updateWorkPreferences() {
    if (mWorkPreferenceCategory == null) {
        return;
    }
    final boolean isAvailable = isAvailable();
    mWorkPreferenceCategory.setVisible(isAvailable);
    if (!isAvailable) {
        return;
    }
    if (mWorkUsePersonalSounds == null) {
        mWorkUsePersonalSounds = (TwoStatePreference) mWorkPreferenceCategory.findPreference(KEY_WORK_USE_PERSONAL_SOUNDS);
        mWorkUsePersonalSounds.setOnPreferenceChangeListener((Preference p, Object value) -> {
            if ((boolean) value) {
                UnifyWorkDialogFragment.show(mParent);
                return false;
            } else {
                disableWorkSync();
                return true;
            }
        });
    }
    if (mWorkPhoneRingtonePreference == null) {
        mWorkPhoneRingtonePreference = initWorkPreference(mWorkPreferenceCategory, KEY_WORK_PHONE_RINGTONE);
    }
    if (mWorkNotificationRingtonePreference == null) {
        mWorkNotificationRingtonePreference = initWorkPreference(mWorkPreferenceCategory, KEY_WORK_NOTIFICATION_RINGTONE);
    }
    if (mWorkAlarmRingtonePreference == null) {
        mWorkAlarmRingtonePreference = initWorkPreference(mWorkPreferenceCategory, KEY_WORK_ALARM_RINGTONE);
    }
    if (!mVoiceCapable) {
        mWorkPhoneRingtonePreference.setVisible(false);
        mWorkPhoneRingtonePreference = null;
    }
    final Context managedProfileContext = getManagedProfileContext();
    if (Settings.Secure.getIntForUser(managedProfileContext.getContentResolver(), Settings.Secure.SYNC_PARENT_SOUNDS, 0, mManagedProfileId) == 1) {
        enableWorkSyncSettings();
    } else {
        disableWorkSyncSettings();
    }
}
Also used : Context(android.content.Context) TwoStatePreference(android.support.v7.preference.TwoStatePreference) DefaultRingtonePreference(com.android.settings.DefaultRingtonePreference) Preference(android.support.v7.preference.Preference)

Example 34 with TwoStatePreference

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

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 35 with TwoStatePreference

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

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)85 Context (android.content.Context)45 Test (org.junit.Test)42 Preference (android.support.v7.preference.Preference)25 ComponentName (android.content.ComponentName)6 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)6 DefaultRingtonePreference (com.android.settings.DefaultRingtonePreference)6 DropDownPreference (android.support.v7.preference.DropDownPreference)5 InputMethodInfo (android.view.inputmethod.InputMethodInfo)5 ConfigKey (cx.ring.model.ConfigKey)5 Calendar (java.util.Calendar)5 Date (java.util.Date)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