[Captioning preferences] Fix wrong color if default color selected
Root cause: When the default captioning color was selected, the opacity became 100% and made the opacity preference is disabled. After changing to non-default color, the opacity preference becomes enabled, but it keeps showing cached opacity in opacity preference and the preview still shows the wrong color. Solution: Cache the latest opacity if default captioning color was selected to show the correct opacity later. Bug: 241308551 Test: make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.accessibility Change-Id: I7712fb25d622da62d7fb2d017e33f94ef258941b
This commit is contained in:
@@ -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;
|
||||
@@ -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);
|
||||
|
@@ -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;
|
||||
@@ -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);
|
||||
|
@@ -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;
|
||||
@@ -102,6 +103,29 @@ public class CaptioningWindowColorControllerTest {
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo("Red");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNoneColorValue_shouldNotHaveColor() {
|
||||
final CaptionHelper captionHelper = new CaptionHelper(mContext);
|
||||
captionHelper.setWindowColor(0xFFFF0000);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.setValue(0x00FFFFFF);
|
||||
|
||||
assertThat(CaptionStyle.hasColor(captionHelper.getWindowColor())).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setRedValueFromNoneValue_halfOpacityRedColor_shouldReturnExpectedColor() {
|
||||
final CaptionHelper captionHelper = new CaptionHelper(mContext);
|
||||
captionHelper.setWindowColor(0x80FF0000);
|
||||
mController.displayPreference(mScreen);
|
||||
mPreference.setValue(0x00FFFFFF);
|
||||
|
||||
mPreference.setValue(0xFFFF0000);
|
||||
|
||||
assertThat(captionHelper.getWindowColor()).isEqualTo(0x80FF0000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onValueChanged_shouldSetCaptionEnabled() {
|
||||
mShadowCaptioningManager.setEnabled(false);
|
||||
|
Reference in New Issue
Block a user