• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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             title: String = SAMPLE_TITLE1,
59             placeholderColor: Int = DEFAULT_PLACEHOLDER_COLOR,
60             attribution: List<String>? = emptyList(),
61             actionUrl: String? = DEFAULT_ACTION_URL,
62             colors: WallpaperColors = DEFAULT_COLORS,
63             asset: Asset = DEFAULT_ASSET,
64             imageWallpaperUri: Uri = Uri.EMPTY,
65             downloadableWallpaperData: DownloadableWallpaperData? = null,
66             cropHints: Map<Point, Rect> = emptyMap(),
67         ): WallpaperModel.StaticWallpaperModel {
68             return WallpaperModel.StaticWallpaperModel(
69                 commonWallpaperData =
70                     CommonWallpaperData(
71                         id =
72                             WallpaperId(
73                                 ComponentName(
74                                     WallpaperModelFactory.STATIC_WALLPAPER_PACKAGE,
75                                     WallpaperModelFactory.STATIC_WALLPAPER_CLASS,
76                                 ),
77                                 wallpaperId,
78                                 collectionId,
79                             ),
80                         title = title,
81                         attributions = attribution,
82                         exploreActionUrl = actionUrl,
83                         thumbAsset = asset,
84                         placeholderColorInfo = ColorInfo(colors, placeholderColor),
85                         destination = Destination.NOT_APPLIED,
86                     ),
87                 staticWallpaperData = StaticWallpaperData(asset, cropHints),
88                 imageWallpaperData = ImageWallpaperData(imageWallpaperUri),
89                 networkWallpaperData = null,
90                 downloadableWallpaperData = downloadableWallpaperData,
91             )
92         }
93 
getLiveWallpaperModelnull94         fun getLiveWallpaperModel(
95             wallpaperId: String,
96             collectionId: String,
97             placeholderColor: Int = DEFAULT_PLACEHOLDER_COLOR,
98             attribution: List<String>? = emptyList(),
99             actionUrl: String? = DEFAULT_ACTION_URL,
100             colors: WallpaperColors = DEFAULT_COLORS,
101             asset: Asset = DEFAULT_ASSET,
102             groupName: String = DEFAULT_GROUP_NAME,
103             systemWallpaperInfo: WallpaperInfo,
104             isTitleVisible: Boolean = true,
105             isApplied: Boolean = true,
106             effectNames: String? = null,
107             creativeWallpaperData: CreativeWallpaperData? = null,
108             description: WallpaperDescription =
109                 WallpaperDescription.Builder().setComponent(systemWallpaperInfo.component).build(),
110         ): WallpaperModel.LiveWallpaperModel {
111             return WallpaperModel.LiveWallpaperModel(
112                 commonWallpaperData =
113                     CommonWallpaperData(
114                         id = WallpaperId(systemWallpaperInfo.component, wallpaperId, collectionId),
115                         title = SAMPLE_TITLE2,
116                         attributions = attribution,
117                         exploreActionUrl = actionUrl,
118                         thumbAsset = asset,
119                         placeholderColorInfo = ColorInfo(colors, placeholderColor),
120                         destination = Destination.NOT_APPLIED,
121                     ),
122                 liveWallpaperData =
123                     LiveWallpaperData(
124                         groupName = groupName,
125                         systemWallpaperInfo = systemWallpaperInfo,
126                         isTitleVisible = isTitleVisible,
127                         isApplied = isApplied,
128                         isEffectWallpaper = effectNames != null,
129                         effectNames = effectNames,
130                         description = description,
131                     ),
132                 creativeWallpaperData = creativeWallpaperData,
133                 internalLiveWallpaperData = null,
134             )
135         }
136     }
137 }
138