Merge "Change unfold background color based on split screen state" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
550f35fcdb
@@ -20,6 +20,7 @@ import static android.graphics.Color.blue;
|
|||||||
import static android.graphics.Color.green;
|
import static android.graphics.Color.green;
|
||||||
import static android.graphics.Color.red;
|
import static android.graphics.Color.red;
|
||||||
|
|
||||||
|
import android.annotation.ColorRes;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.SurfaceControl;
|
import android.view.SurfaceControl;
|
||||||
@@ -33,10 +34,14 @@ public class UnfoldBackgroundController {
|
|||||||
|
|
||||||
private static final int BACKGROUND_LAYER_Z_INDEX = -1;
|
private static final int BACKGROUND_LAYER_Z_INDEX = -1;
|
||||||
private final float[] mBackgroundColor;
|
private final float[] mBackgroundColor;
|
||||||
|
private final float[] mSplitScreenBackgroundColor;
|
||||||
|
private float[] mBackgroundColorSet;
|
||||||
private SurfaceControl mBackgroundLayer;
|
private SurfaceControl mBackgroundLayer;
|
||||||
|
private boolean mSplitScreenVisible = false;
|
||||||
|
|
||||||
public UnfoldBackgroundController(@NonNull Context context) {
|
public UnfoldBackgroundController(@NonNull Context context) {
|
||||||
mBackgroundColor = getBackgroundColor(context);
|
mBackgroundColor = getRGBColorFromId(context, R.color.unfold_background);
|
||||||
|
mSplitScreenBackgroundColor = getRGBColorFromId(context, R.color.split_divider_background);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,7 +49,14 @@ public class UnfoldBackgroundController {
|
|||||||
* @param transaction where we should add the background if it is not added
|
* @param transaction where we should add the background if it is not added
|
||||||
*/
|
*/
|
||||||
public void ensureBackground(@NonNull SurfaceControl.Transaction transaction) {
|
public void ensureBackground(@NonNull SurfaceControl.Transaction transaction) {
|
||||||
if (mBackgroundLayer != null) return;
|
float[] expectedColor = getCurrentBackgroundColor();
|
||||||
|
if (mBackgroundLayer != null) {
|
||||||
|
if (mBackgroundColorSet != expectedColor) {
|
||||||
|
transaction.setColor(mBackgroundLayer, expectedColor);
|
||||||
|
mBackgroundColorSet = expectedColor;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SurfaceControl.Builder colorLayerBuilder = new SurfaceControl.Builder()
|
SurfaceControl.Builder colorLayerBuilder = new SurfaceControl.Builder()
|
||||||
.setName("app-unfold-background")
|
.setName("app-unfold-background")
|
||||||
@@ -53,9 +65,10 @@ public class UnfoldBackgroundController {
|
|||||||
mBackgroundLayer = colorLayerBuilder.build();
|
mBackgroundLayer = colorLayerBuilder.build();
|
||||||
|
|
||||||
transaction
|
transaction
|
||||||
.setColor(mBackgroundLayer, mBackgroundColor)
|
.setColor(mBackgroundLayer, expectedColor)
|
||||||
.show(mBackgroundLayer)
|
.show(mBackgroundLayer)
|
||||||
.setLayer(mBackgroundLayer, BACKGROUND_LAYER_Z_INDEX);
|
.setLayer(mBackgroundLayer, BACKGROUND_LAYER_Z_INDEX);
|
||||||
|
mBackgroundColorSet = expectedColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,8 +83,25 @@ public class UnfoldBackgroundController {
|
|||||||
mBackgroundLayer = null;
|
mBackgroundLayer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private float[] getBackgroundColor(Context context) {
|
/**
|
||||||
int colorInt = context.getResources().getColor(R.color.unfold_background);
|
* Expected to be called whenever split screen visibility changes.
|
||||||
|
*
|
||||||
|
* @param visible True when split screen is visible
|
||||||
|
*/
|
||||||
|
public void onSplitVisibilityChanged(boolean visible) {
|
||||||
|
mSplitScreenVisible = visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float[] getCurrentBackgroundColor() {
|
||||||
|
if (mSplitScreenVisible) {
|
||||||
|
return mSplitScreenBackgroundColor;
|
||||||
|
} else {
|
||||||
|
return mBackgroundColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private float[] getRGBColorFromId(Context context, @ColorRes int id) {
|
||||||
|
int colorInt = context.getResources().getColor(id);
|
||||||
return new float[]{
|
return new float[]{
|
||||||
(float) red(colorInt) / 255.0F,
|
(float) red(colorInt) / 255.0F,
|
||||||
(float) green(colorInt) / 255.0F,
|
(float) green(colorInt) / 255.0F,
|
||||||
|
|||||||
@@ -292,6 +292,11 @@ public class SplitTaskUnfoldAnimator implements UnfoldTaskAnimator,
|
|||||||
.setCornerRadius(context.mLeash, 0.0F);
|
.setCornerRadius(context.mLeash, 0.0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSplitVisibilityChanged(boolean visible) {
|
||||||
|
mUnfoldBackgroundController.onSplitVisibilityChanged(visible);
|
||||||
|
}
|
||||||
|
|
||||||
private class AnimationContext {
|
private class AnimationContext {
|
||||||
final SurfaceControl mLeash;
|
final SurfaceControl mLeash;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user