Modify the code logic of OnLayoutChangeListener in Caption preferences
Remove the listener and add statement to refresh the text when the caption turns on.
Bug: 142632389
Test: Manual
Change-Id: Ic5711309c5b8af9834e5439d825b4cb2ed55fe01
Merged-In: Ic5711309c5b8af9834e5439d825b4cb2ed55fe01
diff --git a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java
index 9c344df..ce81f43 100644
--- a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java
+++ b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java
@@ -95,6 +95,17 @@
private final List<Preference> mPreferenceList = new ArrayList<>();
+ private final View.OnLayoutChangeListener mLayoutChangeListener =
+ new View.OnLayoutChangeListener() {
+ @Override
+ public void onLayoutChange(View v, int left, int top, int right, int bottom,
+ int oldLeft, int oldTop, int oldRight, int oldBottom) {
+ // Remove the listener once the callback is triggered.
+ mPreviewViewport.removeOnLayoutChangeListener(this);
+ refreshPreviewText();
+ }
+ };
+
@Override
public int getMetricsCategory() {
return SettingsEnums.ACCESSIBILITY_CAPTION_PROPERTIES;
@@ -192,9 +203,7 @@
mPreviewWindow = captionPreview.findViewById(R.id.preview_window);
mPreviewViewport = captionPreview.findViewById(R.id.preview_viewport);
- mPreviewViewport.addOnLayoutChangeListener(
- (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom)
- -> refreshPreviewText());
+ mPreviewViewport.addOnLayoutChangeListener(mLayoutChangeListener);
final Resources res = getResources();
final int[] presetValues = res.getIntArray(R.array.captioning_preset_selector_values);