Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui; |
| 18 | |
| 19 | import android.content.Context; |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 20 | import android.content.res.Configuration; |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 21 | import android.util.AttributeSet; |
| 22 | import android.view.View; |
| 23 | import android.view.ViewGroup; |
| 24 | import android.widget.LinearLayout; |
| 25 | |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 26 | import com.android.systemui.util.leak.RotationUtils; |
| 27 | |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 28 | /** |
| 29 | * Layout class representing the Global Actions menu which appears when the power button is held. |
| 30 | */ |
| 31 | public abstract class MultiListLayout extends LinearLayout { |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 32 | protected boolean mHasOutsideTouch; |
| 33 | protected boolean mHasSeparatedView; |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 34 | |
Aaron Heuckroth | 166392f | 2019-01-17 16:50:59 -0500 | [diff] [blame] | 35 | protected int mExpectedSeparatedItemCount; |
| 36 | protected int mExpectedListItemCount; |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 37 | |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 38 | protected int mRotation; |
| 39 | protected RotationListener mRotationListener; |
| 40 | |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 41 | public MultiListLayout(Context context, AttributeSet attrs) { |
| 42 | super(context, attrs); |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 43 | mRotation = RotationUtils.getRotation(context); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | protected abstract ViewGroup getSeparatedView(); |
| 47 | |
| 48 | protected abstract ViewGroup getListView(); |
| 49 | |
| 50 | /** |
| 51 | * Removes all child items from the separated and list views, if they exist. |
| 52 | */ |
| 53 | public abstract void removeAllItems(); |
| 54 | |
| 55 | /** |
| 56 | * Get the parent view which will be used to contain the item at the specified index. |
| 57 | * @param separated Whether or not this index refers to a position in the separated or list |
| 58 | * container. |
| 59 | * @param index The index of the item within the container. |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 60 | * @param reverse If the MultiListLayout contains sub-lists within the list container, reverse |
| 61 | * the order that they are filled. |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 62 | * @return The parent ViewGroup which will be used to contain the specified item |
| 63 | * after it has been added to the layout. |
| 64 | */ |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 65 | public abstract ViewGroup getParentView(boolean separated, int index, boolean reverse); |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * Sets the divided view, which may have a differently-colored background. |
| 69 | */ |
| 70 | public abstract void setDivisionView(View v); |
| 71 | |
| 72 | /** |
| 73 | * Set the view accessibility delegate for the list view container. |
| 74 | */ |
| 75 | public void setListViewAccessibilityDelegate(View.AccessibilityDelegate delegate) { |
| 76 | getListView().setAccessibilityDelegate(delegate); |
| 77 | } |
| 78 | |
| 79 | protected void setSeparatedViewVisibility(boolean visible) { |
| 80 | getSeparatedView().setVisibility(visible ? View.VISIBLE : View.GONE); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Sets the number of items expected to be rendered in the separated container. This allows the |
| 85 | * layout to correctly determine which parent containers will be used for items before they have |
| 86 | * beenadded to the layout. |
| 87 | * @param count The number of items expected. |
| 88 | */ |
| 89 | public void setExpectedSeparatedItemCount(int count) { |
| 90 | mExpectedSeparatedItemCount = count; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Sets the number of items expected to be rendered in the list container. This allows the |
| 95 | * layout to correctly determine which parent containers will be used for items before they have |
| 96 | * beenadded to the layout. |
| 97 | * @param count The number of items expected. |
| 98 | */ |
| 99 | public void setExpectedListItemCount(int count) { |
| 100 | mExpectedListItemCount = count; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Sets whether the separated view should be shown, and handles updating visibility on |
| 105 | * that view. |
| 106 | */ |
| 107 | public void setHasSeparatedView(boolean hasSeparatedView) { |
| 108 | mHasSeparatedView = hasSeparatedView; |
| 109 | setSeparatedViewVisibility(hasSeparatedView); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Sets this layout to respond to an outside touch listener. |
| 114 | */ |
| 115 | public void setOutsideTouchListener(OnClickListener onClickListener) { |
| 116 | mHasOutsideTouch = true; |
| 117 | requestLayout(); |
| 118 | setOnClickListener(onClickListener); |
| 119 | setClickable(true); |
| 120 | setFocusable(true); |
| 121 | } |
| 122 | |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 123 | @Override |
| 124 | protected void onConfigurationChanged(Configuration newConfig) { |
| 125 | super.onConfigurationChanged(newConfig); |
| 126 | int newRotation = RotationUtils.getRotation(mContext); |
| 127 | if (newRotation != mRotation) { |
| 128 | rotate(mRotation, newRotation); |
| 129 | mRotation = newRotation; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | protected void rotate(int from, int to) { |
| 134 | if (mRotationListener != null) { |
| 135 | mRotationListener.onRotate(from, to); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | public void setRotationListener(RotationListener listener) { |
| 140 | mRotationListener = listener; |
| 141 | } |
| 142 | |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 143 | /** |
| 144 | * Retrieve the MultiListLayout associated with the given view. |
| 145 | */ |
| 146 | public static MultiListLayout get(View v) { |
| 147 | if (v instanceof MultiListLayout) return (MultiListLayout) v; |
| 148 | if (v.getParent() instanceof View) { |
| 149 | return get((View) v.getParent()); |
| 150 | } |
| 151 | return null; |
| 152 | } |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 153 | |
Aaron Heuckroth | 4ea2fdb | 2019-02-14 16:28:35 -0500 | [diff] [blame] | 154 | /** |
| 155 | * Interface to provide callbacks which trigger when this list detects a rotation. |
| 156 | */ |
| 157 | public interface RotationListener { |
Aaron Heuckroth | 75e249f | 2019-02-01 15:59:57 -0500 | [diff] [blame] | 158 | void onRotate(int from, int to); |
| 159 | } |
Aaron Heuckroth | f708d47 | 2019-01-10 16:54:51 -0500 | [diff] [blame] | 160 | } |