1 /*
2  * Copyright (C) 2017 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 package com.android.launcher3.icons;
17 
18 import android.graphics.Bitmap;
19 import android.graphics.Bitmap.Config;
20 
21 public class BitmapInfo {
22 
23     public static final Bitmap LOW_RES_ICON = Bitmap.createBitmap(1, 1, Config.ALPHA_8);
24 
25     public Bitmap icon;
26     public int color;
27 
applyTo(BitmapInfo info)28     public void applyTo(BitmapInfo info) {
29         info.icon = icon;
30         info.color = color;
31     }
32 
isLowRes()33     public final boolean isLowRes() {
34         return LOW_RES_ICON == icon;
35     }
36 
fromBitmap(Bitmap bitmap)37     public static BitmapInfo fromBitmap(Bitmap bitmap) {
38         return fromBitmap(bitmap, null);
39     }
40 
fromBitmap(Bitmap bitmap, ColorExtractor dominantColorExtractor)41     public static BitmapInfo fromBitmap(Bitmap bitmap, ColorExtractor dominantColorExtractor) {
42         BitmapInfo info = new BitmapInfo();
43         info.icon = bitmap;
44         info.color = dominantColorExtractor != null
45                 ? dominantColorExtractor.findDominantColorByHue(bitmap)
46                 : 0;
47         return info;
48     }
49 }
50