Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
Fan Zhang | 83dde97 | 2018-07-23 16:51:14 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.settingslib.drawer; |
| 18 | |
Fan Zhang | 4c07a71 | 2018-08-06 10:04:14 -0700 | [diff] [blame] | 19 | import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_ORDER; |
arangelov | 24eec2f | 2018-05-30 18:24:23 +0100 | [diff] [blame] | 20 | import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_PROFILE; |
Fan Zhang | 83dde97 | 2018-07-23 16:51:14 -0700 | [diff] [blame] | 21 | import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON; |
| 22 | import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_URI; |
Fan Zhang | 4c07a71 | 2018-08-06 10:04:14 -0700 | [diff] [blame] | 23 | import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT; |
Fan Zhang | 4aa6da6 | 2018-08-20 14:13:59 -0700 | [diff] [blame] | 24 | import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_SUMMARY; |
| 25 | import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_SUMMARY_URI; |
Fan Zhang | a6afef8 | 2018-08-17 11:34:27 -0700 | [diff] [blame] | 26 | import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_TITLE; |
arangelov | 24eec2f | 2018-05-30 18:24:23 +0100 | [diff] [blame] | 27 | import static com.android.settingslib.drawer.TileUtils.PROFILE_ALL; |
| 28 | import static com.android.settingslib.drawer.TileUtils.PROFILE_PRIMARY; |
| 29 | |
Fan Zhang | 0e20123 | 2018-07-26 11:26:44 -0700 | [diff] [blame] | 30 | import android.content.Context; |
Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 31 | import android.content.Intent; |
Fan Zhang | 83dde97 | 2018-07-23 16:51:14 -0700 | [diff] [blame] | 32 | import android.content.pm.ActivityInfo; |
Fan Zhang | 0e20123 | 2018-07-26 11:26:44 -0700 | [diff] [blame] | 33 | import android.content.pm.PackageManager; |
| 34 | import android.content.pm.ResolveInfo; |
Fan Zhang | a6afef8 | 2018-08-17 11:34:27 -0700 | [diff] [blame] | 35 | import android.content.res.Resources; |
Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 36 | import android.graphics.drawable.Icon; |
| 37 | import android.os.Bundle; |
| 38 | import android.os.Parcel; |
| 39 | import android.os.Parcelable; |
| 40 | import android.os.UserHandle; |
| 41 | import android.text.TextUtils; |
Fan Zhang | a6afef8 | 2018-08-17 11:34:27 -0700 | [diff] [blame] | 42 | import android.util.Log; |
Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 43 | |
Fan Zhang | 8f942a4 | 2019-03-05 17:04:06 -0800 | [diff] [blame] | 44 | import androidx.annotation.VisibleForTesting; |
| 45 | |
Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 46 | import java.util.ArrayList; |
Fan Zhang | 23baea9 | 2018-08-02 13:20:22 -0700 | [diff] [blame] | 47 | import java.util.Comparator; |
Fan Zhang | 0e20123 | 2018-07-26 11:26:44 -0700 | [diff] [blame] | 48 | import java.util.List; |
Fan Zhang | a6afef8 | 2018-08-17 11:34:27 -0700 | [diff] [blame] | 49 | import java.util.Objects; |
Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Description of a single dashboard tile that the user can select. |
| 53 | */ |
Jason Monk | f509d7e | 2016-01-07 16:22:53 -0500 | [diff] [blame] | 54 | public class Tile implements Parcelable { |
Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 55 | |
Fan Zhang | 83dde97 | 2018-07-23 16:51:14 -0700 | [diff] [blame] | 56 | private static final String TAG = "Tile"; |
Fan Zhang | 83dde97 | 2018-07-23 16:51:14 -0700 | [diff] [blame] | 57 | |
Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 58 | /** |
Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 59 | * Optional list of user handles which the intent should be launched on. |
| 60 | */ |
| 61 | public ArrayList<UserHandle> userHandle = new ArrayList<>(); |
| 62 | |
Fan Zhang | 8f942a4 | 2019-03-05 17:04:06 -0800 | [diff] [blame] | 63 | @VisibleForTesting |
| 64 | long mLastUpdateTime; |
Fan Zhang | 0e20123 | 2018-07-26 11:26:44 -0700 | [diff] [blame] | 65 | private final String mActivityPackage; |
| 66 | private final String mActivityName; |
Fan Zhang | a79ab48 | 2018-08-07 13:04:20 -0700 | [diff] [blame] | 67 | private final Intent mIntent; |
Fan Zhang | 83961e1 | 2018-08-21 18:06:24 -0700 | [diff] [blame] | 68 | |
Fan Zhang | 0e20123 | 2018-07-26 11:26:44 -0700 | [diff] [blame] | 69 | private ActivityInfo mActivityInfo; |
Fan Zhang | 4aa6da6 | 2018-08-20 14:13:59 -0700 | [diff] [blame] | 70 | private CharSequence mSummaryOverride; |
Fan Zhang | 83961e1 | 2018-08-21 18:06:24 -0700 | [diff] [blame] | 71 | private Bundle mMetaData; |
Fan Zhang | a79ab48 | 2018-08-07 13:04:20 -0700 | [diff] [blame] | 72 | private String mCategory; |
Fan Zhang | 0e20123 | 2018-07-26 11:26:44 -0700 | [diff] [blame] | 73 | |
Fan Zhang | f5c1d76 | 2018-08-03 09:14:32 -0700 | [diff] [blame] | 74 | public Tile(ActivityInfo activityInfo, String category) { |
Fan Zhang | 83dde97 | 2018-07-23 16:51:14 -0700 | [diff] [blame] | 75 | mActivityInfo = activityInfo; |
Fan Zhang | 0e20123 | 2018-07-26 11:26:44 -0700 | [diff] [blame] | 76 | mActivityPackage = mActivityInfo.packageName; |
| 77 | mActivityName = mActivityInfo.name; |
Fan Zhang | f5c1d76 | 2018-08-03 09:14:32 -0700 | [diff] [blame] | 78 | mMetaData = activityInfo.metaData; |
| 79 | mCategory = category; |
Fan Zhang | a79ab48 | 2018-08-07 13:04:20 -0700 | [diff] [blame] | 80 | mIntent = new Intent().setClassName(mActivityPackage, mActivityName); |
| 81 | } |
| 82 | |
| 83 | Tile(Parcel in) { |
| 84 | mActivityPackage = in.readString(); |
| 85 | mActivityName = in.readString(); |
| 86 | mIntent = new Intent().setClassName(mActivityPackage, mActivityName); |
Fan Zhang | a79ab48 | 2018-08-07 13:04:20 -0700 | [diff] [blame] | 87 | final int N = in.readInt(); |
| 88 | for (int i = 0; i < N; i++) { |
| 89 | userHandle.add(UserHandle.CREATOR.createFromParcel(in)); |
| 90 | } |
| 91 | mCategory = in.readString(); |
Fan Zhang | a79ab48 | 2018-08-07 13:04:20 -0700 | [diff] [blame] | 92 | mMetaData = in.readBundle(); |
Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public int describeContents() { |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public void writeToParcel(Parcel dest, int flags) { |
Fan Zhang | 0e20123 | 2018-07-26 11:26:44 -0700 | [diff] [blame] | 102 | dest.writeString(mActivityPackage); |
| 103 | dest.writeString(mActivityName); |
Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 104 | final int N = userHandle.size(); |
| 105 | dest.writeInt(N); |
| 106 | for (int i = 0; i < N; i++) { |
| 107 | userHandle.get(i).writeToParcel(dest, flags); |
| 108 | } |
Fan Zhang | f5c1d76 | 2018-08-03 09:14:32 -0700 | [diff] [blame] | 109 | dest.writeString(mCategory); |
Fan Zhang | f5c1d76 | 2018-08-03 09:14:32 -0700 | [diff] [blame] | 110 | dest.writeBundle(mMetaData); |
Fan Zhang | f5c1d76 | 2018-08-03 09:14:32 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Fan Zhang | a6afef8 | 2018-08-17 11:34:27 -0700 | [diff] [blame] | 113 | public int getId() { |
| 114 | return Objects.hash(mActivityPackage, mActivityName); |
| 115 | } |
| 116 | |
| 117 | public String getDescription() { |
| 118 | return mActivityPackage + "/" + mActivityName; |
| 119 | } |
| 120 | |
Fan Zhang | a79ab48 | 2018-08-07 13:04:20 -0700 | [diff] [blame] | 121 | public String getPackageName() { |
| 122 | return mActivityPackage; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Intent to launch when the preference is selected. |
| 127 | */ |
| 128 | public Intent getIntent() { |
| 129 | return mIntent; |
| 130 | } |
| 131 | |
Fan Zhang | f5c1d76 | 2018-08-03 09:14:32 -0700 | [diff] [blame] | 132 | /** |
| 133 | * Category in which the tile should be placed. |
| 134 | */ |
| 135 | public String getCategory() { |
| 136 | return mCategory; |
| 137 | } |
| 138 | |
| 139 | public void setCategory(String newCategoryKey) { |
| 140 | mCategory = newCategoryKey; |
| 141 | } |
| 142 | |
| 143 | /** |
Fan Zhang | 4c07a71 | 2018-08-06 10:04:14 -0700 | [diff] [blame] | 144 | * Priority of this tile, used for display ordering. |
Fan Zhang | f5c1d76 | 2018-08-03 09:14:32 -0700 | [diff] [blame] | 145 | */ |
Fan Zhang | 4c07a71 | 2018-08-06 10:04:14 -0700 | [diff] [blame] | 146 | public int getOrder() { |
| 147 | if (hasOrder()) { |
| 148 | return mMetaData.getInt(META_DATA_KEY_ORDER); |
| 149 | } else { |
| 150 | return 0; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | public boolean hasOrder() { |
| 155 | return mMetaData.containsKey(META_DATA_KEY_ORDER) |
| 156 | && mMetaData.get(META_DATA_KEY_ORDER) instanceof Integer; |
Fan Zhang | f5c1d76 | 2018-08-03 09:14:32 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Fan Zhang | a6afef8 | 2018-08-17 11:34:27 -0700 | [diff] [blame] | 159 | /** |
| 160 | * Title of the tile that is shown to the user. |
| 161 | */ |
| 162 | public CharSequence getTitle(Context context) { |
| 163 | CharSequence title = null; |
Fan Zhang | 8f942a4 | 2019-03-05 17:04:06 -0800 | [diff] [blame] | 164 | ensureMetadataNotStale(context); |
Fan Zhang | a6afef8 | 2018-08-17 11:34:27 -0700 | [diff] [blame] | 165 | final PackageManager packageManager = context.getPackageManager(); |
| 166 | if (mMetaData.containsKey(META_DATA_PREFERENCE_TITLE)) { |
| 167 | if (mMetaData.get(META_DATA_PREFERENCE_TITLE) instanceof Integer) { |
| 168 | try { |
| 169 | final Resources res = |
| 170 | packageManager.getResourcesForApplication(mActivityPackage); |
| 171 | title = res.getString(mMetaData.getInt(META_DATA_PREFERENCE_TITLE)); |
| 172 | } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) { |
| 173 | Log.d(TAG, "Couldn't find info", e); |
| 174 | } |
| 175 | } else { |
| 176 | title = mMetaData.getString(META_DATA_PREFERENCE_TITLE); |
| 177 | } |
| 178 | } |
| 179 | // Set the preference title to the activity's label if no |
| 180 | // meta-data is found |
| 181 | if (title == null) { |
| 182 | title = getActivityInfo(context).loadLabel(packageManager); |
| 183 | } |
| 184 | return title; |
| 185 | } |
| 186 | |
Fan Zhang | 4aa6da6 | 2018-08-20 14:13:59 -0700 | [diff] [blame] | 187 | /** |
| 188 | * Returns the raw metadata for summary, this is used for comparing 2 summary text without |
| 189 | * loading the real string. |
| 190 | */ |
| 191 | public String getSummaryReference() { |
| 192 | if (mSummaryOverride != null) { |
| 193 | return mSummaryOverride.toString(); |
| 194 | } |
| 195 | if (mMetaData != null && mMetaData.containsKey(META_DATA_PREFERENCE_SUMMARY)) { |
| 196 | return mMetaData.get(META_DATA_PREFERENCE_SUMMARY).toString(); |
| 197 | } |
| 198 | return null; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Overrides the summary. This can happen when injected tile wants to provide dynamic summary. |
| 203 | */ |
| 204 | public void overrideSummary(CharSequence summaryOverride) { |
| 205 | mSummaryOverride = summaryOverride; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Optional summary describing what this tile controls. |
| 210 | */ |
| 211 | public CharSequence getSummary(Context context) { |
| 212 | if (mSummaryOverride != null) { |
| 213 | return mSummaryOverride; |
| 214 | } |
Fan Zhang | 8f942a4 | 2019-03-05 17:04:06 -0800 | [diff] [blame] | 215 | ensureMetadataNotStale(context); |
Fan Zhang | 4aa6da6 | 2018-08-20 14:13:59 -0700 | [diff] [blame] | 216 | CharSequence summary = null; |
| 217 | final PackageManager packageManager = context.getPackageManager(); |
| 218 | if (mMetaData != null) { |
| 219 | if (mMetaData.containsKey(META_DATA_PREFERENCE_SUMMARY_URI)) { |
| 220 | return null; |
| 221 | } |
| 222 | if (mMetaData.containsKey(META_DATA_PREFERENCE_SUMMARY)) { |
| 223 | if (mMetaData.get(META_DATA_PREFERENCE_SUMMARY) instanceof Integer) { |
| 224 | try { |
| 225 | final Resources res = |
| 226 | packageManager.getResourcesForApplication(mActivityPackage); |
| 227 | summary = res.getString(mMetaData.getInt(META_DATA_PREFERENCE_SUMMARY)); |
| 228 | } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) { |
| 229 | Log.d(TAG, "Couldn't find info", e); |
| 230 | } |
| 231 | } else { |
| 232 | summary = mMetaData.getString(META_DATA_PREFERENCE_SUMMARY); |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | return summary; |
| 237 | } |
| 238 | |
Fan Zhang | 83961e1 | 2018-08-21 18:06:24 -0700 | [diff] [blame] | 239 | public void setMetaData(Bundle metaData) { |
| 240 | mMetaData = metaData; |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * The metaData from the activity that defines this tile. |
| 245 | */ |
Fan Zhang | f5c1d76 | 2018-08-03 09:14:32 -0700 | [diff] [blame] | 246 | public Bundle getMetaData() { |
| 247 | return mMetaData; |
Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 248 | } |
| 249 | |
Fan Zhang | 83dde97 | 2018-07-23 16:51:14 -0700 | [diff] [blame] | 250 | /** |
Fan Zhang | 4c07a71 | 2018-08-06 10:04:14 -0700 | [diff] [blame] | 251 | * Optional key to use for this tile. |
| 252 | */ |
| 253 | public String getKey(Context context) { |
| 254 | if (!hasKey()) { |
| 255 | return null; |
| 256 | } |
Fan Zhang | 8f942a4 | 2019-03-05 17:04:06 -0800 | [diff] [blame] | 257 | ensureMetadataNotStale(context); |
Fan Zhang | 4c07a71 | 2018-08-06 10:04:14 -0700 | [diff] [blame] | 258 | if (mMetaData.get(META_DATA_PREFERENCE_KEYHINT) instanceof Integer) { |
| 259 | return context.getResources().getString(mMetaData.getInt(META_DATA_PREFERENCE_KEYHINT)); |
| 260 | } else { |
| 261 | return mMetaData.getString(META_DATA_PREFERENCE_KEYHINT); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | public boolean hasKey() { |
| 266 | return mMetaData != null && mMetaData.containsKey(META_DATA_PREFERENCE_KEYHINT); |
| 267 | } |
| 268 | |
| 269 | /** |
Fan Zhang | 83dde97 | 2018-07-23 16:51:14 -0700 | [diff] [blame] | 270 | * Optional icon to show for this tile. |
| 271 | * |
| 272 | * @attr ref android.R.styleable#PreferenceHeader_icon |
| 273 | */ |
Fan Zhang | 0e20123 | 2018-07-26 11:26:44 -0700 | [diff] [blame] | 274 | public Icon getIcon(Context context) { |
Fan Zhang | f5c1d76 | 2018-08-03 09:14:32 -0700 | [diff] [blame] | 275 | if (context == null || mMetaData == null) { |
Fan Zhang | 83dde97 | 2018-07-23 16:51:14 -0700 | [diff] [blame] | 276 | return null; |
| 277 | } |
Fan Zhang | 8f942a4 | 2019-03-05 17:04:06 -0800 | [diff] [blame] | 278 | ensureMetadataNotStale(context); |
Fan Zhang | f5c1d76 | 2018-08-03 09:14:32 -0700 | [diff] [blame] | 279 | int iconResId = mMetaData.getInt(META_DATA_PREFERENCE_ICON); |
Fan Zhang | 83dde97 | 2018-07-23 16:51:14 -0700 | [diff] [blame] | 280 | // Set the icon |
| 281 | if (iconResId == 0) { |
| 282 | // Only fallback to activityinfo.icon if metadata does not contain ICON_URI. |
| 283 | // ICON_URI should be loaded in app UI when need the icon object. Handling IPC at this |
| 284 | // level is too complex because we don't have a strong threading contract for this class |
Fan Zhang | f5c1d76 | 2018-08-03 09:14:32 -0700 | [diff] [blame] | 285 | if (!mMetaData.containsKey(META_DATA_PREFERENCE_ICON_URI)) { |
Fan Zhang | 0e20123 | 2018-07-26 11:26:44 -0700 | [diff] [blame] | 286 | iconResId = getActivityInfo(context).icon; |
Fan Zhang | 83dde97 | 2018-07-23 16:51:14 -0700 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | if (iconResId != 0) { |
Fan Zhang | 0e20123 | 2018-07-26 11:26:44 -0700 | [diff] [blame] | 290 | return Icon.createWithResource(getActivityInfo(context).packageName, iconResId); |
Fan Zhang | 83dde97 | 2018-07-23 16:51:14 -0700 | [diff] [blame] | 291 | } else { |
| 292 | return null; |
| 293 | } |
| 294 | } |
| 295 | |
Fan Zhang | f5c1d76 | 2018-08-03 09:14:32 -0700 | [diff] [blame] | 296 | /** |
| 297 | * Whether the icon can be tinted. This is true when icon needs to be monochrome (single-color) |
| 298 | */ |
| 299 | public boolean isIconTintable(Context context) { |
| 300 | if (mMetaData != null |
| 301 | && mMetaData.containsKey(TileUtils.META_DATA_PREFERENCE_ICON_TINTABLE)) { |
| 302 | return mMetaData.getBoolean(TileUtils.META_DATA_PREFERENCE_ICON_TINTABLE); |
| 303 | } |
Fan Zhang | 8f942a4 | 2019-03-05 17:04:06 -0800 | [diff] [blame] | 304 | ensureMetadataNotStale(context); |
Fan Zhang | f5c1d76 | 2018-08-03 09:14:32 -0700 | [diff] [blame] | 305 | final String pkgName = context.getPackageName(); |
| 306 | // If this drawable is coming from outside Settings, tint it to match the color. |
| 307 | final ActivityInfo activityInfo = getActivityInfo(context); |
| 308 | return activityInfo != null |
| 309 | && !TextUtils.equals(pkgName, activityInfo.packageName); |
| 310 | } |
| 311 | |
Fan Zhang | 8f942a4 | 2019-03-05 17:04:06 -0800 | [diff] [blame] | 312 | /** |
| 313 | * Ensures metadata is not stale for this tile. |
| 314 | */ |
| 315 | private void ensureMetadataNotStale(Context context) { |
| 316 | final PackageManager pm = context.getApplicationContext().getPackageManager(); |
| 317 | |
| 318 | try { |
| 319 | final long lastUpdateTime = pm.getPackageInfo(mActivityPackage, |
| 320 | PackageManager.GET_META_DATA).lastUpdateTime; |
| 321 | if (lastUpdateTime == mLastUpdateTime) { |
| 322 | // All good. Do nothing |
| 323 | return; |
| 324 | } |
| 325 | // App has been updated since we load metadata last time. Reload metadata. |
| 326 | mActivityInfo = null; |
| 327 | getActivityInfo(context); |
| 328 | mLastUpdateTime = lastUpdateTime; |
| 329 | } catch (PackageManager.NameNotFoundException e) { |
| 330 | Log.d(TAG, "Can't find package, probably uninstalled."); |
| 331 | } |
| 332 | } |
| 333 | |
Fan Zhang | 0e20123 | 2018-07-26 11:26:44 -0700 | [diff] [blame] | 334 | private ActivityInfo getActivityInfo(Context context) { |
| 335 | if (mActivityInfo == null) { |
| 336 | final PackageManager pm = context.getApplicationContext().getPackageManager(); |
| 337 | final Intent intent = new Intent().setClassName(mActivityPackage, mActivityName); |
| 338 | final List<ResolveInfo> infoList = |
| 339 | pm.queryIntentActivities(intent, PackageManager.GET_META_DATA); |
| 340 | if (infoList != null && !infoList.isEmpty()) { |
| 341 | mActivityInfo = infoList.get(0).activityInfo; |
Fan Zhang | 8f942a4 | 2019-03-05 17:04:06 -0800 | [diff] [blame] | 342 | mMetaData = mActivityInfo.metaData; |
Fan Zhang | 0e20123 | 2018-07-26 11:26:44 -0700 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | return mActivityInfo; |
Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 346 | } |
| 347 | |
Jason Monk | f509d7e | 2016-01-07 16:22:53 -0500 | [diff] [blame] | 348 | public static final Creator<Tile> CREATOR = new Creator<Tile>() { |
| 349 | public Tile createFromParcel(Parcel source) { |
| 350 | return new Tile(source); |
Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 351 | } |
Fan Zhang | 83dde97 | 2018-07-23 16:51:14 -0700 | [diff] [blame] | 352 | |
Jason Monk | f509d7e | 2016-01-07 16:22:53 -0500 | [diff] [blame] | 353 | public Tile[] newArray(int size) { |
| 354 | return new Tile[size]; |
Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 355 | } |
| 356 | }; |
arangelov | 24eec2f | 2018-05-30 18:24:23 +0100 | [diff] [blame] | 357 | |
| 358 | public boolean isPrimaryProfileOnly() { |
Fan Zhang | f5c1d76 | 2018-08-03 09:14:32 -0700 | [diff] [blame] | 359 | String profile = mMetaData != null ? |
| 360 | mMetaData.getString(META_DATA_KEY_PROFILE) : PROFILE_ALL; |
arangelov | 24eec2f | 2018-05-30 18:24:23 +0100 | [diff] [blame] | 361 | profile = (profile != null ? profile : PROFILE_ALL); |
| 362 | return TextUtils.equals(profile, PROFILE_PRIMARY); |
| 363 | } |
Fan Zhang | 23baea9 | 2018-08-02 13:20:22 -0700 | [diff] [blame] | 364 | |
| 365 | public static final Comparator<Tile> TILE_COMPARATOR = |
Fan Zhang | 4c07a71 | 2018-08-06 10:04:14 -0700 | [diff] [blame] | 366 | (lhs, rhs) -> rhs.getOrder() - lhs.getOrder(); |
Jason Monk | 744b636 | 2015-11-03 18:24:29 -0500 | [diff] [blame] | 367 | } |