| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.wm.shell.unfold; |
| 18 |
|
| 19 |
import static android.graphics.Color.blue; |
| 20 |
import static android.graphics.Color.green; |
| 21 |
import static android.graphics.Color.red; |
| 22 |
import static android.view.Display.DEFAULT_DISPLAY; |
| 23 |
|
| 24 |
import android.annotation.NonNull; |
| 25 |
import android.content.Context; |
| 26 |
import android.view.SurfaceControl; |
| 27 |
|
| 28 |
import com.android.wm.shell.R; |
| 29 |
import com.android.wm.shell.RootTaskDisplayAreaOrganizer; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public class UnfoldBackgroundController { |
| 35 |
|
| 36 |
private static final int BACKGROUND_LAYER_Z_INDEX = -1; |
| 37 |
|
| 38 |
private final RootTaskDisplayAreaOrganizer mRootTaskDisplayAreaOrganizer; |
| 39 |
private final float[] mBackgroundColor; |
| 40 |
private SurfaceControl mBackgroundLayer; |
| 41 |
|
| 42 |
public UnfoldBackgroundController( |
| 43 |
@NonNull Context context, |
| 44 |
@NonNull RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer) { |
| 45 |
mRootTaskDisplayAreaOrganizer = rootTaskDisplayAreaOrganizer; |
| 46 |
mBackgroundColor = getBackgroundColor(context); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public void ensureBackground(@NonNull SurfaceControl.Transaction transaction) { |
| 54 |
if (mBackgroundLayer != null) return; |
| 55 |
|
| 56 |
SurfaceControl.Builder colorLayerBuilder = new SurfaceControl.Builder() |
| 57 |
.setName("app-unfold-background") |
| 58 |
.setCallsite("AppUnfoldTransitionController") |
| 59 |
.setColorLayer(); |
| 60 |
mRootTaskDisplayAreaOrganizer.attachToDisplayArea(DEFAULT_DISPLAY, colorLayerBuilder); |
| 61 |
mBackgroundLayer = colorLayerBuilder.build(); |
| 62 |
|
| 63 |
transaction |
| 64 |
.setColor(mBackgroundLayer, mBackgroundColor) |
| 65 |
.show(mBackgroundLayer) |
| 66 |
.setLayer(mBackgroundLayer, BACKGROUND_LAYER_Z_INDEX); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public void removeBackground(@NonNull SurfaceControl.Transaction transaction) { |
| 74 |
if (mBackgroundLayer == null) return; |
| 75 |
if (mBackgroundLayer.isValid()) { |
| 76 |
transaction.remove(mBackgroundLayer); |
| 77 |
} |
| 78 |
mBackgroundLayer = null; |
| 79 |
} |
| 80 |
|
| 81 |
private float[] getBackgroundColor(Context context) { |
| 82 |
int colorInt = context.getResources().getColor(R.color.taskbar_background); |
| 83 |
return new float[]{ |
| 84 |
(float) red(colorInt) / 255.0F, |
| 85 |
(float) green(colorInt) / 255.0F, |
| 86 |
(float) blue(colorInt) / 255.0F |
| 87 |
}; |
| 88 |
} |
| 89 |
} |