blob: f208470a2927c25b4775e8bef93d11a9200784e5 [file] [log] [blame]
Jason Monkc34befb2015-10-07 16:40:02 -04001/*
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
17package com.android.systemui.qs;
18
19import android.content.Context;
20import android.content.res.ColorStateList;
Jason Monkfece2ab2016-02-04 11:41:18 -050021import android.content.res.Configuration;
Jason Monkc34befb2015-10-07 16:40:02 -040022import android.util.AttributeSet;
Jason Monkc133d262015-10-27 12:32:45 -040023import android.view.Gravity;
Jason Monkc34befb2015-10-07 16:40:02 -040024import android.view.View;
25import android.widget.ImageView;
26import android.widget.LinearLayout;
Jason Monkdb50de82016-02-03 15:34:54 -050027import android.widget.Space;
Jason Monkc34befb2015-10-07 16:40:02 -040028import com.android.systemui.R;
29
30import java.util.ArrayList;
31import java.util.Collection;
32
33/**
Jason Monkdc35dcb2015-12-04 16:36:15 -050034 * Version of QSPanel that only shows N Quick Tiles in the QS Header.
Jason Monkc34befb2015-10-07 16:40:02 -040035 */
36public class QuickQSPanel extends QSPanel {
37
Jason Monkdc35dcb2015-12-04 16:36:15 -050038 private int mMaxTiles;
39 private QSPanel mFullPanel;
40 private View mHeader;
41
Jason Monkc34befb2015-10-07 16:40:02 -040042 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 Monk51c444b2016-01-06 16:32:29 -050054 @Override
55 protected void createCustomizePanel() {
56 // No customizing from the header.
57 }
58
Jason Monkdc35dcb2015-12-04 16:36:15 -050059 public void setQSPanelAndHeader(QSPanel fullPanel, View header) {
60 mFullPanel = fullPanel;
61 mHeader = header;
62 }
63
64 @Override
Jason Monkca894a02016-01-12 15:30:22 -050065 protected void showDetail(boolean show, Record r) {
66 // Do nothing, will be handled by the QSPanel.
Jason Monkdc35dcb2015-12-04 16:36:15 -050067 }
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 Monkc34befb2015-10-07 16:40:02 -040083 @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 Monkdc35dcb2015-12-04 16:36:15 -050096 quickTiles.add(tile);
97 if (quickTiles.size() == mMaxTiles) {
Jason Monkc34befb2015-10-07 16:40:02 -040098 break;
99 }
100 }
101 super.setTiles(quickTiles);
102 }
103
104 private static class HeaderTileLayout extends LinearLayout implements QSTileLayout {
105
Jason Monkfece2ab2016-02-04 11:41:18 -0500106 private final ImageView mDownArrow;
107
Jason Monkc34befb2015-10-07 16:40:02 -0400108 public HeaderTileLayout(Context context) {
109 super(context);
Jason Monkdc35dcb2015-12-04 16:36:15 -0500110 setClipChildren(false);
111 setClipToPadding(false);
Jason Monkc133d262015-10-27 12:32:45 -0400112 setGravity(Gravity.CENTER_VERTICAL);
Jason Monkc34befb2015-10-07 16:40:02 -0400113 setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
Jason Monkc133d262015-10-27 12:32:45 -0400114
115 int padding =
116 mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_padding);
Jason Monkfece2ab2016-02-04 11:41:18 -0500117 mDownArrow = new ImageView(context);
118 mDownArrow.setImageResource(R.drawable.ic_expand_more);
119 mDownArrow.setImageTintList(ColorStateList.valueOf(context.getResources().getColor(
Jason Monkc34befb2015-10-07 16:40:02 -0400120 android.R.color.white, null)));
Jason Monkfece2ab2016-02-04 11:41:18 -0500121 mDownArrow.setLayoutParams(generateLayoutParams());
122 mDownArrow.setPadding(padding, padding, padding, padding);
123 updateDownArrowMargin();
124 addView(mDownArrow);
Jason Monkc34befb2015-10-07 16:40:02 -0400125 setOrientation(LinearLayout.HORIZONTAL);
126 }
127
128 @Override
Jason Monkfece2ab2016-02-04 11:41:18 -0500129 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 Monkc34befb2015-10-07 16:40:02 -0400142 public void addTile(TileRecord tile) {
Jason Monkdb50de82016-02-03 15:34:54 -0500143 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 Monkc34befb2015-10-07 16:40:02 -0400148 }
149
Jason Monkdb50de82016-02-03 15:34:54 -0500150 private LayoutParams generateSpaceParams() {
Jason Monkdeba7a42015-12-08 16:14:10 -0500151 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 Monkc34befb2015-10-07 16:40:02 -0400155 return lp;
156 }
157
Jason Monkdb50de82016-02-03 15:34:54 -0500158 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 Monkc34befb2015-10-07 16:40:02 -0400165 @Override
166 public void removeTile(TileRecord tile) {
Jason Monkdb50de82016-02-03 15:34:54 -0500167 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 Monkc34befb2015-10-07 16:40:02 -0400182 }
183
184 @Override
Jason Monkc34befb2015-10-07 16:40:02 -0400185 public int getOffsetTop(TileRecord tile) {
186 return 0;
187 }
188
189 @Override
Jason Monk9d02a432016-01-20 16:33:46 -0500190 public boolean updateResources() {
Jason Monkc34befb2015-10-07 16:40:02 -0400191 // No resources here.
Jason Monk9d02a432016-01-20 16:33:46 -0500192 return false;
Jason Monkc34befb2015-10-07 16:40:02 -0400193 }
194 }
195}