blob: 945ed761c2b4f7afaa963cf9b3e3fe3f94c178e7 [file] [log] [blame]
Jason Monkaa573e92017-01-27 17:00:29 -05001/*
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.statusbar.policy;
16
17import android.graphics.Color;
18import android.graphics.Rect;
19import android.view.View;
20import android.widget.ImageView;
21
22import com.android.systemui.statusbar.phone.LightBarTransitionsController;
23
24public interface DarkIconDispatcher {
25
26 void setIconsDarkArea(Rect r);
27 LightBarTransitionsController getTransitionsController();
28
29 void addDarkReceiver(DarkReceiver receiver);
30 void addDarkReceiver(ImageView imageView);
31
32 // Must have been previously been added through one of the addDarkReceive methods above.
33 void removeDarkReceiver(DarkReceiver object);
34 void removeDarkReceiver(ImageView object);
35
36 // Used to reapply darkness on an object, must have previously been added through
37 // addDarkReceiver.
Evan Lairde1d13c92018-03-20 16:58:01 -040038 void applyDark(DarkReceiver object);
Jason Monkaa573e92017-01-27 17:00:29 -050039
40 int DEFAULT_ICON_TINT = Color.WHITE;
41 Rect sTmpRect = new Rect();
42 int[] sTmpInt2 = new int[2];
43
44 /**
45 * @return the tint to apply to {@param view} depending on the desired tint {@param color} and
46 * the screen {@param tintArea} in which to apply that tint
47 */
48 static int getTint(Rect tintArea, View view, int color) {
49 if (isInArea(tintArea, view)) {
50 return color;
51 } else {
52 return DEFAULT_ICON_TINT;
53 }
54 }
55
56 /**
57 * @return the dark intensity to apply to {@param view} depending on the desired dark
58 * {@param intensity} and the screen {@param tintArea} in which to apply that intensity
59 */
60 static float getDarkIntensity(Rect tintArea, View view, float intensity) {
61 if (isInArea(tintArea, view)) {
62 return intensity;
63 } else {
64 return 0f;
65 }
66 }
67
68 /**
69 * @return true if more than half of the {@param view} area are in {@param area}, false
70 * otherwise
71 */
72 static boolean isInArea(Rect area, View view) {
73 if (area.isEmpty()) {
74 return true;
75 }
76 sTmpRect.set(area);
77 view.getLocationOnScreen(sTmpInt2);
78 int left = sTmpInt2[0];
79
80 int intersectStart = Math.max(left, area.left);
81 int intersectEnd = Math.min(left + view.getWidth(), area.right);
82 int intersectAmount = Math.max(0, intersectEnd - intersectStart);
83
84 boolean coversFullStatusBar = area.top <= 0;
85 boolean majorityOfWidth = 2 * intersectAmount > view.getWidth();
86 return majorityOfWidth && coversFullStatusBar;
87 }
88
89 interface DarkReceiver {
90 void onDarkChanged(Rect area, float darkIntensity, int tint);
91 }
92}