下面列出了android.view.SurfaceControl#setLayer ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public EmulatorDisplayOverlay(Context context, DisplayContent dc,
int zOrder) {
final Display display = dc.getDisplay();
mScreenSize = new Point();
display.getSize(mScreenSize);
SurfaceControl ctrl = null;
try {
ctrl = dc.makeOverlay()
.setName("EmulatorDisplayOverlay")
.setSize(mScreenSize.x, mScreenSize.y)
.setFormat(PixelFormat.TRANSLUCENT)
.build();
ctrl.setLayer(zOrder);
ctrl.setPosition(0, 0);
ctrl.show();
mSurface.copyFrom(ctrl);
} catch (OutOfResourcesException e) {
}
mSurfaceControl = ctrl;
mDrawNeeded = true;
mOverlay = context.getDrawable(
com.android.internal.R.drawable.emulator_circular_window_overlay);
}
public StrictModeFlash(DisplayContent dc) {
SurfaceControl ctrl = null;
try {
ctrl = dc.makeOverlay()
.setName("StrictModeFlash")
.setSize(1, 1)
.setFormat(PixelFormat.TRANSLUCENT)
.build();
ctrl.setLayer(WindowManagerService.TYPE_LAYER_MULTIPLIER * 101); // one more than Watermark? arbitrary.
ctrl.setPosition(0, 0);
ctrl.show();
mSurface.copyFrom(ctrl);
} catch (OutOfResourcesException e) {
}
mSurfaceControl = ctrl;
mDrawNeeded = true;
}
@Override
public void onAnimationLeashCreated(Transaction t, SurfaceControl leash) {
// The leash is parented to the animation layer. We need to preserve the z-order by using
// the prefix order index, but we boost if necessary.
int layer = 0;
if (!inPinnedWindowingMode()) {
layer = getPrefixOrderIndex();
} else {
// Pinned stacks have animations take place within themselves rather than an animation
// layer so we need to preserve the order relative to the stack (e.g. the order of our
// task/parent).
layer = getParent().getPrefixOrderIndex();
}
if (mNeedsZBoost) {
layer += Z_BOOST_BASE;
}
leash.setLayer(layer);
final DisplayContent dc = getDisplayContent();
dc.assignStackOrdering();
if (mAnimatingAppWindowTokenRegistry != null) {
mAnimatingAppWindowTokenRegistry.notifyStarting(this);
}
}
public CircularDisplayMask(DisplayContent dc, int zOrder,
int screenOffset, int maskThickness) {
final Display display = dc.getDisplay();
mScreenSize = new Point();
display.getSize(mScreenSize);
if (mScreenSize.x != mScreenSize.y + screenOffset) {
Slog.w(TAG, "Screen dimensions of displayId = " + display.getDisplayId() +
"are not equal, circularMask will not be drawn.");
mDimensionsUnequal = true;
}
SurfaceControl ctrl = null;
try {
ctrl = dc.makeOverlay()
.setName("CircularDisplayMask")
.setSize(mScreenSize.x, mScreenSize.y) // not a typo
.setFormat(PixelFormat.TRANSLUCENT)
.build();
ctrl.setLayerStack(display.getLayerStack());
ctrl.setLayer(zOrder);
ctrl.setPosition(0, 0);
ctrl.show();
mSurface.copyFrom(ctrl);
} catch (OutOfResourcesException e) {
}
mSurfaceControl = ctrl;
mDrawNeeded = true;
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
mScreenOffset = screenOffset;
mMaskThickness = maskThickness;
}
Watermark(DisplayContent dc, DisplayMetrics dm, String[] tokens) {
if (false) {
Log.i(TAG_WM, "*********************** WATERMARK");
for (int i=0; i<tokens.length; i++) {
Log.i(TAG_WM, " TOKEN #" + i + ": " + tokens[i]);
}
}
mDisplay = dc.getDisplay();
mTokens = tokens;
StringBuilder builder = new StringBuilder(32);
int len = mTokens[0].length();
len = len & ~1;
for (int i=0; i<len; i+=2) {
int c1 = mTokens[0].charAt(i);
int c2 = mTokens[0].charAt(i+1);
if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10;
else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10;
else c1 -= '0';
if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10;
else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10;
else c2 -= '0';
builder.append((char)(255-((c1*16)+c2)));
}
mText = builder.toString();
if (false) {
Log.i(TAG_WM, "Final text: " + mText);
}
int fontSize = WindowManagerService.getPropertyInt(tokens, 1,
TypedValue.COMPLEX_UNIT_DIP, 20, dm);
mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mTextPaint.setTextSize(fontSize);
mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
FontMetricsInt fm = mTextPaint.getFontMetricsInt();
mTextWidth = (int)mTextPaint.measureText(mText);
mTextHeight = fm.descent - fm.ascent;
mDeltaX = WindowManagerService.getPropertyInt(tokens, 2,
TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm);
mDeltaY = WindowManagerService.getPropertyInt(tokens, 3,
TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm);
int shadowColor = WindowManagerService.getPropertyInt(tokens, 4,
TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm);
int color = WindowManagerService.getPropertyInt(tokens, 5,
TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm);
int shadowRadius = WindowManagerService.getPropertyInt(tokens, 6,
TypedValue.COMPLEX_UNIT_PX, 7, dm);
int shadowDx = WindowManagerService.getPropertyInt(tokens, 8,
TypedValue.COMPLEX_UNIT_PX, 0, dm);
int shadowDy = WindowManagerService.getPropertyInt(tokens, 9,
TypedValue.COMPLEX_UNIT_PX, 0, dm);
mTextPaint.setColor(color);
mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
SurfaceControl ctrl = null;
try {
ctrl = dc.makeOverlay()
.setName("WatermarkSurface")
.setSize(1, 1)
.setFormat(PixelFormat.TRANSLUCENT)
.build();
ctrl.setLayerStack(mDisplay.getLayerStack());
ctrl.setLayer(WindowManagerService.TYPE_LAYER_MULTIPLIER*100);
ctrl.setPosition(0, 0);
ctrl.show();
mSurface.copyFrom(ctrl);
} catch (OutOfResourcesException e) {
}
mSurfaceControl = ctrl;
}