blob: bb59cb131be10b2204700b0335d26bd8e452a989 [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.module;
17
18import android.app.Activity;
19import android.graphics.Bitmap;
20import android.graphics.Rect;
21import android.support.annotation.IntDef;
22import android.support.annotation.Nullable;
23
24import com.android.wallpaper.asset.Asset;
25import com.android.wallpaper.model.WallpaperInfo;
26
27import java.util.List;
28
29/**
30 * Interface for classes which persist wallpapers to the system.
31 */
32public interface WallpaperPersister {
33
34 int DEST_HOME_SCREEN = 0;
35 int DEST_LOCK_SCREEN = 1;
36 int DEST_BOTH = 2;
37 int WALLPAPER_POSITION_CENTER = 0;
38 int WALLPAPER_POSITION_CENTER_CROP = 1;
39 int WALLPAPER_POSITION_STRETCH = 2;
40
41 /**
42 * Sets a static individual wallpaper to the system via the WallpaperManager.
43 *
44 * @param wallpaper Wallpaper model object. Wallpaper image will be set from the asset provided
45 * to this method.
46 * @param asset Wallpaper asset from which to retrieve image data.
47 * @param cropRect Desired crop area of the wallpaper in post-scale units. If null, then the
48 * wallpaper image will be set without any scaling or cropping.
49 * @param scale Scaling factor applied to the source image before setting the wallpaper to the
50 * device.
51 * @param destination The destination - where to set the wallpaper to.
52 * @param callback Called once the wallpaper was set or if an error occurred.
53 */
54 void setIndividualWallpaper(WallpaperInfo wallpaper, Asset asset, @Nullable Rect cropRect,
55 float scale, @Destination int destination, SetWallpaperCallback callback);
56
57 /**
58 * Sets a static individual wallpaper to the system with the provided wallpaper position
59 * preference to fit the device display. This method does not provide a destination option since
60 * the UI that calls this interface does not support separate home and lock screens.
61 *
62 * @param wallpaper Wallpaper model object. Wallpaper image will be set from the asset provided
63 * by the wallpaper's default asset.
64 * @param wallpaperPosition Crop strategy for fitting the wallpaper asset to the device display.
65 * @param callback Called once the wallpaper was set or if an error occurred.
66 */
67 void setIndividualWallpaperWithPosition(Activity activity, WallpaperInfo wallpaper,
68 @WallpaperPosition int wallpaperPosition, SetWallpaperCallback callback);
69
70 /**
71 * Sets an individual wallpaper to the system as the wallpaper in the current rotation along with
72 * its metadata. Prevents automatic wallpaper backup to conserve user data.
73 * <p>
74 * This method should only be called off the main UI thread because it will compress and set the
75 * bitmap on the same thread as the caller.
76 *
77 * @param wallpaperBitmap Cropped and scaled wallpaper bitmap. This bitmap will be persisted as-is
78 * with no additional processing.
79 * @param attributions List of attribution items.
80 * @param actionUrl The action or "explore" URL for the wallpaper.
81 * @param collectionId ID of this wallpaper's collection.
82 * @return Whether the set wallpaper operation was successful.
83 */
84 boolean setWallpaperInRotation(Bitmap wallpaperBitmap, List<String> attributions,
Santiago Etchebehered1bd5092018-04-18 16:03:30 -070085 int actionLabelRes, int actionIconRes,
Jon Miranda16ea1b12017-12-12 14:52:48 -080086 String actionUrl, String collectionId);
87
88 /**
89 * Sets only the bitmap of a rotating wallpaper of the next rotation to the system (and not
90 * metadata).
91 *
92 * @param wallpaperBitmap The rotating wallpaper's bitmap.
93 * @return wallpaper ID, which is a positive integer if the set wallpaper operation was
94 * successful, or 0 otherwise. On Android versions prior to N, this method will always return
95 * 1 if the operation was successful because wallpaper IDs are not supported prior to N.
96 */
97 int setWallpaperBitmapInNextRotation(Bitmap wallpaperBitmap);
98
99 /**
100 * Persists rotating wallpaper metadata for the next rotation and finalizes the preview wallpaper
101 * image so that it's visible as the actual device wallpaper.
102 *
103 * @param attributions List of attribution items.
104 * @param actionUrl The action or "explore" URL for the wallpaper.
105 * @param collectionId ID of this wallpaper's collection.
106 * @param wallpaperId Wallpaper ID that on Android N and later uniquely identifies the wallpaper
107 * image.
108 * @return Whether the operation succeeded.
109 */
110 boolean finalizeWallpaperForNextRotation(List<String> attributions, String actionUrl,
Santiago Etchebehered1bd5092018-04-18 16:03:30 -0700111 int actionLabelRes, int actionIconRes,
Jon Miranda16ea1b12017-12-12 14:52:48 -0800112 String collectionId, int wallpaperId);
113
114 /**
115 * Saves the last wallpaper which showed a preview from this app.
116 */
117 void setWallpaperInfoInPreview(WallpaperInfo wallpaper);
118
119 /**
120 * Saves attributions to WallpaperPreferences for the last previewed wallpaper if it has an
121 * {@link android.app.WallpaperInfo} component matching the one currently set to the
122 * {@link android.app.WallpaperManager}.
123 */
124 void onLiveWallpaperSet();
125
126 /**
127 * Interface for tracking success or failure of set wallpaper operations.
128 */
129 interface SetWallpaperCallback {
130 void onSuccess();
131
132 void onError(@Nullable Throwable throwable);
133 }
134
135 /**
136 * The possible destinations to which a wallpaper may be set.
137 */
138 @IntDef({
139 DEST_HOME_SCREEN,
140 DEST_LOCK_SCREEN,
141 DEST_BOTH})
142 @interface Destination {
143 }
144
145 /**
146 * Possible wallpaper positions for setting an image wallpaper on desktop.
147 */
148 @IntDef({
149 WALLPAPER_POSITION_CENTER,
150 WALLPAPER_POSITION_CENTER_CROP,
151 WALLPAPER_POSITION_STRETCH})
152 @interface WallpaperPosition {
153 }
154}