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