Search in sources :

Example 56 with ListPreference

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

the class ApplicationSettings method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.application_settings);
    mToggleAdvancedSettings = (CheckBoxPreference) findPreference(KEY_TOGGLE_ADVANCED_SETTINGS);
    mToggleAdvancedSettings.setChecked(isAdvancedSettingsEnabled());
    getPreferenceScreen().removePreference(mToggleAdvancedSettings);
    // not ready for prime time yet
    if (false) {
        getPreferenceScreen().removePreference(mInstallLocation);
    }
    mInstallLocation = (ListPreference) findPreference(KEY_APP_INSTALL_LOCATION);
    // Is app default install location set?
    boolean userSetInstLocation = (Settings.Global.getInt(getContentResolver(), Settings.Global.SET_INSTALL_LOCATION, 0) != 0);
    if (!userSetInstLocation) {
        getPreferenceScreen().removePreference(mInstallLocation);
    } else {
        mInstallLocation.setValue(getAppInstallLocation());
        mInstallLocation.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                String value = (String) newValue;
                handleUpdateAppInstallLocation(value);
                return false;
            }
        });
    }
}
Also used : Preference(android.support.v7.preference.Preference) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) ListPreference(android.support.v7.preference.ListPreference) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener)

Example 57 with ListPreference

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

the class AccessibilitySettings method initializeAllPreferences.

private void initializeAllPreferences() {
    for (int i = 0; i < CATEGORIES.length; i++) {
        PreferenceCategory prefCategory = (PreferenceCategory) findPreference(CATEGORIES[i]);
        mCategoryToPrefCategoryMap.put(CATEGORIES[i], prefCategory);
    }
    // Text contrast.
    mToggleHighTextContrastPreference = (SwitchPreference) findPreference(TOGGLE_HIGH_TEXT_CONTRAST_PREFERENCE);
    // Display inversion.
    mToggleInversionPreference = (SwitchPreference) findPreference(TOGGLE_INVERSION_PREFERENCE);
    mToggleInversionPreference.setOnPreferenceChangeListener(this);
    // Power button ends calls.
    mTogglePowerButtonEndsCallPreference = (SwitchPreference) findPreference(TOGGLE_POWER_BUTTON_ENDS_CALL_PREFERENCE);
    if (!KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_POWER) || !Utils.isVoiceCapable(getActivity())) {
        mCategoryToPrefCategoryMap.get(CATEGORY_INTERACTION_CONTROL).removePreference(mTogglePowerButtonEndsCallPreference);
    }
    // Lock screen rotation.
    // mToggleLockScreenRotationPreference =
    // (SwitchPreference) findPreference(TOGGLE_LOCK_SCREEN_ROTATION_PREFERENCE);
    // if (!RotationPolicy.isRotationSupported(getActivity())) {
    // mCategoryToPrefCategoryMap.get(CATEGORY_INTERACTION_CONTROL)
    // .removePreference(mToggleLockScreenRotationPreference);
    // }
    // Large pointer icon.
    mToggleLargePointerIconPreference = (SwitchPreference) findPreference(TOGGLE_LARGE_POINTER_ICON);
    // Master Mono
    mToggleMasterMonoPreference = (SwitchPreference) findPreference(TOGGLE_MASTER_MONO);
    // Long press timeout.
    mSelectLongPressTimeoutPreference = (ListPreference) findPreference(SELECT_LONG_PRESS_TIMEOUT_PREFERENCE);
    mSelectLongPressTimeoutPreference.setOnPreferenceChangeListener(this);
    if (mLongPressTimeoutValueToTitleMap.size() == 0) {
        String[] timeoutValues = getResources().getStringArray(R.array.long_press_timeout_selector_values);
        mLongPressTimeoutDefault = Integer.parseInt(timeoutValues[0]);
        String[] timeoutTitles = getResources().getStringArray(R.array.long_press_timeout_selector_titles);
        final int timeoutValueCount = timeoutValues.length;
        for (int i = 0; i < timeoutValueCount; i++) {
            mLongPressTimeoutValueToTitleMap.put(timeoutValues[i], timeoutTitles[i]);
        }
    }
    // Captioning.
    mCaptioningPreferenceScreen = findPreference(CAPTIONING_PREFERENCE_SCREEN);
    // Display magnification.
    mDisplayMagnificationPreferenceScreen = findPreference(DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN);
    configureMagnificationPreferenceIfNeeded(mDisplayMagnificationPreferenceScreen);
    // Font size.
    // mFontSizePreferenceScreen = findPreference(FONT_SIZE_PREFERENCE_SCREEN);
    // Autoclick after pointer stops.
    mAutoclickPreferenceScreen = findPreference(AUTOCLICK_PREFERENCE_SCREEN);
    // Display color adjustments.
    mDisplayDaltonizerPreferenceScreen = findPreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN);
    // Accessibility shortcut
    mAccessibilityShortcutPreferenceScreen = findPreference(ACCESSIBILITY_SHORTCUT_PREFERENCE);
}
Also used : PreferenceCategory(android.support.v7.preference.PreferenceCategory)

Example 58 with ListPreference

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

the class WifiTetherApBandPreferenceController method displayPreference.

@Override
public void displayPreference(PreferenceScreen screen) {
    super.displayPreference(screen);
    ListPreference preference = (ListPreference) mPreference;
    if (!is5GhzBandSupported()) {
        preference.setEnabled(false);
        preference.setSummary(R.string.wifi_ap_choose_2G);
    } else {
        preference.setEntries(mBandEntries);
        preference.setEntryValues(BAND_VALUES);
        preference.setSummary(mBandEntries[mBandIndex]);
        preference.setValue(String.valueOf(mBandIndex));
    }
}
Also used : ListPreference(android.support.v7.preference.ListPreference)

Example 59 with ListPreference

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

the class ThemePreferenceControllerTest method testUpdateState.

@Test
public void testUpdateState() throws Exception {
    OverlayInfo info1 = new OverlayInfo("com.android.Theme1", "android", "", OverlayInfo.STATE_ENABLED, 0);
    OverlayInfo info2 = new OverlayInfo("com.android.Theme2", "android", "", 0, 0);
    when(mMockPackageManager.getApplicationInfo(any(), anyInt())).thenAnswer(inv -> {
        ApplicationInfo info = mock(ApplicationInfo.class);
        if ("com.android.Theme1".equals(inv.getArguments()[0])) {
            when(info.loadLabel(any())).thenReturn("Theme1");
        } else {
            when(info.loadLabel(any())).thenReturn("Theme2");
        }
        return info;
    });
    when(mMockPackageManager.getPackageInfo(anyString(), anyInt())).thenReturn(new PackageInfo());
    when(mMockOverlayManager.getOverlayInfosForTarget(any(), anyInt())).thenReturn(list(info1, info2));
    ListPreference pref = mock(ListPreference.class);
    mPreferenceController.updateState(pref);
    ArgumentCaptor<String[]> arg = ArgumentCaptor.forClass(String[].class);
    verify(pref).setEntries(arg.capture());
    CharSequence[] entries = arg.getValue();
    assertThat(entries).asList().containsExactly("Theme1", "Theme2");
    verify(pref).setEntryValues(arg.capture());
    CharSequence[] entryValues = arg.getValue();
    assertThat(entryValues).asList().containsExactly("com.android.Theme1", "com.android.Theme2");
    verify(pref).setValue(eq("com.android.Theme1"));
}
Also used : PackageInfo(android.content.pm.PackageInfo) OverlayInfo(android.content.om.OverlayInfo) ApplicationInfo(android.content.pm.ApplicationInfo) ListPreference(android.support.v7.preference.ListPreference) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest)

Example 60 with ListPreference

use of android.support.v7.preference.ListPreference in project MPW by shineangelic.

the class SettingsFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.preferences);
    // Crashlytics.getInstance().crash();
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(getActivity());
    PoolEnum mPool = PoolEnum.valueOf(prefs.getString("poolEnum", ""));
    CurrencyEnum mCur = CurrencyEnum.valueOf(prefs.getString("curEnum", ""));
    final android.support.v7.preference.SwitchPreferenceCompat globalNotifications = (SwitchPreferenceCompat) findPreference("pref_notify");
    final android.support.v7.preference.EditTextPreference walletAddr = (EditTextPreference) findPreference("wallet_addr");
    final android.support.v7.preference.SwitchPreferenceCompat service = (SwitchPreferenceCompat) findPreference("pref_sync");
    final android.support.v7.preference.ListPreference listFreqPreference = (ListPreference) findPreference("pref_sync_freq");
    final android.support.v7.preference.SwitchPreferenceCompat offlineNotifications = (SwitchPreferenceCompat) findPreference("pref_notify_offline");
    final android.support.v7.preference.SwitchPreferenceCompat blockNotifications = (SwitchPreferenceCompat) findPreference("pref_notify_block");
    final android.support.v7.preference.SwitchPreferenceCompat paymentNotifications = (SwitchPreferenceCompat) findPreference("pref_notify_payment");
    // Service Enabled listener
    Preference.OnPreferenceChangeListener listenerServ = new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // newValue is the value you choose
            listFreqPreference.setEnabled((Boolean) newValue);
            Boolean nv = (Boolean) newValue;
            FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(getActivity()));
            dispatcher.cancelAll();
            if (nv) {
                Job myJob = MPWService.getJobUpdate(prefs, dispatcher, true);
                int res = dispatcher.schedule(myJob);
                if (res != dispatcher.SCHEDULE_RESULT_SUCCESS) {
                    Toast.makeText(getActivity(), "Cannot enable service. Is Play Services up to date? Notifications won't work", Toast.LENGTH_SHORT).show();
                    return false;
                }
                Log.w(Constants.TAG, "SERVICE ACTIVE, schedule res: " + res);
            }
            // firebase log event
            Bundle bundle = new Bundle();
            bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, nv.toString());
            mFirebaseAnalytics.logEvent("service_active", bundle);
            return true;
        }
    };
    service.setOnPreferenceChangeListener(listenerServ);
    // Service FREQ listener
    Preference.OnPreferenceChangeListener listenerServF = new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Integer nv = Integer.valueOf((String) newValue);
            // newValue is the value you choose
            Log.w(Constants.TAG, "Changed FREQ setting to: " + nv);
            // pezza perche il val ancora non c'e
            prefs.edit().putString("pref_sync_freq", "" + nv).apply();
            FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(getActivity()));
            Job myJob = MPWService.getJobUpdate(prefs, dispatcher, true);
            dispatcher.schedule(myJob);
            Bundle bundle = new Bundle();
            bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "" + nv);
            mFirebaseAnalytics.logEvent("service_freq", bundle);
            return true;
        }
    };
    listFreqPreference.setOnPreferenceChangeListener(listenerServF);
    // Notification global
    Preference.OnPreferenceChangeListener listener = new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Log.w(Constants.TAG, "Changed NOTIF setting to: " + newValue);
            Boolean nv = (Boolean) newValue;
            // newValue is the value you choose
            blockNotifications.setEnabled(nv);
            offlineNotifications.setEnabled(nv);
            paymentNotifications.setEnabled(nv);
            Bundle bundle = new Bundle();
            bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "" + nv);
            mFirebaseAnalytics.logEvent("service_notifications", bundle);
            return true;
        }
    };
    globalNotifications.setOnPreferenceChangeListener(listener);
    // Listener x controllo correttezza
    walletAddr.setOnPreferenceChangeListener(new WalletPrefChangeListener(getActivity(), mPool, mCur));
    walletAddr.setSummary(getString(R.string.wallet_info, mPool.toString(), mCur.toString()));
    walletAddr.setDialogTitle(mPool.toString() + " Network Login");
}
Also used : FirebaseJobDispatcher(com.firebase.jobdispatcher.FirebaseJobDispatcher) SharedPreferences(android.content.SharedPreferences) SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) Bundle(android.os.Bundle) GooglePlayDriver(com.firebase.jobdispatcher.GooglePlayDriver) ListPreference(android.support.v7.preference.ListPreference) EditTextPreference(android.support.v7.preference.EditTextPreference) ListPreference(android.support.v7.preference.ListPreference) PoolEnum(it.angelic.mpw.model.enums.PoolEnum) EditTextPreference(android.support.v7.preference.EditTextPreference) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) EditTextPreference(android.support.v7.preference.EditTextPreference) Job(com.firebase.jobdispatcher.Job) CurrencyEnum(it.angelic.mpw.model.enums.CurrencyEnum)

Aggregations

ListPreference (android.support.v7.preference.ListPreference)115 Preference (android.support.v7.preference.Preference)51 PreferenceScreen (android.support.v7.preference.PreferenceScreen)34 SwitchPreference (android.support.v14.preference.SwitchPreference)31 ContentResolver (android.content.ContentResolver)24 PreferenceCategory (android.support.v7.preference.PreferenceCategory)20 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)17 Intent (android.content.Intent)12 Resources (android.content.res.Resources)12 MultiSelectListPreference (android.support.v14.preference.MultiSelectListPreference)12 PackageInfo (android.content.pm.PackageInfo)11 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)11 RestrictionEntry (android.content.RestrictionEntry)10 OverlayInfo (android.content.om.OverlayInfo)10 ApplicationInfo (android.content.pm.ApplicationInfo)10 SmallTest (android.support.test.filters.SmallTest)10 HashSet (java.util.HashSet)10 Test (org.junit.Test)10 Matchers.anyString (org.mockito.Matchers.anyString)10 IBinder (android.os.IBinder)7