OSDN Git Service

Fix Global Actions animations, and use old power menu when panel is disabled.
authorAaron Heuckroth <nesciosquid@google.com>
Tue, 2 Apr 2019 18:21:57 +0000 (14:21 -0400)
committerAaron Heuckroth <nesciosquid@google.com>
Wed, 3 Apr 2019 20:33:55 +0000 (16:33 -0400)
Also tweak feature flags setup to use old flag as a force option for debugging.

Test: Automated tests pass. Long-press power menu without plugin installed from different device orientations -- menu should animate in from the closest screen edge in all orientations and rotate correctly when device is rotated. Repeat after enabling the settings_global_actions_force_grid_enabled option in Feature Flags to ensure the correct behavior persists when using the new grid layout.

Fixes: 126444760
Fixes: 129698948

Change-Id: I9ac387244a5904f832c5d8b6c40362c00c6a22a2

core/java/android/util/FeatureFlagUtils.java
packages/SystemUI/src/com/android/systemui/HardwareUiLayout.java
packages/SystemUI/src/com/android/systemui/MultiListLayout.java
packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsGridLayout.java
packages/SystemUI/src/com/android/systemui/globalactions/ListGridLayout.java

index da6ef4c..6db4bf3 100644 (file)
@@ -38,7 +38,8 @@ public class FeatureFlagUtils {
     public static final String HEARING_AID_SETTINGS = "settings_bluetooth_hearing_aid";
     public static final String SAFETY_HUB = "settings_safety_hub";
     public static final String SCREENRECORD_LONG_PRESS = "settings_screenrecord_long_press";
-    public static final String GLOBAL_ACTIONS_GRID_ENABLED = "settings_global_actions_grid_enabled";
+    public static final String FORCE_GLOBAL_ACTIONS_GRID_ENABLED =
+            "settings_global_actions_force_grid_enabled";
     public static final String GLOBAL_ACTIONS_PANEL_ENABLED =
             "settings_global_actions_panel_enabled";
 
@@ -57,7 +58,7 @@ public class FeatureFlagUtils {
         DEFAULT_FLAGS.put(HEARING_AID_SETTINGS, "false");
         DEFAULT_FLAGS.put(SAFETY_HUB, "false");
         DEFAULT_FLAGS.put(SCREENRECORD_LONG_PRESS, "false");
-        DEFAULT_FLAGS.put(GLOBAL_ACTIONS_GRID_ENABLED, "true");
+        DEFAULT_FLAGS.put(FORCE_GLOBAL_ACTIONS_GRID_ENABLED, "false");
         DEFAULT_FLAGS.put(GLOBAL_ACTIONS_PANEL_ENABLED, "true");
         DEFAULT_FLAGS.put("settings_wifi_details_saved_screen", "true");
         DEFAULT_FLAGS.put("settings_wifi_details_datausage_header", "false");
index 72ab02c..822538b 100644 (file)
@@ -561,4 +561,29 @@ public class HardwareUiLayout extends MultiListLayout implements Tunable {
         inoutInfo.contentInsets.set(mList.getLeft(), mList.getTop(),
                 0, getBottom() - mList.getBottom());
     };
+
+    private float getAnimationDistance() {
+        return getContext().getResources().getDimension(
+                com.android.systemui.R.dimen.global_actions_panel_width) / 2;
+    }
+
+    @Override
+    public float getAnimationOffsetX() {
+        if (RotationUtils.getRotation(mContext) == ROTATION_NONE) {
+            return getAnimationDistance();
+        }
+        return 0;
+    }
+
+    @Override
+    public float getAnimationOffsetY() {
+        switch (RotationUtils.getRotation(getContext())) {
+            case RotationUtils.ROTATION_LANDSCAPE:
+                return -getAnimationDistance();
+            case RotationUtils.ROTATION_SEASCAPE:
+                return getAnimationDistance();
+            default: // Portrait
+                return 0;
+        }
+    }
 }
\ No newline at end of file
index d063a0f..a30b681 100644 (file)
@@ -148,6 +148,16 @@ public abstract class MultiListLayout extends LinearLayout {
     }
 
     /**
+     * Get the X offset in pixels for use when animating the view onto or off of the screen.
+     */
+    public abstract float getAnimationOffsetX();
+
+    /**
+     * Get the Y offset in pixels for use when animating the view onto or off of the screen.
+     */
+    public abstract float getAnimationOffsetY();
+
+    /**
      * Adapter class for converting items into child views for MultiListLayout and handling
      * callbacks for input events.
      */
index dcacd0f..e22b24e 100644 (file)
@@ -1127,10 +1127,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
         }
 
         protected int getActionLayoutId(Context context) {
-            if (isGridEnabled(context)) {
-                return com.android.systemui.R.layout.global_actions_grid_item;
-            }
-            return com.android.systemui.R.layout.global_actions_item;
+            return com.android.systemui.R.layout.global_actions_grid_item;
         }
 
         public View create(
@@ -1540,26 +1537,28 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
             initializeLayout();
         }
 
-        private boolean initializePanel() {
+        private boolean shouldUsePanel() {
             if (!isPanelEnabled(mContext) || mPanelController == null) {
                 return false;
             }
-            View panelView = mPanelController.getPanelContent();
-            if (panelView == null) {
+            if (mPanelController.getPanelContent() == null) {
                 return false;
             }
+            return true;
+        }
+
+        private void initializePanel() {
             FrameLayout panelContainer = new FrameLayout(mContext);
             FrameLayout.LayoutParams panelParams =
                     new FrameLayout.LayoutParams(
                             FrameLayout.LayoutParams.MATCH_PARENT,
                             FrameLayout.LayoutParams.WRAP_CONTENT);
-            panelContainer.addView(panelView, panelParams);
+            panelContainer.addView(mPanelController.getPanelContent(), panelParams);
             addContentView(
                     panelContainer,
                     new ViewGroup.LayoutParams(
                             ViewGroup.LayoutParams.MATCH_PARENT,
                             ViewGroup.LayoutParams.MATCH_PARENT));
-            return true;
         }
 
         private void initializeLayout() {
@@ -1578,8 +1577,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
             mGlobalActionsLayout.setRotationListener(this::onRotate);
             mGlobalActionsLayout.setAdapter(mAdapter);
 
-            boolean panelEnabled = initializePanel();
-            if (!panelEnabled) {
+            if (!shouldUsePanel()) {
                 if (mBackgroundDrawable == null) {
                     mBackgroundDrawable = new GradientDrawable(mContext);
                 }
@@ -1589,12 +1587,12 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
                         com.android.systemui.R.drawable.global_action_panel_scrim);
                 mScrimAlpha = 1f;
             }
-            mGlobalActionsLayout.setSnapToEdge(panelEnabled);
+            mGlobalActionsLayout.setSnapToEdge(true);
             getWindow().setBackgroundDrawable(mBackgroundDrawable);
         }
 
         private int getGlobalActionsLayoutId(Context context) {
-            if (isGridEnabled(context)) {
+            if (isForceGridEnabled(context) || shouldUsePanel()) {
                 if (RotationUtils.getRotation(context) == RotationUtils.ROTATION_SEASCAPE) {
                     return com.android.systemui.R.layout.global_actions_grid_seascape;
                 }
@@ -1653,11 +1651,13 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
             super.show();
             mShowing = true;
             mBackgroundDrawable.setAlpha(0);
-            mGlobalActionsLayout.setTranslationX(getAnimTranslation());
+            mGlobalActionsLayout.setTranslationX(mGlobalActionsLayout.getAnimationOffsetX());
+            mGlobalActionsLayout.setTranslationY(mGlobalActionsLayout.getAnimationOffsetY());
             mGlobalActionsLayout.setAlpha(0);
             mGlobalActionsLayout.animate()
                     .alpha(1)
                     .translationX(0)
+                    .translationY(0)
                     .setDuration(300)
                     .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
                     .setUpdateListener(animation -> {
@@ -1675,10 +1675,12 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
             }
             mShowing = false;
             mGlobalActionsLayout.setTranslationX(0);
+            mGlobalActionsLayout.setTranslationY(0);
             mGlobalActionsLayout.setAlpha(1);
             mGlobalActionsLayout.animate()
                     .alpha(0)
-                    .translationX(getAnimTranslation())
+                    .translationX(mGlobalActionsLayout.getAnimationOffsetX())
+                    .translationY(mGlobalActionsLayout.getAnimationOffsetY())
                     .setDuration(300)
                     .withEndAction(super::dismiss)
                     .setInterpolator(new LogAccelerateInterpolator())
@@ -1701,11 +1703,6 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
             }
         }
 
-        private float getAnimTranslation() {
-            return getContext().getResources().getDimension(
-                    com.android.systemui.R.dimen.global_actions_panel_width) / 2;
-        }
-
         @Override
         public void onColorsChanged(ColorExtractor extractor, int which) {
             if (mKeyguardShowing) {
@@ -1731,17 +1728,19 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
         }
 
         public void onRotate(int from, int to) {
-            if (mShowing && isGridEnabled(mContext)) {
+            if (mShowing && (shouldUsePanel() || isForceGridEnabled(mContext))) {
                 refreshDialog();
             }
         }
     }
 
     /**
-     * Determines whether or not the Global Actions menu should use the newer grid-style layout.
+     * Determines whether or not the Global Actions menu should be forced to
+     * use the newer grid-style layout.
      */
-    private static boolean isGridEnabled(Context context) {
-        return FeatureFlagUtils.isEnabled(context, FeatureFlagUtils.GLOBAL_ACTIONS_GRID_ENABLED);
+    private static boolean isForceGridEnabled(Context context) {
+        return FeatureFlagUtils.isEnabled(context,
+                FeatureFlagUtils.FORCE_GLOBAL_ACTIONS_GRID_ENABLED);
     }
 
     /**
index 9a0759c..f882569 100644 (file)
 
 package com.android.systemui.globalactions;
 
+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.content.Context;
 import android.text.TextUtils;
 import android.util.AttributeSet;
@@ -85,8 +89,8 @@ public class GlobalActionsGridLayout extends MultiListLayout {
         int rotation = RotationUtils.getRotation(mContext);
 
         boolean reverse = false; // should we add items to parents in the reverse order?
-        if (rotation == RotationUtils.ROTATION_NONE
-                || rotation == RotationUtils.ROTATION_SEASCAPE) {
+        if (rotation == ROTATION_NONE
+                || rotation == ROTATION_SEASCAPE) {
             reverse = !reverse; // if we're in portrait or seascape, reverse items
         }
         if (TextUtils.getLayoutDirectionFromLocale(Locale.getDefault())
@@ -125,9 +129,9 @@ public class GlobalActionsGridLayout extends MultiListLayout {
     private void updateSnapPosition() {
         if (mSnapToEdge) {
             setPadding(0, 0, 0, 0);
-            if (mRotation == RotationUtils.ROTATION_LANDSCAPE) {
+            if (mRotation == ROTATION_LANDSCAPE) {
                 setGravity(Gravity.RIGHT);
-            } else if (mRotation == RotationUtils.ROTATION_SEASCAPE) {
+            } else if (mRotation == ROTATION_SEASCAPE) {
                 setGravity(Gravity.LEFT);
             } else {
                 setGravity(Gravity.BOTTOM);
@@ -157,9 +161,9 @@ public class GlobalActionsGridLayout extends MultiListLayout {
             return getSeparatedView();
         } else {
             switch (rotation) {
-                case RotationUtils.ROTATION_LANDSCAPE:
+                case ROTATION_LANDSCAPE:
                     return getListView().getParentView(index, false, true);
-                case RotationUtils.ROTATION_SEASCAPE:
+                case ROTATION_SEASCAPE:
                     return getListView().getParentView(index, true, true);
                 default:
                     return getListView().getParentView(index, false, false);
@@ -174,4 +178,31 @@ public class GlobalActionsGridLayout extends MultiListLayout {
     public void setDivisionView(View v) {
         // do nothing
     }
+
+    private float getAnimationDistance() {
+        int rows = getListView().getRowCount();
+        float gridItemSize = getContext().getResources().getDimension(
+                com.android.systemui.R.dimen.global_actions_grid_item_height);
+        return rows * gridItemSize / 2;
+    }
+
+    @Override
+    public float getAnimationOffsetX() {
+        switch (RotationUtils.getRotation(getContext())) {
+            case ROTATION_LANDSCAPE:
+                return getAnimationDistance();
+            case ROTATION_SEASCAPE:
+                return -getAnimationDistance();
+            default: // Portrait
+                return 0;
+        }
+    }
+
+    @Override
+    public float getAnimationOffsetY() {
+        if (RotationUtils.getRotation(mContext) == ROTATION_NONE) {
+            return getAnimationDistance();
+        }
+        return 0;
+    }
 }
index 048f801..9c71ffc 100644 (file)
@@ -109,7 +109,10 @@ public class ListGridLayout extends LinearLayout {
         }
     }
 
-    private int getRowCount() {
+    /**
+     * Get the number of rows which will be used to render children.
+     */
+    public int getRowCount() {
         // special case for 3 to use a single row
         if (mExpectedCount == 3) {
             return 1;
@@ -117,7 +120,10 @@ public class ListGridLayout extends LinearLayout {
         return (int) Math.round(Math.sqrt(mExpectedCount));
     }
 
-    private int getColumnCount() {
+    /**
+     * Get the number of columns which will be used to render children.
+     */
+    public int getColumnCount() {
         // special case for 3 to use a single row
         if (mExpectedCount == 3) {
             return 3;