blob: a5c8d919165448ff70a0052525fba053e4c4ab5c [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 Monkdc35dcb2015-12-04 16:36:15 -050052 public void setQSPanelAndHeader(QSPanel fullPanel, View header) {
53 mFullPanel = fullPanel;
54 mHeader = header;
55 }
56
57 @Override
58 protected void handleShowDetail(QSPanel.Record r, boolean show) {
59 if (show) {
60 mHeader.performClick();
61 mFullPanel.showDetail(show, r);
62 } else {
63 // Not sure how we would end up here...
64 super.handleShowDetail(r, show);
65 }
66 }
67
68 @Override
69 protected QSTileBaseView createTileView(QSTile<?> tile) {
70 return new QSTileBaseView(mContext, tile.createTileView(mContext));
71 }
72
73 public void setMaxTiles(int maxTiles) {
74 mMaxTiles = maxTiles;
75 }
76
77 @Override
78 protected void onTileClick(QSTile<?> tile) {
79 tile.secondaryClick();
80 }
81
Jason Monkc34befb2015-10-07 16:40:02 -040082 @Override
83 public void onTuningChanged(String key, String newValue) {
84 // No tunings for you.
85 if (key.equals(QS_SHOW_BRIGHTNESS)) {
86 // No Brightness for you.
87 super.onTuningChanged(key, "0");
88 }
89 }
90
91 @Override
92 public void setTiles(Collection<QSTile<?>> tiles) {
93 ArrayList<QSTile<?>> quickTiles = new ArrayList<>();
94 for (QSTile<?> tile : tiles) {
Jason Monkdc35dcb2015-12-04 16:36:15 -050095 quickTiles.add(tile);
96 if (quickTiles.size() == mMaxTiles) {
Jason Monkc34befb2015-10-07 16:40:02 -040097 break;
98 }
99 }
100 super.setTiles(quickTiles);
101 }
102
103 private static class HeaderTileLayout extends LinearLayout implements QSTileLayout {
104
105 public HeaderTileLayout(Context context) {
106 super(context);
Jason Monkdc35dcb2015-12-04 16:36:15 -0500107 setClipChildren(false);
108 setClipToPadding(false);
Jason Monkc133d262015-10-27 12:32:45 -0400109 setGravity(Gravity.CENTER_VERTICAL);
Jason Monkc34befb2015-10-07 16:40:02 -0400110 setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
Jason Monkc133d262015-10-27 12:32:45 -0400111
112 int padding =
113 mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_padding);
Jason Monkc34befb2015-10-07 16:40:02 -0400114 ImageView downArrow = new ImageView(context);
115 downArrow.setImageResource(R.drawable.ic_expand_more);
116 downArrow.setImageTintList(ColorStateList.valueOf(context.getResources().getColor(
117 android.R.color.white, null)));
118 downArrow.setLayoutParams(generateLayoutParams());
Jason Monkc133d262015-10-27 12:32:45 -0400119 downArrow.setPadding(padding, padding, padding, padding);
Jason Monkc34befb2015-10-07 16:40:02 -0400120 addView(downArrow);
121 setOrientation(LinearLayout.HORIZONTAL);
122 }
123
124 @Override
125 public void addTile(TileRecord tile) {
126 tile.tileView.setLayoutParams(generateLayoutParams());
Jason Monkc34befb2015-10-07 16:40:02 -0400127 addView(tile.tileView, getChildCount() - 1 /* Leave icon at end */);
128 }
129
130 private LayoutParams generateLayoutParams() {
Jason Monkc133d262015-10-27 12:32:45 -0400131 int size =
132 mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_size);
Jason Monkdc35dcb2015-12-04 16:36:15 -0500133 LayoutParams lp = new LayoutParams(size, size);
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
143 public void setTileVisibility(TileRecord tile, int visibility) {
144 tile.tileView.setVisibility(visibility);
145 }
146
147 @Override
148 public int getOffsetTop(TileRecord tile) {
149 return 0;
150 }
151
152 @Override
153 public void updateResources() {
154 // No resources here.
155 }
156 }
157}