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