Search in sources :

Example 26 with DashboardCategory

use of com.android.settingslib.drawer.DashboardCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class CategoryManagerTest method sortCategories_singlePackage_shouldReorderBasedOnPriority.

@Test
public void sortCategories_singlePackage_shouldReorderBasedOnPriority() {
    // Create some fake tiles that are not sorted.
    final String testPackage = "com.android.test";
    final DashboardCategory category = new DashboardCategory(CATEGORY_HOMEPAGE);
    final ActivityInfo activityInfo1 = new ActivityInfo();
    activityInfo1.metaData = new Bundle();
    activityInfo1.metaData.putInt(META_DATA_KEY_ORDER, 100);
    activityInfo1.packageName = testPackage;
    activityInfo1.name = "class1";
    final ActivityInfo activityInfo2 = new ActivityInfo();
    activityInfo2.metaData = new Bundle();
    activityInfo2.metaData.putInt(META_DATA_KEY_ORDER, 50);
    activityInfo2.packageName = testPackage;
    activityInfo2.name = "class2";
    final ActivityInfo activityInfo3 = new ActivityInfo();
    activityInfo3.metaData = new Bundle();
    activityInfo3.metaData.putInt(META_DATA_KEY_ORDER, 200);
    activityInfo3.packageName = testPackage;
    activityInfo3.name = "class3";
    final Tile tile1 = new Tile(activityInfo1, category.key);
    final Tile tile2 = new Tile(activityInfo2, category.key);
    final Tile tile3 = new Tile(activityInfo3, category.key);
    category.addTile(tile1);
    category.addTile(tile2);
    category.addTile(tile3);
    mCategoryByKeyMap.put(CATEGORY_HOMEPAGE, category);
    // Sort their priorities
    mCategoryManager.sortCategories(RuntimeEnvironment.application, mCategoryByKeyMap);
    // Verify they are now sorted.
    assertThat(category.getTile(0)).isSameAs(tile3);
    assertThat(category.getTile(1)).isSameAs(tile1);
    assertThat(category.getTile(2)).isSameAs(tile2);
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) ActivityInfo(android.content.pm.ActivityInfo) Bundle(android.os.Bundle) Tile(com.android.settingslib.drawer.Tile) Test(org.junit.Test)

Example 27 with DashboardCategory

use of com.android.settingslib.drawer.DashboardCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DashboardFragmentTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    mActivityInfo = new ActivityInfo();
    mActivityInfo.packageName = "pkg";
    mActivityInfo.name = "class";
    mActivityInfo.metaData = new Bundle();
    mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "injected_tile_key");
    mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
    mDashboardCategory = new DashboardCategory("key");
    mDashboardCategory.addTile(new Tile(mActivityInfo, mDashboardCategory.key));
    mTestFragment = new TestFragment(RuntimeEnvironment.application);
    when(mFakeFeatureFactory.dashboardFeatureProvider.getTilesForCategory(nullable(String.class))).thenReturn(mDashboardCategory);
    mTestFragment.onAttach(RuntimeEnvironment.application);
    when(mContext.getPackageName()).thenReturn("TestPackage");
    mControllers = new ArrayList<>();
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) ActivityInfo(android.content.pm.ActivityInfo) Bundle(android.os.Bundle) Tile(com.android.settingslib.drawer.Tile) Before(org.junit.Before)

Example 28 with DashboardCategory

use of com.android.settingslib.drawer.DashboardCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class CategoryManagerTest method backwardCompatCleanupForCategory_shouldChangeCategoryForOldKeys.

@Test
public void backwardCompatCleanupForCategory_shouldChangeCategoryForOldKeys() {
    final String oldCategory = "com.android.settings.category.wireless";
    final Tile tile1 = new Tile(mActivityInfo, oldCategory);
    tile1.setCategory(oldCategory);
    final DashboardCategory category1 = new DashboardCategory(oldCategory);
    category1.addTile(tile1);
    mCategoryByKeyMap.put(oldCategory, category1);
    mTileByComponentCache.put(new Pair<>("PACKAGE", "CLASS1"), tile1);
    mCategoryManager.backwardCompatCleanupForCategory(mTileByComponentCache, mCategoryByKeyMap);
    // Added 1 more category to category map.
    assertThat(mCategoryByKeyMap.size()).isEqualTo(2);
    // The new category map has CATEGORY_NETWORK type now, which contains 1 tile.
    assertThat(mCategoryByKeyMap.get(CategoryKey.CATEGORY_NETWORK).getTilesCount()).isEqualTo(1);
    // Old category still exists.
    assertThat(mCategoryByKeyMap.get(oldCategory).getTilesCount()).isEqualTo(1);
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) Tile(com.android.settingslib.drawer.Tile) Test(org.junit.Test)

Example 29 with DashboardCategory

use of com.android.settingslib.drawer.DashboardCategory 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 30 with DashboardCategory

use of com.android.settingslib.drawer.DashboardCategory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DashboardFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    final DashboardCategory category = mDashboardFeatureProvider.getTilesForCategory(getCategoryKey());
    if (category == null) {
        return;
    }
    if (mSummaryLoader != null) {
        // SummaryLoader can be null when there is no dynamic tiles.
        mSummaryLoader.setListening(true);
    }
    final Activity activity = getActivity();
    if (activity instanceof SettingsBaseActivity) {
        mListeningToCategoryChange = true;
        ((SettingsBaseActivity) activity).addCategoryListener(this);
    }
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) SettingsBaseActivity(com.android.settings.core.SettingsBaseActivity) SettingsBaseActivity(com.android.settings.core.SettingsBaseActivity) Activity(android.app.Activity)

Aggregations

DashboardCategory (com.android.settingslib.drawer.DashboardCategory)449 Tile (com.android.settingslib.drawer.Tile)303 Test (org.junit.Test)225 ProviderTile (com.android.settingslib.drawer.ProviderTile)185 ActivityTile (com.android.settingslib.drawer.ActivityTile)179 Bundle (android.os.Bundle)77 ArrayList (java.util.ArrayList)71 VisibleForTesting (androidx.annotation.VisibleForTesting)52 ActivityInfo (android.content.pm.ActivityInfo)41 Intent (android.content.Intent)32 ComponentName (android.content.ComponentName)31 Context (android.content.Context)31 Before (org.junit.Before)30 Activity (android.app.Activity)27 View (android.view.View)27 PreferenceScreen (android.support.v7.preference.PreferenceScreen)26 List (java.util.List)26 ProviderInfo (android.content.pm.ProviderInfo)23 HashMap (java.util.HashMap)20 TestConfig (com.android.settings.TestConfig)18