ViewCompat.java revision 83df688ed22cdc90e7eae83e13ddf1b3ba378947
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.support.v4.view;
18
19import android.graphics.Paint;
20import android.graphics.Rect;
21import android.os.Bundle;
22import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
23import android.support.v4.view.accessibility.AccessibilityNodeProviderCompat;
24import android.view.View;
25import android.view.accessibility.AccessibilityEvent;
26
27/**
28 * Helper for accessing features in {@link View} introduced after API
29 * level 4 in a backwards compatible fashion.
30 */
31public class ViewCompat {
32    /**
33     * Always allow a user to over-scroll this view, provided it is a
34     * view that can scroll.
35     */
36    public static final int OVER_SCROLL_ALWAYS = 0;
37
38    /**
39     * Allow a user to over-scroll this view only if the content is large
40     * enough to meaningfully scroll, provided it is a view that can scroll.
41     */
42    public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1;
43
44    /**
45     * Never allow a user to over-scroll this view.
46     */
47    public static final int OVER_SCROLL_NEVER = 2;
48
49    private static final long FAKE_FRAME_TIME = 10;
50
51    /**
52     * Automatically determine whether a view is important for accessibility.
53     */
54    public static final int IMPORTANT_FOR_ACCESSIBILITY_AUTO = 0x00000000;
55
56    /**
57     * The view is important for accessibility.
58     */
59    public static final int IMPORTANT_FOR_ACCESSIBILITY_YES = 0x00000001;
60
61    /**
62     * The view is not important for accessibility.
63     */
64    public static final int IMPORTANT_FOR_ACCESSIBILITY_NO = 0x00000002;
65
66    /**
67     * Indicates that the view does not have a layer.
68     */
69    public static final int LAYER_TYPE_NONE = 0;
70
71    /**
72     * <p>Indicates that the view has a software layer. A software layer is backed
73     * by a bitmap and causes the view to be rendered using Android's software
74     * rendering pipeline, even if hardware acceleration is enabled.</p>
75     *
76     * <p>Software layers have various usages:</p>
77     * <p>When the application is not using hardware acceleration, a software layer
78     * is useful to apply a specific color filter and/or blending mode and/or
79     * translucency to a view and all its children.</p>
80     * <p>When the application is using hardware acceleration, a software layer
81     * is useful to render drawing primitives not supported by the hardware
82     * accelerated pipeline. It can also be used to cache a complex view tree
83     * into a texture and reduce the complexity of drawing operations. For instance,
84     * when animating a complex view tree with a translation, a software layer can
85     * be used to render the view tree only once.</p>
86     * <p>Software layers should be avoided when the affected view tree updates
87     * often. Every update will require to re-render the software layer, which can
88     * potentially be slow (particularly when hardware acceleration is turned on
89     * since the layer will have to be uploaded into a hardware texture after every
90     * update.)</p>
91     */
92    public static final int LAYER_TYPE_SOFTWARE = 1;
93
94    /**
95     * <p>Indicates that the view has a hardware layer. A hardware layer is backed
96     * by a hardware specific texture (generally Frame Buffer Objects or FBO on
97     * OpenGL hardware) and causes the view to be rendered using Android's hardware
98     * rendering pipeline, but only if hardware acceleration is turned on for the
99     * view hierarchy. When hardware acceleration is turned off, hardware layers
100     * behave exactly as {@link #LAYER_TYPE_SOFTWARE software layers}.</p>
101     *
102     * <p>A hardware layer is useful to apply a specific color filter and/or
103     * blending mode and/or translucency to a view and all its children.</p>
104     * <p>A hardware layer can be used to cache a complex view tree into a
105     * texture and reduce the complexity of drawing operations. For instance,
106     * when animating a complex view tree with a translation, a hardware layer can
107     * be used to render the view tree only once.</p>
108     * <p>A hardware layer can also be used to increase the rendering quality when
109     * rotation transformations are applied on a view. It can also be used to
110     * prevent potential clipping issues when applying 3D transforms on a view.</p>
111     */
112    public static final int LAYER_TYPE_HARDWARE = 2;
113
114    interface ViewCompatImpl {
115        public boolean canScrollHorizontally(View v, int direction);
116        public boolean canScrollVertically(View v, int direction);
117        public int getOverScrollMode(View v);
118        public void setOverScrollMode(View v, int mode);
119        public void onInitializeAccessibilityEvent(View v, AccessibilityEvent event);
120        public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event);
121        public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info);
122        public void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate);
123        public boolean hasTransientState(View view);
124        public void setHasTransientState(View view, boolean hasTransientState);
125        public void postInvalidateOnAnimation(View view);
126        public void postInvalidateOnAnimation(View view, int left, int top, int right, int bottom);
127        public void postOnAnimation(View view, Runnable action);
128        public void postOnAnimationDelayed(View view, Runnable action, long delayMillis);
129        public int getImportantForAccessibility(View view);
130        public void setImportantForAccessibility(View view, int mode);
131        public boolean performAccessibilityAction(View view, int action, Bundle arguments);
132        public AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view);
133        public void setLayerType(View view, int layerType, Paint paint);
134        public int getLayerType(View view);
135    }
136
137    static class BaseViewCompatImpl implements ViewCompatImpl {
138        public boolean canScrollHorizontally(View v, int direction) {
139            return false;
140        }
141        public boolean canScrollVertically(View v, int direction) {
142            return false;
143        }
144        public int getOverScrollMode(View v) {
145            return OVER_SCROLL_NEVER;
146        }
147        public void setOverScrollMode(View v, int mode) {
148            // Do nothing; API doesn't exist
149        }
150        public void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) {
151            // Do nothing; API doesn't exist
152        }
153        public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) {
154            // Do nothing; API doesn't exist
155        }
156        public void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) {
157         // Do nothing; API doesn't exist
158        }
159        public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) {
160            // Do nothing; API doesn't exist
161        }
162        public boolean hasTransientState(View view) {
163            // A view can't have transient state if transient state wasn't supported.
164            return false;
165        }
166        public void setHasTransientState(View view, boolean hasTransientState) {
167            // Do nothing; API doesn't exist
168        }
169        public void postInvalidateOnAnimation(View view) {
170            view.postInvalidateDelayed(getFrameTime());
171        }
172        public void postInvalidateOnAnimation(View view, int left, int top, int right, int bottom) {
173            view.postInvalidateDelayed(getFrameTime(), left, top, right, bottom);
174        }
175        public void postOnAnimation(View view, Runnable action) {
176            view.postDelayed(action, getFrameTime());
177        }
178        public void postOnAnimationDelayed(View view, Runnable action, long delayMillis) {
179            view.postDelayed(action, getFrameTime() + delayMillis);
180        }
181        long getFrameTime() {
182            return FAKE_FRAME_TIME;
183        }
184        public int getImportantForAccessibility(View view) {
185            return 0;
186        }
187        public void setImportantForAccessibility(View view, int mode) {
188
189        }
190        public boolean performAccessibilityAction(View view, int action, Bundle arguments) {
191            return false;
192        }
193        public AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view) {
194            return null;
195        }
196        public void setLayerType(View view, int layerType, Paint paint) {
197        }
198        public int getLayerType(View view) {
199            return LAYER_TYPE_NONE;
200        }
201    }
202
203    static class GBViewCompatImpl extends BaseViewCompatImpl {
204        @Override
205        public int getOverScrollMode(View v) {
206            return ViewCompatGingerbread.getOverScrollMode(v);
207        }
208        @Override
209        public void setOverScrollMode(View v, int mode) {
210            ViewCompatGingerbread.setOverScrollMode(v, mode);
211        }
212    }
213
214    static class HCViewCompatImpl extends GBViewCompatImpl {
215        long getFrameTime() {
216            return ViewCompatHC.getFrameTime();
217        }
218        @Override public void setLayerType(View view, int layerType, Paint paint) {
219            ViewCompatHC.setLayerType(view, layerType, paint);
220        }
221        @Override public int getLayerType(View view)  {
222            return ViewCompatHC.getLayerType(view);
223        }
224    }
225
226    static class ICSViewCompatImpl extends HCViewCompatImpl {
227        @Override
228        public boolean canScrollHorizontally(View v, int direction) {
229            return ViewCompatICS.canScrollHorizontally(v, direction);
230        }
231        @Override
232        public boolean canScrollVertically(View v, int direction) {
233            return ViewCompatICS.canScrollVertically(v, direction);
234        }
235        @Override
236        public void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) {
237            ViewCompatICS.onPopulateAccessibilityEvent(v, event);
238        }
239        @Override
240        public void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) {
241            ViewCompatICS.onInitializeAccessibilityEvent(v, event);
242        }
243        @Override
244        public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) {
245            ViewCompatICS.onInitializeAccessibilityNodeInfo(v, info.getInfo());
246        }
247        @Override
248        public void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) {
249            ViewCompatICS.setAccessibilityDelegate(v, delegate.getBridge());
250        }
251    }
252
253    static class JBViewCompatImpl extends ICSViewCompatImpl {
254        @Override
255        public boolean hasTransientState(View view) {
256            return ViewCompatJB.hasTransientState(view);
257        }
258        @Override
259        public void setHasTransientState(View view, boolean hasTransientState) {
260            ViewCompatJB.setHasTransientState(view, hasTransientState);
261        }
262        @Override
263        public void postInvalidateOnAnimation(View view) {
264            ViewCompatJB.postInvalidateOnAnimation(view);
265        }
266        @Override
267        public void postInvalidateOnAnimation(View view, int left, int top, int right, int bottom) {
268            ViewCompatJB.postInvalidateOnAnimation(view, left, top, right, bottom);
269        }
270        @Override
271        public void postOnAnimation(View view, Runnable action) {
272            ViewCompatJB.postOnAnimation(view, action);
273        }
274        @Override
275        public void postOnAnimationDelayed(View view, Runnable action, long delayMillis) {
276            ViewCompatJB.postOnAnimationDelayed(view, action, delayMillis);
277        }
278        @Override
279        public int getImportantForAccessibility(View view) {
280            return ViewCompatJB.getImportantForAccessibility(view);
281        }
282        @Override
283        public void setImportantForAccessibility(View view, int mode) {
284            ViewCompatJB.setImportantForAccessibility(view, mode);
285        }
286        @Override
287        public boolean performAccessibilityAction(View view, int action, Bundle arguments) {
288            return ViewCompatJB.performAccessibilityAction(view, action, arguments);
289        }
290        @Override
291        public AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view) {
292            Object compat = ViewCompatJB.getAccessibilityNodeProvider(view);
293            if (compat != null) {
294                return new AccessibilityNodeProviderCompat(compat);
295            }
296            return null;
297        }
298    }
299
300    static final ViewCompatImpl IMPL;
301    static {
302        final int version = android.os.Build.VERSION.SDK_INT;
303        if (version >= 16 || android.os.Build.VERSION.CODENAME.equals("JellyBean")) {
304            IMPL = new JBViewCompatImpl();
305        } else if (version >= 14) {
306            IMPL = new ICSViewCompatImpl();
307        } else if (version >= 11) {
308            IMPL = new HCViewCompatImpl();
309        } else if (version >= 9) {
310            IMPL = new GBViewCompatImpl();
311        } else {
312            IMPL = new BaseViewCompatImpl();
313        }
314    }
315
316    /**
317     * Check if this view can be scrolled horizontally in a certain direction.
318     *
319     * @param v The View against which to invoke the method.
320     * @param direction Negative to check scrolling left, positive to check scrolling right.
321     * @return true if this view can be scrolled in the specified direction, false otherwise.
322     */
323    public static boolean canScrollHorizontally(View v, int direction) {
324        return IMPL.canScrollHorizontally(v, direction);
325    }
326
327    /**
328     * Check if this view can be scrolled vertically in a certain direction.
329     *
330     * @param v The View against which to invoke the method.
331     * @param direction Negative to check scrolling up, positive to check scrolling down.
332     * @return true if this view can be scrolled in the specified direction, false otherwise.
333     */
334    public static boolean canScrollVertically(View v, int direction) {
335        return IMPL.canScrollVertically(v, direction);
336    }
337
338    /**
339     * Returns the over-scroll mode for this view. The result will be
340     * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS}
341     * (allow over-scrolling only if the view content is larger than the container),
342     * or {@link #OVER_SCROLL_NEVER}.
343     *
344     * @param v The View against which to invoke the method.
345     * @return This view's over-scroll mode.
346     */
347    public static int getOverScrollMode(View v) {
348        return IMPL.getOverScrollMode(v);
349    }
350
351    /**
352     * Set the over-scroll mode for this view. Valid over-scroll modes are
353     * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS}
354     * (allow over-scrolling only if the view content is larger than the container),
355     * or {@link #OVER_SCROLL_NEVER}.
356     *
357     * Setting the over-scroll mode of a view will have an effect only if the
358     * view is capable of scrolling.
359     *
360     * @param v The View against which to invoke the method.
361     * @param overScrollMode The new over-scroll mode for this view.
362     */
363    public static void setOverScrollMode(View v, int overScrollMode) {
364        IMPL.setOverScrollMode(v, overScrollMode);
365    }
366
367    /**
368     * Called from {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)}
369     * giving a chance to this View to populate the accessibility event with its
370     * text content. While this method is free to modify event
371     * attributes other than text content, doing so should normally be performed in
372     * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent)}.
373     * <p>
374     * Example: Adding formatted date string to an accessibility event in addition
375     *          to the text added by the super implementation:
376     * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
377     *     super.onPopulateAccessibilityEvent(event);
378     *     final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY;
379     *     String selectedDateUtterance = DateUtils.formatDateTime(mContext,
380     *         mCurrentDate.getTimeInMillis(), flags);
381     *     event.getText().add(selectedDateUtterance);
382     * }</pre>
383     * <p>
384     * If an {@link android.view.View.AccessibilityDelegate} has been specified via calling
385     * {@link View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)} its
386     * {@link android.view.View.AccessibilityDelegate#onPopulateAccessibilityEvent(View,
387     *  AccessibilityEvent)}
388     * is responsible for handling this call.
389     * </p>
390     * <p class="note"><strong>Note:</strong> Always call the super implementation before adding
391     * information to the event, in case the default implementation has basic information to add.
392     * </p>
393     *
394     * @param v The View against which to invoke the method.
395     * @param event The accessibility event which to populate.
396     *
397     * @see View#sendAccessibilityEvent(int)
398     * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
399     */
400    public static void onPopulateAccessibilityEvent(View v, AccessibilityEvent event) {
401        IMPL.onPopulateAccessibilityEvent(v, event);
402    }
403
404    /**
405     * Initializes an {@link AccessibilityEvent} with information about
406     * this View which is the event source. In other words, the source of
407     * an accessibility event is the view whose state change triggered firing
408     * the event.
409     * <p>
410     * Example: Setting the password property of an event in addition
411     *          to properties set by the super implementation:
412     * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
413     *     super.onInitializeAccessibilityEvent(event);
414     *     event.setPassword(true);
415     * }</pre>
416     * <p>
417     * If an {@link android.view.View.AccessibilityDelegate} has been specified via calling
418     * {@link View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)} its
419     * {@link android.view.View.AccessibilityDelegate#onInitializeAccessibilityEvent(View,
420     *  AccessibilityEvent)}
421     * is responsible for handling this call.
422     * </p>
423     * <p class="note"><strong>Note:</strong> Always call the super implementation before adding
424     * information to the event, in case the default implementation has basic information to add.
425     * </p>
426     *
427     * @param v The View against which to invoke the method.
428     * @param event The event to initialize.
429     *
430     * @see View#sendAccessibilityEvent(int)
431     * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
432     */
433    public static void onInitializeAccessibilityEvent(View v, AccessibilityEvent event) {
434        IMPL.onInitializeAccessibilityEvent(v, event);
435    }
436
437    /**
438     * Initializes an {@link android.view.accessibility.AccessibilityNodeInfo} with information
439     * about this view. The base implementation sets:
440     * <ul>
441     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setParent(View)},</li>
442     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setBoundsInParent(Rect)},</li>
443     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li>
444     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setPackageName(CharSequence)},</li>
445     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setClassName(CharSequence)},</li>
446     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setContentDescription(CharSequence)},</li>
447     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setEnabled(boolean)},</li>
448     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setClickable(boolean)},</li>
449     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setFocusable(boolean)},</li>
450     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setFocused(boolean)},</li>
451     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setLongClickable(boolean)},</li>
452     * <li>{@link android.view.accessibility.AccessibilityNodeInfo#setSelected(boolean)},</li>
453     * </ul>
454     * <p>
455     * Subclasses should override this method, call the super implementation,
456     * and set additional attributes.
457     * </p>
458     * <p>
459     * If an {@link android.view.View.AccessibilityDelegate} has been specified via calling
460     * {@link View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)} its
461     * {@link android.view.View.AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View,
462     *  android.view.accessibility.AccessibilityNodeInfo)}
463     * is responsible for handling this call.
464     * </p>
465     *
466     * @param v The View against which to invoke the method.
467     * @param info The instance to initialize.
468     */
469    public static void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info) {
470        IMPL.onInitializeAccessibilityNodeInfo(v, info);
471    }
472
473    /**
474     * Sets a delegate for implementing accessibility support via compositon as
475     * opposed to inheritance. The delegate's primary use is for implementing
476     * backwards compatible widgets. For more details see
477     * {@link android.view.View.AccessibilityDelegate}.
478     *
479     * @param v The View against which to invoke the method.
480     * @param delegate The delegate instance.
481     *
482     * @see android.view.View.AccessibilityDelegate
483     */
484    public static void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) {
485        IMPL.setAccessibilityDelegate(v, delegate);
486    }
487
488    /**
489     * Indicates whether the view is currently tracking transient state that the
490     * app should not need to concern itself with saving and restoring, but that
491     * the framework should take special note to preserve when possible.
492     *
493     * @param view View to check for transient state
494     * @return true if the view has transient state
495     */
496    public static boolean hasTransientState(View view) {
497        return IMPL.hasTransientState(view);
498    }
499
500    /**
501     * Set whether this view is currently tracking transient state that the
502     * framework should attempt to preserve when possible.
503     *
504     * @param view View tracking transient state
505     * @param hasTransientState true if this view has transient state
506     */
507    public static void setHasTransientState(View view, boolean hasTransientState) {
508        IMPL.setHasTransientState(view, hasTransientState);
509    }
510
511    /**
512     * <p>Cause an invalidate to happen on the next animation time step, typically the
513     * next display frame.</p>
514     *
515     * <p>This method can be invoked from outside of the UI thread
516     * only when this View is attached to a window.</p>
517     *
518     * @param view View to invalidate
519     */
520    public static void postInvalidateOnAnimation(View view) {
521        IMPL.postInvalidateOnAnimation(view);
522    }
523
524    /**
525     * <p>Cause an invalidate of the specified area to happen on the next animation
526     * time step, typically the next display frame.</p>
527     *
528     * <p>This method can be invoked from outside of the UI thread
529     * only when this View is attached to a window.</p>
530     *
531     * @param view View to invalidate
532     * @param left The left coordinate of the rectangle to invalidate.
533     * @param top The top coordinate of the rectangle to invalidate.
534     * @param right The right coordinate of the rectangle to invalidate.
535     * @param bottom The bottom coordinate of the rectangle to invalidate.
536     */
537    public static void postInvalidateOnAnimation(View view, int left, int top,
538            int right, int bottom) {
539        IMPL.postInvalidateOnAnimation(view, left, top, right, bottom);
540    }
541
542    /**
543     * <p>Causes the Runnable to execute on the next animation time step.
544     * The runnable will be run on the user interface thread.</p>
545     *
546     * <p>This method can be invoked from outside of the UI thread
547     * only when this View is attached to a window.</p>
548     *
549     * @param view View to post this Runnable to
550     * @param action The Runnable that will be executed.
551     */
552    public static void postOnAnimation(View view, Runnable action) {
553        IMPL.postOnAnimation(view, action);
554    }
555
556    /**
557     * <p>Causes the Runnable to execute on the next animation time step,
558     * after the specified amount of time elapses.
559     * The runnable will be run on the user interface thread.</p>
560     *
561     * <p>This method can be invoked from outside of the UI thread
562     * only when this View is attached to a window.</p>
563     *
564     * @param view The view to post this Runnable to
565     * @param action The Runnable that will be executed.
566     * @param delayMillis The delay (in milliseconds) until the Runnable
567     *        will be executed.
568     */
569    public static void postOnAnimationDelayed(View view, Runnable action, long delayMillis) {
570        IMPL.postOnAnimationDelayed(view, action, delayMillis);
571    }
572
573    /**
574     * Gets the mode for determining whether this View is important for accessibility
575     * which is if it fires accessibility events and if it is reported to
576     * accessibility services that query the screen.
577     *
578     * @param view The view whose property to get.
579     * @return The mode for determining whether a View is important for accessibility.
580     *
581     * @see #IMPORTANT_FOR_ACCESSIBILITY_YES
582     * @see #IMPORTANT_FOR_ACCESSIBILITY_NO
583     * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO
584     */
585    public static int getImportantForAccessibility(View view) {
586        return IMPL.getImportantForAccessibility(view);
587    }
588
589    /**
590     * Sets how to determine whether this view is important for accessibility
591     * which is if it fires accessibility events and if it is reported to
592     * accessibility services that query the screen.
593     *
594     * @param view The view whose property to set.
595     * @param mode How to determine whether this view is important for accessibility.
596     *
597     * @see #IMPORTANT_FOR_ACCESSIBILITY_YES
598     * @see #IMPORTANT_FOR_ACCESSIBILITY_NO
599     * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO
600     */
601    public static void setImportantForAccessibility(View view, int mode) {
602        IMPL.setImportantForAccessibility(view, mode);
603    }
604
605    /**
606     * Performs the specified accessibility action on the view. For
607     * possible accessibility actions look at {@link AccessibilityNodeInfoCompat}.
608     * <p>
609     * If an {@link AccessibilityDelegateCompat} has been specified via calling
610     * {@link #setAccessibilityDelegate(View, AccessibilityDelegateCompat)} its
611     * {@link AccessibilityDelegateCompat#performAccessibilityAction(View, int, Bundle)}
612     * is responsible for handling this call.
613     * </p>
614     *
615     * @param action The action to perform.
616     * @param arguments Optional action arguments.
617     * @return Whether the action was performed.
618     */
619    public static boolean performAccessibilityAction(View view, int action, Bundle arguments) {
620        return IMPL.performAccessibilityAction(view, action, arguments);
621    }
622
623    /**
624     * Gets the provider for managing a virtual view hierarchy rooted at this View
625     * and reported to {@link android.accessibilityservice.AccessibilityService}s
626     * that explore the window content.
627     * <p>
628     * If this method returns an instance, this instance is responsible for managing
629     * {@link AccessibilityNodeInfoCompat}s describing the virtual sub-tree rooted at
630     * this View including the one representing the View itself. Similarly the returned
631     * instance is responsible for performing accessibility actions on any virtual
632     * view or the root view itself.
633     * </p>
634     * <p>
635     * If an {@link AccessibilityDelegateCompat} has been specified via calling
636     * {@link #setAccessibilityDelegate(View, AccessibilityDelegateCompat) its
637     * {@link AccessibilityDelegateCompat#getAccessibilityNodeProvider(View)}
638     * is responsible for handling this call.
639     * </p>
640     *
641     * @param view The view whose property to get.
642     * @return The provider.
643     *
644     * @see AccessibilityNodeProviderCompat
645     */
646    public static AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view) {
647        return IMPL.getAccessibilityNodeProvider(view);
648    }
649
650    /**
651     * <p>Specifies the type of layer backing this view. The layer can be
652     * {@link #LAYER_TYPE_NONE disabled}, {@link #LAYER_TYPE_SOFTWARE software} or
653     * {@link #LAYER_TYPE_HARDWARE hardware}.</p>
654     *
655     * <p>A layer is associated with an optional {@link android.graphics.Paint}
656     * instance that controls how the layer is composed on screen. The following
657     * properties of the paint are taken into account when composing the layer:</p>
658     * <ul>
659     * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li>
660     * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li>
661     * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li>
662     * </ul>
663     *
664     * <p>If this view has an alpha value set to < 1.0 by calling
665     * setAlpha(float), the alpha value of the layer's paint is replaced by
666     * this view's alpha value. Calling setAlpha(float) is therefore
667     * equivalent to setting a hardware layer on this view and providing a paint with
668     * the desired alpha value.<p>
669     *
670     * <p>Refer to the documentation of {@link #LAYER_TYPE_NONE disabled},
671     * {@link #LAYER_TYPE_SOFTWARE software} and {@link #LAYER_TYPE_HARDWARE hardware}
672     * for more information on when and how to use layers.</p>
673     *
674     * @param layerType The ype of layer to use with this view, must be one of
675     *        {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or
676     *        {@link #LAYER_TYPE_HARDWARE}
677     * @param paint The paint used to compose the layer. This argument is optional
678     *        and can be null. It is ignored when the layer type is
679     *        {@link #LAYER_TYPE_NONE}
680     *
681     * @param view View to set the layer type for
682     * @param layerType The type of layer to use with this view, must be one of
683     *        {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or
684     *        {@link #LAYER_TYPE_HARDWARE}
685     * @param paint The paint used to compose the layer. This argument is optional
686     *        and can be null. It is ignored when the layer type is
687     *        {@link #LAYER_TYPE_NONE}
688     */
689    public static void setLayerType(View view, int layerType, Paint paint) {
690        IMPL.setLayerType(view, layerType, paint);
691    }
692
693    /**
694     * Indicates what type of layer is currently associated with this view. By default
695     * a view does not have a layer, and the layer type is {@link #LAYER_TYPE_NONE}.
696     * Refer to the documentation of
697     * {@link #setLayerType(android.view.View, int, android.graphics.Paint)}
698     * for more information on the different types of layers.
699     *
700     * @param view The view to fetch the layer type from
701     * @return {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or
702     *         {@link #LAYER_TYPE_HARDWARE}
703     *
704     * @see #setLayerType(android.view.View, int, android.graphics.Paint)
705     * @see #LAYER_TYPE_NONE
706     * @see #LAYER_TYPE_SOFTWARE
707     * @see #LAYER_TYPE_HARDWARE
708     */
709    public static int getLayerType(View view) {
710        return IMPL.getLayerType(view);
711    }
712}
713