From 48b1ef1a1c5842d0f3b4656560c538015007e9bd Mon Sep 17 00:00:00 2001 From: Tyler Gunn Date: Mon, 18 May 2015 09:40:31 -0700 Subject: Remove reliance on getDefaultDisplay() to determine screen rotation. Replaced the calls to getWindowManager().getDefaultDisplay() with code to determine the screen rotation angle based on the angle ranges. Bug: 21208380 Change-Id: Ie91d38f9c0b4227bb2148a193c00339b5d8f4ce6 --- .../src/com/android/incallui/InCallActivity.java | 28 +++++++++++++++++++--- .../src/com/android/incallui/InCallPresenter.java | 12 +++++++--- .../android/incallui/InCallVideoCallCallback.java | 2 +- .../com/android/incallui/VideoCallPresenter.java | 22 ++++++++--------- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/InCallUI/src/com/android/incallui/InCallActivity.java b/InCallUI/src/com/android/incallui/InCallActivity.java index 289bf6388..d1bebe738 100644 --- a/InCallUI/src/com/android/incallui/InCallActivity.java +++ b/InCallUI/src/com/android/incallui/InCallActivity.java @@ -39,6 +39,7 @@ import android.text.TextUtils; import android.view.Display; import android.view.MenuItem; import android.view.OrientationEventListener; +import android.view.Surface; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.view.KeyEvent; @@ -203,10 +204,29 @@ public class InCallActivity extends Activity implements FragmentDisplayManager { SensorManager.SENSOR_DELAY_NORMAL) { @Override public void onOrientationChanged(int orientation) { + // Device is flat, don't change orientation. + if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) { + return; + } + + int newRotation = Surface.ROTATION_0; + // We only shift if we're within 22.5 (23) degrees of the target + // orientation. This avoids flopping back and forth when holding + // the device at 45 degrees or so. + if (orientation >= 337 || orientation <= 23) { + newRotation = Surface.ROTATION_0; + } else if (orientation >= 67 && orientation <= 113) { + // Why not 90? Because screen and sensor orientation are + // reversed. + newRotation = Surface.ROTATION_270; + } else if (orientation >= 157 && orientation <= 203) { + newRotation = Surface.ROTATION_180; + } else if (orientation >= 247 && orientation <= 293) { + newRotation = Surface.ROTATION_90; + } + // Orientation is the current device orientation in degrees. Ultimately we want // the rotation (in fixed 90 degree intervals). - Display display = getWindowManager().getDefaultDisplay(); - int newRotation = display.getRotation(); if (newRotation != sPreviousRotation) { doOrientationChanged(newRotation); } @@ -500,7 +520,9 @@ public class InCallActivity extends Activity implements FragmentDisplayManager { /** * Handles changes in device rotation. * - * @param rotation The new device rotation. + * @param rotation The new device rotation (one of: {@link Surface#ROTATION_0}, + * {@link Surface#ROTATION_90}, {@link Surface#ROTATION_180}, + * {@link Surface#ROTATION_270}). */ private void doOrientationChanged(int rotation) { Log.d(this, "doOrientationChanged prevOrientation=" + sPreviousRotation + diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java index 022651cfc..18b268654 100644 --- a/InCallUI/src/com/android/incallui/InCallPresenter.java +++ b/InCallUI/src/com/android/incallui/InCallPresenter.java @@ -1339,7 +1339,9 @@ public class InCallPresenter implements CallList.Listener, /** * Handles changes to the device rotation. * - * @param rotation The device rotation. + * @param rotation The device rotation (one of: {@link Surface#ROTATION_0}, + * {@link Surface#ROTATION_90}, {@link Surface#ROTATION_180}, + * {@link Surface#ROTATION_270}). */ public void onDeviceRotationChange(int rotation) { Log.d(this, "onDeviceRotationChange: rotation=" + rotation); @@ -1353,7 +1355,9 @@ public class InCallPresenter implements CallList.Listener, /** * Converts rotation constants to rotation in degrees. - * @param rotation Rotation constants. + * @param rotation Rotation constants (one of: {@link Surface#ROTATION_0}, + * {@link Surface#ROTATION_90}, {@link Surface#ROTATION_180}, + * {@link Surface#ROTATION_270}). */ public static int toRotationAngle(int rotation) { int rotationAngle; @@ -1379,7 +1383,9 @@ public class InCallPresenter implements CallList.Listener, /** * Notifies listeners of changes in orientation (e.g. portrait/landscape). * - * @param orientation The orientation of the device. + * @param orientation The orientation of the device (one of: {@link Surface#ROTATION_0}, + * {@link Surface#ROTATION_90}, {@link Surface#ROTATION_180}, + * {@link Surface#ROTATION_270}). */ public void onDeviceOrientationChange(int orientation) { for (InCallOrientationListener listener : mOrientationListeners) { diff --git a/InCallUI/src/com/android/incallui/InCallVideoCallCallback.java b/InCallUI/src/com/android/incallui/InCallVideoCallCallback.java index a35404a76..87b886d81 100644 --- a/InCallUI/src/com/android/incallui/InCallVideoCallCallback.java +++ b/InCallUI/src/com/android/incallui/InCallVideoCallCallback.java @@ -28,7 +28,7 @@ import android.telecom.VideoProfile.CameraCapabilities; public class InCallVideoCallCallback extends VideoCall.Callback { /** - * The call associated with this {@link InCallVideoClient}. + * The call associated with this {@link InCallVideoCallCallback}. */ private Call mCall; diff --git a/InCallUI/src/com/android/incallui/VideoCallPresenter.java b/InCallUI/src/com/android/incallui/VideoCallPresenter.java index ed7edf93c..20f3912b4 100644 --- a/InCallUI/src/com/android/incallui/VideoCallPresenter.java +++ b/InCallUI/src/com/android/incallui/VideoCallPresenter.java @@ -90,13 +90,6 @@ public class VideoCallPresenter extends Presenter