• 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 import java.util.function.Consumer;
28 
29 /**
30  * This class represents a page of a launcher page used by the wallpaper
31  * @hide
32  */
33 public class EngineWindowPage {
34     private Bitmap mScreenShot;
35     private volatile long  mLastUpdateTime = 0;
36     private Set<RectF> mCallbackAreas = new ArraySet<>();
37     private Map<RectF, WallpaperColors> mRectFColors = new ArrayMap<>();
38 
39     /** should be locked extrnally */
addArea(RectF area)40     public void addArea(RectF area) {
41         mCallbackAreas.add(area);
42     }
43 
44     /** should be locked extrnally */
addWallpaperColors(RectF area, WallpaperColors colors)45     public void addWallpaperColors(RectF area, WallpaperColors colors) {
46         mCallbackAreas.add(area);
47         mRectFColors.put(area, colors);
48     }
49 
50     /** get screenshot bitmap */
getBitmap()51     public Bitmap getBitmap() {
52         if (mScreenShot == null || mScreenShot.isRecycled()) return null;
53         return mScreenShot;
54     }
55 
56     /** remove callbacks for an area */
removeArea(RectF area)57     public void removeArea(RectF area) {
58         mCallbackAreas.remove(area);
59         mRectFColors.remove(area);
60     }
61 
62     /** set the last time the screenshot was updated */
setLastUpdateTime(long lastUpdateTime)63     public void setLastUpdateTime(long lastUpdateTime) {
64         mLastUpdateTime = lastUpdateTime;
65     }
66 
67     /** get last screenshot time */
getLastUpdateTime()68     public long getLastUpdateTime() {
69         return mLastUpdateTime;
70     }
71 
72     /** get colors for an area */
getColors(RectF rect)73     public WallpaperColors getColors(RectF rect) {
74         return mRectFColors.get(rect);
75     }
76 
77     /** set the new bitmap version */
setBitmap(Bitmap screenShot)78     public void setBitmap(Bitmap screenShot) {
79         mScreenShot = screenShot;
80     }
81 
82     /** get areas of interest */
getAreas()83     public Set<RectF> getAreas() {
84         return mCallbackAreas;
85     }
86 
87     /** run operations on this page */
execSync(Consumer<EngineWindowPage> run)88     public synchronized void execSync(Consumer<EngineWindowPage> run) {
89         run.accept(this);
90     }
91 
92     /** nullify the area color */
removeColor(RectF colorArea)93     public void removeColor(RectF colorArea) {
94         mRectFColors.remove(colorArea);
95     }
96 }
97