summaryrefslogtreecommitdiff
path: root/InCallUI
diff options
context:
space:
mode:
authorTyler Gunn <tgunn@google.com>2015-05-18 09:40:31 -0700
committerTyler Gunn <tgunn@google.com>2015-05-18 10:02:14 -0700
commit48b1ef1a1c5842d0f3b4656560c538015007e9bd (patch)
tree4e07c0343adf596834057aafa2c27686807b511e /InCallUI
parent61b21efb1c4e3b2c1a4d33b6bf5eda3e528139c1 (diff)
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
Diffstat (limited to 'InCallUI')
-rw-r--r--InCallUI/src/com/android/incallui/InCallActivity.java28
-rw-r--r--InCallUI/src/com/android/incallui/InCallPresenter.java12
-rw-r--r--InCallUI/src/com/android/incallui/InCallVideoCallCallback.java2
-rw-r--r--InCallUI/src/com/android/incallui/VideoCallPresenter.java22
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
@@ -91,13 +91,6 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
};
/**
- * Determines the device orientation (portrait/lanscape).
- */
- public int getDeviceOrientation() {
- return mDeviceOrientation;
- }
-
- /**
* Defines the state of the preview surface negotiation with the telephony layer.
*/
private class PreviewSurfaceState {
@@ -947,8 +940,10 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
/**
* Handles changes to the device orientation.
- * See: {@link Configuration.ORIENTATION_LANDSCAPE}, {@link Configuration.ORIENTATION_PORTRAIT}
- * @param orientation The device orientation.
+ *
+ * @param orientation The device orientation (one of: {@link Surface#ROTATION_0},
+ * {@link Surface#ROTATION_90}, {@link Surface#ROTATION_180},
+ * {@link Surface#ROTATION_270}).
*/
@Override
public void onDeviceOrientationChanged(int orientation) {
@@ -1009,9 +1004,10 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
/**
* Sets the preview surface size based on the current device orientation.
- * See: {@link Configuration.ORIENTATION_LANDSCAPE}, {@link Configuration.ORIENTATION_PORTRAIT}
*
- * @param orientation The device orientation.
+ * @param orientation The device orientation (one of: {@link Surface#ROTATION_0},
+ * {@link Surface#ROTATION_90}, {@link Surface#ROTATION_180},
+ * {@link Surface#ROTATION_270}).
* @param aspectRatio The aspect ratio of the camera (width / height).
*/
private void setPreviewSize(int orientation, float aspectRatio) {
@@ -1023,10 +1019,12 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
int height;
int width;
- if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
+ if (orientation == Surface.ROTATION_90 || orientation == Surface.ROTATION_270) {
+ // Landscape or reverse landscape orientation.
width = (int) (mMinimumVideoDimension * aspectRatio);
height = (int) mMinimumVideoDimension;
} else {
+ // Portrait or reverse portrait orientation.
width = (int) mMinimumVideoDimension;
height = (int) (mMinimumVideoDimension * aspectRatio);
}