[Android] VideoPlayerActivity: fix lock with horizontally native tablets
Edward Wang
git at videolan.org
Sun Sep 1 14:06:14 CEST 2013
vlc-ports/android | branch: 0.1.x-bugfix | Edward Wang <edward.c.wang at compdigitec.com> | Sun Sep 1 13:53:30 2013 +0200| [93f83fa91f258e45de75e7244ca168688c59e149] | committer: Edward Wang
VideoPlayerActivity: fix lock with horizontally native tablets
(cherry picked from commit 712f9388d9aee7960a5544af24fa722fe7b0c213)
Signed-off-by: Edward Wang <edward.c.wang at compdigitec.com>
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=93f83fa91f258e45de75e7244ca168688c59e149
---
.../vlc/gui/video/VideoPlayerActivity.java | 70 +++++++++++++++-----
1 file changed, 52 insertions(+), 18 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 0a624d6..e03443b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -1557,24 +1557,58 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
}
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
- private int getScreenOrientation (){
- switch (getScreenRotation()) {
- case Surface.ROTATION_0:
- return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
- case Surface.ROTATION_90:
- return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
- case Surface.ROTATION_180:
- // SCREEN_ORIENTATION_REVERSE_PORTRAIT only available since API Level 9+
- return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO
- ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
- : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- case Surface.ROTATION_270:
- // SCREEN_ORIENTATION_REVERSE_LANDSCAPE only available since API Level 9+
- return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO
- ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
- : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- default :
- return 0;
+ private int getScreenOrientation(){
+ WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
+ Display display = wm.getDefaultDisplay();
+ int rot = getScreenRotation();
+ /*
+ * Since getRotation() returns the screen's "natural" orientation,
+ * which is not guaranteed to be SCREEN_ORIENTATION_PORTRAIT,
+ * we have to invert the SCREEN_ORIENTATION value if it is "naturally"
+ * landscape.
+ */
+ @SuppressWarnings("deprecation")
+ boolean defaultWide = display.getWidth() > display.getHeight();
+ if(rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270)
+ defaultWide = !defaultWide;
+ if(defaultWide) {
+ switch (rot) {
+ case Surface.ROTATION_0:
+ return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
+ case Surface.ROTATION_90:
+ return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+ case Surface.ROTATION_180:
+ // SCREEN_ORIENTATION_REVERSE_PORTRAIT only available since API
+ // Level 9+
+ return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
+ : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ case Surface.ROTATION_270:
+ // SCREEN_ORIENTATION_REVERSE_LANDSCAPE only available since API
+ // Level 9+
+ return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
+ : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ default:
+ return 0;
+ }
+ } else {
+ switch (rot) {
+ case Surface.ROTATION_0:
+ return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+ case Surface.ROTATION_90:
+ return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
+ case Surface.ROTATION_180:
+ // SCREEN_ORIENTATION_REVERSE_PORTRAIT only available since API
+ // Level 9+
+ return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
+ : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ case Surface.ROTATION_270:
+ // SCREEN_ORIENTATION_REVERSE_LANDSCAPE only available since API
+ // Level 9+
+ return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
+ : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ default:
+ return 0;
+ }
}
}
More information about the Android
mailing list