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

Commit 5e28f8c8 authored by Aaron Heuckroth's avatar Aaron Heuckroth
Browse files

Add unit tests to GlobalActionsGridLayout.

Refactor GlobalActionsGridLayout, ListGridLayout, and related classes/XML files to clean things up and improve testability.

Test: Automated tests pass. (Hooray, they exist now!)

Fixes: 130808337
Change-Id: I89f1a90b07425a95ce600dd104ed3a4729c2215b
parent fcb633f9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
    android:clipToPadding="false"
    android:theme="@style/qs_theme"
    android:paddingLeft="@dimen/global_actions_top_padding"
    android:gravity="top|left"
    android:gravity="right"
    android:clipChildren="false"
>
    <LinearLayout
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
    android:orientation="horizontal"
    android:clipToPadding="false"
    android:theme="@style/qs_theme"
    android:gravity="top|right"
    android:gravity="left"
    android:paddingRight="@dimen/global_actions_top_padding"
    android:clipChildren="false"
>
+1 −2
Original line number Diff line number Diff line
@@ -6,9 +6,8 @@
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:clipToPadding="false"
    android:paddingTop="@dimen/global_actions_top_padding"
    android:theme="@style/qs_theme"
    android:gravity="top|center"
    android:gravity="bottom"
    android:clipChildren="false"
>
    <LinearLayout
+4 −13
Original line number Diff line number Diff line
@@ -32,13 +32,10 @@ import android.view.ViewOutlineProvider;
import android.view.ViewTreeObserver;
import android.widget.LinearLayout;

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

import java.util.ArrayList;

/**
 * Layout for placing two containers at a specific physical position on the device, relative to the
 * device's hardware, regardless of screen rotation.
@@ -258,24 +255,16 @@ public class HardwareUiLayout extends MultiListLayout implements Tunable {
    @Override
    public void onUpdateList() {
        super.onUpdateList();
        ArrayList<GlobalActionsDialog.Action> separatedActions =
                mAdapter.getSeparatedItems();
        ArrayList<GlobalActionsDialog.Action> listActions = mAdapter.getListItems();

        for (int i = 0; i < mAdapter.getCount(); i++) {
            Object action = mAdapter.getItem(i);
            int separatedIndex = separatedActions.indexOf(action);
            ViewGroup parent;
            if (separatedIndex != -1) {
            boolean separated = mAdapter.shouldBeSeparated(i);
            if (separated) {
                parent = getSeparatedView();
            } else {
                int listIndex = listActions.indexOf(action);
                parent = getListView();
            }
            View v = mAdapter.getView(i, null, parent);
            final int pos = i;
            v.setOnClickListener(view -> mAdapter.onClickItem(pos));
            v.setOnLongClickListener(view -> mAdapter.onLongClickItem(pos));
            parent.addView(v);
        }
    }
@@ -421,7 +410,9 @@ public class HardwareUiLayout extends MultiListLayout implements Tunable {
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);

        post(() -> updatePosition());

    }

    private void animateChild(int oldHeight, int newHeight) {
+13 −19
Original line number Diff line number Diff line
@@ -26,16 +26,12 @@ import android.widget.LinearLayout;

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

import java.util.ArrayList;

/**
 * Layout class representing the Global Actions menu which appears when the power button is held.
 */
public abstract class MultiListLayout extends LinearLayout {
    protected boolean mHasOutsideTouch;
    protected MultiListAdapter mAdapter;
    protected boolean mSnapToEdge;

    protected int mRotation;
    protected RotationListener mRotationListener;

@@ -51,7 +47,7 @@ public abstract class MultiListLayout extends LinearLayout {
    /**
     * Removes all child items from the separated and list views, if they exist.
     */
    public abstract void removeAllItems();
    protected abstract void removeAllItems();

    /**
     * Sets the divided view, which may have a differently-colored background.
@@ -69,13 +65,6 @@ public abstract class MultiListLayout extends LinearLayout {
        getSeparatedView().setVisibility(visible ? View.VISIBLE : View.GONE);
    }

    /**
     * Sets whether the GlobalActions view should snap to the edge of the screen.
     */
    public void setSnapToEdge(boolean snap) {
        mSnapToEdge = snap;
    }

    /**
     * Sets the adapter used to inflate items.
     */
@@ -122,6 +111,7 @@ public abstract class MultiListLayout extends LinearLayout {
    }

    protected void onUpdateList() {
        removeAllItems();
        setSeparatedViewVisibility(mAdapter.hasSeparatedItems());
    }

@@ -163,16 +153,14 @@ public abstract class MultiListLayout extends LinearLayout {
     */
    public abstract static class MultiListAdapter extends BaseAdapter {
        /**
         * Creates an ArrayList of items which should be rendered in the separated view.
         * @param useSeparatedView is true if the separated view will be used, false otherwise.
         * Counts the number of items to be rendered in the separated view.
         */
        public abstract ArrayList getSeparatedItems();
        public abstract int countSeparatedItems();

        /**
         * Creates an ArrayList of items which should be rendered in the list view.
         * @param useSeparatedView True if the separated view will be used, false otherwise.
         * Counts the number of items be rendered in the list view.
         */
        public abstract ArrayList getListItems();
        public abstract int countListItems();

        /**
         * Callback to run when an individual item is clicked or pressed.
@@ -192,7 +180,13 @@ public abstract class MultiListLayout extends LinearLayout {
         * or not to hide the separated list from view.
         */
        public boolean hasSeparatedItems() {
            return getSeparatedItems().size() > 0;
            return countSeparatedItems() > 0;
        }

        /**
         * Determines whether the item at the given index should be rendered in the separarted view.
         * @param position The index of the item.
         */
        public abstract boolean shouldBeSeparated(int position);
    }
}
Loading