Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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.qs; |
| 18 | |
| 19 | import android.content.Context; |
Jason Monk | fece2ab | 2016-02-04 11:41:18 -0500 | [diff] [blame] | 20 | import android.content.res.Configuration; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 21 | import android.util.AttributeSet; |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 22 | import android.view.Gravity; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 23 | import android.view.View; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 24 | import android.widget.LinearLayout; |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 25 | import android.widget.Space; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 26 | import com.android.systemui.R; |
Jason Monk | ec87a87 | 2016-03-01 15:00:16 -0500 | [diff] [blame] | 27 | import com.android.systemui.qs.QSTile.SignalState; |
| 28 | import com.android.systemui.qs.QSTile.State; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 29 | |
| 30 | import java.util.ArrayList; |
| 31 | import java.util.Collection; |
| 32 | |
| 33 | /** |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 34 | * Version of QSPanel that only shows N Quick Tiles in the QS Header. |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 35 | */ |
| 36 | public class QuickQSPanel extends QSPanel { |
| 37 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 38 | private int mMaxTiles; |
| 39 | private QSPanel mFullPanel; |
| 40 | private View mHeader; |
| 41 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 42 | public QuickQSPanel(Context context, AttributeSet attrs) { |
| 43 | super(context, attrs); |
| 44 | if (mTileLayout != null) { |
| 45 | for (int i = 0; i < mRecords.size(); i++) { |
| 46 | mTileLayout.removeTile(mRecords.get(i)); |
| 47 | } |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 48 | removeView((View) mTileLayout); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 49 | } |
| 50 | mTileLayout = new HeaderTileLayout(context); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 51 | addView((View) mTileLayout, 1 /* Between brightness and footer */); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 52 | } |
| 53 | |
Jason Monk | 51c444b | 2016-01-06 16:32:29 -0500 | [diff] [blame] | 54 | @Override |
| 55 | protected void createCustomizePanel() { |
| 56 | // No customizing from the header. |
| 57 | } |
| 58 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 59 | public void setQSPanelAndHeader(QSPanel fullPanel, View header) { |
| 60 | mFullPanel = fullPanel; |
| 61 | mHeader = header; |
| 62 | } |
| 63 | |
| 64 | @Override |
Jason Monk | ec87a87 | 2016-03-01 15:00:16 -0500 | [diff] [blame] | 65 | protected void drawTile(TileRecord r, State state) { |
| 66 | if (state instanceof SignalState) { |
| 67 | State copy = r.tile.newTileState(); |
| 68 | state.copyTo(copy); |
| 69 | // No activity shown in the quick panel. |
| 70 | ((SignalState) copy).activityIn = false; |
| 71 | ((SignalState) copy).activityOut = false; |
| 72 | state = copy; |
| 73 | } |
| 74 | super.drawTile(r, state); |
| 75 | } |
| 76 | |
| 77 | @Override |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 78 | protected void showDetail(boolean show, Record r) { |
| 79 | // Do nothing, will be handled by the QSPanel. |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Override |
| 83 | protected QSTileBaseView createTileView(QSTile<?> tile) { |
| 84 | return new QSTileBaseView(mContext, tile.createTileView(mContext)); |
| 85 | } |
| 86 | |
| 87 | public void setMaxTiles(int maxTiles) { |
| 88 | mMaxTiles = maxTiles; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | protected void onTileClick(QSTile<?> tile) { |
| 93 | tile.secondaryClick(); |
| 94 | } |
| 95 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 96 | @Override |
| 97 | public void onTuningChanged(String key, String newValue) { |
| 98 | // No tunings for you. |
| 99 | if (key.equals(QS_SHOW_BRIGHTNESS)) { |
| 100 | // No Brightness for you. |
| 101 | super.onTuningChanged(key, "0"); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public void setTiles(Collection<QSTile<?>> tiles) { |
| 107 | ArrayList<QSTile<?>> quickTiles = new ArrayList<>(); |
| 108 | for (QSTile<?> tile : tiles) { |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 109 | quickTiles.add(tile); |
| 110 | if (quickTiles.size() == mMaxTiles) { |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 111 | break; |
| 112 | } |
| 113 | } |
| 114 | super.setTiles(quickTiles); |
| 115 | } |
| 116 | |
| 117 | private static class HeaderTileLayout extends LinearLayout implements QSTileLayout { |
| 118 | |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 119 | private final Space mEndSpacer; |
Jason Monk | fece2ab | 2016-02-04 11:41:18 -0500 | [diff] [blame] | 120 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 121 | public HeaderTileLayout(Context context) { |
| 122 | super(context); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 123 | setClipChildren(false); |
| 124 | setClipToPadding(false); |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 125 | setGravity(Gravity.CENTER_VERTICAL); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 126 | setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 127 | |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 128 | mEndSpacer = new Space(context); |
| 129 | mEndSpacer.setLayoutParams(generateLayoutParams()); |
Jason Monk | fece2ab | 2016-02-04 11:41:18 -0500 | [diff] [blame] | 130 | updateDownArrowMargin(); |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 131 | addView(mEndSpacer); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 132 | setOrientation(LinearLayout.HORIZONTAL); |
| 133 | } |
| 134 | |
| 135 | @Override |
Jason Monk | fece2ab | 2016-02-04 11:41:18 -0500 | [diff] [blame] | 136 | protected void onConfigurationChanged(Configuration newConfig) { |
| 137 | super.onConfigurationChanged(newConfig); |
| 138 | updateDownArrowMargin(); |
| 139 | } |
| 140 | |
| 141 | private void updateDownArrowMargin() { |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 142 | LayoutParams params = (LayoutParams) mEndSpacer.getLayoutParams(); |
Jason Monk | fece2ab | 2016-02-04 11:41:18 -0500 | [diff] [blame] | 143 | params.setMarginStart(mContext.getResources().getDimensionPixelSize( |
| 144 | R.dimen.qs_expand_margin)); |
Jason Monk | 97cb9c7 | 2016-02-17 16:41:01 -0500 | [diff] [blame] | 145 | mEndSpacer.setLayoutParams(params); |
Jason Monk | fece2ab | 2016-02-04 11:41:18 -0500 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | @Override |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 149 | public void addTile(TileRecord tile) { |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 150 | addView(tile.tileView, getChildCount() - 1 /* Leave icon at end */, |
| 151 | generateLayoutParams()); |
| 152 | // Add a spacer. |
| 153 | addView(new Space(mContext), getChildCount() - 1 /* Leave icon at end */, |
| 154 | generateSpaceParams()); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 155 | } |
| 156 | |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 157 | private LayoutParams generateSpaceParams() { |
Jason Monk | deba7a4 | 2015-12-08 16:14:10 -0500 | [diff] [blame] | 158 | int size = mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_size); |
| 159 | LayoutParams lp = new LayoutParams(0, size); |
| 160 | lp.weight = 1; |
| 161 | lp.gravity = Gravity.CENTER; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 162 | return lp; |
| 163 | } |
| 164 | |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 165 | private LayoutParams generateLayoutParams() { |
| 166 | int size = mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_size); |
| 167 | LayoutParams lp = new LayoutParams(size, size); |
| 168 | lp.gravity = Gravity.CENTER; |
| 169 | return lp; |
| 170 | } |
| 171 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 172 | @Override |
| 173 | public void removeTile(TileRecord tile) { |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 174 | int childIndex = getChildIndex(tile.tileView); |
| 175 | // Remove the tile. |
| 176 | removeViewAt(childIndex); |
| 177 | // Remove its spacer as well. |
| 178 | removeViewAt(childIndex); |
| 179 | } |
| 180 | |
| 181 | private int getChildIndex(QSTileBaseView tileView) { |
| 182 | final int N = getChildCount(); |
| 183 | for (int i = 0; i < N; i++) { |
| 184 | if (getChildAt(i) == tileView) { |
| 185 | return i; |
| 186 | } |
| 187 | } |
| 188 | return -1; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | @Override |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 192 | public int getOffsetTop(TileRecord tile) { |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | @Override |
Jason Monk | 9d02a43 | 2016-01-20 16:33:46 -0500 | [diff] [blame] | 197 | public boolean updateResources() { |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 198 | // No resources here. |
Jason Monk | 9d02a43 | 2016-01-20 16:33:46 -0500 | [diff] [blame] | 199 | return false; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 200 | } |
Jason Monk | c5bdafb | 2016-02-25 16:24:21 -0500 | [diff] [blame] | 201 | |
| 202 | @Override |
| 203 | public boolean hasOverlappingRendering() { |
| 204 | return false; |
| 205 | } |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 206 | } |
| 207 | } |