Add NEW_TASK flag to intent if metadata matches
This is a refactoring CL for the isNewTask() method. Before this CL we check isNewTask() in different places. This CL tries to simplify the logic by moving the check to where the intent is generated, so we don't have to check the condition here and there. Also did some minor refactoring. Fixes: 216026158 Test: robotest Change-Id: I3d8b4864e73fc49c83c46fc2d219b2b74c1ab5a4
This commit is contained in:
@@ -35,8 +35,7 @@ public class ActivityTile extends Tile {
|
||||
private static final String TAG = "ActivityTile";
|
||||
|
||||
public ActivityTile(ActivityInfo info, String category) {
|
||||
super(info, category);
|
||||
setMetaData(info.metaData);
|
||||
super(info, category, info.metaData);
|
||||
}
|
||||
|
||||
ActivityTile(Parcel in) {
|
||||
|
||||
@@ -43,8 +43,7 @@ public class ProviderTile extends Tile {
|
||||
private String mKey;
|
||||
|
||||
public ProviderTile(ProviderInfo info, String category, Bundle metaData) {
|
||||
super(info, category);
|
||||
setMetaData(metaData);
|
||||
super(info, category, metaData);
|
||||
mAuthority = info.authority;
|
||||
mKey = metaData.getString(META_DATA_PREFERENCE_KEYHINT);
|
||||
}
|
||||
|
||||
@@ -71,16 +71,19 @@ public abstract class Tile implements Parcelable {
|
||||
private Bundle mMetaData;
|
||||
private String mCategory;
|
||||
|
||||
public Tile(ComponentInfo info, String category) {
|
||||
public Tile(ComponentInfo info, String category, Bundle metaData) {
|
||||
mComponentInfo = info;
|
||||
mComponentPackage = mComponentInfo.packageName;
|
||||
mComponentName = mComponentInfo.name;
|
||||
mCategory = category;
|
||||
mMetaData = metaData;
|
||||
mIntent = new Intent().setClassName(mComponentPackage, mComponentName);
|
||||
if (isNewTask()) {
|
||||
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
}
|
||||
}
|
||||
|
||||
Tile(Parcel in) {
|
||||
final boolean isProviderTile = in.readBoolean();
|
||||
mComponentPackage = in.readString();
|
||||
mComponentName = in.readString();
|
||||
mIntent = new Intent().setClassName(mComponentPackage, mComponentName);
|
||||
@@ -90,6 +93,9 @@ public abstract class Tile implements Parcelable {
|
||||
}
|
||||
mCategory = in.readString();
|
||||
mMetaData = in.readBundle();
|
||||
if (isNewTask()) {
|
||||
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -332,8 +338,7 @@ public abstract class Tile implements Parcelable {
|
||||
/**
|
||||
* Whether the {@link Activity} should be launched in a separate task.
|
||||
*/
|
||||
public boolean isNewTask(Context context) {
|
||||
ensureMetadataNotStale(context);
|
||||
public boolean isNewTask() {
|
||||
if (mMetaData != null
|
||||
&& mMetaData.containsKey(META_DATA_NEW_TASK)) {
|
||||
return mMetaData.getBoolean(META_DATA_NEW_TASK);
|
||||
|
||||
Reference in New Issue
Block a user