Index: content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java |
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java b/content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java |
index 7cd3b6ef79fa2c87017696dbe3ac97b8fa42ea6c..b0bee67b9f5ec491d73081f7ee343550165f4989 100644 |
--- a/content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java |
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java |
@@ -8,7 +8,10 @@ import android.app.Activity; |
import android.app.AlertDialog; |
import android.content.Context; |
import android.content.DialogInterface; |
+import android.graphics.Point; |
+import android.provider.Settings; |
import android.util.Log; |
+import android.view.Display; |
import android.view.Gravity; |
import android.view.KeyEvent; |
import android.view.Surface; |
@@ -16,6 +19,7 @@ import android.view.SurfaceHolder; |
import android.view.SurfaceView; |
import android.view.View; |
import android.view.ViewGroup; |
+import android.view.WindowManager; |
import android.widget.FrameLayout; |
import android.widget.LinearLayout; |
import android.widget.ProgressBar; |
@@ -92,6 +96,11 @@ public class ContentVideoView extends FrameLayout |
private final ContentVideoViewClient mClient; |
+ private boolean mInitialOrientation; |
+ private boolean mUmaRecorded; |
+ private long mOrientationChangedTime; |
+ private long mPlaybackStartTime; |
+ |
private class VideoSurfaceView extends SurfaceView { |
public VideoSurfaceView(Context context) { |
@@ -113,6 +122,11 @@ public class ContentVideoView extends FrameLayout |
width = height * mVideoWidth / mVideoHeight; |
} |
} |
+ if (mUmaRecorded && (mPlaybackStartTime == mOrientationChangedTime)) { |
+ if (isOrientationPortrait() != mInitialOrientation) { |
+ mOrientationChangedTime = System.currentTimeMillis(); |
+ } |
+ } |
setMeasuredDimension(width, height); |
} |
} |
@@ -275,6 +289,21 @@ public class ContentVideoView extends FrameLayout |
mProgressView.setVisibility(View.GONE); |
mCurrentState = isPlaying() ? STATE_PLAYING : STATE_PAUSED; |
onVideoSizeChanged(videoWidth, videoHeight); |
+ if (mUmaRecorded) return; |
+ try { |
+ if (Settings.System.getInt(getContext().getContentResolver(), |
+ Settings.System.ACCELEROMETER_ROTATION) == 0) { |
+ return; |
+ } |
+ } catch (Settings.SettingNotFoundException e) { |
+ return; |
+ } |
+ mInitialOrientation = isOrientationPortrait(); |
+ mUmaRecorded = true; |
+ mPlaybackStartTime = System.currentTimeMillis(); |
+ mOrientationChangedTime = mPlaybackStartTime; |
+ nativeRecordFullscreenPlayback( |
+ mNativeContentVideoView, videoHeight > videoWidth, mInitialOrientation); |
} |
@Override |
@@ -404,6 +433,17 @@ public class ContentVideoView extends FrameLayout |
public void exitFullscreen(boolean relaseMediaPlayer) { |
destroyContentVideoView(false); |
if (mNativeContentVideoView != 0) { |
+ if (mUmaRecorded) { |
+ long currentTime = System.currentTimeMillis(); |
+ long timeBeforeOrientationChange = mOrientationChangedTime - mPlaybackStartTime; |
+ long timeAfterOrientationChange = currentTime - mOrientationChangedTime; |
+ if (timeBeforeOrientationChange == 0) { |
+ timeBeforeOrientationChange = timeAfterOrientationChange; |
+ timeAfterOrientationChange = 0; |
+ } |
+ nativeRecordExitFullscreenPlayback(mNativeContentVideoView, mInitialOrientation, |
+ timeBeforeOrientationChange, timeAfterOrientationChange); |
+ } |
nativeExitFullscreen(mNativeContentVideoView, relaseMediaPlayer); |
mNativeContentVideoView = 0; |
} |
@@ -467,6 +507,18 @@ public class ContentVideoView extends FrameLayout |
return mViewAndroid.getNativePointer(); |
} |
+ private boolean isOrientationPortrait() { |
+ Context context = getContext(); |
+ WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
+ Display display = manager.getDefaultDisplay(); |
+ Point outputSize = new Point(0, 0); |
+ display.getSize(outputSize); |
+ if (outputSize.x > outputSize.y) { |
+ return false; |
+ } |
+ return true; |
+ } |
+ |
private static native ContentVideoView nativeGetSingletonJavaContentVideoView(); |
private native void nativeExitFullscreen(long nativeContentVideoView, |
boolean relaseMediaPlayer); |
@@ -480,4 +532,10 @@ public class ContentVideoView extends FrameLayout |
private native void nativePlay(long nativeContentVideoView); |
private native void nativeSeekTo(long nativeContentVideoView, int msec); |
private native void nativeSetSurface(long nativeContentVideoView, Surface surface); |
+ private native void nativeRecordFullscreenPlayback( |
+ long nativeContentVideoView, boolean isVideoPortrait, boolean isOrientationPortrait); |
+ private native void nativeRecordExitFullscreenPlayback( |
+ long nativeContentVideoView, boolean isOrientationPortrait, |
+ long playbackDurationBeforeOrientationChange, |
+ long playbackDurationAfterOrientationChange); |
} |