Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 48b1ef1a authored by Tyler Gunn's avatar Tyler Gunn
Browse files

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
parent 61b21efb
Loading
Loading
Loading
Loading
+25 −3
Original line number Diff line number Diff line
@@ -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 +
+9 −3
Original line number Diff line number Diff line
@@ -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) {
+1 −1
Original line number Diff line number Diff line
@@ -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;

+10 −12
Original line number Diff line number Diff line
@@ -90,13 +90,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.
     */
@@ -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);
        }