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

Commit f3b18885 authored by Lucas Silva's avatar Lucas Silva Committed by Android (Google) Code Review
Browse files

Merge "Update clock complication text protection." into tm-qpr-dev

parents 526beb44 22c6b36c
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
-->
<TextClock
<com.android.systemui.dreams.complication.DoubleShadowTextClock
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/time_view"
    android:layout_width="wrap_content"
@@ -23,8 +23,6 @@
    android:textColor="@android:color/white"
    android:format12Hour="@string/dream_time_complication_12_hr_time_format"
    android:format24Hour="@string/dream_time_complication_24_hr_time_format"
    android:shadowColor="@color/keyguard_shadow_color"
    android:shadowRadius="?attr/shadowRadius"
    android:fontFeatureSettings="pnum, lnum"
    android:letterSpacing="0.02"
    android:textSize="@dimen/dream_overlay_complication_clock_time_text_size"/>
+2 −0
Original line number Diff line number Diff line
@@ -241,4 +241,6 @@
    <color name="dream_overlay_aqi_very_unhealthy">#AD1457</color>
    <color name="dream_overlay_aqi_hazardous">#880E4F</color>
    <color name="dream_overlay_aqi_unknown">#BDC1C6</color>
    <color name="dream_overlay_clock_key_text_shadow_color">#4D000000</color>
    <color name="dream_overlay_clock_ambient_text_shadow_color">#4D000000</color>
</resources>
+6 −0
Original line number Diff line number Diff line
@@ -1539,4 +1539,10 @@
    <dimen name="broadcast_dialog_btn_text_size">16sp</dimen>
    <dimen name="broadcast_dialog_btn_minHeight">44dp</dimen>
    <dimen name="broadcast_dialog_margin">16dp</dimen>
    <dimen name="dream_overlay_clock_key_text_shadow_dx">0dp</dimen>
    <dimen name="dream_overlay_clock_key_text_shadow_dy">0dp</dimen>
    <dimen name="dream_overlay_clock_key_text_shadow_radius">5dp</dimen>
    <dimen name="dream_overlay_clock_ambient_text_shadow_dx">0dp</dimen>
    <dimen name="dream_overlay_clock_ambient_text_shadow_dy">0dp</dimen>
    <dimen name="dream_overlay_clock_ambient_text_shadow_radius">1dp</dimen>
</resources>
+83 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.systemui.dreams.complication;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.widget.TextClock;

import com.android.systemui.R;

/**
 * Extension of {@link TextClock} which draws two shadows on the text (ambient and key shadows)
 */
public class DoubleShadowTextClock extends TextClock {
    private final float mAmbientShadowBlur;
    private final int mAmbientShadowColor;
    private final float mKeyShadowBlur;
    private final float mKeyShadowOffsetX;
    private final float mKeyShadowOffsetY;
    private final int mKeyShadowColor;
    private final float mAmbientShadowOffsetX;
    private final float mAmbientShadowOffsetY;

    public DoubleShadowTextClock(Context context) {
        this(context, null);
    }

    public DoubleShadowTextClock(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public DoubleShadowTextClock(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mKeyShadowBlur = context.getResources()
                .getDimensionPixelSize(R.dimen.dream_overlay_clock_key_text_shadow_radius);
        mKeyShadowOffsetX = context.getResources()
                .getDimensionPixelSize(R.dimen.dream_overlay_clock_key_text_shadow_dx);
        mKeyShadowOffsetY = context.getResources()
                .getDimensionPixelSize(R.dimen.dream_overlay_clock_key_text_shadow_dy);
        mKeyShadowColor = context.getResources().getColor(
                R.color.dream_overlay_clock_key_text_shadow_color);
        mAmbientShadowBlur = context.getResources()
                .getDimensionPixelSize(R.dimen.dream_overlay_clock_ambient_text_shadow_radius);
        mAmbientShadowColor = context.getResources().getColor(
                R.color.dream_overlay_clock_ambient_text_shadow_color);
        mAmbientShadowOffsetX = context.getResources()
                .getDimensionPixelSize(R.dimen.dream_overlay_clock_ambient_text_shadow_dx);
        mAmbientShadowOffsetY = context.getResources()
                .getDimensionPixelSize(R.dimen.dream_overlay_clock_ambient_text_shadow_dy);
    }

    @Override
    public void onDraw(Canvas canvas) {
        // We enhance the shadow by drawing the shadow twice
        getPaint().setShadowLayer(mAmbientShadowBlur, mAmbientShadowOffsetX, mAmbientShadowOffsetY,
                mAmbientShadowColor);
        super.onDraw(canvas);
        canvas.save();
        canvas.clipRect(getScrollX(), getScrollY() + getExtendedPaddingTop(),
                getScrollX() + getWidth(),
                getScrollY() + getHeight());

        getPaint().setShadowLayer(
                mKeyShadowBlur, mKeyShadowOffsetX, mKeyShadowOffsetY, mKeyShadowColor);
        super.onDraw(canvas);
        canvas.restore();
    }
}