• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 com.android.systemui.keyguard;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.content.res.ColorStateList;
22 import android.graphics.drawable.Drawable;
23 import android.text.TextUtils;
24 import android.view.View;
25 
26 /**
27  * Data class containing display information (message, icon, styling) for indication to show at
28  * the bottom of the keyguard.
29  *
30  * See {@link com.android.systemui.statusbar.phone.KeyguardBottomAreaView}.
31  */
32 public class KeyguardIndication {
33     @Nullable
34     private final CharSequence mMessage;
35     @Nullable
36     private final boolean mForceAccessibilityLiveRegionAssertive;
37     @NonNull
38     private final ColorStateList mTextColor;
39     @Nullable
40     private final Drawable mIcon;
41     @Nullable
42     private final View.OnClickListener mOnClickListener;
43     @Nullable
44     private final Drawable mBackground;
45     @Nullable
46     private final Long mMinVisibilityMillis; // in milliseconds
47 
KeyguardIndication( CharSequence message, ColorStateList textColor, Drawable icon, View.OnClickListener onClickListener, Drawable background, Long minVisibilityMillis, Boolean foceAssertive)48     private KeyguardIndication(
49             CharSequence message,
50             ColorStateList textColor,
51             Drawable icon,
52             View.OnClickListener onClickListener,
53             Drawable background,
54             Long minVisibilityMillis,
55             Boolean foceAssertive) {
56         mMessage = message;
57         mTextColor = textColor;
58         mIcon = icon;
59         mOnClickListener = onClickListener;
60         mBackground = background;
61         mMinVisibilityMillis = minVisibilityMillis;
62         mForceAccessibilityLiveRegionAssertive = foceAssertive;
63     }
64 
65     /**
66      * Message to display
67      */
getMessage()68     public @Nullable CharSequence getMessage() {
69         return mMessage;
70     }
71 
72     /**
73      * TextColor to display the message.
74      */
getTextColor()75     public @NonNull ColorStateList getTextColor() {
76         return mTextColor;
77     }
78 
79     /**
80      * Icon to display.
81      */
getIcon()82     public @Nullable Drawable getIcon() {
83         return mIcon;
84     }
85 
86     /**
87      * Click listener for message.
88      */
getClickListener()89     public @Nullable View.OnClickListener getClickListener() {
90         return mOnClickListener;
91     }
92 
93     /**
94      * Background for textView.
95      */
getBackground()96     public @Nullable Drawable getBackground() {
97         return mBackground;
98     }
99 
100     /**
101      * Minimum time to show text in milliseconds.
102      * @return null if unspecified
103      */
getMinVisibilityMillis()104     public @Nullable Long getMinVisibilityMillis() {
105         return mMinVisibilityMillis;
106     }
107 
108 
109     /**
110      * Whether to force the accessibility live region to be assertive.
111      */
getForceAssertiveAccessibilityLiveRegion()112     public boolean getForceAssertiveAccessibilityLiveRegion() {
113         return mForceAccessibilityLiveRegionAssertive;
114     }
115 
116 
117     @Override
toString()118     public String toString() {
119         String str = "KeyguardIndication{";
120         if (!TextUtils.isEmpty(mMessage)) str += "mMessage=" + mMessage;
121         if (mIcon != null) str += " mIcon=" + mIcon;
122         if (mOnClickListener != null) str += " mOnClickListener=" + mOnClickListener;
123         if (mBackground != null) str += " mBackground=" + mBackground;
124         if (mMinVisibilityMillis != null) str += " mMinVisibilityMillis=" + mMinVisibilityMillis;
125         if (mForceAccessibilityLiveRegionAssertive) str += "mForceAccessibilityLiveRegionAssertive";
126         str += "}";
127         return str;
128     }
129 
130     /**
131      * KeyguardIndication Builder
132      */
133     public static class Builder {
134         private CharSequence mMessage;
135         private Drawable mIcon;
136         private View.OnClickListener mOnClickListener;
137         private ColorStateList mTextColor;
138         private Drawable mBackground;
139         private Long mMinVisibilityMillis;
140         private boolean mForceAccessibilityLiveRegionAssertive;
141 
Builder()142         public Builder() { }
143 
144         /**
145          * Message to display. Indication requires a non-null message or icon.
146          */
setMessage(@onNull CharSequence message)147         public Builder setMessage(@NonNull CharSequence message) {
148             this.mMessage = message;
149             return this;
150         }
151 
152         /**
153          * Required field. Text color to use to display the message.
154          */
setTextColor(@onNull ColorStateList textColor)155         public Builder setTextColor(@NonNull ColorStateList textColor) {
156             this.mTextColor = textColor;
157             return this;
158         }
159 
160         /**
161          * Icon to show next to the text. Indication requires a non-null icon or message.
162          * Icon location changes based on language display direction. For LTR, icon shows to the
163          * left of the message. For RTL, icon shows to the right of the message.
164          */
setIcon(Drawable icon)165         public Builder setIcon(Drawable icon) {
166             this.mIcon = icon;
167             return this;
168         }
169 
170         /**
171          * Optional. Set a click listener on the message.
172          */
setClickListener(View.OnClickListener onClickListener)173         public Builder setClickListener(View.OnClickListener onClickListener) {
174             this.mOnClickListener = onClickListener;
175             return this;
176         }
177 
178         /**
179          * Optional. Set a custom background on the TextView.
180          */
setBackground(Drawable background)181         public Builder setBackground(Drawable background) {
182             this.mBackground = background;
183             return this;
184         }
185 
186         /**
187          * Optional. Set a required minimum visibility time in milliseconds for the text
188          * to show.
189          */
setMinVisibilityMillis(Long minVisibilityMillis)190         public Builder setMinVisibilityMillis(Long minVisibilityMillis) {
191             this.mMinVisibilityMillis = minVisibilityMillis;
192             return this;
193         }
194 
195         /**
196          * Optional. Can force the accessibility live region to be assertive for this message.
197          */
setForceAccessibilityLiveRegionAssertive()198         public Builder setForceAccessibilityLiveRegionAssertive() {
199             this.mForceAccessibilityLiveRegionAssertive = true;
200             return this;
201         }
202 
203         /**
204          * Build the KeyguardIndication.
205          */
build()206         public KeyguardIndication build() {
207             if (TextUtils.isEmpty(mMessage) && mIcon == null) {
208                 throw new IllegalStateException("message or icon must be set");
209             }
210             if (mTextColor == null) {
211                 throw new IllegalStateException("text color must be set");
212             }
213 
214             return new KeyguardIndication(
215                     mMessage, mTextColor, mIcon, mOnClickListener, mBackground,
216                     mMinVisibilityMillis, mForceAccessibilityLiveRegionAssertive);
217         }
218     }
219 }
220