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.content.Context; 20 import android.graphics.Color; 21 import android.os.UserHandle; 22 import android.provider.Settings; 23 import android.view.View; 24 import android.widget.ImageView; 25 26 import com.android.internal.util.NotificationColorUtil; 27 import com.android.systemui.R; 28 import com.android.systemui.statusbar.stack.NotificationChildrenContainer; 29 30 /** 31 * A util class for various reusable functions 32 */ 33 public class NotificationUtils { 34 private static final int[] sLocationBase = new int[2]; 35 private static final int[] sLocationOffset = new int[2]; isGrayscale(ImageView v, NotificationColorUtil colorUtil)36 public static boolean isGrayscale(ImageView v, NotificationColorUtil colorUtil) { 37 Object isGrayscale = v.getTag(R.id.icon_is_grayscale); 38 if (isGrayscale != null) { 39 return Boolean.TRUE.equals(isGrayscale); 40 } 41 boolean grayscale = colorUtil.isGrayscaleIcon(v.getDrawable()); 42 v.setTag(R.id.icon_is_grayscale, grayscale); 43 return grayscale; 44 } 45 interpolate(float start, float end, float amount)46 public static float interpolate(float start, float end, float amount) { 47 return start * (1.0f - amount) + end * amount; 48 } 49 interpolateColors(int startColor, int endColor, float amount)50 public static int interpolateColors(int startColor, int endColor, float amount) { 51 return Color.argb( 52 (int) interpolate(Color.alpha(startColor), Color.alpha(endColor), amount), 53 (int) interpolate(Color.red(startColor), Color.red(endColor), amount), 54 (int) interpolate(Color.green(startColor), Color.green(endColor), amount), 55 (int) interpolate(Color.blue(startColor), Color.blue(endColor), amount)); 56 } 57 getRelativeYOffset(View offsetView, View baseView)58 public static float getRelativeYOffset(View offsetView, View baseView) { 59 baseView.getLocationOnScreen(sLocationBase); 60 offsetView.getLocationOnScreen(sLocationOffset); 61 return sLocationOffset[1] - sLocationBase[1]; 62 } 63 64 /** 65 * @param dimenId the dimen to look up 66 * @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp 67 */ getFontScaledHeight(Context context, int dimenId)68 public static int getFontScaledHeight(Context context, int dimenId) { 69 int dimensionPixelSize = context.getResources().getDimensionPixelSize(dimenId); 70 float factor = Math.max(1.0f, context.getResources().getDisplayMetrics().scaledDensity / 71 context.getResources().getDisplayMetrics().density); 72 return (int) (dimensionPixelSize * factor); 73 } 74 } 75