Merge "D-pad should be able to push seek bar to 0 or max value"
This commit is contained in:
committed by
Android (Google) Code Review
commit
df3139db33
@@ -703,9 +703,9 @@ public abstract class AbsSeekBar extends ProgressBar {
|
||||
// fallthrough
|
||||
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
||||
increment = isLayoutRtl() ? -increment : increment;
|
||||
int progress = getProgress() + increment;
|
||||
if (progress > 0 && progress < getMax()) {
|
||||
setProgress(progress, true);
|
||||
|
||||
// Let progress bar handle clamping values.
|
||||
if (setProgress(getProgress() + increment, true)) {
|
||||
onKeyChange();
|
||||
return true;
|
||||
}
|
||||
@@ -729,10 +729,10 @@ public abstract class AbsSeekBar extends ProgressBar {
|
||||
if (isEnabled()) {
|
||||
final int progress = getProgress();
|
||||
if (progress > 0) {
|
||||
info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
|
||||
info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD);
|
||||
}
|
||||
if (progress < getMax()) {
|
||||
info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
|
||||
info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -743,29 +743,26 @@ public abstract class AbsSeekBar extends ProgressBar {
|
||||
if (super.performAccessibilityActionInternal(action, arguments)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
final int progress = getProgress();
|
||||
final int increment = Math.max(1, Math.round((float) getMax() / 5));
|
||||
switch (action) {
|
||||
case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD: {
|
||||
if (progress <= 0) {
|
||||
return false;
|
||||
}
|
||||
setProgress(progress - increment, true);
|
||||
onKeyChange();
|
||||
return true;
|
||||
}
|
||||
case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD: {
|
||||
if (progress >= getMax()) {
|
||||
return false;
|
||||
}
|
||||
setProgress(progress + increment, true);
|
||||
|
||||
if (action == AccessibilityNodeInfo.ACTION_SCROLL_FORWARD
|
||||
|| action == AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
|
||||
int increment = Math.max(1, Math.round((float) getMax() / 5));
|
||||
if (action == AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
|
||||
increment = -increment;
|
||||
}
|
||||
|
||||
// Let progress bar handle clamping values.
|
||||
if (setProgress(getProgress() + increment, true)) {
|
||||
onKeyChange();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ import android.graphics.drawable.shapes.Shape;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.MathUtils;
|
||||
import android.util.Pools.SynchronizedPool;
|
||||
import android.view.Gravity;
|
||||
import android.view.RemotableViewMethod;
|
||||
@@ -1341,23 +1342,22 @@ public class ProgressBar extends View {
|
||||
}
|
||||
|
||||
@android.view.RemotableViewMethod
|
||||
synchronized void setProgress(int progress, boolean fromUser) {
|
||||
synchronized boolean setProgress(int progress, boolean fromUser) {
|
||||
if (mIndeterminate) {
|
||||
return;
|
||||
// Not applicable.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (progress < 0) {
|
||||
progress = 0;
|
||||
progress = MathUtils.constrain(progress, 0, mMax);
|
||||
|
||||
if (progress == mProgress) {
|
||||
// No change from current.
|
||||
return false;
|
||||
}
|
||||
|
||||
if (progress > mMax) {
|
||||
progress = mMax;
|
||||
}
|
||||
|
||||
if (progress != mProgress) {
|
||||
mProgress = progress;
|
||||
refreshProgress(R.id.progress, mProgress, fromUser);
|
||||
}
|
||||
mProgress = progress;
|
||||
refreshProgress(R.id.progress, mProgress, fromUser);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user