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