• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.statusbar.notification;
18 
19 import android.graphics.Color;
20 import android.view.View;
21 import android.widget.ImageView;
22 
23 import com.android.internal.util.NotificationColorUtil;
24 import com.android.systemui.R;
25 import com.android.systemui.statusbar.stack.NotificationChildrenContainer;
26 
27 /**
28  * A util class for various reusable functions
29  */
30 public class NotificationUtils {
31     private static final int[] sLocationBase = new int[2];
32     private static final int[] sLocationOffset = new int[2];
isGrayscale(ImageView v, NotificationColorUtil colorUtil)33     public static boolean isGrayscale(ImageView v, NotificationColorUtil colorUtil) {
34         Object isGrayscale = v.getTag(R.id.icon_is_grayscale);
35         if (isGrayscale != null) {
36             return Boolean.TRUE.equals(isGrayscale);
37         }
38         boolean grayscale = colorUtil.isGrayscaleIcon(v.getDrawable());
39         v.setTag(R.id.icon_is_grayscale, grayscale);
40         return grayscale;
41     }
42 
interpolate(float start, float end, float amount)43     public static float interpolate(float start, float end, float amount) {
44         return start * (1.0f - amount) + end * amount;
45     }
46 
interpolateColors(int startColor, int endColor, float amount)47     public static int interpolateColors(int startColor, int endColor, float amount) {
48         return Color.argb(
49                 (int) interpolate(Color.alpha(startColor), Color.alpha(endColor), amount),
50                 (int) interpolate(Color.red(startColor), Color.red(endColor), amount),
51                 (int) interpolate(Color.green(startColor), Color.green(endColor), amount),
52                 (int) interpolate(Color.blue(startColor), Color.blue(endColor), amount));
53     }
54 
getRelativeYOffset(View offsetView, View baseView)55     public static float getRelativeYOffset(View offsetView, View baseView) {
56         baseView.getLocationOnScreen(sLocationBase);
57         offsetView.getLocationOnScreen(sLocationOffset);
58         return sLocationOffset[1] - sLocationBase[1];
59     }
60 }
61