Merge "Use Builder for ActivityView"
This commit is contained in:
@@ -156,8 +156,6 @@ package android.app {
|
||||
public class ActivityView extends android.view.ViewGroup {
|
||||
ctor public ActivityView(android.content.Context);
|
||||
ctor public ActivityView(android.content.Context, android.util.AttributeSet);
|
||||
ctor public ActivityView(android.content.Context, android.util.AttributeSet, int);
|
||||
ctor public ActivityView(android.content.Context, android.util.AttributeSet, int, boolean);
|
||||
ctor public ActivityView(@NonNull android.content.Context, @NonNull android.util.AttributeSet, int, boolean, boolean);
|
||||
method public int getVirtualDisplayId();
|
||||
method public void onLayout(boolean, int, int, int, int);
|
||||
@@ -172,6 +170,17 @@ package android.app {
|
||||
method public void startActivity(@NonNull android.app.PendingIntent, @Nullable android.content.Intent, @NonNull android.app.ActivityOptions);
|
||||
}
|
||||
|
||||
public static final class ActivityView.Builder {
|
||||
ctor public ActivityView.Builder(@NonNull android.content.Context);
|
||||
method @NonNull public android.app.ActivityView build();
|
||||
method @NonNull public android.app.ActivityView.Builder setAttributeSet(@Nullable android.util.AttributeSet);
|
||||
method @NonNull public android.app.ActivityView.Builder setDefaultStyle(int);
|
||||
method @NonNull public android.app.ActivityView.Builder setDisableSurfaceViewBackgroundLayer(boolean);
|
||||
method @NonNull public android.app.ActivityView.Builder setSingleInstance(boolean);
|
||||
method @NonNull public android.app.ActivityView.Builder setUsePublicVirtualDisplay(boolean);
|
||||
method @NonNull public android.app.ActivityView.Builder setUseTrustedDisplay(boolean);
|
||||
}
|
||||
|
||||
public abstract static class ActivityView.StateCallback {
|
||||
ctor public ActivityView.StateCallback();
|
||||
method public abstract void onActivityViewDestroyed(android.app.ActivityView);
|
||||
|
||||
@@ -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 */);
|
||||
false /* disableSurfaceViewBackgroundLayer */,
|
||||
false /* useTrustedDisplay */);
|
||||
}
|
||||
|
||||
/** @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 */);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -303,9 +303,11 @@ public class BubbleExpandedView extends LinearLayout {
|
||||
R.dimen.bubble_manage_button_height);
|
||||
mSettingsIcon = findViewById(R.id.settings_button);
|
||||
|
||||
mActivityView = new ActivityView(mContext, null /* attrs */, 0 /* defStyle */,
|
||||
true /* singleTaskInstance */, false /* usePublicVirtualDisplay*/,
|
||||
true /* disableSurfaceViewBackgroundLayer */, true /* useTrustedDisplay */);
|
||||
mActivityView = new ActivityView.Builder(mContext)
|
||||
.setSingleInstance(true)
|
||||
.setDisableSurfaceViewBackgroundLayer(true)
|
||||
.setUseTrustedDisplay(true)
|
||||
.build();
|
||||
|
||||
// Set ActivityView's alpha value as zero, since there is no view content to be shown.
|
||||
setContentVisibility(false);
|
||||
|
||||
@@ -49,7 +49,7 @@ class DetailDialog(
|
||||
private const val EXTRA_USE_PANEL = "controls.DISPLAY_IN_PANEL"
|
||||
}
|
||||
|
||||
var activityView = ActivityView(context, null, 0, false)
|
||||
var activityView = ActivityView(context)
|
||||
|
||||
val stateCallback: ActivityView.StateCallback = object : ActivityView.StateCallback() {
|
||||
override fun onActivityViewReady(view: ActivityView) {
|
||||
|
||||
@@ -603,8 +603,7 @@ public class TaskStackChangedListenerTest {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mActivityView = new ActivityView(this, null /* attrs */, 0 /* defStyle */,
|
||||
true /* singleTaskInstance */);
|
||||
mActivityView = new ActivityView.Builder(this).setSingleInstance(true).build();
|
||||
setContentView(mActivityView);
|
||||
|
||||
ViewGroup.LayoutParams layoutParams = mActivityView.getLayoutParams();
|
||||
|
||||
Reference in New Issue
Block a user