[Android] VideoPlayerActivity: fix lock with horizontally native tablets
Edward Wang
git at videolan.org
Sun Sep 1 14:00:02 CEST 2013
vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Sun Sep 1 13:53:30 2013 +0200| [085842afdd5c61931f7d24b3861e7b71480908cc] | committer: Edward Wang
VideoPlayerActivity: fix lock with horizontally native tablets
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=085842afdd5c61931f7d24b3861e7b71480908cc
---
.../vlc/gui/video/VideoPlayerActivity.java | 72 ++++++++++++++------
1 file changed, 53 insertions(+), 19 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 83aec5e..4c06f5d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -46,7 +46,6 @@ import org.videolan.vlc.Util;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.WeakHandler;
import org.videolan.vlc.gui.CommonDialogs;
-import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.CommonDialogs.MenuType;
import org.videolan.vlc.gui.PreferencesActivity;
import org.videolan.vlc.gui.audio.AudioPlayerFragment;
@@ -1583,24 +1582,59 @@ 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(){
+ Log.d(TAG, "getScreenOrientation() -> getScreenRotation = " + getScreenRotation());
+ 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