Loading src/com/android/settings/accessibility/CaptioningBackgroundColorController.java +20 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.settings.accessibility; import android.content.Context; import android.content.res.Resources; import android.graphics.Color; import android.view.accessibility.CaptioningManager.CaptionStyle; import androidx.preference.PreferenceScreen; Loading @@ -31,6 +32,7 @@ public class CaptioningBackgroundColorController extends BasePreferenceControlle implements OnValueChangedListener { private final CaptionHelper mCaptionHelper; private int mCachedNonDefaultOpacity = CaptionStyle.COLOR_UNSPECIFIED; public CaptioningBackgroundColorController(Context context, String preferenceKey) { super(context, preferenceKey); Loading Loading @@ -67,10 +69,26 @@ public class CaptioningBackgroundColorController extends BasePreferenceControlle @Override public void onValueChanged(ListDialogPreference preference, int value) { final int backBackgroundColor = mCaptionHelper.getBackgroundColor(); final int opacity = CaptionUtils.parseOpacity(backBackgroundColor); final boolean isNonDefaultColor = CaptionStyle.hasColor(value); final int opacity = getNonDefaultOpacity(isNonDefaultColor); final int merged = CaptionUtils.mergeColorOpacity(value, opacity); mCaptionHelper.setBackgroundColor(merged); mCaptionHelper.setEnabled(true); } private int getNonDefaultOpacity(boolean isNonDefaultColor) { final int backBackgroundColor = mCaptionHelper.getBackgroundColor(); final int opacity = CaptionUtils.parseOpacity(backBackgroundColor); if (isNonDefaultColor) { final int lastOpacity = mCachedNonDefaultOpacity != CaptionStyle.COLOR_UNSPECIFIED ? mCachedNonDefaultOpacity : opacity; // Reset cached opacity to use current color opacity to merge color. mCachedNonDefaultOpacity = CaptionStyle.COLOR_UNSPECIFIED; return lastOpacity; } // When default captioning color was selected, the opacity become 100% and make opacity // preference disable. Cache the latest opacity to show the correct opacity later. mCachedNonDefaultOpacity = opacity; return opacity; } } src/com/android/settings/accessibility/CaptioningForegroundColorController.java +20 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.settings.accessibility; import android.content.Context; import android.content.res.Resources; import android.view.accessibility.CaptioningManager.CaptionStyle; import androidx.preference.PreferenceScreen; Loading @@ -30,6 +31,7 @@ public class CaptioningForegroundColorController extends BasePreferenceControlle implements OnValueChangedListener { private final CaptionHelper mCaptionHelper; private int mCachedNonDefaultOpacity = CaptionStyle.COLOR_UNSPECIFIED; public CaptioningForegroundColorController(Context context, String preferenceKey) { super(context, preferenceKey); Loading Loading @@ -59,10 +61,26 @@ public class CaptioningForegroundColorController extends BasePreferenceControlle @Override public void onValueChanged(ListDialogPreference preference, int value) { final int foregroundColor = mCaptionHelper.getForegroundColor(); final int opacity = CaptionUtils.parseOpacity(foregroundColor); final boolean isNonDefaultColor = CaptionStyle.hasColor(value); final int opacity = getNonDefaultOpacity(isNonDefaultColor); final int merged = CaptionUtils.mergeColorOpacity(value, opacity); mCaptionHelper.setForegroundColor(merged); mCaptionHelper.setEnabled(true); } private int getNonDefaultOpacity(boolean isNonDefaultColor) { final int foregroundColor = mCaptionHelper.getForegroundColor(); final int opacity = CaptionUtils.parseOpacity(foregroundColor); if (isNonDefaultColor) { final int lastOpacity = mCachedNonDefaultOpacity != CaptionStyle.COLOR_UNSPECIFIED ? mCachedNonDefaultOpacity : opacity; // Reset cached opacity to use current color opacity to merge color. mCachedNonDefaultOpacity = CaptionStyle.COLOR_UNSPECIFIED; return lastOpacity; } // When default captioning color was selected, the opacity become 100% and make opacity // preference disable. Cache the latest opacity to show the correct opacity later. mCachedNonDefaultOpacity = opacity; return opacity; } } src/com/android/settings/accessibility/CaptioningWindowColorController.java +20 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.settings.accessibility; import android.content.Context; import android.content.res.Resources; import android.graphics.Color; import android.view.accessibility.CaptioningManager.CaptionStyle; import androidx.preference.PreferenceScreen; Loading @@ -31,6 +32,7 @@ public class CaptioningWindowColorController extends BasePreferenceController implements OnValueChangedListener { private final CaptionHelper mCaptionHelper; private int mCachedNonDefaultOpacity = CaptionStyle.COLOR_UNSPECIFIED; public CaptioningWindowColorController(Context context, String preferenceKey) { super(context, preferenceKey); Loading Loading @@ -67,10 +69,26 @@ public class CaptioningWindowColorController extends BasePreferenceController @Override public void onValueChanged(ListDialogPreference preference, int value) { final int windowColor = mCaptionHelper.getWindowColor(); final int opacity = CaptionUtils.parseOpacity(windowColor); final boolean isNonDefaultColor = CaptionStyle.hasColor(value); final int opacity = getNonDefaultOpacity(isNonDefaultColor); final int merged = CaptionUtils.mergeColorOpacity(value, opacity); mCaptionHelper.setWindowColor(merged); mCaptionHelper.setEnabled(true); } private int getNonDefaultOpacity(boolean isNonDefaultColor) { final int windowColor = mCaptionHelper.getWindowColor(); final int opacity = CaptionUtils.parseOpacity(windowColor); if (isNonDefaultColor) { final int lastOpacity = mCachedNonDefaultOpacity != CaptionStyle.COLOR_UNSPECIFIED ? mCachedNonDefaultOpacity : opacity; // Reset cached opacity to use current color opacity to merge color. mCachedNonDefaultOpacity = CaptionStyle.COLOR_UNSPECIFIED; return lastOpacity; } // When default captioning color was selected, the opacity become 100% and make opacity // preference disable. Cache the latest opacity to show the correct opacity later. mCachedNonDefaultOpacity = opacity; return opacity; } } tests/robotests/src/com/android/settings/accessibility/CaptioningBackgroundColorControllerTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.content.Context; import android.provider.Settings; import android.util.AttributeSet; import android.view.accessibility.CaptioningManager; import android.view.accessibility.CaptioningManager.CaptionStyle; import androidx.preference.PreferenceScreen; import androidx.test.core.app.ApplicationProvider; Loading Loading @@ -101,6 +102,29 @@ public class CaptioningBackgroundColorControllerTest { assertThat(mPreference.getSummary().toString()).isEqualTo("Red"); } @Test public void setNoneColorValue_shouldNotHaveColor() { final CaptionHelper captionHelper = new CaptionHelper(mContext); captionHelper.setBackgroundColor(0xFFFF0000); mController.displayPreference(mScreen); mPreference.setValue(0x00FFFFFF); assertThat(CaptionStyle.hasColor(captionHelper.getBackgroundColor())).isFalse(); } @Test public void setRedValueFromNoneValue_halfOpacityRedColor_shouldReturnExpectedColor() { final CaptionHelper captionHelper = new CaptionHelper(mContext); captionHelper.setBackgroundColor(0x80FF0000); mController.displayPreference(mScreen); mPreference.setValue(0x00FFFFFF); mPreference.setValue(0xFFFF0000); assertThat(captionHelper.getBackgroundColor()).isEqualTo(0x80FF0000); } @Test public void onValueChanged_shouldSetCaptionEnabled() { mShadowCaptioningManager.setEnabled(false); Loading tests/robotests/src/com/android/settings/accessibility/CaptioningForegroundColorControllerTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.content.Context; import android.provider.Settings; import android.util.AttributeSet; import android.view.accessibility.CaptioningManager; import android.view.accessibility.CaptioningManager.CaptionStyle; import androidx.preference.PreferenceScreen; import androidx.test.core.app.ApplicationProvider; Loading Loading @@ -101,6 +102,29 @@ public class CaptioningForegroundColorControllerTest { assertThat(mPreference.getSummary().toString()).isEqualTo("Red"); } @Test public void setNoneColorValue_shouldNotHaveColor() { final CaptionHelper captionHelper = new CaptionHelper(mContext); captionHelper.setForegroundColor(0xFFFF0000); mController.displayPreference(mScreen); mPreference.setValue(0x00FFFFFF); assertThat(CaptionStyle.hasColor(captionHelper.getForegroundColor())).isFalse(); } @Test public void setRedValueFromNoneValue_halfOpacityRedColor_shouldReturnExpectedColor() { final CaptionHelper captionHelper = new CaptionHelper(mContext); captionHelper.setForegroundColor(0x80FF0000); mController.displayPreference(mScreen); mPreference.setValue(0x00FFFFFF); mPreference.setValue(0xFFFF0000); assertThat(captionHelper.getForegroundColor()).isEqualTo(0x80FF0000); } @Test public void onValueChanged_shouldSetCaptionEnabled() { mShadowCaptioningManager.setEnabled(false); Loading Loading
src/com/android/settings/accessibility/CaptioningBackgroundColorController.java +20 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.settings.accessibility; import android.content.Context; import android.content.res.Resources; import android.graphics.Color; import android.view.accessibility.CaptioningManager.CaptionStyle; import androidx.preference.PreferenceScreen; Loading @@ -31,6 +32,7 @@ public class CaptioningBackgroundColorController extends BasePreferenceControlle implements OnValueChangedListener { private final CaptionHelper mCaptionHelper; private int mCachedNonDefaultOpacity = CaptionStyle.COLOR_UNSPECIFIED; public CaptioningBackgroundColorController(Context context, String preferenceKey) { super(context, preferenceKey); Loading Loading @@ -67,10 +69,26 @@ public class CaptioningBackgroundColorController extends BasePreferenceControlle @Override public void onValueChanged(ListDialogPreference preference, int value) { final int backBackgroundColor = mCaptionHelper.getBackgroundColor(); final int opacity = CaptionUtils.parseOpacity(backBackgroundColor); final boolean isNonDefaultColor = CaptionStyle.hasColor(value); final int opacity = getNonDefaultOpacity(isNonDefaultColor); final int merged = CaptionUtils.mergeColorOpacity(value, opacity); mCaptionHelper.setBackgroundColor(merged); mCaptionHelper.setEnabled(true); } private int getNonDefaultOpacity(boolean isNonDefaultColor) { final int backBackgroundColor = mCaptionHelper.getBackgroundColor(); final int opacity = CaptionUtils.parseOpacity(backBackgroundColor); if (isNonDefaultColor) { final int lastOpacity = mCachedNonDefaultOpacity != CaptionStyle.COLOR_UNSPECIFIED ? mCachedNonDefaultOpacity : opacity; // Reset cached opacity to use current color opacity to merge color. mCachedNonDefaultOpacity = CaptionStyle.COLOR_UNSPECIFIED; return lastOpacity; } // When default captioning color was selected, the opacity become 100% and make opacity // preference disable. Cache the latest opacity to show the correct opacity later. mCachedNonDefaultOpacity = opacity; return opacity; } }
src/com/android/settings/accessibility/CaptioningForegroundColorController.java +20 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.settings.accessibility; import android.content.Context; import android.content.res.Resources; import android.view.accessibility.CaptioningManager.CaptionStyle; import androidx.preference.PreferenceScreen; Loading @@ -30,6 +31,7 @@ public class CaptioningForegroundColorController extends BasePreferenceControlle implements OnValueChangedListener { private final CaptionHelper mCaptionHelper; private int mCachedNonDefaultOpacity = CaptionStyle.COLOR_UNSPECIFIED; public CaptioningForegroundColorController(Context context, String preferenceKey) { super(context, preferenceKey); Loading Loading @@ -59,10 +61,26 @@ public class CaptioningForegroundColorController extends BasePreferenceControlle @Override public void onValueChanged(ListDialogPreference preference, int value) { final int foregroundColor = mCaptionHelper.getForegroundColor(); final int opacity = CaptionUtils.parseOpacity(foregroundColor); final boolean isNonDefaultColor = CaptionStyle.hasColor(value); final int opacity = getNonDefaultOpacity(isNonDefaultColor); final int merged = CaptionUtils.mergeColorOpacity(value, opacity); mCaptionHelper.setForegroundColor(merged); mCaptionHelper.setEnabled(true); } private int getNonDefaultOpacity(boolean isNonDefaultColor) { final int foregroundColor = mCaptionHelper.getForegroundColor(); final int opacity = CaptionUtils.parseOpacity(foregroundColor); if (isNonDefaultColor) { final int lastOpacity = mCachedNonDefaultOpacity != CaptionStyle.COLOR_UNSPECIFIED ? mCachedNonDefaultOpacity : opacity; // Reset cached opacity to use current color opacity to merge color. mCachedNonDefaultOpacity = CaptionStyle.COLOR_UNSPECIFIED; return lastOpacity; } // When default captioning color was selected, the opacity become 100% and make opacity // preference disable. Cache the latest opacity to show the correct opacity later. mCachedNonDefaultOpacity = opacity; return opacity; } }
src/com/android/settings/accessibility/CaptioningWindowColorController.java +20 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.settings.accessibility; import android.content.Context; import android.content.res.Resources; import android.graphics.Color; import android.view.accessibility.CaptioningManager.CaptionStyle; import androidx.preference.PreferenceScreen; Loading @@ -31,6 +32,7 @@ public class CaptioningWindowColorController extends BasePreferenceController implements OnValueChangedListener { private final CaptionHelper mCaptionHelper; private int mCachedNonDefaultOpacity = CaptionStyle.COLOR_UNSPECIFIED; public CaptioningWindowColorController(Context context, String preferenceKey) { super(context, preferenceKey); Loading Loading @@ -67,10 +69,26 @@ public class CaptioningWindowColorController extends BasePreferenceController @Override public void onValueChanged(ListDialogPreference preference, int value) { final int windowColor = mCaptionHelper.getWindowColor(); final int opacity = CaptionUtils.parseOpacity(windowColor); final boolean isNonDefaultColor = CaptionStyle.hasColor(value); final int opacity = getNonDefaultOpacity(isNonDefaultColor); final int merged = CaptionUtils.mergeColorOpacity(value, opacity); mCaptionHelper.setWindowColor(merged); mCaptionHelper.setEnabled(true); } private int getNonDefaultOpacity(boolean isNonDefaultColor) { final int windowColor = mCaptionHelper.getWindowColor(); final int opacity = CaptionUtils.parseOpacity(windowColor); if (isNonDefaultColor) { final int lastOpacity = mCachedNonDefaultOpacity != CaptionStyle.COLOR_UNSPECIFIED ? mCachedNonDefaultOpacity : opacity; // Reset cached opacity to use current color opacity to merge color. mCachedNonDefaultOpacity = CaptionStyle.COLOR_UNSPECIFIED; return lastOpacity; } // When default captioning color was selected, the opacity become 100% and make opacity // preference disable. Cache the latest opacity to show the correct opacity later. mCachedNonDefaultOpacity = opacity; return opacity; } }
tests/robotests/src/com/android/settings/accessibility/CaptioningBackgroundColorControllerTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.content.Context; import android.provider.Settings; import android.util.AttributeSet; import android.view.accessibility.CaptioningManager; import android.view.accessibility.CaptioningManager.CaptionStyle; import androidx.preference.PreferenceScreen; import androidx.test.core.app.ApplicationProvider; Loading Loading @@ -101,6 +102,29 @@ public class CaptioningBackgroundColorControllerTest { assertThat(mPreference.getSummary().toString()).isEqualTo("Red"); } @Test public void setNoneColorValue_shouldNotHaveColor() { final CaptionHelper captionHelper = new CaptionHelper(mContext); captionHelper.setBackgroundColor(0xFFFF0000); mController.displayPreference(mScreen); mPreference.setValue(0x00FFFFFF); assertThat(CaptionStyle.hasColor(captionHelper.getBackgroundColor())).isFalse(); } @Test public void setRedValueFromNoneValue_halfOpacityRedColor_shouldReturnExpectedColor() { final CaptionHelper captionHelper = new CaptionHelper(mContext); captionHelper.setBackgroundColor(0x80FF0000); mController.displayPreference(mScreen); mPreference.setValue(0x00FFFFFF); mPreference.setValue(0xFFFF0000); assertThat(captionHelper.getBackgroundColor()).isEqualTo(0x80FF0000); } @Test public void onValueChanged_shouldSetCaptionEnabled() { mShadowCaptioningManager.setEnabled(false); Loading
tests/robotests/src/com/android/settings/accessibility/CaptioningForegroundColorControllerTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.content.Context; import android.provider.Settings; import android.util.AttributeSet; import android.view.accessibility.CaptioningManager; import android.view.accessibility.CaptioningManager.CaptionStyle; import androidx.preference.PreferenceScreen; import androidx.test.core.app.ApplicationProvider; Loading Loading @@ -101,6 +102,29 @@ public class CaptioningForegroundColorControllerTest { assertThat(mPreference.getSummary().toString()).isEqualTo("Red"); } @Test public void setNoneColorValue_shouldNotHaveColor() { final CaptionHelper captionHelper = new CaptionHelper(mContext); captionHelper.setForegroundColor(0xFFFF0000); mController.displayPreference(mScreen); mPreference.setValue(0x00FFFFFF); assertThat(CaptionStyle.hasColor(captionHelper.getForegroundColor())).isFalse(); } @Test public void setRedValueFromNoneValue_halfOpacityRedColor_shouldReturnExpectedColor() { final CaptionHelper captionHelper = new CaptionHelper(mContext); captionHelper.setForegroundColor(0x80FF0000); mController.displayPreference(mScreen); mPreference.setValue(0x00FFFFFF); mPreference.setValue(0xFFFF0000); assertThat(captionHelper.getForegroundColor()).isEqualTo(0x80FF0000); } @Test public void onValueChanged_shouldSetCaptionEnabled() { mShadowCaptioningManager.setEnabled(false); Loading