blob: 2f605c0b27a4e2bb307c8546cc70b09cce800476 [file] [log] [blame]
Jon Miranda16ea1b12017-12-12 14:52:48 -08001/*
2 * Copyright (C) 2017 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 */
16package com.android.wallpaper.model;
17
18import android.app.Activity;
19import android.content.Context;
20import android.graphics.drawable.Drawable;
Clément Julliardea1638d2018-05-21 19:15:17 -070021import android.net.Uri;
Jon Miranda16ea1b12017-12-12 14:52:48 -080022import android.os.Parcelable;
Jon Miranda16ea1b12017-12-12 14:52:48 -080023
Santiago Etchebehered1bd5092018-04-18 16:03:30 -070024import com.android.wallpaper.R;
Jon Miranda16ea1b12017-12-12 14:52:48 -080025import com.android.wallpaper.asset.Asset;
26
27import java.util.List;
28
Sunny Goyal8600a3f2018-08-15 12:48:01 -070029import androidx.annotation.DrawableRes;
30import androidx.annotation.IntDef;
31import androidx.annotation.StringRes;
32
Jon Miranda16ea1b12017-12-12 14:52:48 -080033/**
34 * Interface for wallpaper info model.
35 */
36public abstract class WallpaperInfo implements Parcelable {
37
Santiago Etchebehered1bd5092018-04-18 16:03:30 -070038 @DrawableRes
39 public static int getDefaultActionIcon() {
40 return R.drawable.ic_explore_24px;
41 }
42
43 @StringRes
44 public static int getDefaultActionLabel() {
45 return R.string.explore;
46 }
47
Jon Miranda16ea1b12017-12-12 14:52:48 -080048 public static final int BACKUP_NOT_ALLOWED = 0;
49 public static final int BACKUP_ALLOWED = 1;
50
51 /**
52 * @param context
53 * @return The title for this wallpaper, if applicable (as in a wallpaper "app" or live
54 * wallpaper), or null if not applicable.
55 */
56 public String getTitle(Context context) {
57 return null;
58 }
59
60 /**
61 * @param context
62 * @return The available attributions for this wallpaper, as a list of strings.
63 */
64 public abstract List<String> getAttributions(Context context);
65
66 /**
67 * Returns the base (remote) image URL for this wallpaper, or null if none exists.
68 */
69 public String getBaseImageUrl() {
70 return null;
71 }
72
73 /**
74 * Returns the action or "explore" URL for the wallpaper, or null if none exists.
75 */
76 public String getActionUrl(Context unused) {
77 return null;
78 }
79
Clément Julliardea1638d2018-05-21 19:15:17 -070080 /** Returns the URI corresponding to the wallpaper, or null if none exists. */
81 public Uri getUri() {
82 return null;
83 }
84
Jon Miranda16ea1b12017-12-12 14:52:48 -080085 /**
Santiago Etchebehered1bd5092018-04-18 16:03:30 -070086 * Returns the icon to use to represent the action link corresponding to
87 * {@link #getActionUrl(Context)}
88 */
89 @DrawableRes
Santiago Etchebeheree0810d02018-05-10 17:39:40 -070090 public int getActionIconRes(Context context) {
Santiago Etchebehered1bd5092018-04-18 16:03:30 -070091 return getDefaultActionIcon();
92 }
93
94 /**
95 * Returns the label to use for the action link corresponding to
96 * {@link #getActionUrl(Context)}
97 */
98 @StringRes
Santiago Etchebeheree0810d02018-05-10 17:39:40 -070099 public int getActionLabelRes(Context context) {
Santiago Etchebehered1bd5092018-04-18 16:03:30 -0700100 return getDefaultActionLabel();
101 }
102
103 /**
Jon Miranda16ea1b12017-12-12 14:52:48 -0800104 * @param context
105 * @return An overlay icon to be used instead of a thumbnail, if appropriate, or null if not
106 * applicable.
107 */
108 public Drawable getOverlayIcon(Context context) {
109 return null;
110 }
111
112 ;
113
114 @Override
115 public int describeContents() {
116 return 0;
117 }
118
119 /**
120 * @param context The client application's context.
121 * @return The {@link Asset} representing the wallpaper image.
122 */
123 public abstract Asset getAsset(Context context);
124
125 /**
126 * @param context The client application's context.
127 * @return The {@link Asset} representing the wallpaper's thumbnail.
128 */
129 public abstract Asset getThumbAsset(Context context);
130
131 /**
132 * @param context The client application's context.
133 * @return An {@link Asset} that is appropriately sized to be directly set to the desktop. By
134 * default, this just the full wallpaper image asset (#getAsset) but subclasses may provide an
135 * Asset sized exactly for the device's primary display (i.e., cropped prior to providing a
136 * bitmap or input stream).
137 */
138 public Asset getDesktopAsset(Context context) {
139 return getAsset(context);
140 }
141
142 /**
143 * @return the {@link android.app.WallpaperInfo} associated with this wallpaper, which is
144 * generally present for live wallpapers, or null if there is none.
145 */
146 public android.app.WallpaperInfo getWallpaperComponent() {
147 return null;
148 }
149
150 /**
151 * Returns the ID of the collection this image is associated with, if any.
152 */
153 public abstract String getCollectionId(Context context);
154
155 /**
156 * Returns the ID of this wallpaper or null if there is no ID.
157 */
158 public String getWallpaperId() {
159 return null;
160 }
161
162 /**
163 * Returns whether backup is allowed for this wallpaper.
164 */
165 @BackupPermission
166 public int getBackupPermission() {
167 return BACKUP_ALLOWED;
168 }
169
170 /**
171 * Shows the appropriate preview activity for this WallpaperInfo.
172 *
173 * @param srcActivity
174 * @param factory A factory for showing the inline preview activity for within this app.
175 * Only used for certain WallpaperInfo implementations that require an inline preview
176 * (as opposed to some external preview activity).
177 * @param requestCode Request code to pass in when starting the inline preview activity.
178 */
179 public abstract void showPreview(Activity srcActivity, InlinePreviewIntentFactory factory,
180 int requestCode);
181
182 /**
183 * Whether backup is allowed for this type of wallpaper.
184 */
185 @IntDef({
186 BACKUP_NOT_ALLOWED,
187 BACKUP_ALLOWED
188 })
189 public @interface BackupPermission {
190 }
191}