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

Commit 7dba1da1 authored by Himanshu Jaju's avatar Himanshu Jaju
Browse files

Refactors RotationUtils to be independent from device width.

Currently the RotationUtils class checks for the device orientation
AND the device width to figure out the current orientation. This CL
moves the device width checks to the caller class so that Util class
is free of special cases.

Test: Manual
Bug: 171918213
Change-Id: Ide67ee35394f48f3312e5ece1228e450fbdf30b4
parent 685eca70
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.recents;

import static com.android.systemui.util.leak.RotationUtils.ROTATION_LANDSCAPE;
import static com.android.systemui.util.leak.RotationUtils.ROTATION_NONE;
import static com.android.systemui.util.leak.RotationUtils.ROTATION_SEASCAPE;

import android.animation.ArgbEvaluator;
@@ -27,6 +28,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.graphics.drawable.ColorDrawable;
import android.os.Binder;
@@ -186,7 +188,7 @@ public class ScreenPinningRequest implements View.OnClickListener,
            DisplayMetrics metrics = new DisplayMetrics();
            mWindowManager.getDefaultDisplay().getMetrics(metrics);
            float density = metrics.density;
            int rotation = RotationUtils.getRotation(mContext);
            int rotation = getRotation(mContext);

            inflateView(rotation);
            int bgColor = mContext.getColor(
@@ -342,14 +344,23 @@ public class ScreenPinningRequest implements View.OnClickListener,

        protected void onConfigurationChanged() {
            removeAllViews();
            inflateView(RotationUtils.getRotation(mContext));
            inflateView(getRotation(mContext));
        }

        private int getRotation(Context context) {
            Configuration config = context.getResources().getConfiguration();
            if (config.smallestScreenWidthDp >= 600) {
                return ROTATION_NONE;
            }

            return RotationUtils.getRotation(context);
        }

        private final Runnable mUpdateLayoutRunnable = new Runnable() {
            @Override
            public void run() {
                if (mLayout != null && mLayout.getParent() != null) {
                    mLayout.setLayoutParams(getRequestLayoutParams(RotationUtils.getRotation(mContext)));
                    mLayout.setLayoutParams(getRequestLayoutParams(getRotation(mContext)));
                }
            }
        };
+14 −19
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@
package com.android.systemui.util.leak;

import android.content.Context;
import android.content.res.Configuration;
import android.view.Surface;

public class RotationUtils {
@@ -26,30 +25,26 @@ public class RotationUtils {
    public static final int ROTATION_UPSIDE_DOWN = 3;

    public static int getRotation(Context context) {
        Configuration config = context.getResources().getConfiguration();
        int rot = context.getDisplay().getRotation();
        if (config.smallestScreenWidthDp < 600) {
        if (rot == Surface.ROTATION_90) {
            return ROTATION_LANDSCAPE;
        } else if (rot == Surface.ROTATION_270) {
            return ROTATION_SEASCAPE;
            }
        }
        } else {
            return ROTATION_NONE;
        }
    }

    public static int getExactRotation(Context context) {
        Configuration config = context.getResources().getConfiguration();
        int rot = context.getDisplay().getRotation();
        if (config.smallestScreenWidthDp < 600) {
        if (rot == Surface.ROTATION_90) {
            return ROTATION_LANDSCAPE;
        } else if (rot == Surface.ROTATION_270) {
            return ROTATION_SEASCAPE;
        } else if (rot == Surface.ROTATION_180) {
            return ROTATION_UPSIDE_DOWN;
            }
        }
        } else {
            return ROTATION_NONE;
        }
    }
}