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