Merge "Uses a custom state description for the Audio Balance seek bar." into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
034e6db92e
@@ -20,6 +20,7 @@ import static android.view.HapticFeedbackConstants.CLOCK_TICK;
|
||||
|
||||
import static com.android.settings.Utils.isNightMode;
|
||||
|
||||
import android.annotation.StringRes;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Resources;
|
||||
@@ -86,6 +87,14 @@ public class BalanceSeekBar extends SeekBar {
|
||||
Settings.System.putFloatForUser(mContext.getContentResolver(),
|
||||
Settings.System.MASTER_BALANCE, balance, UserHandle.USER_CURRENT);
|
||||
}
|
||||
final int max = getMax();
|
||||
if (Flags.audioBalanceStateDescription() && max > 0) {
|
||||
seekBar.setStateDescription(createStateDescription(mContext,
|
||||
R.string.audio_seek_bar_state_left_first,
|
||||
R.string.audio_seek_bar_state_right_first,
|
||||
progress,
|
||||
max));
|
||||
}
|
||||
// If fromUser is false, the call is a set from the framework on creation or on
|
||||
// internal update. The progress may be zero, ignore (don't change system settings).
|
||||
|
||||
@@ -161,5 +170,19 @@ public class BalanceSeekBar extends SeekBar {
|
||||
canvas.restore();
|
||||
super.onDraw(canvas);
|
||||
}
|
||||
|
||||
private static CharSequence createStateDescription(Context context,
|
||||
@StringRes int resIdLeftFirst, @StringRes int resIdRightFirst,
|
||||
int progress, float max) {
|
||||
final boolean isLayoutRtl = context.getResources().getConfiguration().getLayoutDirection()
|
||||
== LAYOUT_DIRECTION_RTL;
|
||||
final int rightPercent = (int) (100 * (progress / max));
|
||||
final int leftPercent = 100 - rightPercent;
|
||||
if (rightPercent > leftPercent || (rightPercent == leftPercent && isLayoutRtl)) {
|
||||
return context.getString(resIdRightFirst, rightPercent, leftPercent);
|
||||
} else {
|
||||
return context.getString(resIdLeftFirst, leftPercent, rightPercent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user