blob: 99d7500b9c28b5ab518a3b95a5ff860a9fc48a48 [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;
Santiago Etchebehere1ee76a22018-05-15 15:02:24 -070021import android.text.TextUtils;
Jon Miranda16ea1b12017-12-12 14:52:48 -080022
Santiago Etchebehere39c31342021-05-03 15:35:06 -070023import androidx.annotation.Nullable;
24
Jon Miranda16ea1b12017-12-12 14:52:48 -080025import com.android.wallpaper.asset.Asset;
26
27/**
28 * Wallpaper category model object.
29 */
30public 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 */
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 factory A factory for showing the picker activity for within this app. Only used for
53 * certain Category implementations that show a picker in-app (as opposed to launching an
54 * external intent).
55 * @param requestCode Request code to pass in when starting the picker activity.
56 */
57 public abstract void show(Activity srcActivity, PickerIntentFactory factory, int requestCode);
58
59 /**
60 * Returns true if this Category contains an enumerable set of wallpapers which can be presented
61 * by a UI enclosed in an activity. Returns false if, by contrast, this Category must be presented
62 * via #show() because its contents are not enumerable.
63 */
64 public boolean isEnumerable() {
65 return false;
66 }
67
Jon Miranda16ea1b12017-12-12 14:52:48 -080068 /**
Santiago Etchebehere39c31342021-05-03 15:35:06 -070069 * Returns true if this category contains a single Wallpaper, which could then be retrieved
70 * via {@link #getSingleWallpaper()}
71 */
72 public boolean isSingleWallpaperCategory() {
73 return false;
74 }
75
76 /**
77 * If {@link #isSingleWallpaperCategory()} returned true, this method will return the single
78 * wallpaper contained in this category.
79 * @return a {@link WallpaperInfo} for the one wallpaper in this category, if this category is
80 * a single wallpaper category, or {@code null} otherwise.
81 */
82 @Nullable
83 public WallpaperInfo getSingleWallpaper() {
84 return null;
85 }
86
87 /**
Jon Miranda16ea1b12017-12-12 14:52:48 -080088 * @return The title of the category.
89 */
90 public String getTitle() {
91 return mTitle;
92 }
93
94 /**
95 * @return The ID of the collection this category represents.
96 */
97 public String getCollectionId() {
98 return mCollectionId;
99 }
100
101 /**
102 * Returns the overlay icon. Takes an application's Context if a Category needs to query for what
103 * resources may be available on the device (for example, querying permissions).
104 */
105 public Drawable getOverlayIcon(Context unused) {
106 return null;
107 }
108
109 /**
110 * Returns the relative priority of the category. The lower the number, the higher the priority.
111 */
112 public int getPriority() {
113 return mPriority;
114 }
115
116 /**
117 * Returns the desired size of the overlay icon in density-independent pixels. Default value is
118 * 40.
119 */
120 public int getOverlayIconSizeDp() {
121 return 40;
122 }
123
124 /**
125 * Returns the {@link WallpaperRotationInitializer} for this category or null if rotation is not
126 * enabled for this category.
127 */
128 public WallpaperRotationInitializer getWallpaperRotationInitializer() {
129 return null;
130 }
131
132 /**
133 * Returns the thumbnail Asset. Takes an application's Context if a Category needs to query for
134 * what resources may be available on the device (for example, querying permissions).
135 */
136 public abstract Asset getThumbnail(Context context);
137
138 /**
139 * Returns whether this category allows the user to pick custom photos via Android's photo picker.
140 */
141 public boolean supportsCustomPhotos() {
142 return false;
143 }
Santiago Etchebehere1ee76a22018-05-15 15:02:24 -0700144
145 /**
146 * Returns whether this category is or contains third-party wallpapers
147 */
148 public boolean supportsThirdParty() {
149 return false;
150 }
151
152 /**
153 * Returns whether this Category contains or represents a third party wallpaper with the given
154 * packageName (this only makes sense if #supportsThirdParty() returns true).
155 */
156 public boolean containsThirdParty(String packageName) {
157 return false;
158 }
159
160 @Override
161 public boolean equals(Object obj) {
162 if (!(obj instanceof Category)) return false;
163 if (obj == this) return true;
164 return TextUtils.equals(getCollectionId(), ((Category) obj).getCollectionId());
165 }
166
167 @Override
168 public int hashCode() {
169 return mCollectionId == null ? super.hashCode() : mCollectionId.hashCode();
170 }
Jon Miranda16ea1b12017-12-12 14:52:48 -0800171}