QuickStatusBarHeader.java revision 10b4c8a4ab3fc1fd55e5a636066e210ad17cf92b
1/* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15package com.android.systemui.qs; 16 17import android.content.Context; 18import android.content.res.Configuration; 19import android.content.res.Resources; 20import android.graphics.Color; 21import android.graphics.Rect; 22import android.support.annotation.VisibleForTesting; 23import android.util.AttributeSet; 24import android.view.View; 25import android.widget.RelativeLayout; 26 27import com.android.settingslib.Utils; 28import com.android.systemui.BatteryMeterView; 29import com.android.systemui.Dependency; 30import com.android.systemui.R; 31import com.android.systemui.plugins.ActivityStarter; 32import com.android.systemui.qs.QSDetail.Callback; 33import com.android.systemui.statusbar.SignalClusterView; 34import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver; 35 36 37public class QuickStatusBarHeader extends RelativeLayout { 38 39 private ActivityStarter mActivityStarter; 40 41 private QSPanel mQsPanel; 42 43 private boolean mExpanded; 44 private boolean mListening; 45 46 protected QuickQSPanel mHeaderQsPanel; 47 protected QSTileHost mHost; 48 49 public QuickStatusBarHeader(Context context, AttributeSet attrs) { 50 super(context, attrs); 51 } 52 53 @Override 54 protected void onFinishInflate() { 55 super.onFinishInflate(); 56 Resources res = getResources(); 57 58 mHeaderQsPanel = findViewById(R.id.quick_qs_panel); 59 mHeaderQsPanel.setVisibility(res.getBoolean(R.bool.config_showQuickSettingsRow) 60 ? VISIBLE : GONE); 61 62 // RenderThread is doing more harm than good when touching the header (to expand quick 63 // settings), so disable it for this view 64 65 updateResources(); 66 67 // Set the light/dark theming on the header status UI to match the current theme. 68 int colorForeground = Utils.getColorAttr(getContext(), android.R.attr.colorForeground); 69 float intensity = colorForeground == Color.WHITE ? 0 : 1; 70 Rect tintArea = new Rect(0, 0, 0, 0); 71 72 applyDarkness(R.id.signal_cluster, tintArea, intensity, colorForeground); 73 applyDarkness(R.id.battery, tintArea, intensity, colorForeground); 74 applyDarkness(R.id.clock, tintArea, intensity, colorForeground); 75 76 BatteryMeterView battery = findViewById(R.id.battery); 77 battery.setForceShowPercent(true); 78 // Don't show the Wi-Fi indicator here, because it is shown just below in the tile. 79 SignalClusterView signalCluster = findViewById(R.id.signal_cluster); 80 signalCluster.setQsSignalCluster(); 81 82 mActivityStarter = Dependency.get(ActivityStarter.class); 83 } 84 85 private void applyDarkness(int id, Rect tintArea, float intensity, int color) { 86 View v = findViewById(id); 87 if (v instanceof DarkReceiver) { 88 ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color); 89 } 90 } 91 92 @Override 93 protected void onConfigurationChanged(Configuration newConfig) { 94 super.onConfigurationChanged(newConfig); 95 updateResources(); 96 } 97 98 @Override 99 public void onRtlPropertiesChanged(int layoutDirection) { 100 super.onRtlPropertiesChanged(layoutDirection); 101 updateResources(); 102 } 103 104 private void updateResources() { 105 } 106 107 public int getCollapsedHeight() { 108 return getHeight(); 109 } 110 111 public int getExpandedHeight() { 112 return getHeight(); 113 } 114 115 public void setExpanded(boolean expanded) { 116 if (mExpanded == expanded) return; 117 mExpanded = expanded; 118 mHeaderQsPanel.setExpanded(expanded); 119 updateEverything(); 120 } 121 122 public void setExpansion(float headerExpansionFraction) { 123 } 124 125 @Override 126 @VisibleForTesting 127 public void onDetachedFromWindow() { 128 setListening(false); 129 super.onDetachedFromWindow(); 130 } 131 132 public void setListening(boolean listening) { 133 if (listening == mListening) { 134 return; 135 } 136 mHeaderQsPanel.setListening(listening); 137 mListening = listening; 138 } 139 140 public void updateEverything() { 141 post(() -> setClickable(false)); 142 } 143 144 public void setQSPanel(final QSPanel qsPanel) { 145 mQsPanel = qsPanel; 146 setupHost(qsPanel.getHost()); 147 } 148 149 public void setupHost(final QSTileHost host) { 150 mHost = host; 151 //host.setHeaderView(mExpandIndicator); 152 mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this); 153 mHeaderQsPanel.setHost(host, null /* No customization in header */); 154 } 155 156 public void setCallback(Callback qsPanelCallback) { 157 mHeaderQsPanel.setCallback(qsPanelCallback); 158 } 159} 160