blob: 6a053bee36cd9d9803bbf63eade40fa924b783fe [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.util.Log;
23import android.view.Gravity;
Jason Monkc34befb2015-10-07 16:40:02 -040024import android.view.View;
25import android.widget.ImageView;
26import android.widget.LinearLayout;
27import com.android.systemui.R;
28
29import java.util.ArrayList;
30import java.util.Collection;
31
32/**
33 * Version of QSPanel that only shows 4 Quick Tiles in the QS Header.
34 */
35public class QuickQSPanel extends QSPanel {
36
37 public QuickQSPanel(Context context, AttributeSet attrs) {
38 super(context, attrs);
39 if (mTileLayout != null) {
40 for (int i = 0; i < mRecords.size(); i++) {
41 mTileLayout.removeTile(mRecords.get(i));
42 }
43 mQsContainer.removeView((View) mTileLayout);
44 }
45 mTileLayout = new HeaderTileLayout(context);
46 mQsContainer.addView((View) mTileLayout, 1 /* Between brightness and footer */);
47 }
48
49 @Override
50 public void onTuningChanged(String key, String newValue) {
51 // No tunings for you.
52 if (key.equals(QS_SHOW_BRIGHTNESS)) {
53 // No Brightness for you.
54 super.onTuningChanged(key, "0");
55 }
56 }
57
58 @Override
59 public void setTiles(Collection<QSTile<?>> tiles) {
60 ArrayList<QSTile<?>> quickTiles = new ArrayList<>();
61 for (QSTile<?> tile : tiles) {
62 if (tile.getTileType() == QSTileView.QS_TYPE_QUICK) {
Jason Monkc133d262015-10-27 12:32:45 -040063 Log.d("QSPanel", "Adding " + tile.getTileSpec());
Jason Monkc34befb2015-10-07 16:40:02 -040064 quickTiles.add(tile);
65 }
Jason Monk94a1bf62015-10-20 08:43:36 -070066 if (quickTiles.size() == 2) {
Jason Monkc34befb2015-10-07 16:40:02 -040067 break;
68 }
69 }
70 super.setTiles(quickTiles);
71 }
72
73 private static class HeaderTileLayout extends LinearLayout implements QSTileLayout {
74
75 public HeaderTileLayout(Context context) {
76 super(context);
Jason Monkc133d262015-10-27 12:32:45 -040077 setGravity(Gravity.CENTER_VERTICAL);
Jason Monkc34befb2015-10-07 16:40:02 -040078 setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
Jason Monkc133d262015-10-27 12:32:45 -040079
80 int padding =
81 mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_padding);
Jason Monkc34befb2015-10-07 16:40:02 -040082 ImageView downArrow = new ImageView(context);
83 downArrow.setImageResource(R.drawable.ic_expand_more);
84 downArrow.setImageTintList(ColorStateList.valueOf(context.getResources().getColor(
85 android.R.color.white, null)));
86 downArrow.setLayoutParams(generateLayoutParams());
Jason Monkc133d262015-10-27 12:32:45 -040087 downArrow.setPadding(padding, padding, padding, padding);
Jason Monkc34befb2015-10-07 16:40:02 -040088 addView(downArrow);
89 setOrientation(LinearLayout.HORIZONTAL);
90 }
91
92 @Override
93 public void addTile(TileRecord tile) {
94 tile.tileView.setLayoutParams(generateLayoutParams());
95 // These shouldn't be normal tiles, but they will be for now so that the circles don't
96 // show up.
97 tile.tileView.setType(QSTileView.QS_TYPE_NORMAL);
98 addView(tile.tileView, getChildCount() - 1 /* Leave icon at end */);
99 }
100
101 private LayoutParams generateLayoutParams() {
Jason Monkc133d262015-10-27 12:32:45 -0400102 int size =
103 mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_size);
104 LayoutParams lp = new LayoutParams(0, size);
Jason Monkc34befb2015-10-07 16:40:02 -0400105 lp.weight = 1;
106 return lp;
107 }
108
109 @Override
110 public void removeTile(TileRecord tile) {
111 removeView(tile.tileView);
112 }
113
114 @Override
115 public void setTileVisibility(TileRecord tile, int visibility) {
116 tile.tileView.setVisibility(visibility);
117 }
118
119 @Override
120 public int getOffsetTop(TileRecord tile) {
121 return 0;
122 }
123
124 @Override
125 public void updateResources() {
126 // No resources here.
127 }
128 }
129}