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 @NonNull 36 private final ColorStateList mTextColor; 37 @Nullable 38 private final Drawable mIcon; 39 @Nullable 40 private final View.OnClickListener mOnClickListener; 41 @Nullable 42 private final Drawable mBackground; 43 @Nullable 44 private final Long mMinVisibilityMillis; // in milliseconds 45 KeyguardIndication( CharSequence message, ColorStateList textColor, Drawable icon, View.OnClickListener onClickListener, Drawable background, Long minVisibilityMillis)46 private KeyguardIndication( 47 CharSequence message, 48 ColorStateList textColor, 49 Drawable icon, 50 View.OnClickListener onClickListener, 51 Drawable background, 52 Long minVisibilityMillis) { 53 mMessage = message; 54 mTextColor = textColor; 55 mIcon = icon; 56 mOnClickListener = onClickListener; 57 mBackground = background; 58 mMinVisibilityMillis = minVisibilityMillis; 59 } 60 61 /** 62 * Message to display 63 */ getMessage()64 public @Nullable CharSequence getMessage() { 65 return mMessage; 66 } 67 68 /** 69 * TextColor to display the message. 70 */ getTextColor()71 public @NonNull ColorStateList getTextColor() { 72 return mTextColor; 73 } 74 75 /** 76 * Icon to display. 77 */ getIcon()78 public @Nullable Drawable getIcon() { 79 return mIcon; 80 } 81 82 /** 83 * Click listener for messsage. 84 */ getClickListener()85 public @Nullable View.OnClickListener getClickListener() { 86 return mOnClickListener; 87 } 88 89 /** 90 * Background for textView. 91 */ getBackground()92 public @Nullable Drawable getBackground() { 93 return mBackground; 94 } 95 96 /** 97 * Minimum time to show text in milliseconds. 98 * @return null if unspecified 99 */ getMinVisibilityMillis()100 public @Nullable Long getMinVisibilityMillis() { 101 return mMinVisibilityMillis; 102 } 103 104 @Override toString()105 public String toString() { 106 String str = "KeyguardIndication{"; 107 if (!TextUtils.isEmpty(mMessage)) str += "mMessage=" + mMessage; 108 if (mIcon != null) str += " mIcon=" + mIcon; 109 if (mOnClickListener != null) str += " mOnClickListener=" + mOnClickListener; 110 if (mBackground != null) str += " mBackground=" + mBackground; 111 if (mMinVisibilityMillis != null) str += " mMinVisibilityMillis=" + mMinVisibilityMillis; 112 str += "}"; 113 return str; 114 } 115 116 /** 117 * KeyguardIndication Builder 118 */ 119 public static class Builder { 120 private CharSequence mMessage; 121 private Drawable mIcon; 122 private View.OnClickListener mOnClickListener; 123 private ColorStateList mTextColor; 124 private Drawable mBackground; 125 private Long mMinVisibilityMillis; 126 Builder()127 public Builder() { } 128 129 /** 130 * Message to display. Indication requires a non-null message or icon. 131 */ setMessage(@onNull CharSequence message)132 public Builder setMessage(@NonNull CharSequence message) { 133 this.mMessage = message; 134 return this; 135 } 136 137 /** 138 * Required field. Text color to use to display the message. 139 */ setTextColor(@onNull ColorStateList textColor)140 public Builder setTextColor(@NonNull ColorStateList textColor) { 141 this.mTextColor = textColor; 142 return this; 143 } 144 145 /** 146 * Icon to show next to the text. Indication requires a non-null icon or message. 147 * Icon location changes based on language display direction. For LTR, icon shows to the 148 * left of the message. For RTL, icon shows to the right of the message. 149 */ setIcon(Drawable icon)150 public Builder setIcon(Drawable icon) { 151 this.mIcon = icon; 152 return this; 153 } 154 155 /** 156 * Optional. Set a click listener on the message. 157 */ setClickListener(View.OnClickListener onClickListener)158 public Builder setClickListener(View.OnClickListener onClickListener) { 159 this.mOnClickListener = onClickListener; 160 return this; 161 } 162 163 /** 164 * Optional. Set a custom background on the TextView. 165 */ setBackground(Drawable background)166 public Builder setBackground(Drawable background) { 167 this.mBackground = background; 168 return this; 169 } 170 171 /** 172 * Optional. Set a required minimum visibility time in milliseconds for the text 173 * to show. 174 */ setMinVisibilityMillis(Long minVisibilityMillis)175 public Builder setMinVisibilityMillis(Long minVisibilityMillis) { 176 this.mMinVisibilityMillis = minVisibilityMillis; 177 return this; 178 } 179 180 /** 181 * Build the KeyguardIndication. 182 */ build()183 public KeyguardIndication build() { 184 if (TextUtils.isEmpty(mMessage) && mIcon == null) { 185 throw new IllegalStateException("message or icon must be set"); 186 } 187 if (mTextColor == null) { 188 throw new IllegalStateException("text color must be set"); 189 } 190 191 return new KeyguardIndication( 192 mMessage, mTextColor, mIcon, mOnClickListener, mBackground, 193 mMinVisibilityMillis); 194 } 195 } 196 } 197