summaryrefslogtreecommitdiff
path: root/core/java/android/app/ActivityView.java
diff options
context:
space:
mode:
authorCharles Chen <charlesccchen@google.com>2020-09-07 17:51:18 +0800
committerCharles Chen <charlesccchen@google.com>2020-09-16 10:44:07 +0800
commit87f67a9fe9a254208047180b9a8077aa6e91573c (patch)
tree7841913c564005f5f4dcd361013c0e46d0f22b8f /core/java/android/app/ActivityView.java
parentc9b8f55133689067cd2401ccfa2f2f169123bd34 (diff)
Use Builder for ActivityView
fixes: 162901735 Test: touched tests Change-Id: I230d65d76b1bc8dfbae304b33579e7eb96d0593d
Diffstat (limited to 'core/java/android/app/ActivityView.java')
-rw-r--r--core/java/android/app/ActivityView.java122
1 files changed, 99 insertions, 23 deletions
diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java
index 3cb6293f0706..5ffea797e157 100644
--- a/core/java/android/app/ActivityView.java
+++ b/core/java/android/app/ActivityView.java
@@ -85,16 +85,9 @@ public class ActivityView extends ViewGroup implements android.window.TaskEmbedd
}
public ActivityView(Context context, AttributeSet attrs) {
- this(context, attrs, 0 /* defStyle */);
- }
-
- public ActivityView(Context context, AttributeSet attrs, int defStyle) {
- this(context, attrs, defStyle, false /*singleTaskInstance*/);
- }
-
- public ActivityView(Context context, AttributeSet attrs, int defStyle,
- boolean singleTaskInstance) {
- this(context, attrs, defStyle, singleTaskInstance, false /* usePublicVirtualDisplay */);
+ this(context, attrs, 0 /* defStyle */, false /* singleTaskInstance */,
+ false /* usePublicVirtualDisplay */,
+ false /* disableSurfaceViewBackgroundLayer */, false /* useTrustedDisplay */);
}
/**
@@ -106,21 +99,11 @@ public class ActivityView extends ViewGroup implements android.window.TaskEmbedd
@NonNull Context context, @NonNull AttributeSet attrs, int defStyle,
boolean singleTaskInstance, boolean usePublicVirtualDisplay) {
this(context, attrs, defStyle, singleTaskInstance, usePublicVirtualDisplay,
- false /* disableSurfaceViewBackgroundLayer */);
- }
-
- /** @hide */
- public ActivityView(
- @NonNull Context context, @NonNull AttributeSet attrs, int defStyle,
- boolean singleTaskInstance, boolean usePublicVirtualDisplay,
- boolean disableSurfaceViewBackgroundLayer) {
- this(context, attrs, defStyle, singleTaskInstance, usePublicVirtualDisplay,
- disableSurfaceViewBackgroundLayer, false /* useTrustedDisplay */);
+ false /* disableSurfaceViewBackgroundLayer */,
+ false /* useTrustedDisplay */);
}
- // TODO(b/162901735): Refactor ActivityView with Builder
- /** @hide */
- public ActivityView(
+ private ActivityView(
@NonNull Context context, @NonNull AttributeSet attrs, int defStyle,
boolean singleTaskInstance, boolean usePublicVirtualDisplay,
boolean disableSurfaceViewBackgroundLayer, boolean useTrustedDisplay) {
@@ -652,4 +635,97 @@ public class ActivityView extends ViewGroup implements android.window.TaskEmbedd
mCallback.onBackPressedOnTaskRoot(taskId);
}
}
+
+ /** The builder of {@link ActivityView} */
+ public static final class Builder {
+ private final Context mContext;
+ private AttributeSet mAttrs;
+ private int mDefStyle;
+ private boolean mSingleInstance;
+ private boolean mUsePublicVirtualDisplay;
+ private boolean mDisableSurfaceViewBackgroundLayer;
+ private boolean mUseTrustedDisplay;
+
+ public Builder(@NonNull Context context) {
+ mContext = context;
+ mAttrs = null;
+ mDefStyle = 0;
+ mSingleInstance = false;
+ mUsePublicVirtualDisplay = false;
+ mDisableSurfaceViewBackgroundLayer = false;
+ mUseTrustedDisplay = false;
+ }
+
+ /** Sets {@link AttributeSet} to the {@link ActivityView}. */
+ @NonNull
+ public Builder setAttributeSet(@Nullable AttributeSet attrs) {
+ mAttrs = attrs;
+ return this;
+ }
+
+ /**
+ * Sets {@code defStyle} to the {@link ActivityView}.
+ *
+ * @param defaultStyle An attribute in the current theme that contains a
+ * reference to a style resource that supplies default values for
+ * the view. Can be {@code 0} to not look for defaults.
+ */
+ @NonNull
+ public Builder setDefaultStyle(int defaultStyle) {
+ mDefStyle = defaultStyle;
+ return this;
+ }
+
+ /** Sets to {@code true} to make the {@link ActivityView} single instance. */
+ @NonNull
+ public Builder setSingleInstance(boolean singleInstance) {
+ mSingleInstance = singleInstance;
+ return this;
+ }
+
+ /**
+ * Sets to {@code true} to use public virtual display for the {@link ActivityView}.
+ * <p>
+ * Note that using a public display is not recommended as it exposes it to other
+ * applications, but it might be needed for backwards compatibility.
+ * </p>
+ */
+ @NonNull
+ public Builder setUsePublicVirtualDisplay(boolean usePublicVirtualDisplay) {
+ mUsePublicVirtualDisplay = usePublicVirtualDisplay;
+ return this;
+ }
+
+ /**
+ * Sets to {@code true} to disable {@link SurfaceView} background for the
+ * {@link ActivityView}.
+ */
+ @NonNull
+ public Builder setDisableSurfaceViewBackgroundLayer(
+ boolean disableSurfaceViewBackgroundLayer) {
+ mDisableSurfaceViewBackgroundLayer = disableSurfaceViewBackgroundLayer;
+ return this;
+ }
+
+ /**
+ * Sets to {@code true} to use trusted display for the {@link ActivityView}.
+ * <p>
+ * It enables the {@link ActivityView} to be focused without users' first touches.
+ * </p>
+ */
+ @NonNull
+ public Builder setUseTrustedDisplay(boolean useTrustedDisplay) {
+ mUseTrustedDisplay = useTrustedDisplay;
+ return this;
+ }
+
+ /** Creates an {@link ActivityView} */
+ @NonNull
+ public ActivityView build() {
+ return new ActivityView(mContext, mAttrs, mDefStyle, mSingleInstance,
+ mUsePublicVirtualDisplay, mDisableSurfaceViewBackgroundLayer,
+ mUseTrustedDisplay);
+ }
+ }
}
+