Code example for Surface

Methods: lockCanvasunlockCanvasAndPost

0
        final int dh = mLastDH;
 
        Rect dirty = new Rect(0, 0, dw, dh);
        Canvas c = null;
        try { 
            c = mSurface.lockCanvas(dirty);
        } catch (IllegalArgumentException e) {
        } catch (Surface.OutOfResourcesException e) {
        } 
        if (c == null) {
            return; 
        } 
 
        // Top 
        c.clipRect(new Rect(0, 0, dw, mThickness), Region.Op.REPLACE);
        c.drawColor(Color.RED);
        // Left 
        c.clipRect(new Rect(0, 0, mThickness, dh), Region.Op.REPLACE);
        c.drawColor(Color.RED);
        // Right 
        c.clipRect(new Rect(dw - mThickness, 0, dw, dh), Region.Op.REPLACE);
        c.drawColor(Color.RED);
        // Bottom 
        c.clipRect(new Rect(0, dh - mThickness, dw, dh), Region.Op.REPLACE);
        c.drawColor(Color.RED);
 
        mSurface.unlockCanvasAndPost(c);
    } 
 
    // Note: caller responsible for being inside 
    // Surface.openTransaction() / closeTransaction() 
    public void setVisibility(boolean on) {
Contextual code suggestions in your IDE  Get Codota for Java