[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:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user