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