diff options
author | Svetoslav Ganov <svetoslavganov@google.com> | 2012-05-16 15:53:35 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-05-16 15:53:35 -0700 |
commit | 6467f94b371e1af1b5e0ab63eb3b39671e04ff8d (patch) | |
tree | fa11b04b87b0889fe3171381a0fe7eaf7b116247 | |
parent | 4ee6a63dfef77e932a9e0e419dc445ae25da6ebd (diff) | |
parent | c826b7d8fa330970d1ab29fd3b2790a5bc01e26c (diff) | |
download | frameworks_base-6467f94b371e1af1b5e0ab63eb3b39671e04ff8d.zip frameworks_base-6467f94b371e1af1b5e0ab63eb3b39671e04ff8d.tar.gz frameworks_base-6467f94b371e1af1b5e0ab63eb3b39671e04ff8d.tar.bz2 |
Merge "Make AbsSeekBar widget adjustable via accessibility actions." into jb-dev
-rw-r--r-- | core/java/android/widget/AbsSeekBar.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/core/java/android/widget/AbsSeekBar.java b/core/java/android/widget/AbsSeekBar.java index ae68794..e217e4f 100644 --- a/core/java/android/widget/AbsSeekBar.java +++ b/core/java/android/widget/AbsSeekBar.java @@ -21,6 +21,7 @@ import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.os.Bundle; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.MotionEvent; @@ -486,5 +487,46 @@ public abstract class AbsSeekBar extends ProgressBar { public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { super.onInitializeAccessibilityNodeInfo(info); info.setClassName(AbsSeekBar.class.getName()); + + if (isEnabled()) { + final int progress = getProgress(); + if (progress > 0) { + info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD); + } + if (progress < getMax()) { + info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD); + } + } + } + + @Override + public boolean performAccessibilityAction(int action, Bundle arguments) { + if (super.performAccessibilityAction(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); + onKeyChange(); + return true; + } + } + return false; } } |