Change string of switchbar and installed service category title

Bug: 122897712
Test: Visual
Change-Id: I4e15ebc8b91c58d24aadb7e665c6692ebcd627a8
This commit is contained in:
Kevin Chang
2019-05-06 13:31:05 +08:00
parent 1915fe3b67
commit 7eddb0e4dc
3 changed files with 35 additions and 11 deletions

View File

@@ -61,6 +61,16 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
void onSwitchChanged(Switch switchView, boolean isChecked);
}
public interface LabelDelegate {
/**
* Called to create label and set the title with Accessibility
* service name to the textView of switchBar.
*
* @param isChecked The checked state of switchView.
*/
String createLabel(boolean isChecked);
}
private static final int[] XML_ATTRIBUTES = {
R.attr.switchBarMarginStart,
R.attr.switchBarMarginEnd,
@@ -90,6 +100,7 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
private boolean mDisabledByAdmin;
private EnforcedAdmin mEnforcedAdmin = null;
private String mMetricsTag;
private LabelDelegate mLabelDelegate;
public SwitchBar(Context context) {
@@ -178,7 +189,11 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
}
public void setTextViewLabelAndBackground(boolean isChecked) {
mLabel = getResources().getString(isChecked ? mOnTextId : mOffTextId);
if(mLabelDelegate != null) {
mLabel = mLabelDelegate.createLabel(isChecked);
} else {
mLabel = getResources().getString(isChecked ? mOnTextId : mOffTextId);
}
setBackgroundColor(isChecked ? mBackgroundActivatedColor : mBackgroundColor);
updateText();
}
@@ -383,4 +398,9 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
requestLayout();
}
public void setLabelDelegate(LabelDelegate labelDelegate) {
mLabelDelegate = labelDelegate;
setTextViewLabelAndBackground(isChecked());
}
}