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

The following are Jave code examples for showing how to use setFixedSize() 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: Android-LSS   File: StreamingActivity.java   Source Code and License Vote up 5 votes
private void fitPreviewToParentByResolution(SurfaceHolder holder, int width, int height) {
    // Adjust the size of SurfaceView dynamically
    int screenHeight = getWindow().getDecorView().getRootView().getHeight();
    int screenWidth = getWindow().getDecorView().getRootView().getWidth();
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { // If
                                                                                               // portrait,
                                                                                               // we
                                                                                               // should
                                                                                               // swap
                                                                                               // width
                                                                                               // and
                                                                                               // height
        width = width ^ height;
        height = width ^ height;
        width = width ^ height;
    }
    // Fit height
    int adjustedVideoHeight = screenHeight;
    int adjustedVideoWidth = screenWidth;
    if (width * screenHeight > height * screenWidth) { // means width/height
                                                       // >
                                                       // screenWidth/screenHeight
        // Fit width
        adjustedVideoHeight = height * screenWidth / width;
        adjustedVideoWidth = screenWidth;
    } else {
        // Fit height
        adjustedVideoHeight = screenHeight;
        adjustedVideoWidth = width * screenHeight / height;
    }
    holder.setFixedSize(adjustedVideoWidth, adjustedVideoHeight);
}
 
Example 2
Project: grafika   File: HardwareScalerActivity.java   Source Code and License Vote up 5 votes
/**
 * onClick handler for radio buttons.
 */
public void onRadioButtonClicked(View view) {
    int newSize;

    RadioButton rb = (RadioButton) view;
    if (!rb.isChecked()) {
        Log.d(TAG, "Got click on non-checked radio button");
        return;
    }

    switch (rb.getId()) {
        case R.id.surfaceSizeTiny_radio:
            newSize = SURFACE_SIZE_TINY;
            break;
        case R.id.surfaceSizeSmall_radio:
            newSize = SURFACE_SIZE_SMALL;
            break;
        case R.id.surfaceSizeMedium_radio:
            newSize = SURFACE_SIZE_MEDIUM;
            break;
        case R.id.surfaceSizeFull_radio:
            newSize = SURFACE_SIZE_FULL;
            break;
        default:
            throw new RuntimeException("Click from unknown id " + rb.getId());
    }
    mSelectedSize = newSize;

    int[] wh = mWindowWidthHeight[newSize];

    // Update the Surface size.  This causes a "surface changed" event, but does not
    // destroy and re-create the Surface.
    SurfaceView sv = (SurfaceView) findViewById(R.id.hardwareScaler_surfaceView);
    SurfaceHolder sh = sv.getHolder();
    Log.d(TAG, "setting size to " + wh[0] + "x" + wh[1]);
    sh.setFixedSize(wh[0], wh[1]);
}
 
Example 3
Project: AJCPlayer   File: VideoPlayerActivity.java   Source Code and License Vote up 5 votes
@Override
protected void onResume() {
    super.onResume();

    mChromeCast.resume();

    SurfaceHolder holder = mSurfaceView.getHolder();
    DisplayMetrics metrics = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    holder.setFixedSize(metrics.widthPixels, (int) ((float) metrics.widthPixels / (float) 16 / (float) 9));
    holder.addCallback(this);

    videoPlayer.onViewSizeChanged();
}
 
Example 4
Project: CCDownload   File: ADMediaPlayActivity.java   Source Code and License Vote up 4 votes
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
		int height) {
	holder.setFixedSize(width, height);
}
 
Example 5
Project: CCDownload   File: MediaPlayActivity.java   Source Code and License Vote up 4 votes
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
		int height) {
	holder.setFixedSize(width, height);
}