ViewGroupCompat.java revision 9648c538bac4f04145c118cc41168d1d7a536312
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
17package android.support.v4.view;
18
19import android.os.Build;
20import android.view.View;
21import android.view.ViewGroup;
22import android.view.accessibility.AccessibilityEvent;
23
24/**
25 * Helper for accessing newer features in ViewGroup.
26 */
27public class ViewGroupCompat {
28
29    interface ViewGroupCompatImpl {
30        public boolean onRequestSendAccessibilityEvent(ViewGroup group, View child,
31                AccessibilityEvent event);
32    }
33
34    static class ViewGroupCompatStubImpl implements ViewGroupCompatImpl {
35        public boolean onRequestSendAccessibilityEvent(
36                ViewGroup group, View child, AccessibilityEvent event) {
37            return true;
38        }
39    }
40
41    static class ViewGroupCompatIcsImpl extends ViewGroupCompatStubImpl {
42        @Override
43        public boolean onRequestSendAccessibilityEvent(
44                ViewGroup group, View child, AccessibilityEvent event) {
45            return ViewGroupCompatIcs.onRequestSendAccessibilityEvent(group, child, event);
46        }
47    }
48
49    static final ViewGroupCompatImpl IMPL;
50    static {
51        if (Build.VERSION.SDK_INT >= 14) {
52            IMPL = new ViewGroupCompatIcsImpl();
53        } else {
54            IMPL = new ViewGroupCompatStubImpl();
55        }
56    }
57
58    /*
59     * Hide the constructor.
60     */
61    private ViewGroupCompat() {
62
63    }
64
65    /**
66     * Called when a child has requested sending an {@link AccessibilityEvent} and
67     * gives an opportunity to its parent to augment the event.
68     * <p>
69     * If an {@link AccessibilityDelegateCompat} has been specified via calling
70     * {@link ViewCompat#setAccessibilityDelegate(View, AccessibilityDelegateCompat)} its
71     * {@link AccessibilityDelegateCompat#onRequestSendAccessibilityEvent(ViewGroup, View,
72     * AccessibilityEvent)} is responsible for handling this call.
73     * </p>
74     *
75     * @param group The group whose method to invoke.
76     * @param child The child which requests sending the event.
77     * @param event The event to be sent.
78     * @return True if the event should be sent.
79     */
80    public static boolean onRequestSendAccessibilityEvent(ViewGroup group, View child,
81            AccessibilityEvent event) {
82        return IMPL.onRequestSendAccessibilityEvent(group, child, event);
83    }
84}
85