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.util.Log; |
| 23 | import android.view.Gravity; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 24 | import android.view.View; |
| 25 | import android.widget.ImageView; |
| 26 | import android.widget.LinearLayout; |
| 27 | import com.android.systemui.R; |
| 28 | |
| 29 | import java.util.ArrayList; |
| 30 | import java.util.Collection; |
| 31 | |
| 32 | /** |
| 33 | * Version of QSPanel that only shows 4 Quick Tiles in the QS Header. |
| 34 | */ |
| 35 | public 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 Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame^] | 63 | Log.d("QSPanel", "Adding " + tile.getTileSpec()); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 64 | quickTiles.add(tile); |
| 65 | } |
Jason Monk | 94a1bf6 | 2015-10-20 08:43:36 -0700 | [diff] [blame] | 66 | if (quickTiles.size() == 2) { |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 67 | 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 Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame^] | 77 | setGravity(Gravity.CENTER_VERTICAL); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 78 | setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame^] | 79 | |
| 80 | int padding = |
| 81 | mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_padding); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 82 | 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 Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame^] | 87 | downArrow.setPadding(padding, padding, padding, padding); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 88 | 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 Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame^] | 102 | int size = |
| 103 | mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_size); |
| 104 | LayoutParams lp = new LayoutParams(0, size); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 105 | 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 | } |