ViewCompat.java revision 0d4ffdf13a16b1ce2f3bc458002374cdd25663c3
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; 200d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanvimport android.os.Bundle; 219648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganovimport android.support.v4.view.accessibility.AccessibilityNodeInfoCompat; 2225121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganovimport android.support.v4.view.accessibility.AccessibilityNodeProviderCompat; 23bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powellimport android.view.View; 249648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganovimport android.view.accessibility.AccessibilityEvent; 25bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell 26bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell/** 270574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Helper for accessing features in {@link View} introduced after API 280574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * level 4 in a backwards compatible fashion. 29bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell */ 30bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powellpublic class ViewCompat { 31560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell /** 32560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell * Always allow a user to over-scroll this view, provided it is a 33560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell * view that can scroll. 34560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell */ 35560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public static final int OVER_SCROLL_ALWAYS = 0; 36560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell 37560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell /** 38560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell * Allow a user to over-scroll this view only if the content is large 39560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell * enough to meaningfully scroll, provided it is a view that can scroll. 40560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell */ 41560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1; 42560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell 43560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell /** 44560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell * Never allow a user to over-scroll this view. 45560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell */ 46560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public static final int OVER_SCROLL_NEVER = 2; 47560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell 48ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell private static final long FAKE_FRAME_TIME = 10; 49ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell 5025121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov /** 5125121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * Automatically determine whether a view is important for accessibility. 5225121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov */ 5325121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov public static final int IMPORTANT_FOR_ACCESSIBILITY_AUTO = 0x00000000; 5425121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov 5525121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov /** 5625121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * The view is important for accessibility. 5725121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov */ 5825121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov public static final int IMPORTANT_FOR_ACCESSIBILITY_YES = 0x00000001; 5925121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov 6025121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov /** 6125121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * The view is not important for accessibility. 6225121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov */ 6325121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov public static final int IMPORTANT_FOR_ACCESSIBILITY_NO = 0x00000002; 6425121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov 65bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell interface ViewCompatImpl { 66bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell public boolean canScrollHorizontally(View v, int direction); 67bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell public boolean canScrollVertically(View v, int direction); 68560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public int getOverScrollMode(View v); 69560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public void setOverScrollMode(View v, int mode); 709648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onInitializeAccessibilityEvent(View v, AccessibilityEvent event); 719648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event); 729648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info); 739648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate); 74c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell public boolean hasTransientState(View view); 75c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell public void setHasTransientState(View view, boolean hasTransientState); 76ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell public void postInvalidateOnAnimation(View view); 77ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell public void postInvalidateOnAnimation(View view, int left, int top, int right, int bottom); 78ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell public void postOnAnimation(View view, Runnable action); 79ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell public void postOnAnimationDelayed(View view, Runnable action, long delayMillis); 8025121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov public int getImportantForAccessibility(View view); 8125121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov public void setImportantForAccessibility(View view, int mode); 820d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv public boolean performAccessibilityAction(View view, int action, Bundle arguments); 8325121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov public AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view); 84bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 85bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell 86bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell static class BaseViewCompatImpl implements ViewCompatImpl { 87bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell public boolean canScrollHorizontally(View v, int direction) { 88bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell return false; 89bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 90bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell public boolean canScrollVertically(View v, int direction) { 91bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell return false; 92bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 93560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public int getOverScrollMode(View v) { 94560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell return OVER_SCROLL_NEVER; 95560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell } 96560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public void setOverScrollMode(View v, int mode) { 97560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell // Do nothing; API doesn't exist 98560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell } 999648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) { 1009648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov // Do nothing; API doesn't exist 1019648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 1029648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) { 1039648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov // Do nothing; API doesn't exist 1049648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 1059648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) { 1069648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov // Do nothing; API doesn't exist 1079648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 1089648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) { 1099648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov // Do nothing; API doesn't exist 1109648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 111c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell public boolean hasTransientState(View view) { 112c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell // A view can't have transient state if transient state wasn't supported. 113c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell return false; 114c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell } 115c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell public void setHasTransientState(View view, boolean hasTransientState) { 116c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell // Do nothing; API doesn't exist 117c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell } 118ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell public void postInvalidateOnAnimation(View view) { 119ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell view.postInvalidateDelayed(getFrameTime()); 120ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell } 121ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell public void postInvalidateOnAnimation(View view, int left, int top, int right, int bottom) { 122ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell view.postInvalidateDelayed(getFrameTime(), left, top, right, bottom); 123ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell } 124ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell public void postOnAnimation(View view, Runnable action) { 125ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell view.postDelayed(action, getFrameTime()); 126ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell } 127ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell public void postOnAnimationDelayed(View view, Runnable action, long delayMillis) { 128ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell view.postDelayed(action, getFrameTime() + delayMillis); 129ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell } 130ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell long getFrameTime() { 131ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell return FAKE_FRAME_TIME; 132ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell } 13325121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov public int getImportantForAccessibility(View view) { 13425121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov return 0; 13525121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov } 13625121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov public void setImportantForAccessibility(View view, int mode) { 13725121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov 13825121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov } 1390d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv public boolean performAccessibilityAction(View view, int action, Bundle arguments) { 1400d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv return false; 1410d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv } 14225121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov public AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view) { 14325121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov return null; 14425121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov } 145bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 146bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell 147560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell static class GBViewCompatImpl extends BaseViewCompatImpl { 1489648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov @Override 149560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public int getOverScrollMode(View v) { 150560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell return ViewCompatGingerbread.getOverScrollMode(v); 151560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell } 1529648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov @Override 153560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public void setOverScrollMode(View v, int mode) { 154560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell ViewCompatGingerbread.setOverScrollMode(v, mode); 155560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell } 156560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell } 157560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell 158ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell static class HCViewCompatImpl extends GBViewCompatImpl { 159ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell long getFrameTime() { 160ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell return ViewCompatHC.getFrameTime(); 161ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell } 162ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell } 163ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell 164ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell static class ICSViewCompatImpl extends HCViewCompatImpl { 1659648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov @Override 166bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell public boolean canScrollHorizontally(View v, int direction) { 167bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell return ViewCompatICS.canScrollHorizontally(v, direction); 168bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 1699648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov @Override 170bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell public boolean canScrollVertically(View v, int direction) { 171bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell return ViewCompatICS.canScrollVertically(v, direction); 172bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 1739648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov @Override 1749648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) { 1759648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov ViewCompatICS.onPopulateAccessibilityEvent(v, event); 1769648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 1779648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov @Override 1789648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) { 1799648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov ViewCompatICS.onInitializeAccessibilityEvent(v, event); 1809648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 1819648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov @Override 1829648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) { 183956b013dfda37760b0232ed6d448900a546d2903Svetoslav Ganov ViewCompatICS.onInitializeAccessibilityNodeInfo(v, info.getInfo()); 1849648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 1859648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov @Override 1869648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) { 1879648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov ViewCompatICS.setAccessibilityDelegate(v, delegate.getBridge()); 1889648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 189bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 190bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell 191c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell static class JBViewCompatImpl extends ICSViewCompatImpl { 192c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell @Override 193c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell public boolean hasTransientState(View view) { 194c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell return ViewCompatJB.hasTransientState(view); 195c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell } 196c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell @Override 197c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell public void setHasTransientState(View view, boolean hasTransientState) { 198c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell ViewCompatJB.setHasTransientState(view, hasTransientState); 199c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell } 200ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell @Override 201ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell public void postInvalidateOnAnimation(View view) { 202ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell ViewCompatJB.postInvalidateOnAnimation(view); 203ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell } 204ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell @Override 205ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell public void postInvalidateOnAnimation(View view, int left, int top, int right, int bottom) { 206ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell ViewCompatJB.postInvalidateOnAnimation(view, left, top, right, bottom); 207ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell } 208ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell @Override 209ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell public void postOnAnimation(View view, Runnable action) { 210ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell ViewCompatJB.postOnAnimation(view, action); 211ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell } 212ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell @Override 213ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell public void postOnAnimationDelayed(View view, Runnable action, long delayMillis) { 214ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell ViewCompatJB.postOnAnimationDelayed(view, action, delayMillis); 215ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell } 21625121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov @Override 21725121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov public int getImportantForAccessibility(View view) { 21825121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov return ViewCompatJB.getImportantForAccessibility(view); 21925121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov } 22025121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov @Override 22125121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov public void setImportantForAccessibility(View view, int mode) { 22225121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov ViewCompatJB.setImportantForAccessibility(view, mode); 22325121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov } 22425121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov @Override 2250d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv public boolean performAccessibilityAction(View view, int action, Bundle arguments) { 2260d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv return ViewCompatJB.performAccessibilityAction(view, action, arguments); 2270d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv } 2280d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv @Override 22925121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov public AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view) { 23025121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov Object compat = ViewCompatJB.getAccessibilityNodeProvider(view); 23125121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov if (compat != null) { 23225121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov return new AccessibilityNodeProviderCompat(compat); 23325121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov } 23425121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov return null; 23525121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov } 236c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell } 237c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell 238bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell static final ViewCompatImpl IMPL; 239bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell static { 240560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell final int version = android.os.Build.VERSION.SDK_INT; 241c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell if (version >= 16 || android.os.Build.VERSION.CODENAME.equals("JellyBean")) { 242c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell IMPL = new JBViewCompatImpl(); 243c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell } else if (version >= 14) { 244bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell IMPL = new ICSViewCompatImpl(); 245ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell } else if (version >= 11) { 246ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell IMPL = new HCViewCompatImpl(); 247560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell } else if (version >= 9) { 248560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell IMPL = new GBViewCompatImpl(); 249bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } else { 250bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell IMPL = new BaseViewCompatImpl(); 251bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 252bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 253bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell 2540574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov /** 2550574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Check if this view can be scrolled horizontally in a certain direction. 2560574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 2570574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param v The View against which to invoke the method. 2580574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param direction Negative to check scrolling left, positive to check scrolling right. 2590574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @return true if this view can be scrolled in the specified direction, false otherwise. 2600574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov */ 261bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell public static boolean canScrollHorizontally(View v, int direction) { 262bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell return IMPL.canScrollHorizontally(v, direction); 263bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 264bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell 2650574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov /** 2660574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Check if this view can be scrolled vertically in a certain direction. 2670574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 2680574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param v The View against which to invoke the method. 2690574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param direction Negative to check scrolling up, positive to check scrolling down. 2700574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @return true if this view can be scrolled in the specified direction, false otherwise. 2710574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov */ 272bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell public static boolean canScrollVertically(View v, int direction) { 273bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell return IMPL.canScrollVertically(v, direction); 274bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell } 275560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell 2760574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov /** 2770574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Returns the over-scroll mode for this view. The result will be 2780574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} 2790574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * (allow over-scrolling only if the view content is larger than the container), 2800574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * or {@link #OVER_SCROLL_NEVER}. 2810574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 2820574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param v The View against which to invoke the method. 2830574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @return This view's over-scroll mode. 2840574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov */ 285560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell public static int getOverScrollMode(View v) { 286560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell return IMPL.getOverScrollMode(v); 287560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell } 288560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell 2890574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov /** 2900574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Set the over-scroll mode for this view. Valid over-scroll modes are 2910574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} 2920574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * (allow over-scrolling only if the view content is larger than the container), 2930574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * or {@link #OVER_SCROLL_NEVER}. 2940574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 2950574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Setting the over-scroll mode of a view will have an effect only if the 2960574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * view is capable of scrolling. 2970574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 2980574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param v The View against which to invoke the method. 2990574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param overScrollMode The new over-scroll mode for this view. 3000574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov */ 3010574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov public static void setOverScrollMode(View v, int overScrollMode) { 3020574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov IMPL.setOverScrollMode(v, overScrollMode); 303560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell } 3049648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov 3050574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov /** 3060574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Called from {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)} 3070574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * giving a chance to this View to populate the accessibility event with its 3080574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * text content. While this method is free to modify event 3090574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * attributes other than text content, doing so should normally be performed in 3100574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent)}. 3110574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <p> 3120574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Example: Adding formatted date string to an accessibility event in addition 3130574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * to the text added by the super implementation: 3140574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) { 3150574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * super.onPopulateAccessibilityEvent(event); 3160574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; 3170574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * String selectedDateUtterance = DateUtils.formatDateTime(mContext, 3180574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * mCurrentDate.getTimeInMillis(), flags); 3190574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * event.getText().add(selectedDateUtterance); 3200574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * }</pre> 3210574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <p> 3220574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * If an {@link android.view.View.AccessibilityDelegate} has been specified via calling 3230574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)} its 3240574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link android.view.View.AccessibilityDelegate#onPopulateAccessibilityEvent(View, 3250574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * AccessibilityEvent)} 3260574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * is responsible for handling this call. 3270574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * </p> 3280574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <p class="note"><strong>Note:</strong> Always call the super implementation before adding 3290574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * information to the event, in case the default implementation has basic information to add. 3300574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * </p> 3310574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 3320574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param v The View against which to invoke the method. 3330574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param event The accessibility event which to populate. 3340574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 3350574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @see View#sendAccessibilityEvent(int) 3360574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) 3370574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov */ 3389648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public static void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) { 3399648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov IMPL.onPopulateAccessibilityEvent(v, event); 3409648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 3419648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov 3420574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov /** 3430574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Initializes an {@link AccessibilityEvent} with information about 3440574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * this View which is the event source. In other words, the source of 3450574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * an accessibility event is the view whose state change triggered firing 3460574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * the event. 3470574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <p> 3480574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Example: Setting the password property of an event in addition 3490574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * to properties set by the super implementation: 3500574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) { 3510574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * super.onInitializeAccessibilityEvent(event); 3520574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * event.setPassword(true); 3530574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * }</pre> 3540574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <p> 3550574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * If an {@link android.view.View.AccessibilityDelegate} has been specified via calling 3560574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)} its 3570574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link android.view.View.AccessibilityDelegate#onInitializeAccessibilityEvent(View, 3580574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * AccessibilityEvent)} 3590574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * is responsible for handling this call. 3600574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * </p> 3610574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <p class="note"><strong>Note:</strong> Always call the super implementation before adding 3620574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * information to the event, in case the default implementation has basic information to add. 3630574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * </p> 3640574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 3650574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param v The View against which to invoke the method. 3660574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param event The event to initialize. 3670574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 3680574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @see View#sendAccessibilityEvent(int) 3690574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) 3700574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov */ 3719648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public static void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) { 3729648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov IMPL.onInitializeAccessibilityEvent(v, event); 3739648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 3749648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov 3750574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov /** 3760574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Initializes an {@link android.view.accessibility.AccessibilityNodeInfo} with information 3770574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * about this view. The base implementation sets: 3780574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <ul> 3790574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setParent(View)},</li> 3800574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setBoundsInParent(Rect)},</li> 3810574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li> 3820574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setPackageName(CharSequence)},</li> 3830574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setClassName(CharSequence)},</li> 3840574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setContentDescription(CharSequence)},</li> 3850574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setEnabled(boolean)},</li> 3860574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setClickable(boolean)},</li> 3870574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setFocusable(boolean)},</li> 3880574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setFocused(boolean)},</li> 3890574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setLongClickable(boolean)},</li> 3900574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setSelected(boolean)},</li> 3910574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * </ul> 3920574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <p> 3930574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Subclasses should override this method, call the super implementation, 3940574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * and set additional attributes. 3950574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * </p> 3960574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * <p> 3970574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * If an {@link android.view.View.AccessibilityDelegate} has been specified via calling 3980574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)} its 3990574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link android.view.View.AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View, 4000574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * android.view.accessibility.AccessibilityNodeInfo)} 4010574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * is responsible for handling this call. 4020574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * </p> 4030574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 4040574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param v The View against which to invoke the method. 4050574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param info The instance to initialize. 4060574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov */ 4079648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public static void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) { 4089648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov IMPL.onInitializeAccessibilityNodeInfo(v, info); 4099648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 4109648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov 4110574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov /** 4120574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * Sets a delegate for implementing accessibility support via compositon as 4130574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * opposed to inheritance. The delegate's primary use is for implementing 4140574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * backwards compatible widgets. For more details see 4150574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * {@link android.view.View.AccessibilityDelegate}. 4160574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 4170574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param v The View against which to invoke the method. 4180574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @param delegate The delegate instance. 4190574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * 4200574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov * @see android.view.View.AccessibilityDelegate 4210574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov */ 4229648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov public static void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) { 4239648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov IMPL.setAccessibilityDelegate(v, delegate); 4249648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov } 425c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell 426c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell /** 427c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell * Indicates whether the view is currently tracking transient state that the 428c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell * app should not need to concern itself with saving and restoring, but that 429c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell * the framework should take special note to preserve when possible. 430c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell * 431c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell * @param view View to check for transient state 432c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell * @return true if the view has transient state 433c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell */ 434c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell public static boolean hasTransientState(View view) { 435c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell return IMPL.hasTransientState(view); 436c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell } 437c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell 438c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell /** 439c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell * Set whether this view is currently tracking transient state that the 440c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell * framework should attempt to preserve when possible. 441c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell * 442c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell * @param view View tracking transient state 443c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell * @param hasTransientState true if this view has transient state 444c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell */ 445c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell public static void setHasTransientState(View view, boolean hasTransientState) { 446c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell IMPL.setHasTransientState(view, hasTransientState); 447c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell } 448ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell 449ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell /** 450ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * <p>Cause an invalidate to happen on the next animation time step, typically the 451ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * next display frame.</p> 452ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * 453ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * <p>This method can be invoked from outside of the UI thread 454ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * only when this View is attached to a window.</p> 455ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * 456ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * @param view View to invalidate 457ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell */ 458ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell public static void postInvalidateOnAnimation(View view) { 459ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell IMPL.postInvalidateOnAnimation(view); 460ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell } 461ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell 462ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell /** 463ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * <p>Cause an invalidate of the specified area to happen on the next animation 464ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * time step, typically the next display frame.</p> 465ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * 466ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * <p>This method can be invoked from outside of the UI thread 467ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * only when this View is attached to a window.</p> 468ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * 469ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * @param view View to invalidate 470ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * @param left The left coordinate of the rectangle to invalidate. 471ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * @param top The top coordinate of the rectangle to invalidate. 472ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * @param right The right coordinate of the rectangle to invalidate. 473ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * @param bottom The bottom coordinate of the rectangle to invalidate. 474ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell */ 475ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell public static void postInvalidateOnAnimation(View view, int left, int top, 476ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell int right, int bottom) { 477ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell IMPL.postInvalidateOnAnimation(view, left, top, right, bottom); 478ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell } 479ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell 480ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell /** 481ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * <p>Causes the Runnable to execute on the next animation time step. 482ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * The runnable will be run on the user interface thread.</p> 483ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * 484ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * <p>This method can be invoked from outside of the UI thread 485ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * only when this View is attached to a window.</p> 486ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * 487ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * @param view View to post this Runnable to 488ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * @param action The Runnable that will be executed. 489ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell */ 490ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell public static void postOnAnimation(View view, Runnable action) { 491ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell IMPL.postOnAnimation(view, action); 492ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell } 493ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell 494ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell /** 495ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * <p>Causes the Runnable to execute on the next animation time step, 496ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * after the specified amount of time elapses. 497ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * The runnable will be run on the user interface thread.</p> 498ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * 499ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * <p>This method can be invoked from outside of the UI thread 500ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * only when this View is attached to a window.</p> 501ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * 502ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * @param view The view to post this Runnable to 503ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * @param action The Runnable that will be executed. 504ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * @param delayMillis The delay (in milliseconds) until the Runnable 505ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell * will be executed. 506ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell */ 507ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell public static void postOnAnimationDelayed(View view, Runnable action, long delayMillis) { 508ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell IMPL.postOnAnimationDelayed(view, action, delayMillis); 509ec03704fbb4f0217d4c274d1c6cf56e6ea4dcfbdAdam Powell } 51025121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov 51125121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov /** 51225121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * Gets the mode for determining whether this View is important for accessibility 51325121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * which is if it fires accessibility events and if it is reported to 51425121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * accessibility services that query the screen. 51525121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * 51625121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * @param view The view whose property to get. 51725121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * @return The mode for determining whether a View is important for accessibility. 51825121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * 51925121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * @see #IMPORTANT_FOR_ACCESSIBILITY_YES 52025121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * @see #IMPORTANT_FOR_ACCESSIBILITY_NO 52125121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO 52225121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov */ 52325121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov public static int getImportantForAccessibility(View view) { 52425121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov return IMPL.getImportantForAccessibility(view); 52525121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov } 52625121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov 52725121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov /** 52825121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * Sets how to determine whether this view is important for accessibility 52925121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * which is if it fires accessibility events and if it is reported to 53025121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * accessibility services that query the screen. 53125121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * 53225121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * @param view The view whose property to set. 53325121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * @param mode How to determine whether this view is important for accessibility. 53425121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * 53525121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * @see #IMPORTANT_FOR_ACCESSIBILITY_YES 53625121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * @see #IMPORTANT_FOR_ACCESSIBILITY_NO 53725121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO 53825121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov */ 53925121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov public static void setImportantForAccessibility(View view, int mode) { 54025121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov IMPL.setImportantForAccessibility(view, mode); 54125121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov } 54225121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov 54325121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov /** 5440d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv * Performs the specified accessibility action on the view. For 5450d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv * possible accessibility actions look at {@link AccessibilityNodeInfoCompat}. 5460d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv * <p> 5470d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv * If an {@link AccessibilityDelegateCompat} has been specified via calling 5480d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv * {@link #setAccessibilityDelegate(View, AccessibilityDelegateCompat)} its 5490d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv * {@link AccessibilityDelegateCompat#performAccessibilityAction(View, int, Bundle)} 5500d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv * is responsible for handling this call. 5510d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv * </p> 5520d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv * 5530d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv * @param action The action to perform. 5540d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv * @param arguments Optional action arguments. 5550d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv * @return Whether the action was performed. 5560d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv */ 5570d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv public static boolean performAccessibilityAction(View view, int action, Bundle arguments) { 5580d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv return IMPL.performAccessibilityAction(view, action, arguments); 5590d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv } 5600d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv 5610d4ffdf13a16b1ce2f3bc458002374cdd25663c3alanv /** 56225121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * Gets the provider for managing a virtual view hierarchy rooted at this View 563e13cf48dc33e3865794d145ae8f4daed0bb2274bSvetoslav Ganov * and reported to {@link android.accessibilityservice.AccessibilityService}s 56425121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * that explore the window content. 56525121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * <p> 56625121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * If this method returns an instance, this instance is responsible for managing 567e13cf48dc33e3865794d145ae8f4daed0bb2274bSvetoslav Ganov * {@link AccessibilityNodeInfoCompat}s describing the virtual sub-tree rooted at 56825121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * this View including the one representing the View itself. Similarly the returned 56925121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * instance is responsible for performing accessibility actions on any virtual 57025121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * view or the root view itself. 57125121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * </p> 57225121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * <p> 57325121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * If an {@link AccessibilityDelegateCompat} has been specified via calling 574e13cf48dc33e3865794d145ae8f4daed0bb2274bSvetoslav Ganov * {@link #setAccessibilityDelegate(View, AccessibilityDelegateCompat) its 57525121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * {@link AccessibilityDelegateCompat#getAccessibilityNodeProvider(View)} 57625121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * is responsible for handling this call. 57725121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * </p> 57825121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * 57925121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * @param view The view whose property to get. 58025121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * @return The provider. 58125121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * 58225121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov * @see AccessibilityNodeProviderCompat 58325121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov */ 58425121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov public static AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view) { 58525121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov return IMPL.getAccessibilityNodeProvider(view); 58625121559b53b9f6c7ef7159203d42e11b9aee281Svetoslav Ganov } 587bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell} 588