Loading packages/SettingsLib/src/com/android/settingslib/drawer/Tile.java +8 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.UserHandle; import android.text.TextUtils; import android.widget.RemoteViews; import java.util.ArrayList; Loading Loading @@ -84,6 +85,11 @@ public class Tile implements Parcelable { */ public String key; /** * Optional remote view which will be displayed instead of the regular title-summary item. */ public RemoteViews remoteViews; public Tile() { // Empty } Loading Loading @@ -119,6 +125,7 @@ public class Tile implements Parcelable { dest.writeInt(priority); dest.writeBundle(metaData); dest.writeString(key); dest.writeParcelable(remoteViews, flags); } public void readFromParcel(Parcel in) { Loading @@ -139,6 +146,7 @@ public class Tile implements Parcelable { priority = in.readInt(); metaData = in.readBundle(); key = in.readString(); remoteViews = in.readParcelable(RemoteViews.class.getClassLoader()); } Tile(Parcel in) { Loading packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java +15 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.content.IContentProvider; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Resources; Loading @@ -35,6 +34,7 @@ import android.provider.Settings.Global; import android.text.TextUtils; import android.util.Log; import android.util.Pair; import android.widget.RemoteViews; import java.util.ArrayList; import java.util.Collections; Loading Loading @@ -153,6 +153,14 @@ public class TileUtils { public static final String META_DATA_PREFERENCE_SUMMARY_URI = "com.android.settings.summary_uri"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml to specify the * custom view which should be displayed for the preference. The custom view will be inflated * as a remote view. */ public static final String META_DATA_PREFERENCE_CUSTOM_VIEW = "com.android.settings.custom_view"; public static final String SETTING_PKG = "com.android.settings"; /** Loading Loading @@ -353,6 +361,7 @@ public class TileUtils { String summary = null; String keyHint = null; Uri uri = null; RemoteViews remoteViews = null; // Get the activity's meta-data try { Loading Loading @@ -385,6 +394,10 @@ public class TileUtils { keyHint = metaData.getString(META_DATA_PREFERENCE_KEYHINT); } } if (metaData.containsKey(META_DATA_PREFERENCE_CUSTOM_VIEW)) { int layoutId = metaData.getInt(META_DATA_PREFERENCE_CUSTOM_VIEW); remoteViews = new RemoteViews(applicationInfo.packageName, layoutId); } } } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) { if (DEBUG) Log.d(LOG_TAG, "Couldn't find info", e); Loading Loading @@ -414,6 +427,7 @@ public class TileUtils { activityInfo.name); // Suggest a key for this tile tile.key = keyHint; tile.remoteViews = remoteViews; return true; } Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java +25 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ import android.text.TextUtils; import android.util.ArrayMap; import android.util.Pair; import com.android.settingslib.R; import com.android.settingslib.SuggestionParser; import com.android.settingslib.TestConfig; Loading Loading @@ -293,6 +294,30 @@ public class TileUtilsTest { assertThat(outTiles.size()).isEqualTo(1); } @Test public void getTilesForIntent_shouldShowRemoteViewIfSpecified() { Intent intent = new Intent(); Map<Pair<String, String>, Tile> addedCache = new ArrayMap<>(); List<Tile> outTiles = new ArrayList<>(); List<ResolveInfo> info = new ArrayList<>(); ResolveInfo resolveInfo = newInfo(true, null /* category */); resolveInfo.activityInfo.metaData.putInt("com.android.settings.custom_view", R.layout.user_preference); info.add(resolveInfo); when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt())) .thenReturn(info); TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache, null /* defaultCategory */, outTiles, false /* usePriority */, false /* checkCategory */); assertThat(outTiles.size()).isEqualTo(1); Tile tile = outTiles.get(0); assertThat(tile.remoteViews).isNotNull(); assertThat(tile.remoteViews.getLayoutId()).isEqualTo(R.layout.user_preference); } public static ResolveInfo newInfo(boolean systemApp, String category) { return newInfo(systemApp, category, null); } Loading Loading
packages/SettingsLib/src/com/android/settingslib/drawer/Tile.java +8 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.UserHandle; import android.text.TextUtils; import android.widget.RemoteViews; import java.util.ArrayList; Loading Loading @@ -84,6 +85,11 @@ public class Tile implements Parcelable { */ public String key; /** * Optional remote view which will be displayed instead of the regular title-summary item. */ public RemoteViews remoteViews; public Tile() { // Empty } Loading Loading @@ -119,6 +125,7 @@ public class Tile implements Parcelable { dest.writeInt(priority); dest.writeBundle(metaData); dest.writeString(key); dest.writeParcelable(remoteViews, flags); } public void readFromParcel(Parcel in) { Loading @@ -139,6 +146,7 @@ public class Tile implements Parcelable { priority = in.readInt(); metaData = in.readBundle(); key = in.readString(); remoteViews = in.readParcelable(RemoteViews.class.getClassLoader()); } Tile(Parcel in) { Loading
packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java +15 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.content.IContentProvider; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Resources; Loading @@ -35,6 +34,7 @@ import android.provider.Settings.Global; import android.text.TextUtils; import android.util.Log; import android.util.Pair; import android.widget.RemoteViews; import java.util.ArrayList; import java.util.Collections; Loading Loading @@ -153,6 +153,14 @@ public class TileUtils { public static final String META_DATA_PREFERENCE_SUMMARY_URI = "com.android.settings.summary_uri"; /** * Name of the meta-data item that should be set in the AndroidManifest.xml to specify the * custom view which should be displayed for the preference. The custom view will be inflated * as a remote view. */ public static final String META_DATA_PREFERENCE_CUSTOM_VIEW = "com.android.settings.custom_view"; public static final String SETTING_PKG = "com.android.settings"; /** Loading Loading @@ -353,6 +361,7 @@ public class TileUtils { String summary = null; String keyHint = null; Uri uri = null; RemoteViews remoteViews = null; // Get the activity's meta-data try { Loading Loading @@ -385,6 +394,10 @@ public class TileUtils { keyHint = metaData.getString(META_DATA_PREFERENCE_KEYHINT); } } if (metaData.containsKey(META_DATA_PREFERENCE_CUSTOM_VIEW)) { int layoutId = metaData.getInt(META_DATA_PREFERENCE_CUSTOM_VIEW); remoteViews = new RemoteViews(applicationInfo.packageName, layoutId); } } } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) { if (DEBUG) Log.d(LOG_TAG, "Couldn't find info", e); Loading Loading @@ -414,6 +427,7 @@ public class TileUtils { activityInfo.name); // Suggest a key for this tile tile.key = keyHint; tile.remoteViews = remoteViews; return true; } Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java +25 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ import android.text.TextUtils; import android.util.ArrayMap; import android.util.Pair; import com.android.settingslib.R; import com.android.settingslib.SuggestionParser; import com.android.settingslib.TestConfig; Loading Loading @@ -293,6 +294,30 @@ public class TileUtilsTest { assertThat(outTiles.size()).isEqualTo(1); } @Test public void getTilesForIntent_shouldShowRemoteViewIfSpecified() { Intent intent = new Intent(); Map<Pair<String, String>, Tile> addedCache = new ArrayMap<>(); List<Tile> outTiles = new ArrayList<>(); List<ResolveInfo> info = new ArrayList<>(); ResolveInfo resolveInfo = newInfo(true, null /* category */); resolveInfo.activityInfo.metaData.putInt("com.android.settings.custom_view", R.layout.user_preference); info.add(resolveInfo); when(mPackageManager.queryIntentActivitiesAsUser(eq(intent), anyInt(), anyInt())) .thenReturn(info); TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache, null /* defaultCategory */, outTiles, false /* usePriority */, false /* checkCategory */); assertThat(outTiles.size()).isEqualTo(1); Tile tile = outTiles.get(0); assertThat(tile.remoteViews).isNotNull(); assertThat(tile.remoteViews.getLayoutId()).isEqualTo(R.layout.user_preference); } public static ResolveInfo newInfo(boolean systemApp, String category) { return newInfo(systemApp, category, null); } Loading