1/*
2 * Copyright (C) 2013 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 * KitKat-specific AccessibilityNodeProvider API implementation.
27 */
28class AccessibilityNodeProviderCompatKitKat {
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        public Object findFocus(int focus);
35    }
36
37    public static Object newAccessibilityNodeProviderBridge(
38            final AccessibilityNodeInfoBridge bridge) {
39        return new AccessibilityNodeProvider() {
40            @Override
41            public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
42                return (AccessibilityNodeInfo) bridge.createAccessibilityNodeInfo(virtualViewId);
43            }
44
45            @Override
46            @SuppressWarnings("unchecked")
47            public List<AccessibilityNodeInfo> findAccessibilityNodeInfosByText(
48                    String text, int virtualViewId) {
49                // Use some voodoo to avoid creating intermediary instances.
50                return (List<AccessibilityNodeInfo>) (List<?>)
51                    bridge.findAccessibilityNodeInfosByText(text, virtualViewId);
52            }
53
54            @Override
55            public boolean performAction(int virtualViewId, int action, Bundle arguments) {
56                return bridge.performAction(virtualViewId, action, arguments);
57            }
58
59            @Override
60            public AccessibilityNodeInfo findFocus(int focus) {
61                return (AccessibilityNodeInfo) bridge.findFocus(focus);
62            }
63        };
64    }
65}
66