From 01357b5b73262f4bac353decfd167d748fb6e8a9 Mon Sep 17 00:00:00 2001 From: Kevin Chang Date: Mon, 13 Jan 2020 10:07:19 +0800 Subject: [PATCH] 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 --- .../accessibility/CaptionPropertiesFragment.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java index 9c344df7689..ce81f43646d 100644 --- a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java +++ b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java @@ -95,6 +95,17 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment private final List 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 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment 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);