blob: 8b826eea4285e63bee2f879d79999dab81e16bdd [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;
Jason Monkfece2ab2016-02-04 11:41:18 -050020import android.content.res.Configuration;
Jason Monkc34befb2015-10-07 16:40:02 -040021import android.util.AttributeSet;
Jason Monkc133d262015-10-27 12:32:45 -040022import android.view.Gravity;
Jason Monkc34befb2015-10-07 16:40:02 -040023import android.view.View;
Jason Monkc34befb2015-10-07 16:40:02 -040024import android.widget.LinearLayout;
Jason Monkdb50de82016-02-03 15:34:54 -050025import android.widget.Space;
Jason Monkc34befb2015-10-07 16:40:02 -040026import com.android.systemui.R;
Jason Monkec87a872016-03-01 15:00:16 -050027import com.android.systemui.qs.QSTile.SignalState;
28import com.android.systemui.qs.QSTile.State;
Jason Monkc34befb2015-10-07 16:40:02 -040029
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 }
Jason Monk162011e2016-02-19 08:11:55 -050048 removeView((View) mTileLayout);
Jason Monkc34befb2015-10-07 16:40:02 -040049 }
50 mTileLayout = new HeaderTileLayout(context);
Jason Monk162011e2016-02-19 08:11:55 -050051 addView((View) mTileLayout, 1 /* Between brightness and footer */);
Jason Monkc34befb2015-10-07 16:40:02 -040052 }
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 Monkec87a872016-03-01 15:00:16 -050065 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 Monkca894a02016-01-12 15:30:22 -050078 protected void showDetail(boolean show, Record r) {
79 // Do nothing, will be handled by the QSPanel.
Jason Monkdc35dcb2015-12-04 16:36:15 -050080 }
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 Monkc34befb2015-10-07 16:40:02 -040096 @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 Monkdc35dcb2015-12-04 16:36:15 -0500109 quickTiles.add(tile);
110 if (quickTiles.size() == mMaxTiles) {
Jason Monkc34befb2015-10-07 16:40:02 -0400111 break;
112 }
113 }
114 super.setTiles(quickTiles);
115 }
116
117 private static class HeaderTileLayout extends LinearLayout implements QSTileLayout {
118
Jason Monk97cb9c72016-02-17 16:41:01 -0500119 private final Space mEndSpacer;
Jason Monkfece2ab2016-02-04 11:41:18 -0500120
Jason Monkc34befb2015-10-07 16:40:02 -0400121 public HeaderTileLayout(Context context) {
122 super(context);
Jason Monkdc35dcb2015-12-04 16:36:15 -0500123 setClipChildren(false);
124 setClipToPadding(false);
Jason Monkc133d262015-10-27 12:32:45 -0400125 setGravity(Gravity.CENTER_VERTICAL);
Jason Monkc34befb2015-10-07 16:40:02 -0400126 setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
Jason Monkc133d262015-10-27 12:32:45 -0400127
Jason Monk97cb9c72016-02-17 16:41:01 -0500128 mEndSpacer = new Space(context);
129 mEndSpacer.setLayoutParams(generateLayoutParams());
Jason Monkfece2ab2016-02-04 11:41:18 -0500130 updateDownArrowMargin();
Jason Monk97cb9c72016-02-17 16:41:01 -0500131 addView(mEndSpacer);
Jason Monkc34befb2015-10-07 16:40:02 -0400132 setOrientation(LinearLayout.HORIZONTAL);
133 }
134
135 @Override
Jason Monkfece2ab2016-02-04 11:41:18 -0500136 protected void onConfigurationChanged(Configuration newConfig) {
137 super.onConfigurationChanged(newConfig);
138 updateDownArrowMargin();
139 }
140
141 private void updateDownArrowMargin() {
Jason Monk97cb9c72016-02-17 16:41:01 -0500142 LayoutParams params = (LayoutParams) mEndSpacer.getLayoutParams();
Jason Monkfece2ab2016-02-04 11:41:18 -0500143 params.setMarginStart(mContext.getResources().getDimensionPixelSize(
144 R.dimen.qs_expand_margin));
Jason Monk97cb9c72016-02-17 16:41:01 -0500145 mEndSpacer.setLayoutParams(params);
Jason Monkfece2ab2016-02-04 11:41:18 -0500146 }
147
148 @Override
Jason Monkc34befb2015-10-07 16:40:02 -0400149 public void addTile(TileRecord tile) {
Jason Monkdb50de82016-02-03 15:34:54 -0500150 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 Monkc34befb2015-10-07 16:40:02 -0400155 }
156
Jason Monkdb50de82016-02-03 15:34:54 -0500157 private LayoutParams generateSpaceParams() {
Jason Monkdeba7a42015-12-08 16:14:10 -0500158 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 Monkc34befb2015-10-07 16:40:02 -0400162 return lp;
163 }
164
Jason Monkdb50de82016-02-03 15:34:54 -0500165 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 Monkc34befb2015-10-07 16:40:02 -0400172 @Override
173 public void removeTile(TileRecord tile) {
Jason Monkdb50de82016-02-03 15:34:54 -0500174 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 Monkc34befb2015-10-07 16:40:02 -0400189 }
190
191 @Override
Jason Monkc34befb2015-10-07 16:40:02 -0400192 public int getOffsetTop(TileRecord tile) {
193 return 0;
194 }
195
196 @Override
Jason Monk9d02a432016-01-20 16:33:46 -0500197 public boolean updateResources() {
Jason Monkc34befb2015-10-07 16:40:02 -0400198 // No resources here.
Jason Monk9d02a432016-01-20 16:33:46 -0500199 return false;
Jason Monkc34befb2015-10-07 16:40:02 -0400200 }
Jason Monkc5bdafb2016-02-25 16:24:21 -0500201
202 @Override
203 public boolean hasOverlappingRendering() {
204 return false;
205 }
Jason Monkc34befb2015-10-07 16:40:02 -0400206 }
207}