aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornchalko <nchalko@google.com>2018-08-31 11:02:22 -0700
committerCopybara-Service <copybara-piper@google.com>2018-08-31 11:03:13 -0700
commit097dcbe73092fe4e57964fb7479381a1f1c177eb (patch)
tree529b4d504f73b26abb02e3eabe02d5895f860f62
parentd5266629301953f16763ed27bdbe589ba1352c99 (diff)
downloadTV-097dcbe73092fe4e57964fb7479381a1f1c177eb.tar.gz
Fix: Add a11y Delegate to scroll with Talkback enabled
When Talkback is enabled, RecyclerView does not scroll to hidden elements in UI for DPAD inputs. Added Accessibility Delegate to listen to focus change events, to force a forward scroll. Focus Search is also modified to handle scroll in backward direction. Live Channels: Import of 1122460 Change-Id: I0c725b8caeafc095d698a46e3588a21c74435fe9 PiperOrigin-RevId: 211111443
-rw-r--r--src/com/android/tv/guide/ProgramGuide.java5
-rw-r--r--src/com/android/tv/guide/ProgramRow.java22
-rw-r--r--src/com/android/tv/guide/ProgramRowAccessibilityDelegate.java64
3 files changed, 89 insertions, 2 deletions
diff --git a/src/com/android/tv/guide/ProgramGuide.java b/src/com/android/tv/guide/ProgramGuide.java
index 4b448fb2..9b90c1fa 100644
--- a/src/com/android/tv/guide/ProgramGuide.java
+++ b/src/com/android/tv/guide/ProgramGuide.java
@@ -643,6 +643,11 @@ public class ProgramGuide
return mGrid;
}
+ /** Returns if Accessibility is enabled. */
+ boolean isAccessibilityEnabled() {
+ return mAccessibilityManager.isEnabled();
+ }
+
/** Gets {@link VerticalGridView} for "genre select" side panel. */
VerticalGridView getSidePanel() {
return mSidePanelGridView;
diff --git a/src/com/android/tv/guide/ProgramRow.java b/src/com/android/tv/guide/ProgramRow.java
index 83175bb6..3317c15f 100644
--- a/src/com/android/tv/guide/ProgramRow.java
+++ b/src/com/android/tv/guide/ProgramRow.java
@@ -72,6 +72,9 @@ public class ProgramRow extends TimelineGridView {
public ProgramRow(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
+ ProgramRowAccessibilityDelegate rowAccessibilityDelegate =
+ new ProgramRowAccessibilityDelegate(this);
+ this.setAccessibilityDelegateCompat(rowAccessibilityDelegate);
}
/** Registers a listener focus events occurring on children to the {@code ProgramRow}. */
@@ -126,13 +129,26 @@ public class ProgramRow extends TimelineGridView {
: direction == View.FOCUS_LEFT;
}
+ // When Accessibility is enabled, this API will keep next node visible
+ void focusSearchAccessibility(View focused, int direction) {
+ TableEntry focusedEntry = ((ProgramItemView) focused).getTableEntry();
+ long toMillis = mProgramManager.getToUtcMillis();
+
+ if (isDirectionEnd(direction) || direction == View.FOCUS_FORWARD) {
+ if (focusedEntry.entryEndUtcMillis >= toMillis) {
+ scrollByTime(focusedEntry.entryEndUtcMillis - toMillis + HALF_HOUR_MILLIS);
+ }
+ }
+ }
+
@Override
public View focusSearch(View focused, int direction) {
TableEntry focusedEntry = ((ProgramItemView) focused).getTableEntry();
long fromMillis = mProgramManager.getFromUtcMillis();
long toMillis = mProgramManager.getToUtcMillis();
- if (isDirectionStart(direction) || direction == View.FOCUS_BACKWARD) {
+ if (!mProgramGuide.isAccessibilityEnabled()
+ && (isDirectionStart(direction) || direction == View.FOCUS_BACKWARD)) {
if (focusedEntry.entryStartUtcMillis < fromMillis) {
// The current entry starts outside of the view; Align or scroll to the left.
scrollByTime(
@@ -162,7 +178,9 @@ public class ProgramRow extends TimelineGridView {
TableEntry targetEntry = ((ProgramItemView) target).getTableEntry();
if (isDirectionStart(direction) || direction == View.FOCUS_BACKWARD) {
- if (targetEntry.entryStartUtcMillis < fromMillis
+ if (mProgramGuide.isAccessibilityEnabled()) {
+ scrollByTime(targetEntry.entryStartUtcMillis - fromMillis);
+ } else if (targetEntry.entryStartUtcMillis < fromMillis
&& targetEntry.entryEndUtcMillis < fromMillis + HALF_HOUR_MILLIS) {
// The target entry starts outside the view; Align or scroll to the left.
scrollByTime(
diff --git a/src/com/android/tv/guide/ProgramRowAccessibilityDelegate.java b/src/com/android/tv/guide/ProgramRowAccessibilityDelegate.java
new file mode 100644
index 00000000..5e498be4
--- /dev/null
+++ b/src/com/android/tv/guide/ProgramRowAccessibilityDelegate.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.tv.guide;
+
+import android.os.Bundle;
+import android.support.v7.widget.RecyclerView;
+import android.support.v7.widget.RecyclerViewAccessibilityDelegate;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityNodeInfo;
+
+/** AccessibilityDelegate for {@link ProgramRow} */
+class ProgramRowAccessibilityDelegate extends RecyclerViewAccessibilityDelegate {
+ private final ItemDelegate mItemDelegate;
+
+ ProgramRowAccessibilityDelegate(RecyclerView recyclerView) {
+ super(recyclerView);
+
+ mItemDelegate =
+ new ItemDelegate(this) {
+ @Override
+ public boolean performAccessibilityAction(View host, int action, Bundle args) {
+ // Prevent Accessibility service to move the Program Row elements
+ // Ignoring Accessibility action above Set Text
+ // (accessibilityActionShowOnScreen)
+ if (action > AccessibilityNodeInfo.ACTION_SET_TEXT) {
+ return false;
+ }
+
+ return super.performAccessibilityAction(host, action, args);
+ }
+ };
+ }
+
+ @Override
+ public ItemDelegate getItemDelegate() {
+ return mItemDelegate;
+ }
+
+ @Override
+ public boolean onRequestSendAccessibilityEvent(
+ ViewGroup host, View child, AccessibilityEvent event) {
+ // Forcing the next item to be visible for scrolling in forward direction
+ if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
+ ((ProgramRow) host).focusSearchAccessibility(child, View.FOCUS_FORWARD);
+ }
+ return super.onRequestSendAccessibilityEvent(host, child, event);
+ }
+}