1eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek/* 2eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek * Copyright (C) 2015 The Android Open Source Project 3eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek * 4eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek * Licensed under the Apache License, Version 2.0 (the "License"); 5eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek * you may not use this file except in compliance with the License. 6eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek * You may obtain a copy of the License at 7eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek * 8eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek * http://www.apache.org/licenses/LICENSE-2.0 9eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek * 10eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek * Unless required by applicable law or agreed to in writing, software 11eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek * distributed under the License is distributed on an "AS IS" BASIS, 12eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek * See the License for the specific language governing permissions and 14eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek * limitations under the License 15eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek */ 16eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek 17eef842851026a90b6a217d8bc423454fa48df4feSelim Cinekpackage com.android.systemui.statusbar.notification; 18eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek 19c317933a91b1d33cc4af9b7c6218b9ce675d05eaSelim Cinekimport android.graphics.Color; 20c897bd3e91ed442b0f32c3a5b9918e9e580b62b1Selim Cinekimport android.view.View; 21eef842851026a90b6a217d8bc423454fa48df4feSelim Cinekimport android.widget.ImageView; 22eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek 23eef842851026a90b6a217d8bc423454fa48df4feSelim Cinekimport com.android.internal.util.NotificationColorUtil; 24eef842851026a90b6a217d8bc423454fa48df4feSelim Cinekimport com.android.systemui.R; 25c897bd3e91ed442b0f32c3a5b9918e9e580b62b1Selim Cinekimport com.android.systemui.statusbar.stack.NotificationChildrenContainer; 26eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek 27eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek/** 28eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek * A util class for various reusable functions 29eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek */ 30eef842851026a90b6a217d8bc423454fa48df4feSelim Cinekpublic class NotificationUtils { 31c897bd3e91ed442b0f32c3a5b9918e9e580b62b1Selim Cinek private static final int[] sLocationBase = new int[2]; 32c897bd3e91ed442b0f32c3a5b9918e9e580b62b1Selim Cinek private static final int[] sLocationOffset = new int[2]; 33eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek public static boolean isGrayscale(ImageView v, NotificationColorUtil colorUtil) { 34eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek Object isGrayscale = v.getTag(R.id.icon_is_grayscale); 35eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek if (isGrayscale != null) { 36eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek return Boolean.TRUE.equals(isGrayscale); 37eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek } 38eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek boolean grayscale = colorUtil.isGrayscaleIcon(v.getDrawable()); 39eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek v.setTag(R.id.icon_is_grayscale, grayscale); 40eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek return grayscale; 41eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek } 428f2f6a67fad7aed720e33a6629cb65d368ebfb80Selim Cinek 438f2f6a67fad7aed720e33a6629cb65d368ebfb80Selim Cinek public static float interpolate(float start, float end, float amount) { 448f2f6a67fad7aed720e33a6629cb65d368ebfb80Selim Cinek return start * (1.0f - amount) + end * amount; 458f2f6a67fad7aed720e33a6629cb65d368ebfb80Selim Cinek } 46c317933a91b1d33cc4af9b7c6218b9ce675d05eaSelim Cinek 47c317933a91b1d33cc4af9b7c6218b9ce675d05eaSelim Cinek public static int interpolateColors(int startColor, int endColor, float amount) { 48c317933a91b1d33cc4af9b7c6218b9ce675d05eaSelim Cinek return Color.argb( 49c317933a91b1d33cc4af9b7c6218b9ce675d05eaSelim Cinek (int) interpolate(Color.alpha(startColor), Color.alpha(endColor), amount), 50c317933a91b1d33cc4af9b7c6218b9ce675d05eaSelim Cinek (int) interpolate(Color.red(startColor), Color.red(endColor), amount), 51c317933a91b1d33cc4af9b7c6218b9ce675d05eaSelim Cinek (int) interpolate(Color.green(startColor), Color.green(endColor), amount), 52c317933a91b1d33cc4af9b7c6218b9ce675d05eaSelim Cinek (int) interpolate(Color.blue(startColor), Color.blue(endColor), amount)); 53c317933a91b1d33cc4af9b7c6218b9ce675d05eaSelim Cinek } 54c897bd3e91ed442b0f32c3a5b9918e9e580b62b1Selim Cinek 55c897bd3e91ed442b0f32c3a5b9918e9e580b62b1Selim Cinek public static float getRelativeYOffset(View offsetView, View baseView) { 56c897bd3e91ed442b0f32c3a5b9918e9e580b62b1Selim Cinek baseView.getLocationOnScreen(sLocationBase); 57c897bd3e91ed442b0f32c3a5b9918e9e580b62b1Selim Cinek offsetView.getLocationOnScreen(sLocationOffset); 58c897bd3e91ed442b0f32c3a5b9918e9e580b62b1Selim Cinek return sLocationOffset[1] - sLocationBase[1]; 59c897bd3e91ed442b0f32c3a5b9918e9e580b62b1Selim Cinek } 60eef842851026a90b6a217d8bc423454fa48df4feSelim Cinek} 61