Search in sources :

Example 6 with PreferenceGroup

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

the class SettingsPreferenceFragment method removePreference.

@VisibleForTesting
boolean removePreference(PreferenceGroup group, String key) {
    final int preferenceCount = group.getPreferenceCount();
    for (int i = 0; i < preferenceCount; i++) {
        final Preference preference = group.getPreference(i);
        final String curKey = preference.getKey();
        if (TextUtils.equals(curKey, key)) {
            return group.removePreference(preference);
        }
        if (preference instanceof PreferenceGroup) {
            if (removePreference((PreferenceGroup) preference, key)) {
                return true;
            }
        }
    }
    return false;
}
Also used : LayoutPreference(com.android.settingslib.widget.LayoutPreference) Preference(androidx.preference.Preference) PreferenceGroup(androidx.preference.PreferenceGroup) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 7 with PreferenceGroup

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

the class PrivateVolumeSettings method update.

private void update() {
    if (!isVolumeValid()) {
        getActivity().finish();
        return;
    }
    setTitle();
    // Valid options may have changed
    getActivity().invalidateOptionsMenu();
    final Context context = getActivity();
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    addPreference(screen, mSummary);
    List<UserInfo> allUsers = mUserManager.getUsers();
    final int userCount = allUsers.size();
    final boolean showHeaders = userCount > 1;
    final boolean showShared = (mSharedVolume != null) && mSharedVolume.isMountedReadable();
    mItemPoolIndex = 0;
    mHeaderPoolIndex = 0;
    int addedUserCount = 0;
    // Add current user and its profiles first
    for (int userIndex = 0; userIndex < userCount; ++userIndex) {
        final UserInfo userInfo = allUsers.get(userIndex);
        if (Utils.isProfileOf(mCurrentUser, userInfo)) {
            final PreferenceGroup details = showHeaders ? addCategory(screen, userInfo.name) : screen;
            addDetailItems(details, showShared, userInfo.id);
            ++addedUserCount;
        }
    }
    // Add rest of users
    if (userCount - addedUserCount > 0) {
        PreferenceGroup otherUsers = addCategory(screen, getText(R.string.storage_other_users));
        for (int userIndex = 0; userIndex < userCount; ++userIndex) {
            final UserInfo userInfo = allUsers.get(userIndex);
            if (!Utils.isProfileOf(mCurrentUser, userInfo)) {
                addItem(otherUsers, /* titleRes */
                0, userInfo.name, userInfo.id);
            }
        }
    }
    addItem(screen, R.string.storage_detail_cached, null, UserHandle.USER_NULL);
    if (showShared) {
        addPreference(screen, mExplore);
    }
    final long freeBytes = mVolume.getPath().getFreeSpace();
    final long usedBytes = mTotalSize - freeBytes;
    if (LOGV)
        Log.v(TAG, "update() freeBytes: " + freeBytes + " usedBytes: " + usedBytes);
    final BytesResult result = Formatter.formatBytes(getResources(), usedBytes, 0);
    mSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large), result.value, result.units));
    mSummary.setSummary(getString(R.string.storage_volume_used, Formatter.formatFileSize(context, mTotalSize)));
    mSummary.setPercent(usedBytes, mTotalSize);
    mMeasure.forceMeasure();
    mNeedsUpdate = false;
}
Also used : Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) UserInfo(android.content.pm.UserInfo) PreferenceGroup(androidx.preference.PreferenceGroup) BytesResult(android.text.format.Formatter.BytesResult)

Example 8 with PreferenceGroup

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

the class InactiveApps method init.

private void init() {
    PreferenceGroup screen = getPreferenceScreen();
    screen.removeAll();
    screen.setOrderingAsAdded(false);
    final Context context = getActivity();
    final PackageManager pm = context.getPackageManager();
    final UsageStatsManager usm = context.getSystemService(UsageStatsManager.class);
    Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
    launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> apps = pm.queryIntentActivities(launcherIntent, 0);
    for (ResolveInfo app : apps) {
        String packageName = app.activityInfo.applicationInfo.packageName;
        ListPreference p = new ListPreference(getPrefContext());
        p.setTitle(app.loadLabel(pm));
        p.setIcon(app.loadIcon(pm));
        p.setKey(packageName);
        p.setEntries(SETTABLE_BUCKETS_NAMES);
        p.setEntryValues(SETTABLE_BUCKETS_VALUES);
        updateSummary(p);
        p.setOnPreferenceChangeListener(this);
        screen.addPreference(p);
    }
}
Also used : Context(android.content.Context) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) UsageStatsManager(android.app.usage.UsageStatsManager) PreferenceGroup(androidx.preference.PreferenceGroup) Intent(android.content.Intent) ListPreference(androidx.preference.ListPreference)

Example 9 with PreferenceGroup

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

the class AppNotificationSettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final PreferenceScreen screen = getPreferenceScreen();
    if (mShowLegacyChannelConfig && screen != null) {
        // if showing legacy settings, pull advanced settings out of the advanced category
        PreferenceGroup advanced = (PreferenceGroup) findPreference(KEY_ADVANCED_CATEGORY);
        removePreference(KEY_ADVANCED_CATEGORY);
        if (advanced != null) {
            for (String key : LEGACY_NON_ADVANCED_KEYS) {
                Preference pref = advanced.findPreference(key);
                advanced.removePreference(pref);
                if (pref != null) {
                    screen.addPreference(pref);
                }
            }
        }
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Preference(androidx.preference.Preference) PreferenceGroup(androidx.preference.PreferenceGroup)

Example 10 with PreferenceGroup

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

the class NotificationLightSettings method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final Context context = getContext();
    addPreferencesFromResource(R.xml.notification_light_settings);
    getActivity().getActionBar().setTitle(R.string.notification_light_title);
    PreferenceScreen prefSet = getPreferenceScreen();
    Resources resources = getResources();
    PreferenceGroup mAdvancedPrefs = (PreferenceGroup) prefSet.findPreference(ADVANCED_SECTION);
    PreferenceGroup mGeneralPrefs = (PreferenceGroup) prefSet.findPreference(GENERAL_SECTION);
    // Get the system defined default notification color
    mDefaultColor = resources.getColor(com.android.internal.R.color.config_defaultNotificationColor, null);
    mDefaultLedOn = resources.getInteger(com.android.internal.R.integer.config_defaultNotificationLedOn);
    mDefaultLedOff = resources.getInteger(com.android.internal.R.integer.config_defaultNotificationLedOff);
    mHALAdjustableBrightness = LightsCapabilities.supports(context, LightsCapabilities.LIGHTS_ADJUSTABLE_NOTIFICATION_LED_BRIGHTNESS);
    mLedCanPulse = LightsCapabilities.supports(context, LightsCapabilities.LIGHTS_PULSATING_LED);
    mMultiColorLed = LightsCapabilities.supports(context, LightsCapabilities.LIGHTS_RGB_NOTIFICATION_LED);
    mEnabledPref = (SystemSettingSwitchPreference) findPreference(Settings.System.NOTIFICATION_LIGHT_PULSE);
    mEnabledPref.setOnPreferenceChangeListener(this);
    mDefaultPref = (ApplicationLightPreference) findPreference(DEFAULT_PREF);
    mAutoGenerateColors = (LineageSystemSettingSwitchPreference) findPreference(LineageSettings.System.NOTIFICATION_LIGHT_COLOR_AUTO);
    // Advanced light settings
    mNotificationBrightnessPref = (NotificationBrightnessPreference) findPreference(LineageSettings.System.NOTIFICATION_LIGHT_BRIGHTNESS_LEVEL);
    mScreenOnLightsPref = (LineageSystemSettingSwitchPreference) findPreference(LineageSettings.System.NOTIFICATION_LIGHT_SCREEN_ON);
    mScreenOnLightsPref.setOnPreferenceChangeListener(this);
    mCustomEnabledPref = (LineageSystemSettingSwitchPreference) findPreference(LineageSettings.System.NOTIFICATION_LIGHT_PULSE_CUSTOM_ENABLE);
    if (!mMultiColorLed && !mHALAdjustableBrightness) {
        removePreference(BRIGHTNESS_SECTION);
    }
    if (!mLedCanPulse && !mMultiColorLed) {
        mGeneralPrefs.removePreference(mDefaultPref);
        mAdvancedPrefs.removePreference(mCustomEnabledPref);
    } else {
        mCustomEnabledPref.setOnPreferenceChangeListener(this);
        mDefaultPref.setOnPreferenceChangeListener(this);
        mDefaultPref.setDefaultValues(mDefaultColor, mDefaultLedOn, mDefaultLedOff);
    }
    // Missed call and Voicemail preferences should only show on devices with a voice capabilities
    TelephonyManager tm = getActivity().getSystemService(TelephonyManager.class);
    if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE || (!mLedCanPulse && !mMultiColorLed)) {
        removePreference(PHONE_SECTION);
    } else {
        mCallPref = (ApplicationLightPreference) findPreference(MISSED_CALL_PREF);
        mCallPref.setOnPreferenceChangeListener(this);
        mCallPref.setDefaultValues(mDefaultColor, mDefaultLedOn, mDefaultLedOff);
        mVoicemailPref = (ApplicationLightPreference) findPreference(VOICEMAIL_PREF);
        mVoicemailPref.setOnPreferenceChangeListener(this);
        mVoicemailPref.setDefaultValues(mDefaultColor, mDefaultLedOn, mDefaultLedOff);
    }
    if (!mLedCanPulse && !mMultiColorLed) {
        removePreference(APPLICATION_SECTION);
    } else {
        mApplicationPrefList = (PreferenceGroup) findPreference(APPLICATION_SECTION);
        mApplicationPrefList.setOrderingAsAdded(false);
    }
    // Get launch-able applications
    mPackageManager = getActivity().getPackageManager();
    mPackageAdapter = new PackageListAdapter(getActivity());
    mPackages = new HashMap<String, Package>();
    setHasOptionsMenu(true);
    if (!mMultiColorLed) {
        resetColors();
        mGeneralPrefs.removePreference(mAutoGenerateColors);
    } else {
        mAutoGenerateColors.setOnPreferenceChangeListener(this);
    // watch(LineageSettings.System.getUriFor(LineageSettings.System.NOTIFICATION_LIGHT_COLOR_AUTO));
    }
// watch(Settings.System.getUriFor(Settings.System.NOTIFICATION_LIGHT_PULSE));
}
Also used : Context(android.content.Context) PackageListAdapter(com.crdroid.settings.preferences.PackageListAdapter) PreferenceScreen(androidx.preference.PreferenceScreen) TelephonyManager(android.telephony.TelephonyManager) PreferenceGroup(androidx.preference.PreferenceGroup) Resources(android.content.res.Resources)

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