Loading packages/SystemUI/shared/res/values-my/bools.xml 0 → 100644 +25 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- 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. --> <!-- Formatting note: terminate all comments with a period, to avoid breaking the documentation output. To suppress comment lines from the documentation output, insert an eat-comment element after the comment lines. --> <resources> <!-- Whether to add padding at the bottom of the complication clock --> <bool name="dream_overlay_complication_clock_bottom_padding">true</bool> </resources> No newline at end of file packages/SystemUI/shared/res/values/bools.xml 0 → 100644 +25 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- 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. --> <!-- Formatting note: terminate all comments with a period, to avoid breaking the documentation output. To suppress comment lines from the documentation output, insert an eat-comment element after the comment lines. --> <resources> <!-- Whether to add padding at the bottom of the complication clock --> <bool name="dream_overlay_complication_clock_bottom_padding">false</bool> </resources> No newline at end of file packages/SystemUI/shared/src/com/android/systemui/shared/shadow/DoubleShadowTextClock.kt +48 −16 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.systemui.shared.shadow import android.content.Context import android.content.res.Resources import android.content.res.TypedArray import android.graphics.Canvas import android.util.AttributeSet import android.widget.TextClock Loading @@ -31,19 +33,40 @@ constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0 defStyleRes: Int = 0, ) : TextClock(context, attrs, defStyleAttr, defStyleRes) { private val mAmbientShadowInfo: ShadowInfo private val mKeyShadowInfo: ShadowInfo private lateinit var mAmbientShadowInfo: ShadowInfo private lateinit var mKeyShadowInfo: ShadowInfo private var attributesInput: TypedArray? = null private var resources: Resources? = null constructor( resources: Resources, context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0, attributesInput: TypedArray? = null ) : this(context, attrs, defStyleAttr, defStyleRes) { this.attributesInput = attributesInput this.resources = resources this.initializeAttributes(attrs, defStyleAttr, defStyleRes) } init { val attributes = context.obtainStyledAttributes( initializeAttributes(attrs, defStyleAttr, defStyleRes) } private fun initializeAttributes(attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) { var attributes: TypedArray = this.attributesInput ?: context.obtainStyledAttributes( attrs, R.styleable.DoubleShadowTextClock, defStyleAttr, defStyleRes ) var resource: Resources = this.resources ?: context.resources try { val keyShadowBlur = attributes.getDimensionPixelSize(R.styleable.DoubleShadowTextClock_keyShadowBlur, 0) Loading Loading @@ -98,18 +121,27 @@ constructor( 0 ) if (removeTextDescent) { setPaddingRelative( 0, 0, 0, textDescentExtraPadding - floor(paint.fontMetrics.descent.toDouble()).toInt() ) val addBottomPaddingToClock = resource.getBoolean(R.bool.dream_overlay_complication_clock_bottom_padding) val metrics = paint.fontMetrics val padding = if (addBottomPaddingToClock) { textDescentExtraPadding + floor(metrics.descent.toDouble()).toInt() / paddingDividedOffset } else { textDescentExtraPadding - floor(metrics.descent.toDouble()).toInt() } setPaddingRelative(0, 0, 0, padding) } } finally { attributes.recycle() } } companion object { private val paddingDividedOffset = 2 } public override fun onDraw(canvas: Canvas) { applyShadows(mKeyShadowInfo, mAmbientShadowInfo, this, canvas) { super.onDraw(canvas) } } Loading packages/SystemUI/tests/src/com/android/systemui/shadow/DoubleShadowTextClockTest.kt 0 → 100644 +88 −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.shadow import android.content.Context import android.content.res.Resources import android.content.res.TypedArray import android.testing.AndroidTestingRunner import android.util.AttributeSet import androidx.test.filters.SmallTest import com.android.systemui.R import com.android.systemui.SysuiTestCase import com.android.systemui.shared.shadow.DoubleShadowTextClock import com.android.systemui.util.mockito.whenever import junit.framework.Assert.assertTrue import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.MockitoAnnotations import org.mockito.junit.MockitoJUnit import org.mockito.junit.MockitoRule @SmallTest @RunWith(AndroidTestingRunner::class) class DoubleShadowTextClockTest : SysuiTestCase() { @get:Rule val mockito: MockitoRule = MockitoJUnit.rule() @Mock lateinit var resources: Resources @Mock lateinit var attributes: TypedArray private lateinit var context: Context private var attrs: AttributeSet? = null @Before fun setup() { MockitoAnnotations.initMocks(this) context = getContext() whenever(attributes.getBoolean(R.styleable.DoubleShadowTextClock_removeTextDescent, false)) .thenReturn(true) } @Test fun testAddingPaddingToBottomOfClockWhenConfigIsTrue() { whenever(resources.getBoolean(R.bool.dream_overlay_complication_clock_bottom_padding)) .thenReturn(true) val doubleShadowTextClock = DoubleShadowTextClock( resources = resources, context = context, attrs = attrs, attributesInput = attributes ) assertTrue(doubleShadowTextClock.paddingBottom > 0) } @Test fun testRemovingPaddingToBottomOfClockWhenConfigIsFalse() { whenever(resources.getBoolean(R.bool.dream_overlay_complication_clock_bottom_padding)) .thenReturn(false) val doubleShadowTextClock = DoubleShadowTextClock( resources = resources, context = context, attrs = attrs, attributesInput = attributes ) assertTrue(doubleShadowTextClock.paddingBottom < 0) } } Loading
packages/SystemUI/shared/res/values-my/bools.xml 0 → 100644 +25 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- 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. --> <!-- Formatting note: terminate all comments with a period, to avoid breaking the documentation output. To suppress comment lines from the documentation output, insert an eat-comment element after the comment lines. --> <resources> <!-- Whether to add padding at the bottom of the complication clock --> <bool name="dream_overlay_complication_clock_bottom_padding">true</bool> </resources> No newline at end of file
packages/SystemUI/shared/res/values/bools.xml 0 → 100644 +25 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- 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. --> <!-- Formatting note: terminate all comments with a period, to avoid breaking the documentation output. To suppress comment lines from the documentation output, insert an eat-comment element after the comment lines. --> <resources> <!-- Whether to add padding at the bottom of the complication clock --> <bool name="dream_overlay_complication_clock_bottom_padding">false</bool> </resources> No newline at end of file
packages/SystemUI/shared/src/com/android/systemui/shared/shadow/DoubleShadowTextClock.kt +48 −16 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.systemui.shared.shadow import android.content.Context import android.content.res.Resources import android.content.res.TypedArray import android.graphics.Canvas import android.util.AttributeSet import android.widget.TextClock Loading @@ -31,19 +33,40 @@ constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0 defStyleRes: Int = 0, ) : TextClock(context, attrs, defStyleAttr, defStyleRes) { private val mAmbientShadowInfo: ShadowInfo private val mKeyShadowInfo: ShadowInfo private lateinit var mAmbientShadowInfo: ShadowInfo private lateinit var mKeyShadowInfo: ShadowInfo private var attributesInput: TypedArray? = null private var resources: Resources? = null constructor( resources: Resources, context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0, attributesInput: TypedArray? = null ) : this(context, attrs, defStyleAttr, defStyleRes) { this.attributesInput = attributesInput this.resources = resources this.initializeAttributes(attrs, defStyleAttr, defStyleRes) } init { val attributes = context.obtainStyledAttributes( initializeAttributes(attrs, defStyleAttr, defStyleRes) } private fun initializeAttributes(attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) { var attributes: TypedArray = this.attributesInput ?: context.obtainStyledAttributes( attrs, R.styleable.DoubleShadowTextClock, defStyleAttr, defStyleRes ) var resource: Resources = this.resources ?: context.resources try { val keyShadowBlur = attributes.getDimensionPixelSize(R.styleable.DoubleShadowTextClock_keyShadowBlur, 0) Loading Loading @@ -98,18 +121,27 @@ constructor( 0 ) if (removeTextDescent) { setPaddingRelative( 0, 0, 0, textDescentExtraPadding - floor(paint.fontMetrics.descent.toDouble()).toInt() ) val addBottomPaddingToClock = resource.getBoolean(R.bool.dream_overlay_complication_clock_bottom_padding) val metrics = paint.fontMetrics val padding = if (addBottomPaddingToClock) { textDescentExtraPadding + floor(metrics.descent.toDouble()).toInt() / paddingDividedOffset } else { textDescentExtraPadding - floor(metrics.descent.toDouble()).toInt() } setPaddingRelative(0, 0, 0, padding) } } finally { attributes.recycle() } } companion object { private val paddingDividedOffset = 2 } public override fun onDraw(canvas: Canvas) { applyShadows(mKeyShadowInfo, mAmbientShadowInfo, this, canvas) { super.onDraw(canvas) } } Loading
packages/SystemUI/tests/src/com/android/systemui/shadow/DoubleShadowTextClockTest.kt 0 → 100644 +88 −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.shadow import android.content.Context import android.content.res.Resources import android.content.res.TypedArray import android.testing.AndroidTestingRunner import android.util.AttributeSet import androidx.test.filters.SmallTest import com.android.systemui.R import com.android.systemui.SysuiTestCase import com.android.systemui.shared.shadow.DoubleShadowTextClock import com.android.systemui.util.mockito.whenever import junit.framework.Assert.assertTrue import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.MockitoAnnotations import org.mockito.junit.MockitoJUnit import org.mockito.junit.MockitoRule @SmallTest @RunWith(AndroidTestingRunner::class) class DoubleShadowTextClockTest : SysuiTestCase() { @get:Rule val mockito: MockitoRule = MockitoJUnit.rule() @Mock lateinit var resources: Resources @Mock lateinit var attributes: TypedArray private lateinit var context: Context private var attrs: AttributeSet? = null @Before fun setup() { MockitoAnnotations.initMocks(this) context = getContext() whenever(attributes.getBoolean(R.styleable.DoubleShadowTextClock_removeTextDescent, false)) .thenReturn(true) } @Test fun testAddingPaddingToBottomOfClockWhenConfigIsTrue() { whenever(resources.getBoolean(R.bool.dream_overlay_complication_clock_bottom_padding)) .thenReturn(true) val doubleShadowTextClock = DoubleShadowTextClock( resources = resources, context = context, attrs = attrs, attributesInput = attributes ) assertTrue(doubleShadowTextClock.paddingBottom > 0) } @Test fun testRemovingPaddingToBottomOfClockWhenConfigIsFalse() { whenever(resources.getBoolean(R.bool.dream_overlay_complication_clock_bottom_padding)) .thenReturn(false) val doubleShadowTextClock = DoubleShadowTextClock( resources = resources, context = context, attrs = attrs, attributesInput = attributes ) assertTrue(doubleShadowTextClock.paddingBottom < 0) } }