Java tutorial
//package com.java2s; //License from project: Open Source License import android.annotation.SuppressLint; import android.support.annotation.NonNull; import android.view.Surface; import android.view.WindowManager; public class Main { @SuppressLint("SwitchIntDef") public static int getRotationOffset(@NonNull WindowManager windowManager) { switch (windowManager.getDefaultDisplay().getRotation()) { case Surface.ROTATION_90: return 90; case Surface.ROTATION_180: return 180; case Surface.ROTATION_270: return 270; default: return 0; } } }