Merge "Add API to allow apps to update their background color programatically" into tm-dev

This commit is contained in:
Pablo Gamito
2022-03-18 21:41:03 +00:00
committed by Android (Google) Code Review
2 changed files with 141 additions and 12 deletions

View File

@@ -4532,22 +4532,36 @@ package android.app {
}
public static class ActivityManager.TaskDescription implements android.os.Parcelable {
ctor public ActivityManager.TaskDescription(String, @DrawableRes int, int);
ctor public ActivityManager.TaskDescription(String, @DrawableRes int);
ctor public ActivityManager.TaskDescription(String);
ctor public ActivityManager.TaskDescription();
ctor @Deprecated public ActivityManager.TaskDescription(String, @DrawableRes int, int);
ctor @Deprecated public ActivityManager.TaskDescription(String, @DrawableRes int);
ctor @Deprecated public ActivityManager.TaskDescription(String);
ctor @Deprecated public ActivityManager.TaskDescription();
ctor @Deprecated public ActivityManager.TaskDescription(String, android.graphics.Bitmap, int);
ctor @Deprecated public ActivityManager.TaskDescription(String, android.graphics.Bitmap);
ctor public ActivityManager.TaskDescription(android.app.ActivityManager.TaskDescription);
method public int describeContents();
method @ColorInt public int getBackgroundColor();
method @Deprecated public android.graphics.Bitmap getIcon();
method public String getLabel();
method public int getPrimaryColor();
method @ColorInt public int getNavigationBarColor();
method @ColorInt public int getPrimaryColor();
method @ColorInt public int getStatusBarColor();
method public void readFromParcel(android.os.Parcel);
method public void writeToParcel(android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.app.ActivityManager.TaskDescription> CREATOR;
}
public static final class ActivityManager.TaskDescription.Builder {
ctor public ActivityManager.TaskDescription.Builder();
method @NonNull public android.app.ActivityManager.TaskDescription build();
method @NonNull public android.app.ActivityManager.TaskDescription.Builder setBackgroundColor(@ColorInt int);
method @NonNull public android.app.ActivityManager.TaskDescription.Builder setIcon(@DrawableRes int);
method @NonNull public android.app.ActivityManager.TaskDescription.Builder setLabel(@Nullable String);
method @NonNull public android.app.ActivityManager.TaskDescription.Builder setNavigationBarColor(@ColorInt int);
method @NonNull public android.app.ActivityManager.TaskDescription.Builder setPrimaryColor(@ColorInt int);
method @NonNull public android.app.ActivityManager.TaskDescription.Builder setStatusBarColor(@ColorInt int);
}
public class ActivityOptions {
method @Nullable public android.graphics.Rect getLaunchBounds();
method public int getLaunchDisplayId();

View File

@@ -22,6 +22,7 @@ import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
import android.Manifest;
import android.annotation.ColorInt;
import android.annotation.DrawableRes;
import android.annotation.IntDef;
import android.annotation.IntRange;
@@ -1264,6 +1265,104 @@ public class ActivityManager {
private int mMinWidth;
private int mMinHeight;
/**
* Provides a convenient way to set the fields of a {@link TaskDescription} when creating a
* new instance.
*/
public static final class Builder {
/**
* Default values for the TaskDescription
*/
@Nullable
private String mLabel = null;
@DrawableRes
private int mIconRes = Resources.ID_NULL;
private int mPrimaryColor = 0;
private int mBackgroundColor = 0;
private int mStatusBarColor = 0;
private int mNavigationBarColor = 0;
/**
* Set the label to use in the TaskDescription.
* @param label A label and description of the current state of this activity.
* @return The same instance of the builder.
*/
@NonNull
public Builder setLabel(@Nullable String label) {
this.mLabel = label;
return this;
}
/**
* Set the drawable resource of the icon to use in the TaskDescription.
* @param iconRes A drawable resource of an icon that represents the current state of
* this activity.
* @return The same instance of the builder.
*/
@NonNull
public Builder setIcon(@DrawableRes int iconRes) {
this.mIconRes = iconRes;
return this;
}
/**
* Set the primary color to use in the TaskDescription.
* @param color A color to override the theme's primary color. The color must be opaque.
* @return The same instance of the builder.
*/
@NonNull
public Builder setPrimaryColor(@ColorInt int color) {
this.mPrimaryColor = color;
return this;
}
/**
* Set the background color to use in the TaskDescription.
* @param color A color to override the theme's background color. The color must be
* opaque.
* @return The same instance of the builder.
*/
@NonNull
public Builder setBackgroundColor(@ColorInt int color) {
this.mBackgroundColor = color;
return this;
}
/**
* Set the status bar color to use in the TaskDescription.
* @param color A color to override the theme's status bar color.
* @return The same instance of the builder.
*/
@NonNull
public Builder setStatusBarColor(@ColorInt int color) {
this.mStatusBarColor = color;
return this;
}
/**
* Set the navigation bar color to use in the TaskDescription.
* @param color A color to override the theme's navigation bar color.
* @return The same instance of the builder.
*/
@NonNull
public Builder setNavigationBarColor(@ColorInt int color) {
this.mNavigationBarColor = color;
return this;
}
/**
* Build the TaskDescription.
* @return the TaskDescription object.
*/
@NonNull
public TaskDescription build() {
final Icon icon = mIconRes == Resources.ID_NULL ? null :
Icon.createWithResource(ActivityThread.currentPackageName(), mIconRes);
return new TaskDescription(mLabel, icon, mPrimaryColor, mBackgroundColor,
mStatusBarColor, mNavigationBarColor, false, false, RESIZE_MODE_RESIZEABLE,
-1, -1, 0);
}
}
/**
* Creates the TaskDescription to the specified values.
@@ -1273,7 +1372,10 @@ public class ActivityManager {
* activity.
* @param colorPrimary A color to override the theme's primary color. This color must be
* opaque.
*
* @deprecated Use {@link Builder} instead.
*/
@Deprecated
public TaskDescription(String label, @DrawableRes int iconRes, int colorPrimary) {
this(label, Icon.createWithResource(ActivityThread.currentPackageName(), iconRes),
colorPrimary, 0, 0, 0, false, false, RESIZE_MODE_RESIZEABLE, -1, -1, 0);
@@ -1288,7 +1390,10 @@ public class ActivityManager {
* @param label A label and description of the current state of this activity.
* @param iconRes A drawable resource of an icon that represents the current state of this
* activity.
*
* @deprecated Use {@link Builder} instead.
*/
@Deprecated
public TaskDescription(String label, @DrawableRes int iconRes) {
this(label, Icon.createWithResource(ActivityThread.currentPackageName(), iconRes),
0, 0, 0, 0, false, false, RESIZE_MODE_RESIZEABLE, -1, -1, 0);
@@ -1298,14 +1403,20 @@ public class ActivityManager {
* Creates the TaskDescription to the specified values.
*
* @param label A label and description of the current state of this activity.
*
* @deprecated Use {@link Builder} instead.
*/
@Deprecated
public TaskDescription(String label) {
this(label, null, 0, 0, 0, 0, false, false, RESIZE_MODE_RESIZEABLE, -1, -1, 0);
}
/**
* Creates an empty TaskDescription.
*
* @deprecated Use {@link Builder} instead.
*/
@Deprecated
public TaskDescription() {
this(null, null, 0, 0, 0, 0, false, false, RESIZE_MODE_RESIZEABLE, -1, -1, 0);
}
@@ -1317,7 +1428,8 @@ public class ActivityManager {
* @param icon An icon that represents the current state of this task.
* @param colorPrimary A color to override the theme's primary color. This color must be
* opaque.
* @deprecated use TaskDescription constructor with icon resource instead
*
* @deprecated Use {@link Builder} instead.
*/
@Deprecated
public TaskDescription(String label, Bitmap icon, int colorPrimary) {
@@ -1333,7 +1445,8 @@ public class ActivityManager {
*
* @param label A label and description of the current state of this activity.
* @param icon An icon that represents the current state of this activity.
* @deprecated use TaskDescription constructor with icon resource instead
*
* @deprecated Use {@link Builder} instead.
*/
@Deprecated
public TaskDescription(String label, Bitmap icon) {
@@ -1635,15 +1748,15 @@ public class ActivityManager {
/**
* @return The color override on the theme's primary color.
*/
@ColorInt
public int getPrimaryColor() {
return mColorPrimary;
}
/**
* @return The background color.
* @hide
* @return The color override on the theme's background color.
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
@ColorInt
public int getBackgroundColor() {
return mColorBackground;
}
@@ -1657,15 +1770,17 @@ public class ActivityManager {
}
/**
* @hide
* @return The color override on the theme's status bar color.
*/
@ColorInt
public int getStatusBarColor() {
return mStatusBarColor;
}
/**
* @hide
* @return The color override on the theme's navigation bar color.
*/
@ColorInt
public int getNavigationBarColor() {
return mNavigationBarColor;
}