1 /*
2  * Copyright (C) 2011 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 android.support.v4.view;
18 
19 import android.view.View;
20 import android.view.View.AccessibilityDelegate;
21 import android.view.ViewGroup;
22 import android.view.accessibility.AccessibilityEvent;
23 import android.view.accessibility.AccessibilityNodeInfo;
24 
25 /**
26  * ICS specific AccessibilityDelegate API implementation.
27  */
28 class AccessibilityDelegateCompatIcs {
29 
30     public interface AccessibilityDelegateBridge {
dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event)31         public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event);
onInitializeAccessibilityEvent(View host, AccessibilityEvent event)32         public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event);
onInitializeAccessibilityNodeInfo(View host, Object info)33         public void onInitializeAccessibilityNodeInfo(View host, Object info);
onPopulateAccessibilityEvent(View host, AccessibilityEvent event)34         public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event);
onRequestSendAccessibilityEvent(ViewGroup host, View child, AccessibilityEvent event)35         public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child,
36             AccessibilityEvent event);
sendAccessibilityEvent(View host, int eventType)37         public void sendAccessibilityEvent(View host, int eventType);
sendAccessibilityEventUnchecked(View host, AccessibilityEvent event)38         public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event);
39     }
40 
newAccessibilityDelegateDefaultImpl()41     public static Object newAccessibilityDelegateDefaultImpl() {
42         return new AccessibilityDelegate();
43     }
44 
newAccessibilityDelegateBridge(final AccessibilityDelegateBridge bridge)45     public static Object newAccessibilityDelegateBridge(final AccessibilityDelegateBridge bridge) {
46         return new AccessibilityDelegate() {
47             @Override
48             public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
49                 return bridge.dispatchPopulateAccessibilityEvent(host, event);
50             }
51 
52             @Override
53             public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
54                 bridge.onInitializeAccessibilityEvent(host, event);
55             }
56 
57             @Override
58             public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
59                 bridge.onInitializeAccessibilityNodeInfo(host, info);
60             }
61 
62             @Override
63             public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
64                 bridge.onPopulateAccessibilityEvent(host, event);
65             }
66 
67             @Override
68             public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child,
69                     AccessibilityEvent event) {
70                 return bridge.onRequestSendAccessibilityEvent(host, child, event);
71             }
72 
73             @Override
74             public void sendAccessibilityEvent(View host, int eventType) {
75                 bridge.sendAccessibilityEvent(host, eventType);
76             }
77 
78             @Override
79             public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) {
80                 bridge.sendAccessibilityEventUnchecked(host, event);
81             }
82         };
83     }
84 
85     public static boolean dispatchPopulateAccessibilityEvent(Object delegate, View host,
86             AccessibilityEvent event) {
87         return ((AccessibilityDelegate) delegate).dispatchPopulateAccessibilityEvent(host, event);
88     }
89 
90     public static void onInitializeAccessibilityEvent(Object delegate, View host,
91             AccessibilityEvent event) {
92         ((AccessibilityDelegate) delegate).onInitializeAccessibilityEvent(host, event);
93     }
94 
95     public static void onInitializeAccessibilityNodeInfo(Object delegate, View host, Object info) {
96         ((AccessibilityDelegate) delegate).onInitializeAccessibilityNodeInfo(host,
97                 (AccessibilityNodeInfo) info);
98     }
99 
100     public static void onPopulateAccessibilityEvent(Object delegate, View host,
101             AccessibilityEvent event) {
102         ((AccessibilityDelegate) delegate).onPopulateAccessibilityEvent(host, event);
103     }
104 
105     public static boolean onRequestSendAccessibilityEvent(Object delegate, ViewGroup host,
106             View child, AccessibilityEvent event) {
107         return ((AccessibilityDelegate) delegate).onRequestSendAccessibilityEvent(host, child,
108                 event);
109     }
110 
111     public static void sendAccessibilityEvent(Object delegate, View host, int eventType) {
112         ((AccessibilityDelegate) delegate).sendAccessibilityEvent(host, eventType);
113     }
114 
115     public static void sendAccessibilityEventUnchecked(Object delegate, View host,
116             AccessibilityEvent event) {
117         ((AccessibilityDelegate) delegate).sendAccessibilityEventUnchecked(host, event);
118     }
119 }
120