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