• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 
17 package android.service.wallpaper;
18 
19 import android.app.WallpaperColors;
20 import android.graphics.Bitmap;
21 import android.graphics.RectF;
22 import android.util.ArrayMap;
23 import android.util.ArraySet;
24 
25 import java.util.Map;
26 import java.util.Set;
27 
28 /**
29  * This class represents a page of a launcher page used by the wallpaper
30  * @hide
31  */
32 public class EngineWindowPage {
33     private Bitmap mScreenShot;
34     private volatile long  mLastUpdateTime = 0;
35     private Set<RectF> mCallbackAreas = new ArraySet<>();
36     private Map<RectF, WallpaperColors> mRectFColors = new ArrayMap<>();
37 
38     /** should be locked extrnally */
addArea(RectF area)39     public void addArea(RectF area) {
40         mCallbackAreas.add(area);
41     }
42 
43     /** should be locked extrnally */
addWallpaperColors(RectF area, WallpaperColors colors)44     public void addWallpaperColors(RectF area, WallpaperColors colors) {
45         mCallbackAreas.add(area);
46         mRectFColors.put(area, colors);
47     }
48 
49     /** get screenshot bitmap */
getBitmap()50     public Bitmap getBitmap() {
51         if (mScreenShot == null || mScreenShot.isRecycled()) return null;
52         return mScreenShot;
53     }
54 
55     /** remove callbacks for an area */
removeArea(RectF area)56     public void removeArea(RectF area) {
57         mCallbackAreas.remove(area);
58         mRectFColors.remove(area);
59     }
60 
61     /** set the last time the screenshot was updated */
setLastUpdateTime(long lastUpdateTime)62     public void setLastUpdateTime(long lastUpdateTime) {
63         mLastUpdateTime = lastUpdateTime;
64     }
65 
66     /** get last screenshot time */
getLastUpdateTime()67     public long getLastUpdateTime() {
68         return mLastUpdateTime;
69     }
70 
71     /** get colors for an area */
getColors(RectF rect)72     public WallpaperColors getColors(RectF rect) {
73         return mRectFColors.get(rect);
74     }
75 
76     /** set the new bitmap version */
setBitmap(Bitmap screenShot)77     public void setBitmap(Bitmap screenShot) {
78         mScreenShot = screenShot;
79     }
80 
81     /** get areas of interest */
getAreas()82     public Set<RectF> getAreas() {
83         return mCallbackAreas;
84     }
85 
86     /** nullify the area color */
removeColor(RectF colorArea)87     public void removeColor(RectF colorArea) {
88         mRectFColors.remove(colorArea);
89     }
90 }
91