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 15 package com.android.systemui.qs; 16 17 import android.content.Context; 18 import android.content.res.Configuration; 19 import android.content.res.Resources; 20 import android.graphics.Color; 21 import android.graphics.Rect; 22 import android.support.annotation.VisibleForTesting; 23 import android.util.AttributeSet; 24 import android.view.View; 25 import android.widget.RelativeLayout; 26 import android.widget.TextClock; 27 28 import com.android.settingslib.Utils; 29 import com.android.systemui.BatteryMeterView; 30 import com.android.systemui.Dependency; 31 import com.android.systemui.R; 32 import com.android.systemui.R.id; 33 import com.android.systemui.plugins.ActivityStarter; 34 import com.android.systemui.qs.QSDetail.Callback; 35 import com.android.systemui.statusbar.SignalClusterView; 36 import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver; 37 38 39 public class QuickStatusBarHeader extends RelativeLayout { 40 41 private ActivityStarter mActivityStarter; 42 43 private QSPanel mQsPanel; 44 45 private boolean mExpanded; 46 private boolean mListening; 47 48 protected QuickQSPanel mHeaderQsPanel; 49 protected QSTileHost mHost; 50 QuickStatusBarHeader(Context context, AttributeSet attrs)51 public QuickStatusBarHeader(Context context, AttributeSet attrs) { 52 super(context, attrs); 53 } 54 55 @Override onFinishInflate()56 protected void onFinishInflate() { 57 super.onFinishInflate(); 58 Resources res = getResources(); 59 60 mHeaderQsPanel = findViewById(R.id.quick_qs_panel); 61 mHeaderQsPanel.setVisibility(res.getBoolean(R.bool.config_showQuickSettingsRow) 62 ? VISIBLE : GONE); 63 64 // RenderThread is doing more harm than good when touching the header (to expand quick 65 // settings), so disable it for this view 66 67 updateResources(); 68 69 // Set the light/dark theming on the header status UI to match the current theme. 70 int colorForeground = Utils.getColorAttr(getContext(), android.R.attr.colorForeground); 71 float intensity = colorForeground == Color.WHITE ? 0 : 1; 72 Rect tintArea = new Rect(0, 0, 0, 0); 73 74 applyDarkness(R.id.battery, tintArea, intensity, colorForeground); 75 applyDarkness(R.id.clock, tintArea, intensity, colorForeground); 76 77 BatteryMeterView battery = findViewById(R.id.battery); 78 battery.setForceShowPercent(true); 79 80 mActivityStarter = Dependency.get(ActivityStarter.class); 81 } 82 applyDarkness(int id, Rect tintArea, float intensity, int color)83 private void applyDarkness(int id, Rect tintArea, float intensity, int color) { 84 View v = findViewById(id); 85 if (v instanceof DarkReceiver) { 86 ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color); 87 } 88 } 89 90 @Override onConfigurationChanged(Configuration newConfig)91 protected void onConfigurationChanged(Configuration newConfig) { 92 super.onConfigurationChanged(newConfig); 93 updateResources(); 94 } 95 96 @Override onRtlPropertiesChanged(int layoutDirection)97 public void onRtlPropertiesChanged(int layoutDirection) { 98 super.onRtlPropertiesChanged(layoutDirection); 99 updateResources(); 100 } 101 updateResources()102 private void updateResources() { 103 } 104 getCollapsedHeight()105 public int getCollapsedHeight() { 106 return getHeight(); 107 } 108 getExpandedHeight()109 public int getExpandedHeight() { 110 return getHeight(); 111 } 112 setExpanded(boolean expanded)113 public void setExpanded(boolean expanded) { 114 if (mExpanded == expanded) return; 115 mExpanded = expanded; 116 mHeaderQsPanel.setExpanded(expanded); 117 updateEverything(); 118 } 119 setExpansion(float headerExpansionFraction)120 public void setExpansion(float headerExpansionFraction) { 121 } 122 123 @Override 124 @VisibleForTesting onDetachedFromWindow()125 public void onDetachedFromWindow() { 126 setListening(false); 127 super.onDetachedFromWindow(); 128 } 129 setListening(boolean listening)130 public void setListening(boolean listening) { 131 if (listening == mListening) { 132 return; 133 } 134 mHeaderQsPanel.setListening(listening); 135 mListening = listening; 136 } 137 updateEverything()138 public void updateEverything() { 139 post(() -> setClickable(false)); 140 } 141 setQSPanel(final QSPanel qsPanel)142 public void setQSPanel(final QSPanel qsPanel) { 143 mQsPanel = qsPanel; 144 setupHost(qsPanel.getHost()); 145 } 146 setupHost(final QSTileHost host)147 public void setupHost(final QSTileHost host) { 148 mHost = host; 149 //host.setHeaderView(mExpandIndicator); 150 mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this); 151 mHeaderQsPanel.setHost(host, null /* No customization in header */); 152 } 153 setCallback(Callback qsPanelCallback)154 public void setCallback(Callback qsPanelCallback) { 155 mHeaderQsPanel.setCallback(qsPanelCallback); 156 } 157 } 158