Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fafe0407 authored by Beverly's avatar Beverly
Browse files

Use AOD/LS SystemUI clock-specific font

Use a custom variable width font on AOD/LS. Use weight 200 on AOD and weight
400 on LS. The animation currently re-layouts throughout the animation,
and eventually should animate using new TextAPIs.

To toggle on the new lockscreen:
  adb shell settings put global show_new_lockscreen 1

Test: manual
Bug: 170228350
Change-Id: I62072a3e4a045f10606f8c7ed3f5214107e1670d
parent ae31181f
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
**
** Copyright 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.
*/
-->

<!--
** AOD/LockScreen Clock font.
** Should include all numeric glyphs in all supported locales.
** Recommended: font with variable width to support AOD => LS animations
-->
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- TODO (b/171376810): switch this font with a variable width clock font for AOSP -->
    <font android:typeface="monospace" android:font="@*android:string/config_headlineFontFamily" />
</font-family>
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@
            android:letterSpacing="0.02"
            android:lineSpacingMultiplier=".8"
            android:includeFontPadding="false"
            android:fontFamily="sans-serif"
            android:fontFamily="@font/clock"
            android:typeface="monospace"
            android:format12Hour="hh\nmm"
            android:format24Hour="HH\nmm"
+1 −1
Original line number Diff line number Diff line
@@ -61,7 +61,6 @@ public class GradientTextClock extends TextClock {

    @Override
    public void refreshTime() {
        updatePaint();
        super.refreshTime();
    }

@@ -77,6 +76,7 @@ public class GradientTextClock extends TextClock {

    public void setGradientColors(int[] colors) {
        mGradientColors = colors;
        updatePaint();
    }

    public void setColorPositions(float[] positions) {
+8 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ import android.transition.TransitionValues;
import android.util.AttributeSet;
import android.util.Log;
import android.util.MathUtils;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
@@ -149,6 +150,11 @@ public class KeyguardClockSwitch extends RelativeLayout {
                mKeyguardStatusArea.getLayoutParams();

        if (mode == KeyguardUpdateMonitor.LOCK_SCREEN_MODE_LAYOUT_1) {
            final int startEndPadding = (int) TypedValue.applyDimension(
                    TypedValue.COMPLEX_UNIT_DIP,
                    12,
                    getResources().getDisplayMetrics());
            setPaddingRelative(startEndPadding, 0, startEndPadding, 0);
            mSmallClockFrame.setVisibility(GONE);
            mNewLockscreenClockFrame.setVisibility(VISIBLE);
            mNewLockscreenClockViewController.init();
@@ -157,6 +163,7 @@ public class KeyguardClockSwitch extends RelativeLayout {
            statusAreaLP.addRule(RelativeLayout.LEFT_OF, R.id.new_lockscreen_clock_view);
            statusAreaLP.addRule(RelativeLayout.ALIGN_PARENT_START);
        } else {
            setPaddingRelative(0, 0, 0, 0);
            mSmallClockFrame.setVisibility(VISIBLE);
            mNewLockscreenClockFrame.setVisibility(GONE);

@@ -298,6 +305,7 @@ public class KeyguardClockSwitch extends RelativeLayout {
        if (mClockPlugin != null) {
            mClockPlugin.setDarkAmount(darkAmount);
        }
        mNewLockscreenClockViewController.setDarkAmount(darkAmount);
        updateBigClockAlpha();
    }

+49 −10
Original line number Diff line number Diff line
@@ -16,6 +16,11 @@

package com.android.keyguard;

import android.util.MathUtils;

import com.android.internal.graphics.ColorUtils;
import com.android.settingslib.Utils;
import com.android.systemui.R;
import com.android.systemui.util.ViewController;

import java.util.Calendar;
@@ -28,6 +33,13 @@ public class TimeBasedColorsClockController extends ViewController<GradientTextC
    private final int[] mGradientColors = new int[3];
    private final float[] mPositions = new float[3];

    /**
     * 0 = fully awake
     * between 0 and 1 = transitioning between awake and doze
     * 1 = fully in doze
     */
    private float mDarkAmount = 0f;

    public TimeBasedColorsClockController(GradientTextClock view) {
        super(view);
    }
@@ -46,14 +58,29 @@ public class TimeBasedColorsClockController extends ViewController<GradientTextC
     * Updates the time for this view. Also updates any color changes.
     */
    public void refreshTime(long timeInMillis) {
        Calendar now = new GregorianCalendar();
        now.setTimeInMillis(timeInMillis);
        updateColors(now);
        updatePositions(now);
        updateColors(timeInMillis);
        updatePositions(timeInMillis);
        mView.refreshTime();
    }

    private int getTimeIndex(Calendar now) {
    /**
     * Set the amount (ratio) that the device has transitioned to doze.
     *
     * @param darkAmount Amount of transition to doze: 1f for doze and 0f for awake.
     */
    public void setDarkAmount(float darkAmount) {
        mDarkAmount = darkAmount;

        // TODO: (b/170228350) currently this relayouts throughout the animation;
        //  eventually this should use new Text APIs to animate the variable font weight
        refreshTime(System.currentTimeMillis());

        int weight = (int) MathUtils.lerp(200, 400, 1f - darkAmount);
        mView.setFontVariationSettings("'wght' " + weight);
    }

    private int getTimeIndex(long timeInMillis) {
        Calendar now = getCalendar(timeInMillis);
        int hour = now.get(Calendar.HOUR_OF_DAY); // 0 - 23
        if (hour < mTimes[0]) {
            return mTimes.length - 1;
@@ -68,16 +95,22 @@ public class TimeBasedColorsClockController extends ViewController<GradientTextC
        return mTimes.length - 1;
    }

    private void updateColors(Calendar now) {
        final int index = getTimeIndex(now);
    private void updateColors(long timeInMillis) {
        final int index = getTimeIndex(timeInMillis);
        final int wallpaperTextColor =
                Utils.getColorAttrDefaultColor(mView.getContext(), R.attr.wallpaperTextColor);
        for (int i = 0; i < mGradientColors.length; i++) {
            mGradientColors[i] = COLORS[index][i];
            // wallpaperTextColor on LS when mDarkAmount = 0f
            // full color on AOD when mDarkAmount = 1f
            mGradientColors[i] =
                    ColorUtils.blendARGB(wallpaperTextColor, COLORS[index][i], mDarkAmount);
        }
        mView.setGradientColors(mGradientColors);
    }

    private void updatePositions(Calendar now) {
        final int index = getTimeIndex(now);
    private void updatePositions(long timeInMillis) {
        Calendar now = getCalendar(timeInMillis);
        final int index = getTimeIndex(timeInMillis);

        final Calendar startTime = new GregorianCalendar();
        startTime.setTimeInMillis(now.getTimeInMillis());
@@ -108,6 +141,12 @@ public class TimeBasedColorsClockController extends ViewController<GradientTextC
        mView.setColorPositions(mPositions);
    }

    private Calendar getCalendar(long timeInMillis) {
        Calendar now = new GregorianCalendar();
        now.setTimeInMillis(timeInMillis);
        return now;
    }

    private static final int[] SUNRISE = new int[] {0xFF6F75AA, 0xFFAFF0FF, 0xFFFFDEBF};
    private static final int[] DAY = new int[] {0xFF9BD8FB, 0xFFD7F5FF, 0xFFFFF278};
    private static final int[] NIGHT = new int[] {0xFF333D5E, 0xFFC5A1D6, 0xFF907359};