| 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 6113a087d19ff0c0bac3150518786db2510507af..156377047b1a67458df12d9bf853c9291e90c2df 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
|
| @@ -9,7 +9,10 @@ import android.app.AlertDialog;
|
| import android.content.Context;
|
| import android.content.ContextWrapper;
|
| 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;
|
| @@ -17,6 +20,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;
|
| @@ -93,6 +97,12 @@ public class ContentVideoView extends FrameLayout
|
|
|
| private final ContentVideoViewClient mClient;
|
|
|
| + private boolean mInitialOrientation;
|
| + private boolean mPossibleAccidentalChange;
|
| + private boolean mUmaRecorded;
|
| + private long mOrientationChangedTime;
|
| + private long mPlaybackStartTime;
|
| +
|
| private class VideoSurfaceView extends SurfaceView {
|
|
|
| public VideoSurfaceView(Context context) {
|
| @@ -114,6 +124,23 @@ public class ContentVideoView extends FrameLayout
|
| width = height * mVideoWidth / mVideoHeight;
|
| }
|
| }
|
| + if (mUmaRecorded) {
|
| + // If we have never switched orientation, record the orientation
|
| + // time.
|
| + if (mPlaybackStartTime == mOrientationChangedTime) {
|
| + if (isOrientationPortrait() != mInitialOrientation) {
|
| + mOrientationChangedTime = System.currentTimeMillis();
|
| + }
|
| + } else {
|
| + // if user quickly switched the orientation back and force, don't
|
| + // count it in UMA.
|
| + if (!mPossibleAccidentalChange &&
|
| + isOrientationPortrait() == mInitialOrientation &&
|
| + System.currentTimeMillis() - mOrientationChangedTime < 5000) {
|
| + mPossibleAccidentalChange = true;
|
| + }
|
| + }
|
| + }
|
| setMeasuredDimension(width, height);
|
| }
|
| }
|
| @@ -150,6 +177,8 @@ public class ContentVideoView extends FrameLayout
|
| mNativeContentVideoView = nativeContentVideoView;
|
| mViewAndroid = new ViewAndroid(new WindowAndroid(context.getApplicationContext()), this);
|
| mClient = client;
|
| + mUmaRecorded = false;
|
| + mPossibleAccidentalChange = false;
|
| initResources(context);
|
| mVideoSurfaceView = new VideoSurfaceView(context);
|
| showContentVideoView();
|
| @@ -276,6 +305,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
|
| @@ -414,6 +458,17 @@ public class ContentVideoView extends FrameLayout
|
| public void exitFullscreen(boolean relaseMediaPlayer) {
|
| destroyContentVideoView(false);
|
| if (mNativeContentVideoView != 0) {
|
| + if (mUmaRecorded && !mPossibleAccidentalChange) {
|
| + 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;
|
| }
|
| @@ -477,6 +532,15 @@ 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);
|
| + return outputSize.x <= outputSize.y;
|
| + }
|
| +
|
| private static native ContentVideoView nativeGetSingletonJavaContentVideoView();
|
| private native void nativeExitFullscreen(long nativeContentVideoView,
|
| boolean relaseMediaPlayer);
|
| @@ -490,4 +554,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);
|
| }
|
|
|