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 package com.android.systemui.qs.car; 15 16 import android.content.Context; 17 import android.graphics.Color; 18 import android.graphics.Rect; 19 import android.support.annotation.IdRes; 20 import android.util.AttributeSet; 21 import android.view.View; 22 import android.widget.LinearLayout; 23 24 import com.android.settingslib.Utils; 25 import com.android.systemui.BatteryMeterView; 26 import com.android.systemui.R; 27 import com.android.systemui.statusbar.policy.DarkIconDispatcher; 28 29 /** 30 * A view that forms the header of the notification panel. This view will ensure that any 31 * status icons that are displayed are tinted accordingly to the current theme. 32 */ 33 public class CarStatusBarHeader extends LinearLayout { 34 public CarStatusBarHeader(Context context, AttributeSet attrs) { 35 super(context, attrs); 36 } 37 38 @Override 39 protected void onFinishInflate() { 40 super.onFinishInflate(); 41 42 // Set the light/dark theming on the header status UI to match the current theme. 43 int colorForeground = Utils.getColorAttr(getContext(), android.R.attr.colorForeground); 44 float intensity = colorForeground == Color.WHITE ? 0f : 1f; 45 Rect tintArea = new Rect(0, 0, 0, 0); 46 47 applyDarkness(R.id.battery, tintArea, intensity, colorForeground); 48 applyDarkness(R.id.clock, tintArea, intensity, colorForeground); 49 50 ((BatteryMeterView) findViewById(R.id.battery)).setForceShowPercent(true); 51 } 52 53 private void applyDarkness(@IdRes int id, Rect tintArea, float intensity, int color) { 54 View v = findViewById(id); 55 if (v instanceof DarkIconDispatcher.DarkReceiver) { 56 ((DarkIconDispatcher.DarkReceiver) v).onDarkChanged(tintArea, intensity, color); 57 } 58 } 59 } 60