1 /*
2  * Copyright (C) 2023 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.wallpaper.testing
18 
19 import android.app.WallpaperColors
20 import android.app.WallpaperInfo
21 import android.app.wallpaper.WallpaperDescription
22 import android.content.ComponentName
23 import android.graphics.Color
24 import android.graphics.Point
25 import android.graphics.Rect
26 import android.net.Uri
27 import com.android.wallpaper.asset.Asset
28 import com.android.wallpaper.picker.data.ColorInfo
29 import com.android.wallpaper.picker.data.CommonWallpaperData
30 import com.android.wallpaper.picker.data.CreativeWallpaperData
31 import com.android.wallpaper.picker.data.Destination
32 import com.android.wallpaper.picker.data.DownloadableWallpaperData
33 import com.android.wallpaper.picker.data.ImageWallpaperData
34 import com.android.wallpaper.picker.data.LiveWallpaperData
35 import com.android.wallpaper.picker.data.StaticWallpaperData
36 import com.android.wallpaper.picker.data.WallpaperId
37 import com.android.wallpaper.picker.data.WallpaperModel
38 import com.android.wallpaper.util.converter.WallpaperModelFactory
39 
40 class WallpaperModelUtils {
41     companion object {
42         const val SAMPLE_TITLE1 = "wallpaper-1"
43         const val SAMPLE_TITLE2 = "wallpaper-2"
44         const val DEFAULT_PLACEHOLDER_COLOR = 1200
45         const val DEFAULT_ACTION_URL = "http://www.bogus.com"
46         val DEFAULT_COLORS =
47             WallpaperColors(
48                 Color.valueOf(Color.RED),
49                 Color.valueOf(Color.GREEN),
50                 Color.valueOf(Color.BLUE),
51             )
52         val DEFAULT_ASSET = TestAsset(TestStaticWallpaperInfo.COLOR_DEFAULT, false)
53         const val DEFAULT_GROUP_NAME = "group name"
54 
getStaticWallpaperModelnull55         fun getStaticWallpaperModel(
56             wallpaperId: String,
57             collectionId: String,
58             placeholderColor: Int = DEFAULT_PLACEHOLDER_COLOR,
59             attribution: List<String>? = emptyList(),
60             actionUrl: String? = DEFAULT_ACTION_URL,
61             colors: WallpaperColors = DEFAULT_COLORS,
62             asset: Asset = DEFAULT_ASSET,
63             imageWallpaperUri: Uri = Uri.EMPTY,
64             downloadableWallpaperData: DownloadableWallpaperData? = null,
65             cropHints: Map<Point, Rect> = emptyMap(),
66         ): WallpaperModel.StaticWallpaperModel {
67             return WallpaperModel.StaticWallpaperModel(
68                 commonWallpaperData =
69                     CommonWallpaperData(
70                         id =
71                             WallpaperId(
72                                 ComponentName(
73                                     WallpaperModelFactory.STATIC_WALLPAPER_PACKAGE,
74                                     WallpaperModelFactory.STATIC_WALLPAPER_CLASS,
75                                 ),
76                                 wallpaperId,
77                                 collectionId,
78                             ),
79                         title = SAMPLE_TITLE1,
80                         attributions = attribution,
81                         exploreActionUrl = actionUrl,
82                         thumbAsset = asset,
83                         placeholderColorInfo = ColorInfo(colors, placeholderColor),
84                         destination = Destination.NOT_APPLIED,
85                     ),
86                 staticWallpaperData = StaticWallpaperData(asset, cropHints),
87                 imageWallpaperData = ImageWallpaperData(imageWallpaperUri),
88                 networkWallpaperData = null,
89                 downloadableWallpaperData = downloadableWallpaperData,
90             )
91         }
92 
getLiveWallpaperModelnull93         fun getLiveWallpaperModel(
94             wallpaperId: String,
95             collectionId: String,
96             placeholderColor: Int = DEFAULT_PLACEHOLDER_COLOR,
97             attribution: List<String>? = emptyList(),
98             actionUrl: String? = DEFAULT_ACTION_URL,
99             colors: WallpaperColors = DEFAULT_COLORS,
100             asset: Asset = DEFAULT_ASSET,
101             groupName: String = DEFAULT_GROUP_NAME,
102             systemWallpaperInfo: WallpaperInfo,
103             isTitleVisible: Boolean = true,
104             isApplied: Boolean = true,
105             effectNames: String? = null,
106             creativeWallpaperData: CreativeWallpaperData? = null,
107             description: WallpaperDescription =
108                 WallpaperDescription.Builder().setComponent(systemWallpaperInfo.component).build(),
109         ): WallpaperModel.LiveWallpaperModel {
110             return WallpaperModel.LiveWallpaperModel(
111                 commonWallpaperData =
112                     CommonWallpaperData(
113                         id = WallpaperId(systemWallpaperInfo.component, wallpaperId, collectionId),
114                         title = SAMPLE_TITLE2,
115                         attributions = attribution,
116                         exploreActionUrl = actionUrl,
117                         thumbAsset = asset,
118                         placeholderColorInfo = ColorInfo(colors, placeholderColor),
119                         destination = Destination.NOT_APPLIED,
120                     ),
121                 liveWallpaperData =
122                     LiveWallpaperData(
123                         groupName = groupName,
124                         systemWallpaperInfo = systemWallpaperInfo,
125                         isTitleVisible = isTitleVisible,
126                         isApplied = isApplied,
127                         isEffectWallpaper = effectNames != null,
128                         effectNames = effectNames,
129                         description = description,
130                     ),
131                 creativeWallpaperData = creativeWallpaperData,
132                 internalLiveWallpaperData = null,
133             )
134         }
135     }
136 }
137