Search in sources :

Example 11 with PreferenceGroup

use of androidx.preference.PreferenceGroup in project android_packages_apps_crDroidSettings by crdroidandroid.

the class BatteryLightSettings method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final Context context = getContext();
    final Resources res = getResources();
    ContentResolver resolver = context.getContentResolver();
    // Collect battery led capabilities.
    mMultiColorLed = LightsCapabilities.supports(context, LightsCapabilities.LIGHTS_RGB_BATTERY_LED);
    mHALAdjustableBrightness = LightsCapabilities.supports(context, LightsCapabilities.LIGHTS_ADJUSTABLE_BATTERY_LED_BRIGHTNESS);
    final boolean pulsatingLed = LightsCapabilities.supports(context, LightsCapabilities.LIGHTS_PULSATING_LED);
    final boolean segmentedBatteryLed = LightsCapabilities.supports(context, LightsCapabilities.LIGHTS_SEGMENTED_BATTERY_LED);
    addPreferencesFromResource(R.xml.battery_light_settings);
    getActivity().getActionBar().setTitle(R.string.battery_light_title);
    PreferenceScreen prefSet = getPreferenceScreen();
    PreferenceGroup generalPrefs = (PreferenceGroup) prefSet.findPreference(GENERAL_SECTION);
    mLightEnabledPref = (LineageSystemSettingSwitchPreference) prefSet.findPreference(LIGHT_ENABLED_PREF);
    mLightFullChargeDisabledPref = (LineageSystemSettingSwitchPreference) prefSet.findPreference(LIGHT_FULL_CHARGE_DISABLED_PREF);
    mPulseEnabledPref = (LineageSystemSettingSwitchPreference) prefSet.findPreference(PULSE_ENABLED_PREF);
    mBatteryBrightnessPref = (BatteryBrightnessPreference) prefSet.findPreference(BRIGHTNESS_PREFERENCE);
    mBatteryBrightnessZenPref = (BatteryBrightnessZenPreference) prefSet.findPreference(BRIGHTNESS_ZEN_PREFERENCE);
    boolean isLightEnabled = LineageSettings.System.getIntForUser(resolver, LineageSettings.System.BATTERY_LIGHT_ENABLED, isBatteryLightEnabled(context) ? 1 : 0, UserHandle.USER_CURRENT) != 0;
    mLightEnabledPref.setChecked(isLightEnabled);
    boolean isLightFullChargeDisabled = LineageSettings.System.getIntForUser(resolver, LineageSettings.System.BATTERY_LIGHT_FULL_CHARGE_DISABLED, isBatteryLightFullChargeDisabled(context) ? 1 : 0, UserHandle.USER_CURRENT) != 0;
    mLightFullChargeDisabledPref.setChecked(isLightFullChargeDisabled);
    mDefaultLowColor = res.getInteger(com.android.internal.R.integer.config_notificationsBatteryLowARGB);
    mDefaultMediumColor = res.getInteger(com.android.internal.R.integer.config_notificationsBatteryMediumARGB);
    mDefaultFullColor = res.getInteger(com.android.internal.R.integer.config_notificationsBatteryFullARGB);
    mDefaultReallyFullColor = res.getInteger(com.android.internal.R.integer.config_notificationsBatteryReallyFullARGB);
    mBatteryBrightness = mBatteryBrightnessPref.getBrightnessSetting();
    if (!pulsatingLed || segmentedBatteryLed) {
        generalPrefs.removePreference(mPulseEnabledPref);
    } else {
        boolean isPulseEnabled = LineageSettings.System.getIntForUser(resolver, LineageSettings.System.BATTERY_LIGHT_PULSE, isBatteryLightPulseEnabled(context) ? 1 : 0, UserHandle.USER_CURRENT) != 0;
        mPulseEnabledPref.setChecked(isPulseEnabled);
    }
    if (mMultiColorLed) {
        generalPrefs.removePreference(mLightFullChargeDisabledPref);
        setHasOptionsMenu(true);
        // Low, Medium and full color preferences
        mLowColorPref = (ApplicationLightPreference) prefSet.findPreference(LOW_COLOR_PREF);
        mLowColorPref.setOnPreferenceChangeListener(this);
        mLowColorPref.setDefaultValues(mDefaultLowColor, 0, 0);
        mLowColorPref.setBrightness(mBatteryBrightness);
        mMediumColorPref = (ApplicationLightPreference) prefSet.findPreference(MEDIUM_COLOR_PREF);
        mMediumColorPref.setOnPreferenceChangeListener(this);
        mMediumColorPref.setDefaultValues(mDefaultMediumColor, 0, 0);
        mMediumColorPref.setBrightness(mBatteryBrightness);
        mFullColorPref = (ApplicationLightPreference) prefSet.findPreference(FULL_COLOR_PREF);
        mFullColorPref.setOnPreferenceChangeListener(this);
        mFullColorPref.setDefaultValues(mDefaultFullColor, 0, 0);
        mFullColorPref.setBrightness(mBatteryBrightness);
        mReallyFullColorPref = (ApplicationLightPreference) prefSet.findPreference(REALLY_FULL_COLOR_PREF);
        mReallyFullColorPref.setOnPreferenceChangeListener(this);
        mReallyFullColorPref.setDefaultValues(mDefaultReallyFullColor, 0, 0);
        mReallyFullColorPref.setBrightness(mBatteryBrightness);
        final BrightnessPreference.OnBrightnessChangedListener brightnessListener = new BrightnessPreference.OnBrightnessChangedListener() {

            @Override
            public void onBrightnessChanged(int brightness) {
                mLowColorPref.setBrightness(brightness);
                mMediumColorPref.setBrightness(brightness);
                mFullColorPref.setBrightness(brightness);
                mReallyFullColorPref.setBrightness(brightness);
            }
        };
        mBatteryBrightnessPref.setOnBrightnessChangedListener(brightnessListener);
    } else {
        prefSet.removePreference(prefSet.findPreference(COLORS_SECTION));
        resetColors();
    }
    // Remove battery LED brightness controls if we can't support them.
    if (segmentedBatteryLed || (!mMultiColorLed && !mHALAdjustableBrightness)) {
        prefSet.removePreference(prefSet.findPreference(BRIGHTNESS_SECTION));
    }
// watch(LineageSettings.System.getUriFor(LineageSettings.System.BATTERY_LIGHT_ENABLED));
}
Also used : Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) PreferenceGroup(androidx.preference.PreferenceGroup) Resources(android.content.res.Resources) ContentResolver(android.content.ContentResolver)

Example 12 with PreferenceGroup

use of androidx.preference.PreferenceGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class VpnSettings method setShownPreferences.

@VisibleForTesting
@UiThread
public void setShownPreferences(final Collection<Preference> updates) {
    mLegacyVpnPreferences.values().retainAll(updates);
    mAppPreferences.values().retainAll(updates);
    // Change {@param updates} in-place to only contain new preferences that were not already
    // added to the preference screen.
    final PreferenceGroup vpnGroup = getPreferenceScreen();
    for (int i = vpnGroup.getPreferenceCount() - 1; i >= 0; i--) {
        Preference p = vpnGroup.getPreference(i);
        if (updates.contains(p)) {
            updates.remove(p);
        } else {
            vpnGroup.removePreference(p);
        }
    }
    // Show any new preferences on the screen
    for (Preference pref : updates) {
        vpnGroup.addPreference(pref);
    }
}
Also used : GearPreference(com.android.settings.widget.GearPreference) Preference(androidx.preference.Preference) PreferenceGroup(androidx.preference.PreferenceGroup) VisibleForTesting(androidx.annotation.VisibleForTesting) UiThread(android.annotation.UiThread)

Example 13 with PreferenceGroup

use of androidx.preference.PreferenceGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ChannelListPreferenceController method onGroupBlockStateChanged.

protected void onGroupBlockStateChanged(NotificationChannelGroup group) {
    if (group == null) {
        return;
    }
    PreferenceGroup groupGroup = mPreference.findPreference(group.getId());
    if (groupGroup != null) {
        if (group.isBlocked()) {
            List<Preference> toRemove = new ArrayList<>();
            int childCount = groupGroup.getPreferenceCount();
            for (int i = 0; i < childCount; i++) {
                Preference pref = groupGroup.getPreference(i);
                if (pref instanceof MasterSwitchPreference) {
                    toRemove.add(pref);
                }
            }
            for (Preference pref : toRemove) {
                groupGroup.removePreference(pref);
            }
        } else {
            final List<NotificationChannel> channels = group.getChannels();
            Collections.sort(channels, mChannelComparator);
            int N = channels.size();
            for (int i = 0; i < N; i++) {
                final NotificationChannel channel = channels.get(i);
                populateSingleChannelPrefs(groupGroup, channel, group.isBlocked());
            }
        }
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) ArrayList(java.util.ArrayList) PreferenceGroup(androidx.preference.PreferenceGroup)

Example 14 with PreferenceGroup

use of androidx.preference.PreferenceGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AccountTypePreferenceLoaderTest method updatePreferenceIntents_shouldRunRecursively.

@Test
@Config(shadows = { ShadowAccountManager.class, ShadowContentResolver.class })
public void updatePreferenceIntents_shouldRunRecursively() {
    final PreferenceManager preferenceManager = mock(PreferenceManager.class);
    // Top level
    PreferenceGroup prefRoot = spy(new PreferenceScreen(mContext, null));
    when(prefRoot.getPreferenceManager()).thenReturn(preferenceManager);
    Preference pref1 = mock(Preference.class);
    PreferenceGroup prefGroup2 = spy(new PreferenceScreen(mContext, null));
    when(prefGroup2.getPreferenceManager()).thenReturn(preferenceManager);
    Preference pref3 = mock(Preference.class);
    PreferenceGroup prefGroup4 = spy(new PreferenceScreen(mContext, null));
    when(prefGroup4.getPreferenceManager()).thenReturn(preferenceManager);
    prefRoot.addPreference(pref1);
    prefRoot.addPreference(prefGroup2);
    prefRoot.addPreference(pref3);
    prefRoot.addPreference(prefGroup4);
    // 2nd level
    Preference pref21 = mock(Preference.class);
    Preference pref22 = mock(Preference.class);
    prefGroup2.addPreference(pref21);
    prefGroup2.addPreference(pref22);
    PreferenceGroup prefGroup41 = spy(new PreferenceScreen(mContext, null));
    when(prefGroup41.getPreferenceManager()).thenReturn(preferenceManager);
    Preference pref42 = mock(Preference.class);
    prefGroup4.addPreference(prefGroup41);
    prefGroup4.addPreference(pref42);
    // 3rd level
    Preference pref411 = mock(Preference.class);
    Preference pref412 = mock(Preference.class);
    prefGroup41.addPreference(pref411);
    prefGroup41.addPreference(pref412);
    final String acctType = "testType";
    mPrefLoader.updatePreferenceIntents(prefRoot, acctType, mAccount);
    verify(mPrefLoader).updatePreferenceIntents(prefGroup2, acctType, mAccount);
    verify(mPrefLoader).updatePreferenceIntents(prefGroup4, acctType, mAccount);
    verify(mPrefLoader).updatePreferenceIntents(prefGroup41, acctType, mAccount);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Preference(androidx.preference.Preference) PreferenceGroup(androidx.preference.PreferenceGroup) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 15 with PreferenceGroup

use of androidx.preference.PreferenceGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ModuleLicensesPreferenceControllerTest method displayPreference_alphabeticalOrder.

@Test
public void displayPreference_alphabeticalOrder() throws PackageManager.NameNotFoundException, IOException {
    Context context = mock(Context.class);
    ModuleLicensesPreferenceController controller = new ModuleLicensesPreferenceController(context, PREFERENCE_KEY);
    PackageManager packageManager = mock(PackageManager.class);
    when(context.getPackageManager()).thenReturn(packageManager);
    PreferenceScreen screen = mock(PreferenceScreen.class);
    PreferenceGroup group = spy(new MockPreferenceGroup(RuntimeEnvironment.application, null));
    when(screen.findPreference(PREFERENCE_KEY)).thenReturn(group);
    when(group.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
    when(packageManager.getInstalledModules(0)).thenReturn(Arrays.asList(mModuleTwo, mModuleOne));
    PackageInfo packageInfo = new PackageInfo();
    ApplicationInfo applicationInfo = new ApplicationInfo();
    packageInfo.applicationInfo = applicationInfo;
    when(packageManager.getPackageInfo(MODULE_1_PACKAGE_NAME, PackageManager.MATCH_APEX)).thenReturn(packageInfo);
    when(packageManager.getPackageInfo(MODULE_2_PACKAGE_NAME, PackageManager.MATCH_APEX)).thenReturn(packageInfo);
    Resources resources = mock(Resources.class);
    when(packageManager.getResourcesForApplication(applicationInfo)).thenReturn(resources);
    AssetManager manager = mock(AssetManager.class);
    when(resources.getAssets()).thenReturn(manager);
    when(manager.list("")).thenReturn(new String[] { GZIPPED_LICENSE_FILE_NAME });
    controller.displayPreference(screen);
    assertThat(group.getPreferenceCount()).isEqualTo(2);
    assertThat(group.getPreference(0).getTitle()).isEqualTo(MODULE_1_NAME);
    assertThat(group.getPreference(1).getTitle()).isEqualTo(MODULE_2_NAME);
}
Also used : Context(android.content.Context) AssetManager(android.content.res.AssetManager) PackageManager(android.content.pm.PackageManager) PreferenceScreen(androidx.preference.PreferenceScreen) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) PreferenceGroup(androidx.preference.PreferenceGroup) Resources(android.content.res.Resources) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test)

Aggregations

PreferenceGroup (androidx.preference.PreferenceGroup)19 PreferenceScreen (androidx.preference.PreferenceScreen)11 Preference (androidx.preference.Preference)10 Context (android.content.Context)8 PackageManager (android.content.pm.PackageManager)5 Test (org.junit.Test)5 Resources (android.content.res.Resources)4 Intent (android.content.Intent)3 ResolveInfo (android.content.pm.ResolveInfo)3 PreferenceCategory (androidx.preference.PreferenceCategory)3 PreferenceManager (androidx.preference.PreferenceManager)3 ArrayList (java.util.ArrayList)3 ContentResolver (android.content.ContentResolver)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 PackageInfo (android.content.pm.PackageInfo)2 AssetManager (android.content.res.AssetManager)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2 ListPreference (androidx.preference.ListPreference)2 SwitchPreference (androidx.preference.SwitchPreference)2 RestrictedPreference (com.android.settingslib.RestrictedPreference)2