am 576a0d14: Merge "Fix circular mask" into klp-modular-dev
* commit '576a0d14e19dae9fa6aa50e0bb836a1da793ef21': Fix circular mask
This commit is contained in:
@@ -21,6 +21,7 @@ import android.graphics.Canvas;
|
|||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
@@ -32,6 +33,10 @@ class CircularDisplayMask {
|
|||||||
private static final String TAG = "CircularDisplayMask";
|
private static final String TAG = "CircularDisplayMask";
|
||||||
|
|
||||||
private static final int STROKE_WIDTH = 2;
|
private static final int STROKE_WIDTH = 2;
|
||||||
|
// half the screen size
|
||||||
|
private static final int CIRCLE_RADIUS = 160;
|
||||||
|
// size of the chin
|
||||||
|
private static final int SCREEN_OFFSET = 30;
|
||||||
|
|
||||||
private final SurfaceControl mSurfaceControl;
|
private final SurfaceControl mSurfaceControl;
|
||||||
private final Surface mSurface = new Surface();
|
private final Surface mSurface = new Surface();
|
||||||
@@ -40,12 +45,13 @@ class CircularDisplayMask {
|
|||||||
private boolean mDrawNeeded;
|
private boolean mDrawNeeded;
|
||||||
private Paint mPaint;
|
private Paint mPaint;
|
||||||
private int mRotation;
|
private int mRotation;
|
||||||
|
private boolean mVisible;
|
||||||
|
|
||||||
public CircularDisplayMask(Display display, SurfaceSession session, int zOrder) {
|
public CircularDisplayMask(Display display, SurfaceSession session, int zOrder) {
|
||||||
SurfaceControl ctrl = null;
|
SurfaceControl ctrl = null;
|
||||||
try {
|
try {
|
||||||
ctrl = new SurfaceControl(session, "CircularDisplayMask",
|
ctrl = new SurfaceControl(session, "CircularDisplayMask",
|
||||||
320, 290, PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
|
320, 320, PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
|
||||||
ctrl.setLayerStack(display.getLayerStack());
|
ctrl.setLayerStack(display.getLayerStack());
|
||||||
ctrl.setLayer(zOrder);
|
ctrl.setLayer(zOrder);
|
||||||
ctrl.setPosition(0, 0);
|
ctrl.setPosition(0, 0);
|
||||||
@@ -63,12 +69,12 @@ class CircularDisplayMask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void drawIfNeeded() {
|
private void drawIfNeeded() {
|
||||||
if (!mDrawNeeded) {
|
if (!mDrawNeeded || !mVisible) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mDrawNeeded = false;
|
mDrawNeeded = false;
|
||||||
|
|
||||||
Rect dirty = new Rect(0, 0, mLastDW, mLastDH);
|
Rect dirty = new Rect(0, 0, 320, 320);
|
||||||
Canvas c = null;
|
Canvas c = null;
|
||||||
try {
|
try {
|
||||||
c = mSurface.lockCanvas(dirty);
|
c = mSurface.lockCanvas(dirty);
|
||||||
@@ -78,27 +84,23 @@ class CircularDisplayMask {
|
|||||||
if (c == null) {
|
if (c == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int cx = 160;
|
c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.SRC);
|
||||||
int cy = 160;
|
|
||||||
switch (mRotation) {
|
switch (mRotation) {
|
||||||
case Surface.ROTATION_0:
|
case Surface.ROTATION_0:
|
||||||
case Surface.ROTATION_90:
|
case Surface.ROTATION_90:
|
||||||
// chin bottom or right
|
// chin bottom or right
|
||||||
cx = 160;
|
mSurfaceControl.setPosition(0, 0);
|
||||||
cy = 160;
|
break;
|
||||||
break;
|
case Surface.ROTATION_180:
|
||||||
case Surface.ROTATION_180:
|
// chin top
|
||||||
// chin top
|
mSurfaceControl.setPosition(0, -SCREEN_OFFSET);
|
||||||
cx = 160;
|
break;
|
||||||
cy = 145;
|
case Surface.ROTATION_270:
|
||||||
break;
|
// chin left
|
||||||
case Surface.ROTATION_270:
|
mSurfaceControl.setPosition(-SCREEN_OFFSET, 0);
|
||||||
cx = 145;
|
break;
|
||||||
cy = 160;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
c.drawCircle(cx, cy, 160, mPaint);
|
c.drawCircle(CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS, mPaint);
|
||||||
|
|
||||||
mSurface.unlockCanvasAndPost(c);
|
mSurface.unlockCanvasAndPost(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +110,7 @@ class CircularDisplayMask {
|
|||||||
if (mSurfaceControl == null) {
|
if (mSurfaceControl == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
mVisible = on;
|
||||||
drawIfNeeded();
|
drawIfNeeded();
|
||||||
if (on) {
|
if (on) {
|
||||||
mSurfaceControl.show();
|
mSurfaceControl.show();
|
||||||
@@ -117,14 +120,14 @@ class CircularDisplayMask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void positionSurface(int dw, int dh, int rotation) {
|
void positionSurface(int dw, int dh, int rotation) {
|
||||||
if (mLastDW == dw && mLastDH == dh) {
|
if (mLastDW == dw && mLastDH == dh && mRotation == rotation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mLastDW = dw;
|
mLastDW = dw;
|
||||||
mLastDH = dh;
|
mLastDH = dh;
|
||||||
mSurfaceControl.setSize(dw, dh);
|
|
||||||
mDrawNeeded = true;
|
mDrawNeeded = true;
|
||||||
mRotation = rotation;
|
mRotation = rotation;
|
||||||
|
drawIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user