ViewCompat.java revision 956b013dfda37760b0232ed6d448900a546d2903
1bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell/* 2bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * Copyright (C) 2011 The Android Open Source Project 3bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * 4bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * Licensed under the Apache License, Version 2.0 (the "License"); 5bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * you may not use this file except in compliance with the License. 6bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * You may obtain a copy of the License at 7bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * 8bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * http://www.apache.org/licenses/LICENSE-2.0 9bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * 10bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * Unless required by applicable law or agreed to in writing, software 11bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * distributed under the License is distributed on an "AS IS" BASIS, 12bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * See the License for the specific language governing permissions and 14bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell * limitations under the License. 15bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell */ 16bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell 17bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powellpackage android.support.v4.view; 18bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell 190574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganovimport android.graphics.Rect; 209648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganovimport android.support.v4.view.accessibility.AccessibilityNodeInfoCompat; 21bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powellimport android.view.View; 229648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganovimport android.view.accessibility.AccessibilityEvent; 23bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell 24bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell/** 250574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Helper for accessing features in {@link View} introduced after API 260574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * level 4 in a backwards compatible fashion. 27bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell */ 28bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powellpublic class ViewCompat { 29560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell /** 30560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell * Always allow a user to over-scroll this view, provided it is a 31560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell * view that can scroll. 32560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell */ 33560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public static final int OVER_SCROLL_ALWAYS = 0; 34560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell 35560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell /** 36560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell * Allow a user to over-scroll this view only if the content is large 37560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell * enough to meaningfully scroll, provided it is a view that can scroll. 38560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell */ 39560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1; 40560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell 41560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell /** 42560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell * Never allow a user to over-scroll this view. 43560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell */ 44560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public static final int OVER_SCROLL_NEVER = 2; 45560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell 46bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell interface ViewCompatImpl { 47bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell public boolean canScrollHorizontally(View v, int direction); 48bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell public boolean canScrollVertically(View v, int direction); 49560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public int getOverScrollMode(View v); 50560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public void setOverScrollMode(View v, int mode); 519648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onInitializeAccessibilityEvent(View v, AccessibilityEvent event); 529648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event); 539648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info); 549648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate); 55bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 56bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell 57bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell static class BaseViewCompatImpl implements ViewCompatImpl { 58bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell public boolean canScrollHorizontally(View v, int direction) { 59bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell return false; 60bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 61bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell public boolean canScrollVertically(View v, int direction) { 62bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell return false; 63bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 64560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public int getOverScrollMode(View v) { 65560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell return OVER_SCROLL_NEVER; 66560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell } 67560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public void setOverScrollMode(View v, int mode) { 68560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell // Do nothing; API doesn't exist 69560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell } 709648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) { 719648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov // Do nothing; API doesn't exist 729648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 739648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) { 749648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov // Do nothing; API doesn't exist 759648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 769648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) { 779648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov // Do nothing; API doesn't exist 789648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 799648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) { 809648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov // Do nothing; API doesn't exist 819648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 82bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 83bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell 84560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell static class GBViewCompatImpl extends BaseViewCompatImpl { 859648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov @Override 86560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public int getOverScrollMode(View v) { 87560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell return ViewCompatGingerbread.getOverScrollMode(v); 88560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell } 899648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov @Override 90560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public void setOverScrollMode(View v, int mode) { 91560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell ViewCompatGingerbread.setOverScrollMode(v, mode); 92560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell } 93560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell } 94560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell 95560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell static class ICSViewCompatImpl extends GBViewCompatImpl { 969648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov @Override 97bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell public boolean canScrollHorizontally(View v, int direction) { 98bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell return ViewCompatICS.canScrollHorizontally(v, direction); 99bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 1009648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov @Override 101bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell public boolean canScrollVertically(View v, int direction) { 102bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell return ViewCompatICS.canScrollVertically(v, direction); 103bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 1049648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov @Override 1059648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) { 1069648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov ViewCompatICS.onPopulateAccessibilityEvent(v, event); 1079648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 1089648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov @Override 1099648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) { 1109648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov ViewCompatICS.onInitializeAccessibilityEvent(v, event); 1119648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 1129648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov @Override 1139648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) { 114956b013dfda37760b0232ed6d448900a546d2903Svetoslav Ganov ViewCompatICS.onInitializeAccessibilityNodeInfo(v, info.getInfo()); 1159648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 1169648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov @Override 1179648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) { 1189648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov ViewCompatICS.setAccessibilityDelegate(v, delegate.getBridge()); 1199648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 120bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 121bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell 122bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell static final ViewCompatImpl IMPL; 123bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell static { 124560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell final int version = android.os.Build.VERSION.SDK_INT; 125560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell if (version >= 14) { 126bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell IMPL = new ICSViewCompatImpl(); 127560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell } else if (version >= 9) { 128560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell IMPL = new GBViewCompatImpl(); 129bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } else { 130bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell IMPL = new BaseViewCompatImpl(); 131bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 132bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 133bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell 1340574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov /** 1350574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Check if this view can be scrolled horizontally in a certain direction. 1360574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 1370574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param v The View against which to invoke the method. 1380574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param direction Negative to check scrolling left, positive to check scrolling right. 1390574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @return true if this view can be scrolled in the specified direction, false otherwise. 1400574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov */ 141bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell public static boolean canScrollHorizontally(View v, int direction) { 142bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell return IMPL.canScrollHorizontally(v, direction); 143bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 144bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell 1450574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov /** 1460574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Check if this view can be scrolled vertically in a certain direction. 1470574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 1480574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param v The View against which to invoke the method. 1490574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param direction Negative to check scrolling up, positive to check scrolling down. 1500574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @return true if this view can be scrolled in the specified direction, false otherwise. 1510574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov */ 152bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell public static boolean canScrollVertically(View v, int direction) { 153bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell return IMPL.canScrollVertically(v, direction); 154bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 155560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell 1560574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov /** 1570574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Returns the over-scroll mode for this view. The result will be 1580574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} 1590574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * (allow over-scrolling only if the view content is larger than the container), 1600574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * or {@link #OVER_SCROLL_NEVER}. 1610574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 1620574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param v The View against which to invoke the method. 1630574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @return This view's over-scroll mode. 1640574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov */ 165560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public static int getOverScrollMode(View v) { 166560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell return IMPL.getOverScrollMode(v); 167560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell } 168560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell 1690574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov /** 1700574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Set the over-scroll mode for this view. Valid over-scroll modes are 1710574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} 1720574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * (allow over-scrolling only if the view content is larger than the container), 1730574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * or {@link #OVER_SCROLL_NEVER}. 1740574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 1750574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Setting the over-scroll mode of a view will have an effect only if the 1760574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * view is capable of scrolling. 1770574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 1780574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param v The View against which to invoke the method. 1790574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param overScrollMode The new over-scroll mode for this view. 1800574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov */ 1810574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov public static void setOverScrollMode(View v, int overScrollMode) { 1820574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov IMPL.setOverScrollMode(v, overScrollMode); 183560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell } 1849648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov 1850574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov /** 1860574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Called from {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)} 1870574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * giving a chance to this View to populate the accessibility event with its 1880574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * text content. While this method is free to modify event 1890574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * attributes other than text content, doing so should normally be performed in 1900574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent)}. 1910574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <p> 1920574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Example: Adding formatted date string to an accessibility event in addition 1930574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * to the text added by the super implementation: 1940574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) { 1950574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * super.onPopulateAccessibilityEvent(event); 1960574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; 1970574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * String selectedDateUtterance = DateUtils.formatDateTime(mContext, 1980574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * mCurrentDate.getTimeInMillis(), flags); 1990574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * event.getText().add(selectedDateUtterance); 2000574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * }</pre> 2010574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <p> 2020574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * If an {@link android.view.View.AccessibilityDelegate} has been specified via calling 2030574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)} its 2040574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link android.view.View.AccessibilityDelegate#onPopulateAccessibilityEvent(View, 2050574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * AccessibilityEvent)} 2060574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * is responsible for handling this call. 2070574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * </p> 2080574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <p class="note"><strong>Note:</strong> Always call the super implementation before adding 2090574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * information to the event, in case the default implementation has basic information to add. 2100574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * </p> 2110574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 2120574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param v The View against which to invoke the method. 2130574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param event The accessibility event which to populate. 2140574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 2150574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @see View#sendAccessibilityEvent(int) 2160574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) 2170574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov */ 2189648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public static void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) { 2199648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov IMPL.onPopulateAccessibilityEvent(v, event); 2209648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 2219648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov 2220574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov /** 2230574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Initializes an {@link AccessibilityEvent} with information about 2240574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * this View which is the event source. In other words, the source of 2250574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * an accessibility event is the view whose state change triggered firing 2260574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * the event. 2270574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <p> 2280574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Example: Setting the password property of an event in addition 2290574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * to properties set by the super implementation: 2300574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) { 2310574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * super.onInitializeAccessibilityEvent(event); 2320574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * event.setPassword(true); 2330574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * }</pre> 2340574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <p> 2350574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * If an {@link android.view.View.AccessibilityDelegate} has been specified via calling 2360574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)} its 2370574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link android.view.View.AccessibilityDelegate#onInitializeAccessibilityEvent(View, 2380574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * AccessibilityEvent)} 2390574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * is responsible for handling this call. 2400574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * </p> 2410574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <p class="note"><strong>Note:</strong> Always call the super implementation before adding 2420574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * information to the event, in case the default implementation has basic information to add. 2430574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * </p> 2440574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 2450574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param v The View against which to invoke the method. 2460574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param event The event to initialize. 2470574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 2480574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @see View#sendAccessibilityEvent(int) 2490574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) 2500574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov */ 2519648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public static void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) { 2529648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov IMPL.onInitializeAccessibilityEvent(v, event); 2539648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 2549648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov 2550574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov /** 2560574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Initializes an {@link android.view.accessibility.AccessibilityNodeInfo} with information 2570574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * about this view. The base implementation sets: 2580574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <ul> 2590574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setParent(View)},</li> 2600574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setBoundsInParent(Rect)},</li> 2610574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li> 2620574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setPackageName(CharSequence)},</li> 2630574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setClassName(CharSequence)},</li> 2640574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setContentDescription(CharSequence)},</li> 2650574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setEnabled(boolean)},</li> 2660574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setClickable(boolean)},</li> 2670574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setFocusable(boolean)},</li> 2680574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setFocused(boolean)},</li> 2690574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setLongClickable(boolean)},</li> 2700574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setSelected(boolean)},</li> 2710574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * </ul> 2720574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <p> 2730574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Subclasses should override this method, call the super implementation, 2740574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * and set additional attributes. 2750574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * </p> 2760574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <p> 2770574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * If an {@link android.view.View.AccessibilityDelegate} has been specified via calling 2780574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)} its 2790574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link android.view.View.AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View, 2800574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * android.view.accessibility.AccessibilityNodeInfo)} 2810574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * is responsible for handling this call. 2820574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * </p> 2830574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 2840574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param v The View against which to invoke the method. 2850574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param info The instance to initialize. 2860574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov */ 2879648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public static void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) { 2889648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov IMPL.onInitializeAccessibilityNodeInfo(v, info); 2899648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 2909648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov 2910574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov /** 2920574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Sets a delegate for implementing accessibility support via compositon as 2930574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * opposed to inheritance. The delegate's primary use is for implementing 2940574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * backwards compatible widgets. For more details see 2950574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link android.view.View.AccessibilityDelegate}. 2960574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 2970574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param v The View against which to invoke the method. 2980574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param delegate The delegate instance. 2990574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 3000574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @see android.view.View.AccessibilityDelegate 3010574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov */ 3029648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public static void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) { 3039648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov IMPL.setAccessibilityDelegate(v, delegate); 3049648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 305bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell} 306