Java Code Examples for android.view.Display#getRotation()

The following examples show how to use android.view.Display#getRotation() . 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: ScannerManager.java    From attendee-checkin with Apache License 2.0 6 votes vote down vote up
private int getDisplayInfo(Point size) {
    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    if (size != null) {
        display.getSize(size);
    }
    int rotation = display.getRotation();
    switch (rotation) {
        case Surface.ROTATION_0:
            return 0;
        case Surface.ROTATION_90:
            return 90;
        case Surface.ROTATION_180:
            return 180;
        case Surface.ROTATION_270:
            return 270;
    }
    throw new RuntimeException("Unknown screen rotation: " + rotation);
}
 
Example 2
Source File: PhysicalDisplayAndroid.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
/* package */ void updateFromDisplay(Display display) {
    Point size = new Point();
    DisplayMetrics displayMetrics = new DisplayMetrics();
    PixelFormat pixelFormat = new PixelFormat();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        display.getRealSize(size);
        display.getRealMetrics(displayMetrics);
    } else {
        display.getSize(size);
        display.getMetrics(displayMetrics);
    }
    if (hasForcedDIPScale()) displayMetrics.density = sForcedDIPScale.floatValue();

    // JellyBean MR1 and later always uses RGBA_8888.
    int pixelFormatId = (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
            ? display.getPixelFormat()
            : PixelFormat.RGBA_8888;
    PixelFormat.getPixelFormatInfo(pixelFormatId, pixelFormat);
    super.update(size, displayMetrics.density, pixelFormat.bitsPerPixel,
            bitsPerComponent(pixelFormatId), display.getRotation());
}
 
Example 3
Source File: ReactOrientationControllerModule.java    From react-native-orientation-controller with MIT License 6 votes vote down vote up
/**
 * Return the application orientation
 * @return the application orientation of a Integer
 */
private int getApplicationOrientationAsNumber() {

    final Display display = ((WindowManager) getReactApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

    switch (display.getRotation()) {
        case Surface.ROTATION_0:
            return 0;
        case Surface.ROTATION_90:
            return 1;
        case Surface.ROTATION_180:
            return 2;
        case Surface.ROTATION_270:
            return 3;
    }
    return 0;
}
 
Example 4
Source File: ViewUtils.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * 画面の回転状態を取得
 * @param view
 * @return Surface.ROTATION_0, Surface.ROTATION_90, Surface.ROTATION_180, Surface.ROTATION_270のいずれか
 */
@SuppressLint("NewApi")
@Rotation
public static int getRotation(@NonNull final View view) {
	int rotation;
	if (BuildCheck.isAPI17()) {
		rotation = view.getDisplay().getRotation();
	} else {
		final Display display
			= ContextUtils.requireSystemService(view.getContext(), WindowManager.class)
				.getDefaultDisplay();
		rotation = display.getRotation();
	}
	return rotation;
}
 
Example 5
Source File: SkinNotchUtils.java    From Android-skin-support with MIT License 5 votes vote down vote up
/**
 * this method is private, because we do not need to handle tablet
 *
 * @param context
 * @return
 */
private static int getScreenRotation(Context context) {
    WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    if (w == null) {
        return Surface.ROTATION_0;
    }
    Display display = w.getDefaultDisplay();
    if (display == null) {
        return Surface.ROTATION_0;
    }

    return display.getRotation();
}
 
Example 6
Source File: MainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
private void listing16_14() {
  float[] values = new float[3];
  float[] inR = new float[9];
  float[] outR = new float[9];

  SensorManager.getRotationMatrix(inR, null,
    mAccelerometerValues,
    mMagneticFieldValues);

  // Listing 16-14: Remapping the orientation reference frame based on the natural orientation of the device
  // Determine the current orientation relative to the natural orientation
  WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
  Display display = wm.getDefaultDisplay();

  int rotation = display.getRotation();
  int x_axis = SensorManager.AXIS_X;
  int y_axis = SensorManager.AXIS_Y;

  switch (rotation) {
    case (Surface.ROTATION_0): break;
    case (Surface.ROTATION_90):
      x_axis = SensorManager.AXIS_Y;
      y_axis = SensorManager.AXIS_MINUS_X;
      break;
    case (Surface.ROTATION_180):
      y_axis = SensorManager.AXIS_MINUS_Y;
      break;
    case (Surface.ROTATION_270):
      x_axis = SensorManager.AXIS_MINUS_Y;
      y_axis = SensorManager.AXIS_X;
      break;
    default: break;
  }

  SensorManager.remapCoordinateSystem(inR, x_axis, y_axis, outR);

  // Obtain the new, remapped, orientation values.
  SensorManager.getOrientation(outR, values);
}
 
Example 7
Source File: PopupWindowManager.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("depecation")
protected static int getRotation(Display mDisplay) {		
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO)
		return mDisplay.getRotation();
	else
		return mDisplay.getOrientation();
}
 
Example 8
Source File: CameraPreview.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
public int getDisplayOrientation() {
    if (mCameraWrapper == null) {
        //If we don't have a camera set there is no orientation so return dummy value
        return 0;
    }

    Camera.CameraInfo info = new Camera.CameraInfo();
    if(mCameraWrapper.mCameraId == -1) {
        Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_BACK, info);
    } else {
        Camera.getCameraInfo(mCameraWrapper.mCameraId, info);
    }

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    int rotation = display.getRotation();
    int degrees = 0;
    switch (rotation) {
        case Surface.ROTATION_0: degrees = 0; break;
        case Surface.ROTATION_90: degrees = 90; break;
        case Surface.ROTATION_180: degrees = 180; break;
        case Surface.ROTATION_270: degrees = 270; break;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = (info.orientation + degrees) % 360;
        result = (360 - result) % 360;  // compensate the mirror
    } else {  // back-facing
        result = (info.orientation - degrees + 360) % 360;
    }
    return result;
}
 
Example 9
Source File: CameraClient.java    From RtmpPublisher with Apache License 2.0 5 votes vote down vote up
private void setParameters(Camera.Parameters params) {
    boolean isDesiredSizeFound = false;
    for (Camera.Size size : params.getSupportedPreviewSizes()) {
        if (size.width == desiredWidth && size.height == desiredHeight) {
            params.setPreviewSize(desiredWidth, desiredHeight);
            isDesiredSizeFound = true;
        }
    }

    if (!isDesiredSizeFound) {
        Camera.Size ppsfv = params.getPreferredPreviewSizeForVideo();
        if (ppsfv != null) {
            params.setPreviewSize(ppsfv.width, ppsfv.height);
        }
    }

    params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
    params.setRecordingHint(true);

    camera.setParameters(params);

    int[] fpsRange = new int[2];
    params.getPreviewFpsRange(fpsRange);

    Display display =
            ((WindowManager) context.getSystemService(WINDOW_SERVICE)).getDefaultDisplay();

    if (display.getRotation() == Surface.ROTATION_0) {
        camera.setDisplayOrientation(90);
    } else if (display.getRotation() == Surface.ROTATION_270) {
        camera.setDisplayOrientation(180);
    }
}
 
Example 10
Source File: VideoCaptureActivity.java    From VideoCamera with Apache License 2.0 5 votes vote down vote up
private void initializeRecordingUI() {
    Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    mVideoRecorder = new VideoRecorder(this, mCaptureConfiguration, mVideoFile, new CameraWrapper(new NativeCamera(), display.getRotation()),
            mVideoCaptureView.getPreviewSurfaceHolder());
    mVideoCaptureView.setRecordingButtonInterface(this);
    boolean showTimer = this.getIntent().getBooleanExtra(EXTRA_SHOW_TIMER, false);
    mVideoCaptureView.showTimer(showTimer);
    if (mVideoRecorded) {
        mVideoCaptureView.updateUIRecordingFinished(getVideoThumbnail());
    } else {
        mVideoCaptureView.updateUINotRecording();
    }
    mVideoCaptureView.showTimer(mCaptureConfiguration.getShowTimer());
}
 
Example 11
Source File: FeedsActivity.java    From rss with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks to see if the default Display in the WindowManager is rotated horizontally.
 *
 * @return true if the display is currently rotated horizontally, false otherwise.
 */
private static
boolean isDisplayHorizontal()
{
    Display display = s_windowManager.getDefaultDisplay();
    int rotation = display.getRotation();
    return Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation;
}
 
Example 12
Source File: CameraWizard.java    From OnionCamera with MIT License 5 votes vote down vote up
public void setOrientation(Display display) {
    CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraId, info);
    int rotation = display.getRotation();
    int degrees = 0;
    switch (rotation) {
        case Surface.ROTATION_0:
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
    }

    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        orientation = (info.orientation + degrees) % 360;
        orientation = (360 - orientation) % 360; // compensate the mirror
    } else { // back-facing
        orientation = (info.orientation - degrees + 360) % 360;
    }
    camera.setDisplayOrientation(orientation);
}
 
Example 13
Source File: CameraCaptureActivity.java    From mobile-ar-sensor-logger with GNU General Public License v3.0 5 votes vote down vote up
private void setLayoutAspectRatio(Size cameraPreviewSize) {
    AspectFrameLayout layout = findViewById(R.id.cameraPreview_afl);
    Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    mCameraPreviewWidth = cameraPreviewSize.getWidth();
    mCameraPreviewHeight = cameraPreviewSize.getHeight();
    if (display.getRotation() == Surface.ROTATION_0) {
        layout.setAspectRatio((double) mCameraPreviewHeight / mCameraPreviewWidth);
    } else if (display.getRotation() == Surface.ROTATION_180) {
        layout.setAspectRatio((double) mCameraPreviewHeight / mCameraPreviewWidth);
    } else {
        layout.setAspectRatio((double) mCameraPreviewWidth / mCameraPreviewHeight);
    }
}
 
Example 14
Source File: AsyncInitializationActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void checkOrientation() {
    WindowManager wm = getWindowManager();
    if (wm == null) return;

    Display display = wm.getDefaultDisplay();
    if (display == null) return;

    int oldOrientation = mCurrentOrientation;
    mCurrentOrientation = display.getRotation();

    if (oldOrientation != mCurrentOrientation) onOrientationChange(mCurrentOrientation);
}
 
Example 15
Source File: VideoFragment.java    From RPiCameraViewer with MIT License 5 votes vote down vote up
public void setControlMargins()
{
	Activity activity = getActivity();
	if (activity != null)
	{
		// get the margins accounting for the navigation and status bars
		Display display = activity.getWindowManager().getDefaultDisplay();
		float scale = getContext().getResources().getDisplayMetrics().density;
		int margin = (int)(5 * scale + 0.5f);
		int extra = Utils.getNavigationBarWidth(getContext());
		int rotation = display.getRotation();
		int leftMargin = margin;
		int rightMargin = margin;
		if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270)
		{
			leftMargin += extra;
		}
		else
		{
			rightMargin += extra;
		}
		int topMargin = margin + Utils.getStatusBarHeight(getContext());

		// set the control margins
		ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams)closeButton.getLayoutParams();
		lp.setMargins(leftMargin, topMargin, rightMargin, margin);
		lp = (ViewGroup.MarginLayoutParams)snapshotButton.getLayoutParams();
		lp.setMargins(leftMargin, margin, rightMargin, margin);
		lp = (ViewGroup.MarginLayoutParams)nameView.getLayoutParams();
		lp.setMargins(leftMargin, margin, rightMargin, margin);
	}
}
 
Example 16
Source File: CameraConfigurationManager.java    From reacteu-app with MIT License 4 votes vote down vote up
void setDesiredCameraParameters(Camera camera, boolean safeMode) {
  // Checkout screen orientation
  int rotation = context.getApplicationContext().getResources().getConfiguration().orientation;

  WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
  Display display = windowManager.getDefaultDisplay();
  int deviceSpecificRotation = display.getRotation();

  if (rotation == Configuration.ORIENTATION_PORTRAIT) {
    if (deviceSpecificRotation == Surface.ROTATION_0 || deviceSpecificRotation == Surface.ROTATION_90) {
      camera.setDisplayOrientation(90);
    } else {
      camera.setDisplayOrientation(270);
    }
  } else {
    // landscape
    if (deviceSpecificRotation == Surface.ROTATION_180 || deviceSpecificRotation == Surface.ROTATION_270) {
      camera.setDisplayOrientation(180);
    }
  }

  Camera.Parameters parameters = camera.getParameters();

  if (parameters == null) {
    Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
    return;
  }

  Log.i(TAG, "Initial camera parameters: " + parameters.flatten());

  if (safeMode) {
    Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
  }

  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

  initializeTorch(parameters, prefs, safeMode);

  String focusMode = null;
  if (prefs.getBoolean(PreferencesActivity.KEY_AUTO_FOCUS, true)) {
    if (safeMode || prefs.getBoolean(PreferencesActivity.KEY_DISABLE_CONTINUOUS_FOCUS, false)) {
      focusMode = findSettableValue(parameters.getSupportedFocusModes(),
          Camera.Parameters.FOCUS_MODE_AUTO);
    } else {
      focusMode = findSettableValue(parameters.getSupportedFocusModes(),
          "continuous-picture", // Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE in 4.0+
          "continuous-video",   // Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO in 4.0+
          Camera.Parameters.FOCUS_MODE_AUTO);
    }
  }
  // Maybe selected auto-focus but not available, so fall through here:
  if (!safeMode && focusMode == null) {
    focusMode = findSettableValue(parameters.getSupportedFocusModes(),
        Camera.Parameters.FOCUS_MODE_MACRO,
        "edof"); // Camera.Parameters.FOCUS_MODE_EDOF in 2.2+
  }
  if (focusMode != null) {
    parameters.setFocusMode(focusMode);
  }

  parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
  camera.setParameters(parameters);
}
 
Example 17
Source File: JoH.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static void lockOrientation(Activity activity) {
    Display display = activity.getWindowManager().getDefaultDisplay();
    int rotation = display.getRotation();
    int height;
    int width;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        height = display.getHeight();
        width = display.getWidth();
    } else {
        Point size = new Point();
        display.getSize(size);
        height = size.y;
        width = size.x;
    }
    switch (rotation) {
        case Surface.ROTATION_90:
            if (width > height)
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            else
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
            break;
        case Surface.ROTATION_180:
            if (height > width)
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
            else
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
            break;
        case Surface.ROTATION_270:
            if (width > height)
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
            else
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            break;
        default:
            if (height > width)
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            else
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
}
 
Example 18
Source File: ClassifierActivity.java    From tensorflow-classifier-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onPreviewSizeChosen(final Size size, final int rotation) {
  final float textSizePx = TypedValue.applyDimension(
      TypedValue.COMPLEX_UNIT_DIP, TEXT_SIZE_DIP, getResources().getDisplayMetrics());
  borderedText = new BorderedText(textSizePx);
  borderedText.setTypeface(Typeface.MONOSPACE);

  classifier =
      TensorFlowImageClassifier.create(
          getAssets(),
          MODEL_FILE,
          LABEL_FILE,
          INPUT_SIZE,
          IMAGE_MEAN,
          IMAGE_STD,
          INPUT_NAME,
          OUTPUT_NAME);

  previewWidth = size.getWidth();
  previewHeight = size.getHeight();

  final Display display = getWindowManager().getDefaultDisplay();
  final int screenOrientation = display.getRotation();

  LOGGER.i("Sensor orientation: %d, Screen orientation: %d", rotation, screenOrientation);

  sensorOrientation = rotation + screenOrientation;

  LOGGER.i("Initializing at size %dx%d", previewWidth, previewHeight);
  rgbFrameBitmap = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888);
  croppedBitmap = Bitmap.createBitmap(INPUT_SIZE, INPUT_SIZE, Config.ARGB_8888);

  frameToCropTransform = ImageUtils.getTransformationMatrix(
      previewWidth, previewHeight,
      INPUT_SIZE, INPUT_SIZE,
      sensorOrientation, MAINTAIN_ASPECT);

  cropToFrameTransform = new Matrix();
  frameToCropTransform.invert(cropToFrameTransform);

  addCallback(
      new DrawCallback() {
        @Override
        public void drawCallback(final Canvas canvas) {
          renderDebug(canvas);
        }
      });
}
 
Example 19
Source File: AdActivity.java    From mobile-sdk-android with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private static void setOrientation(Activity a, int orientation) {
    boolean isKindleFireHD = false;  // Fix an accelerometer bug with kindle fire HDs

    String device = Settings.getSettings().deviceModel.toUpperCase(Locale.US);
    String make = Settings.getSettings().deviceMake.toUpperCase(Locale.US);

    if (make.equals("AMAZON")
            && (device.equals("KFTT") || device.equals("KFJWI") || device.equals("KFJWA"))) {
        isKindleFireHD = true;
    }

    if ((a != null) && !a.isFinishing()) {
        Display d = ((WindowManager) a.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        int rotation = d.getRotation();


        if (orientation == Configuration.ORIENTATION_PORTRAIT) {
            if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
                a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

            } else {
                if (rotation == android.view.Surface.ROTATION_180) {
                    a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                } else {
                    a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
            }
        } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
                a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

            } else {
                if (isKindleFireHD) {
                    if (rotation == android.view.Surface.ROTATION_0 || rotation == android.view.Surface.ROTATION_90) {
                        a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                    } else {
                        a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

                    }

                } else {
                    if (rotation == android.view.Surface.ROTATION_0 || rotation == android.view.Surface.ROTATION_90) {
                        a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                    } else {
                        a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                    }
                }
            }
        } //endif -- orientation is PORTRAIT; else LANDSCAPE
    } //endif -- a && a
}
 
Example 20
Source File: DynamicWindowUtils.java    From dynamic-utils with Apache License 2.0 4 votes vote down vote up
/**
 * Get the current device orientation.
 *
 * @param context The context to get the resources and window service.
 *
 * @return The current activity orientation info.
 *
 * @see ActivityInfo#SCREEN_ORIENTATION_PORTRAIT
 * @see ActivityInfo#SCREEN_ORIENTATION_REVERSE_PORTRAIT
 * @see ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE
 * @see ActivityInfo#SCREEN_ORIENTATION_REVERSE_LANDSCAPE
 */
public static int getScreenOrientation(@NonNull Context context) {
    WindowManager windowManager = (WindowManager)
            context.getSystemService(Context.WINDOW_SERVICE);

    if (windowManager == null) {
        return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
    }

    Display display = windowManager.getDefaultDisplay();
    int rotation = display.getRotation();
    DisplayMetrics displayMatrix = context.getResources().getDisplayMetrics();
    float scale = displayMatrix.density;
    int width = (int) (displayMatrix.widthPixels * scale + 0.5f);
    int height = (int) (displayMatrix.heightPixels * scale + 0.5f);

    int orientation;
    if ((rotation == Surface.ROTATION_0
            || rotation == Surface.ROTATION_180) && height > width ||
            (rotation == Surface.ROTATION_90
                    || rotation == Surface.ROTATION_270) && width > height) {
        switch (rotation) {
            default:
            case Surface.ROTATION_0:
                orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
                break;
            case Surface.ROTATION_90:
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                break;
            case Surface.ROTATION_180:
                orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
                break;
            case Surface.ROTATION_270:
                orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
                break;
        }
    } else {
        switch (rotation) {
            default:
            case Surface.ROTATION_0:
                orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                break;
            case Surface.ROTATION_90:
                orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
                break;
            case Surface.ROTATION_180:
                orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
                break;
            case Surface.ROTATION_270:
                orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
                break;
        }
    }

    return orientation;
}