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 16:47:45 +0000
commit45a8175f3cf779ffbe8cde2018aee4d97748206d (patch)
treeb997bc6f0a8836bb9bf443c3cc94b627acf754a9 /InCallUI
parentfd640ab7b1efe30574c96a12b06627f365d0432a (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 3050dc127..ecca70f80 100644
--- a/InCallUI/src/com/android/incallui/InCallActivity.java
+++ b/InCallUI/src/com/android/incallui/InCallActivity.java
@@ -35,6 +35,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;
@@ -176,10 +177,29 @@ public class InCallActivity extends Activity {
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);
}
@@ -469,7 +489,9 @@ public class InCallActivity extends Activity {
/**
* 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 ed61d05d5..e1247d81c 100644
--- a/InCallUI/src/com/android/incallui/InCallPresenter.java
+++ b/InCallUI/src/com/android/incallui/InCallPresenter.java
@@ -1366,7 +1366,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);
@@ -1380,7 +1382,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;
@@ -1406,7 +1410,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 27df11911..db6ca2b2c 100644
--- a/InCallUI/src/com/android/incallui/VideoCallPresenter.java
+++ b/InCallUI/src/com/android/incallui/VideoCallPresenter.java
@@ -89,13 +89,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 {
@@ -991,8 +984,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) {
@@ -1053,9 +1048,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) {
@@ -1067,10 +1063,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);
}