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,7 +16,11 @@
package com.android.settings.accessibility;
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
import android.content.Context;
import android.provider.Settings;
import android.view.View;
import android.view.accessibility.CaptioningManager;
@@ -45,6 +49,29 @@ public class CaptionHelper {
mCaptioningManager = context.getSystemService(CaptioningManager.class);
}
/**
* Sets the user's preferred captioning enabled state.
*
* @param enabled Whether to enable or disable captioning manager.
*/
public void setEnabled(boolean enabled) {
if (isEnabled() == enabled) {
return;
}
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, enabled ? ON : OFF);
}
/**
* Gets if the captioning manager is enabled.
*
* @return True if the captioning manager is enabled, false otherwise.
*/
public boolean isEnabled() {
return mCaptioningManager.isEnabled();
}
/**
* Updates font style of captioning properties for preview screen.
*