Refactor CaptionAppearanceFragment to improve maintainability (3/n)
Root cause: There is a bunch of different logic of preferences in CaptionAppearanceFragment. It’s hard to implement new features and hard to maintain and hard to be testable. Solution: Move out color and edge preference logic of CaptionAppearanceFragment into controllers to reduce the complexity of the relationship between preference and fragment. Bug: 197695932 Test: make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.accessibility Change-Id: I8ed80b445a0d376a7e9dda87feda82420a78a9da
This commit is contained in:
@@ -19,10 +19,12 @@ package com.android.settings.accessibility;
|
||||
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
||||
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.view.View;
|
||||
import android.view.accessibility.CaptioningManager;
|
||||
import android.view.accessibility.CaptioningManager.CaptionStyle;
|
||||
|
||||
import com.android.internal.widget.SubtitleView;
|
||||
import com.android.settings.R;
|
||||
@@ -32,9 +34,7 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Helper class for caption.
|
||||
*/
|
||||
/** Helper class for caption. */
|
||||
public class CaptionHelper {
|
||||
|
||||
/* WebVtt specifies line height as 5.3% of the viewport height. */
|
||||
@@ -42,10 +42,12 @@ public class CaptionHelper {
|
||||
static final float LINE_HEIGHT_RATIO = 0.0533f;
|
||||
|
||||
private final Context mContext;
|
||||
private final ContentResolver mContentResolver;
|
||||
private final CaptioningManager mCaptioningManager;
|
||||
|
||||
public CaptionHelper(Context context) {
|
||||
mContext = context;
|
||||
mContentResolver = mContext.getContentResolver();
|
||||
mCaptioningManager = context.getSystemService(CaptioningManager.class);
|
||||
}
|
||||
|
||||
@@ -104,4 +106,84 @@ public class CaptionHelper {
|
||||
previewText.setText(R.string.captioning_preview_characters);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user's preferred captioning background color.
|
||||
*
|
||||
* @param color The captioning background color
|
||||
*/
|
||||
public void setBackgroundColor(int color) {
|
||||
Settings.Secure.putInt(mContentResolver,
|
||||
Settings.Secure.ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR, color);
|
||||
}
|
||||
|
||||
/** Returns the captioning background color.*/
|
||||
public int getBackgroundColor() {
|
||||
final CaptionStyle attrs = CaptionStyle.getCustomStyle(mContentResolver);
|
||||
return attrs.hasBackgroundColor() ? attrs.backgroundColor : CaptionStyle.COLOR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user's preferred captioning foreground color.
|
||||
*
|
||||
* @param color The captioning foreground color
|
||||
*/
|
||||
public void setForegroundColor(int color) {
|
||||
Settings.Secure.putInt(mContentResolver,
|
||||
Settings.Secure.ACCESSIBILITY_CAPTIONING_FOREGROUND_COLOR, color);
|
||||
}
|
||||
|
||||
/** Returns the captioning foreground color.*/
|
||||
public int getForegroundColor() {
|
||||
final CaptionStyle attrs = CaptionStyle.getCustomStyle(mContentResolver);
|
||||
return attrs.hasForegroundColor() ? attrs.foregroundColor : CaptionStyle.COLOR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user's preferred captioning window color.
|
||||
*
|
||||
* @param color The captioning window color
|
||||
*/
|
||||
public void setWindowColor(int color) {
|
||||
Settings.Secure.putInt(mContentResolver,
|
||||
Settings.Secure.ACCESSIBILITY_CAPTIONING_WINDOW_COLOR, color);
|
||||
}
|
||||
|
||||
/** Returns the captioning window color.*/
|
||||
public int getWindowColor() {
|
||||
final CaptionStyle attrs = CaptionStyle.getCustomStyle(mContentResolver);
|
||||
return attrs.hasWindowColor() ? attrs.windowColor : CaptionStyle.COLOR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user's preferred captioning edge color.
|
||||
*
|
||||
* @param color The captioning edge color
|
||||
*/
|
||||
public void setEdgeColor(int color) {
|
||||
Settings.Secure.putInt(mContentResolver,
|
||||
Settings.Secure.ACCESSIBILITY_CAPTIONING_EDGE_COLOR, color);
|
||||
}
|
||||
|
||||
/** Returns the captioning edge color.*/
|
||||
public int getEdgeColor() {
|
||||
final CaptionStyle attrs = CaptionStyle.getCustomStyle(mContentResolver);
|
||||
return attrs.edgeColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user's preferred captioning edge type.
|
||||
*
|
||||
* @param type The captioning edge type
|
||||
*/
|
||||
public void setEdgeType(int type) {
|
||||
Settings.Secure.putInt(mContentResolver,
|
||||
Settings.Secure.ACCESSIBILITY_CAPTIONING_EDGE_TYPE, type);
|
||||
}
|
||||
|
||||
/** Returns the captioning edge type.*/
|
||||
public int getEdgeType() {
|
||||
final CaptionStyle attrs = CaptionStyle.getCustomStyle(mContentResolver);
|
||||
return attrs.edgeType;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user