Robert Snoeberger | 6b244b0 | 2019-02-04 15:33:31 -0500 | [diff] [blame] | 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; |
Robert Snoeberger | 61d1af8 | 2019-12-13 16:37:00 -0500 | [diff] [blame] | 28 | private final Supplier<String> mTitle; |
Robert Snoeberger | 6b244b0 | 2019-02-04 15:33:31 -0500 | [diff] [blame] | 29 | private final String mId; |
| 30 | private final Supplier<Bitmap> mThumbnail; |
| 31 | private final Supplier<Bitmap> mPreview; |
| 32 | |
Robert Snoeberger | 61d1af8 | 2019-12-13 16:37:00 -0500 | [diff] [blame] | 33 | private ClockInfo(String name, Supplier<String> title, String id, |
Robert Snoeberger | 6b244b0 | 2019-02-04 15:33:31 -0500 | [diff] [blame] | 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 | */ |
| 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 | */ |
| 52 | String getTitle() { |
Robert Snoeberger | 61d1af8 | 2019-12-13 16:37:00 -0500 | [diff] [blame] | 53 | return mTitle.get(); |
Robert Snoeberger | 6b244b0 | 2019-02-04 15:33:31 -0500 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Gets the ID of the clock face, used by the picker to set the current selection. |
| 58 | */ |
| 59 | String getId() { |
| 60 | return mId; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Gets a thumbnail image of the clock. |
| 65 | */ |
| 66 | Bitmap getThumbnail() { |
| 67 | return mThumbnail.get(); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Gets a potentially realistic preview image of the clock face. |
| 72 | */ |
| 73 | Bitmap getPreview() { |
| 74 | return mPreview.get(); |
| 75 | } |
| 76 | |
| 77 | static Builder builder() { |
| 78 | return new Builder(); |
| 79 | } |
| 80 | |
| 81 | static class Builder { |
| 82 | private String mName; |
Robert Snoeberger | 61d1af8 | 2019-12-13 16:37:00 -0500 | [diff] [blame] | 83 | private Supplier<String> mTitle; |
Robert Snoeberger | 6b244b0 | 2019-02-04 15:33:31 -0500 | [diff] [blame] | 84 | private String mId; |
| 85 | private Supplier<Bitmap> mThumbnail; |
| 86 | private Supplier<Bitmap> mPreview; |
| 87 | |
| 88 | public ClockInfo build() { |
| 89 | return new ClockInfo(mName, mTitle, mId, mThumbnail, mPreview); |
| 90 | } |
| 91 | |
| 92 | public Builder setName(String name) { |
| 93 | mName = name; |
| 94 | return this; |
| 95 | } |
| 96 | |
Robert Snoeberger | 61d1af8 | 2019-12-13 16:37:00 -0500 | [diff] [blame] | 97 | public Builder setTitle(Supplier<String> title) { |
Robert Snoeberger | 6b244b0 | 2019-02-04 15:33:31 -0500 | [diff] [blame] | 98 | mTitle = title; |
| 99 | return this; |
| 100 | } |
| 101 | |
| 102 | public Builder setId(String id) { |
| 103 | mId = id; |
| 104 | return this; |
| 105 | } |
| 106 | |
| 107 | public Builder setThumbnail(Supplier<Bitmap> thumbnail) { |
| 108 | mThumbnail = thumbnail; |
| 109 | return this; |
| 110 | } |
| 111 | |
| 112 | public Builder setPreview(Supplier<Bitmap> preview) { |
| 113 | mPreview = preview; |
| 114 | return this; |
| 115 | } |
| 116 | } |
| 117 | } |