Java Code Examples for android.view.SurfaceControl#setPosition()

The following examples show how to use android.view.SurfaceControl#setPosition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmulatorDisplayOverlay.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: StrictModeFlash.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: CircularDisplayMask.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: Watermark.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
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;
}