Search in sources :

Example 81 with PreferenceScreen

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

the class DashboardFragment method updatePreferenceStates.

/**
 * Update state of each preference managed by PreferenceController.
 */
protected void updatePreferenceStates() {
    final PreferenceScreen screen = getPreferenceScreen();
    Collection<List<AbstractPreferenceController>> controllerLists = mPreferenceControllers.values();
    for (List<AbstractPreferenceController> controllerList : controllerLists) {
        for (AbstractPreferenceController controller : controllerList) {
            if (!controller.isAvailable()) {
                continue;
            }
            final String key = controller.getPreferenceKey();
            if (TextUtils.isEmpty(key)) {
                Log.d(TAG, String.format("Preference key is %s in Controller %s", key, controller.getClass().getSimpleName()));
                continue;
            }
            final Preference preference = screen.findPreference(key);
            if (preference == null) {
                Log.d(TAG, String.format("Cannot find preference with key %s in Controller %s", key, controller.getClass().getSimpleName()));
                continue;
            }
            controller.updateState(preference);
        }
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) Preference(androidx.preference.Preference) ArrayList(java.util.ArrayList) List(java.util.List)

Example 82 with PreferenceScreen

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

the class DashboardFragment method displayResourceTiles.

/**
 * Displays resource based tiles.
 */
private void displayResourceTiles() {
    final int resId = getPreferenceScreenResId();
    if (resId <= 0) {
        return;
    }
    addPreferencesFromResource(resId);
    final PreferenceScreen screen = getPreferenceScreen();
    screen.setOnExpandButtonClickListener(this);
    displayResourceTilesToScreen(screen);
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen)

Example 83 with PreferenceScreen

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

the class DashboardFragment method updatePreferenceVisibility.

@VisibleForTesting
void updatePreferenceVisibility(Map<Class, List<AbstractPreferenceController>> preferenceControllers) {
    final PreferenceScreen screen = getPreferenceScreen();
    if (screen == null || preferenceControllers == null || mBlockerController == null) {
        return;
    }
    final boolean visible = mBlockerController.isBlockerFinished();
    for (List<AbstractPreferenceController> controllerList : preferenceControllers.values()) {
        for (AbstractPreferenceController controller : controllerList) {
            final String key = controller.getPreferenceKey();
            final Preference preference = findPreference(key);
            if (preference != null) {
                preference.setVisible(visible && controller.isAvailable());
            }
        }
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) Preference(androidx.preference.Preference) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 84 with PreferenceScreen

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

the class DashboardFragment method refreshDashboardTiles.

/**
 * Refresh preference items backed by DashboardCategory.
 */
@VisibleForTesting
void refreshDashboardTiles(final String TAG) {
    final PreferenceScreen screen = getPreferenceScreen();
    final DashboardCategory category = mDashboardFeatureProvider.getTilesForCategory(getCategoryKey());
    if (category == null) {
        Log.d(TAG, "NO dashboard tiles for " + TAG);
        return;
    }
    final List<Tile> tiles = category.getTiles();
    if (tiles == null) {
        Log.d(TAG, "tile list is empty, skipping category " + category.key);
        return;
    }
    // Create a list to track which tiles are to be removed.
    final List<String> remove = new ArrayList<>(mDashboardTilePrefKeys);
    // There are dashboard tiles, so we need to install SummaryLoader.
    if (mSummaryLoader != null) {
        mSummaryLoader.release();
    }
    final Context context = getContext();
    mSummaryLoader = new SummaryLoader(getActivity(), getCategoryKey());
    mSummaryLoader.setSummaryConsumer(this);
    // Install dashboard tiles.
    final boolean forceRoundedIcons = shouldForceRoundedIcon();
    for (Tile tile : tiles) {
        final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile);
        if (TextUtils.isEmpty(key)) {
            Log.d(TAG, "tile does not contain a key, skipping " + tile);
            continue;
        }
        if (!displayTile(tile)) {
            continue;
        }
        if (mDashboardTilePrefKeys.contains(key)) {
            // Have the key already, will rebind.
            final Preference preference = screen.findPreference(key);
            mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), forceRoundedIcons, getMetricsCategory(), preference, tile, key, mPlaceholderPreferenceController.getOrder());
        } else {
            // Don't have this key, add it.
            final Preference pref = new Preference(getPrefContext());
            mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), forceRoundedIcons, getMetricsCategory(), pref, tile, key, mPlaceholderPreferenceController.getOrder());
            screen.addPreference(pref);
            mDashboardTilePrefKeys.add(key);
        }
        remove.remove(key);
    }
    // Finally remove tiles that are gone.
    for (String key : remove) {
        mDashboardTilePrefKeys.remove(key);
        final Preference preference = screen.findPreference(key);
        if (preference != null) {
            screen.removePreference(preference);
        }
    }
    mSummaryLoader.setListening(true);
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) Preference(androidx.preference.Preference) ArrayList(java.util.ArrayList) Tile(com.android.settingslib.drawer.Tile) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 85 with PreferenceScreen

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

the class ApplicationListPreferenceController method onListOfAppsResult.

@Override
public void onListOfAppsResult(List<UserAppInfo> result) {
    final PreferenceScreen screen = mParent.getPreferenceScreen();
    if (screen == null) {
        return;
    }
    final IconDrawableFactory iconDrawableFactory = IconDrawableFactory.newInstance(mContext);
    final Context prefContext = mParent.getPreferenceManager().getContext();
    for (int position = 0; position < result.size(); position++) {
        final UserAppInfo item = result.get(position);
        final Preference preference = new AppPreference(prefContext);
        preference.setTitle(item.appInfo.loadLabel(mPm));
        preference.setIcon(iconDrawableFactory.getBadgedIcon(item.appInfo));
        preference.setOrder(position);
        preference.setSelectable(false);
        screen.addPreference(preference);
    }
}
Also used : Context(android.content.Context) PreferenceScreen(androidx.preference.PreferenceScreen) AppPreference(com.android.settingslib.widget.apppreference.AppPreference) Preference(androidx.preference.Preference) AppPreference(com.android.settingslib.widget.apppreference.AppPreference) UserAppInfo(com.android.settings.applications.UserAppInfo) IconDrawableFactory(android.util.IconDrawableFactory)

Aggregations

PreferenceScreen (androidx.preference.PreferenceScreen)244 Preference (androidx.preference.Preference)81 Test (org.junit.Test)60 Context (android.content.Context)36 PreferenceManager (androidx.preference.PreferenceManager)36 ContentResolver (android.content.ContentResolver)25 PreferenceCategory (androidx.preference.PreferenceCategory)24 Bundle (android.os.Bundle)20 ArrayList (java.util.ArrayList)20 SwitchPreference (androidx.preference.SwitchPreference)19 Resources (android.content.res.Resources)18 Before (org.junit.Before)17 ListPreference (androidx.preference.ListPreference)14 PackageManager (android.content.pm.PackageManager)13 PreferenceGroup (androidx.preference.PreferenceGroup)13 ApplicationInfo (android.content.pm.ApplicationInfo)9 VisibleForTesting (androidx.annotation.VisibleForTesting)9 List (java.util.List)9 UserManager (android.os.UserManager)8 StorageItemPreference (com.android.settings.deviceinfo.StorageItemPreference)8