Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(559)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/ContentVideoView.java

Issue 297773004: Add UMA to study the effect of defaulting fullscreen video to landscape mode (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removing noise if user quickly switch orientations Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/android/content_video_view.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « content/browser/android/content_video_view.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698