/* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.launcher3.icons; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import androidx.annotation.NonNull; public class BitmapInfo { public static final Bitmap LOW_RES_ICON = Bitmap.createBitmap(1, 1, Config.ALPHA_8); public static final BitmapInfo LOW_RES_INFO = fromBitmap(LOW_RES_ICON); public final Bitmap icon; public final int color; public BitmapInfo(Bitmap icon, int color) { this.icon = icon; this.color = color; } /** * Ideally icon should not be null, except in cases when generating hardware bitmap failed */ public final boolean isNullOrLowRes() { return icon == null || icon == LOW_RES_ICON; } public final boolean isLowRes() { return LOW_RES_ICON == icon; } public static BitmapInfo fromBitmap(@NonNull Bitmap bitmap) { return of(bitmap, 0); } public static BitmapInfo of(@NonNull Bitmap bitmap, int color) { return new BitmapInfo(bitmap, color); } /** * Interface to be implemented by drawables to provide a custom BitmapInfo */ public interface Extender { /** * Called for creating a custom BitmapInfo */ default BitmapInfo getExtendedInfo(Bitmap bitmap, int color, BaseIconFactory iconFactory) { return BitmapInfo.of(bitmap, color); } /** * Notifies the drawable that it will be drawn directly in the UI, without any preprocessing */ default void prepareToDrawOnUi() { } } }