diff --git a/res/layout/accessibility_text_reading_reset_button.xml b/res/layout/accessibility_text_reading_reset_button.xml index f3691e1f816..a0bdcbad81d 100644 --- a/res/layout/accessibility_text_reading_reset_button.xml +++ b/res/layout/accessibility_text_reading_reset_button.xml @@ -27,14 +27,11 @@ android:id="@+id/reset_button" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_gravity="center|end" + android:layout_gravity="center_vertical|start" android:paddingVertical="14dp" - android:background="@null" android:drawableStart="@drawable/ic_history" android:drawablePadding="9dp" - android:drawableTint="?android:attr/colorAccent" - android:textColor="?android:attr/colorAccent" - android:textSize="16sp" - android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" - android:text="@string/accessibility_text_reading_reset_button_title"/> + android:drawableTint="@color/settingslib_btn_colored_text_material" + android:text="@string/accessibility_text_reading_reset_button_title" + style="@style/ActionPrimaryButton"/> diff --git a/res/layout/icon_discrete_slider.xml b/res/layout/icon_discrete_slider.xml index b1d960f8dec..47be5efff79 100644 --- a/res/layout/icon_discrete_slider.xml +++ b/res/layout/icon_discrete_slider.xml @@ -19,6 +19,7 @@ android:id="@+id/seekbar_frame" android:layout_width="match_parent" android:layout_height="wrap_content" + android:clipChildren="false" android:background="?android:colorBackground" android:gravity="center_vertical"> diff --git a/res/values-land/dimens.xml b/res/values-land/dimens.xml index 37e71e2174e..5248da63de4 100755 --- a/res/values-land/dimens.xml +++ b/res/values-land/dimens.xml @@ -18,8 +18,6 @@ 421dip 68dip - 100dp - 46dip diff --git a/res/values-sw600dp-land/dimens.xml b/res/values-sw600dp-land/dimens.xml index 4e4a1d38e97..015a6af2dde 100755 --- a/res/values-sw600dp-land/dimens.xml +++ b/res/values-sw600dp-land/dimens.xml @@ -19,8 +19,6 @@ 72dip 48dip - 150dp - 20dp 24dp diff --git a/res/values/dimens.xml b/res/values/dimens.xml index b67bb22481b..c80e42c74c0 100755 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -49,7 +49,7 @@ 16dp 3dp - 200dp + 300dp 200dp diff --git a/res/xml/accessibility_text_reading_options.xml b/res/xml/accessibility_text_reading_options.xml index ad742c949b4..7fd5ff9a581 100644 --- a/res/xml/accessibility_text_reading_options.xml +++ b/res/xml/accessibility_text_reading_options.xml @@ -27,7 +27,7 @@ mLifecycle = new AtomicReference(); + + /** + * Constructor + * @param lifecycle {@link Lifecycle} to monitor + */ + @VisibleForTesting + protected LifecycleCallbackAdapter(@NonNull Lifecycle lifecycle) { + mLifecycle.set(lifecycle); + lifecycle.addObserver(this); + } + + /** + * Get {@link Lifecycle} under monitor. + * @return {@link Lifecycle}. Return {@code null} when closed. + */ + @VisibleForTesting + public Lifecycle getLifecycle() { + return mLifecycle.get(); + } + + /** + * Check current callback status. + * @return true when callback is active. + */ + public abstract boolean isCallbackActive(); + + /** + * Change callback status. + * @param isActive true to active callback, otherwise inactive. + */ + public abstract void setCallbackActive(boolean isActive); + + /** + * Implementation of LifecycleEventObserver. + */ + public void onStateChanged(LifecycleOwner source, Lifecycle.Event event) { + if (mLifecycle.get() == null) { + return; + } + + Lifecycle.State state = event.getTargetState(); + boolean expectCallbackActive = state.isAtLeast(Lifecycle.State.STARTED); + if (expectCallbackActive != isCallbackActive()) { + setCallbackActive(expectCallbackActive); + } + if (state == Lifecycle.State.DESTROYED) { + close(); + } + } + + /** + * Implementation of AutoCloseable. + */ + @MainThread + public void close() { + Lifecycle lifecycle = mLifecycle.getAndSet(null); + if (lifecycle != null) { + lifecycle.removeObserver(this); + } + } +} diff --git a/tests/unit/src/com/android/settings/network/helper/LifecycleCallbackAdapterTest.java b/tests/unit/src/com/android/settings/network/helper/LifecycleCallbackAdapterTest.java new file mode 100644 index 00000000000..ddeb3f81bd9 --- /dev/null +++ b/tests/unit/src/com/android/settings/network/helper/LifecycleCallbackAdapterTest.java @@ -0,0 +1,111 @@ +/* + * 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.settings.network.helper; + +import static com.google.common.truth.Truth.assertThat; + +import androidx.lifecycle.Lifecycle; +import androidx.lifecycle.LifecycleOwner; +import androidx.lifecycle.LifecycleRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +public class LifecycleCallbackAdapterTest implements LifecycleOwner { + + private final LifecycleRegistry mRegistry = LifecycleRegistry.createUnsafe(this); + + private TestObj mTarget; + + @Before + public void setUp() { + mTarget = new TestObj(getLifecycle()); + } + + public Lifecycle getLifecycle() { + return mRegistry; + } + + @Test + public void lifecycle_get_lifecycleToMonitor() { + assertThat(mTarget.getLifecycle()).isEqualTo(mRegistry); + } + + @Test + public void lifecycle_stateChangeToStart_callbackActive() { + mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE); + + assertThat(mTarget.getCallbackCount()).isEqualTo(0); + assertThat(mTarget.isCallbackActive()).isEqualTo(Boolean.FALSE); + + mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START); + + assertThat(mTarget.getCallbackCount()).isEqualTo(1); + assertThat(mTarget.isCallbackActive()).isEqualTo(Boolean.TRUE); + } + + @Test + public void lifecycle_stateChangeToStop_callbackInActive() { + mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE); + mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START); + mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP); + + assertThat(mTarget.getCallbackCount()).isEqualTo(2); + assertThat(mTarget.isCallbackActive()).isEqualTo(Boolean.FALSE); + } + + @Test + public void lifecycle_stateChangeToDestroy_noFurtherActive() { + mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE); + mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START); + mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP); + mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY); + + assertThat(mTarget.getCallbackCount()).isEqualTo(2); + assertThat(mTarget.isCallbackActive()).isEqualTo(Boolean.FALSE); + + mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE); + mRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START); + + assertThat(mTarget.getCallbackCount()).isEqualTo(2); + assertThat(mTarget.isCallbackActive()).isEqualTo(Boolean.FALSE); + } + + public static class TestObj extends LifecycleCallbackAdapter { + boolean mIsActive; + int mNumberOfCallback; + + public TestObj(Lifecycle lifecycle) { + super(lifecycle); + } + + public boolean isCallbackActive() { + return mIsActive; + } + + public void setCallbackActive(boolean isActive) { + mIsActive = isActive; + mNumberOfCallback ++; + } + + protected int getCallbackCount() { + return mNumberOfCallback; + } + } +}