Search in sources :

Example 1 with ActivityTile

use of com.android.settingslib.drawer.ActivityTile in project android_packages_apps_Settings by omnirom.

the class CategoryManagerTest method createActivityTile.

private Tile createActivityTile(String categoryKey, String packageName, String className, int order) {
    final ActivityInfo activityInfo = new ActivityInfo();
    activityInfo.packageName = packageName;
    activityInfo.name = className;
    activityInfo.metaData = new Bundle();
    activityInfo.metaData.putInt(META_DATA_KEY_ORDER, order);
    return new ActivityTile(activityInfo, categoryKey);
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) Bundle(android.os.Bundle) ActivityTile(com.android.settingslib.drawer.ActivityTile)

Example 2 with ActivityTile

use of com.android.settingslib.drawer.ActivityTile in project android_packages_apps_Settings by omnirom.

the class CategoryManagerTest method backwardCompatCleanupForCategory_shouldChangeCategoryForOldKeys.

@Test
public void backwardCompatCleanupForCategory_shouldChangeCategoryForOldKeys() {
    final String oldCategory = "com.android.settings.category.wireless";
    final Tile tile1 = new ActivityTile(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) ActivityTile(com.android.settingslib.drawer.ActivityTile) ProviderTile(com.android.settingslib.drawer.ProviderTile) Tile(com.android.settingslib.drawer.Tile) ActivityTile(com.android.settingslib.drawer.ActivityTile) Test(org.junit.Test)

Example 3 with ActivityTile

use of com.android.settingslib.drawer.ActivityTile in project android_packages_apps_Settings by omnirom.

the class DashboardFeatureProviderImpl method bindPreferenceToTileAndGetObservers.

@Override
public List<DynamicDataObserver> bindPreferenceToTileAndGetObservers(FragmentActivity activity, boolean forceRoundedIcon, int sourceMetricsCategory, Preference pref, Tile tile, String key, int baseOrder) {
    if (pref == null) {
        return null;
    }
    if (!TextUtils.isEmpty(key)) {
        pref.setKey(key);
    } else {
        pref.setKey(getDashboardKeyForTile(tile));
    }
    final List<DynamicDataObserver> outObservers = new ArrayList<>();
    DynamicDataObserver observer = bindTitleAndGetObserver(pref, tile);
    if (observer != null) {
        outObservers.add(observer);
    }
    observer = bindSummaryAndGetObserver(pref, tile);
    if (observer != null) {
        outObservers.add(observer);
    }
    observer = bindSwitchAndGetObserver(pref, tile);
    if (observer != null) {
        outObservers.add(observer);
    }
    bindIcon(pref, tile, forceRoundedIcon);
    if (tile instanceof ActivityTile) {
        final Bundle metadata = tile.getMetaData();
        String clsName = null;
        String action = null;
        if (metadata != null) {
            clsName = metadata.getString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS);
            action = metadata.getString(META_DATA_KEY_INTENT_ACTION);
        }
        if (!TextUtils.isEmpty(clsName)) {
            pref.setFragment(clsName);
        } else {
            final Intent intent = new Intent(tile.getIntent());
            intent.putExtra(MetricsFeatureProvider.EXTRA_SOURCE_METRICS_CATEGORY, sourceMetricsCategory);
            if (action != null) {
                intent.setAction(action);
            }
            pref.setOnPreferenceClickListener(preference -> {
                launchIntentOrSelectProfile(activity, tile, intent, sourceMetricsCategory);
                return true;
            });
        }
    }
    if (tile.hasOrder()) {
        final String skipOffsetPackageName = activity.getPackageName();
        final int order = tile.getOrder();
        boolean shouldSkipBaseOrderOffset = TextUtils.equals(skipOffsetPackageName, tile.getIntent().getComponent().getPackageName());
        if (shouldSkipBaseOrderOffset || baseOrder == Preference.DEFAULT_ORDER) {
            pref.setOrder(order);
        } else {
            pref.setOrder(order + baseOrder);
        }
    }
    return outObservers.isEmpty() ? null : outObservers;
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ActivityTile(com.android.settingslib.drawer.ActivityTile)

Example 4 with ActivityTile

use of com.android.settingslib.drawer.ActivityTile in project android_packages_apps_Settings by omnirom.

the class AccountDetailDashboardFragmentTest method refreshDashboardTiles_OtherAccountType_shouldNotDisplay.

@Test
public void refreshDashboardTiles_OtherAccountType_shouldNotDisplay() {
    final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
    mActivityInfo.metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
    mActivityInfo.metaData.putString(METADATA_ACCOUNT_TYPE, "com.other");
    assertThat(mFragment.displayTile(tile)).isFalse();
}
Also used : ActivityTile(com.android.settingslib.drawer.ActivityTile) Tile(com.android.settingslib.drawer.Tile) ActivityTile(com.android.settingslib.drawer.ActivityTile) Test(org.junit.Test)

Example 5 with ActivityTile

use of com.android.settingslib.drawer.ActivityTile in project android_packages_apps_Settings by omnirom.

the class AccountDetailDashboardFragmentTest method refreshDashboardTiles_HasAccountType_shouldDisplay.

@Test
public void refreshDashboardTiles_HasAccountType_shouldDisplay() {
    final Tile tile = new ActivityTile(mActivityInfo, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
    mActivityInfo.metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
    mActivityInfo.metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
    assertThat(mFragment.displayTile(tile)).isTrue();
}
Also used : ActivityTile(com.android.settingslib.drawer.ActivityTile) Tile(com.android.settingslib.drawer.Tile) ActivityTile(com.android.settingslib.drawer.ActivityTile) Test(org.junit.Test)

Aggregations

ActivityTile (com.android.settingslib.drawer.ActivityTile)41 Test (org.junit.Test)37 Tile (com.android.settingslib.drawer.Tile)35 ProviderTile (com.android.settingslib.drawer.ProviderTile)29 Preference (androidx.preference.Preference)20 SwitchPreference (androidx.preference.SwitchPreference)19 Intent (android.content.Intent)11 UserHandle (android.os.UserHandle)10 ArrayList (java.util.ArrayList)7 ActivityInfo (android.content.pm.ActivityInfo)5 DashboardCategory (com.android.settingslib.drawer.DashboardCategory)5 Config (org.robolectric.annotation.Config)5 Bundle (android.os.Bundle)4 FragmentActivity (androidx.fragment.app.FragmentActivity)3 ProviderInfo (android.content.pm.ProviderInfo)2 ResolveInfo (android.content.pm.ResolveInfo)2 Bitmap (android.graphics.Bitmap)2 Drawable (android.graphics.drawable.Drawable)2 Before (org.junit.Before)2 ShadowActivity (org.robolectric.shadows.ShadowActivity)2