1/*
2 * Copyright (C) 2012 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
17package android.support.v4.view.accessibility;
18
19import android.os.Bundle;
20import android.view.accessibility.AccessibilityNodeInfo;
21import android.view.accessibility.AccessibilityNodeProvider;
22
23import java.util.List;
24
25/**
26 * JellyBean specific AccessibilityNodeProvider API implementation.
27 */
28class AccessibilityNodeProviderCompatJellyBean {
29    interface AccessibilityNodeInfoBridge {
30        public Object createAccessibilityNodeInfo(int virtualViewId);
31        public boolean performAction(int virtualViewId, int action, Bundle arguments);
32        public List<Object> findAccessibilityNodeInfosByText(String text,
33            int virtualViewId);
34    }
35
36    public static Object newAccessibilityNodeProviderBridge(
37            final AccessibilityNodeInfoBridge bridge) {
38        return new AccessibilityNodeProvider() {
39            @Override
40            public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
41                return (AccessibilityNodeInfo) bridge.createAccessibilityNodeInfo(virtualViewId);
42            }
43
44            @Override
45            @SuppressWarnings("unchecked")
46            public List<AccessibilityNodeInfo> findAccessibilityNodeInfosByText(
47                    String text, int virtualViewId) {
48                // Use some voodoo to avoid creating intermediary instances.
49                return (List<AccessibilityNodeInfo>) (List<?>)
50                    bridge.findAccessibilityNodeInfosByText(text, virtualViewId);
51            }
52
53            @Override
54            public boolean performAction(int virtualViewId, int action, Bundle arguments) {
55                return bridge.performAction(virtualViewId, action, arguments);
56            }
57        };
58    }
59}
60