Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.qs; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.content.res.ColorStateList; |
| 21 | import android.util.AttributeSet; |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 22 | import android.view.Gravity; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 23 | import android.view.View; |
| 24 | import android.widget.ImageView; |
| 25 | import android.widget.LinearLayout; |
| 26 | import com.android.systemui.R; |
| 27 | |
| 28 | import java.util.ArrayList; |
| 29 | import java.util.Collection; |
| 30 | |
| 31 | /** |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame^] | 32 | * Version of QSPanel that only shows N Quick Tiles in the QS Header. |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 33 | */ |
| 34 | public class QuickQSPanel extends QSPanel { |
| 35 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame^] | 36 | private int mMaxTiles; |
| 37 | private QSPanel mFullPanel; |
| 38 | private View mHeader; |
| 39 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 40 | 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 Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame^] | 52 | 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 Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 82 | @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 Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame^] | 95 | quickTiles.add(tile); |
| 96 | if (quickTiles.size() == mMaxTiles) { |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 97 | 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 Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame^] | 107 | setClipChildren(false); |
| 108 | setClipToPadding(false); |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 109 | setGravity(Gravity.CENTER_VERTICAL); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 110 | setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 111 | |
| 112 | int padding = |
| 113 | mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_padding); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 114 | 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 Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 119 | downArrow.setPadding(padding, padding, padding, padding); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 120 | addView(downArrow); |
| 121 | setOrientation(LinearLayout.HORIZONTAL); |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public void addTile(TileRecord tile) { |
| 126 | tile.tileView.setLayoutParams(generateLayoutParams()); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 127 | addView(tile.tileView, getChildCount() - 1 /* Leave icon at end */); |
| 128 | } |
| 129 | |
| 130 | private LayoutParams generateLayoutParams() { |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 131 | int size = |
| 132 | mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_size); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame^] | 133 | LayoutParams lp = new LayoutParams(size, size); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 134 | 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 | } |