0

I have some code that will run when the orientation changes:

@Override
public void onConfigurationChanged(Configuration newConfig){
    super.onConfigurationChanged(newConfig);
    setVideoSize();
    _videoSurfaceView.changeCameraDisplaySize();
}

private void setVideoSize() {
    //Get the dimensions of the video
    int videoWidth = _videoSurfaceView.getCamera().getParameters().getPreferredPreviewSizeForVideo().width;
    int videoHeight = _videoSurfaceView.getCamera().getParameters().getPreferredPreviewSizeForVideo().height;
    float videoProportion = (float) videoWidth / (float) videoHeight;

    // Get the width of the screen
    int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
    int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
    float screenProportion = (float) screenWidth / (float) screenHeight;

    // Get the SurfaceView layout parameters
    android.view.ViewGroup.LayoutParams lp = _videoSurfaceView.getLayoutParams();
    if (videoProportion > screenProportion) {
        lp.width = screenWidth;
        lp.height = (int) ((float) screenWidth / videoProportion);
    } else {
        lp.width = (int) (videoProportion * (float) screenHeight);
        lp.height = screenHeight;
    }
    // Commit the layout parameters
    _videoSurfaceView.setLayoutParams(lp);
}

This is called when a rotation occurs, but I need to run setVideoSize() after the rotation is complete. Is there a way to do this?

Community
  • 1
  • 1
Soatl
  • 10,224
  • 28
  • 95
  • 153

1 Answers1

0

Instead try running your method in onResume(). Which is called when activity is resumed from a paused state.

Note that when you change your orientation activity gets re-created thus onResume() will be called also.

Simas
  • 43,548
  • 10
  • 88
  • 116