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 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.battery, tintArea, intensity, colorForeground); 73 applyDarkness(R.id.clock, tintArea, intensity, colorForeground); 74 75 BatteryMeterView battery = findViewById(R.id.battery); 76 battery.setForceShowPercent(true); 77 78 mActivityStarter = Dependency.get(ActivityStarter.class); 79 } 80 applyDarkness(int id, Rect tintArea, float intensity, int color)81 private void applyDarkness(int id, Rect tintArea, float intensity, int color) { 82 View v = findViewById(id); 83 if (v instanceof DarkReceiver) { 84 ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color); 85 } 86 } 87 88 @Override onConfigurationChanged(Configuration newConfig)89 protected void onConfigurationChanged(Configuration newConfig) { 90 super.onConfigurationChanged(newConfig); 91 updateResources(); 92 } 93 94 @Override onRtlPropertiesChanged(int layoutDirection)95 public void onRtlPropertiesChanged(int layoutDirection) { 96 super.onRtlPropertiesChanged(layoutDirection); 97 updateResources(); 98 } 99 updateResources()100 private void updateResources() { 101 } 102 getCollapsedHeight()103 public int getCollapsedHeight() { 104 return getHeight(); 105 } 106 getExpandedHeight()107 public int getExpandedHeight() { 108 return getHeight(); 109 } 110 setExpanded(boolean expanded)111 public void setExpanded(boolean expanded) { 112 if (mExpanded == expanded) return; 113 mExpanded = expanded; 114 mHeaderQsPanel.setExpanded(expanded); 115 updateEverything(); 116 } 117 setExpansion(float headerExpansionFraction)118 public void setExpansion(float headerExpansionFraction) { 119 } 120 121 @Override 122 @VisibleForTesting onDetachedFromWindow()123 public void onDetachedFromWindow() { 124 setListening(false); 125 super.onDetachedFromWindow(); 126 } 127 setListening(boolean listening)128 public void setListening(boolean listening) { 129 if (listening == mListening) { 130 return; 131 } 132 mHeaderQsPanel.setListening(listening); 133 mListening = listening; 134 } 135 updateEverything()136 public void updateEverything() { 137 post(() -> setClickable(false)); 138 } 139 setQSPanel(final QSPanel qsPanel)140 public void setQSPanel(final QSPanel qsPanel) { 141 mQsPanel = qsPanel; 142 setupHost(qsPanel.getHost()); 143 } 144 setupHost(final QSTileHost host)145 public void setupHost(final QSTileHost host) { 146 mHost = host; 147 //host.setHeaderView(mExpandIndicator); 148 mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this); 149 mHeaderQsPanel.setHost(host, null /* No customization in header */); 150 } 151 setCallback(Callback qsPanelCallback)152 public void setCallback(Callback qsPanelCallback) { 153 mHeaderQsPanel.setCallback(qsPanelCallback); 154 } 155 } 156