1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.tv.guide;
18 
19 import android.os.Bundle;
20 import androidx.recyclerview.widget.RecyclerView;
21 import androidx.recyclerview.widget.RecyclerViewAccessibilityDelegate;
22 import android.view.View;
23 import android.view.ViewGroup;
24 import android.view.accessibility.AccessibilityEvent;
25 import android.view.accessibility.AccessibilityNodeInfo;
26 
27 /** AccessibilityDelegate for {@link ProgramRow} */
28 class ProgramRowAccessibilityDelegate extends RecyclerViewAccessibilityDelegate {
29     private final ItemDelegate mItemDelegate;
30 
ProgramRowAccessibilityDelegate(RecyclerView recyclerView)31     ProgramRowAccessibilityDelegate(RecyclerView recyclerView) {
32         super(recyclerView);
33 
34         mItemDelegate =
35                 new ItemDelegate(this) {
36                     @Override
37                     public boolean performAccessibilityAction(View host, int action, Bundle args) {
38                         // Prevent Accessibility service to move the Program Row elements
39                         // Ignoring Accessibility action above Set Text
40                         // (accessibilityActionShowOnScreen)
41                         if (action > AccessibilityNodeInfo.ACTION_SET_TEXT) {
42                             return false;
43                         }
44 
45                         return super.performAccessibilityAction(host, action, args);
46                     }
47                 };
48     }
49 
50     @Override
getItemDelegate()51     public ItemDelegate getItemDelegate() {
52         return mItemDelegate;
53     }
54 
55     @Override
onRequestSendAccessibilityEvent( ViewGroup host, View child, AccessibilityEvent event)56     public boolean onRequestSendAccessibilityEvent(
57             ViewGroup host, View child, AccessibilityEvent event) {
58         // Forcing the next item to be visible for scrolling in forward direction
59         if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
60             ((ProgramRow) host).focusSearchAccessibility(child, View.FOCUS_FORWARD);
61         }
62         return super.onRequestSendAccessibilityEvent(host, child, event);
63     }
64 }
65