• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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.row.shared
18 
19 import android.graphics.drawable.Drawable
20 import android.graphics.drawable.Icon
21 
22 /**
23  * An interface which allows the background inflation process, when loading content from a
24  * notification, to acquire a [ImageModel] that can be used later in the inflation process to access
25  * the actual [Drawable] which it represents.
26  */
27 interface ImageModelProvider {
28     /**
29      * Defines the rough size we expect the image to be. We use this abstraction to reduce memory
30      * footprint without coupling image loading to the view layer.
31      */
32     enum class ImageSizeClass {
33         /** Roughly 24dp */
34         SmallSquare,
35 
36         /** Around 48dp */
37         MediumSquare,
38 
39         /** About as wide as a notification. */
40         LargeWide,
41     }
42 
43     /**
44      * This is the base class for an image transform that allows the loaded icon to be altered in
45      * some way (other than resizing) prior to being indexed. This transform will be used as part of
46      * the index key.
47      */
48     abstract class ImageTransform(val key: String) {
49         open val requiresSoftwareBitmapInput: Boolean = false
50 
transformDrawablenull51         abstract fun transformDrawable(input: Drawable): Drawable?
52 
53         final override fun equals(other: Any?): Boolean {
54             if (this === other) return true
55             if (other == null) return false
56             if (other !is ImageTransform) return false
57             return key == other.key
58         }
59 
hashCodenull60         final override fun hashCode(): Int {
61             return key.hashCode()
62         }
63     }
64 
65     /** The default passthrough transform for images */
66     object IdentityImageTransform : ImageTransform("Identity") {
transformDrawablenull67         override fun transformDrawable(input: Drawable) = input
68     }
69 
70     /** Returns an [ImageModel] which will provide access to a [Drawable] in the future. */
71     fun getImageModel(
72         icon: Icon,
73         sizeClass: ImageSizeClass,
74         transform: ImageTransform = IdentityImageTransform,
75     ): ImageModel?
76 }
77