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