diff options
author | Scott Lobdell <slobdell@google.com> | 2020-11-05 18:29:12 -0800 |
---|---|---|
committer | Scott Lobdell <slobdell@google.com> | 2020-11-13 11:48:49 -0800 |
commit | 3933f277a025be704e68ea593536e492831a7e05 (patch) | |
tree | 084aa5e0858c449a63dd18cc57fb21ab054d363a /packages/SystemUI/src/com/android/keyguard/GradientTextClock.java | |
parent | 248a6ce2e2ee65f367b01c43edeecef5a6d57581 (diff) | |
parent | 9c74513b2d828d5169e9942b58b2f93bb3e04aff (diff) |
Merge SP1A.201105.002
Change-Id: Iec83a0c1f6f286a1e51abfc4356633ca9d8aea5f
Diffstat (limited to 'packages/SystemUI/src/com/android/keyguard/GradientTextClock.java')
-rw-r--r-- | packages/SystemUI/src/com/android/keyguard/GradientTextClock.java | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/GradientTextClock.java b/packages/SystemUI/src/com/android/keyguard/GradientTextClock.java new file mode 100644 index 000000000000..7cf1bd0b3e79 --- /dev/null +++ b/packages/SystemUI/src/com/android/keyguard/GradientTextClock.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.keyguard; + +import android.content.Context; +import android.graphics.LinearGradient; +import android.graphics.Shader; +import android.util.AttributeSet; +import android.widget.TextClock; + +/** + * Displays the time with the hour positioned above the minutes. (ie: 09 above 30 is 9:30) + * The time's text color is a gradient that changes its colors based on its controller. + */ +public class GradientTextClock extends TextClock { + private int[] mGradientColors; + private float[] mPositions; + + public GradientTextClock(Context context) { + this(context, null, 0, 0); + } + + public GradientTextClock(Context context, AttributeSet attrs) { + this(context, attrs, 0, 0); + } + + public GradientTextClock(Context context, AttributeSet attrs, int defStyleAttr) { + this(context, attrs, defStyleAttr, 0); + } + + public GradientTextClock(Context context, AttributeSet attrs, int defStyleAttr, + int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + @Override + public void onAttachedToWindow() { + super.onAttachedToWindow(); + addOnLayoutChangeListener(mOnLayoutChangeListener); + } + + @Override + public void onDetachedFromWindow() { + super.onDetachedFromWindow(); + removeOnLayoutChangeListener(mOnLayoutChangeListener); + } + + @Override + public void refreshTime() { + super.refreshTime(); + } + + @Override + public void setFormat12Hour(CharSequence format) { + super.setFormat12Hour(FORMAT_12); + } + + @Override + public void setFormat24Hour(CharSequence format) { + super.setFormat24Hour(FORMAT_24); + } + + public void setGradientColors(int[] colors) { + mGradientColors = colors; + updatePaint(); + } + + public void setColorPositions(float[] positions) { + mPositions = positions; + } + + private void updatePaint() { + getPaint().setShader( + new LinearGradient( + getX(), getY(), getX(), getMeasuredHeight() + getY(), + mGradientColors, mPositions, Shader.TileMode.REPEAT)); + } + + private final OnLayoutChangeListener mOnLayoutChangeListener = + (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { + if (bottom != oldBottom || top != oldTop) { + updatePaint(); + } + }; + + public static final CharSequence FORMAT_12 = "hh\nmm"; + public static final CharSequence FORMAT_24 = "HH\nmm"; +} |