• 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.text.TextUtils;
22 
23 import androidx.annotation.Nullable;
24 
25 import com.android.wallpaper.asset.Asset;
26 
27 /**
28  * Wallpaper category model object.
29  */
30 public abstract class Category {
31     private final String mTitle;
32     private final String mCollectionId;
33     private final int mPriority;
34 
35     /**
36      * Constructs a Category object.
37      *
38      * @param title        Displayed title of category.
39      * @param collectionId A collection ID that callers must ensure is unique among all categories.
40      * @param priority     Priority (lowest number = highest priority) among all categories presented.
41      */
Category(String title, String collectionId, int priority)42     public Category(String title, String collectionId, int priority) {
43         mTitle = title;
44         mCollectionId = collectionId;
45         mPriority = priority;
46     }
47 
48     /**
49      * Returns whether user created wallpapers are supported or not.
50      */
supportsUserCreatedWallpapers()51     public boolean supportsUserCreatedWallpapers() {
52         return false;
53     }
54 
55     /**
56      * Shows the UI for picking wallpapers within this category.
57      *
58      * @param srcActivity
59      * @param requestCode Request code to pass in when starting the picker activity.
60      */
show(Activity srcActivity, int requestCode)61     public abstract void show(Activity srcActivity, int requestCode);
62 
63     /**
64      * Returns true if this Category contains an enumerable set of wallpapers which can be presented
65      * by a UI enclosed in an activity. Returns false if, by contrast, this Category must be presented
66      * via #show() because its contents are not enumerable.
67      */
isEnumerable()68     public boolean isEnumerable() {
69         return false;
70     }
71 
72     /**
73      * Returns true if this category contains a single Wallpaper, which could then be retrieved
74      * via {@link #getSingleWallpaper()}
75      */
isSingleWallpaperCategory()76     public boolean isSingleWallpaperCategory() {
77         return false;
78     }
79 
80     /**
81      * If {@link #isSingleWallpaperCategory()} returned true, this method will return the single
82      * wallpaper contained in this category.
83      * @return a {@link WallpaperInfo} for the one wallpaper in this category, if this category is
84      * a single wallpaper category, or {@code null} otherwise.
85      */
86     @Nullable
getSingleWallpaper()87     public WallpaperInfo getSingleWallpaper() {
88         return null;
89     }
90 
91     /**
92      * @return The title of the category.
93      */
getTitle()94     public String getTitle() {
95         return mTitle;
96     }
97 
98     /**
99      * @return The ID of the collection this category represents.
100      */
getCollectionId()101     public String getCollectionId() {
102         return mCollectionId;
103     }
104 
105     /**
106      * Returns the overlay icon. Takes an application's Context if a Category needs to query for what
107      * resources may be available on the device (for example, querying permissions).
108      */
getOverlayIcon(Context unused)109     public Drawable getOverlayIcon(Context unused) {
110         return null;
111     }
112 
113     /**
114      * Returns the relative priority of the category. The lower the number, the higher the priority.
115      */
getPriority()116     public int getPriority() {
117         return mPriority;
118     }
119 
120     /**
121      * Returns the desired size of the overlay icon in density-independent pixels. Default value is
122      * 40.
123      */
getOverlayIconSizeDp()124     public int getOverlayIconSizeDp() {
125         return 40;
126     }
127 
128     /**
129      * Returns the {@link WallpaperRotationInitializer} for this category or null if rotation is not
130      * enabled for this category.
131      */
getWallpaperRotationInitializer()132     public WallpaperRotationInitializer getWallpaperRotationInitializer() {
133         return null;
134     }
135 
136     /**
137      * Returns the thumbnail Asset. Takes an application's Context if a Category needs to query for
138      * what resources may be available on the device (for example, querying permissions).
139      */
getThumbnail(Context context)140     public abstract Asset getThumbnail(Context context);
141 
142     /**
143      * Returns whether this category allows the user to pick custom photos via Android's photo picker.
144      */
supportsCustomPhotos()145     public boolean supportsCustomPhotos() {
146         return false;
147     }
148 
149     /**
150      * Returns whether this category is or contains third-party wallpapers
151      */
supportsThirdParty()152     public boolean supportsThirdParty() {
153         return false;
154     }
155 
156     /**
157      * Returns whether this Category contains or represents a third party wallpaper with the given
158      * packageName (this only makes sense if #supportsThirdParty() returns true).
159      */
containsThirdParty(String packageName)160     public boolean containsThirdParty(String packageName) {
161         return false;
162     }
163 
164     /**
165      * Returns whether this category supports content that can be added or removed dynamically.
166      */
supportsWallpaperSetUpdates()167     public boolean supportsWallpaperSetUpdates() {
168         return false;
169     }
170 
171     @Override
equals(Object obj)172     public boolean equals(Object obj) {
173         if (!(obj instanceof Category)) return false;
174         if (obj == this) return true;
175         return TextUtils.equals(getCollectionId(), ((Category) obj).getCollectionId());
176     }
177 
178     @Override
hashCode()179     public int hashCode() {
180         return mCollectionId == null ? super.hashCode() : mCollectionId.hashCode();
181     }
182 }
183