1 /*
2  * Copyright (C) 2019 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.keyguard.clock;
17 
18 import android.graphics.Bitmap;
19 
20 import java.util.function.Supplier;
21 
22 /**
23  * Metadata about an available clock face.
24  */
25 final class ClockInfo {
26 
27     private final String mName;
28     private final Supplier<String> mTitle;
29     private final String mId;
30     private final Supplier<Bitmap> mThumbnail;
31     private final Supplier<Bitmap> mPreview;
32 
ClockInfo(String name, Supplier<String> title, String id, Supplier<Bitmap> thumbnail, Supplier<Bitmap> preview)33     private ClockInfo(String name, Supplier<String> title, String id,
34             Supplier<Bitmap> thumbnail, Supplier<Bitmap> preview) {
35         mName = name;
36         mTitle = title;
37         mId = id;
38         mThumbnail = thumbnail;
39         mPreview = preview;
40     }
41 
42     /**
43      * Gets the non-internationalized name for the clock face.
44      */
getName()45     String getName() {
46         return mName;
47     }
48 
49     /**
50      * Gets the name (title) of the clock face to be shown in the picker app.
51      */
getTitle()52     String getTitle() {
53         return mTitle.get();
54     }
55 
56     /**
57      * Gets the ID of the clock face, used by the picker to set the current selection.
58      */
getId()59     String getId() {
60         return mId;
61     }
62 
63     /**
64      * Gets a thumbnail image of the clock.
65      */
getThumbnail()66     Bitmap getThumbnail() {
67         return mThumbnail.get();
68     }
69 
70     /**
71      * Gets a potentially realistic preview image of the clock face.
72      */
getPreview()73     Bitmap getPreview() {
74         return mPreview.get();
75     }
76 
builder()77     static Builder builder() {
78         return new Builder();
79     }
80 
81     static class Builder {
82         private String mName;
83         private Supplier<String> mTitle;
84         private String mId;
85         private Supplier<Bitmap> mThumbnail;
86         private Supplier<Bitmap> mPreview;
87 
build()88         public ClockInfo build() {
89             return new ClockInfo(mName, mTitle, mId, mThumbnail, mPreview);
90         }
91 
setName(String name)92         public Builder setName(String name) {
93             mName = name;
94             return this;
95         }
96 
setTitle(Supplier<String> title)97         public Builder setTitle(Supplier<String> title) {
98             mTitle = title;
99             return this;
100         }
101 
setId(String id)102         public Builder setId(String id) {
103             mId = id;
104             return this;
105         }
106 
setThumbnail(Supplier<Bitmap> thumbnail)107         public Builder setThumbnail(Supplier<Bitmap> thumbnail) {
108             mThumbnail = thumbnail;
109             return this;
110         }
111 
setPreview(Supplier<Bitmap> preview)112         public Builder setPreview(Supplier<Bitmap> preview) {
113             mPreview = preview;
114             return this;
115         }
116     }
117 }
118