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