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; |
| 22 | import android.view.View; |
| 23 | import android.widget.ImageView; |
| 24 | import android.widget.LinearLayout; |
| 25 | import com.android.systemui.R; |
| 26 | |
| 27 | import java.util.ArrayList; |
| 28 | import java.util.Collection; |
| 29 | |
| 30 | /** |
| 31 | * Version of QSPanel that only shows 4 Quick Tiles in the QS Header. |
| 32 | */ |
| 33 | public class QuickQSPanel extends QSPanel { |
| 34 | |
| 35 | public QuickQSPanel(Context context, AttributeSet attrs) { |
| 36 | super(context, attrs); |
| 37 | if (mTileLayout != null) { |
| 38 | for (int i = 0; i < mRecords.size(); i++) { |
| 39 | mTileLayout.removeTile(mRecords.get(i)); |
| 40 | } |
| 41 | mQsContainer.removeView((View) mTileLayout); |
| 42 | } |
| 43 | mTileLayout = new HeaderTileLayout(context); |
| 44 | mQsContainer.addView((View) mTileLayout, 1 /* Between brightness and footer */); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public void onTuningChanged(String key, String newValue) { |
| 49 | // No tunings for you. |
| 50 | if (key.equals(QS_SHOW_BRIGHTNESS)) { |
| 51 | // No Brightness for you. |
| 52 | super.onTuningChanged(key, "0"); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public void setTiles(Collection<QSTile<?>> tiles) { |
| 58 | ArrayList<QSTile<?>> quickTiles = new ArrayList<>(); |
| 59 | for (QSTile<?> tile : tiles) { |
| 60 | if (tile.getTileType() == QSTileView.QS_TYPE_QUICK) { |
| 61 | quickTiles.add(tile); |
| 62 | } |
| 63 | if (quickTiles.size() == 4) { |
| 64 | break; |
| 65 | } |
| 66 | } |
| 67 | super.setTiles(quickTiles); |
| 68 | } |
| 69 | |
| 70 | private static class HeaderTileLayout extends LinearLayout implements QSTileLayout { |
| 71 | |
| 72 | public HeaderTileLayout(Context context) { |
| 73 | super(context); |
| 74 | setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); |
| 75 | int qsCompensation = (int) |
| 76 | context.getResources().getDimension(R.dimen.qs_header_neg_padding); |
| 77 | setPadding(0, qsCompensation, 0, 0); |
| 78 | ImageView downArrow = new ImageView(context); |
| 79 | downArrow.setImageResource(R.drawable.ic_expand_more); |
| 80 | downArrow.setImageTintList(ColorStateList.valueOf(context.getResources().getColor( |
| 81 | android.R.color.white, null))); |
| 82 | downArrow.setLayoutParams(generateLayoutParams()); |
| 83 | downArrow.setPadding(0, -qsCompensation, 0, 0); |
| 84 | addView(downArrow); |
| 85 | setOrientation(LinearLayout.HORIZONTAL); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public void addTile(TileRecord tile) { |
| 90 | tile.tileView.setLayoutParams(generateLayoutParams()); |
| 91 | // These shouldn't be normal tiles, but they will be for now so that the circles don't |
| 92 | // show up. |
| 93 | tile.tileView.setType(QSTileView.QS_TYPE_NORMAL); |
| 94 | addView(tile.tileView, getChildCount() - 1 /* Leave icon at end */); |
| 95 | } |
| 96 | |
| 97 | private LayoutParams generateLayoutParams() { |
| 98 | LayoutParams lp = new LayoutParams(0, LayoutParams.MATCH_PARENT); |
| 99 | lp.weight = 1; |
| 100 | return lp; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public void removeTile(TileRecord tile) { |
| 105 | removeView(tile.tileView); |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public void setTileVisibility(TileRecord tile, int visibility) { |
| 110 | tile.tileView.setVisibility(visibility); |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public int getOffsetTop(TileRecord tile) { |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public void updateResources() { |
| 120 | // No resources here. |
| 121 | } |
| 122 | } |
| 123 | } |