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

Commit fd27966b authored by Jason Monk's avatar Jason Monk
Browse files

Update power menu + dialog

 - Update power menu to handle seascape properly
 - Update shutting down dialog, the gradient is covered by the
   global actions dialog not going away completely, everything else
   is still in ShutdownThread.

Test: visual
Change-Id: I06a2fdd2652bf006dc5c0b45e3bc922e43093301
Fixes: 62391660
parent c438e306
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2014 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center_horizontal" >

    <Space
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="6" />

    <TextView
        android:id="@id/text1"
        android:layout_width="wrap_content"
        android:layout_height="32dp"
        android:text="@string/shutdown_progress"
        android:textDirection="locale"
        android:textSize="24sp"
        android:textAppearance="?attr/textAppearanceLarge"
        android:gravity="center"
        android:layout_marginBottom="24dp"
        android:fontFamily="@string/config_headlineFontFamily"/>

    <ProgressBar
        android:id="@id/progress"
        android:layout_width="30dp"
        android:layout_height="30dp"
        style="?attr/progressBarStyleLarge" />

    <Space
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="10" />

</LinearLayout>
+1 −0
Original line number Diff line number Diff line
@@ -3058,4 +3058,5 @@
  <java-symbol type="array" name="config_batteryPackageTypeSystem" />
  <java-symbol type="array" name="config_batteryPackageTypeService" />
  <java-symbol type="bool" name="config_showAreaUpdateInfoSettings" />
  <java-symbol type="layout" name="shutdown_dialog" />
</resources>
+71 −22
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.Configuration;
import android.provider.Settings;
import android.util.AttributeSet;
import android.view.Gravity;
@@ -28,9 +29,15 @@ import android.view.ViewOutlineProvider;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerService.Tunable;
import com.android.systemui.util.leak.RotationUtils;

import java.util.ArrayList;

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;

public class HardwareUiLayout extends FrameLayout implements Tunable {

@@ -49,7 +56,7 @@ public class HardwareUiLayout extends FrameLayout implements Tunable {
    private int mEndPoint;
    private boolean mEdgeBleed;
    private boolean mRoundedDivider;
    private boolean mLandscape;
    private int mRotation = ROTATION_NONE;
    private boolean mRotatedBackground;

    public HardwareUiLayout(Context context, AttributeSet attrs) {
@@ -93,8 +100,10 @@ public class HardwareUiLayout extends FrameLayout implements Tunable {
    private void updateEdgeMargin(int edge) {
        if (mChild != null) {
            MarginLayoutParams params = (MarginLayoutParams) mChild.getLayoutParams();
            if (mLandscape) {
            if (mRotation == ROTATION_LANDSCAPE) {
                params.topMargin = edge;
            } else if (mRotation == ROTATION_SEASCAPE) {
                params.bottomMargin = edge;
            } else {
                params.rightMargin = edge;
            }
@@ -118,6 +127,7 @@ public class HardwareUiLayout extends FrameLayout implements Tunable {
                mChild.addOnLayoutChangeListener(
                        (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) ->
                                updatePosition());
                updateRotation();
            } else {
                return;
            }
@@ -127,30 +137,69 @@ public class HardwareUiLayout extends FrameLayout implements Tunable {
            animateChild(mOldHeight, newHeight);
        }
        post(() -> updatePosition());
        boolean landscape = getMeasuredWidth() > getMeasuredHeight();
        if (landscape != mLandscape) {
            mLandscape = landscape;
            if (mLandscape) {
                toLandscape();
    }

    @Override
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        updateRotation();
    }

    private void updateRotation() {
        int rotation = RotationUtils.getRotation(getContext());
        if (rotation != mRotation) {
            rotate(mRotation, rotation);
            mRotation = rotation;
        }
    }

    private void rotate(int from, int to) {
        if (from != ROTATION_NONE && to != ROTATION_NONE) {
            // Rather than handling this confusing case, just do 2 rotations.
            rotate(from, ROTATION_NONE);
            rotate(ROTATION_NONE, to);
            return;
        }
        if (from == ROTATION_LANDSCAPE || to == ROTATION_SEASCAPE) {
            rotateRight();
        } else {
            rotateLeft();
        }
        if (to != ROTATION_NONE) {
            if (mChild instanceof LinearLayout) {
                mRotatedBackground = true;
                mBackground.setRotatedBackground(true);
                    ((LinearLayout) mChild).setOrientation(LinearLayout.HORIZONTAL);
                    swapDimens(mChild);
                LinearLayout linearLayout = (LinearLayout) mChild;
                if (to == ROTATION_SEASCAPE) {
                    swapOrder(linearLayout);
                }
                linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                swapDimens(this.mChild);
            }
        } else {
                fromLandscape();
            if (mChild instanceof LinearLayout) {
                mRotatedBackground = false;
                mBackground.setRotatedBackground(false);
                    ((LinearLayout) mChild).setOrientation(LinearLayout.VERTICAL);
                LinearLayout linearLayout = (LinearLayout) mChild;
                if (from == ROTATION_SEASCAPE) {
                    swapOrder(linearLayout);
                }
                linearLayout.setOrientation(LinearLayout.VERTICAL);
                swapDimens(mChild);
            }
        }
    }

    private void swapOrder(LinearLayout linearLayout) {
        ArrayList<View> children = new ArrayList<>();
        for (int i = 0; i < linearLayout.getChildCount(); i++) {
            children.add(0, linearLayout.getChildAt(i));
            linearLayout.removeViewAt(i);
        }
        children.forEach(v -> linearLayout.addView(v));
    }

    private void fromLandscape() {
    private void rotateRight() {
        rotateRight(this);
        rotateRight(mChild);
        swapDimens(this);
@@ -202,7 +251,7 @@ public class HardwareUiLayout extends FrameLayout implements Tunable {
        return retGravity;
    }

    private void toLandscape() {
    private void rotateLeft() {
        rotateLeft(this);
        rotateLeft(mChild);
        swapDimens(this);
+17 −2
Original line number Diff line number Diff line
@@ -682,10 +682,14 @@ class GlobalActionsDialog implements DialogInterface.OnDismissListener, DialogIn

    /** {@inheritDoc} */
    public void onClick(DialogInterface dialog, int which) {
        if (!(mAdapter.getItem(which) instanceof SilentModeTriStateAction)) {
        Action item = mAdapter.getItem(which);
        if ((item instanceof PowerAction)
                || (item instanceof RestartAction)) {
            if (mDialog != null) mDialog.fadeOut();
        } else if (!(item instanceof SilentModeTriStateAction)) {
            dialog.dismiss();
        }
        mAdapter.getItem(which).onPress();
        item.onPress();
    }

    /**
@@ -1321,6 +1325,17 @@ class GlobalActionsDialog implements DialogInterface.OnDismissListener, DialogIn
                    .start();
        }

        public void fadeOut() {
            mHardwareLayout.setTranslationX(0);
            mHardwareLayout.setAlpha(1);
            mListView.animate()
                    .alpha(0)
                    .translationX(getAnimTranslation())
                    .setDuration(300)
                    .setInterpolator(new LogAccelerateInterpolator())
                    .start();
        }

        private float getAnimTranslation() {
            return getContext().getResources().getDimension(
                    com.android.systemui.R.dimen.global_actions_panel_width) / 2;
+7 −20
Original line number Diff line number Diff line
@@ -43,14 +43,14 @@ import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.systemui.R;
import com.android.systemui.util.leak.RotationUtils;

import java.util.ArrayList;

public class ScreenPinningRequest implements View.OnClickListener {
import static com.android.systemui.util.leak.RotationUtils.ROTATION_LANDSCAPE;
import static com.android.systemui.util.leak.RotationUtils.ROTATION_SEASCAPE;

    private static final int ROTATION_NONE = 0;
    private static final int ROTATION_LANDSCAPE = 1;
    private static final int ROTATION_SEASCAPE = 2;
public class ScreenPinningRequest implements View.OnClickListener {

    private final Context mContext;

@@ -160,7 +160,7 @@ public class ScreenPinningRequest implements View.OnClickListener {
            DisplayMetrics metrics = new DisplayMetrics();
            mWindowManager.getDefaultDisplay().getMetrics(metrics);
            float density = metrics.density;
            int rotation = getRotation(mContext);
            int rotation = RotationUtils.getRotation(mContext);

            inflateView(rotation);
            int bgColor = mContext.getColor(
@@ -202,19 +202,6 @@ public class ScreenPinningRequest implements View.OnClickListener {
            mContext.registerReceiver(mReceiver, filter);
        }

        private int getRotation(Context context) {
            Configuration config = mContext.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;
                }
            }
            return ROTATION_NONE;
        }

        private void inflateView(int rotation) {
            // We only want this landscape orientation on <600dp, so rather than handle
            // resource overlay for -land and -sw600dp-land, just inflate this
@@ -287,14 +274,14 @@ public class ScreenPinningRequest implements View.OnClickListener {

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

        private final Runnable mUpdateLayoutRunnable = new Runnable() {
            @Override
            public void run() {
                if (mLayout != null && mLayout.getParent() != null) {
                    mLayout.setLayoutParams(getRequestLayoutParams(getRotation(mContext)));
                    mLayout.setLayoutParams(getRequestLayoutParams(RotationUtils.getRotation(mContext)));
                }
            }
        };
Loading