Refactor CaptionAppearanceFragment to improve maintainability (1/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 preview 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: Ie8acdcb8659606ce3faf6d5532cc73ee19024725
This commit is contained in:
menghanli
2022-07-05 17:37:09 +08:00
parent 3d2e5a2447
commit 591e44bb99
7 changed files with 420 additions and 118 deletions

View File

@@ -19,26 +19,24 @@ package com.android.settings.accessibility;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.accessibility.CaptioningManager;
import android.view.accessibility.CaptioningManager.CaptionStyle;
import android.widget.TextView;
import com.android.internal.widget.SubtitleView;
import com.android.settings.R;
/** Grid preference that allows the user to pick a captioning preset type. */
public class PresetPreference extends ListDialogPreference {
private static final float DEFAULT_FONT_SIZE = 32f;
private final CaptioningManager mCaptioningManager;
private static final float DEFAULT_FONT_SIZE = 32f;
private final CaptionHelper mCaptionHelper;
public PresetPreference(Context context, AttributeSet attrs) {
super(context, attrs);
mCaptionHelper = new CaptionHelper(context);
setDialogLayoutResource(R.layout.grid_picker_dialog);
setListItemLayoutResource(R.layout.preset_picker_item);
mCaptioningManager = (CaptioningManager) context.getSystemService(
Context.CAPTIONING_SERVICE);
}
@Override
@@ -50,17 +48,16 @@ public class PresetPreference extends ListDialogPreference {
@Override
protected void onBindListItem(View view, int index) {
final View previewViewport = view.findViewById(R.id.preview_viewport);
final SubtitleView previewText = (SubtitleView) view.findViewById(R.id.preview);
final SubtitleView previewText = view.findViewById(R.id.preview);
final int value = getValueAt(index);
CaptionAppearanceFragment.applyCaptionProperties(
mCaptioningManager, previewText, previewViewport, value);
mCaptionHelper.applyCaptionProperties(previewText, previewViewport, value);
final float density = getContext().getResources().getDisplayMetrics().density;
previewText.setTextSize(DEFAULT_FONT_SIZE * density);
final CharSequence title = getTitleAt(index);
if (title != null) {
final TextView summary = (TextView) view.findViewById(R.id.summary);
final TextView summary = view.findViewById(R.id.summary);
summary.setText(title);
}
}