ViewCompat.java revision c95beb648f59c89c6bd7b0eed0a8b266a1b287e2
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);
55c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell        public boolean hasTransientState(View view);
56c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell        public void setHasTransientState(View view, boolean hasTransientState);
57bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    }
58bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell
59bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    static class BaseViewCompatImpl implements ViewCompatImpl {
60bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        public boolean canScrollHorizontally(View v, int direction) {
61bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell            return false;
62bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        }
63bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        public boolean canScrollVertically(View v, int direction) {
64bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell            return false;
65bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        }
66560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell        public int getOverScrollMode(View v) {
67560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell            return OVER_SCROLL_NEVER;
68560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell        }
69560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell        public void setOverScrollMode(View v, int mode) {
70560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell            // Do nothing; API doesn't exist
71560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell        }
729648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        public void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) {
739648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov            // Do nothing; API doesn't exist
749648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        }
759648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) {
769648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov            // Do nothing; API doesn't exist
779648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        }
789648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        public void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) {
799648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov         // Do nothing; API doesn't exist
809648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        }
819648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) {
829648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov            // Do nothing; API doesn't exist
839648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        }
84c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell        public boolean hasTransientState(View view) {
85c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell            // A view can't have transient state if transient state wasn't supported.
86c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell            return false;
87c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell        }
88c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell        public void setHasTransientState(View view, boolean hasTransientState) {
89c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell            // Do nothing; API doesn't exist
90c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell        }
91bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    }
92bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell
93560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell    static class GBViewCompatImpl extends BaseViewCompatImpl {
949648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        @Override
95560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell        public int getOverScrollMode(View v) {
96560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell            return ViewCompatGingerbread.getOverScrollMode(v);
97560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell        }
989648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        @Override
99560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell        public void setOverScrollMode(View v, int mode) {
100560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell            ViewCompatGingerbread.setOverScrollMode(v, mode);
101560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell        }
102560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell    }
103560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell
104560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell    static class ICSViewCompatImpl extends GBViewCompatImpl {
1059648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        @Override
106bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        public boolean canScrollHorizontally(View v, int direction) {
107bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell            return ViewCompatICS.canScrollHorizontally(v, direction);
108bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        }
1099648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        @Override
110bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        public boolean canScrollVertically(View v, int direction) {
111bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell            return ViewCompatICS.canScrollVertically(v, direction);
112bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        }
1139648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        @Override
1149648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) {
1159648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov            ViewCompatICS.onPopulateAccessibilityEvent(v, event);
1169648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        }
1179648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        @Override
1189648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        public void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) {
1199648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov            ViewCompatICS.onInitializeAccessibilityEvent(v, event);
1209648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        }
1219648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        @Override
1229648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) {
123956b013dfda37760b0232ed6d448900a546d2903Svetoslav Ganov            ViewCompatICS.onInitializeAccessibilityNodeInfo(v, info.getInfo());
1249648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        }
1259648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        @Override
1269648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        public void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) {
1279648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov            ViewCompatICS.setAccessibilityDelegate(v, delegate.getBridge());
1289648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        }
129bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    }
130bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell
131c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell    static class JBViewCompatImpl extends ICSViewCompatImpl {
132c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell        @Override
133c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell        public boolean hasTransientState(View view) {
134c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell            return ViewCompatJB.hasTransientState(view);
135c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell        }
136c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell        @Override
137c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell        public void setHasTransientState(View view, boolean hasTransientState) {
138c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell            ViewCompatJB.setHasTransientState(view, hasTransientState);
139c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell        }
140c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell    }
141c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell
142bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    static final ViewCompatImpl IMPL;
143bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    static {
144560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell        final int version = android.os.Build.VERSION.SDK_INT;
145c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell        if (version >= 16 || android.os.Build.VERSION.CODENAME.equals("JellyBean")) {
146c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell            IMPL = new JBViewCompatImpl();
147c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell        } else if (version >= 14) {
148bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell            IMPL = new ICSViewCompatImpl();
149560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell        } else if (version >= 9) {
150560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell            IMPL = new GBViewCompatImpl();
151bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        } else {
152bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell            IMPL = new BaseViewCompatImpl();
153bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        }
154bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    }
155bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell
1560574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov    /**
1570574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * Check if this view can be scrolled horizontally in a certain direction.
1580574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *
1590574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @param v The View against which to invoke the method.
1600574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @param direction Negative to check scrolling left, positive to check scrolling right.
1610574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @return true if this view can be scrolled in the specified direction, false otherwise.
1620574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     */
163bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    public static boolean canScrollHorizontally(View v, int direction) {
164bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        return IMPL.canScrollHorizontally(v, direction);
165bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    }
166bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell
1670574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov    /**
1680574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * Check if this view can be scrolled vertically in a certain direction.
1690574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *
1700574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @param v The View against which to invoke the method.
1710574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @param direction Negative to check scrolling up, positive to check scrolling down.
1720574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @return true if this view can be scrolled in the specified direction, false otherwise.
1730574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     */
174bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    public static boolean canScrollVertically(View v, int direction) {
175bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell        return IMPL.canScrollVertically(v, direction);
176bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell    }
177560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell
1780574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov    /**
1790574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * Returns the over-scroll mode for this view. The result will be
1800574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS}
1810574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * (allow over-scrolling only if the view content is larger than the container),
1820574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * or {@link #OVER_SCROLL_NEVER}.
1830574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *
1840574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @param v The View against which to invoke the method.
1850574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @return This view's over-scroll mode.
1860574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     */
187560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell    public static int getOverScrollMode(View v) {
188560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell        return IMPL.getOverScrollMode(v);
189560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell    }
190560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell
1910574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov    /**
1920574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * Set the over-scroll mode for this view. Valid over-scroll modes are
1930574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS}
1940574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * (allow over-scrolling only if the view content is larger than the container),
1950574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * or {@link #OVER_SCROLL_NEVER}.
1960574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *
1970574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * Setting the over-scroll mode of a view will have an effect only if the
1980574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * view is capable of scrolling.
1990574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *
2000574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @param v The View against which to invoke the method.
2010574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @param overScrollMode The new over-scroll mode for this view.
2020574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     */
2030574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov    public static void setOverScrollMode(View v, int overScrollMode) {
2040574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov        IMPL.setOverScrollMode(v, overScrollMode);
205560114f591be31d0fb73c26a1ee1cc0a15184abaAdam Powell    }
2069648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov
2070574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov    /**
2080574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * Called from {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)}
2090574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * giving a chance to this View to populate the accessibility event with its
2100574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * text content. While this method is free to modify event
2110574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * attributes other than text content, doing so should normally be performed in
2120574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent)}.
2130574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <p>
2140574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * Example: Adding formatted date string to an accessibility event in addition
2150574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *          to the text added by the super implementation:
2160574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
2170574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *     super.onPopulateAccessibilityEvent(event);
2180574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *     final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY;
2190574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *     String selectedDateUtterance = DateUtils.formatDateTime(mContext,
2200574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *         mCurrentDate.getTimeInMillis(), flags);
2210574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *     event.getText().add(selectedDateUtterance);
2220574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * }</pre>
2230574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <p>
2240574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * If an {@link android.view.View.AccessibilityDelegate} has been specified via calling
2250574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * {@link View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)} its
2260574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * {@link android.view.View.AccessibilityDelegate#onPopulateAccessibilityEvent(View,
2270574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *  AccessibilityEvent)}
2280574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * is responsible for handling this call.
2290574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * </p>
2300574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <p class="note"><strong>Note:</strong> Always call the super implementation before adding
2310574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * information to the event, in case the default implementation has basic information to add.
2320574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * </p>
2330574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *
2340574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @param v The View against which to invoke the method.
2350574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @param event The accessibility event which to populate.
2360574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *
2370574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @see View#sendAccessibilityEvent(int)
2380574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
2390574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     */
2409648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov    public static void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) {
2419648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        IMPL.onPopulateAccessibilityEvent(v, event);
2429648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov    }
2439648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov
2440574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov    /**
2450574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * Initializes an {@link AccessibilityEvent} with information about
2460574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * this View which is the event source. In other words, the source of
2470574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * an accessibility event is the view whose state change triggered firing
2480574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * the event.
2490574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <p>
2500574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * Example: Setting the password property of an event in addition
2510574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *          to properties set by the super implementation:
2520574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
2530574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *     super.onInitializeAccessibilityEvent(event);
2540574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *     event.setPassword(true);
2550574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * }</pre>
2560574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <p>
2570574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * If an {@link android.view.View.AccessibilityDelegate} has been specified via calling
2580574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * {@link View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)} its
2590574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * {@link android.view.View.AccessibilityDelegate#onInitializeAccessibilityEvent(View,
2600574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *  AccessibilityEvent)}
2610574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * is responsible for handling this call.
2620574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * </p>
2630574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <p class="note"><strong>Note:</strong> Always call the super implementation before adding
2640574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * information to the event, in case the default implementation has basic information to add.
2650574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * </p>
2660574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *
2670574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @param v The View against which to invoke the method.
2680574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @param event The event to initialize.
2690574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *
2700574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @see View#sendAccessibilityEvent(int)
2710574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
2720574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     */
2739648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov    public static void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) {
2749648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        IMPL.onInitializeAccessibilityEvent(v, event);
2759648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov    }
2769648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov
2770574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov    /**
2780574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * Initializes an {@link android.view.accessibility.AccessibilityNodeInfo} with information
2790574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * about this view. The base implementation sets:
2800574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <ul>
2810574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setParent(View)},</li>
2820574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setBoundsInParent(Rect)},</li>
2830574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li>
2840574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setPackageName(CharSequence)},</li>
2850574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setClassName(CharSequence)},</li>
2860574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setContentDescription(CharSequence)},</li>
2870574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setEnabled(boolean)},</li>
2880574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setClickable(boolean)},</li>
2890574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setFocusable(boolean)},</li>
2900574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setFocused(boolean)},</li>
2910574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setLongClickable(boolean)},</li>
2920574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setSelected(boolean)},</li>
2930574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * </ul>
2940574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <p>
2950574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * Subclasses should override this method, call the super implementation,
2960574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * and set additional attributes.
2970574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * </p>
2980574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * <p>
2990574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * If an {@link android.view.View.AccessibilityDelegate} has been specified via calling
3000574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * {@link View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)} its
3010574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * {@link android.view.View.AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View,
3020574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *  android.view.accessibility.AccessibilityNodeInfo)}
3030574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * is responsible for handling this call.
3040574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * </p>
3050574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *
3060574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @param v The View against which to invoke the method.
3070574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @param info The instance to initialize.
3080574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     */
3099648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov    public static void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) {
3109648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        IMPL.onInitializeAccessibilityNodeInfo(v, info);
3119648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov    }
3129648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov
3130574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov    /**
3140574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * Sets a delegate for implementing accessibility support via compositon as
3150574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * opposed to inheritance. The delegate's primary use is for implementing
3160574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * backwards compatible widgets. For more details see
3170574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * {@link android.view.View.AccessibilityDelegate}.
3180574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *
3190574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @param v The View against which to invoke the method.
3200574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @param delegate The delegate instance.
3210574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     *
3220574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     * @see android.view.View.AccessibilityDelegate
3230574ca37da4619afe4e26753f5a1b4de314b6565Svetoslav Ganov     */
3249648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov    public static void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) {
3259648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov        IMPL.setAccessibilityDelegate(v, delegate);
3269648c538bac4f04145c118cc41168d1d7a536312Svetoslav Ganov    }
327c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell
328c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell    /**
329c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell     * Indicates whether the view is currently tracking transient state that the
330c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell     * app should not need to concern itself with saving and restoring, but that
331c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell     * the framework should take special note to preserve when possible.
332c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell     *
333c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell     * @param view View to check for transient state
334c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell     * @return true if the view has transient state
335c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell     */
336c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell    public static boolean hasTransientState(View view) {
337c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell        return IMPL.hasTransientState(view);
338c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell    }
339c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell
340c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell    /**
341c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell     * Set whether this view is currently tracking transient state that the
342c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell     * framework should attempt to preserve when possible.
343c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell     *
344c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell     * @param view View tracking transient state
345c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell     * @param hasTransientState true if this view has transient state
346c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell     */
347c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell    public static void setHasTransientState(View view, boolean hasTransientState) {
348c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell        IMPL.setHasTransientState(view, hasTransientState);
349c95beb648f59c89c6bd7b0eed0a8b266a1b287e2Adam Powell    }
350bc889e39e279fcf8c3d35fc11d8052c002eddf38Adam Powell}
351