blob: b391c1e3b875891bd843230de3bfd6cf504bc2ce [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;
21import 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;
24import android.widget.ImageView;
25import android.widget.LinearLayout;
26import com.android.systemui.R;
27
28import java.util.ArrayList;
29import java.util.Collection;
30
31/**
Jason Monkdc35dcb2015-12-04 16:36:15 -050032 * Version of QSPanel that only shows N Quick Tiles in the QS Header.
Jason Monkc34befb2015-10-07 16:40:02 -040033 */
34public class QuickQSPanel extends QSPanel {
35
Jason Monkdc35dcb2015-12-04 16:36:15 -050036 private int mMaxTiles;
37 private QSPanel mFullPanel;
38 private View mHeader;
39
Jason Monkc34befb2015-10-07 16:40:02 -040040 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 }
46 mQsContainer.removeView((View) mTileLayout);
47 }
48 mTileLayout = new HeaderTileLayout(context);
49 mQsContainer.addView((View) mTileLayout, 1 /* Between brightness and footer */);
50 }
51
Jason Monk51c444b2016-01-06 16:32:29 -050052 @Override
53 protected void createCustomizePanel() {
54 // No customizing from the header.
55 }
56
Jason Monkdc35dcb2015-12-04 16:36:15 -050057 public void setQSPanelAndHeader(QSPanel fullPanel, View header) {
58 mFullPanel = fullPanel;
59 mHeader = header;
60 }
61
62 @Override
Jason Monkca894a02016-01-12 15:30:22 -050063 protected void showDetail(boolean show, Record r) {
64 // Do nothing, will be handled by the QSPanel.
Jason Monkdc35dcb2015-12-04 16:36:15 -050065 }
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 Monkc34befb2015-10-07 16:40:02 -040081 @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 Monkdc35dcb2015-12-04 16:36:15 -050094 quickTiles.add(tile);
95 if (quickTiles.size() == mMaxTiles) {
Jason Monkc34befb2015-10-07 16:40:02 -040096 break;
97 }
98 }
99 super.setTiles(quickTiles);
100 }
101
102 private static class HeaderTileLayout extends LinearLayout implements QSTileLayout {
103
104 public HeaderTileLayout(Context context) {
105 super(context);
Jason Monkdc35dcb2015-12-04 16:36:15 -0500106 setClipChildren(false);
107 setClipToPadding(false);
Jason Monkc133d262015-10-27 12:32:45 -0400108 setGravity(Gravity.CENTER_VERTICAL);
Jason Monkc34befb2015-10-07 16:40:02 -0400109 setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
Jason Monkc133d262015-10-27 12:32:45 -0400110
111 int padding =
112 mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_padding);
Jason Monkc34befb2015-10-07 16:40:02 -0400113 ImageView downArrow = new ImageView(context);
114 downArrow.setImageResource(R.drawable.ic_expand_more);
115 downArrow.setImageTintList(ColorStateList.valueOf(context.getResources().getColor(
116 android.R.color.white, null)));
117 downArrow.setLayoutParams(generateLayoutParams());
Jason Monkc133d262015-10-27 12:32:45 -0400118 downArrow.setPadding(padding, padding, padding, padding);
Jason Monkc34befb2015-10-07 16:40:02 -0400119 addView(downArrow);
120 setOrientation(LinearLayout.HORIZONTAL);
121 }
122
123 @Override
124 public void addTile(TileRecord tile) {
125 tile.tileView.setLayoutParams(generateLayoutParams());
Jason Monkc34befb2015-10-07 16:40:02 -0400126 addView(tile.tileView, getChildCount() - 1 /* Leave icon at end */);
127 }
128
129 private LayoutParams generateLayoutParams() {
Jason Monkdeba7a42015-12-08 16:14:10 -0500130 int size = mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_size);
131 LayoutParams lp = new LayoutParams(0, size);
132 lp.weight = 1;
133 lp.gravity = Gravity.CENTER;
Jason Monkc34befb2015-10-07 16:40:02 -0400134 return lp;
135 }
136
137 @Override
138 public void removeTile(TileRecord tile) {
139 removeView(tile.tileView);
140 }
141
142 @Override
Jason Monkc34befb2015-10-07 16:40:02 -0400143 public int getOffsetTop(TileRecord tile) {
144 return 0;
145 }
146
147 @Override
Jason Monk9d02a432016-01-20 16:33:46 -0500148 public boolean updateResources() {
Jason Monkc34befb2015-10-07 16:40:02 -0400149 // No resources here.
Jason Monk9d02a432016-01-20 16:33:46 -0500150 return false;
Jason Monkc34befb2015-10-07 16:40:02 -0400151 }
152 }
153}