Refactor CaptionAppearanceFragment to improve maintainability (2/n)

Root cause: There is a bunch of different logic of preferences in CaptionAppearanceFragment. It’s hard to implement new features and hard to maintain and hard to be testable.
Solution: Move out font size and type face preference logic of CaptionAppearanceFragment into controllers to reduce the complexity of the relationship between preference and fragment.

Bug: 197695932
Test: make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.accessibility
Change-Id: Ia52cd272495d49a772c981f51e190ff7d29ee14f
This commit is contained in:
menghanli
2022-07-05 17:54:18 +08:00
parent 591e44bb99
commit 3a591f9a34
9 changed files with 431 additions and 69 deletions

View File

@@ -16,10 +16,16 @@
package com.android.settings.accessibility;
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.provider.Settings;
import android.view.View;
import android.view.accessibility.CaptioningManager;
@@ -101,4 +107,26 @@ public class CaptionHelperTest {
verify(mSubtitleView).setText(text);
}
@Test
public void enableCaptioningManager_shouldSetCaptionEnabled() {
when(mCaptioningManager.isEnabled()).thenReturn(false);
mCaptionHelper.setEnabled(true);
final boolean isCaptionEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, OFF) == ON;
assertThat(isCaptionEnabled).isTrue();
}
@Test
public void disableCaptioningManager_shouldSetCaptionDisabled() {
when(mCaptioningManager.isEnabled()).thenReturn(true);
mCaptionHelper.setEnabled(false);
final boolean isCaptionEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, OFF) == ON;
assertThat(isCaptionEnabled).isFalse();
}
}