Skip to content

Commit

Permalink
Android SeekBars announce their value (flutter#4289)
Browse files Browse the repository at this point in the history
* Android SeekBars announce their value

* style
  • Loading branch information
goderbauer authored Oct 31, 2017
1 parent 58fc251 commit b3d345e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
21 changes: 21 additions & 0 deletions shell/platform/android/io/flutter/view/AccessibilityBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ public boolean performAction(int virtualViewId, int action, Bundle arguments) {
// TODO(ianh): bidi support using textDirection
mOwner.dispatchSemanticsAction(virtualViewId, SEMANTICS_ACTION_SCROLL_LEFT);
} else if ((object.actions & SEMANTICS_ACTION_INCREASE) != 0) {
object.value = object.increasedValue;
// Event causes Android to read out the updated value.
sendAccessibilityEvent(virtualViewId, AccessibilityEvent.TYPE_VIEW_SELECTED);
mOwner.dispatchSemanticsAction(virtualViewId, SEMANTICS_ACTION_INCREASE);
} else {
return false;
Expand All @@ -224,6 +227,9 @@ public boolean performAction(int virtualViewId, int action, Bundle arguments) {
// TODO(ianh): bidi support using textDirection
mOwner.dispatchSemanticsAction(virtualViewId, SEMANTICS_ACTION_SCROLL_RIGHT);
} else if ((object.actions & SEMANTICS_ACTION_DECREASE) != 0) {
object.value = object.decreasedValue;
// Event causes Android to read out the updated value.
sendAccessibilityEvent(virtualViewId, AccessibilityEvent.TYPE_VIEW_SELECTED);
mOwner.dispatchSemanticsAction(virtualViewId, SEMANTICS_ACTION_DECREASE);
} else {
return false;
Expand All @@ -237,13 +243,20 @@ public boolean performAction(int virtualViewId, int action, Bundle arguments) {
}
case AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS: {
sendAccessibilityEvent(virtualViewId, AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);

if (mFocusedObject == null) {
// When Android focuses a node, it doesn't invalidate the view.
// (It does when it sends ACTION_CLEAR_ACCESSIBILITY_FOCUS, so
// we only have to worry about this when the focused node is null.)
mOwner.invalidate();
}
mFocusedObject = object;

if ((object.actions & (SEMANTICS_ACTION_INCREASE | SEMANTICS_ACTION_DECREASE)) != 0) {
// SeekBars only announce themselves after this event.
sendAccessibilityEvent(virtualViewId, AccessibilityEvent.TYPE_VIEW_SELECTED);
}

return true;
}
// TODO(goderbauer): Use ACTION_SHOW_ON_SCREEN from Android Support Library after
Expand Down Expand Up @@ -435,6 +448,8 @@ private class SemanticsObject {
int actions;
String label;
String value;
String increasedValue;
String decreasedValue;
String hint;
TextDirection textDirection;

Expand Down Expand Up @@ -476,6 +491,12 @@ void updateWith(ByteBuffer buffer, String[] strings) {
stringIndex = buffer.getInt();
value = stringIndex == -1 ? null : strings[stringIndex];

stringIndex = buffer.getInt();
increasedValue = stringIndex == -1 ? null : strings[stringIndex];

stringIndex = buffer.getInt();
decreasedValue = stringIndex == -1 ? null : strings[stringIndex];

stringIndex = buffer.getInt();
hint = stringIndex == -1 ? null : strings[stringIndex];

Expand Down
14 changes: 13 additions & 1 deletion shell/platform/android/platform_view_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ bool PlatformViewAndroid::ResourceContextMakeCurrent() {

void PlatformViewAndroid::UpdateSemantics(
std::vector<blink::SemanticsNode> update) {
constexpr size_t kBytesPerNode = 28 * sizeof(int32_t);
constexpr size_t kBytesPerNode = 30 * sizeof(int32_t);
constexpr size_t kBytesPerChild = sizeof(int32_t);

JNIEnv* env = fml::jni::AttachCurrentThread();
Expand Down Expand Up @@ -468,6 +468,18 @@ void PlatformViewAndroid::UpdateSemantics(
buffer_int32[position++] = strings.size();
strings.push_back(node.value);
}
if (node.increasedValue.empty()) {
buffer_int32[position++] = -1;
} else {
buffer_int32[position++] = strings.size();
strings.push_back(node.increasedValue);
}
if (node.decreasedValue.empty()) {
buffer_int32[position++] = -1;
} else {
buffer_int32[position++] = strings.size();
strings.push_back(node.decreasedValue);
}
if (node.hint.empty()) {
buffer_int32[position++] = -1;
} else {
Expand Down

0 comments on commit b3d345e

Please sign in to comment.