Java Code Examples for android.view.SurfaceHolder.getSurfaceFrame()

The following are Jave code examples for showing how to use getSurfaceFrame() of the android.view.SurfaceHolder class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: buildAPKsSamples   File: CubeWallpaper2.java   Source Code and License Vote up 6 votes
void drawFrame() {
    final SurfaceHolder holder = getSurfaceHolder();
    final Rect frame = holder.getSurfaceFrame();
    final int width = frame.width();
    final int height = frame.height();

    Canvas c = null;
    try {
        c = holder.lockCanvas();
        if (c != null) {
            // draw something
            drawCube(c);
            drawTouchPoint(c);
        }
    } finally {
        if (c != null) holder.unlockCanvasAndPost(c);
    }

    mHandler.removeCallbacks(mDrawCube);
    if (mVisible) {
        mHandler.postDelayed(mDrawCube, 1000 / 25);
    }
}
 
Example 2
Project: grafika   File: HardwareScalerActivity.java   Source Code and License Vote up 4 votes
@Override
public void surfaceCreated(SurfaceHolder holder) {
    Log.d(TAG, "surfaceCreated holder=" + holder);

    // Grab the view's width.  It's not available before now.
    Rect size = holder.getSurfaceFrame();
    mFullViewWidth = size.width();
    mFullViewHeight = size.height();

    // Configure our fixed-size values.  We want to configure it so that the narrowest
    // dimension (e.g. width when device is in portrait orientation) is equal to the
    // value in SURFACE_DIM, and the other dimension is sized to maintain the same
    // aspect ratio.
    float windowAspect = (float) mFullViewHeight / (float) mFullViewWidth;
    for (int i = 0; i < SURFACE_DIM.length; i++) {
        if (i == SURFACE_SIZE_FULL) {
            // special-case for full size
            mWindowWidthHeight[i][0] = mFullViewWidth;
            mWindowWidthHeight[i][1] = mFullViewHeight;
        } else if (mFullViewWidth < mFullViewHeight) {
            // portrait
            mWindowWidthHeight[i][0] = SURFACE_DIM[i];
            mWindowWidthHeight[i][1] = (int) (SURFACE_DIM[i] * windowAspect);
        } else {
            // landscape
            mWindowWidthHeight[i][0] = (int) (SURFACE_DIM[i] / windowAspect);
            mWindowWidthHeight[i][1] = SURFACE_DIM[i];
        }
    }

    // Some controls include text based on the view dimensions, so update now.
    updateControls();

    SurfaceView sv = (SurfaceView) findViewById(R.id.hardwareScaler_surfaceView);
    mRenderThread = new RenderThread(sv.getHolder());
    mRenderThread.setName("HardwareScaler GL render");
    mRenderThread.start();
    mRenderThread.waitUntilReady();

    RenderHandler rh = mRenderThread.getHandler();
    if (rh != null) {
        rh.sendSetFlatShading(mFlatShadingChecked);
        rh.sendSurfaceCreated();
    }

    // start the draw events
    Choreographer.getInstance().postFrameCallback(this);
}