Merge "[Captioning preferences] Fix wrong color if default color selected"

This commit is contained in:
Menghan Li
2022-08-17 08:20:48 +00:00
committed by Android (Google) Code Review
6 changed files with 132 additions and 6 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}