• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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  */
16 package com.android.wallpaper.model;
17 
18 import android.app.Activity;
19 import android.content.Context;
20 import android.graphics.drawable.Drawable;
21 import android.net.Uri;
22 import android.os.Parcelable;
23 
24 import androidx.annotation.DrawableRes;
25 import androidx.annotation.IntDef;
26 import androidx.annotation.StringRes;
27 
28 import com.android.wallpaper.R;
29 import com.android.wallpaper.asset.Asset;
30 
31 import java.util.List;
32 
33 /**
34  * Interface for wallpaper info model.
35  */
36 public abstract class WallpaperInfo implements Parcelable {
37 
38     @DrawableRes
getDefaultActionIcon()39     public static int getDefaultActionIcon() {
40         return R.drawable.ic_explore_24px;
41     }
42 
43     @StringRes
getDefaultActionLabel()44     public static int getDefaultActionLabel() {
45         return R.string.explore;
46     }
47 
48     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      */
getTitle(Context context)56     public String getTitle(Context context) {
57         return null;
58     }
59 
60     /**
61      * @return The available attributions for this wallpaper, as a list of strings. These represent
62      * the author / website or any other attribution required to be displayed for this wallpaper
63      * regarding authorship, ownership, etc.
64      */
getAttributions(Context context)65     public abstract List<String> getAttributions(Context context);
66 
67     /**
68      * Returns the base (remote) image URL for this wallpaper, or null if none exists.
69      */
getBaseImageUrl()70     public String getBaseImageUrl() {
71         return null;
72     }
73 
74     /**
75      * Returns the action or "explore" URL for the wallpaper, or null if none exists.
76      */
getActionUrl(Context unused)77     public String getActionUrl(Context unused) {
78         return null;
79     }
80 
81     /** Returns the URI corresponding to the wallpaper, or null if none exists. */
getUri()82     public Uri getUri() {
83         return null;
84     }
85 
86     /**
87      * Returns the icon to use to represent the action link corresponding to
88      * {@link #getActionUrl(Context)}
89      */
90     @DrawableRes
getActionIconRes(Context context)91     public int getActionIconRes(Context context) {
92         return getDefaultActionIcon();
93     }
94 
95     /**
96      * Returns the label to use for the action link corresponding to
97      * {@link #getActionUrl(Context)}
98      */
99     @StringRes
getActionLabelRes(Context context)100     public int getActionLabelRes(Context context) {
101         return getDefaultActionLabel();
102     }
103 
104     /**
105      * @param context
106      * @return An overlay icon to be used instead of a thumbnail, if appropriate, or null if not
107      * applicable.
108      */
getOverlayIcon(Context context)109     public Drawable getOverlayIcon(Context context) {
110         return null;
111     }
112 
113     ;
114 
115     @Override
describeContents()116     public int describeContents() {
117         return 0;
118     }
119 
120     /**
121      * @param context The client application's context.
122      * @return The {@link Asset} representing the wallpaper image.
123      */
getAsset(Context context)124     public abstract Asset getAsset(Context context);
125 
126     /**
127      * @param context The client application's context.
128      * @return The {@link Asset} representing the wallpaper's thumbnail.
129      */
getThumbAsset(Context context)130     public abstract Asset getThumbAsset(Context context);
131 
132     /**
133      * @param context The client application's context.
134      * @return An {@link Asset} that is appropriately sized to be directly set to the desktop. By
135      * default, this just the full wallpaper image asset (#getAsset) but subclasses may provide an
136      * Asset sized exactly for the device's primary display (i.e., cropped prior to providing a
137      * bitmap or input stream).
138      */
getDesktopAsset(Context context)139     public Asset getDesktopAsset(Context context) {
140         return getAsset(context);
141     }
142 
143     /**
144      * @return the {@link android.app.WallpaperInfo} associated with this wallpaper, which is
145      * generally present for live wallpapers, or null if there is none.
146      */
getWallpaperComponent()147     public android.app.WallpaperInfo getWallpaperComponent() {
148         return null;
149     }
150 
151     /**
152      * Returns the ID of the collection this image is associated with, if any.
153      */
getCollectionId(Context context)154     public abstract String getCollectionId(Context context);
155 
156     /**
157      * Returns the ID of this wallpaper or null if there is no ID.
158      */
getWallpaperId()159     public String getWallpaperId() {
160         return null;
161     }
162 
163     /**
164      * Returns whether backup is allowed for this wallpaper.
165      */
166     @BackupPermission
getBackupPermission()167     public int getBackupPermission() {
168         return BACKUP_ALLOWED;
169     }
170 
171     /**
172      * Shows the appropriate preview activity for this WallpaperInfo.
173      *
174      * @param srcActivity
175      * @param factory     A factory for showing the inline preview activity for within this app.
176      *                    Only used for certain WallpaperInfo implementations that require an inline preview
177      *                    (as opposed to some external preview activity).
178      * @param requestCode Request code to pass in when starting the inline preview activity.
179      */
showPreview(Activity srcActivity, InlinePreviewIntentFactory factory, int requestCode)180     public abstract void showPreview(Activity srcActivity, InlinePreviewIntentFactory factory,
181                                      int requestCode);
182 
183     /**
184      * Whether backup is allowed for this type of wallpaper.
185      */
186     @IntDef({
187             BACKUP_NOT_ALLOWED,
188             BACKUP_ALLOWED
189     })
190     public @interface BackupPermission {
191     }
192 }
193