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.WallpaperInfo;
19 import android.graphics.Point;
20 import android.graphics.Rect;
21 
22 import androidx.annotation.Nullable;
23 
24 import java.util.List;
25 import java.util.Map;
26 
27 /**
28  * Lightweight wrapper for user-facing wallpaper metadata.
29  */
30 public class WallpaperMetadata {
31 
32     private final List<String> mAttributions;
33     private final String mActionUrl;
34     private final String mCollectionId;
35     @Nullable private final Map<Point, Rect> mCropHints;
36     protected final android.app.WallpaperInfo mWallpaperComponent;
37 
WallpaperMetadata(List<String> attributions, String actionUrl, String collectionId, android.app.WallpaperInfo wallpaperComponent, Map<Point, Rect> cropHints)38     public WallpaperMetadata(List<String> attributions, String actionUrl, String collectionId,
39             android.app.WallpaperInfo wallpaperComponent, Map<Point, Rect> cropHints) {
40         mAttributions = attributions;
41         mActionUrl = actionUrl;
42         mCollectionId = collectionId;
43         mWallpaperComponent = wallpaperComponent;
44         mCropHints = cropHints;
45     }
46 
47     /**
48      * Returns wallpaper's attributions.
49      */
getAttributions()50     public List<String> getAttributions() {
51         return mAttributions;
52     }
53 
54     /**
55      * Returns the wallpaper's action URL or null if there is none.
56      */
getActionUrl()57     public String getActionUrl() {
58         return mActionUrl;
59     }
60 
61     /**
62      * Returns the wallpaper's collection ID or null if there is none.
63      */
getCollectionId()64     public String getCollectionId() {
65         return mCollectionId;
66     }
67 
68     /**
69      * Returns the {@link android.app.WallpaperInfo} if a live wallpaper, or null if the metadata
70      * describes an image wallpaper.
71      */
getWallpaperComponent()72     public WallpaperInfo getWallpaperComponent() {
73         throw new UnsupportedOperationException("Not implemented for static wallpapers");
74     }
75 
76     /**
77      * Returns the crop {@link Rect} of each display size for this wallpaper.
78      *
79      * <p>Live wallpaper metadata should return null.
80      */
81     @Nullable
getWallpaperCropHints()82     public Map<Point, Rect> getWallpaperCropHints() {
83         return mCropHints;
84     }
85 }
86