Home | History | Annotate | Download | only in view
      1 /*
      2  * Copyright (C) 2006 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.view;
     18 
     19 import android.animation.AnimatorInflater;
     20 import android.animation.StateListAnimator;
     21 import android.annotation.CallSuper;
     22 import android.annotation.ColorInt;
     23 import android.annotation.DrawableRes;
     24 import android.annotation.FloatRange;
     25 import android.annotation.IdRes;
     26 import android.annotation.IntDef;
     27 import android.annotation.IntRange;
     28 import android.annotation.LayoutRes;
     29 import android.annotation.NonNull;
     30 import android.annotation.Nullable;
     31 import android.annotation.Size;
     32 import android.annotation.UiThread;
     33 import android.content.ClipData;
     34 import android.content.Context;
     35 import android.content.ContextWrapper;
     36 import android.content.Intent;
     37 import android.content.res.ColorStateList;
     38 import android.content.res.Configuration;
     39 import android.content.res.Resources;
     40 import android.content.res.TypedArray;
     41 import android.graphics.Bitmap;
     42 import android.graphics.Canvas;
     43 import android.graphics.Insets;
     44 import android.graphics.Interpolator;
     45 import android.graphics.LinearGradient;
     46 import android.graphics.Matrix;
     47 import android.graphics.Outline;
     48 import android.graphics.Paint;
     49 import android.graphics.PixelFormat;
     50 import android.graphics.Point;
     51 import android.graphics.PorterDuff;
     52 import android.graphics.PorterDuffXfermode;
     53 import android.graphics.Rect;
     54 import android.graphics.RectF;
     55 import android.graphics.Region;
     56 import android.graphics.Shader;
     57 import android.graphics.drawable.ColorDrawable;
     58 import android.graphics.drawable.Drawable;
     59 import android.hardware.display.DisplayManagerGlobal;
     60 import android.os.Build.VERSION_CODES;
     61 import android.os.Bundle;
     62 import android.os.Handler;
     63 import android.os.IBinder;
     64 import android.os.Parcel;
     65 import android.os.Parcelable;
     66 import android.os.RemoteException;
     67 import android.os.SystemClock;
     68 import android.os.SystemProperties;
     69 import android.os.Trace;
     70 import android.text.TextUtils;
     71 import android.util.AttributeSet;
     72 import android.util.FloatProperty;
     73 import android.util.LayoutDirection;
     74 import android.util.Log;
     75 import android.util.LongSparseLongArray;
     76 import android.util.Pools.SynchronizedPool;
     77 import android.util.Property;
     78 import android.util.SparseArray;
     79 import android.util.StateSet;
     80 import android.util.SuperNotCalledException;
     81 import android.util.TypedValue;
     82 import android.view.ContextMenu.ContextMenuInfo;
     83 import android.view.AccessibilityIterators.CharacterTextSegmentIterator;
     84 import android.view.AccessibilityIterators.ParagraphTextSegmentIterator;
     85 import android.view.AccessibilityIterators.TextSegmentIterator;
     86 import android.view.AccessibilityIterators.WordTextSegmentIterator;
     87 import android.view.accessibility.AccessibilityEvent;
     88 import android.view.accessibility.AccessibilityEventSource;
     89 import android.view.accessibility.AccessibilityManager;
     90 import android.view.accessibility.AccessibilityNodeInfo;
     91 import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
     92 import android.view.accessibility.AccessibilityNodeProvider;
     93 import android.view.animation.Animation;
     94 import android.view.animation.AnimationUtils;
     95 import android.view.animation.Transformation;
     96 import android.view.inputmethod.EditorInfo;
     97 import android.view.inputmethod.InputConnection;
     98 import android.view.inputmethod.InputMethodManager;
     99 import android.widget.Checkable;
    100 import android.widget.FrameLayout;
    101 import android.widget.ScrollBarDrawable;
    102 import static android.os.Build.VERSION_CODES.*;
    103 import static java.lang.Math.max;
    104 
    105 import com.android.internal.R;
    106 import com.android.internal.util.Predicate;
    107 import com.android.internal.view.menu.MenuBuilder;
    108 import com.android.internal.widget.ScrollBarUtils;
    109 import com.google.android.collect.Lists;
    110 import com.google.android.collect.Maps;
    111 
    112 import java.lang.NullPointerException;
    113 import java.lang.annotation.Retention;
    114 import java.lang.annotation.RetentionPolicy;
    115 import java.lang.ref.WeakReference;
    116 import java.lang.reflect.Field;
    117 import java.lang.reflect.InvocationTargetException;
    118 import java.lang.reflect.Method;
    119 import java.lang.reflect.Modifier;
    120 import java.util.ArrayList;
    121 import java.util.Arrays;
    122 import java.util.Collections;
    123 import java.util.HashMap;
    124 import java.util.List;
    125 import java.util.Locale;
    126 import java.util.Map;
    127 import java.util.concurrent.CopyOnWriteArrayList;
    128 import java.util.concurrent.atomic.AtomicInteger;
    129 
    130 /**
    131  * <p>
    132  * This class represents the basic building block for user interface components. A View
    133  * occupies a rectangular area on the screen and is responsible for drawing and
    134  * event handling. View is the base class for <em>widgets</em>, which are
    135  * used to create interactive UI components (buttons, text fields, etc.). The
    136  * {@link android.view.ViewGroup} subclass is the base class for <em>layouts</em>, which
    137  * are invisible containers that hold other Views (or other ViewGroups) and define
    138  * their layout properties.
    139  * </p>
    140  *
    141  * <div class="special reference">
    142  * <h3>Developer Guides</h3>
    143  * <p>For information about using this class to develop your application's user interface,
    144  * read the <a href="{@docRoot}guide/topics/ui/index.html">User Interface</a> developer guide.
    145  * </div>
    146  *
    147  * <a name="Using"></a>
    148  * <h3>Using Views</h3>
    149  * <p>
    150  * All of the views in a window are arranged in a single tree. You can add views
    151  * either from code or by specifying a tree of views in one or more XML layout
    152  * files. There are many specialized subclasses of views that act as controls or
    153  * are capable of displaying text, images, or other content.
    154  * </p>
    155  * <p>
    156  * Once you have created a tree of views, there are typically a few types of
    157  * common operations you may wish to perform:
    158  * <ul>
    159  * <li><strong>Set properties:</strong> for example setting the text of a
    160  * {@link android.widget.TextView}. The available properties and the methods
    161  * that set them will vary among the different subclasses of views. Note that
    162  * properties that are known at build time can be set in the XML layout
    163  * files.</li>
    164  * <li><strong>Set focus:</strong> The framework will handle moving focus in
    165  * response to user input. To force focus to a specific view, call
    166  * {@link #requestFocus}.</li>
    167  * <li><strong>Set up listeners:</strong> Views allow clients to set listeners
    168  * that will be notified when something interesting happens to the view. For
    169  * example, all views will let you set a listener to be notified when the view
    170  * gains or loses focus. You can register such a listener using
    171  * {@link #setOnFocusChangeListener(android.view.View.OnFocusChangeListener)}.
    172  * Other view subclasses offer more specialized listeners. For example, a Button
    173  * exposes a listener to notify clients when the button is clicked.</li>
    174  * <li><strong>Set visibility:</strong> You can hide or show views using
    175  * {@link #setVisibility(int)}.</li>
    176  * </ul>
    177  * </p>
    178  * <p><em>
    179  * Note: The Android framework is responsible for measuring, laying out and
    180  * drawing views. You should not call methods that perform these actions on
    181  * views yourself unless you are actually implementing a
    182  * {@link android.view.ViewGroup}.
    183  * </em></p>
    184  *
    185  * <a name="Lifecycle"></a>
    186  * <h3>Implementing a Custom View</h3>
    187  *
    188  * <p>
    189  * To implement a custom view, you will usually begin by providing overrides for
    190  * some of the standard methods that the framework calls on all views. You do
    191  * not need to override all of these methods. In fact, you can start by just
    192  * overriding {@link #onDraw(android.graphics.Canvas)}.
    193  * <table border="2" width="85%" align="center" cellpadding="5">
    194  *     <thead>
    195  *         <tr><th>Category</th> <th>Methods</th> <th>Description</th></tr>
    196  *     </thead>
    197  *
    198  *     <tbody>
    199  *     <tr>
    200  *         <td rowspan="2">Creation</td>
    201  *         <td>Constructors</td>
    202  *         <td>There is a form of the constructor that are called when the view
    203  *         is created from code and a form that is called when the view is
    204  *         inflated from a layout file. The second form should parse and apply
    205  *         any attributes defined in the layout file.
    206  *         </td>
    207  *     </tr>
    208  *     <tr>
    209  *         <td><code>{@link #onFinishInflate()}</code></td>
    210  *         <td>Called after a view and all of its children has been inflated
    211  *         from XML.</td>
    212  *     </tr>
    213  *
    214  *     <tr>
    215  *         <td rowspan="3">Layout</td>
    216  *         <td><code>{@link #onMeasure(int, int)}</code></td>
    217  *         <td>Called to determine the size requirements for this view and all
    218  *         of its children.
    219  *         </td>
    220  *     </tr>
    221  *     <tr>
    222  *         <td><code>{@link #onLayout(boolean, int, int, int, int)}</code></td>
    223  *         <td>Called when this view should assign a size and position to all
    224  *         of its children.
    225  *         </td>
    226  *     </tr>
    227  *     <tr>
    228  *         <td><code>{@link #onSizeChanged(int, int, int, int)}</code></td>
    229  *         <td>Called when the size of this view has changed.
    230  *         </td>
    231  *     </tr>
    232  *
    233  *     <tr>
    234  *         <td>Drawing</td>
    235  *         <td><code>{@link #onDraw(android.graphics.Canvas)}</code></td>
    236  *         <td>Called when the view should render its content.
    237  *         </td>
    238  *     </tr>
    239  *
    240  *     <tr>
    241  *         <td rowspan="4">Event processing</td>
    242  *         <td><code>{@link #onKeyDown(int, KeyEvent)}</code></td>
    243  *         <td>Called when a new hardware key event occurs.
    244  *         </td>
    245  *     </tr>
    246  *     <tr>
    247  *         <td><code>{@link #onKeyUp(int, KeyEvent)}</code></td>
    248  *         <td>Called when a hardware key up event occurs.
    249  *         </td>
    250  *     </tr>
    251  *     <tr>
    252  *         <td><code>{@link #onTrackballEvent(MotionEvent)}</code></td>
    253  *         <td>Called when a trackball motion event occurs.
    254  *         </td>
    255  *     </tr>
    256  *     <tr>
    257  *         <td><code>{@link #onTouchEvent(MotionEvent)}</code></td>
    258  *         <td>Called when a touch screen motion event occurs.
    259  *         </td>
    260  *     </tr>
    261  *
    262  *     <tr>
    263  *         <td rowspan="2">Focus</td>
    264  *         <td><code>{@link #onFocusChanged(boolean, int, android.graphics.Rect)}</code></td>
    265  *         <td>Called when the view gains or loses focus.
    266  *         </td>
    267  *     </tr>
    268  *
    269  *     <tr>
    270  *         <td><code>{@link #onWindowFocusChanged(boolean)}</code></td>
    271  *         <td>Called when the window containing the view gains or loses focus.
    272  *         </td>
    273  *     </tr>
    274  *
    275  *     <tr>
    276  *         <td rowspan="3">Attaching</td>
    277  *         <td><code>{@link #onAttachedToWindow()}</code></td>
    278  *         <td>Called when the view is attached to a window.
    279  *         </td>
    280  *     </tr>
    281  *
    282  *     <tr>
    283  *         <td><code>{@link #onDetachedFromWindow}</code></td>
    284  *         <td>Called when the view is detached from its window.
    285  *         </td>
    286  *     </tr>
    287  *
    288  *     <tr>
    289  *         <td><code>{@link #onWindowVisibilityChanged(int)}</code></td>
    290  *         <td>Called when the visibility of the window containing the view
    291  *         has changed.
    292  *         </td>
    293  *     </tr>
    294  *     </tbody>
    295  *
    296  * </table>
    297  * </p>
    298  *
    299  * <a name="IDs"></a>
    300  * <h3>IDs</h3>
    301  * Views may have an integer id associated with them. These ids are typically
    302  * assigned in the layout XML files, and are used to find specific views within
    303  * the view tree. A common pattern is to:
    304  * <ul>
    305  * <li>Define a Button in the layout file and assign it a unique ID.
    306  * <pre>
    307  * &lt;Button
    308  *     android:id="@+id/my_button"
    309  *     android:layout_width="wrap_content"
    310  *     android:layout_height="wrap_content"
    311  *     android:text="@string/my_button_text"/&gt;
    312  * </pre></li>
    313  * <li>From the onCreate method of an Activity, find the Button
    314  * <pre class="prettyprint">
    315  *      Button myButton = (Button) findViewById(R.id.my_button);
    316  * </pre></li>
    317  * </ul>
    318  * <p>
    319  * View IDs need not be unique throughout the tree, but it is good practice to
    320  * ensure that they are at least unique within the part of the tree you are
    321  * searching.
    322  * </p>
    323  *
    324  * <a name="Position"></a>
    325  * <h3>Position</h3>
    326  * <p>
    327  * The geometry of a view is that of a rectangle. A view has a location,
    328  * expressed as a pair of <em>left</em> and <em>top</em> coordinates, and
    329  * two dimensions, expressed as a width and a height. The unit for location
    330  * and dimensions is the pixel.
    331  * </p>
    332  *
    333  * <p>
    334  * It is possible to retrieve the location of a view by invoking the methods
    335  * {@link #getLeft()} and {@link #getTop()}. The former returns the left, or X,
    336  * coordinate of the rectangle representing the view. The latter returns the
    337  * top, or Y, coordinate of the rectangle representing the view. These methods
    338  * both return the location of the view relative to its parent. For instance,
    339  * when getLeft() returns 20, that means the view is located 20 pixels to the
    340  * right of the left edge of its direct parent.
    341  * </p>
    342  *
    343  * <p>
    344  * In addition, several convenience methods are offered to avoid unnecessary
    345  * computations, namely {@link #getRight()} and {@link #getBottom()}.
    346  * These methods return the coordinates of the right and bottom edges of the
    347  * rectangle representing the view. For instance, calling {@link #getRight()}
    348  * is similar to the following computation: <code>getLeft() + getWidth()</code>
    349  * (see <a href="#SizePaddingMargins">Size</a> for more information about the width.)
    350  * </p>
    351  *
    352  * <a name="SizePaddingMargins"></a>
    353  * <h3>Size, padding and margins</h3>
    354  * <p>
    355  * The size of a view is expressed with a width and a height. A view actually
    356  * possess two pairs of width and height values.
    357  * </p>
    358  *
    359  * <p>
    360  * The first pair is known as <em>measured width</em> and
    361  * <em>measured height</em>. These dimensions define how big a view wants to be
    362  * within its parent (see <a href="#Layout">Layout</a> for more details.) The
    363  * measured dimensions can be obtained by calling {@link #getMeasuredWidth()}
    364  * and {@link #getMeasuredHeight()}.
    365  * </p>
    366  *
    367  * <p>
    368  * The second pair is simply known as <em>width</em> and <em>height</em>, or
    369  * sometimes <em>drawing width</em> and <em>drawing height</em>. These
    370  * dimensions define the actual size of the view on screen, at drawing time and
    371  * after layout. These values may, but do not have to, be different from the
    372  * measured width and height. The width and height can be obtained by calling
    373  * {@link #getWidth()} and {@link #getHeight()}.
    374  * </p>
    375  *
    376  * <p>
    377  * To measure its dimensions, a view takes into account its padding. The padding
    378  * is expressed in pixels for the left, top, right and bottom parts of the view.
    379  * Padding can be used to offset the content of the view by a specific amount of
    380  * pixels. For instance, a left padding of 2 will push the view's content by
    381  * 2 pixels to the right of the left edge. Padding can be set using the
    382  * {@link #setPadding(int, int, int, int)} or {@link #setPaddingRelative(int, int, int, int)}
    383  * method and queried by calling {@link #getPaddingLeft()}, {@link #getPaddingTop()},
    384  * {@link #getPaddingRight()}, {@link #getPaddingBottom()}, {@link #getPaddingStart()},
    385  * {@link #getPaddingEnd()}.
    386  * </p>
    387  *
    388  * <p>
    389  * Even though a view can define a padding, it does not provide any support for
    390  * margins. However, view groups provide such a support. Refer to
    391  * {@link android.view.ViewGroup} and
    392  * {@link android.view.ViewGroup.MarginLayoutParams} for further information.
    393  * </p>
    394  *
    395  * <a name="Layout"></a>
    396  * <h3>Layout</h3>
    397  * <p>
    398  * Layout is a two pass process: a measure pass and a layout pass. The measuring
    399  * pass is implemented in {@link #measure(int, int)} and is a top-down traversal
    400  * of the view tree. Each view pushes dimension specifications down the tree
    401  * during the recursion. At the end of the measure pass, every view has stored
    402  * its measurements. The second pass happens in
    403  * {@link #layout(int,int,int,int)} and is also top-down. During
    404  * this pass each parent is responsible for positioning all of its children
    405  * using the sizes computed in the measure pass.
    406  * </p>
    407  *
    408  * <p>
    409  * When a view's measure() method returns, its {@link #getMeasuredWidth()} and
    410  * {@link #getMeasuredHeight()} values must be set, along with those for all of
    411  * that view's descendants. A view's measured width and measured height values
    412  * must respect the constraints imposed by the view's parents. This guarantees
    413  * that at the end of the measure pass, all parents accept all of their
    414  * children's measurements. A parent view may call measure() more than once on
    415  * its children. For example, the parent may measure each child once with
    416  * unspecified dimensions to find out how big they want to be, then call
    417  * measure() on them again with actual numbers if the sum of all the children's
    418  * unconstrained sizes is too big or too small.
    419  * </p>
    420  *
    421  * <p>
    422  * The measure pass uses two classes to communicate dimensions. The
    423  * {@link MeasureSpec} class is used by views to tell their parents how they
    424  * want to be measured and positioned. The base LayoutParams class just
    425  * describes how big the view wants to be for both width and height. For each
    426  * dimension, it can specify one of:
    427  * <ul>
    428  * <li> an exact number
    429  * <li>MATCH_PARENT, which means the view wants to be as big as its parent
    430  * (minus padding)
    431  * <li> WRAP_CONTENT, which means that the view wants to be just big enough to
    432  * enclose its content (plus padding).
    433  * </ul>
    434  * There are subclasses of LayoutParams for different subclasses of ViewGroup.
    435  * For example, AbsoluteLayout has its own subclass of LayoutParams which adds
    436  * an X and Y value.
    437  * </p>
    438  *
    439  * <p>
    440  * MeasureSpecs are used to push requirements down the tree from parent to
    441  * child. A MeasureSpec can be in one of three modes:
    442  * <ul>
    443  * <li>UNSPECIFIED: This is used by a parent to determine the desired dimension
    444  * of a child view. For example, a LinearLayout may call measure() on its child
    445  * with the height set to UNSPECIFIED and a width of EXACTLY 240 to find out how
    446  * tall the child view wants to be given a width of 240 pixels.
    447  * <li>EXACTLY: This is used by the parent to impose an exact size on the
    448  * child. The child must use this size, and guarantee that all of its
    449  * descendants will fit within this size.
    450  * <li>AT_MOST: This is used by the parent to impose a maximum size on the
    451  * child. The child must guarantee that it and all of its descendants will fit
    452  * within this size.
    453  * </ul>
    454  * </p>
    455  *
    456  * <p>
    457  * To initiate a layout, call {@link #requestLayout}. This method is typically
    458  * called by a view on itself when it believes that is can no longer fit within
    459  * its current bounds.
    460  * </p>
    461  *
    462  * <a name="Drawing"></a>
    463  * <h3>Drawing</h3>
    464  * <p>
    465  * Drawing is handled by walking the tree and recording the drawing commands of
    466  * any View that needs to update. After this, the drawing commands of the
    467  * entire tree are issued to screen, clipped to the newly damaged area.
    468  * </p>
    469  *
    470  * <p>
    471  * The tree is largely recorded and drawn in order, with parents drawn before
    472  * (i.e., behind) their children, with siblings drawn in the order they appear
    473  * in the tree. If you set a background drawable for a View, then the View will
    474  * draw it before calling back to its <code>onDraw()</code> method. The child
    475  * drawing order can be overridden with
    476  * {@link ViewGroup#setChildrenDrawingOrderEnabled(boolean) custom child drawing order}
    477  * in a ViewGroup, and with {@link #setZ(float)} custom Z values} set on Views.
    478  * </p>
    479  *
    480  * <p>
    481  * To force a view to draw, call {@link #invalidate()}.
    482  * </p>
    483  *
    484  * <a name="EventHandlingThreading"></a>
    485  * <h3>Event Handling and Threading</h3>
    486  * <p>
    487  * The basic cycle of a view is as follows:
    488  * <ol>
    489  * <li>An event comes in and is dispatched to the appropriate view. The view
    490  * handles the event and notifies any listeners.</li>
    491  * <li>If in the course of processing the event, the view's bounds may need
    492  * to be changed, the view will call {@link #requestLayout()}.</li>
    493  * <li>Similarly, if in the course of processing the event the view's appearance
    494  * may need to be changed, the view will call {@link #invalidate()}.</li>
    495  * <li>If either {@link #requestLayout()} or {@link #invalidate()} were called,
    496  * the framework will take care of measuring, laying out, and drawing the tree
    497  * as appropriate.</li>
    498  * </ol>
    499  * </p>
    500  *
    501  * <p><em>Note: The entire view tree is single threaded. You must always be on
    502  * the UI thread when calling any method on any view.</em>
    503  * If you are doing work on other threads and want to update the state of a view
    504  * from that thread, you should use a {@link Handler}.
    505  * </p>
    506  *
    507  * <a name="FocusHandling"></a>
    508  * <h3>Focus Handling</h3>
    509  * <p>
    510  * The framework will handle routine focus movement in response to user input.
    511  * This includes changing the focus as views are removed or hidden, or as new
    512  * views become available. Views indicate their willingness to take focus
    513  * through the {@link #isFocusable} method. To change whether a view can take
    514  * focus, call {@link #setFocusable(boolean)}.  When in touch mode (see notes below)
    515  * views indicate whether they still would like focus via {@link #isFocusableInTouchMode}
    516  * and can change this via {@link #setFocusableInTouchMode(boolean)}.
    517  * </p>
    518  * <p>
    519  * Focus movement is based on an algorithm which finds the nearest neighbor in a
    520  * given direction. In rare cases, the default algorithm may not match the
    521  * intended behavior of the developer. In these situations, you can provide
    522  * explicit overrides by using these XML attributes in the layout file:
    523  * <pre>
    524  * nextFocusDown
    525  * nextFocusLeft
    526  * nextFocusRight
    527  * nextFocusUp
    528  * </pre>
    529  * </p>
    530  *
    531  *
    532  * <p>
    533  * To get a particular view to take focus, call {@link #requestFocus()}.
    534  * </p>
    535  *
    536  * <a name="TouchMode"></a>
    537  * <h3>Touch Mode</h3>
    538  * <p>
    539  * When a user is navigating a user interface via directional keys such as a D-pad, it is
    540  * necessary to give focus to actionable items such as buttons so the user can see
    541  * what will take input.  If the device has touch capabilities, however, and the user
    542  * begins interacting with the interface by touching it, it is no longer necessary to
    543  * always highlight, or give focus to, a particular view.  This motivates a mode
    544  * for interaction named 'touch mode'.
    545  * </p>
    546  * <p>
    547  * For a touch capable device, once the user touches the screen, the device
    548  * will enter touch mode.  From this point onward, only views for which
    549  * {@link #isFocusableInTouchMode} is true will be focusable, such as text editing widgets.
    550  * Other views that are touchable, like buttons, will not take focus when touched; they will
    551  * only fire the on click listeners.
    552  * </p>
    553  * <p>
    554  * Any time a user hits a directional key, such as a D-pad direction, the view device will
    555  * exit touch mode, and find a view to take focus, so that the user may resume interacting
    556  * with the user interface without touching the screen again.
    557  * </p>
    558  * <p>
    559  * The touch mode state is maintained across {@link android.app.Activity}s.  Call
    560  * {@link #isInTouchMode} to see whether the device is currently in touch mode.
    561  * </p>
    562  *
    563  * <a name="Scrolling"></a>
    564  * <h3>Scrolling</h3>
    565  * <p>
    566  * The framework provides basic support for views that wish to internally
    567  * scroll their content. This includes keeping track of the X and Y scroll
    568  * offset as well as mechanisms for drawing scrollbars. See
    569  * {@link #scrollBy(int, int)}, {@link #scrollTo(int, int)}, and
    570  * {@link #awakenScrollBars()} for more details.
    571  * </p>
    572  *
    573  * <a name="Tags"></a>
    574  * <h3>Tags</h3>
    575  * <p>
    576  * Unlike IDs, tags are not used to identify views. Tags are essentially an
    577  * extra piece of information that can be associated with a view. They are most
    578  * often used as a convenience to store data related to views in the views
    579  * themselves rather than by putting them in a separate structure.
    580  * </p>
    581  * <p>
    582  * Tags may be specified with character sequence values in layout XML as either
    583  * a single tag using the {@link android.R.styleable#View_tag android:tag}
    584  * attribute or multiple tags using the {@code <tag>} child element:
    585  * <pre>
    586  *     &ltView ...
    587  *           android:tag="@string/mytag_value" /&gt;
    588  *     &ltView ...&gt;
    589  *         &lttag android:id="@+id/mytag"
    590  *              android:value="@string/mytag_value" /&gt;
    591  *     &lt/View>
    592  * </pre>
    593  * </p>
    594  * <p>
    595  * Tags may also be specified with arbitrary objects from code using
    596  * {@link #setTag(Object)} or {@link #setTag(int, Object)}.
    597  * </p>
    598  *
    599  * <a name="Themes"></a>
    600  * <h3>Themes</h3>
    601  * <p>
    602  * By default, Views are created using the theme of the Context object supplied
    603  * to their constructor; however, a different theme may be specified by using
    604  * the {@link android.R.styleable#View_theme android:theme} attribute in layout
    605  * XML or by passing a {@link ContextThemeWrapper} to the constructor from
    606  * code.
    607  * </p>
    608  * <p>
    609  * When the {@link android.R.styleable#View_theme android:theme} attribute is
    610  * used in XML, the specified theme is applied on top of the inflation
    611  * context's theme (see {@link LayoutInflater}) and used for the view itself as
    612  * well as any child elements.
    613  * </p>
    614  * <p>
    615  * In the following example, both views will be created using the Material dark
    616  * color scheme; however, because an overlay theme is used which only defines a
    617  * subset of attributes, the value of
    618  * {@link android.R.styleable#Theme_colorAccent android:colorAccent} defined on
    619  * the inflation context's theme (e.g. the Activity theme) will be preserved.
    620  * <pre>
    621  *     &ltLinearLayout
    622  *             ...
    623  *             android:theme="@android:theme/ThemeOverlay.Material.Dark"&gt;
    624  *         &ltView ...&gt;
    625  *     &lt/LinearLayout&gt;
    626  * </pre>
    627  * </p>
    628  *
    629  * <a name="Properties"></a>
    630  * <h3>Properties</h3>
    631  * <p>
    632  * The View class exposes an {@link #ALPHA} property, as well as several transform-related
    633  * properties, such as {@link #TRANSLATION_X} and {@link #TRANSLATION_Y}. These properties are
    634  * available both in the {@link Property} form as well as in similarly-named setter/getter
    635  * methods (such as {@link #setAlpha(float)} for {@link #ALPHA}). These properties can
    636  * be used to set persistent state associated with these rendering-related properties on the view.
    637  * The properties and methods can also be used in conjunction with
    638  * {@link android.animation.Animator Animator}-based animations, described more in the
    639  * <a href="#Animation">Animation</a> section.
    640  * </p>
    641  *
    642  * <a name="Animation"></a>
    643  * <h3>Animation</h3>
    644  * <p>
    645  * Starting with Android 3.0, the preferred way of animating views is to use the
    646  * {@link android.animation} package APIs. These {@link android.animation.Animator Animator}-based
    647  * classes change actual properties of the View object, such as {@link #setAlpha(float) alpha} and
    648  * {@link #setTranslationX(float) translationX}. This behavior is contrasted to that of the pre-3.0
    649  * {@link android.view.animation.Animation Animation}-based classes, which instead animate only
    650  * how the view is drawn on the display. In particular, the {@link ViewPropertyAnimator} class
    651  * makes animating these View properties particularly easy and efficient.
    652  * </p>
    653  * <p>
    654  * Alternatively, you can use the pre-3.0 animation classes to animate how Views are rendered.
    655  * You can attach an {@link Animation} object to a view using
    656  * {@link #setAnimation(Animation)} or
    657  * {@link #startAnimation(Animation)}. The animation can alter the scale,
    658  * rotation, translation and alpha of a view over time. If the animation is
    659  * attached to a view that has children, the animation will affect the entire
    660  * subtree rooted by that node. When an animation is started, the framework will
    661  * take care of redrawing the appropriate views until the animation completes.
    662  * </p>
    663  *
    664  * <a name="Security"></a>
    665  * <h3>Security</h3>
    666  * <p>
    667  * Sometimes it is essential that an application be able to verify that an action
    668  * is being performed with the full knowledge and consent of the user, such as
    669  * granting a permission request, making a purchase or clicking on an advertisement.
    670  * Unfortunately, a malicious application could try to spoof the user into
    671  * performing these actions, unaware, by concealing the intended purpose of the view.
    672  * As a remedy, the framework offers a touch filtering mechanism that can be used to
    673  * improve the security of views that provide access to sensitive functionality.
    674  * </p><p>
    675  * To enable touch filtering, call {@link #setFilterTouchesWhenObscured(boolean)} or set the
    676  * android:filterTouchesWhenObscured layout attribute to true.  When enabled, the framework
    677  * will discard touches that are received whenever the view's window is obscured by
    678  * another visible window.  As a result, the view will not receive touches whenever a
    679  * toast, dialog or other window appears above the view's window.
    680  * </p><p>
    681  * For more fine-grained control over security, consider overriding the
    682  * {@link #onFilterTouchEventForSecurity(MotionEvent)} method to implement your own
    683  * security policy. See also {@link MotionEvent#FLAG_WINDOW_IS_OBSCURED}.
    684  * </p>
    685  *
    686  * @attr ref android.R.styleable#View_alpha
    687  * @attr ref android.R.styleable#View_background
    688  * @attr ref android.R.styleable#View_clickable
    689  * @attr ref android.R.styleable#View_contentDescription
    690  * @attr ref android.R.styleable#View_drawingCacheQuality
    691  * @attr ref android.R.styleable#View_duplicateParentState
    692  * @attr ref android.R.styleable#View_id
    693  * @attr ref android.R.styleable#View_requiresFadingEdge
    694  * @attr ref android.R.styleable#View_fadeScrollbars
    695  * @attr ref android.R.styleable#View_fadingEdgeLength
    696  * @attr ref android.R.styleable#View_filterTouchesWhenObscured
    697  * @attr ref android.R.styleable#View_fitsSystemWindows
    698  * @attr ref android.R.styleable#View_isScrollContainer
    699  * @attr ref android.R.styleable#View_focusable
    700  * @attr ref android.R.styleable#View_focusableInTouchMode
    701  * @attr ref android.R.styleable#View_hapticFeedbackEnabled
    702  * @attr ref android.R.styleable#View_keepScreenOn
    703  * @attr ref android.R.styleable#View_layerType
    704  * @attr ref android.R.styleable#View_layoutDirection
    705  * @attr ref android.R.styleable#View_longClickable
    706  * @attr ref android.R.styleable#View_minHeight
    707  * @attr ref android.R.styleable#View_minWidth
    708  * @attr ref android.R.styleable#View_nextFocusDown
    709  * @attr ref android.R.styleable#View_nextFocusLeft
    710  * @attr ref android.R.styleable#View_nextFocusRight
    711  * @attr ref android.R.styleable#View_nextFocusUp
    712  * @attr ref android.R.styleable#View_onClick
    713  * @attr ref android.R.styleable#View_padding
    714  * @attr ref android.R.styleable#View_paddingBottom
    715  * @attr ref android.R.styleable#View_paddingLeft
    716  * @attr ref android.R.styleable#View_paddingRight
    717  * @attr ref android.R.styleable#View_paddingTop
    718  * @attr ref android.R.styleable#View_paddingStart
    719  * @attr ref android.R.styleable#View_paddingEnd
    720  * @attr ref android.R.styleable#View_saveEnabled
    721  * @attr ref android.R.styleable#View_rotation
    722  * @attr ref android.R.styleable#View_rotationX
    723  * @attr ref android.R.styleable#View_rotationY
    724  * @attr ref android.R.styleable#View_scaleX
    725  * @attr ref android.R.styleable#View_scaleY
    726  * @attr ref android.R.styleable#View_scrollX
    727  * @attr ref android.R.styleable#View_scrollY
    728  * @attr ref android.R.styleable#View_scrollbarSize
    729  * @attr ref android.R.styleable#View_scrollbarStyle
    730  * @attr ref android.R.styleable#View_scrollbars
    731  * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade
    732  * @attr ref android.R.styleable#View_scrollbarFadeDuration
    733  * @attr ref android.R.styleable#View_scrollbarTrackHorizontal
    734  * @attr ref android.R.styleable#View_scrollbarThumbHorizontal
    735  * @attr ref android.R.styleable#View_scrollbarThumbVertical
    736  * @attr ref android.R.styleable#View_scrollbarTrackVertical
    737  * @attr ref android.R.styleable#View_scrollbarAlwaysDrawHorizontalTrack
    738  * @attr ref android.R.styleable#View_scrollbarAlwaysDrawVerticalTrack
    739  * @attr ref android.R.styleable#View_stateListAnimator
    740  * @attr ref android.R.styleable#View_transitionName
    741  * @attr ref android.R.styleable#View_soundEffectsEnabled
    742  * @attr ref android.R.styleable#View_tag
    743  * @attr ref android.R.styleable#View_textAlignment
    744  * @attr ref android.R.styleable#View_textDirection
    745  * @attr ref android.R.styleable#View_transformPivotX
    746  * @attr ref android.R.styleable#View_transformPivotY
    747  * @attr ref android.R.styleable#View_translationX
    748  * @attr ref android.R.styleable#View_translationY
    749  * @attr ref android.R.styleable#View_translationZ
    750  * @attr ref android.R.styleable#View_visibility
    751  * @attr ref android.R.styleable#View_theme
    752  *
    753  * @see android.view.ViewGroup
    754  */
    755 @UiThread
    756 public class View implements Drawable.Callback, KeyEvent.Callback,
    757         AccessibilityEventSource {
    758     private static final boolean DBG = false;
    759 
    760     /**
    761      * The logging tag used by this class with android.util.Log.
    762      */
    763     protected static final String VIEW_LOG_TAG = "View";
    764 
    765     /**
    766      * When set to true, apps will draw debugging information about their layouts.
    767      *
    768      * @hide
    769      */
    770     public static final String DEBUG_LAYOUT_PROPERTY = "debug.layout";
    771 
    772     /**
    773      * When set to true, this view will save its attribute data.
    774      *
    775      * @hide
    776      */
    777     public static boolean mDebugViewAttributes = false;
    778 
    779     /**
    780      * Used to mark a View that has no ID.
    781      */
    782     public static final int NO_ID = -1;
    783 
    784     /**
    785      * Signals that compatibility booleans have been initialized according to
    786      * target SDK versions.
    787      */
    788     private static boolean sCompatibilityDone = false;
    789 
    790     /**
    791      * Use the old (broken) way of building MeasureSpecs.
    792      */
    793     private static boolean sUseBrokenMakeMeasureSpec = false;
    794 
    795     /**
    796      * Always return a size of 0 for MeasureSpec values with a mode of UNSPECIFIED
    797      */
    798     static boolean sUseZeroUnspecifiedMeasureSpec = false;
    799 
    800     /**
    801      * Ignore any optimizations using the measure cache.
    802      */
    803     private static boolean sIgnoreMeasureCache = false;
    804 
    805     /**
    806      * Ignore an optimization that skips unnecessary EXACTLY layout passes.
    807      */
    808     private static boolean sAlwaysRemeasureExactly = false;
    809 
    810     /**
    811      * Relax constraints around whether setLayoutParams() must be called after
    812      * modifying the layout params.
    813      */
    814     private static boolean sLayoutParamsAlwaysChanged = false;
    815 
    816     /**
    817      * Allow setForeground/setBackground to be called (and ignored) on a textureview,
    818      * without throwing
    819      */
    820     static boolean sTextureViewIgnoresDrawableSetters = false;
    821 
    822     /**
    823      * Prior to N, some ViewGroups would not convert LayoutParams properly even though both extend
    824      * MarginLayoutParams. For instance, converting LinearLayout.LayoutParams to
    825      * RelativeLayout.LayoutParams would lose margin information. This is fixed on N but target API
    826      * check is implemented for backwards compatibility.
    827      *
    828      * {@hide}
    829      */
    830     protected static boolean sPreserveMarginParamsInLayoutParamConversion;
    831 
    832     /**
    833      * Prior to N, when drag enters into child of a view that has already received an
    834      * ACTION_DRAG_ENTERED event, the parent doesn't get a ACTION_DRAG_EXITED event.
    835      * ACTION_DRAG_LOCATION and ACTION_DROP were delivered to the parent of a view that returned
    836      * false from its event handler for these events.
    837      * Starting from N, the parent will get ACTION_DRAG_EXITED event before the child gets its
    838      * ACTION_DRAG_ENTERED. ACTION_DRAG_LOCATION and ACTION_DROP are never propagated to the parent.
    839      * sCascadedDragDrop is true for pre-N apps for backwards compatibility implementation.
    840      */
    841     static boolean sCascadedDragDrop;
    842 
    843     /**
    844      * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when
    845      * calling setFlags.
    846      */
    847     private static final int NOT_FOCUSABLE = 0x00000000;
    848 
    849     /**
    850      * This view wants keystrokes. Use with TAKES_FOCUS_MASK when calling
    851      * setFlags.
    852      */
    853     private static final int FOCUSABLE = 0x00000001;
    854 
    855     /**
    856      * Mask for use with setFlags indicating bits used for focus.
    857      */
    858     private static final int FOCUSABLE_MASK = 0x00000001;
    859 
    860     /**
    861      * This view will adjust its padding to fit sytem windows (e.g. status bar)
    862      */
    863     private static final int FITS_SYSTEM_WINDOWS = 0x00000002;
    864 
    865     /** @hide */
    866     @IntDef({VISIBLE, INVISIBLE, GONE})
    867     @Retention(RetentionPolicy.SOURCE)
    868     public @interface Visibility {}
    869 
    870     /**
    871      * This view is visible.
    872      * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code
    873      * android:visibility}.
    874      */
    875     public static final int VISIBLE = 0x00000000;
    876 
    877     /**
    878      * This view is invisible, but it still takes up space for layout purposes.
    879      * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code
    880      * android:visibility}.
    881      */
    882     public static final int INVISIBLE = 0x00000004;
    883 
    884     /**
    885      * This view is invisible, and it doesn't take any space for layout
    886      * purposes. Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code
    887      * android:visibility}.
    888      */
    889     public static final int GONE = 0x00000008;
    890 
    891     /**
    892      * Mask for use with setFlags indicating bits used for visibility.
    893      * {@hide}
    894      */
    895     static final int VISIBILITY_MASK = 0x0000000C;
    896 
    897     private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE};
    898 
    899     /**
    900      * This view is enabled. Interpretation varies by subclass.
    901      * Use with ENABLED_MASK when calling setFlags.
    902      * {@hide}
    903      */
    904     static final int ENABLED = 0x00000000;
    905 
    906     /**
    907      * This view is disabled. Interpretation varies by subclass.
    908      * Use with ENABLED_MASK when calling setFlags.
    909      * {@hide}
    910      */
    911     static final int DISABLED = 0x00000020;
    912 
    913    /**
    914     * Mask for use with setFlags indicating bits used for indicating whether
    915     * this view is enabled
    916     * {@hide}
    917     */
    918     static final int ENABLED_MASK = 0x00000020;
    919 
    920     /**
    921      * This view won't draw. {@link #onDraw(android.graphics.Canvas)} won't be
    922      * called and further optimizations will be performed. It is okay to have
    923      * this flag set and a background. Use with DRAW_MASK when calling setFlags.
    924      * {@hide}
    925      */
    926     static final int WILL_NOT_DRAW = 0x00000080;
    927 
    928     /**
    929      * Mask for use with setFlags indicating bits used for indicating whether
    930      * this view is will draw
    931      * {@hide}
    932      */
    933     static final int DRAW_MASK = 0x00000080;
    934 
    935     /**
    936      * <p>This view doesn't show scrollbars.</p>
    937      * {@hide}
    938      */
    939     static final int SCROLLBARS_NONE = 0x00000000;
    940 
    941     /**
    942      * <p>This view shows horizontal scrollbars.</p>
    943      * {@hide}
    944      */
    945     static final int SCROLLBARS_HORIZONTAL = 0x00000100;
    946 
    947     /**
    948      * <p>This view shows vertical scrollbars.</p>
    949      * {@hide}
    950      */
    951     static final int SCROLLBARS_VERTICAL = 0x00000200;
    952 
    953     /**
    954      * <p>Mask for use with setFlags indicating bits used for indicating which
    955      * scrollbars are enabled.</p>
    956      * {@hide}
    957      */
    958     static final int SCROLLBARS_MASK = 0x00000300;
    959 
    960     /**
    961      * Indicates that the view should filter touches when its window is obscured.
    962      * Refer to the class comments for more information about this security feature.
    963      * {@hide}
    964      */
    965     static final int FILTER_TOUCHES_WHEN_OBSCURED = 0x00000400;
    966 
    967     /**
    968      * Set for framework elements that use FITS_SYSTEM_WINDOWS, to indicate
    969      * that they are optional and should be skipped if the window has
    970      * requested system UI flags that ignore those insets for layout.
    971      */
    972     static final int OPTIONAL_FITS_SYSTEM_WINDOWS = 0x00000800;
    973 
    974     /**
    975      * <p>This view doesn't show fading edges.</p>
    976      * {@hide}
    977      */
    978     static final int FADING_EDGE_NONE = 0x00000000;
    979 
    980     /**
    981      * <p>This view shows horizontal fading edges.</p>
    982      * {@hide}
    983      */
    984     static final int FADING_EDGE_HORIZONTAL = 0x00001000;
    985 
    986     /**
    987      * <p>This view shows vertical fading edges.</p>
    988      * {@hide}
    989      */
    990     static final int FADING_EDGE_VERTICAL = 0x00002000;
    991 
    992     /**
    993      * <p>Mask for use with setFlags indicating bits used for indicating which
    994      * fading edges are enabled.</p>
    995      * {@hide}
    996      */
    997     static final int FADING_EDGE_MASK = 0x00003000;
    998 
    999     /**
   1000      * <p>Indicates this view can be clicked. When clickable, a View reacts
   1001      * to clicks by notifying the OnClickListener.<p>
   1002      * {@hide}
   1003      */
   1004     static final int CLICKABLE = 0x00004000;
   1005 
   1006     /**
   1007      * <p>Indicates this view is caching its drawing into a bitmap.</p>
   1008      * {@hide}
   1009      */
   1010     static final int DRAWING_CACHE_ENABLED = 0x00008000;
   1011 
   1012     /**
   1013      * <p>Indicates that no icicle should be saved for this view.<p>
   1014      * {@hide}
   1015      */
   1016     static final int SAVE_DISABLED = 0x000010000;
   1017 
   1018     /**
   1019      * <p>Mask for use with setFlags indicating bits used for the saveEnabled
   1020      * property.</p>
   1021      * {@hide}
   1022      */
   1023     static final int SAVE_DISABLED_MASK = 0x000010000;
   1024 
   1025     /**
   1026      * <p>Indicates that no drawing cache should ever be created for this view.<p>
   1027      * {@hide}
   1028      */
   1029     static final int WILL_NOT_CACHE_DRAWING = 0x000020000;
   1030 
   1031     /**
   1032      * <p>Indicates this view can take / keep focus when int touch mode.</p>
   1033      * {@hide}
   1034      */
   1035     static final int FOCUSABLE_IN_TOUCH_MODE = 0x00040000;
   1036 
   1037     /** @hide */
   1038     @Retention(RetentionPolicy.SOURCE)
   1039     @IntDef({DRAWING_CACHE_QUALITY_LOW, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_AUTO})
   1040     public @interface DrawingCacheQuality {}
   1041 
   1042     /**
   1043      * <p>Enables low quality mode for the drawing cache.</p>
   1044      */
   1045     public static final int DRAWING_CACHE_QUALITY_LOW = 0x00080000;
   1046 
   1047     /**
   1048      * <p>Enables high quality mode for the drawing cache.</p>
   1049      */
   1050     public static final int DRAWING_CACHE_QUALITY_HIGH = 0x00100000;
   1051 
   1052     /**
   1053      * <p>Enables automatic quality mode for the drawing cache.</p>
   1054      */
   1055     public static final int DRAWING_CACHE_QUALITY_AUTO = 0x00000000;
   1056 
   1057     private static final int[] DRAWING_CACHE_QUALITY_FLAGS = {
   1058             DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_LOW, DRAWING_CACHE_QUALITY_HIGH
   1059     };
   1060 
   1061     /**
   1062      * <p>Mask for use with setFlags indicating bits used for the cache
   1063      * quality property.</p>
   1064      * {@hide}
   1065      */
   1066     static final int DRAWING_CACHE_QUALITY_MASK = 0x00180000;
   1067 
   1068     /**
   1069      * <p>
   1070      * Indicates this view can be long clicked. When long clickable, a View
   1071      * reacts to long clicks by notifying the OnLongClickListener or showing a
   1072      * context menu.
   1073      * </p>
   1074      * {@hide}
   1075      */
   1076     static final int LONG_CLICKABLE = 0x00200000;
   1077 
   1078     /**
   1079      * <p>Indicates that this view gets its drawable states from its direct parent
   1080      * and ignores its original internal states.</p>
   1081      *
   1082      * @hide
   1083      */
   1084     static final int DUPLICATE_PARENT_STATE = 0x00400000;
   1085 
   1086     /**
   1087      * <p>
   1088      * Indicates this view can be context clicked. When context clickable, a View reacts to a
   1089      * context click (e.g. a primary stylus button press or right mouse click) by notifying the
   1090      * OnContextClickListener.
   1091      * </p>
   1092      * {@hide}
   1093      */
   1094     static final int CONTEXT_CLICKABLE = 0x00800000;
   1095 
   1096 
   1097     /** @hide */
   1098     @IntDef({
   1099         SCROLLBARS_INSIDE_OVERLAY,
   1100         SCROLLBARS_INSIDE_INSET,
   1101         SCROLLBARS_OUTSIDE_OVERLAY,
   1102         SCROLLBARS_OUTSIDE_INSET
   1103     })
   1104     @Retention(RetentionPolicy.SOURCE)
   1105     public @interface ScrollBarStyle {}
   1106 
   1107     /**
   1108      * The scrollbar style to display the scrollbars inside the content area,
   1109      * without increasing the padding. The scrollbars will be overlaid with
   1110      * translucency on the view's content.
   1111      */
   1112     public static final int SCROLLBARS_INSIDE_OVERLAY = 0;
   1113 
   1114     /**
   1115      * The scrollbar style to display the scrollbars inside the padded area,
   1116      * increasing the padding of the view. The scrollbars will not overlap the
   1117      * content area of the view.
   1118      */
   1119     public static final int SCROLLBARS_INSIDE_INSET = 0x01000000;
   1120 
   1121     /**
   1122      * The scrollbar style to display the scrollbars at the edge of the view,
   1123      * without increasing the padding. The scrollbars will be overlaid with
   1124      * translucency.
   1125      */
   1126     public static final int SCROLLBARS_OUTSIDE_OVERLAY = 0x02000000;
   1127 
   1128     /**
   1129      * The scrollbar style to display the scrollbars at the edge of the view,
   1130      * increasing the padding of the view. The scrollbars will only overlap the
   1131      * background, if any.
   1132      */
   1133     public static final int SCROLLBARS_OUTSIDE_INSET = 0x03000000;
   1134 
   1135     /**
   1136      * Mask to check if the scrollbar style is overlay or inset.
   1137      * {@hide}
   1138      */
   1139     static final int SCROLLBARS_INSET_MASK = 0x01000000;
   1140 
   1141     /**
   1142      * Mask to check if the scrollbar style is inside or outside.
   1143      * {@hide}
   1144      */
   1145     static final int SCROLLBARS_OUTSIDE_MASK = 0x02000000;
   1146 
   1147     /**
   1148      * Mask for scrollbar style.
   1149      * {@hide}
   1150      */
   1151     static final int SCROLLBARS_STYLE_MASK = 0x03000000;
   1152 
   1153     /**
   1154      * View flag indicating that the screen should remain on while the
   1155      * window containing this view is visible to the user.  This effectively
   1156      * takes care of automatically setting the WindowManager's
   1157      * {@link WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON}.
   1158      */
   1159     public static final int KEEP_SCREEN_ON = 0x04000000;
   1160 
   1161     /**
   1162      * View flag indicating whether this view should have sound effects enabled
   1163      * for events such as clicking and touching.
   1164      */
   1165     public static final int SOUND_EFFECTS_ENABLED = 0x08000000;
   1166 
   1167     /**
   1168      * View flag indicating whether this view should have haptic feedback
   1169      * enabled for events such as long presses.
   1170      */
   1171     public static final int HAPTIC_FEEDBACK_ENABLED = 0x10000000;
   1172 
   1173     /**
   1174      * <p>Indicates that the view hierarchy should stop saving state when
   1175      * it reaches this view.  If state saving is initiated immediately at
   1176      * the view, it will be allowed.
   1177      * {@hide}
   1178      */
   1179     static final int PARENT_SAVE_DISABLED = 0x20000000;
   1180 
   1181     /**
   1182      * <p>Mask for use with setFlags indicating bits used for PARENT_SAVE_DISABLED.</p>
   1183      * {@hide}
   1184      */
   1185     static final int PARENT_SAVE_DISABLED_MASK = 0x20000000;
   1186 
   1187     /** @hide */
   1188     @IntDef(flag = true,
   1189             value = {
   1190                 FOCUSABLES_ALL,
   1191                 FOCUSABLES_TOUCH_MODE
   1192             })
   1193     @Retention(RetentionPolicy.SOURCE)
   1194     public @interface FocusableMode {}
   1195 
   1196     /**
   1197      * View flag indicating whether {@link #addFocusables(ArrayList, int, int)}
   1198      * should add all focusable Views regardless if they are focusable in touch mode.
   1199      */
   1200     public static final int FOCUSABLES_ALL = 0x00000000;
   1201 
   1202     /**
   1203      * View flag indicating whether {@link #addFocusables(ArrayList, int, int)}
   1204      * should add only Views focusable in touch mode.
   1205      */
   1206     public static final int FOCUSABLES_TOUCH_MODE = 0x00000001;
   1207 
   1208     /** @hide */
   1209     @IntDef({
   1210             FOCUS_BACKWARD,
   1211             FOCUS_FORWARD,
   1212             FOCUS_LEFT,
   1213             FOCUS_UP,
   1214             FOCUS_RIGHT,
   1215             FOCUS_DOWN
   1216     })
   1217     @Retention(RetentionPolicy.SOURCE)
   1218     public @interface FocusDirection {}
   1219 
   1220     /** @hide */
   1221     @IntDef({
   1222             FOCUS_LEFT,
   1223             FOCUS_UP,
   1224             FOCUS_RIGHT,
   1225             FOCUS_DOWN
   1226     })
   1227     @Retention(RetentionPolicy.SOURCE)
   1228     public @interface FocusRealDirection {} // Like @FocusDirection, but without forward/backward
   1229 
   1230     /**
   1231      * Use with {@link #focusSearch(int)}. Move focus to the previous selectable
   1232      * item.
   1233      */
   1234     public static final int FOCUS_BACKWARD = 0x00000001;
   1235 
   1236     /**
   1237      * Use with {@link #focusSearch(int)}. Move focus to the next selectable
   1238      * item.
   1239      */
   1240     public static final int FOCUS_FORWARD = 0x00000002;
   1241 
   1242     /**
   1243      * Use with {@link #focusSearch(int)}. Move focus to the left.
   1244      */
   1245     public static final int FOCUS_LEFT = 0x00000011;
   1246 
   1247     /**
   1248      * Use with {@link #focusSearch(int)}. Move focus up.
   1249      */
   1250     public static final int FOCUS_UP = 0x00000021;
   1251 
   1252     /**
   1253      * Use with {@link #focusSearch(int)}. Move focus to the right.
   1254      */
   1255     public static final int FOCUS_RIGHT = 0x00000042;
   1256 
   1257     /**
   1258      * Use with {@link #focusSearch(int)}. Move focus down.
   1259      */
   1260     public static final int FOCUS_DOWN = 0x00000082;
   1261 
   1262     /**
   1263      * Bits of {@link #getMeasuredWidthAndState()} and
   1264      * {@link #getMeasuredWidthAndState()} that provide the actual measured size.
   1265      */
   1266     public static final int MEASURED_SIZE_MASK = 0x00ffffff;
   1267 
   1268     /**
   1269      * Bits of {@link #getMeasuredWidthAndState()} and
   1270      * {@link #getMeasuredWidthAndState()} that provide the additional state bits.
   1271      */
   1272     public static final int MEASURED_STATE_MASK = 0xff000000;
   1273 
   1274     /**
   1275      * Bit shift of {@link #MEASURED_STATE_MASK} to get to the height bits
   1276      * for functions that combine both width and height into a single int,
   1277      * such as {@link #getMeasuredState()} and the childState argument of
   1278      * {@link #resolveSizeAndState(int, int, int)}.
   1279      */
   1280     public static final int MEASURED_HEIGHT_STATE_SHIFT = 16;
   1281 
   1282     /**
   1283      * Bit of {@link #getMeasuredWidthAndState()} and
   1284      * {@link #getMeasuredWidthAndState()} that indicates the measured size
   1285      * is smaller that the space the view would like to have.
   1286      */
   1287     public static final int MEASURED_STATE_TOO_SMALL = 0x01000000;
   1288 
   1289     /**
   1290      * Base View state sets
   1291      */
   1292     // Singles
   1293     /**
   1294      * Indicates the view has no states set. States are used with
   1295      * {@link android.graphics.drawable.Drawable} to change the drawing of the
   1296      * view depending on its state.
   1297      *
   1298      * @see android.graphics.drawable.Drawable
   1299      * @see #getDrawableState()
   1300      */
   1301     protected static final int[] EMPTY_STATE_SET;
   1302     /**
   1303      * Indicates the view is enabled. States are used with
   1304      * {@link android.graphics.drawable.Drawable} to change the drawing of the
   1305      * view depending on its state.
   1306      *
   1307      * @see android.graphics.drawable.Drawable
   1308      * @see #getDrawableState()
   1309      */
   1310     protected static final int[] ENABLED_STATE_SET;
   1311     /**
   1312      * Indicates the view is focused. States are used with
   1313      * {@link android.graphics.drawable.Drawable} to change the drawing of the
   1314      * view depending on its state.
   1315      *
   1316      * @see android.graphics.drawable.Drawable
   1317      * @see #getDrawableState()
   1318      */
   1319     protected static final int[] FOCUSED_STATE_SET;
   1320     /**
   1321      * Indicates the view is selected. States are used with
   1322      * {@link android.graphics.drawable.Drawable} to change the drawing of the
   1323      * view depending on its state.
   1324      *
   1325      * @see android.graphics.drawable.Drawable
   1326      * @see #getDrawableState()
   1327      */
   1328     protected static final int[] SELECTED_STATE_SET;
   1329     /**
   1330      * Indicates the view is pressed. States are used with
   1331      * {@link android.graphics.drawable.Drawable} to change the drawing of the
   1332      * view depending on its state.
   1333      *
   1334      * @see android.graphics.drawable.Drawable
   1335      * @see #getDrawableState()
   1336      */
   1337     protected static final int[] PRESSED_STATE_SET;
   1338     /**
   1339      * Indicates the view's window has focus. States are used with
   1340      * {@link android.graphics.drawable.Drawable} to change the drawing of the
   1341      * view depending on its state.
   1342      *
   1343      * @see android.graphics.drawable.Drawable
   1344      * @see #getDrawableState()
   1345      */
   1346     protected static final int[] WINDOW_FOCUSED_STATE_SET;
   1347     // Doubles
   1348     /**
   1349      * Indicates the view is enabled and has the focus.
   1350      *
   1351      * @see #ENABLED_STATE_SET
   1352      * @see #FOCUSED_STATE_SET
   1353      */
   1354     protected static final int[] ENABLED_FOCUSED_STATE_SET;
   1355     /**
   1356      * Indicates the view is enabled and selected.
   1357      *
   1358      * @see #ENABLED_STATE_SET
   1359      * @see #SELECTED_STATE_SET
   1360      */
   1361     protected static final int[] ENABLED_SELECTED_STATE_SET;
   1362     /**
   1363      * Indicates the view is enabled and that its window has focus.
   1364      *
   1365      * @see #ENABLED_STATE_SET
   1366      * @see #WINDOW_FOCUSED_STATE_SET
   1367      */
   1368     protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET;
   1369     /**
   1370      * Indicates the view is focused and selected.
   1371      *
   1372      * @see #FOCUSED_STATE_SET
   1373      * @see #SELECTED_STATE_SET
   1374      */
   1375     protected static final int[] FOCUSED_SELECTED_STATE_SET;
   1376     /**
   1377      * Indicates the view has the focus and that its window has the focus.
   1378      *
   1379      * @see #FOCUSED_STATE_SET
   1380      * @see #WINDOW_FOCUSED_STATE_SET
   1381      */
   1382     protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET;
   1383     /**
   1384      * Indicates the view is selected and that its window has the focus.
   1385      *
   1386      * @see #SELECTED_STATE_SET
   1387      * @see #WINDOW_FOCUSED_STATE_SET
   1388      */
   1389     protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET;
   1390     // Triples
   1391     /**
   1392      * Indicates the view is enabled, focused and selected.
   1393      *
   1394      * @see #ENABLED_STATE_SET
   1395      * @see #FOCUSED_STATE_SET
   1396      * @see #SELECTED_STATE_SET
   1397      */
   1398     protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET;
   1399     /**
   1400      * Indicates the view is enabled, focused and its window has the focus.
   1401      *
   1402      * @see #ENABLED_STATE_SET
   1403      * @see #FOCUSED_STATE_SET
   1404      * @see #WINDOW_FOCUSED_STATE_SET
   1405      */
   1406     protected static final int[] ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET;
   1407     /**
   1408      * Indicates the view is enabled, selected and its window has the focus.
   1409      *
   1410      * @see #ENABLED_STATE_SET
   1411      * @see #SELECTED_STATE_SET
   1412      * @see #WINDOW_FOCUSED_STATE_SET
   1413      */
   1414     protected static final int[] ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET;
   1415     /**
   1416      * Indicates the view is focused, selected and its window has the focus.
   1417      *
   1418      * @see #FOCUSED_STATE_SET
   1419      * @see #SELECTED_STATE_SET
   1420      * @see #WINDOW_FOCUSED_STATE_SET
   1421      */
   1422     protected static final int[] FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
   1423     /**
   1424      * Indicates the view is enabled, focused, selected and its window
   1425      * has the focus.
   1426      *
   1427      * @see #ENABLED_STATE_SET
   1428      * @see #FOCUSED_STATE_SET
   1429      * @see #SELECTED_STATE_SET
   1430      * @see #WINDOW_FOCUSED_STATE_SET
   1431      */
   1432     protected static final int[] ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
   1433     /**
   1434      * Indicates the view is pressed and its window has the focus.
   1435      *
   1436      * @see #PRESSED_STATE_SET
   1437      * @see #WINDOW_FOCUSED_STATE_SET
   1438      */
   1439     protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET;
   1440     /**
   1441      * Indicates the view is pressed and selected.
   1442      *
   1443      * @see #PRESSED_STATE_SET
   1444      * @see #SELECTED_STATE_SET
   1445      */
   1446     protected static final int[] PRESSED_SELECTED_STATE_SET;
   1447     /**
   1448      * Indicates the view is pressed, selected and its window has the focus.
   1449      *
   1450      * @see #PRESSED_STATE_SET
   1451      * @see #SELECTED_STATE_SET
   1452      * @see #WINDOW_FOCUSED_STATE_SET
   1453      */
   1454     protected static final int[] PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
   1455     /**
   1456      * Indicates the view is pressed and focused.
   1457      *
   1458      * @see #PRESSED_STATE_SET
   1459      * @see #FOCUSED_STATE_SET
   1460      */
   1461     protected static final int[] PRESSED_FOCUSED_STATE_SET;
   1462     /**
   1463      * Indicates the view is pressed, focused and its window has the focus.
   1464      *
   1465      * @see #PRESSED_STATE_SET
   1466      * @see #FOCUSED_STATE_SET
   1467      * @see #WINDOW_FOCUSED_STATE_SET
   1468      */
   1469     protected static final int[] PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET;
   1470     /**
   1471      * Indicates the view is pressed, focused and selected.
   1472      *
   1473      * @see #PRESSED_STATE_SET
   1474      * @see #SELECTED_STATE_SET
   1475      * @see #FOCUSED_STATE_SET
   1476      */
   1477     protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET;
   1478     /**
   1479      * Indicates the view is pressed, focused, selected and its window has the focus.
   1480      *
   1481      * @see #PRESSED_STATE_SET
   1482      * @see #FOCUSED_STATE_SET
   1483      * @see #SELECTED_STATE_SET
   1484      * @see #WINDOW_FOCUSED_STATE_SET
   1485      */
   1486     protected static final int[] PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
   1487     /**
   1488      * Indicates the view is pressed and enabled.
   1489      *
   1490      * @see #PRESSED_STATE_SET
   1491      * @see #ENABLED_STATE_SET
   1492      */
   1493     protected static final int[] PRESSED_ENABLED_STATE_SET;
   1494     /**
   1495      * Indicates the view is pressed, enabled and its window has the focus.
   1496      *
   1497      * @see #PRESSED_STATE_SET
   1498      * @see #ENABLED_STATE_SET
   1499      * @see #WINDOW_FOCUSED_STATE_SET
   1500      */
   1501     protected static final int[] PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET;
   1502     /**
   1503      * Indicates the view is pressed, enabled and selected.
   1504      *
   1505      * @see #PRESSED_STATE_SET
   1506      * @see #ENABLED_STATE_SET
   1507      * @see #SELECTED_STATE_SET
   1508      */
   1509     protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET;
   1510     /**
   1511      * Indicates the view is pressed, enabled, selected and its window has the
   1512      * focus.
   1513      *
   1514      * @see #PRESSED_STATE_SET
   1515      * @see #ENABLED_STATE_SET
   1516      * @see #SELECTED_STATE_SET
   1517      * @see #WINDOW_FOCUSED_STATE_SET
   1518      */
   1519     protected static final int[] PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET;
   1520     /**
   1521      * Indicates the view is pressed, enabled and focused.
   1522      *
   1523      * @see #PRESSED_STATE_SET
   1524      * @see #ENABLED_STATE_SET
   1525      * @see #FOCUSED_STATE_SET
   1526      */
   1527     protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET;
   1528     /**
   1529      * Indicates the view is pressed, enabled, focused and its window has the
   1530      * focus.
   1531      *
   1532      * @see #PRESSED_STATE_SET
   1533      * @see #ENABLED_STATE_SET
   1534      * @see #FOCUSED_STATE_SET
   1535      * @see #WINDOW_FOCUSED_STATE_SET
   1536      */
   1537     protected static final int[] PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET;
   1538     /**
   1539      * Indicates the view is pressed, enabled, focused and selected.
   1540      *
   1541      * @see #PRESSED_STATE_SET
   1542      * @see #ENABLED_STATE_SET
   1543      * @see #SELECTED_STATE_SET
   1544      * @see #FOCUSED_STATE_SET
   1545      */
   1546     protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET;
   1547     /**
   1548      * Indicates the view is pressed, enabled, focused, selected and its window
   1549      * has the focus.
   1550      *
   1551      * @see #PRESSED_STATE_SET
   1552      * @see #ENABLED_STATE_SET
   1553      * @see #SELECTED_STATE_SET
   1554      * @see #FOCUSED_STATE_SET
   1555      * @see #WINDOW_FOCUSED_STATE_SET
   1556      */
   1557     protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
   1558 
   1559     static {
   1560         EMPTY_STATE_SET = StateSet.get(0);
   1561 
   1562         WINDOW_FOCUSED_STATE_SET = StateSet.get(StateSet.VIEW_STATE_WINDOW_FOCUSED);
   1563 
   1564         SELECTED_STATE_SET = StateSet.get(StateSet.VIEW_STATE_SELECTED);
   1565         SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1566                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED);
   1567 
   1568         FOCUSED_STATE_SET = StateSet.get(StateSet.VIEW_STATE_FOCUSED);
   1569         FOCUSED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1570                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_FOCUSED);
   1571         FOCUSED_SELECTED_STATE_SET = StateSet.get(
   1572                 StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_FOCUSED);
   1573         FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1574                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
   1575                         | StateSet.VIEW_STATE_FOCUSED);
   1576 
   1577         ENABLED_STATE_SET = StateSet.get(StateSet.VIEW_STATE_ENABLED);
   1578         ENABLED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1579                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_ENABLED);
   1580         ENABLED_SELECTED_STATE_SET = StateSet.get(
   1581                 StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_ENABLED);
   1582         ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1583                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
   1584                         | StateSet.VIEW_STATE_ENABLED);
   1585         ENABLED_FOCUSED_STATE_SET = StateSet.get(
   1586                 StateSet.VIEW_STATE_FOCUSED | StateSet.VIEW_STATE_ENABLED);
   1587         ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1588                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_FOCUSED
   1589                         | StateSet.VIEW_STATE_ENABLED);
   1590         ENABLED_FOCUSED_SELECTED_STATE_SET = StateSet.get(
   1591                 StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_FOCUSED
   1592                         | StateSet.VIEW_STATE_ENABLED);
   1593         ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1594                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
   1595                         | StateSet.VIEW_STATE_FOCUSED| StateSet.VIEW_STATE_ENABLED);
   1596 
   1597         PRESSED_STATE_SET = StateSet.get(StateSet.VIEW_STATE_PRESSED);
   1598         PRESSED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1599                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_PRESSED);
   1600         PRESSED_SELECTED_STATE_SET = StateSet.get(
   1601                 StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_PRESSED);
   1602         PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1603                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
   1604                         | StateSet.VIEW_STATE_PRESSED);
   1605         PRESSED_FOCUSED_STATE_SET = StateSet.get(
   1606                 StateSet.VIEW_STATE_FOCUSED | StateSet.VIEW_STATE_PRESSED);
   1607         PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1608                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_FOCUSED
   1609                         | StateSet.VIEW_STATE_PRESSED);
   1610         PRESSED_FOCUSED_SELECTED_STATE_SET = StateSet.get(
   1611                 StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_FOCUSED
   1612                         | StateSet.VIEW_STATE_PRESSED);
   1613         PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1614                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
   1615                         | StateSet.VIEW_STATE_FOCUSED | StateSet.VIEW_STATE_PRESSED);
   1616         PRESSED_ENABLED_STATE_SET = StateSet.get(
   1617                 StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_PRESSED);
   1618         PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1619                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_ENABLED
   1620                         | StateSet.VIEW_STATE_PRESSED);
   1621         PRESSED_ENABLED_SELECTED_STATE_SET = StateSet.get(
   1622                 StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_ENABLED
   1623                         | StateSet.VIEW_STATE_PRESSED);
   1624         PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1625                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
   1626                         | StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_PRESSED);
   1627         PRESSED_ENABLED_FOCUSED_STATE_SET = StateSet.get(
   1628                 StateSet.VIEW_STATE_FOCUSED | StateSet.VIEW_STATE_ENABLED
   1629                         | StateSet.VIEW_STATE_PRESSED);
   1630         PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1631                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_FOCUSED
   1632                         | StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_PRESSED);
   1633         PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET = StateSet.get(
   1634                 StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_FOCUSED
   1635                         | StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_PRESSED);
   1636         PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1637                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
   1638                         | StateSet.VIEW_STATE_FOCUSED| StateSet.VIEW_STATE_ENABLED
   1639                         | StateSet.VIEW_STATE_PRESSED);
   1640     }
   1641 
   1642     /**
   1643      * Accessibility event types that are dispatched for text population.
   1644      */
   1645     private static final int POPULATING_ACCESSIBILITY_EVENT_TYPES =
   1646             AccessibilityEvent.TYPE_VIEW_CLICKED
   1647             | AccessibilityEvent.TYPE_VIEW_LONG_CLICKED
   1648             | AccessibilityEvent.TYPE_VIEW_SELECTED
   1649             | AccessibilityEvent.TYPE_VIEW_FOCUSED
   1650             | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
   1651             | AccessibilityEvent.TYPE_VIEW_HOVER_ENTER
   1652             | AccessibilityEvent.TYPE_VIEW_HOVER_EXIT
   1653             | AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED
   1654             | AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED
   1655             | AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED
   1656             | AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY;
   1657 
   1658     /**
   1659      * Temporary Rect currently for use in setBackground().  This will probably
   1660      * be extended in the future to hold our own class with more than just
   1661      * a Rect. :)
   1662      */
   1663     static final ThreadLocal<Rect> sThreadLocal = new ThreadLocal<Rect>();
   1664 
   1665     /**
   1666      * Map used to store views' tags.
   1667      */
   1668     private SparseArray<Object> mKeyedTags;
   1669 
   1670     /**
   1671      * The next available accessibility id.
   1672      */
   1673     private static int sNextAccessibilityViewId;
   1674 
   1675     /**
   1676      * The animation currently associated with this view.
   1677      * @hide
   1678      */
   1679     protected Animation mCurrentAnimation = null;
   1680 
   1681     /**
   1682      * Width as measured during measure pass.
   1683      * {@hide}
   1684      */
   1685     @ViewDebug.ExportedProperty(category = "measurement")
   1686     int mMeasuredWidth;
   1687 
   1688     /**
   1689      * Height as measured during measure pass.
   1690      * {@hide}
   1691      */
   1692     @ViewDebug.ExportedProperty(category = "measurement")
   1693     int mMeasuredHeight;
   1694 
   1695     /**
   1696      * Flag to indicate that this view was marked INVALIDATED, or had its display list
   1697      * invalidated, prior to the current drawing iteration. If true, the view must re-draw
   1698      * its display list. This flag, used only when hw accelerated, allows us to clear the
   1699      * flag while retaining this information until it's needed (at getDisplayList() time and
   1700      * in drawChild(), when we decide to draw a view's children's display lists into our own).
   1701      *
   1702      * {@hide}
   1703      */
   1704     boolean mRecreateDisplayList = false;
   1705 
   1706     /**
   1707      * The view's identifier.
   1708      * {@hide}
   1709      *
   1710      * @see #setId(int)
   1711      * @see #getId()
   1712      */
   1713     @IdRes
   1714     @ViewDebug.ExportedProperty(resolveId = true)
   1715     int mID = NO_ID;
   1716 
   1717     /**
   1718      * The stable ID of this view for accessibility purposes.
   1719      */
   1720     int mAccessibilityViewId = NO_ID;
   1721 
   1722     private int mAccessibilityCursorPosition = ACCESSIBILITY_CURSOR_POSITION_UNDEFINED;
   1723 
   1724     SendViewStateChangedAccessibilityEvent mSendViewStateChangedAccessibilityEvent;
   1725 
   1726     /**
   1727      * The view's tag.
   1728      * {@hide}
   1729      *
   1730      * @see #setTag(Object)
   1731      * @see #getTag()
   1732      */
   1733     protected Object mTag = null;
   1734 
   1735     // for mPrivateFlags:
   1736     /** {@hide} */
   1737     static final int PFLAG_WANTS_FOCUS                 = 0x00000001;
   1738     /** {@hide} */
   1739     static final int PFLAG_FOCUSED                     = 0x00000002;
   1740     /** {@hide} */
   1741     static final int PFLAG_SELECTED                    = 0x00000004;
   1742     /** {@hide} */
   1743     static final int PFLAG_IS_ROOT_NAMESPACE           = 0x00000008;
   1744     /** {@hide} */
   1745     static final int PFLAG_HAS_BOUNDS                  = 0x00000010;
   1746     /** {@hide} */
   1747     static final int PFLAG_DRAWN                       = 0x00000020;
   1748     /**
   1749      * When this flag is set, this view is running an animation on behalf of its
   1750      * children and should therefore not cancel invalidate requests, even if they
   1751      * lie outside of this view's bounds.
   1752      *
   1753      * {@hide}
   1754      */
   1755     static final int PFLAG_DRAW_ANIMATION              = 0x00000040;
   1756     /** {@hide} */
   1757     static final int PFLAG_SKIP_DRAW                   = 0x00000080;
   1758     /** {@hide} */
   1759     static final int PFLAG_REQUEST_TRANSPARENT_REGIONS = 0x00000200;
   1760     /** {@hide} */
   1761     static final int PFLAG_DRAWABLE_STATE_DIRTY        = 0x00000400;
   1762     /** {@hide} */
   1763     static final int PFLAG_MEASURED_DIMENSION_SET      = 0x00000800;
   1764     /** {@hide} */
   1765     static final int PFLAG_FORCE_LAYOUT                = 0x00001000;
   1766     /** {@hide} */
   1767     static final int PFLAG_LAYOUT_REQUIRED             = 0x00002000;
   1768 
   1769     private static final int PFLAG_PRESSED             = 0x00004000;
   1770 
   1771     /** {@hide} */
   1772     static final int PFLAG_DRAWING_CACHE_VALID         = 0x00008000;
   1773     /**
   1774      * Flag used to indicate that this view should be drawn once more (and only once
   1775      * more) after its animation has completed.
   1776      * {@hide}
   1777      */
   1778     static final int PFLAG_ANIMATION_STARTED           = 0x00010000;
   1779 
   1780     private static final int PFLAG_SAVE_STATE_CALLED   = 0x00020000;
   1781 
   1782     /**
   1783      * Indicates that the View returned true when onSetAlpha() was called and that
   1784      * the alpha must be restored.
   1785      * {@hide}
   1786      */
   1787     static final int PFLAG_ALPHA_SET                   = 0x00040000;
   1788 
   1789     /**
   1790      * Set by {@link #setScrollContainer(boolean)}.
   1791      */
   1792     static final int PFLAG_SCROLL_CONTAINER            = 0x00080000;
   1793 
   1794     /**
   1795      * Set by {@link #setScrollContainer(boolean)}.
   1796      */
   1797     static final int PFLAG_SCROLL_CONTAINER_ADDED      = 0x00100000;
   1798 
   1799     /**
   1800      * View flag indicating whether this view was invalidated (fully or partially.)
   1801      *
   1802      * @hide
   1803      */
   1804     static final int PFLAG_DIRTY                       = 0x00200000;
   1805 
   1806     /**
   1807      * View flag indicating whether this view was invalidated by an opaque
   1808      * invalidate request.
   1809      *
   1810      * @hide
   1811      */
   1812     static final int PFLAG_DIRTY_OPAQUE                = 0x00400000;
   1813 
   1814     /**
   1815      * Mask for {@link #PFLAG_DIRTY} and {@link #PFLAG_DIRTY_OPAQUE}.
   1816      *
   1817      * @hide
   1818      */
   1819     static final int PFLAG_DIRTY_MASK                  = 0x00600000;
   1820 
   1821     /**
   1822      * Indicates whether the background is opaque.
   1823      *
   1824      * @hide
   1825      */
   1826     static final int PFLAG_OPAQUE_BACKGROUND           = 0x00800000;
   1827 
   1828     /**
   1829      * Indicates whether the scrollbars are opaque.
   1830      *
   1831      * @hide
   1832      */
   1833     static final int PFLAG_OPAQUE_SCROLLBARS           = 0x01000000;
   1834 
   1835     /**
   1836      * Indicates whether the view is opaque.
   1837      *
   1838      * @hide
   1839      */
   1840     static final int PFLAG_OPAQUE_MASK                 = 0x01800000;
   1841 
   1842     /**
   1843      * Indicates a prepressed state;
   1844      * the short time between ACTION_DOWN and recognizing
   1845      * a 'real' press. Prepressed is used to recognize quick taps
   1846      * even when they are shorter than ViewConfiguration.getTapTimeout().
   1847      *
   1848      * @hide
   1849      */
   1850     private static final int PFLAG_PREPRESSED          = 0x02000000;
   1851 
   1852     /**
   1853      * Indicates whether the view is temporarily detached.
   1854      *
   1855      * @hide
   1856      */
   1857     static final int PFLAG_CANCEL_NEXT_UP_EVENT        = 0x04000000;
   1858 
   1859     /**
   1860      * Indicates that we should awaken scroll bars once attached
   1861      *
   1862      * PLEASE NOTE: This flag is now unused as we now send onVisibilityChanged
   1863      * during window attachment and it is no longer needed. Feel free to repurpose it.
   1864      *
   1865      * @hide
   1866      */
   1867     private static final int PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH = 0x08000000;
   1868 
   1869     /**
   1870      * Indicates that the view has received HOVER_ENTER.  Cleared on HOVER_EXIT.
   1871      * @hide
   1872      */
   1873     private static final int PFLAG_HOVERED             = 0x10000000;
   1874 
   1875     /**
   1876      * no longer needed, should be reused
   1877      */
   1878     private static final int PFLAG_DOES_NOTHING_REUSE_PLEASE = 0x20000000;
   1879 
   1880     /** {@hide} */
   1881     static final int PFLAG_ACTIVATED                   = 0x40000000;
   1882 
   1883     /**
   1884      * Indicates that this view was specifically invalidated, not just dirtied because some
   1885      * child view was invalidated. The flag is used to determine when we need to recreate
   1886      * a view's display list (as opposed to just returning a reference to its existing
   1887      * display list).
   1888      *
   1889      * @hide
   1890      */
   1891     static final int PFLAG_INVALIDATED                 = 0x80000000;
   1892 
   1893     /**
   1894      * Masks for mPrivateFlags2, as generated by dumpFlags():
   1895      *
   1896      * |-------|-------|-------|-------|
   1897      *                                 1 PFLAG2_DRAG_CAN_ACCEPT
   1898      *                                1  PFLAG2_DRAG_HOVERED
   1899      *                              11   PFLAG2_LAYOUT_DIRECTION_MASK
   1900      *                             1     PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL
   1901      *                            1      PFLAG2_LAYOUT_DIRECTION_RESOLVED
   1902      *                            11     PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK
   1903      *                           1       PFLAG2_TEXT_DIRECTION_FLAGS[1]
   1904      *                          1        PFLAG2_TEXT_DIRECTION_FLAGS[2]
   1905      *                          11       PFLAG2_TEXT_DIRECTION_FLAGS[3]
   1906      *                         1         PFLAG2_TEXT_DIRECTION_FLAGS[4]
   1907      *                         1 1       PFLAG2_TEXT_DIRECTION_FLAGS[5]
   1908      *                         11        PFLAG2_TEXT_DIRECTION_FLAGS[6]
   1909      *                         111       PFLAG2_TEXT_DIRECTION_FLAGS[7]
   1910      *                         111       PFLAG2_TEXT_DIRECTION_MASK
   1911      *                        1          PFLAG2_TEXT_DIRECTION_RESOLVED
   1912      *                       1           PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT
   1913      *                     111           PFLAG2_TEXT_DIRECTION_RESOLVED_MASK
   1914      *                    1              PFLAG2_TEXT_ALIGNMENT_FLAGS[1]
   1915      *                   1               PFLAG2_TEXT_ALIGNMENT_FLAGS[2]
   1916      *                   11              PFLAG2_TEXT_ALIGNMENT_FLAGS[3]
   1917      *                  1                PFLAG2_TEXT_ALIGNMENT_FLAGS[4]
   1918      *                  1 1              PFLAG2_TEXT_ALIGNMENT_FLAGS[5]
   1919      *                  11               PFLAG2_TEXT_ALIGNMENT_FLAGS[6]
   1920      *                  111              PFLAG2_TEXT_ALIGNMENT_MASK
   1921      *                 1                 PFLAG2_TEXT_ALIGNMENT_RESOLVED
   1922      *                1                  PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT
   1923      *              111                  PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK
   1924      *           111                     PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK
   1925      *         11                        PFLAG2_ACCESSIBILITY_LIVE_REGION_MASK
   1926      *       1                           PFLAG2_ACCESSIBILITY_FOCUSED
   1927      *      1                            PFLAG2_SUBTREE_ACCESSIBILITY_STATE_CHANGED
   1928      *     1                             PFLAG2_VIEW_QUICK_REJECTED
   1929      *    1                              PFLAG2_PADDING_RESOLVED
   1930      *   1                               PFLAG2_DRAWABLE_RESOLVED
   1931      *  1                                PFLAG2_HAS_TRANSIENT_STATE
   1932      * |-------|-------|-------|-------|
   1933      */
   1934 
   1935     /**
   1936      * Indicates that this view has reported that it can accept the current drag's content.
   1937      * Cleared when the drag operation concludes.
   1938      * @hide
   1939      */
   1940     static final int PFLAG2_DRAG_CAN_ACCEPT            = 0x00000001;
   1941 
   1942     /**
   1943      * Indicates that this view is currently directly under the drag location in a
   1944      * drag-and-drop operation involving content that it can accept.  Cleared when
   1945      * the drag exits the view, or when the drag operation concludes.
   1946      * @hide
   1947      */
   1948     static final int PFLAG2_DRAG_HOVERED               = 0x00000002;
   1949 
   1950     /** @hide */
   1951     @IntDef({
   1952         LAYOUT_DIRECTION_LTR,
   1953         LAYOUT_DIRECTION_RTL,
   1954         LAYOUT_DIRECTION_INHERIT,
   1955         LAYOUT_DIRECTION_LOCALE
   1956     })
   1957     @Retention(RetentionPolicy.SOURCE)
   1958     // Not called LayoutDirection to avoid conflict with android.util.LayoutDirection
   1959     public @interface LayoutDir {}
   1960 
   1961     /** @hide */
   1962     @IntDef({
   1963         LAYOUT_DIRECTION_LTR,
   1964         LAYOUT_DIRECTION_RTL
   1965     })
   1966     @Retention(RetentionPolicy.SOURCE)
   1967     public @interface ResolvedLayoutDir {}
   1968 
   1969     /**
   1970      * A flag to indicate that the layout direction of this view has not been defined yet.
   1971      * @hide
   1972      */
   1973     public static final int LAYOUT_DIRECTION_UNDEFINED = LayoutDirection.UNDEFINED;
   1974 
   1975     /**
   1976      * Horizontal layout direction of this view is from Left to Right.
   1977      * Use with {@link #setLayoutDirection}.
   1978      */
   1979     public static final int LAYOUT_DIRECTION_LTR = LayoutDirection.LTR;
   1980 
   1981     /**
   1982      * Horizontal layout direction of this view is from Right to Left.
   1983      * Use with {@link #setLayoutDirection}.
   1984      */
   1985     public static final int LAYOUT_DIRECTION_RTL = LayoutDirection.RTL;
   1986 
   1987     /**
   1988      * Horizontal layout direction of this view is inherited from its parent.
   1989      * Use with {@link #setLayoutDirection}.
   1990      */
   1991     public static final int LAYOUT_DIRECTION_INHERIT = LayoutDirection.INHERIT;
   1992 
   1993     /**
   1994      * Horizontal layout direction of this view is from deduced from the default language
   1995      * script for the locale. Use with {@link #setLayoutDirection}.
   1996      */
   1997     public static final int LAYOUT_DIRECTION_LOCALE = LayoutDirection.LOCALE;
   1998 
   1999     /**
   2000      * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED)
   2001      * @hide
   2002      */
   2003     static final int PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT = 2;
   2004 
   2005     /**
   2006      * Mask for use with private flags indicating bits used for horizontal layout direction.
   2007      * @hide
   2008      */
   2009     static final int PFLAG2_LAYOUT_DIRECTION_MASK = 0x00000003 << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT;
   2010 
   2011     /**
   2012      * Indicates whether the view horizontal layout direction has been resolved and drawn to the
   2013      * right-to-left direction.
   2014      * @hide
   2015      */
   2016     static final int PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL = 4 << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT;
   2017 
   2018     /**
   2019      * Indicates whether the view horizontal layout direction has been resolved.
   2020      * @hide
   2021      */
   2022     static final int PFLAG2_LAYOUT_DIRECTION_RESOLVED = 8 << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT;
   2023 
   2024     /**
   2025      * Mask for use with private flags indicating bits used for resolved horizontal layout direction.
   2026      * @hide
   2027      */
   2028     static final int PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK = 0x0000000C
   2029             << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT;
   2030 
   2031     /*
   2032      * Array of horizontal layout direction flags for mapping attribute "layoutDirection" to correct
   2033      * flag value.
   2034      * @hide
   2035      */
   2036     private static final int[] LAYOUT_DIRECTION_FLAGS = {
   2037             LAYOUT_DIRECTION_LTR,
   2038             LAYOUT_DIRECTION_RTL,
   2039             LAYOUT_DIRECTION_INHERIT,
   2040             LAYOUT_DIRECTION_LOCALE
   2041     };
   2042 
   2043     /**
   2044      * Default horizontal layout direction.
   2045      */
   2046     private static final int LAYOUT_DIRECTION_DEFAULT = LAYOUT_DIRECTION_INHERIT;
   2047 
   2048     /**
   2049      * Default horizontal layout direction.
   2050      * @hide
   2051      */
   2052     static final int LAYOUT_DIRECTION_RESOLVED_DEFAULT = LAYOUT_DIRECTION_LTR;
   2053 
   2054     /**
   2055      * Text direction is inherited through {@link ViewGroup}
   2056      */
   2057     public static final int TEXT_DIRECTION_INHERIT = 0;
   2058 
   2059     /**
   2060      * Text direction is using "first strong algorithm". The first strong directional character
   2061      * determines the paragraph direction. If there is no strong directional character, the
   2062      * paragraph direction is the view's resolved layout direction.
   2063      */
   2064     public static final int TEXT_DIRECTION_FIRST_STRONG = 1;
   2065 
   2066     /**
   2067      * Text direction is using "any-RTL" algorithm. The paragraph direction is RTL if it contains
   2068      * any strong RTL character, otherwise it is LTR if it contains any strong LTR characters.
   2069      * If there are neither, the paragraph direction is the view's resolved layout direction.
   2070      */
   2071     public static final int TEXT_DIRECTION_ANY_RTL = 2;
   2072 
   2073     /**
   2074      * Text direction is forced to LTR.
   2075      */
   2076     public static final int TEXT_DIRECTION_LTR = 3;
   2077 
   2078     /**
   2079      * Text direction is forced to RTL.
   2080      */
   2081     public static final int TEXT_DIRECTION_RTL = 4;
   2082 
   2083     /**
   2084      * Text direction is coming from the system Locale.
   2085      */
   2086     public static final int TEXT_DIRECTION_LOCALE = 5;
   2087 
   2088     /**
   2089      * Text direction is using "first strong algorithm". The first strong directional character
   2090      * determines the paragraph direction. If there is no strong directional character, the
   2091      * paragraph direction is LTR.
   2092      */
   2093     public static final int TEXT_DIRECTION_FIRST_STRONG_LTR = 6;
   2094 
   2095     /**
   2096      * Text direction is using "first strong algorithm". The first strong directional character
   2097      * determines the paragraph direction. If there is no strong directional character, the
   2098      * paragraph direction is RTL.
   2099      */
   2100     public static final int TEXT_DIRECTION_FIRST_STRONG_RTL = 7;
   2101 
   2102     /**
   2103      * Default text direction is inherited
   2104      */
   2105     private static final int TEXT_DIRECTION_DEFAULT = TEXT_DIRECTION_INHERIT;
   2106 
   2107     /**
   2108      * Default resolved text direction
   2109      * @hide
   2110      */
   2111     static final int TEXT_DIRECTION_RESOLVED_DEFAULT = TEXT_DIRECTION_FIRST_STRONG;
   2112 
   2113     /**
   2114      * Bit shift to get the horizontal layout direction. (bits after LAYOUT_DIRECTION_RESOLVED)
   2115      * @hide
   2116      */
   2117     static final int PFLAG2_TEXT_DIRECTION_MASK_SHIFT = 6;
   2118 
   2119     /**
   2120      * Mask for use with private flags indicating bits used for text direction.
   2121      * @hide
   2122      */
   2123     static final int PFLAG2_TEXT_DIRECTION_MASK = 0x00000007
   2124             << PFLAG2_TEXT_DIRECTION_MASK_SHIFT;
   2125 
   2126     /**
   2127      * Array of text direction flags for mapping attribute "textDirection" to correct
   2128      * flag value.
   2129      * @hide
   2130      */
   2131     private static final int[] PFLAG2_TEXT_DIRECTION_FLAGS = {
   2132             TEXT_DIRECTION_INHERIT << PFLAG2_TEXT_DIRECTION_MASK_SHIFT,
   2133             TEXT_DIRECTION_FIRST_STRONG << PFLAG2_TEXT_DIRECTION_MASK_SHIFT,
   2134             TEXT_DIRECTION_ANY_RTL << PFLAG2_TEXT_DIRECTION_MASK_SHIFT,
   2135             TEXT_DIRECTION_LTR << PFLAG2_TEXT_DIRECTION_MASK_SHIFT,
   2136             TEXT_DIRECTION_RTL << PFLAG2_TEXT_DIRECTION_MASK_SHIFT,
   2137             TEXT_DIRECTION_LOCALE << PFLAG2_TEXT_DIRECTION_MASK_SHIFT,
   2138             TEXT_DIRECTION_FIRST_STRONG_LTR << PFLAG2_TEXT_DIRECTION_MASK_SHIFT,
   2139             TEXT_DIRECTION_FIRST_STRONG_RTL << PFLAG2_TEXT_DIRECTION_MASK_SHIFT
   2140     };
   2141 
   2142     /**
   2143      * Indicates whether the view text direction has been resolved.
   2144      * @hide
   2145      */
   2146     static final int PFLAG2_TEXT_DIRECTION_RESOLVED = 0x00000008
   2147             << PFLAG2_TEXT_DIRECTION_MASK_SHIFT;
   2148 
   2149     /**
   2150      * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED)
   2151      * @hide
   2152      */
   2153     static final int PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT = 10;
   2154 
   2155     /**
   2156      * Mask for use with private flags indicating bits used for resolved text direction.
   2157      * @hide
   2158      */
   2159     static final int PFLAG2_TEXT_DIRECTION_RESOLVED_MASK = 0x00000007
   2160             << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT;
   2161 
   2162     /**
   2163      * Indicates whether the view text direction has been resolved to the "first strong" heuristic.
   2164      * @hide
   2165      */
   2166     static final int PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT =
   2167             TEXT_DIRECTION_RESOLVED_DEFAULT << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT;
   2168 
   2169     /** @hide */
   2170     @IntDef({
   2171         TEXT_ALIGNMENT_INHERIT,
   2172         TEXT_ALIGNMENT_GRAVITY,
   2173         TEXT_ALIGNMENT_CENTER,
   2174         TEXT_ALIGNMENT_TEXT_START,
   2175         TEXT_ALIGNMENT_TEXT_END,
   2176         TEXT_ALIGNMENT_VIEW_START,
   2177         TEXT_ALIGNMENT_VIEW_END
   2178     })
   2179     @Retention(RetentionPolicy.SOURCE)
   2180     public @interface TextAlignment {}
   2181 
   2182     /**
   2183      * Default text alignment. The text alignment of this View is inherited from its parent.
   2184      * Use with {@link #setTextAlignment(int)}
   2185      */
   2186     public static final int TEXT_ALIGNMENT_INHERIT = 0;
   2187 
   2188     /**
   2189      * Default for the root view. The gravity determines the text alignment, ALIGN_NORMAL,
   2190      * ALIGN_CENTER, or ALIGN_OPPOSITE, which are relative to each paragraphs text direction.
   2191      *
   2192      * Use with {@link #setTextAlignment(int)}
   2193      */
   2194     public static final int TEXT_ALIGNMENT_GRAVITY = 1;
   2195 
   2196     /**
   2197      * Align to the start of the paragraph, e.g. ALIGN_NORMAL.
   2198      *
   2199      * Use with {@link #setTextAlignment(int)}
   2200      */
   2201     public static final int TEXT_ALIGNMENT_TEXT_START = 2;
   2202 
   2203     /**
   2204      * Align to the end of the paragraph, e.g. ALIGN_OPPOSITE.
   2205      *
   2206      * Use with {@link #setTextAlignment(int)}
   2207      */
   2208     public static final int TEXT_ALIGNMENT_TEXT_END = 3;
   2209 
   2210     /**
   2211      * Center the paragraph, e.g. ALIGN_CENTER.
   2212      *
   2213      * Use with {@link #setTextAlignment(int)}
   2214      */
   2215     public static final int TEXT_ALIGNMENT_CENTER = 4;
   2216 
   2217     /**
   2218      * Align to the start of the view, which is ALIGN_LEFT if the views resolved
   2219      * layoutDirection is LTR, and ALIGN_RIGHT otherwise.
   2220      *
   2221      * Use with {@link #setTextAlignment(int)}
   2222      */
   2223     public static final int TEXT_ALIGNMENT_VIEW_START = 5;
   2224 
   2225     /**
   2226      * Align to the end of the view, which is ALIGN_RIGHT if the views resolved
   2227      * layoutDirection is LTR, and ALIGN_LEFT otherwise.
   2228      *
   2229      * Use with {@link #setTextAlignment(int)}
   2230      */
   2231     public static final int TEXT_ALIGNMENT_VIEW_END = 6;
   2232 
   2233     /**
   2234      * Default text alignment is inherited
   2235      */
   2236     private static final int TEXT_ALIGNMENT_DEFAULT = TEXT_ALIGNMENT_GRAVITY;
   2237 
   2238     /**
   2239      * Default resolved text alignment
   2240      * @hide
   2241      */
   2242     static final int TEXT_ALIGNMENT_RESOLVED_DEFAULT = TEXT_ALIGNMENT_GRAVITY;
   2243 
   2244     /**
   2245       * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED)
   2246       * @hide
   2247       */
   2248     static final int PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT = 13;
   2249 
   2250     /**
   2251       * Mask for use with private flags indicating bits used for text alignment.
   2252       * @hide
   2253       */
   2254     static final int PFLAG2_TEXT_ALIGNMENT_MASK = 0x00000007 << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT;
   2255 
   2256     /**
   2257      * Array of text direction flags for mapping attribute "textAlignment" to correct
   2258      * flag value.
   2259      * @hide
   2260      */
   2261     private static final int[] PFLAG2_TEXT_ALIGNMENT_FLAGS = {
   2262             TEXT_ALIGNMENT_INHERIT << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT,
   2263             TEXT_ALIGNMENT_GRAVITY << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT,
   2264             TEXT_ALIGNMENT_TEXT_START << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT,
   2265             TEXT_ALIGNMENT_TEXT_END << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT,
   2266             TEXT_ALIGNMENT_CENTER << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT,
   2267             TEXT_ALIGNMENT_VIEW_START << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT,
   2268             TEXT_ALIGNMENT_VIEW_END << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT
   2269     };
   2270 
   2271     /**
   2272      * Indicates whether the view text alignment has been resolved.
   2273      * @hide
   2274      */
   2275     static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED = 0x00000008 << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT;
   2276 
   2277     /**
   2278      * Bit shift to get the resolved text alignment.
   2279      * @hide
   2280      */
   2281     static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT = 17;
   2282 
   2283     /**
   2284      * Mask for use with private flags indicating bits used for text alignment.
   2285      * @hide
   2286      */
   2287     static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK = 0x00000007
   2288             << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT;
   2289 
   2290     /**
   2291      * Indicates whether if the view text alignment has been resolved to gravity
   2292      */
   2293     private static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT =
   2294             TEXT_ALIGNMENT_RESOLVED_DEFAULT << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT;
   2295 
   2296     // Accessiblity constants for mPrivateFlags2
   2297 
   2298     /**
   2299      * Shift for the bits in {@link #mPrivateFlags2} related to the
   2300      * "importantForAccessibility" attribute.
   2301      */
   2302     static final int PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT = 20;
   2303 
   2304     /**
   2305      * Automatically determine whether a view is important for accessibility.
   2306      */
   2307     public static final int IMPORTANT_FOR_ACCESSIBILITY_AUTO = 0x00000000;
   2308 
   2309     /**
   2310      * The view is important for accessibility.
   2311      */
   2312     public static final int IMPORTANT_FOR_ACCESSIBILITY_YES = 0x00000001;
   2313 
   2314     /**
   2315      * The view is not important for accessibility.
   2316      */
   2317     public static final int IMPORTANT_FOR_ACCESSIBILITY_NO = 0x00000002;
   2318 
   2319     /**
   2320      * The view is not important for accessibility, nor are any of its
   2321      * descendant views.
   2322      */
   2323     public static final int IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS = 0x00000004;
   2324 
   2325     /**
   2326      * The default whether the view is important for accessibility.
   2327      */
   2328     static final int IMPORTANT_FOR_ACCESSIBILITY_DEFAULT = IMPORTANT_FOR_ACCESSIBILITY_AUTO;
   2329 
   2330     /**
   2331      * Mask for obtainig the bits which specify how to determine
   2332      * whether a view is important for accessibility.
   2333      */
   2334     static final int PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK = (IMPORTANT_FOR_ACCESSIBILITY_AUTO
   2335         | IMPORTANT_FOR_ACCESSIBILITY_YES | IMPORTANT_FOR_ACCESSIBILITY_NO
   2336         | IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS)
   2337         << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT;
   2338 
   2339     /**
   2340      * Shift for the bits in {@link #mPrivateFlags2} related to the
   2341      * "accessibilityLiveRegion" attribute.
   2342      */
   2343     static final int PFLAG2_ACCESSIBILITY_LIVE_REGION_SHIFT = 23;
   2344 
   2345     /**
   2346      * Live region mode specifying that accessibility services should not
   2347      * automatically announce changes to this view. This is the default live
   2348      * region mode for most views.
   2349      * <p>
   2350      * Use with {@link #setAccessibilityLiveRegion(int)}.
   2351      */
   2352     public static final int ACCESSIBILITY_LIVE_REGION_NONE = 0x00000000;
   2353 
   2354     /**
   2355      * Live region mode specifying that accessibility services should announce
   2356      * changes to this view.
   2357      * <p>
   2358      * Use with {@link #setAccessibilityLiveRegion(int)}.
   2359      */
   2360     public static final int ACCESSIBILITY_LIVE_REGION_POLITE = 0x00000001;
   2361 
   2362     /**
   2363      * Live region mode specifying that accessibility services should interrupt
   2364      * ongoing speech to immediately announce changes to this view.
   2365      * <p>
   2366      * Use with {@link #setAccessibilityLiveRegion(int)}.
   2367      */
   2368     public static final int ACCESSIBILITY_LIVE_REGION_ASSERTIVE = 0x00000002;
   2369 
   2370     /**
   2371      * The default whether the view is important for accessibility.
   2372      */
   2373     static final int ACCESSIBILITY_LIVE_REGION_DEFAULT = ACCESSIBILITY_LIVE_REGION_NONE;
   2374 
   2375     /**
   2376      * Mask for obtaining the bits which specify a view's accessibility live
   2377      * region mode.
   2378      */
   2379     static final int PFLAG2_ACCESSIBILITY_LIVE_REGION_MASK = (ACCESSIBILITY_LIVE_REGION_NONE
   2380             | ACCESSIBILITY_LIVE_REGION_POLITE | ACCESSIBILITY_LIVE_REGION_ASSERTIVE)
   2381             << PFLAG2_ACCESSIBILITY_LIVE_REGION_SHIFT;
   2382 
   2383     /**
   2384      * Flag indicating whether a view has accessibility focus.
   2385      */
   2386     static final int PFLAG2_ACCESSIBILITY_FOCUSED = 0x04000000;
   2387 
   2388     /**
   2389      * Flag whether the accessibility state of the subtree rooted at this view changed.
   2390      */
   2391     static final int PFLAG2_SUBTREE_ACCESSIBILITY_STATE_CHANGED = 0x08000000;
   2392 
   2393     /**
   2394      * Flag indicating whether a view failed the quickReject() check in draw(). This condition
   2395      * is used to check whether later changes to the view's transform should invalidate the
   2396      * view to force the quickReject test to run again.
   2397      */
   2398     static final int PFLAG2_VIEW_QUICK_REJECTED = 0x10000000;
   2399 
   2400     /**
   2401      * Flag indicating that start/end padding has been resolved into left/right padding
   2402      * for use in measurement, layout, drawing, etc. This is set by {@link #resolvePadding()}
   2403      * and checked by {@link #measure(int, int)} to determine if padding needs to be resolved
   2404      * during measurement. In some special cases this is required such as when an adapter-based
   2405      * view measures prospective children without attaching them to a window.
   2406      */
   2407     static final int PFLAG2_PADDING_RESOLVED = 0x20000000;
   2408 
   2409     /**
   2410      * Flag indicating that the start/end drawables has been resolved into left/right ones.
   2411      */
   2412     static final int PFLAG2_DRAWABLE_RESOLVED = 0x40000000;
   2413 
   2414     /**
   2415      * Indicates that the view is tracking some sort of transient state
   2416      * that the app should not need to be aware of, but that the framework
   2417      * should take special care to preserve.
   2418      */
   2419     static final int PFLAG2_HAS_TRANSIENT_STATE = 0x80000000;
   2420 
   2421     /**
   2422      * Group of bits indicating that RTL properties resolution is done.
   2423      */
   2424     static final int ALL_RTL_PROPERTIES_RESOLVED = PFLAG2_LAYOUT_DIRECTION_RESOLVED |
   2425             PFLAG2_TEXT_DIRECTION_RESOLVED |
   2426             PFLAG2_TEXT_ALIGNMENT_RESOLVED |
   2427             PFLAG2_PADDING_RESOLVED |
   2428             PFLAG2_DRAWABLE_RESOLVED;
   2429 
   2430     // There are a couple of flags left in mPrivateFlags2
   2431 
   2432     /* End of masks for mPrivateFlags2 */
   2433 
   2434     /**
   2435      * Masks for mPrivateFlags3, as generated by dumpFlags():
   2436      *
   2437      * |-------|-------|-------|-------|
   2438      *                                 1 PFLAG3_VIEW_IS_ANIMATING_TRANSFORM
   2439      *                                1  PFLAG3_VIEW_IS_ANIMATING_ALPHA
   2440      *                               1   PFLAG3_IS_LAID_OUT
   2441      *                              1    PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT
   2442      *                             1     PFLAG3_CALLED_SUPER
   2443      *                            1      PFLAG3_APPLYING_INSETS
   2444      *                           1       PFLAG3_FITTING_SYSTEM_WINDOWS
   2445      *                          1        PFLAG3_NESTED_SCROLLING_ENABLED
   2446      *                         1         PFLAG3_SCROLL_INDICATOR_TOP
   2447      *                        1          PFLAG3_SCROLL_INDICATOR_BOTTOM
   2448      *                       1           PFLAG3_SCROLL_INDICATOR_LEFT
   2449      *                      1            PFLAG3_SCROLL_INDICATOR_RIGHT
   2450      *                     1             PFLAG3_SCROLL_INDICATOR_START
   2451      *                    1              PFLAG3_SCROLL_INDICATOR_END
   2452      *                   1               PFLAG3_ASSIST_BLOCKED
   2453      *                  1                PFLAG3_POINTER_ICON_NULL
   2454      *                 1                 PFLAG3_POINTER_ICON_VALUE_START
   2455      *           11111111                PFLAG3_POINTER_ICON_MASK
   2456      *          1                        PFLAG3_OVERLAPPING_RENDERING_FORCED_VALUE
   2457      *         1                         PFLAG3_HAS_OVERLAPPING_RENDERING_FORCED
   2458      *        1                          PFLAG3_TEMPORARY_DETACH
   2459      *       1                           PFLAG3_NO_REVEAL_ON_FOCUS
   2460      * |-------|-------|-------|-------|
   2461      */
   2462 
   2463     /**
   2464      * Flag indicating that view has a transform animation set on it. This is used to track whether
   2465      * an animation is cleared between successive frames, in order to tell the associated
   2466      * DisplayList to clear its animation matrix.
   2467      */
   2468     static final int PFLAG3_VIEW_IS_ANIMATING_TRANSFORM = 0x1;
   2469 
   2470     /**
   2471      * Flag indicating that view has an alpha animation set on it. This is used to track whether an
   2472      * animation is cleared between successive frames, in order to tell the associated
   2473      * DisplayList to restore its alpha value.
   2474      */
   2475     static final int PFLAG3_VIEW_IS_ANIMATING_ALPHA = 0x2;
   2476 
   2477     /**
   2478      * Flag indicating that the view has been through at least one layout since it
   2479      * was last attached to a window.
   2480      */
   2481     static final int PFLAG3_IS_LAID_OUT = 0x4;
   2482 
   2483     /**
   2484      * Flag indicating that a call to measure() was skipped and should be done
   2485      * instead when layout() is invoked.
   2486      */
   2487     static final int PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT = 0x8;
   2488 
   2489     /**
   2490      * Flag indicating that an overridden method correctly called down to
   2491      * the superclass implementation as required by the API spec.
   2492      */
   2493     static final int PFLAG3_CALLED_SUPER = 0x10;
   2494 
   2495     /**
   2496      * Flag indicating that we're in the process of applying window insets.
   2497      */
   2498     static final int PFLAG3_APPLYING_INSETS = 0x20;
   2499 
   2500     /**
   2501      * Flag indicating that we're in the process of fitting system windows using the old method.
   2502      */
   2503     static final int PFLAG3_FITTING_SYSTEM_WINDOWS = 0x40;
   2504 
   2505     /**
   2506      * Flag indicating that nested scrolling is enabled for this view.
   2507      * The view will optionally cooperate with views up its parent chain to allow for
   2508      * integrated nested scrolling along the same axis.
   2509      */
   2510     static final int PFLAG3_NESTED_SCROLLING_ENABLED = 0x80;
   2511 
   2512     /**
   2513      * Flag indicating that the bottom scroll indicator should be displayed
   2514      * when this view can scroll up.
   2515      */
   2516     static final int PFLAG3_SCROLL_INDICATOR_TOP = 0x0100;
   2517 
   2518     /**
   2519      * Flag indicating that the bottom scroll indicator should be displayed
   2520      * when this view can scroll down.
   2521      */
   2522     static final int PFLAG3_SCROLL_INDICATOR_BOTTOM = 0x0200;
   2523 
   2524     /**
   2525      * Flag indicating that the left scroll indicator should be displayed
   2526      * when this view can scroll left.
   2527      */
   2528     static final int PFLAG3_SCROLL_INDICATOR_LEFT = 0x0400;
   2529 
   2530     /**
   2531      * Flag indicating that the right scroll indicator should be displayed
   2532      * when this view can scroll right.
   2533      */
   2534     static final int PFLAG3_SCROLL_INDICATOR_RIGHT = 0x0800;
   2535 
   2536     /**
   2537      * Flag indicating that the start scroll indicator should be displayed
   2538      * when this view can scroll in the start direction.
   2539      */
   2540     static final int PFLAG3_SCROLL_INDICATOR_START = 0x1000;
   2541 
   2542     /**
   2543      * Flag indicating that the end scroll indicator should be displayed
   2544      * when this view can scroll in the end direction.
   2545      */
   2546     static final int PFLAG3_SCROLL_INDICATOR_END = 0x2000;
   2547 
   2548     static final int DRAG_MASK = PFLAG2_DRAG_CAN_ACCEPT | PFLAG2_DRAG_HOVERED;
   2549 
   2550     static final int SCROLL_INDICATORS_NONE = 0x0000;
   2551 
   2552     /**
   2553      * Mask for use with setFlags indicating bits used for indicating which
   2554      * scroll indicators are enabled.
   2555      */
   2556     static final int SCROLL_INDICATORS_PFLAG3_MASK = PFLAG3_SCROLL_INDICATOR_TOP
   2557             | PFLAG3_SCROLL_INDICATOR_BOTTOM | PFLAG3_SCROLL_INDICATOR_LEFT
   2558             | PFLAG3_SCROLL_INDICATOR_RIGHT | PFLAG3_SCROLL_INDICATOR_START
   2559             | PFLAG3_SCROLL_INDICATOR_END;
   2560 
   2561     /**
   2562      * Left-shift required to translate between public scroll indicator flags
   2563      * and internal PFLAGS3 flags. When used as a right-shift, translates
   2564      * PFLAGS3 flags to public flags.
   2565      */
   2566     static final int SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT = 8;
   2567 
   2568     /** @hide */
   2569     @Retention(RetentionPolicy.SOURCE)
   2570     @IntDef(flag = true,
   2571             value = {
   2572                     SCROLL_INDICATOR_TOP,
   2573                     SCROLL_INDICATOR_BOTTOM,
   2574                     SCROLL_INDICATOR_LEFT,
   2575                     SCROLL_INDICATOR_RIGHT,
   2576                     SCROLL_INDICATOR_START,
   2577                     SCROLL_INDICATOR_END,
   2578             })
   2579     public @interface ScrollIndicators {}
   2580 
   2581     /**
   2582      * Scroll indicator direction for the top edge of the view.
   2583      *
   2584      * @see #setScrollIndicators(int)
   2585      * @see #setScrollIndicators(int, int)
   2586      * @see #getScrollIndicators()
   2587      */
   2588     public static final int SCROLL_INDICATOR_TOP =
   2589             PFLAG3_SCROLL_INDICATOR_TOP >> SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT;
   2590 
   2591     /**
   2592      * Scroll indicator direction for the bottom edge of the view.
   2593      *
   2594      * @see #setScrollIndicators(int)
   2595      * @see #setScrollIndicators(int, int)
   2596      * @see #getScrollIndicators()
   2597      */
   2598     public static final int SCROLL_INDICATOR_BOTTOM =
   2599             PFLAG3_SCROLL_INDICATOR_BOTTOM >> SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT;
   2600 
   2601     /**
   2602      * Scroll indicator direction for the left edge of the view.
   2603      *
   2604      * @see #setScrollIndicators(int)
   2605      * @see #setScrollIndicators(int, int)
   2606      * @see #getScrollIndicators()
   2607      */
   2608     public static final int SCROLL_INDICATOR_LEFT =
   2609             PFLAG3_SCROLL_INDICATOR_LEFT >> SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT;
   2610 
   2611     /**
   2612      * Scroll indicator direction for the right edge of the view.
   2613      *
   2614      * @see #setScrollIndicators(int)
   2615      * @see #setScrollIndicators(int, int)
   2616      * @see #getScrollIndicators()
   2617      */
   2618     public static final int SCROLL_INDICATOR_RIGHT =
   2619             PFLAG3_SCROLL_INDICATOR_RIGHT >> SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT;
   2620 
   2621     /**
   2622      * Scroll indicator direction for the starting edge of the view.
   2623      * <p>
   2624      * Resolved according to the view's layout direction, see
   2625      * {@link #getLayoutDirection()} for more information.
   2626      *
   2627      * @see #setScrollIndicators(int)
   2628      * @see #setScrollIndicators(int, int)
   2629      * @see #getScrollIndicators()
   2630      */
   2631     public static final int SCROLL_INDICATOR_START =
   2632             PFLAG3_SCROLL_INDICATOR_START >> SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT;
   2633 
   2634     /**
   2635      * Scroll indicator direction for the ending edge of the view.
   2636      * <p>
   2637      * Resolved according to the view's layout direction, see
   2638      * {@link #getLayoutDirection()} for more information.
   2639      *
   2640      * @see #setScrollIndicators(int)
   2641      * @see #setScrollIndicators(int, int)
   2642      * @see #getScrollIndicators()
   2643      */
   2644     public static final int SCROLL_INDICATOR_END =
   2645             PFLAG3_SCROLL_INDICATOR_END >> SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT;
   2646 
   2647     /**
   2648      * <p>Indicates that we are allowing {@link ViewStructure} to traverse
   2649      * into this view.<p>
   2650      */
   2651     static final int PFLAG3_ASSIST_BLOCKED = 0x4000;
   2652 
   2653     /**
   2654      * The mask for use with private flags indicating bits used for pointer icon shapes.
   2655      */
   2656     static final int PFLAG3_POINTER_ICON_MASK = 0x7f8000;
   2657 
   2658     /**
   2659      * Left-shift used for pointer icon shape values in private flags.
   2660      */
   2661     static final int PFLAG3_POINTER_ICON_LSHIFT = 15;
   2662 
   2663     /**
   2664      * Value indicating no specific pointer icons.
   2665      */
   2666     private static final int PFLAG3_POINTER_ICON_NOT_SPECIFIED = 0 << PFLAG3_POINTER_ICON_LSHIFT;
   2667 
   2668     /**
   2669      * Value indicating {@link PointerIcon.TYPE_NULL}.
   2670      */
   2671     private static final int PFLAG3_POINTER_ICON_NULL = 1 << PFLAG3_POINTER_ICON_LSHIFT;
   2672 
   2673     /**
   2674      * The base value for other pointer icon shapes.
   2675      */
   2676     private static final int PFLAG3_POINTER_ICON_VALUE_START = 2 << PFLAG3_POINTER_ICON_LSHIFT;
   2677 
   2678     /**
   2679      * Whether this view has rendered elements that overlap (see {@link
   2680      * #hasOverlappingRendering()}, {@link #forceHasOverlappingRendering(boolean)}, and
   2681      * {@link #getHasOverlappingRendering()} ). The value in this bit is only valid when
   2682      * PFLAG3_HAS_OVERLAPPING_RENDERING_FORCED has been set. Otherwise, the value is
   2683      * determined by whatever {@link #hasOverlappingRendering()} returns.
   2684      */
   2685     private static final int PFLAG3_OVERLAPPING_RENDERING_FORCED_VALUE = 0x800000;
   2686 
   2687     /**
   2688      * Whether {@link #forceHasOverlappingRendering(boolean)} has been called. When true, value
   2689      * in PFLAG3_OVERLAPPING_RENDERING_FORCED_VALUE is valid.
   2690      */
   2691     private static final int PFLAG3_HAS_OVERLAPPING_RENDERING_FORCED = 0x1000000;
   2692 
   2693     /**
   2694      * Flag indicating that the view is temporarily detached from the parent view.
   2695      *
   2696      * @see #onStartTemporaryDetach()
   2697      * @see #onFinishTemporaryDetach()
   2698      */
   2699     static final int PFLAG3_TEMPORARY_DETACH = 0x2000000;
   2700 
   2701     /**
   2702      * Flag indicating that the view does not wish to be revealed within its parent
   2703      * hierarchy when it gains focus. Expressed in the negative since the historical
   2704      * default behavior is to reveal on focus; this flag suppresses that behavior.
   2705      *
   2706      * @see #setRevealOnFocusHint(boolean)
   2707      * @see #getRevealOnFocusHint()
   2708      */
   2709     private static final int PFLAG3_NO_REVEAL_ON_FOCUS = 0x4000000;
   2710 
   2711     /* End of masks for mPrivateFlags3 */
   2712 
   2713     /**
   2714      * Always allow a user to over-scroll this view, provided it is a
   2715      * view that can scroll.
   2716      *
   2717      * @see #getOverScrollMode()
   2718      * @see #setOverScrollMode(int)
   2719      */
   2720     public static final int OVER_SCROLL_ALWAYS = 0;
   2721 
   2722     /**
   2723      * Allow a user to over-scroll this view only if the content is large
   2724      * enough to meaningfully scroll, provided it is a view that can scroll.
   2725      *
   2726      * @see #getOverScrollMode()
   2727      * @see #setOverScrollMode(int)
   2728      */
   2729     public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1;
   2730 
   2731     /**
   2732      * Never allow a user to over-scroll this view.
   2733      *
   2734      * @see #getOverScrollMode()
   2735      * @see #setOverScrollMode(int)
   2736      */
   2737     public static final int OVER_SCROLL_NEVER = 2;
   2738 
   2739     /**
   2740      * Special constant for {@link #setSystemUiVisibility(int)}: View has
   2741      * requested the system UI (status bar) to be visible (the default).
   2742      *
   2743      * @see #setSystemUiVisibility(int)
   2744      */
   2745     public static final int SYSTEM_UI_FLAG_VISIBLE = 0;
   2746 
   2747     /**
   2748      * Flag for {@link #setSystemUiVisibility(int)}: View has requested the
   2749      * system UI to enter an unobtrusive "low profile" mode.
   2750      *
   2751      * <p>This is for use in games, book readers, video players, or any other
   2752      * "immersive" application where the usual system chrome is deemed too distracting.
   2753      *
   2754      * <p>In low profile mode, the status bar and/or navigation icons may dim.
   2755      *
   2756      * @see #setSystemUiVisibility(int)
   2757      */
   2758     public static final int SYSTEM_UI_FLAG_LOW_PROFILE = 0x00000001;
   2759 
   2760     /**
   2761      * Flag for {@link #setSystemUiVisibility(int)}: View has requested that the
   2762      * system navigation be temporarily hidden.
   2763      *
   2764      * <p>This is an even less obtrusive state than that called for by
   2765      * {@link #SYSTEM_UI_FLAG_LOW_PROFILE}; on devices that draw essential navigation controls
   2766      * (Home, Back, and the like) on screen, <code>SYSTEM_UI_FLAG_HIDE_NAVIGATION</code> will cause
   2767      * those to disappear. This is useful (in conjunction with the
   2768      * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN FLAG_FULLSCREEN} and
   2769      * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN FLAG_LAYOUT_IN_SCREEN}
   2770      * window flags) for displaying content using every last pixel on the display.
   2771      *
   2772      * <p>There is a limitation: because navigation controls are so important, the least user
   2773      * interaction will cause them to reappear immediately.  When this happens, both
   2774      * this flag and {@link #SYSTEM_UI_FLAG_FULLSCREEN} will be cleared automatically,
   2775      * so that both elements reappear at the same time.
   2776      *
   2777      * @see #setSystemUiVisibility(int)
   2778      */
   2779     public static final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 0x00000002;
   2780 
   2781     /**
   2782      * Flag for {@link #setSystemUiVisibility(int)}: View has requested to go
   2783      * into the normal fullscreen mode so that its content can take over the screen
   2784      * while still allowing the user to interact with the application.
   2785      *
   2786      * <p>This has the same visual effect as
   2787      * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN
   2788      * WindowManager.LayoutParams.FLAG_FULLSCREEN},
   2789      * meaning that non-critical screen decorations (such as the status bar) will be
   2790      * hidden while the user is in the View's window, focusing the experience on
   2791      * that content.  Unlike the window flag, if you are using ActionBar in
   2792      * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY
   2793      * Window.FEATURE_ACTION_BAR_OVERLAY}, then enabling this flag will also
   2794      * hide the action bar.
   2795      *
   2796      * <p>This approach to going fullscreen is best used over the window flag when
   2797      * it is a transient state -- that is, the application does this at certain
   2798      * points in its user interaction where it wants to allow the user to focus
   2799      * on content, but not as a continuous state.  For situations where the application
   2800      * would like to simply stay full screen the entire time (such as a game that
   2801      * wants to take over the screen), the
   2802      * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN window flag}
   2803      * is usually a better approach.  The state set here will be removed by the system
   2804      * in various situations (such as the user moving to another application) like
   2805      * the other system UI states.
   2806      *
   2807      * <p>When using this flag, the application should provide some easy facility
   2808      * for the user to go out of it.  A common example would be in an e-book
   2809      * reader, where tapping on the screen brings back whatever screen and UI
   2810      * decorations that had been hidden while the user was immersed in reading
   2811      * the book.
   2812      *
   2813      * @see #setSystemUiVisibility(int)
   2814      */
   2815     public static final int SYSTEM_UI_FLAG_FULLSCREEN = 0x00000004;
   2816 
   2817     /**
   2818      * Flag for {@link #setSystemUiVisibility(int)}: When using other layout
   2819      * flags, we would like a stable view of the content insets given to
   2820      * {@link #fitSystemWindows(Rect)}.  This means that the insets seen there
   2821      * will always represent the worst case that the application can expect
   2822      * as a continuous state.  In the stock Android UI this is the space for
   2823      * the system bar, nav bar, and status bar, but not more transient elements
   2824      * such as an input method.
   2825      *
   2826      * The stable layout your UI sees is based on the system UI modes you can
   2827      * switch to.  That is, if you specify {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}
   2828      * then you will get a stable layout for changes of the
   2829      * {@link #SYSTEM_UI_FLAG_FULLSCREEN} mode; if you specify
   2830      * {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} and
   2831      * {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, then you can transition
   2832      * to {@link #SYSTEM_UI_FLAG_FULLSCREEN} and {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}
   2833      * with a stable layout.  (Note that you should avoid using
   2834      * {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION} by itself.)
   2835      *
   2836      * If you have set the window flag {@link WindowManager.LayoutParams#FLAG_FULLSCREEN}
   2837      * to hide the status bar (instead of using {@link #SYSTEM_UI_FLAG_FULLSCREEN}),
   2838      * then a hidden status bar will be considered a "stable" state for purposes
   2839      * here.  This allows your UI to continually hide the status bar, while still
   2840      * using the system UI flags to hide the action bar while still retaining
   2841      * a stable layout.  Note that changing the window fullscreen flag will never
   2842      * provide a stable layout for a clean transition.
   2843      *
   2844      * <p>If you are using ActionBar in
   2845      * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY
   2846      * Window.FEATURE_ACTION_BAR_OVERLAY}, this flag will also impact the
   2847      * insets it adds to those given to the application.
   2848      */
   2849     public static final int SYSTEM_UI_FLAG_LAYOUT_STABLE = 0x00000100;
   2850 
   2851     /**
   2852      * Flag for {@link #setSystemUiVisibility(int)}: View would like its window
   2853      * to be laid out as if it has requested
   2854      * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, even if it currently hasn't.  This
   2855      * allows it to avoid artifacts when switching in and out of that mode, at
   2856      * the expense that some of its user interface may be covered by screen
   2857      * decorations when they are shown.  You can perform layout of your inner
   2858      * UI elements to account for the navigation system UI through the
   2859      * {@link #fitSystemWindows(Rect)} method.
   2860      */
   2861     public static final int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = 0x00000200;
   2862 
   2863     /**
   2864      * Flag for {@link #setSystemUiVisibility(int)}: View would like its window
   2865      * to be laid out as if it has requested
   2866      * {@link #SYSTEM_UI_FLAG_FULLSCREEN}, even if it currently hasn't.  This
   2867      * allows it to avoid artifacts when switching in and out of that mode, at
   2868      * the expense that some of its user interface may be covered by screen
   2869      * decorations when they are shown.  You can perform layout of your inner
   2870      * UI elements to account for non-fullscreen system UI through the
   2871      * {@link #fitSystemWindows(Rect)} method.
   2872      */
   2873     public static final int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 0x00000400;
   2874 
   2875     /**
   2876      * Flag for {@link #setSystemUiVisibility(int)}: View would like to remain interactive when
   2877      * hiding the navigation bar with {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}.  If this flag is
   2878      * not set, {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION} will be force cleared by the system on any
   2879      * user interaction.
   2880      * <p>Since this flag is a modifier for {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, it only
   2881      * has an effect when used in combination with that flag.</p>
   2882      */
   2883     public static final int SYSTEM_UI_FLAG_IMMERSIVE = 0x00000800;
   2884 
   2885     /**
   2886      * Flag for {@link #setSystemUiVisibility(int)}: View would like to remain interactive when
   2887      * hiding the status bar with {@link #SYSTEM_UI_FLAG_FULLSCREEN} and/or hiding the navigation
   2888      * bar with {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}.  Use this flag to create an immersive
   2889      * experience while also hiding the system bars.  If this flag is not set,
   2890      * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION} will be force cleared by the system on any user
   2891      * interaction, and {@link #SYSTEM_UI_FLAG_FULLSCREEN} will be force-cleared by the system
   2892      * if the user swipes from the top of the screen.
   2893      * <p>When system bars are hidden in immersive mode, they can be revealed temporarily with
   2894      * system gestures, such as swiping from the top of the screen.  These transient system bars
   2895      * will overlay apps content, may have some degree of transparency, and will automatically
   2896      * hide after a short timeout.
   2897      * </p><p>Since this flag is a modifier for {@link #SYSTEM_UI_FLAG_FULLSCREEN} and
   2898      * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, it only has an effect when used in combination
   2899      * with one or both of those flags.</p>
   2900      */
   2901     public static final int SYSTEM_UI_FLAG_IMMERSIVE_STICKY = 0x00001000;
   2902 
   2903     /**
   2904      * Flag for {@link #setSystemUiVisibility(int)}: Requests the status bar to draw in a mode that
   2905      * is compatible with light status bar backgrounds.
   2906      *
   2907      * <p>For this to take effect, the window must request
   2908      * {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
   2909      *         FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} but not
   2910      * {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_STATUS
   2911      *         FLAG_TRANSLUCENT_STATUS}.
   2912      *
   2913      * @see android.R.attr#windowLightStatusBar
   2914      */
   2915     public static final int SYSTEM_UI_FLAG_LIGHT_STATUS_BAR = 0x00002000;
   2916 
   2917     /**
   2918      * @deprecated Use {@link #SYSTEM_UI_FLAG_LOW_PROFILE} instead.
   2919      */
   2920     public static final int STATUS_BAR_HIDDEN = SYSTEM_UI_FLAG_LOW_PROFILE;
   2921 
   2922     /**
   2923      * @deprecated Use {@link #SYSTEM_UI_FLAG_VISIBLE} instead.
   2924      */
   2925     public static final int STATUS_BAR_VISIBLE = SYSTEM_UI_FLAG_VISIBLE;
   2926 
   2927     /**
   2928      * @hide
   2929      *
   2930      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   2931      * out of the public fields to keep the undefined bits out of the developer's way.
   2932      *
   2933      * Flag to make the status bar not expandable.  Unless you also
   2934      * set {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show.
   2935      */
   2936     public static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000;
   2937 
   2938     /**
   2939      * @hide
   2940      *
   2941      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   2942      * out of the public fields to keep the undefined bits out of the developer's way.
   2943      *
   2944      * Flag to hide notification icons and scrolling ticker text.
   2945      */
   2946     public static final int STATUS_BAR_DISABLE_NOTIFICATION_ICONS = 0x00020000;
   2947 
   2948     /**
   2949      * @hide
   2950      *
   2951      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   2952      * out of the public fields to keep the undefined bits out of the developer's way.
   2953      *
   2954      * Flag to disable incoming notification alerts.  This will not block
   2955      * icons, but it will block sound, vibrating and other visual or aural notifications.
   2956      */
   2957     public static final int STATUS_BAR_DISABLE_NOTIFICATION_ALERTS = 0x00040000;
   2958 
   2959     /**
   2960      * @hide
   2961      *
   2962      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   2963      * out of the public fields to keep the undefined bits out of the developer's way.
   2964      *
   2965      * Flag to hide only the scrolling ticker.  Note that
   2966      * {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS} implies
   2967      * {@link #STATUS_BAR_DISABLE_NOTIFICATION_TICKER}.
   2968      */
   2969     public static final int STATUS_BAR_DISABLE_NOTIFICATION_TICKER = 0x00080000;
   2970 
   2971     /**
   2972      * @hide
   2973      *
   2974      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   2975      * out of the public fields to keep the undefined bits out of the developer's way.
   2976      *
   2977      * Flag to hide the center system info area.
   2978      */
   2979     public static final int STATUS_BAR_DISABLE_SYSTEM_INFO = 0x00100000;
   2980 
   2981     /**
   2982      * @hide
   2983      *
   2984      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   2985      * out of the public fields to keep the undefined bits out of the developer's way.
   2986      *
   2987      * Flag to hide only the home button.  Don't use this
   2988      * unless you're a special part of the system UI (i.e., setup wizard, keyguard).
   2989      */
   2990     public static final int STATUS_BAR_DISABLE_HOME = 0x00200000;
   2991 
   2992     /**
   2993      * @hide
   2994      *
   2995      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   2996      * out of the public fields to keep the undefined bits out of the developer's way.
   2997      *
   2998      * Flag to hide only the back button. Don't use this
   2999      * unless you're a special part of the system UI (i.e., setup wizard, keyguard).
   3000      */
   3001     public static final int STATUS_BAR_DISABLE_BACK = 0x00400000;
   3002 
   3003     /**
   3004      * @hide
   3005      *
   3006      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   3007      * out of the public fields to keep the undefined bits out of the developer's way.
   3008      *
   3009      * Flag to hide only the clock.  You might use this if your activity has
   3010      * its own clock making the status bar's clock redundant.
   3011      */
   3012     public static final int STATUS_BAR_DISABLE_CLOCK = 0x00800000;
   3013 
   3014     /**
   3015      * @hide
   3016      *
   3017      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   3018      * out of the public fields to keep the undefined bits out of the developer's way.
   3019      *
   3020      * Flag to hide only the recent apps button. Don't use this
   3021      * unless you're a special part of the system UI (i.e., setup wizard, keyguard).
   3022      */
   3023     public static final int STATUS_BAR_DISABLE_RECENT = 0x01000000;
   3024 
   3025     /**
   3026      * @hide
   3027      *
   3028      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   3029      * out of the public fields to keep the undefined bits out of the developer's way.
   3030      *
   3031      * Flag to disable the global search gesture. Don't use this
   3032      * unless you're a special part of the system UI (i.e., setup wizard, keyguard).
   3033      */
   3034     public static final int STATUS_BAR_DISABLE_SEARCH = 0x02000000;
   3035 
   3036     /**
   3037      * @hide
   3038      *
   3039      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   3040      * out of the public fields to keep the undefined bits out of the developer's way.
   3041      *
   3042      * Flag to specify that the status bar is displayed in transient mode.
   3043      */
   3044     public static final int STATUS_BAR_TRANSIENT = 0x04000000;
   3045 
   3046     /**
   3047      * @hide
   3048      *
   3049      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   3050      * out of the public fields to keep the undefined bits out of the developer's way.
   3051      *
   3052      * Flag to specify that the navigation bar is displayed in transient mode.
   3053      */
   3054     public static final int NAVIGATION_BAR_TRANSIENT = 0x08000000;
   3055 
   3056     /**
   3057      * @hide
   3058      *
   3059      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   3060      * out of the public fields to keep the undefined bits out of the developer's way.
   3061      *
   3062      * Flag to specify that the hidden status bar would like to be shown.
   3063      */
   3064     public static final int STATUS_BAR_UNHIDE = 0x10000000;
   3065 
   3066     /**
   3067      * @hide
   3068      *
   3069      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   3070      * out of the public fields to keep the undefined bits out of the developer's way.
   3071      *
   3072      * Flag to specify that the hidden navigation bar would like to be shown.
   3073      */
   3074     public static final int NAVIGATION_BAR_UNHIDE = 0x20000000;
   3075 
   3076     /**
   3077      * @hide
   3078      *
   3079      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   3080      * out of the public fields to keep the undefined bits out of the developer's way.
   3081      *
   3082      * Flag to specify that the status bar is displayed in translucent mode.
   3083      */
   3084     public static final int STATUS_BAR_TRANSLUCENT = 0x40000000;
   3085 
   3086     /**
   3087      * @hide
   3088      *
   3089      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   3090      * out of the public fields to keep the undefined bits out of the developer's way.
   3091      *
   3092      * Flag to specify that the navigation bar is displayed in translucent mode.
   3093      */
   3094     public static final int NAVIGATION_BAR_TRANSLUCENT = 0x80000000;
   3095 
   3096     /**
   3097      * @hide
   3098      *
   3099      * Makes navigation bar transparent (but not the status bar).
   3100      */
   3101     public static final int NAVIGATION_BAR_TRANSPARENT = 0x00008000;
   3102 
   3103     /**
   3104      * @hide
   3105      *
   3106      * Makes status bar transparent (but not the navigation bar).
   3107      */
   3108     public static final int STATUS_BAR_TRANSPARENT = 0x0000008;
   3109 
   3110     /**
   3111      * @hide
   3112      *
   3113      * Makes both status bar and navigation bar transparent.
   3114      */
   3115     public static final int SYSTEM_UI_TRANSPARENT = NAVIGATION_BAR_TRANSPARENT
   3116             | STATUS_BAR_TRANSPARENT;
   3117 
   3118     /**
   3119      * @hide
   3120      */
   3121     public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK = 0x00003FF7;
   3122 
   3123     /**
   3124      * These are the system UI flags that can be cleared by events outside
   3125      * of an application.  Currently this is just the ability to tap on the
   3126      * screen while hiding the navigation bar to have it return.
   3127      * @hide
   3128      */
   3129     public static final int SYSTEM_UI_CLEARABLE_FLAGS =
   3130             SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_HIDE_NAVIGATION
   3131             | SYSTEM_UI_FLAG_FULLSCREEN;
   3132 
   3133     /**
   3134      * Flags that can impact the layout in relation to system UI.
   3135      */
   3136     public static final int SYSTEM_UI_LAYOUT_FLAGS =
   3137             SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
   3138             | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
   3139 
   3140     /** @hide */
   3141     @IntDef(flag = true,
   3142             value = { FIND_VIEWS_WITH_TEXT, FIND_VIEWS_WITH_CONTENT_DESCRIPTION })
   3143     @Retention(RetentionPolicy.SOURCE)
   3144     public @interface FindViewFlags {}
   3145 
   3146     /**
   3147      * Find views that render the specified text.
   3148      *
   3149      * @see #findViewsWithText(ArrayList, CharSequence, int)
   3150      */
   3151     public static final int FIND_VIEWS_WITH_TEXT = 0x00000001;
   3152 
   3153     /**
   3154      * Find find views that contain the specified content description.
   3155      *
   3156      * @see #findViewsWithText(ArrayList, CharSequence, int)
   3157      */
   3158     public static final int FIND_VIEWS_WITH_CONTENT_DESCRIPTION = 0x00000002;
   3159 
   3160     /**
   3161      * Find views that contain {@link AccessibilityNodeProvider}. Such
   3162      * a View is a root of virtual view hierarchy and may contain the searched
   3163      * text. If this flag is set Views with providers are automatically
   3164      * added and it is a responsibility of the client to call the APIs of
   3165      * the provider to determine whether the virtual tree rooted at this View
   3166      * contains the text, i.e. getting the list of {@link AccessibilityNodeInfo}s
   3167      * representing the virtual views with this text.
   3168      *
   3169      * @see #findViewsWithText(ArrayList, CharSequence, int)
   3170      *
   3171      * @hide
   3172      */
   3173     public static final int FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS = 0x00000004;
   3174 
   3175     /**
   3176      * The undefined cursor position.
   3177      *
   3178      * @hide
   3179      */
   3180     public static final int ACCESSIBILITY_CURSOR_POSITION_UNDEFINED = -1;
   3181 
   3182     /**
   3183      * Indicates that the screen has changed state and is now off.
   3184      *
   3185      * @see #onScreenStateChanged(int)
   3186      */
   3187     public static final int SCREEN_STATE_OFF = 0x0;
   3188 
   3189     /**
   3190      * Indicates that the screen has changed state and is now on.
   3191      *
   3192      * @see #onScreenStateChanged(int)
   3193      */
   3194     public static final int SCREEN_STATE_ON = 0x1;
   3195 
   3196     /**
   3197      * Indicates no axis of view scrolling.
   3198      */
   3199     public static final int SCROLL_AXIS_NONE = 0;
   3200 
   3201     /**
   3202      * Indicates scrolling along the horizontal axis.
   3203      */
   3204     public static final int SCROLL_AXIS_HORIZONTAL = 1 << 0;
   3205 
   3206     /**
   3207      * Indicates scrolling along the vertical axis.
   3208      */
   3209     public static final int SCROLL_AXIS_VERTICAL = 1 << 1;
   3210 
   3211     /**
   3212      * Controls the over-scroll mode for this view.
   3213      * See {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)},
   3214      * {@link #OVER_SCROLL_ALWAYS}, {@link #OVER_SCROLL_IF_CONTENT_SCROLLS},
   3215      * and {@link #OVER_SCROLL_NEVER}.
   3216      */
   3217     private int mOverScrollMode;
   3218 
   3219     /**
   3220      * The parent this view is attached to.
   3221      * {@hide}
   3222      *
   3223      * @see #getParent()
   3224      */
   3225     protected ViewParent mParent;
   3226 
   3227     /**
   3228      * {@hide}
   3229      */
   3230     AttachInfo mAttachInfo;
   3231 
   3232     /**
   3233      * {@hide}
   3234      */
   3235     @ViewDebug.ExportedProperty(flagMapping = {
   3236         @ViewDebug.FlagToString(mask = PFLAG_FORCE_LAYOUT, equals = PFLAG_FORCE_LAYOUT,
   3237                 name = "FORCE_LAYOUT"),
   3238         @ViewDebug.FlagToString(mask = PFLAG_LAYOUT_REQUIRED, equals = PFLAG_LAYOUT_REQUIRED,
   3239                 name = "LAYOUT_REQUIRED"),
   3240         @ViewDebug.FlagToString(mask = PFLAG_DRAWING_CACHE_VALID, equals = PFLAG_DRAWING_CACHE_VALID,
   3241             name = "DRAWING_CACHE_INVALID", outputIf = false),
   3242         @ViewDebug.FlagToString(mask = PFLAG_DRAWN, equals = PFLAG_DRAWN, name = "DRAWN", outputIf = true),
   3243         @ViewDebug.FlagToString(mask = PFLAG_DRAWN, equals = PFLAG_DRAWN, name = "NOT_DRAWN", outputIf = false),
   3244         @ViewDebug.FlagToString(mask = PFLAG_DIRTY_MASK, equals = PFLAG_DIRTY_OPAQUE, name = "DIRTY_OPAQUE"),
   3245         @ViewDebug.FlagToString(mask = PFLAG_DIRTY_MASK, equals = PFLAG_DIRTY, name = "DIRTY")
   3246     }, formatToHexString = true)
   3247     int mPrivateFlags;
   3248     int mPrivateFlags2;
   3249     int mPrivateFlags3;
   3250 
   3251     /**
   3252      * This view's request for the visibility of the status bar.
   3253      * @hide
   3254      */
   3255     @ViewDebug.ExportedProperty(flagMapping = {
   3256         @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_LOW_PROFILE,
   3257                                 equals = SYSTEM_UI_FLAG_LOW_PROFILE,
   3258                                 name = "SYSTEM_UI_FLAG_LOW_PROFILE", outputIf = true),
   3259         @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_HIDE_NAVIGATION,
   3260                                 equals = SYSTEM_UI_FLAG_HIDE_NAVIGATION,
   3261                                 name = "SYSTEM_UI_FLAG_HIDE_NAVIGATION", outputIf = true),
   3262         @ViewDebug.FlagToString(mask = PUBLIC_STATUS_BAR_VISIBILITY_MASK,
   3263                                 equals = SYSTEM_UI_FLAG_VISIBLE,
   3264                                 name = "SYSTEM_UI_FLAG_VISIBLE", outputIf = true)
   3265     }, formatToHexString = true)
   3266     int mSystemUiVisibility;
   3267 
   3268     /**
   3269      * Reference count for transient state.
   3270      * @see #setHasTransientState(boolean)
   3271      */
   3272     int mTransientStateCount = 0;
   3273 
   3274     /**
   3275      * Count of how many windows this view has been attached to.
   3276      */
   3277     int mWindowAttachCount;
   3278 
   3279     /**
   3280      * The layout parameters associated with this view and used by the parent
   3281      * {@link android.view.ViewGroup} to determine how this view should be
   3282      * laid out.
   3283      * {@hide}
   3284      */
   3285     protected ViewGroup.LayoutParams mLayoutParams;
   3286 
   3287     /**
   3288      * The view flags hold various views states.
   3289      * {@hide}
   3290      */
   3291     @ViewDebug.ExportedProperty(formatToHexString = true)
   3292     int mViewFlags;
   3293 
   3294     static class TransformationInfo {
   3295         /**
   3296          * The transform matrix for the View. This transform is calculated internally
   3297          * based on the translation, rotation, and scale properties.
   3298          *
   3299          * Do *not* use this variable directly; instead call getMatrix(), which will
   3300          * load the value from the View's RenderNode.
   3301          */
   3302         private final Matrix mMatrix = new Matrix();
   3303 
   3304         /**
   3305          * The inverse transform matrix for the View. This transform is calculated
   3306          * internally based on the translation, rotation, and scale properties.
   3307          *
   3308          * Do *not* use this variable directly; instead call getInverseMatrix(),
   3309          * which will load the value from the View's RenderNode.
   3310          */
   3311         private Matrix mInverseMatrix;
   3312 
   3313         /**
   3314          * The opacity of the View. This is a value from 0 to 1, where 0 means
   3315          * completely transparent and 1 means completely opaque.
   3316          */
   3317         @ViewDebug.ExportedProperty
   3318         float mAlpha = 1f;
   3319 
   3320         /**
   3321          * The opacity of the view as manipulated by the Fade transition. This is a hidden
   3322          * property only used by transitions, which is composited with the other alpha
   3323          * values to calculate the final visual alpha value.
   3324          */
   3325         float mTransitionAlpha = 1f;
   3326     }
   3327 
   3328     TransformationInfo mTransformationInfo;
   3329 
   3330     /**
   3331      * Current clip bounds. to which all drawing of this view are constrained.
   3332      */
   3333     Rect mClipBounds = null;
   3334 
   3335     private boolean mLastIsOpaque;
   3336 
   3337     /**
   3338      * The distance in pixels from the left edge of this view's parent
   3339      * to the left edge of this view.
   3340      * {@hide}
   3341      */
   3342     @ViewDebug.ExportedProperty(category = "layout")
   3343     protected int mLeft;
   3344     /**
   3345      * The distance in pixels from the left edge of this view's parent
   3346      * to the right edge of this view.
   3347      * {@hide}
   3348      */
   3349     @ViewDebug.ExportedProperty(category = "layout")
   3350     protected int mRight;
   3351     /**
   3352      * The distance in pixels from the top edge of this view's parent
   3353      * to the top edge of this view.
   3354      * {@hide}
   3355      */
   3356     @ViewDebug.ExportedProperty(category = "layout")
   3357     protected int mTop;
   3358     /**
   3359      * The distance in pixels from the top edge of this view's parent
   3360      * to the bottom edge of this view.
   3361      * {@hide}
   3362      */
   3363     @ViewDebug.ExportedProperty(category = "layout")
   3364     protected int mBottom;
   3365 
   3366     /**
   3367      * The offset, in pixels, by which the content of this view is scrolled
   3368      * horizontally.
   3369      * {@hide}
   3370      */
   3371     @ViewDebug.ExportedProperty(category = "scrolling")
   3372     protected int mScrollX;
   3373     /**
   3374      * The offset, in pixels, by which the content of this view is scrolled
   3375      * vertically.
   3376      * {@hide}
   3377      */
   3378     @ViewDebug.ExportedProperty(category = "scrolling")
   3379     protected int mScrollY;
   3380 
   3381     /**
   3382      * The left padding in pixels, that is the distance in pixels between the
   3383      * left edge of this view and the left edge of its content.
   3384      * {@hide}
   3385      */
   3386     @ViewDebug.ExportedProperty(category = "padding")
   3387     protected int mPaddingLeft = 0;
   3388     /**
   3389      * The right padding in pixels, that is the distance in pixels between the
   3390      * right edge of this view and the right edge of its content.
   3391      * {@hide}
   3392      */
   3393     @ViewDebug.ExportedProperty(category = "padding")
   3394     protected int mPaddingRight = 0;
   3395     /**
   3396      * The top padding in pixels, that is the distance in pixels between the
   3397      * top edge of this view and the top edge of its content.
   3398      * {@hide}
   3399      */
   3400     @ViewDebug.ExportedProperty(category = "padding")
   3401     protected int mPaddingTop;
   3402     /**
   3403      * The bottom padding in pixels, that is the distance in pixels between the
   3404      * bottom edge of this view and the bottom edge of its content.
   3405      * {@hide}
   3406      */
   3407     @ViewDebug.ExportedProperty(category = "padding")
   3408     protected int mPaddingBottom;
   3409 
   3410     /**
   3411      * The layout insets in pixels, that is the distance in pixels between the
   3412      * visible edges of this view its bounds.
   3413      */
   3414     private Insets mLayoutInsets;
   3415 
   3416     /**
   3417      * Briefly describes the view and is primarily used for accessibility support.
   3418      */
   3419     private CharSequence mContentDescription;
   3420 
   3421     /**
   3422      * Specifies the id of a view for which this view serves as a label for
   3423      * accessibility purposes.
   3424      */
   3425     private int mLabelForId = View.NO_ID;
   3426 
   3427     /**
   3428      * Predicate for matching labeled view id with its label for
   3429      * accessibility purposes.
   3430      */
   3431     private MatchLabelForPredicate mMatchLabelForPredicate;
   3432 
   3433     /**
   3434      * Specifies a view before which this one is visited in accessibility traversal.
   3435      */
   3436     private int mAccessibilityTraversalBeforeId = NO_ID;
   3437 
   3438     /**
   3439      * Specifies a view after which this one is visited in accessibility traversal.
   3440      */
   3441     private int mAccessibilityTraversalAfterId = NO_ID;
   3442 
   3443     /**
   3444      * Predicate for matching a view by its id.
   3445      */
   3446     private MatchIdPredicate mMatchIdPredicate;
   3447 
   3448     /**
   3449      * Cache the paddingRight set by the user to append to the scrollbar's size.
   3450      *
   3451      * @hide
   3452      */
   3453     @ViewDebug.ExportedProperty(category = "padding")
   3454     protected int mUserPaddingRight;
   3455 
   3456     /**
   3457      * Cache the paddingBottom set by the user to append to the scrollbar's size.
   3458      *
   3459      * @hide
   3460      */
   3461     @ViewDebug.ExportedProperty(category = "padding")
   3462     protected int mUserPaddingBottom;
   3463 
   3464     /**
   3465      * Cache the paddingLeft set by the user to append to the scrollbar's size.
   3466      *
   3467      * @hide
   3468      */
   3469     @ViewDebug.ExportedProperty(category = "padding")
   3470     protected int mUserPaddingLeft;
   3471 
   3472     /**
   3473      * Cache the paddingStart set by the user to append to the scrollbar's size.
   3474      *
   3475      */
   3476     @ViewDebug.ExportedProperty(category = "padding")
   3477     int mUserPaddingStart;
   3478 
   3479     /**
   3480      * Cache the paddingEnd set by the user to append to the scrollbar's size.
   3481      *
   3482      */
   3483     @ViewDebug.ExportedProperty(category = "padding")
   3484     int mUserPaddingEnd;
   3485 
   3486     /**
   3487      * Cache initial left padding.
   3488      *
   3489      * @hide
   3490      */
   3491     int mUserPaddingLeftInitial;
   3492 
   3493     /**
   3494      * Cache initial right padding.
   3495      *
   3496      * @hide
   3497      */
   3498     int mUserPaddingRightInitial;
   3499 
   3500     /**
   3501      * Default undefined padding
   3502      */
   3503     private static final int UNDEFINED_PADDING = Integer.MIN_VALUE;
   3504 
   3505     /**
   3506      * Cache if a left padding has been defined
   3507      */
   3508     private boolean mLeftPaddingDefined = false;
   3509 
   3510     /**
   3511      * Cache if a right padding has been defined
   3512      */
   3513     private boolean mRightPaddingDefined = false;
   3514 
   3515     /**
   3516      * @hide
   3517      */
   3518     int mOldWidthMeasureSpec = Integer.MIN_VALUE;
   3519     /**
   3520      * @hide
   3521      */
   3522     int mOldHeightMeasureSpec = Integer.MIN_VALUE;
   3523 
   3524     private LongSparseLongArray mMeasureCache;
   3525 
   3526     @ViewDebug.ExportedProperty(deepExport = true, prefix = "bg_")
   3527     private Drawable mBackground;
   3528     private TintInfo mBackgroundTint;
   3529 
   3530     @ViewDebug.ExportedProperty(deepExport = true, prefix = "fg_")
   3531     private ForegroundInfo mForegroundInfo;
   3532 
   3533     private Drawable mScrollIndicatorDrawable;
   3534 
   3535     /**
   3536      * RenderNode used for backgrounds.
   3537      * <p>
   3538      * When non-null and valid, this is expected to contain an up-to-date copy
   3539      * of the background drawable. It is cleared on temporary detach, and reset
   3540      * on cleanup.
   3541      */
   3542     private RenderNode mBackgroundRenderNode;
   3543 
   3544     private int mBackgroundResource;
   3545     private boolean mBackgroundSizeChanged;
   3546 
   3547     private String mTransitionName;
   3548 
   3549     static class TintInfo {
   3550         ColorStateList mTintList;
   3551         PorterDuff.Mode mTintMode;
   3552         boolean mHasTintMode;
   3553         boolean mHasTintList;
   3554     }
   3555 
   3556     private static class ForegroundInfo {
   3557         private Drawable mDrawable;
   3558         private TintInfo mTintInfo;
   3559         private int mGravity = Gravity.FILL;
   3560         private boolean mInsidePadding = true;
   3561         private boolean mBoundsChanged = true;
   3562         private final Rect mSelfBounds = new Rect();
   3563         private final Rect mOverlayBounds = new Rect();
   3564     }
   3565 
   3566     static class ListenerInfo {
   3567         /**
   3568          * Listener used to dispatch focus change events.
   3569          * This field should be made private, so it is hidden from the SDK.
   3570          * {@hide}
   3571          */
   3572         protected OnFocusChangeListener mOnFocusChangeListener;
   3573 
   3574         /**
   3575          * Listeners for layout change events.
   3576          */
   3577         private ArrayList<OnLayoutChangeListener> mOnLayoutChangeListeners;
   3578 
   3579         protected OnScrollChangeListener mOnScrollChangeListener;
   3580 
   3581         /**
   3582          * Listeners for attach events.
   3583          */
   3584         private CopyOnWriteArrayList<OnAttachStateChangeListener> mOnAttachStateChangeListeners;
   3585 
   3586         /**
   3587          * Listener used to dispatch click events.
   3588          * This field should be made private, so it is hidden from the SDK.
   3589          * {@hide}
   3590          */
   3591         public OnClickListener mOnClickListener;
   3592 
   3593         /**
   3594          * Listener used to dispatch long click events.
   3595          * This field should be made private, so it is hidden from the SDK.
   3596          * {@hide}
   3597          */
   3598         protected OnLongClickListener mOnLongClickListener;
   3599 
   3600         /**
   3601          * Listener used to dispatch context click events. This field should be made private, so it
   3602          * is hidden from the SDK.
   3603          * {@hide}
   3604          */
   3605         protected OnContextClickListener mOnContextClickListener;
   3606 
   3607         /**
   3608          * Listener used to build the context menu.
   3609          * This field should be made private, so it is hidden from the SDK.
   3610          * {@hide}
   3611          */
   3612         protected OnCreateContextMenuListener mOnCreateContextMenuListener;
   3613 
   3614         private OnKeyListener mOnKeyListener;
   3615 
   3616         private OnTouchListener mOnTouchListener;
   3617 
   3618         private OnHoverListener mOnHoverListener;
   3619 
   3620         private OnGenericMotionListener mOnGenericMotionListener;
   3621 
   3622         private OnDragListener mOnDragListener;
   3623 
   3624         private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener;
   3625 
   3626         OnApplyWindowInsetsListener mOnApplyWindowInsetsListener;
   3627     }
   3628 
   3629     ListenerInfo mListenerInfo;
   3630 
   3631     // Temporary values used to hold (x,y) coordinates when delegating from the
   3632     // two-arg performLongClick() method to the legacy no-arg version.
   3633     private float mLongClickX = Float.NaN;
   3634     private float mLongClickY = Float.NaN;
   3635 
   3636     /**
   3637      * The application environment this view lives in.
   3638      * This field should be made private, so it is hidden from the SDK.
   3639      * {@hide}
   3640      */
   3641     @ViewDebug.ExportedProperty(deepExport = true)
   3642     protected Context mContext;
   3643 
   3644     private final Resources mResources;
   3645 
   3646     private ScrollabilityCache mScrollCache;
   3647 
   3648     private int[] mDrawableState = null;
   3649 
   3650     ViewOutlineProvider mOutlineProvider = ViewOutlineProvider.BACKGROUND;
   3651 
   3652     /**
   3653      * Animator that automatically runs based on state changes.
   3654      */
   3655     private StateListAnimator mStateListAnimator;
   3656 
   3657     /**
   3658      * When this view has focus and the next focus is {@link #FOCUS_LEFT},
   3659      * the user may specify which view to go to next.
   3660      */
   3661     private int mNextFocusLeftId = View.NO_ID;
   3662 
   3663     /**
   3664      * When this view has focus and the next focus is {@link #FOCUS_RIGHT},
   3665      * the user may specify which view to go to next.
   3666      */
   3667     private int mNextFocusRightId = View.NO_ID;
   3668 
   3669     /**
   3670      * When this view has focus and the next focus is {@link #FOCUS_UP},
   3671      * the user may specify which view to go to next.
   3672      */
   3673     private int mNextFocusUpId = View.NO_ID;
   3674 
   3675     /**
   3676      * When this view has focus and the next focus is {@link #FOCUS_DOWN},
   3677      * the user may specify which view to go to next.
   3678      */
   3679     private int mNextFocusDownId = View.NO_ID;
   3680 
   3681     /**
   3682      * When this view has focus and the next focus is {@link #FOCUS_FORWARD},
   3683      * the user may specify which view to go to next.
   3684      */
   3685     int mNextFocusForwardId = View.NO_ID;
   3686 
   3687     private CheckForLongPress mPendingCheckForLongPress;
   3688     private CheckForTap mPendingCheckForTap = null;
   3689     private PerformClick mPerformClick;
   3690     private SendViewScrolledAccessibilityEvent mSendViewScrolledAccessibilityEvent;
   3691 
   3692     private UnsetPressedState mUnsetPressedState;
   3693 
   3694     /**
   3695      * Whether the long press's action has been invoked.  The tap's action is invoked on the
   3696      * up event while a long press is invoked as soon as the long press duration is reached, so
   3697      * a long press could be performed before the tap is checked, in which case the tap's action
   3698      * should not be invoked.
   3699      */
   3700     private boolean mHasPerformedLongPress;
   3701 
   3702     /**
   3703      * Whether a context click button is currently pressed down. This is true when the stylus is
   3704      * touching the screen and the primary button has been pressed, or if a mouse's right button is
   3705      * pressed. This is false once the button is released or if the stylus has been lifted.
   3706      */
   3707     private boolean mInContextButtonPress;
   3708 
   3709     /**
   3710      * Whether the next up event should be ignored for the purposes of gesture recognition. This is
   3711      * true after a stylus button press has occured, when the next up event should not be recognized
   3712      * as a tap.
   3713      */
   3714     private boolean mIgnoreNextUpEvent;
   3715 
   3716     /**
   3717      * The minimum height of the view. We'll try our best to have the height
   3718      * of this view to at least this amount.
   3719      */
   3720     @ViewDebug.ExportedProperty(category = "measurement")
   3721     private int mMinHeight;
   3722 
   3723     /**
   3724      * The minimum width of the view. We'll try our best to have the width
   3725      * of this view to at least this amount.
   3726      */
   3727     @ViewDebug.ExportedProperty(category = "measurement")
   3728     private int mMinWidth;
   3729 
   3730     /**
   3731      * The delegate to handle touch events that are physically in this view
   3732      * but should be handled by another view.
   3733      */
   3734     private TouchDelegate mTouchDelegate = null;
   3735 
   3736     /**
   3737      * Solid color to use as a background when creating the drawing cache. Enables
   3738      * the cache to use 16 bit bitmaps instead of 32 bit.
   3739      */
   3740     private int mDrawingCacheBackgroundColor = 0;
   3741 
   3742     /**
   3743      * Special tree observer used when mAttachInfo is null.
   3744      */
   3745     private ViewTreeObserver mFloatingTreeObserver;
   3746 
   3747     /**
   3748      * Cache the touch slop from the context that created the view.
   3749      */
   3750     private int mTouchSlop;
   3751 
   3752     /**
   3753      * Object that handles automatic animation of view properties.
   3754      */
   3755     private ViewPropertyAnimator mAnimator = null;
   3756 
   3757     /**
   3758      * List of registered FrameMetricsObservers.
   3759      */
   3760     private ArrayList<FrameMetricsObserver> mFrameMetricsObservers;
   3761 
   3762     /**
   3763      * Flag indicating that a drag can cross window boundaries.  When
   3764      * {@link #startDragAndDrop(ClipData, DragShadowBuilder, Object, int)} is called
   3765      * with this flag set, all visible applications with targetSdkVersion >=
   3766      * {@link android.os.Build.VERSION_CODES#N API 24} will be able to participate
   3767      * in the drag operation and receive the dragged content.
   3768      *
   3769      * <p>If this is the only flag set, then the drag recipient will only have access to text data
   3770      * and intents contained in the {@link ClipData} object. Access to URIs contained in the
   3771      * {@link ClipData} is determined by other DRAG_FLAG_GLOBAL_* flags</p>
   3772      */
   3773     public static final int DRAG_FLAG_GLOBAL = 1 << 8;  // 256
   3774 
   3775     /**
   3776      * When this flag is used with {@link #DRAG_FLAG_GLOBAL}, the drag recipient will be able to
   3777      * request read access to the content URI(s) contained in the {@link ClipData} object.
   3778      * @see android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION
   3779      */
   3780     public static final int DRAG_FLAG_GLOBAL_URI_READ = Intent.FLAG_GRANT_READ_URI_PERMISSION;
   3781 
   3782     /**
   3783      * When this flag is used with {@link #DRAG_FLAG_GLOBAL}, the drag recipient will be able to
   3784      * request write access to the content URI(s) contained in the {@link ClipData} object.
   3785      * @see android.content.Intent.FLAG_GRANT_WRITE_URI_PERMISSION
   3786      */
   3787     public static final int DRAG_FLAG_GLOBAL_URI_WRITE = Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
   3788 
   3789     /**
   3790      * When this flag is used with {@link #DRAG_FLAG_GLOBAL_URI_READ} and/or {@link
   3791      * #DRAG_FLAG_GLOBAL_URI_WRITE}, the URI permission grant can be persisted across device
   3792      * reboots until explicitly revoked with
   3793      * {@link android.content.Context#revokeUriPermission(Uri,int) Context.revokeUriPermission}.
   3794      * @see android.content.Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
   3795      */
   3796     public static final int DRAG_FLAG_GLOBAL_PERSISTABLE_URI_PERMISSION =
   3797             Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION;
   3798 
   3799     /**
   3800      * When this flag is used with {@link #DRAG_FLAG_GLOBAL_URI_READ} and/or {@link
   3801      * #DRAG_FLAG_GLOBAL_URI_WRITE}, the URI permission grant applies to any URI that is a prefix
   3802      * match against the original granted URI.
   3803      * @see android.content.Intent.FLAG_GRANT_PREFIX_URI_PERMISSION
   3804      */
   3805     public static final int DRAG_FLAG_GLOBAL_PREFIX_URI_PERMISSION =
   3806             Intent.FLAG_GRANT_PREFIX_URI_PERMISSION;
   3807 
   3808     /**
   3809      * Flag indicating that the drag shadow will be opaque.  When
   3810      * {@link #startDragAndDrop(ClipData, DragShadowBuilder, Object, int)} is called
   3811      * with this flag set, the drag shadow will be opaque, otherwise, it will be semitransparent.
   3812      */
   3813     public static final int DRAG_FLAG_OPAQUE = 1 << 9;
   3814 
   3815     /**
   3816      * Vertical scroll factor cached by {@link #getVerticalScrollFactor}.
   3817      */
   3818     private float mVerticalScrollFactor;
   3819 
   3820     /**
   3821      * Position of the vertical scroll bar.
   3822      */
   3823     private int mVerticalScrollbarPosition;
   3824 
   3825     /**
   3826      * Position the scroll bar at the default position as determined by the system.
   3827      */
   3828     public static final int SCROLLBAR_POSITION_DEFAULT = 0;
   3829 
   3830     /**
   3831      * Position the scroll bar along the left edge.
   3832      */
   3833     public static final int SCROLLBAR_POSITION_LEFT = 1;
   3834 
   3835     /**
   3836      * Position the scroll bar along the right edge.
   3837      */
   3838     public static final int SCROLLBAR_POSITION_RIGHT = 2;
   3839 
   3840     /**
   3841      * Indicates that the view does not have a layer.
   3842      *
   3843      * @see #getLayerType()
   3844      * @see #setLayerType(int, android.graphics.Paint)
   3845      * @see #LAYER_TYPE_SOFTWARE
   3846      * @see #LAYER_TYPE_HARDWARE
   3847      */
   3848     public static final int LAYER_TYPE_NONE = 0;
   3849 
   3850     /**
   3851      * <p>Indicates that the view has a software layer. A software layer is backed
   3852      * by a bitmap and causes the view to be rendered using Android's software
   3853      * rendering pipeline, even if hardware acceleration is enabled.</p>
   3854      *
   3855      * <p>Software layers have various usages:</p>
   3856      * <p>When the application is not using hardware acceleration, a software layer
   3857      * is useful to apply a specific color filter and/or blending mode and/or
   3858      * translucency to a view and all its children.</p>
   3859      * <p>When the application is using hardware acceleration, a software layer
   3860      * is useful to render drawing primitives not supported by the hardware
   3861      * accelerated pipeline. It can also be used to cache a complex view tree
   3862      * into a texture and reduce the complexity of drawing operations. For instance,
   3863      * when animating a complex view tree with a translation, a software layer can
   3864      * be used to render the view tree only once.</p>
   3865      * <p>Software layers should be avoided when the affected view tree updates
   3866      * often. Every update will require to re-render the software layer, which can
   3867      * potentially be slow (particularly when hardware acceleration is turned on
   3868      * since the layer will have to be uploaded into a hardware texture after every
   3869      * update.)</p>
   3870      *
   3871      * @see #getLayerType()
   3872      * @see #setLayerType(int, android.graphics.Paint)
   3873      * @see #LAYER_TYPE_NONE
   3874      * @see #LAYER_TYPE_HARDWARE
   3875      */
   3876     public static final int LAYER_TYPE_SOFTWARE = 1;
   3877 
   3878     /**
   3879      * <p>Indicates that the view has a hardware layer. A hardware layer is backed
   3880      * by a hardware specific texture (generally Frame Buffer Objects or FBO on
   3881      * OpenGL hardware) and causes the view to be rendered using Android's hardware
   3882      * rendering pipeline, but only if hardware acceleration is turned on for the
   3883      * view hierarchy. When hardware acceleration is turned off, hardware layers
   3884      * behave exactly as {@link #LAYER_TYPE_SOFTWARE software layers}.</p>
   3885      *
   3886      * <p>A hardware layer is useful to apply a specific color filter and/or
   3887      * blending mode and/or translucency to a view and all its children.</p>
   3888      * <p>A hardware layer can be used to cache a complex view tree into a
   3889      * texture and reduce the complexity of drawing operations. For instance,
   3890      * when animating a complex view tree with a translation, a hardware layer can
   3891      * be used to render the view tree only once.</p>
   3892      * <p>A hardware layer can also be used to increase the rendering quality when
   3893      * rotation transformations are applied on a view. It can also be used to
   3894      * prevent potential clipping issues when applying 3D transforms on a view.</p>
   3895      *
   3896      * @see #getLayerType()
   3897      * @see #setLayerType(int, android.graphics.Paint)
   3898      * @see #LAYER_TYPE_NONE
   3899      * @see #LAYER_TYPE_SOFTWARE
   3900      */
   3901     public static final int LAYER_TYPE_HARDWARE = 2;
   3902 
   3903     @ViewDebug.ExportedProperty(category = "drawing", mapping = {
   3904             @ViewDebug.IntToString(from = LAYER_TYPE_NONE, to = "NONE"),
   3905             @ViewDebug.IntToString(from = LAYER_TYPE_SOFTWARE, to = "SOFTWARE"),
   3906             @ViewDebug.IntToString(from = LAYER_TYPE_HARDWARE, to = "HARDWARE")
   3907     })
   3908     int mLayerType = LAYER_TYPE_NONE;
   3909     Paint mLayerPaint;
   3910 
   3911     /**
   3912      * Set to true when drawing cache is enabled and cannot be created.
   3913      *
   3914      * @hide
   3915      */
   3916     public boolean mCachingFailed;
   3917     private Bitmap mDrawingCache;
   3918     private Bitmap mUnscaledDrawingCache;
   3919 
   3920     /**
   3921      * RenderNode holding View properties, potentially holding a DisplayList of View content.
   3922      * <p>
   3923      * When non-null and valid, this is expected to contain an up-to-date copy
   3924      * of the View content. Its DisplayList content is cleared on temporary detach and reset on
   3925      * cleanup.
   3926      */
   3927     final RenderNode mRenderNode;
   3928 
   3929     /**
   3930      * Set to true when the view is sending hover accessibility events because it
   3931      * is the innermost hovered view.
   3932      */
   3933     private boolean mSendingHoverAccessibilityEvents;
   3934 
   3935     /**
   3936      * Delegate for injecting accessibility functionality.
   3937      */
   3938     AccessibilityDelegate mAccessibilityDelegate;
   3939 
   3940     /**
   3941      * The view's overlay layer. Developers get a reference to the overlay via getOverlay()
   3942      * and add/remove objects to/from the overlay directly through the Overlay methods.
   3943      */
   3944     ViewOverlay mOverlay;
   3945 
   3946     /**
   3947      * The currently active parent view for receiving delegated nested scrolling events.
   3948      * This is set by {@link #startNestedScroll(int)} during a touch interaction and cleared
   3949      * by {@link #stopNestedScroll()} at the same point where we clear
   3950      * requestDisallowInterceptTouchEvent.
   3951      */
   3952     private ViewParent mNestedScrollingParent;
   3953 
   3954     /**
   3955      * Consistency verifier for debugging purposes.
   3956      * @hide
   3957      */
   3958     protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier =
   3959             InputEventConsistencyVerifier.isInstrumentationEnabled() ?
   3960                     new InputEventConsistencyVerifier(this, 0) : null;
   3961 
   3962     private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);
   3963 
   3964     private int[] mTempNestedScrollConsumed;
   3965 
   3966     /**
   3967      * An overlay is going to draw this View instead of being drawn as part of this
   3968      * View's parent. mGhostView is the View in the Overlay that must be invalidated
   3969      * when this view is invalidated.
   3970      */
   3971     GhostView mGhostView;
   3972 
   3973     /**
   3974      * Holds pairs of adjacent attribute data: attribute name followed by its value.
   3975      * @hide
   3976      */
   3977     @ViewDebug.ExportedProperty(category = "attributes", hasAdjacentMapping = true)
   3978     public String[] mAttributes;
   3979 
   3980     /**
   3981      * Maps a Resource id to its name.
   3982      */
   3983     private static SparseArray<String> mAttributeMap;
   3984 
   3985     /**
   3986      * Queue of pending runnables. Used to postpone calls to post() until this
   3987      * view is attached and has a handler.
   3988      */
   3989     private HandlerActionQueue mRunQueue;
   3990 
   3991     /**
   3992      * The pointer icon when the mouse hovers on this view. The default is null.
   3993      */
   3994     private PointerIcon mPointerIcon;
   3995 
   3996     /**
   3997      * @hide
   3998      */
   3999     String mStartActivityRequestWho;
   4000 
   4001     @Nullable
   4002     private RoundScrollbarRenderer mRoundScrollbarRenderer;
   4003 
   4004     /**
   4005      * Simple constructor to use when creating a view from code.
   4006      *
   4007      * @param context The Context the view is running in, through which it can
   4008      *        access the current theme, resources, etc.
   4009      */
   4010     public View(Context context) {
   4011         mContext = context;
   4012         mResources = context != null ? context.getResources() : null;
   4013         mViewFlags = SOUND_EFFECTS_ENABLED | HAPTIC_FEEDBACK_ENABLED;
   4014         // Set some flags defaults
   4015         mPrivateFlags2 =
   4016                 (LAYOUT_DIRECTION_DEFAULT << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) |
   4017                 (TEXT_DIRECTION_DEFAULT << PFLAG2_TEXT_DIRECTION_MASK_SHIFT) |
   4018                 (PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT) |
   4019                 (TEXT_ALIGNMENT_DEFAULT << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT) |
   4020                 (PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT) |
   4021                 (IMPORTANT_FOR_ACCESSIBILITY_DEFAULT << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT);
   4022         mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
   4023         setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS);
   4024         mUserPaddingStart = UNDEFINED_PADDING;
   4025         mUserPaddingEnd = UNDEFINED_PADDING;
   4026         mRenderNode = RenderNode.create(getClass().getName(), this);
   4027 
   4028         if (!sCompatibilityDone && context != null) {
   4029             final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion;
   4030 
   4031             // Older apps may need this compatibility hack for measurement.
   4032             sUseBrokenMakeMeasureSpec = targetSdkVersion <= JELLY_BEAN_MR1;
   4033 
   4034             // Older apps expect onMeasure() to always be called on a layout pass, regardless
   4035             // of whether a layout was requested on that View.
   4036             sIgnoreMeasureCache = targetSdkVersion < KITKAT;
   4037 
   4038             Canvas.sCompatibilityRestore = targetSdkVersion < M;
   4039 
   4040             // In M and newer, our widgets can pass a "hint" value in the size
   4041             // for UNSPECIFIED MeasureSpecs. This lets child views of scrolling containers
   4042             // know what the expected parent size is going to be, so e.g. list items can size
   4043             // themselves at 1/3 the size of their container. It breaks older apps though,
   4044             // specifically apps that use some popular open source libraries.
   4045             sUseZeroUnspecifiedMeasureSpec = targetSdkVersion < M;
   4046 
   4047             // Old versions of the platform would give different results from
   4048             // LinearLayout measurement passes using EXACTLY and non-EXACTLY
   4049             // modes, so we always need to run an additional EXACTLY pass.
   4050             sAlwaysRemeasureExactly = targetSdkVersion <= M;
   4051 
   4052             // Prior to N, layout params could change without requiring a
   4053             // subsequent call to setLayoutParams() and they would usually
   4054             // work. Partial layout breaks this assumption.
   4055             sLayoutParamsAlwaysChanged = targetSdkVersion <= M;
   4056 
   4057             // Prior to N, TextureView would silently ignore calls to setBackground/setForeground.
   4058             // On N+, we throw, but that breaks compatibility with apps that use these methods.
   4059             sTextureViewIgnoresDrawableSetters = targetSdkVersion <= M;
   4060 
   4061             // Prior to N, we would drop margins in LayoutParam conversions. The fix triggers bugs
   4062             // in apps so we target check it to avoid breaking existing apps.
   4063             sPreserveMarginParamsInLayoutParamConversion = targetSdkVersion >= N;
   4064 
   4065             sCascadedDragDrop = targetSdkVersion < N;
   4066 
   4067             sCompatibilityDone = true;
   4068         }
   4069     }
   4070 
   4071     /**
   4072      * Constructor that is called when inflating a view from XML. This is called
   4073      * when a view is being constructed from an XML file, supplying attributes
   4074      * that were specified in the XML file. This version uses a default style of
   4075      * 0, so the only attribute values applied are those in the Context's Theme
   4076      * and the given AttributeSet.
   4077      *
   4078      * <p>
   4079      * The method onFinishInflate() will be called after all children have been
   4080      * added.
   4081      *
   4082      * @param context The Context the view is running in, through which it can
   4083      *        access the current theme, resources, etc.
   4084      * @param attrs The attributes of the XML tag that is inflating the view.
   4085      * @see #View(Context, AttributeSet, int)
   4086      */
   4087     public View(Context context, @Nullable AttributeSet attrs) {
   4088         this(context, attrs, 0);
   4089     }
   4090 
   4091     /**
   4092      * Perform inflation from XML and apply a class-specific base style from a
   4093      * theme attribute. This constructor of View allows subclasses to use their
   4094      * own base style when they are inflating. For example, a Button class's
   4095      * constructor would call this version of the super class constructor and
   4096      * supply <code>R.attr.buttonStyle</code> for <var>defStyleAttr</var>; this
   4097      * allows the theme's button style to modify all of the base view attributes
   4098      * (in particular its background) as well as the Button class's attributes.
   4099      *
   4100      * @param context The Context the view is running in, through which it can
   4101      *        access the current theme, resources, etc.
   4102      * @param attrs The attributes of the XML tag that is inflating the view.
   4103      * @param defStyleAttr An attribute in the current theme that contains a
   4104      *        reference to a style resource that supplies default values for
   4105      *        the view. Can be 0 to not look for defaults.
   4106      * @see #View(Context, AttributeSet)
   4107      */
   4108     public View(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
   4109         this(context, attrs, defStyleAttr, 0);
   4110     }
   4111 
   4112     /**
   4113      * Perform inflation from XML and apply a class-specific base style from a
   4114      * theme attribute or style resource. This constructor of View allows
   4115      * subclasses to use their own base style when they are inflating.
   4116      * <p>
   4117      * When determining the final value of a particular attribute, there are
   4118      * four inputs that come into play:
   4119      * <ol>
   4120      * <li>Any attribute values in the given AttributeSet.
   4121      * <li>The style resource specified in the AttributeSet (named "style").
   4122      * <li>The default style specified by <var>defStyleAttr</var>.
   4123      * <li>The default style specified by <var>defStyleRes</var>.
   4124      * <li>The base values in this theme.
   4125      * </ol>
   4126      * <p>
   4127      * Each of these inputs is considered in-order, with the first listed taking
   4128      * precedence over the following ones. In other words, if in the
   4129      * AttributeSet you have supplied <code>&lt;Button * textColor="#ff000000"&gt;</code>
   4130      * , then the button's text will <em>always</em> be black, regardless of
   4131      * what is specified in any of the styles.
   4132      *
   4133      * @param context The Context the view is running in, through which it can
   4134      *        access the current theme, resources, etc.
   4135      * @param attrs The attributes of the XML tag that is inflating the view.
   4136      * @param defStyleAttr An attribute in the current theme that contains a
   4137      *        reference to a style resource that supplies default values for
   4138      *        the view. Can be 0 to not look for defaults.
   4139      * @param defStyleRes A resource identifier of a style resource that
   4140      *        supplies default values for the view, used only if
   4141      *        defStyleAttr is 0 or can not be found in the theme. Can be 0
   4142      *        to not look for defaults.
   4143      * @see #View(Context, AttributeSet, int)
   4144      */
   4145     public View(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
   4146         this(context);
   4147 
   4148         final TypedArray a = context.obtainStyledAttributes(
   4149                 attrs, com.android.internal.R.styleable.View, defStyleAttr, defStyleRes);
   4150 
   4151         if (mDebugViewAttributes) {
   4152             saveAttributeData(attrs, a);
   4153         }
   4154 
   4155         Drawable background = null;
   4156 
   4157         int leftPadding = -1;
   4158         int topPadding = -1;
   4159         int rightPadding = -1;
   4160         int bottomPadding = -1;
   4161         int startPadding = UNDEFINED_PADDING;
   4162         int endPadding = UNDEFINED_PADDING;
   4163 
   4164         int padding = -1;
   4165 
   4166         int viewFlagValues = 0;
   4167         int viewFlagMasks = 0;
   4168 
   4169         boolean setScrollContainer = false;
   4170 
   4171         int x = 0;
   4172         int y = 0;
   4173 
   4174         float tx = 0;
   4175         float ty = 0;
   4176         float tz = 0;
   4177         float elevation = 0;
   4178         float rotation = 0;
   4179         float rotationX = 0;
   4180         float rotationY = 0;
   4181         float sx = 1f;
   4182         float sy = 1f;
   4183         boolean transformSet = false;
   4184 
   4185         int scrollbarStyle = SCROLLBARS_INSIDE_OVERLAY;
   4186         int overScrollMode = mOverScrollMode;
   4187         boolean initializeScrollbars = false;
   4188         boolean initializeScrollIndicators = false;
   4189 
   4190         boolean startPaddingDefined = false;
   4191         boolean endPaddingDefined = false;
   4192         boolean leftPaddingDefined = false;
   4193         boolean rightPaddingDefined = false;
   4194 
   4195         final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion;
   4196 
   4197         final int N = a.getIndexCount();
   4198         for (int i = 0; i < N; i++) {
   4199             int attr = a.getIndex(i);
   4200             switch (attr) {
   4201                 case com.android.internal.R.styleable.View_background:
   4202                     background = a.getDrawable(attr);
   4203                     break;
   4204                 case com.android.internal.R.styleable.View_padding:
   4205                     padding = a.getDimensionPixelSize(attr, -1);
   4206                     mUserPaddingLeftInitial = padding;
   4207                     mUserPaddingRightInitial = padding;
   4208                     leftPaddingDefined = true;
   4209                     rightPaddingDefined = true;
   4210                     break;
   4211                  case com.android.internal.R.styleable.View_paddingLeft:
   4212                     leftPadding = a.getDimensionPixelSize(attr, -1);
   4213                     mUserPaddingLeftInitial = leftPadding;
   4214                     leftPaddingDefined = true;
   4215                     break;
   4216                 case com.android.internal.R.styleable.View_paddingTop:
   4217                     topPadding = a.getDimensionPixelSize(attr, -1);
   4218                     break;
   4219                 case com.android.internal.R.styleable.View_paddingRight:
   4220                     rightPadding = a.getDimensionPixelSize(attr, -1);
   4221                     mUserPaddingRightInitial = rightPadding;
   4222                     rightPaddingDefined = true;
   4223                     break;
   4224                 case com.android.internal.R.styleable.View_paddingBottom:
   4225                     bottomPadding = a.getDimensionPixelSize(attr, -1);
   4226                     break;
   4227                 case com.android.internal.R.styleable.View_paddingStart:
   4228                     startPadding = a.getDimensionPixelSize(attr, UNDEFINED_PADDING);
   4229                     startPaddingDefined = (startPadding != UNDEFINED_PADDING);
   4230                     break;
   4231                 case com.android.internal.R.styleable.View_paddingEnd:
   4232                     endPadding = a.getDimensionPixelSize(attr, UNDEFINED_PADDING);
   4233                     endPaddingDefined = (endPadding != UNDEFINED_PADDING);
   4234                     break;
   4235                 case com.android.internal.R.styleable.View_scrollX:
   4236                     x = a.getDimensionPixelOffset(attr, 0);
   4237                     break;
   4238                 case com.android.internal.R.styleable.View_scrollY:
   4239                     y = a.getDimensionPixelOffset(attr, 0);
   4240                     break;
   4241                 case com.android.internal.R.styleable.View_alpha:
   4242                     setAlpha(a.getFloat(attr, 1f));
   4243                     break;
   4244                 case com.android.internal.R.styleable.View_transformPivotX:
   4245                     setPivotX(a.getDimension(attr, 0));
   4246                     break;
   4247                 case com.android.internal.R.styleable.View_transformPivotY:
   4248                     setPivotY(a.getDimension(attr, 0));
   4249                     break;
   4250                 case com.android.internal.R.styleable.View_translationX:
   4251                     tx = a.getDimension(attr, 0);
   4252                     transformSet = true;
   4253                     break;
   4254                 case com.android.internal.R.styleable.View_translationY:
   4255                     ty = a.getDimension(attr, 0);
   4256                     transformSet = true;
   4257                     break;
   4258                 case com.android.internal.R.styleable.View_translationZ:
   4259                     tz = a.getDimension(attr, 0);
   4260                     transformSet = true;
   4261                     break;
   4262                 case com.android.internal.R.styleable.View_elevation:
   4263                     elevation = a.getDimension(attr, 0);
   4264                     transformSet = true;
   4265                     break;
   4266                 case com.android.internal.R.styleable.View_rotation:
   4267                     rotation = a.getFloat(attr, 0);
   4268                     transformSet = true;
   4269                     break;
   4270                 case com.android.internal.R.styleable.View_rotationX:
   4271                     rotationX = a.getFloat(attr, 0);
   4272                     transformSet = true;
   4273                     break;
   4274                 case com.android.internal.R.styleable.View_rotationY:
   4275                     rotationY = a.getFloat(attr, 0);
   4276                     transformSet = true;
   4277                     break;
   4278                 case com.android.internal.R.styleable.View_scaleX:
   4279                     sx = a.getFloat(attr, 1f);
   4280                     transformSet = true;
   4281                     break;
   4282                 case com.android.internal.R.styleable.View_scaleY:
   4283                     sy = a.getFloat(attr, 1f);
   4284                     transformSet = true;
   4285                     break;
   4286                 case com.android.internal.R.styleable.View_id:
   4287                     mID = a.getResourceId(attr, NO_ID);
   4288                     break;
   4289                 case com.android.internal.R.styleable.View_tag:
   4290                     mTag = a.getText(attr);
   4291                     break;
   4292                 case com.android.internal.R.styleable.View_fitsSystemWindows:
   4293                     if (a.getBoolean(attr, false)) {
   4294                         viewFlagValues |= FITS_SYSTEM_WINDOWS;
   4295                         viewFlagMasks |= FITS_SYSTEM_WINDOWS;
   4296                     }
   4297                     break;
   4298                 case com.android.internal.R.styleable.View_focusable:
   4299                     if (a.getBoolean(attr, false)) {
   4300                         viewFlagValues |= FOCUSABLE;
   4301                         viewFlagMasks |= FOCUSABLE_MASK;
   4302                     }
   4303                     break;
   4304                 case com.android.internal.R.styleable.View_focusableInTouchMode:
   4305                     if (a.getBoolean(attr, false)) {
   4306                         viewFlagValues |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE;
   4307                         viewFlagMasks |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE_MASK;
   4308                     }
   4309                     break;
   4310                 case com.android.internal.R.styleable.View_clickable:
   4311                     if (a.getBoolean(attr, false)) {
   4312                         viewFlagValues |= CLICKABLE;
   4313                         viewFlagMasks |= CLICKABLE;
   4314                     }
   4315                     break;
   4316                 case com.android.internal.R.styleable.View_longClickable:
   4317                     if (a.getBoolean(attr, false)) {
   4318                         viewFlagValues |= LONG_CLICKABLE;
   4319                         viewFlagMasks |= LONG_CLICKABLE;
   4320                     }
   4321                     break;
   4322                 case com.android.internal.R.styleable.View_contextClickable:
   4323                     if (a.getBoolean(attr, false)) {
   4324                         viewFlagValues |= CONTEXT_CLICKABLE;
   4325                         viewFlagMasks |= CONTEXT_CLICKABLE;
   4326                     }
   4327                     break;
   4328                 case com.android.internal.R.styleable.View_saveEnabled:
   4329                     if (!a.getBoolean(attr, true)) {
   4330                         viewFlagValues |= SAVE_DISABLED;
   4331                         viewFlagMasks |= SAVE_DISABLED_MASK;
   4332                     }
   4333                     break;
   4334                 case com.android.internal.R.styleable.View_duplicateParentState:
   4335                     if (a.getBoolean(attr, false)) {
   4336                         viewFlagValues |= DUPLICATE_PARENT_STATE;
   4337                         viewFlagMasks |= DUPLICATE_PARENT_STATE;
   4338                     }
   4339                     break;
   4340                 case com.android.internal.R.styleable.View_visibility:
   4341                     final int visibility = a.getInt(attr, 0);
   4342                     if (visibility != 0) {
   4343                         viewFlagValues |= VISIBILITY_FLAGS[visibility];
   4344                         viewFlagMasks |= VISIBILITY_MASK;
   4345                     }
   4346                     break;
   4347                 case com.android.internal.R.styleable.View_layoutDirection:
   4348                     // Clear any layout direction flags (included resolved bits) already set
   4349                     mPrivateFlags2 &=
   4350                             ~(PFLAG2_LAYOUT_DIRECTION_MASK | PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK);
   4351                     // Set the layout direction flags depending on the value of the attribute
   4352                     final int layoutDirection = a.getInt(attr, -1);
   4353                     final int value = (layoutDirection != -1) ?
   4354                             LAYOUT_DIRECTION_FLAGS[layoutDirection] : LAYOUT_DIRECTION_DEFAULT;
   4355                     mPrivateFlags2 |= (value << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT);
   4356                     break;
   4357                 case com.android.internal.R.styleable.View_drawingCacheQuality:
   4358                     final int cacheQuality = a.getInt(attr, 0);
   4359                     if (cacheQuality != 0) {
   4360                         viewFlagValues |= DRAWING_CACHE_QUALITY_FLAGS[cacheQuality];
   4361                         viewFlagMasks |= DRAWING_CACHE_QUALITY_MASK;
   4362                     }
   4363                     break;
   4364                 case com.android.internal.R.styleable.View_contentDescription:
   4365                     setContentDescription(a.getString(attr));
   4366                     break;
   4367                 case com.android.internal.R.styleable.View_accessibilityTraversalBefore:
   4368                     setAccessibilityTraversalBefore(a.getResourceId(attr, NO_ID));
   4369                     break;
   4370                 case com.android.internal.R.styleable.View_accessibilityTraversalAfter:
   4371                     setAccessibilityTraversalAfter(a.getResourceId(attr, NO_ID));
   4372                     break;
   4373                 case com.android.internal.R.styleable.View_labelFor:
   4374                     setLabelFor(a.getResourceId(attr, NO_ID));
   4375                     break;
   4376                 case com.android.internal.R.styleable.View_soundEffectsEnabled:
   4377                     if (!a.getBoolean(attr, true)) {
   4378                         viewFlagValues &= ~SOUND_EFFECTS_ENABLED;
   4379                         viewFlagMasks |= SOUND_EFFECTS_ENABLED;
   4380                     }
   4381                     break;
   4382                 case com.android.internal.R.styleable.View_hapticFeedbackEnabled:
   4383                     if (!a.getBoolean(attr, true)) {
   4384                         viewFlagValues &= ~HAPTIC_FEEDBACK_ENABLED;
   4385                         viewFlagMasks |= HAPTIC_FEEDBACK_ENABLED;
   4386                     }
   4387                     break;
   4388                 case R.styleable.View_scrollbars:
   4389                     final int scrollbars = a.getInt(attr, SCROLLBARS_NONE);
   4390                     if (scrollbars != SCROLLBARS_NONE) {
   4391                         viewFlagValues |= scrollbars;
   4392                         viewFlagMasks |= SCROLLBARS_MASK;
   4393                         initializeScrollbars = true;
   4394                     }
   4395                     break;
   4396                 //noinspection deprecation
   4397                 case R.styleable.View_fadingEdge:
   4398                     if (targetSdkVersion >= ICE_CREAM_SANDWICH) {
   4399                         // Ignore the attribute starting with ICS
   4400                         break;
   4401                     }
   4402                     // With builds < ICS, fall through and apply fading edges
   4403                 case R.styleable.View_requiresFadingEdge:
   4404                     final int fadingEdge = a.getInt(attr, FADING_EDGE_NONE);
   4405                     if (fadingEdge != FADING_EDGE_NONE) {
   4406                         viewFlagValues |= fadingEdge;
   4407                         viewFlagMasks |= FADING_EDGE_MASK;
   4408                         initializeFadingEdgeInternal(a);
   4409                     }
   4410                     break;
   4411                 case R.styleable.View_scrollbarStyle:
   4412                     scrollbarStyle = a.getInt(attr, SCROLLBARS_INSIDE_OVERLAY);
   4413                     if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) {
   4414                         viewFlagValues |= scrollbarStyle & SCROLLBARS_STYLE_MASK;
   4415                         viewFlagMasks |= SCROLLBARS_STYLE_MASK;
   4416                     }
   4417                     break;
   4418                 case R.styleable.View_isScrollContainer:
   4419                     setScrollContainer = true;
   4420                     if (a.getBoolean(attr, false)) {
   4421                         setScrollContainer(true);
   4422                     }
   4423                     break;
   4424                 case com.android.internal.R.styleable.View_keepScreenOn:
   4425                     if (a.getBoolean(attr, false)) {
   4426                         viewFlagValues |= KEEP_SCREEN_ON;
   4427                         viewFlagMasks |= KEEP_SCREEN_ON;
   4428                     }
   4429                     break;
   4430                 case R.styleable.View_filterTouchesWhenObscured:
   4431                     if (a.getBoolean(attr, false)) {
   4432                         viewFlagValues |= FILTER_TOUCHES_WHEN_OBSCURED;
   4433                         viewFlagMasks |= FILTER_TOUCHES_WHEN_OBSCURED;
   4434                     }
   4435                     break;
   4436                 case R.styleable.View_nextFocusLeft:
   4437                     mNextFocusLeftId = a.getResourceId(attr, View.NO_ID);
   4438                     break;
   4439                 case R.styleable.View_nextFocusRight:
   4440                     mNextFocusRightId = a.getResourceId(attr, View.NO_ID);
   4441                     break;
   4442                 case R.styleable.View_nextFocusUp:
   4443                     mNextFocusUpId = a.getResourceId(attr, View.NO_ID);
   4444                     break;
   4445                 case R.styleable.View_nextFocusDown:
   4446                     mNextFocusDownId = a.getResourceId(attr, View.NO_ID);
   4447                     break;
   4448                 case R.styleable.View_nextFocusForward:
   4449                     mNextFocusForwardId = a.getResourceId(attr, View.NO_ID);
   4450                     break;
   4451                 case R.styleable.View_minWidth:
   4452                     mMinWidth = a.getDimensionPixelSize(attr, 0);
   4453                     break;
   4454                 case R.styleable.View_minHeight:
   4455                     mMinHeight = a.getDimensionPixelSize(attr, 0);
   4456                     break;
   4457                 case R.styleable.View_onClick:
   4458                     if (context.isRestricted()) {
   4459                         throw new IllegalStateException("The android:onClick attribute cannot "
   4460                                 + "be used within a restricted context");
   4461                     }
   4462 
   4463                     final String handlerName = a.getString(attr);
   4464                     if (handlerName != null) {
   4465                         setOnClickListener(new DeclaredOnClickListener(this, handlerName));
   4466                     }
   4467                     break;
   4468                 case R.styleable.View_overScrollMode:
   4469                     overScrollMode = a.getInt(attr, OVER_SCROLL_IF_CONTENT_SCROLLS);
   4470                     break;
   4471                 case R.styleable.View_verticalScrollbarPosition:
   4472                     mVerticalScrollbarPosition = a.getInt(attr, SCROLLBAR_POSITION_DEFAULT);
   4473                     break;
   4474                 case R.styleable.View_layerType:
   4475                     setLayerType(a.getInt(attr, LAYER_TYPE_NONE), null);
   4476                     break;
   4477                 case R.styleable.View_textDirection:
   4478                     // Clear any text direction flag already set
   4479                     mPrivateFlags2 &= ~PFLAG2_TEXT_DIRECTION_MASK;
   4480                     // Set the text direction flags depending on the value of the attribute
   4481                     final int textDirection = a.getInt(attr, -1);
   4482                     if (textDirection != -1) {
   4483                         mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_FLAGS[textDirection];
   4484                     }
   4485                     break;
   4486                 case R.styleable.View_textAlignment:
   4487                     // Clear any text alignment flag already set
   4488                     mPrivateFlags2 &= ~PFLAG2_TEXT_ALIGNMENT_MASK;
   4489                     // Set the text alignment flag depending on the value of the attribute
   4490                     final int textAlignment = a.getInt(attr, TEXT_ALIGNMENT_DEFAULT);
   4491                     mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_FLAGS[textAlignment];
   4492                     break;
   4493                 case R.styleable.View_importantForAccessibility:
   4494                     setImportantForAccessibility(a.getInt(attr,
   4495                             IMPORTANT_FOR_ACCESSIBILITY_DEFAULT));
   4496                     break;
   4497                 case R.styleable.View_accessibilityLiveRegion:
   4498                     setAccessibilityLiveRegion(a.getInt(attr, ACCESSIBILITY_LIVE_REGION_DEFAULT));
   4499                     break;
   4500                 case R.styleable.View_transitionName:
   4501                     setTransitionName(a.getString(attr));
   4502                     break;
   4503                 case R.styleable.View_nestedScrollingEnabled:
   4504                     setNestedScrollingEnabled(a.getBoolean(attr, false));
   4505                     break;
   4506                 case R.styleable.View_stateListAnimator:
   4507                     setStateListAnimator(AnimatorInflater.loadStateListAnimator(context,
   4508                             a.getResourceId(attr, 0)));
   4509                     break;
   4510                 case R.styleable.View_backgroundTint:
   4511                     // This will get applied later during setBackground().
   4512                     if (mBackgroundTint == null) {
   4513                         mBackgroundTint = new TintInfo();
   4514                     }
   4515                     mBackgroundTint.mTintList = a.getColorStateList(
   4516                             R.styleable.View_backgroundTint);
   4517                     mBackgroundTint.mHasTintList = true;
   4518                     break;
   4519                 case R.styleable.View_backgroundTintMode:
   4520                     // This will get applied later during setBackground().
   4521                     if (mBackgroundTint == null) {
   4522                         mBackgroundTint = new TintInfo();
   4523                     }
   4524                     mBackgroundTint.mTintMode = Drawable.parseTintMode(a.getInt(
   4525                             R.styleable.View_backgroundTintMode, -1), null);
   4526                     mBackgroundTint.mHasTintMode = true;
   4527                     break;
   4528                 case R.styleable.View_outlineProvider:
   4529                     setOutlineProviderFromAttribute(a.getInt(R.styleable.View_outlineProvider,
   4530                             PROVIDER_BACKGROUND));
   4531                     break;
   4532                 case R.styleable.View_foreground:
   4533                     if (targetSdkVersion >= VERSION_CODES.M || this instanceof FrameLayout) {
   4534                         setForeground(a.getDrawable(attr));
   4535                     }
   4536                     break;
   4537                 case R.styleable.View_foregroundGravity:
   4538                     if (targetSdkVersion >= VERSION_CODES.M || this instanceof FrameLayout) {
   4539                         setForegroundGravity(a.getInt(attr, Gravity.NO_GRAVITY));
   4540                     }
   4541                     break;
   4542                 case R.styleable.View_foregroundTintMode:
   4543                     if (targetSdkVersion >= VERSION_CODES.M || this instanceof FrameLayout) {
   4544                         setForegroundTintMode(Drawable.parseTintMode(a.getInt(attr, -1), null));
   4545                     }
   4546                     break;
   4547                 case R.styleable.View_foregroundTint:
   4548                     if (targetSdkVersion >= VERSION_CODES.M || this instanceof FrameLayout) {
   4549                         setForegroundTintList(a.getColorStateList(attr));
   4550                     }
   4551                     break;
   4552                 case R.styleable.View_foregroundInsidePadding:
   4553                     if (targetSdkVersion >= VERSION_CODES.M || this instanceof FrameLayout) {
   4554                         if (mForegroundInfo == null) {
   4555                             mForegroundInfo = new ForegroundInfo();
   4556                         }
   4557                         mForegroundInfo.mInsidePadding = a.getBoolean(attr,
   4558                                 mForegroundInfo.mInsidePadding);
   4559                     }
   4560                     break;
   4561                 case R.styleable.View_scrollIndicators:
   4562                     final int scrollIndicators =
   4563                             (a.getInt(attr, 0) << SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT)
   4564                                     & SCROLL_INDICATORS_PFLAG3_MASK;
   4565                     if (scrollIndicators != 0) {
   4566                         mPrivateFlags3 |= scrollIndicators;
   4567                         initializeScrollIndicators = true;
   4568                     }
   4569                     break;
   4570                 case R.styleable.View_pointerIcon:
   4571                     final int resourceId = a.getResourceId(attr, 0);
   4572                     if (resourceId != 0) {
   4573                         setPointerIcon(PointerIcon.load(
   4574                                 context.getResources(), resourceId));
   4575                     } else {
   4576                         final int pointerType = a.getInt(attr, PointerIcon.TYPE_NOT_SPECIFIED);
   4577                         if (pointerType != PointerIcon.TYPE_NOT_SPECIFIED) {
   4578                             setPointerIcon(PointerIcon.getSystemIcon(context, pointerType));
   4579                         }
   4580                     }
   4581                     break;
   4582                 case R.styleable.View_forceHasOverlappingRendering:
   4583                     if (a.peekValue(attr) != null) {
   4584                         forceHasOverlappingRendering(a.getBoolean(attr, true));
   4585                     }
   4586                     break;
   4587 
   4588             }
   4589         }
   4590 
   4591         setOverScrollMode(overScrollMode);
   4592 
   4593         // Cache start/end user padding as we cannot fully resolve padding here (we dont have yet
   4594         // the resolved layout direction). Those cached values will be used later during padding
   4595         // resolution.
   4596         mUserPaddingStart = startPadding;
   4597         mUserPaddingEnd = endPadding;
   4598 
   4599         if (background != null) {
   4600             setBackground(background);
   4601         }
   4602 
   4603         // setBackground above will record that padding is currently provided by the background.
   4604         // If we have padding specified via xml, record that here instead and use it.
   4605         mLeftPaddingDefined = leftPaddingDefined;
   4606         mRightPaddingDefined = rightPaddingDefined;
   4607 
   4608         if (padding >= 0) {
   4609             leftPadding = padding;
   4610             topPadding = padding;
   4611             rightPadding = padding;
   4612             bottomPadding = padding;
   4613             mUserPaddingLeftInitial = padding;
   4614             mUserPaddingRightInitial = padding;
   4615         }
   4616 
   4617         if (isRtlCompatibilityMode()) {
   4618             // RTL compatibility mode: pre Jelly Bean MR1 case OR no RTL support case.
   4619             // left / right padding are used if defined (meaning here nothing to do). If they are not
   4620             // defined and start / end padding are defined (e.g. in Frameworks resources), then we use
   4621             // start / end and resolve them as left / right (layout direction is not taken into account).
   4622             // Padding from the background drawable is stored at this point in mUserPaddingLeftInitial
   4623             // and mUserPaddingRightInitial) so drawable padding will be used as ultimate default if
   4624             // defined.
   4625             if (!mLeftPaddingDefined && startPaddingDefined) {
   4626                 leftPadding = startPadding;
   4627             }
   4628             mUserPaddingLeftInitial = (leftPadding >= 0) ? leftPadding : mUserPaddingLeftInitial;
   4629             if (!mRightPaddingDefined && endPaddingDefined) {
   4630                 rightPadding = endPadding;
   4631             }
   4632             mUserPaddingRightInitial = (rightPadding >= 0) ? rightPadding : mUserPaddingRightInitial;
   4633         } else {
   4634             // Jelly Bean MR1 and after case: if start/end defined, they will override any left/right
   4635             // values defined. Otherwise, left /right values are used.
   4636             // Padding from the background drawable is stored at this point in mUserPaddingLeftInitial
   4637             // and mUserPaddingRightInitial) so drawable padding will be used as ultimate default if
   4638             // defined.
   4639             final boolean hasRelativePadding = startPaddingDefined || endPaddingDefined;
   4640 
   4641             if (mLeftPaddingDefined && !hasRelativePadding) {
   4642                 mUserPaddingLeftInitial = leftPadding;
   4643             }
   4644             if (mRightPaddingDefined && !hasRelativePadding) {
   4645                 mUserPaddingRightInitial = rightPadding;
   4646             }
   4647         }
   4648 
   4649         internalSetPadding(
   4650                 mUserPaddingLeftInitial,
   4651                 topPadding >= 0 ? topPadding : mPaddingTop,
   4652                 mUserPaddingRightInitial,
   4653                 bottomPadding >= 0 ? bottomPadding : mPaddingBottom);
   4654 
   4655         if (viewFlagMasks != 0) {
   4656             setFlags(viewFlagValues, viewFlagMasks);
   4657         }
   4658 
   4659         if (initializeScrollbars) {
   4660             initializeScrollbarsInternal(a);
   4661         }
   4662 
   4663         if (initializeScrollIndicators) {
   4664             initializeScrollIndicatorsInternal();
   4665         }
   4666 
   4667         a.recycle();
   4668 
   4669         // Needs to be called after mViewFlags is set
   4670         if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) {
   4671             recomputePadding();
   4672         }
   4673 
   4674         if (x != 0 || y != 0) {
   4675             scrollTo(x, y);
   4676         }
   4677 
   4678         if (transformSet) {
   4679             setTranslationX(tx);
   4680             setTranslationY(ty);
   4681             setTranslationZ(tz);
   4682             setElevation(elevation);
   4683             setRotation(rotation);
   4684             setRotationX(rotationX);
   4685             setRotationY(rotationY);
   4686             setScaleX(sx);
   4687             setScaleY(sy);
   4688         }
   4689 
   4690         if (!setScrollContainer && (viewFlagValues&SCROLLBARS_VERTICAL) != 0) {
   4691             setScrollContainer(true);
   4692         }
   4693 
   4694         computeOpaqueFlags();
   4695     }
   4696 
   4697     /**
   4698      * An implementation of OnClickListener that attempts to lazily load a
   4699      * named click handling method from a parent or ancestor context.
   4700      */
   4701     private static class DeclaredOnClickListener implements OnClickListener {
   4702         private final View mHostView;
   4703         private final String mMethodName;
   4704 
   4705         private Method mResolvedMethod;
   4706         private Context mResolvedContext;
   4707 
   4708         public DeclaredOnClickListener(@NonNull View hostView, @NonNull String methodName) {
   4709             mHostView = hostView;
   4710             mMethodName = methodName;
   4711         }
   4712 
   4713         @Override
   4714         public void onClick(@NonNull View v) {
   4715             if (mResolvedMethod == null) {
   4716                 resolveMethod(mHostView.getContext(), mMethodName);
   4717             }
   4718 
   4719             try {
   4720                 mResolvedMethod.invoke(mResolvedContext, v);
   4721             } catch (IllegalAccessException e) {
   4722                 throw new IllegalStateException(
   4723                         "Could not execute non-public method for android:onClick", e);
   4724             } catch (InvocationTargetException e) {
   4725                 throw new IllegalStateException(
   4726                         "Could not execute method for android:onClick", e);
   4727             }
   4728         }
   4729 
   4730         @NonNull
   4731         private void resolveMethod(@Nullable Context context, @NonNull String name) {
   4732             while (context != null) {
   4733                 try {
   4734                     if (!context.isRestricted()) {
   4735                         final Method method = context.getClass().getMethod(mMethodName, View.class);
   4736                         if (method != null) {
   4737                             mResolvedMethod = method;
   4738                             mResolvedContext = context;
   4739                             return;
   4740                         }
   4741                     }
   4742                 } catch (NoSuchMethodException e) {
   4743                     // Failed to find method, keep searching up the hierarchy.
   4744                 }
   4745 
   4746                 if (context instanceof ContextWrapper) {
   4747                     context = ((ContextWrapper) context).getBaseContext();
   4748                 } else {
   4749                     // Can't search up the hierarchy, null out and fail.
   4750                     context = null;
   4751                 }
   4752             }
   4753 
   4754             final int id = mHostView.getId();
   4755             final String idText = id == NO_ID ? "" : " with id '"
   4756                     + mHostView.getContext().getResources().getResourceEntryName(id) + "'";
   4757             throw new IllegalStateException("Could not find method " + mMethodName
   4758                     + "(View) in a parent or ancestor Context for android:onClick "
   4759                     + "attribute defined on view " + mHostView.getClass() + idText);
   4760         }
   4761     }
   4762 
   4763     /**
   4764      * Non-public constructor for use in testing
   4765      */
   4766     View() {
   4767         mResources = null;
   4768         mRenderNode = RenderNode.create(getClass().getName(), this);
   4769     }
   4770 
   4771     private static SparseArray<String> getAttributeMap() {
   4772         if (mAttributeMap == null) {
   4773             mAttributeMap = new SparseArray<>();
   4774         }
   4775         return mAttributeMap;
   4776     }
   4777 
   4778     private void saveAttributeData(@Nullable AttributeSet attrs, @NonNull TypedArray t) {
   4779         final int attrsCount = attrs == null ? 0 : attrs.getAttributeCount();
   4780         final int indexCount = t.getIndexCount();
   4781         final String[] attributes = new String[(attrsCount + indexCount) * 2];
   4782 
   4783         int i = 0;
   4784 
   4785         // Store raw XML attributes.
   4786         for (int j = 0; j < attrsCount; ++j) {
   4787             attributes[i] = attrs.getAttributeName(j);
   4788             attributes[i + 1] = attrs.getAttributeValue(j);
   4789             i += 2;
   4790         }
   4791 
   4792         // Store resolved styleable attributes.
   4793         final Resources res = t.getResources();
   4794         final SparseArray<String> attributeMap = getAttributeMap();
   4795         for (int j = 0; j < indexCount; ++j) {
   4796             final int index = t.getIndex(j);
   4797             if (!t.hasValueOrEmpty(index)) {
   4798                 // Value is undefined. Skip it.
   4799                 continue;
   4800             }
   4801 
   4802             final int resourceId = t.getResourceId(index, 0);
   4803             if (resourceId == 0) {
   4804                 // Value is not a reference. Skip it.
   4805                 continue;
   4806             }
   4807 
   4808             String resourceName = attributeMap.get(resourceId);
   4809             if (resourceName == null) {
   4810                 try {
   4811                     resourceName = res.getResourceName(resourceId);
   4812                 } catch (Resources.NotFoundException e) {
   4813                     resourceName = "0x" + Integer.toHexString(resourceId);
   4814                 }
   4815                 attributeMap.put(resourceId, resourceName);
   4816             }
   4817 
   4818             attributes[i] = resourceName;
   4819             attributes[i + 1] = t.getString(index);
   4820             i += 2;
   4821         }
   4822 
   4823         // Trim to fit contents.
   4824         final String[] trimmed = new String[i];
   4825         System.arraycopy(attributes, 0, trimmed, 0, i);
   4826         mAttributes = trimmed;
   4827     }
   4828 
   4829     public String toString() {
   4830         StringBuilder out = new StringBuilder(128);
   4831         out.append(getClass().getName());
   4832         out.append('{');
   4833         out.append(Integer.toHexString(System.identityHashCode(this)));
   4834         out.append(' ');
   4835         switch (mViewFlags&VISIBILITY_MASK) {
   4836             case VISIBLE: out.append('V'); break;
   4837             case INVISIBLE: out.append('I'); break;
   4838             case GONE: out.append('G'); break;
   4839             default: out.append('.'); break;
   4840         }
   4841         out.append((mViewFlags&FOCUSABLE_MASK) == FOCUSABLE ? 'F' : '.');
   4842         out.append((mViewFlags&ENABLED_MASK) == ENABLED ? 'E' : '.');
   4843         out.append((mViewFlags&DRAW_MASK) == WILL_NOT_DRAW ? '.' : 'D');
   4844         out.append((mViewFlags&SCROLLBARS_HORIZONTAL) != 0 ? 'H' : '.');
   4845         out.append((mViewFlags&SCROLLBARS_VERTICAL) != 0 ? 'V' : '.');
   4846         out.append((mViewFlags&CLICKABLE) != 0 ? 'C' : '.');
   4847         out.append((mViewFlags&LONG_CLICKABLE) != 0 ? 'L' : '.');
   4848         out.append((mViewFlags&CONTEXT_CLICKABLE) != 0 ? 'X' : '.');
   4849         out.append(' ');
   4850         out.append((mPrivateFlags&PFLAG_IS_ROOT_NAMESPACE) != 0 ? 'R' : '.');
   4851         out.append((mPrivateFlags&PFLAG_FOCUSED) != 0 ? 'F' : '.');
   4852         out.append((mPrivateFlags&PFLAG_SELECTED) != 0 ? 'S' : '.');
   4853         if ((mPrivateFlags&PFLAG_PREPRESSED) != 0) {
   4854             out.append('p');
   4855         } else {
   4856             out.append((mPrivateFlags&PFLAG_PRESSED) != 0 ? 'P' : '.');
   4857         }
   4858         out.append((mPrivateFlags&PFLAG_HOVERED) != 0 ? 'H' : '.');
   4859         out.append((mPrivateFlags&PFLAG_ACTIVATED) != 0 ? 'A' : '.');
   4860         out.append((mPrivateFlags&PFLAG_INVALIDATED) != 0 ? 'I' : '.');
   4861         out.append((mPrivateFlags&PFLAG_DIRTY_MASK) != 0 ? 'D' : '.');
   4862         out.append(' ');
   4863         out.append(mLeft);
   4864         out.append(',');
   4865         out.append(mTop);
   4866         out.append('-');
   4867         out.append(mRight);
   4868         out.append(',');
   4869         out.append(mBottom);
   4870         final int id = getId();
   4871         if (id != NO_ID) {
   4872             out.append(" #");
   4873             out.append(Integer.toHexString(id));
   4874             final Resources r = mResources;
   4875             if (id > 0 && Resources.resourceHasPackage(id) && r != null) {
   4876                 try {
   4877                     String pkgname;
   4878                     switch (id&0xff000000) {
   4879                         case 0x7f000000:
   4880                             pkgname="app";
   4881                             break;
   4882                         case 0x01000000:
   4883                             pkgname="android";
   4884                             break;
   4885                         default:
   4886                             pkgname = r.getResourcePackageName(id);
   4887                             break;
   4888                     }
   4889                     String typename = r.getResourceTypeName(id);
   4890                     String entryname = r.getResourceEntryName(id);
   4891                     out.append(" ");
   4892                     out.append(pkgname);
   4893                     out.append(":");
   4894                     out.append(typename);
   4895                     out.append("/");
   4896                     out.append(entryname);
   4897                 } catch (Resources.NotFoundException e) {
   4898                 }
   4899             }
   4900         }
   4901         out.append("}");
   4902         return out.toString();
   4903     }
   4904 
   4905     /**
   4906      * <p>
   4907      * Initializes the fading edges from a given set of styled attributes. This
   4908      * method should be called by subclasses that need fading edges and when an
   4909      * instance of these subclasses is created programmatically rather than
   4910      * being inflated from XML. This method is automatically called when the XML
   4911      * is inflated.
   4912      * </p>
   4913      *
   4914      * @param a the styled attributes set to initialize the fading edges from
   4915      *
   4916      * @removed
   4917      */
   4918     protected void initializeFadingEdge(TypedArray a) {
   4919         // This method probably shouldn't have been included in the SDK to begin with.
   4920         // It relies on 'a' having been initialized using an attribute filter array that is
   4921         // not publicly available to the SDK. The old method has been renamed
   4922         // to initializeFadingEdgeInternal and hidden for framework use only;
   4923         // this one initializes using defaults to make it safe to call for apps.
   4924 
   4925         TypedArray arr = mContext.obtainStyledAttributes(com.android.internal.R.styleable.View);
   4926 
   4927         initializeFadingEdgeInternal(arr);
   4928 
   4929         arr.recycle();
   4930     }
   4931 
   4932     /**
   4933      * <p>
   4934      * Initializes the fading edges from a given set of styled attributes. This
   4935      * method should be called by subclasses that need fading edges and when an
   4936      * instance of these subclasses is created programmatically rather than
   4937      * being inflated from XML. This method is automatically called when the XML
   4938      * is inflated.
   4939      * </p>
   4940      *
   4941      * @param a the styled attributes set to initialize the fading edges from
   4942      * @hide This is the real method; the public one is shimmed to be safe to call from apps.
   4943      */
   4944     protected void initializeFadingEdgeInternal(TypedArray a) {
   4945         initScrollCache();
   4946 
   4947         mScrollCache.fadingEdgeLength = a.getDimensionPixelSize(
   4948                 R.styleable.View_fadingEdgeLength,
   4949                 ViewConfiguration.get(mContext).getScaledFadingEdgeLength());
   4950     }
   4951 
   4952     /**
   4953      * Returns the size of the vertical faded edges used to indicate that more
   4954      * content in this view is visible.
   4955      *
   4956      * @return The size in pixels of the vertical faded edge or 0 if vertical
   4957      *         faded edges are not enabled for this view.
   4958      * @attr ref android.R.styleable#View_fadingEdgeLength
   4959      */
   4960     public int getVerticalFadingEdgeLength() {
   4961         if (isVerticalFadingEdgeEnabled()) {
   4962             ScrollabilityCache cache = mScrollCache;
   4963             if (cache != null) {
   4964                 return cache.fadingEdgeLength;
   4965             }
   4966         }
   4967         return 0;
   4968     }
   4969 
   4970     /**
   4971      * Set the size of the faded edge used to indicate that more content in this
   4972      * view is available.  Will not change whether the fading edge is enabled; use
   4973      * {@link #setVerticalFadingEdgeEnabled(boolean)} or
   4974      * {@link #setHorizontalFadingEdgeEnabled(boolean)} to enable the fading edge
   4975      * for the vertical or horizontal fading edges.
   4976      *
   4977      * @param length The size in pixels of the faded edge used to indicate that more
   4978      *        content in this view is visible.
   4979      */
   4980     public void setFadingEdgeLength(int length) {
   4981         initScrollCache();
   4982         mScrollCache.fadingEdgeLength = length;
   4983     }
   4984 
   4985     /**
   4986      * Returns the size of the horizontal faded edges used to indicate that more
   4987      * content in this view is visible.
   4988      *
   4989      * @return The size in pixels of the horizontal faded edge or 0 if horizontal
   4990      *         faded edges are not enabled for this view.
   4991      * @attr ref android.R.styleable#View_fadingEdgeLength
   4992      */
   4993     public int getHorizontalFadingEdgeLength() {
   4994         if (isHorizontalFadingEdgeEnabled()) {
   4995             ScrollabilityCache cache = mScrollCache;
   4996             if (cache != null) {
   4997                 return cache.fadingEdgeLength;
   4998             }
   4999         }
   5000         return 0;
   5001     }
   5002 
   5003     /**
   5004      * Returns the width of the vertical scrollbar.
   5005      *
   5006      * @return The width in pixels of the vertical scrollbar or 0 if there
   5007      *         is no vertical scrollbar.
   5008      */
   5009     public int getVerticalScrollbarWidth() {
   5010         ScrollabilityCache cache = mScrollCache;
   5011         if (cache != null) {
   5012             ScrollBarDrawable scrollBar = cache.scrollBar;
   5013             if (scrollBar != null) {
   5014                 int size = scrollBar.getSize(true);
   5015                 if (size <= 0) {
   5016                     size = cache.scrollBarSize;
   5017                 }
   5018                 return size;
   5019             }
   5020             return 0;
   5021         }
   5022         return 0;
   5023     }
   5024 
   5025     /**
   5026      * Returns the height of the horizontal scrollbar.
   5027      *
   5028      * @return The height in pixels of the horizontal scrollbar or 0 if
   5029      *         there is no horizontal scrollbar.
   5030      */
   5031     protected int getHorizontalScrollbarHeight() {
   5032         ScrollabilityCache cache = mScrollCache;
   5033         if (cache != null) {
   5034             ScrollBarDrawable scrollBar = cache.scrollBar;
   5035             if (scrollBar != null) {
   5036                 int size = scrollBar.getSize(false);
   5037                 if (size <= 0) {
   5038                     size = cache.scrollBarSize;
   5039                 }
   5040                 return size;
   5041             }
   5042             return 0;
   5043         }
   5044         return 0;
   5045     }
   5046 
   5047     /**
   5048      * <p>
   5049      * Initializes the scrollbars from a given set of styled attributes. This
   5050      * method should be called by subclasses that need scrollbars and when an
   5051      * instance of these subclasses is created programmatically rather than
   5052      * being inflated from XML. This method is automatically called when the XML
   5053      * is inflated.
   5054      * </p>
   5055      *
   5056      * @param a the styled attributes set to initialize the scrollbars from
   5057      *
   5058      * @removed
   5059      */
   5060     protected void initializeScrollbars(TypedArray a) {
   5061         // It's not safe to use this method from apps. The parameter 'a' must have been obtained
   5062         // using the View filter array which is not available to the SDK. As such, internal
   5063         // framework usage now uses initializeScrollbarsInternal and we grab a default
   5064         // TypedArray with the right filter instead here.
   5065         TypedArray arr = mContext.obtainStyledAttributes(com.android.internal.R.styleable.View);
   5066 
   5067         initializeScrollbarsInternal(arr);
   5068 
   5069         // We ignored the method parameter. Recycle the one we actually did use.
   5070         arr.recycle();
   5071     }
   5072 
   5073     /**
   5074      * <p>
   5075      * Initializes the scrollbars from a given set of styled attributes. This
   5076      * method should be called by subclasses that need scrollbars and when an
   5077      * instance of these subclasses is created programmatically rather than
   5078      * being inflated from XML. This method is automatically called when the XML
   5079      * is inflated.
   5080      * </p>
   5081      *
   5082      * @param a the styled attributes set to initialize the scrollbars from
   5083      * @hide
   5084      */
   5085     protected void initializeScrollbarsInternal(TypedArray a) {
   5086         initScrollCache();
   5087 
   5088         final ScrollabilityCache scrollabilityCache = mScrollCache;
   5089 
   5090         if (scrollabilityCache.scrollBar == null) {
   5091             scrollabilityCache.scrollBar = new ScrollBarDrawable();
   5092             scrollabilityCache.scrollBar.setState(getDrawableState());
   5093             scrollabilityCache.scrollBar.setCallback(this);
   5094         }
   5095 
   5096         final boolean fadeScrollbars = a.getBoolean(R.styleable.View_fadeScrollbars, true);
   5097 
   5098         if (!fadeScrollbars) {
   5099             scrollabilityCache.state = ScrollabilityCache.ON;
   5100         }
   5101         scrollabilityCache.fadeScrollBars = fadeScrollbars;
   5102 
   5103 
   5104         scrollabilityCache.scrollBarFadeDuration = a.getInt(
   5105                 R.styleable.View_scrollbarFadeDuration, ViewConfiguration
   5106                         .getScrollBarFadeDuration());
   5107         scrollabilityCache.scrollBarDefaultDelayBeforeFade = a.getInt(
   5108                 R.styleable.View_scrollbarDefaultDelayBeforeFade,
   5109                 ViewConfiguration.getScrollDefaultDelay());
   5110 
   5111 
   5112         scrollabilityCache.scrollBarSize = a.getDimensionPixelSize(
   5113                 com.android.internal.R.styleable.View_scrollbarSize,
   5114                 ViewConfiguration.get(mContext).getScaledScrollBarSize());
   5115 
   5116         Drawable track = a.getDrawable(R.styleable.View_scrollbarTrackHorizontal);
   5117         scrollabilityCache.scrollBar.setHorizontalTrackDrawable(track);
   5118 
   5119         Drawable thumb = a.getDrawable(R.styleable.View_scrollbarThumbHorizontal);
   5120         if (thumb != null) {
   5121             scrollabilityCache.scrollBar.setHorizontalThumbDrawable(thumb);
   5122         }
   5123 
   5124         boolean alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawHorizontalTrack,
   5125                 false);
   5126         if (alwaysDraw) {
   5127             scrollabilityCache.scrollBar.setAlwaysDrawHorizontalTrack(true);
   5128         }
   5129 
   5130         track = a.getDrawable(R.styleable.View_scrollbarTrackVertical);
   5131         scrollabilityCache.scrollBar.setVerticalTrackDrawable(track);
   5132 
   5133         thumb = a.getDrawable(R.styleable.View_scrollbarThumbVertical);
   5134         if (thumb != null) {
   5135             scrollabilityCache.scrollBar.setVerticalThumbDrawable(thumb);
   5136         }
   5137 
   5138         alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawVerticalTrack,
   5139                 false);
   5140         if (alwaysDraw) {
   5141             scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true);
   5142         }
   5143 
   5144         // Apply layout direction to the new Drawables if needed
   5145         final int layoutDirection = getLayoutDirection();
   5146         if (track != null) {
   5147             track.setLayoutDirection(layoutDirection);
   5148         }
   5149         if (thumb != null) {
   5150             thumb.setLayoutDirection(layoutDirection);
   5151         }
   5152 
   5153         // Re-apply user/background padding so that scrollbar(s) get added
   5154         resolvePadding();
   5155     }
   5156 
   5157     private void initializeScrollIndicatorsInternal() {
   5158         // Some day maybe we'll break this into top/left/start/etc. and let the
   5159         // client control it. Until then, you can have any scroll indicator you
   5160         // want as long as it's a 1dp foreground-colored rectangle.
   5161         if (mScrollIndicatorDrawable == null) {
   5162             mScrollIndicatorDrawable = mContext.getDrawable(R.drawable.scroll_indicator_material);
   5163         }
   5164     }
   5165 
   5166     /**
   5167      * <p>
   5168      * Initalizes the scrollability cache if necessary.
   5169      * </p>
   5170      */
   5171     private void initScrollCache() {
   5172         if (mScrollCache == null) {
   5173             mScrollCache = new ScrollabilityCache(ViewConfiguration.get(mContext), this);
   5174         }
   5175     }
   5176 
   5177     private ScrollabilityCache getScrollCache() {
   5178         initScrollCache();
   5179         return mScrollCache;
   5180     }
   5181 
   5182     /**
   5183      * Set the position of the vertical scroll bar. Should be one of
   5184      * {@link #SCROLLBAR_POSITION_DEFAULT}, {@link #SCROLLBAR_POSITION_LEFT} or
   5185      * {@link #SCROLLBAR_POSITION_RIGHT}.
   5186      *
   5187      * @param position Where the vertical scroll bar should be positioned.
   5188      */
   5189     public void setVerticalScrollbarPosition(int position) {
   5190         if (mVerticalScrollbarPosition != position) {
   5191             mVerticalScrollbarPosition = position;
   5192             computeOpaqueFlags();
   5193             resolvePadding();
   5194         }
   5195     }
   5196 
   5197     /**
   5198      * @return The position where the vertical scroll bar will show, if applicable.
   5199      * @see #setVerticalScrollbarPosition(int)
   5200      */
   5201     public int getVerticalScrollbarPosition() {
   5202         return mVerticalScrollbarPosition;
   5203     }
   5204 
   5205     boolean isOnScrollbar(float x, float y) {
   5206         if (mScrollCache == null) {
   5207             return false;
   5208         }
   5209         x += getScrollX();
   5210         y += getScrollY();
   5211         if (isVerticalScrollBarEnabled() && !isVerticalScrollBarHidden()) {
   5212             final Rect bounds = mScrollCache.mScrollBarBounds;
   5213             getVerticalScrollBarBounds(bounds);
   5214             if (bounds.contains((int)x, (int)y)) {
   5215                 return true;
   5216             }
   5217         }
   5218         if (isHorizontalScrollBarEnabled()) {
   5219             final Rect bounds = mScrollCache.mScrollBarBounds;
   5220             getHorizontalScrollBarBounds(bounds);
   5221             if (bounds.contains((int)x, (int)y)) {
   5222                 return true;
   5223             }
   5224         }
   5225         return false;
   5226     }
   5227 
   5228     boolean isOnScrollbarThumb(float x, float y) {
   5229         return isOnVerticalScrollbarThumb(x, y) || isOnHorizontalScrollbarThumb(x, y);
   5230     }
   5231 
   5232     private boolean isOnVerticalScrollbarThumb(float x, float y) {
   5233         if (mScrollCache == null) {
   5234             return false;
   5235         }
   5236         if (isVerticalScrollBarEnabled() && !isVerticalScrollBarHidden()) {
   5237             x += getScrollX();
   5238             y += getScrollY();
   5239             final Rect bounds = mScrollCache.mScrollBarBounds;
   5240             getVerticalScrollBarBounds(bounds);
   5241             final int range = computeVerticalScrollRange();
   5242             final int offset = computeVerticalScrollOffset();
   5243             final int extent = computeVerticalScrollExtent();
   5244             final int thumbLength = ScrollBarUtils.getThumbLength(bounds.height(), bounds.width(),
   5245                     extent, range);
   5246             final int thumbOffset = ScrollBarUtils.getThumbOffset(bounds.height(), thumbLength,
   5247                     extent, range, offset);
   5248             final int thumbTop = bounds.top + thumbOffset;
   5249             if (x >= bounds.left && x <= bounds.right && y >= thumbTop
   5250                     && y <= thumbTop + thumbLength) {
   5251                 return true;
   5252             }
   5253         }
   5254         return false;
   5255     }
   5256 
   5257     private boolean isOnHorizontalScrollbarThumb(float x, float y) {
   5258         if (mScrollCache == null) {
   5259             return false;
   5260         }
   5261         if (isHorizontalScrollBarEnabled()) {
   5262             x += getScrollX();
   5263             y += getScrollY();
   5264             final Rect bounds = mScrollCache.mScrollBarBounds;
   5265             getHorizontalScrollBarBounds(bounds);
   5266             final int range = computeHorizontalScrollRange();
   5267             final int offset = computeHorizontalScrollOffset();
   5268             final int extent = computeHorizontalScrollExtent();
   5269             final int thumbLength = ScrollBarUtils.getThumbLength(bounds.width(), bounds.height(),
   5270                     extent, range);
   5271             final int thumbOffset = ScrollBarUtils.getThumbOffset(bounds.width(), thumbLength,
   5272                     extent, range, offset);
   5273             final int thumbLeft = bounds.left + thumbOffset;
   5274             if (x >= thumbLeft && x <= thumbLeft + thumbLength && y >= bounds.top
   5275                     && y <= bounds.bottom) {
   5276                 return true;
   5277             }
   5278         }
   5279         return false;
   5280     }
   5281 
   5282     boolean isDraggingScrollBar() {
   5283         return mScrollCache != null
   5284                 && mScrollCache.mScrollBarDraggingState != ScrollabilityCache.NOT_DRAGGING;
   5285     }
   5286 
   5287     /**
   5288      * Sets the state of all scroll indicators.
   5289      * <p>
   5290      * See {@link #setScrollIndicators(int, int)} for usage information.
   5291      *
   5292      * @param indicators a bitmask of indicators that should be enabled, or
   5293      *                   {@code 0} to disable all indicators
   5294      * @see #setScrollIndicators(int, int)
   5295      * @see #getScrollIndicators()
   5296      * @attr ref android.R.styleable#View_scrollIndicators
   5297      */
   5298     public void setScrollIndicators(@ScrollIndicators int indicators) {
   5299         setScrollIndicators(indicators,
   5300                 SCROLL_INDICATORS_PFLAG3_MASK >>> SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT);
   5301     }
   5302 
   5303     /**
   5304      * Sets the state of the scroll indicators specified by the mask. To change
   5305      * all scroll indicators at once, see {@link #setScrollIndicators(int)}.
   5306      * <p>
   5307      * When a scroll indicator is enabled, it will be displayed if the view
   5308      * can scroll in the direction of the indicator.
   5309      * <p>
   5310      * Multiple indicator types may be enabled or disabled by passing the
   5311      * logical OR of the desired types. If multiple types are specified, they
   5312      * will all be set to the same enabled state.
   5313      * <p>
   5314      * For example, to enable the top scroll indicatorExample: {@code setScrollIndicators
   5315      *
   5316      * @param indicators the indicator direction, or the logical OR of multiple
   5317      *             indicator directions. One or more of:
   5318      *             <ul>
   5319      *               <li>{@link #SCROLL_INDICATOR_TOP}</li>
   5320      *               <li>{@link #SCROLL_INDICATOR_BOTTOM}</li>
   5321      *               <li>{@link #SCROLL_INDICATOR_LEFT}</li>
   5322      *               <li>{@link #SCROLL_INDICATOR_RIGHT}</li>
   5323      *               <li>{@link #SCROLL_INDICATOR_START}</li>
   5324      *               <li>{@link #SCROLL_INDICATOR_END}</li>
   5325      *             </ul>
   5326      * @see #setScrollIndicators(int)
   5327      * @see #getScrollIndicators()
   5328      * @attr ref android.R.styleable#View_scrollIndicators
   5329      */
   5330     public void setScrollIndicators(@ScrollIndicators int indicators, @ScrollIndicators int mask) {
   5331         // Shift and sanitize mask.
   5332         mask <<= SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT;
   5333         mask &= SCROLL_INDICATORS_PFLAG3_MASK;
   5334 
   5335         // Shift and mask indicators.
   5336         indicators <<= SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT;
   5337         indicators &= mask;
   5338 
   5339         // Merge with non-masked flags.
   5340         final int updatedFlags = indicators | (mPrivateFlags3 & ~mask);
   5341 
   5342         if (mPrivateFlags3 != updatedFlags) {
   5343             mPrivateFlags3 = updatedFlags;
   5344 
   5345             if (indicators != 0) {
   5346                 initializeScrollIndicatorsInternal();
   5347             }
   5348             invalidate();
   5349         }
   5350     }
   5351 
   5352     /**
   5353      * Returns a bitmask representing the enabled scroll indicators.
   5354      * <p>
   5355      * For example, if the top and left scroll indicators are enabled and all
   5356      * other indicators are disabled, the return value will be
   5357      * {@code View.SCROLL_INDICATOR_TOP | View.SCROLL_INDICATOR_LEFT}.
   5358      * <p>
   5359      * To check whether the bottom scroll indicator is enabled, use the value
   5360      * of {@code (getScrollIndicators() & View.SCROLL_INDICATOR_BOTTOM) != 0}.
   5361      *
   5362      * @return a bitmask representing the enabled scroll indicators
   5363      */
   5364     @ScrollIndicators
   5365     public int getScrollIndicators() {
   5366         return (mPrivateFlags3 & SCROLL_INDICATORS_PFLAG3_MASK)
   5367                 >>> SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT;
   5368     }
   5369 
   5370     ListenerInfo getListenerInfo() {
   5371         if (mListenerInfo != null) {
   5372             return mListenerInfo;
   5373         }
   5374         mListenerInfo = new ListenerInfo();
   5375         return mListenerInfo;
   5376     }
   5377 
   5378     /**
   5379      * Register a callback to be invoked when the scroll X or Y positions of
   5380      * this view change.
   5381      * <p>
   5382      * <b>Note:</b> Some views handle scrolling independently from View and may
   5383      * have their own separate listeners for scroll-type events. For example,
   5384      * {@link android.widget.ListView ListView} allows clients to register an
   5385      * {@link android.widget.ListView#setOnScrollListener(android.widget.AbsListView.OnScrollListener) AbsListView.OnScrollListener}
   5386      * to listen for changes in list scroll position.
   5387      *
   5388      * @param l The listener to notify when the scroll X or Y position changes.
   5389      * @see android.view.View#getScrollX()
   5390      * @see android.view.View#getScrollY()
   5391      */
   5392     public void setOnScrollChangeListener(OnScrollChangeListener l) {
   5393         getListenerInfo().mOnScrollChangeListener = l;
   5394     }
   5395 
   5396     /**
   5397      * Register a callback to be invoked when focus of this view changed.
   5398      *
   5399      * @param l The callback that will run.
   5400      */
   5401     public void setOnFocusChangeListener(OnFocusChangeListener l) {
   5402         getListenerInfo().mOnFocusChangeListener = l;
   5403     }
   5404 
   5405     /**
   5406      * Add a listener that will be called when the bounds of the view change due to
   5407      * layout processing.
   5408      *
   5409      * @param listener The listener that will be called when layout bounds change.
   5410      */
   5411     public void addOnLayoutChangeListener(OnLayoutChangeListener listener) {
   5412         ListenerInfo li = getListenerInfo();
   5413         if (li.mOnLayoutChangeListeners == null) {
   5414             li.mOnLayoutChangeListeners = new ArrayList<OnLayoutChangeListener>();
   5415         }
   5416         if (!li.mOnLayoutChangeListeners.contains(listener)) {
   5417             li.mOnLayoutChangeListeners.add(listener);
   5418         }
   5419     }
   5420 
   5421     /**
   5422      * Remove a listener for layout changes.
   5423      *
   5424      * @param listener The listener for layout bounds change.
   5425      */
   5426     public void removeOnLayoutChangeListener(OnLayoutChangeListener listener) {
   5427         ListenerInfo li = mListenerInfo;
   5428         if (li == null || li.mOnLayoutChangeListeners == null) {
   5429             return;
   5430         }
   5431         li.mOnLayoutChangeListeners.remove(listener);
   5432     }
   5433 
   5434     /**
   5435      * Add a listener for attach state changes.
   5436      *
   5437      * This listener will be called whenever this view is attached or detached
   5438      * from a window. Remove the listener using
   5439      * {@link #removeOnAttachStateChangeListener(OnAttachStateChangeListener)}.
   5440      *
   5441      * @param listener Listener to attach
   5442      * @see #removeOnAttachStateChangeListener(OnAttachStateChangeListener)
   5443      */
   5444     public void addOnAttachStateChangeListener(OnAttachStateChangeListener listener) {
   5445         ListenerInfo li = getListenerInfo();
   5446         if (li.mOnAttachStateChangeListeners == null) {
   5447             li.mOnAttachStateChangeListeners
   5448                     = new CopyOnWriteArrayList<OnAttachStateChangeListener>();
   5449         }
   5450         li.mOnAttachStateChangeListeners.add(listener);
   5451     }
   5452 
   5453     /**
   5454      * Remove a listener for attach state changes. The listener will receive no further
   5455      * notification of window attach/detach events.
   5456      *
   5457      * @param listener Listener to remove
   5458      * @see #addOnAttachStateChangeListener(OnAttachStateChangeListener)
   5459      */
   5460     public void removeOnAttachStateChangeListener(OnAttachStateChangeListener listener) {
   5461         ListenerInfo li = mListenerInfo;
   5462         if (li == null || li.mOnAttachStateChangeListeners == null) {
   5463             return;
   5464         }
   5465         li.mOnAttachStateChangeListeners.remove(listener);
   5466     }
   5467 
   5468     /**
   5469      * Returns the focus-change callback registered for this view.
   5470      *
   5471      * @return The callback, or null if one is not registered.
   5472      */
   5473     public OnFocusChangeListener getOnFocusChangeListener() {
   5474         ListenerInfo li = mListenerInfo;
   5475         return li != null ? li.mOnFocusChangeListener : null;
   5476     }
   5477 
   5478     /**
   5479      * Register a callback to be invoked when this view is clicked. If this view is not
   5480      * clickable, it becomes clickable.
   5481      *
   5482      * @param l The callback that will run
   5483      *
   5484      * @see #setClickable(boolean)
   5485      */
   5486     public void setOnClickListener(@Nullable OnClickListener l) {
   5487         if (!isClickable()) {
   5488             setClickable(true);
   5489         }
   5490         getListenerInfo().mOnClickListener = l;
   5491     }
   5492 
   5493     /**
   5494      * Return whether this view has an attached OnClickListener.  Returns
   5495      * true if there is a listener, false if there is none.
   5496      */
   5497     public boolean hasOnClickListeners() {
   5498         ListenerInfo li = mListenerInfo;
   5499         return (li != null && li.mOnClickListener != null);
   5500     }
   5501 
   5502     /**
   5503      * Register a callback to be invoked when this view is clicked and held. If this view is not
   5504      * long clickable, it becomes long clickable.
   5505      *
   5506      * @param l The callback that will run
   5507      *
   5508      * @see #setLongClickable(boolean)
   5509      */
   5510     public void setOnLongClickListener(@Nullable OnLongClickListener l) {
   5511         if (!isLongClickable()) {
   5512             setLongClickable(true);
   5513         }
   5514         getListenerInfo().mOnLongClickListener = l;
   5515     }
   5516 
   5517     /**
   5518      * Register a callback to be invoked when this view is context clicked. If the view is not
   5519      * context clickable, it becomes context clickable.
   5520      *
   5521      * @param l The callback that will run
   5522      * @see #setContextClickable(boolean)
   5523      */
   5524     public void setOnContextClickListener(@Nullable OnContextClickListener l) {
   5525         if (!isContextClickable()) {
   5526             setContextClickable(true);
   5527         }
   5528         getListenerInfo().mOnContextClickListener = l;
   5529     }
   5530 
   5531     /**
   5532      * Register a callback to be invoked when the context menu for this view is
   5533      * being built. If this view is not long clickable, it becomes long clickable.
   5534      *
   5535      * @param l The callback that will run
   5536      *
   5537      */
   5538     public void setOnCreateContextMenuListener(OnCreateContextMenuListener l) {
   5539         if (!isLongClickable()) {
   5540             setLongClickable(true);
   5541         }
   5542         getListenerInfo().mOnCreateContextMenuListener = l;
   5543     }
   5544 
   5545     /**
   5546      * Set an observer to collect stats for each frame rendered for this view.
   5547      *
   5548      * @hide
   5549      */
   5550     public void addFrameMetricsListener(Window window,
   5551             Window.OnFrameMetricsAvailableListener listener,
   5552             Handler handler) {
   5553         if (mAttachInfo != null) {
   5554             if (mAttachInfo.mHardwareRenderer != null) {
   5555                 if (mFrameMetricsObservers == null) {
   5556                     mFrameMetricsObservers = new ArrayList<>();
   5557                 }
   5558 
   5559                 FrameMetricsObserver fmo = new FrameMetricsObserver(window,
   5560                         handler.getLooper(), listener);
   5561                 mFrameMetricsObservers.add(fmo);
   5562                 mAttachInfo.mHardwareRenderer.addFrameMetricsObserver(fmo);
   5563             } else {
   5564                 Log.w(VIEW_LOG_TAG, "View not hardware-accelerated. Unable to observe frame stats");
   5565             }
   5566         } else {
   5567             if (mFrameMetricsObservers == null) {
   5568                 mFrameMetricsObservers = new ArrayList<>();
   5569             }
   5570 
   5571             FrameMetricsObserver fmo = new FrameMetricsObserver(window,
   5572                     handler.getLooper(), listener);
   5573             mFrameMetricsObservers.add(fmo);
   5574         }
   5575     }
   5576 
   5577     /**
   5578      * Remove observer configured to collect frame stats for this view.
   5579      *
   5580      * @hide
   5581      */
   5582     public void removeFrameMetricsListener(
   5583             Window.OnFrameMetricsAvailableListener listener) {
   5584         ThreadedRenderer renderer = getHardwareRenderer();
   5585         FrameMetricsObserver fmo = findFrameMetricsObserver(listener);
   5586         if (fmo == null) {
   5587             throw new IllegalArgumentException(
   5588                     "attempt to remove OnFrameMetricsAvailableListener that was never added");
   5589         }
   5590 
   5591         if (mFrameMetricsObservers != null) {
   5592             mFrameMetricsObservers.remove(fmo);
   5593             if (renderer != null) {
   5594                 renderer.removeFrameMetricsObserver(fmo);
   5595             }
   5596         }
   5597     }
   5598 
   5599     private void registerPendingFrameMetricsObservers() {
   5600         if (mFrameMetricsObservers != null) {
   5601             ThreadedRenderer renderer = getHardwareRenderer();
   5602             if (renderer != null) {
   5603                 for (FrameMetricsObserver fmo : mFrameMetricsObservers) {
   5604                     renderer.addFrameMetricsObserver(fmo);
   5605                 }
   5606             } else {
   5607                 Log.w(VIEW_LOG_TAG, "View not hardware-accelerated. Unable to observe frame stats");
   5608             }
   5609         }
   5610     }
   5611 
   5612     private FrameMetricsObserver findFrameMetricsObserver(
   5613             Window.OnFrameMetricsAvailableListener listener) {
   5614         for (int i = 0; i < mFrameMetricsObservers.size(); i++) {
   5615             FrameMetricsObserver observer = mFrameMetricsObservers.get(i);
   5616             if (observer.mListener == listener) {
   5617                 return observer;
   5618             }
   5619         }
   5620 
   5621         return null;
   5622     }
   5623 
   5624     /**
   5625      * Call this view's OnClickListener, if it is defined.  Performs all normal
   5626      * actions associated with clicking: reporting accessibility event, playing
   5627      * a sound, etc.
   5628      *
   5629      * @return True there was an assigned OnClickListener that was called, false
   5630      *         otherwise is returned.
   5631      */
   5632     public boolean performClick() {
   5633         final boolean result;
   5634         final ListenerInfo li = mListenerInfo;
   5635         if (li != null && li.mOnClickListener != null) {
   5636             playSoundEffect(SoundEffectConstants.CLICK);
   5637             li.mOnClickListener.onClick(this);
   5638             result = true;
   5639         } else {
   5640             result = false;
   5641         }
   5642 
   5643         sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
   5644         return result;
   5645     }
   5646 
   5647     /**
   5648      * Directly call any attached OnClickListener.  Unlike {@link #performClick()},
   5649      * this only calls the listener, and does not do any associated clicking
   5650      * actions like reporting an accessibility event.
   5651      *
   5652      * @return True there was an assigned OnClickListener that was called, false
   5653      *         otherwise is returned.
   5654      */
   5655     public boolean callOnClick() {
   5656         ListenerInfo li = mListenerInfo;
   5657         if (li != null && li.mOnClickListener != null) {
   5658             li.mOnClickListener.onClick(this);
   5659             return true;
   5660         }
   5661         return false;
   5662     }
   5663 
   5664     /**
   5665      * Calls this view's OnLongClickListener, if it is defined. Invokes the
   5666      * context menu if the OnLongClickListener did not consume the event.
   5667      *
   5668      * @return {@code true} if one of the above receivers consumed the event,
   5669      *         {@code false} otherwise
   5670      */
   5671     public boolean performLongClick() {
   5672         return performLongClickInternal(mLongClickX, mLongClickY);
   5673     }
   5674 
   5675     /**
   5676      * Calls this view's OnLongClickListener, if it is defined. Invokes the
   5677      * context menu if the OnLongClickListener did not consume the event,
   5678      * anchoring it to an (x,y) coordinate.
   5679      *
   5680      * @param x x coordinate of the anchoring touch event, or {@link Float#NaN}
   5681      *          to disable anchoring
   5682      * @param y y coordinate of the anchoring touch event, or {@link Float#NaN}
   5683      *          to disable anchoring
   5684      * @return {@code true} if one of the above receivers consumed the event,
   5685      *         {@code false} otherwise
   5686      */
   5687     public boolean performLongClick(float x, float y) {
   5688         mLongClickX = x;
   5689         mLongClickY = y;
   5690         final boolean handled = performLongClick();
   5691         mLongClickX = Float.NaN;
   5692         mLongClickY = Float.NaN;
   5693         return handled;
   5694     }
   5695 
   5696     /**
   5697      * Calls this view's OnLongClickListener, if it is defined. Invokes the
   5698      * context menu if the OnLongClickListener did not consume the event,
   5699      * optionally anchoring it to an (x,y) coordinate.
   5700      *
   5701      * @param x x coordinate of the anchoring touch event, or {@link Float#NaN}
   5702      *          to disable anchoring
   5703      * @param y y coordinate of the anchoring touch event, or {@link Float#NaN}
   5704      *          to disable anchoring
   5705      * @return {@code true} if one of the above receivers consumed the event,
   5706      *         {@code false} otherwise
   5707      */
   5708     private boolean performLongClickInternal(float x, float y) {
   5709         sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
   5710 
   5711         boolean handled = false;
   5712         final ListenerInfo li = mListenerInfo;
   5713         if (li != null && li.mOnLongClickListener != null) {
   5714             handled = li.mOnLongClickListener.onLongClick(View.this);
   5715         }
   5716         if (!handled) {
   5717             final boolean isAnchored = !Float.isNaN(x) && !Float.isNaN(y);
   5718             handled = isAnchored ? showContextMenu(x, y) : showContextMenu();
   5719         }
   5720         if (handled) {
   5721             performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
   5722         }
   5723         return handled;
   5724     }
   5725 
   5726     /**
   5727      * Call this view's OnContextClickListener, if it is defined.
   5728      *
   5729      * @param x the x coordinate of the context click
   5730      * @param y the y coordinate of the context click
   5731      * @return True if there was an assigned OnContextClickListener that consumed the event, false
   5732      *         otherwise.
   5733      */
   5734     public boolean performContextClick(float x, float y) {
   5735         return performContextClick();
   5736     }
   5737 
   5738     /**
   5739      * Call this view's OnContextClickListener, if it is defined.
   5740      *
   5741      * @return True if there was an assigned OnContextClickListener that consumed the event, false
   5742      *         otherwise.
   5743      */
   5744     public boolean performContextClick() {
   5745         sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CONTEXT_CLICKED);
   5746 
   5747         boolean handled = false;
   5748         ListenerInfo li = mListenerInfo;
   5749         if (li != null && li.mOnContextClickListener != null) {
   5750             handled = li.mOnContextClickListener.onContextClick(View.this);
   5751         }
   5752         if (handled) {
   5753             performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK);
   5754         }
   5755         return handled;
   5756     }
   5757 
   5758     /**
   5759      * Performs button-related actions during a touch down event.
   5760      *
   5761      * @param event The event.
   5762      * @return True if the down was consumed.
   5763      *
   5764      * @hide
   5765      */
   5766     protected boolean performButtonActionOnTouchDown(MotionEvent event) {
   5767         if (event.isFromSource(InputDevice.SOURCE_MOUSE) &&
   5768             (event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) {
   5769             showContextMenu(event.getX(), event.getY());
   5770             mPrivateFlags |= PFLAG_CANCEL_NEXT_UP_EVENT;
   5771             return true;
   5772         }
   5773         return false;
   5774     }
   5775 
   5776     /**
   5777      * Shows the context menu for this view.
   5778      *
   5779      * @return {@code true} if the context menu was shown, {@code false}
   5780      *         otherwise
   5781      * @see #showContextMenu(float, float)
   5782      */
   5783     public boolean showContextMenu() {
   5784         return getParent().showContextMenuForChild(this);
   5785     }
   5786 
   5787     /**
   5788      * Shows the context menu for this view anchored to the specified
   5789      * view-relative coordinate.
   5790      *
   5791      * @param x the X coordinate in pixels relative to the view to which the
   5792      *          menu should be anchored, or {@link Float#NaN} to disable anchoring
   5793      * @param y the Y coordinate in pixels relative to the view to which the
   5794      *          menu should be anchored, or {@link Float#NaN} to disable anchoring
   5795      * @return {@code true} if the context menu was shown, {@code false}
   5796      *         otherwise
   5797      */
   5798     public boolean showContextMenu(float x, float y) {
   5799         return getParent().showContextMenuForChild(this, x, y);
   5800     }
   5801 
   5802     /**
   5803      * Start an action mode with the default type {@link ActionMode#TYPE_PRIMARY}.
   5804      *
   5805      * @param callback Callback that will control the lifecycle of the action mode
   5806      * @return The new action mode if it is started, null otherwise
   5807      *
   5808      * @see ActionMode
   5809      * @see #startActionMode(android.view.ActionMode.Callback, int)
   5810      */
   5811     public ActionMode startActionMode(ActionMode.Callback callback) {
   5812         return startActionMode(callback, ActionMode.TYPE_PRIMARY);
   5813     }
   5814 
   5815     /**
   5816      * Start an action mode with the given type.
   5817      *
   5818      * @param callback Callback that will control the lifecycle of the action mode
   5819      * @param type One of {@link ActionMode#TYPE_PRIMARY} or {@link ActionMode#TYPE_FLOATING}.
   5820      * @return The new action mode if it is started, null otherwise
   5821      *
   5822      * @see ActionMode
   5823      */
   5824     public ActionMode startActionMode(ActionMode.Callback callback, int type) {
   5825         ViewParent parent = getParent();
   5826         if (parent == null) return null;
   5827         try {
   5828             return parent.startActionModeForChild(this, callback, type);
   5829         } catch (AbstractMethodError ame) {
   5830             // Older implementations of custom views might not implement this.
   5831             return parent.startActionModeForChild(this, callback);
   5832         }
   5833     }
   5834 
   5835     /**
   5836      * Call {@link Context#startActivityForResult(String, Intent, int, Bundle)} for the View's
   5837      * Context, creating a unique View identifier to retrieve the result.
   5838      *
   5839      * @param intent The Intent to be started.
   5840      * @param requestCode The request code to use.
   5841      * @hide
   5842      */
   5843     public void startActivityForResult(Intent intent, int requestCode) {
   5844         mStartActivityRequestWho = "@android:view:" + System.identityHashCode(this);
   5845         getContext().startActivityForResult(mStartActivityRequestWho, intent, requestCode, null);
   5846     }
   5847 
   5848     /**
   5849      * If this View corresponds to the calling who, dispatches the activity result.
   5850      * @param who The identifier for the targeted View to receive the result.
   5851      * @param requestCode The integer request code originally supplied to
   5852      *                    startActivityForResult(), allowing you to identify who this
   5853      *                    result came from.
   5854      * @param resultCode The integer result code returned by the child activity
   5855      *                   through its setResult().
   5856      * @param data An Intent, which can return result data to the caller
   5857      *               (various data can be attached to Intent "extras").
   5858      * @return {@code true} if the activity result was dispatched.
   5859      * @hide
   5860      */
   5861     public boolean dispatchActivityResult(
   5862             String who, int requestCode, int resultCode, Intent data) {
   5863         if (mStartActivityRequestWho != null && mStartActivityRequestWho.equals(who)) {
   5864             onActivityResult(requestCode, resultCode, data);
   5865             mStartActivityRequestWho = null;
   5866             return true;
   5867         }
   5868         return false;
   5869     }
   5870 
   5871     /**
   5872      * Receive the result from a previous call to {@link #startActivityForResult(Intent, int)}.
   5873      *
   5874      * @param requestCode The integer request code originally supplied to
   5875      *                    startActivityForResult(), allowing you to identify who this
   5876      *                    result came from.
   5877      * @param resultCode The integer result code returned by the child activity
   5878      *                   through its setResult().
   5879      * @param data An Intent, which can return result data to the caller
   5880      *               (various data can be attached to Intent "extras").
   5881      * @hide
   5882      */
   5883     public void onActivityResult(int requestCode, int resultCode, Intent data) {
   5884         // Do nothing.
   5885     }
   5886 
   5887     /**
   5888      * Register a callback to be invoked when a hardware key is pressed in this view.
   5889      * Key presses in software input methods will generally not trigger the methods of
   5890      * this listener.
   5891      * @param l the key listener to attach to this view
   5892      */
   5893     public void setOnKeyListener(OnKeyListener l) {
   5894         getListenerInfo().mOnKeyListener = l;
   5895     }
   5896 
   5897     /**
   5898      * Register a callback to be invoked when a touch event is sent to this view.
   5899      * @param l the touch listener to attach to this view
   5900      */
   5901     public void setOnTouchListener(OnTouchListener l) {
   5902         getListenerInfo().mOnTouchListener = l;
   5903     }
   5904 
   5905     /**
   5906      * Register a callback to be invoked when a generic motion event is sent to this view.
   5907      * @param l the generic motion listener to attach to this view
   5908      */
   5909     public void setOnGenericMotionListener(OnGenericMotionListener l) {
   5910         getListenerInfo().mOnGenericMotionListener = l;
   5911     }
   5912 
   5913     /**
   5914      * Register a callback to be invoked when a hover event is sent to this view.
   5915      * @param l the hover listener to attach to this view
   5916      */
   5917     public void setOnHoverListener(OnHoverListener l) {
   5918         getListenerInfo().mOnHoverListener = l;
   5919     }
   5920 
   5921     /**
   5922      * Register a drag event listener callback object for this View. The parameter is
   5923      * an implementation of {@link android.view.View.OnDragListener}. To send a drag event to a
   5924      * View, the system calls the
   5925      * {@link android.view.View.OnDragListener#onDrag(View,DragEvent)} method.
   5926      * @param l An implementation of {@link android.view.View.OnDragListener}.
   5927      */
   5928     public void setOnDragListener(OnDragListener l) {
   5929         getListenerInfo().mOnDragListener = l;
   5930     }
   5931 
   5932     /**
   5933      * Give this view focus. This will cause
   5934      * {@link #onFocusChanged(boolean, int, android.graphics.Rect)} to be called.
   5935      *
   5936      * Note: this does not check whether this {@link View} should get focus, it just
   5937      * gives it focus no matter what.  It should only be called internally by framework
   5938      * code that knows what it is doing, namely {@link #requestFocus(int, Rect)}.
   5939      *
   5940      * @param direction values are {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN},
   5941      *        {@link View#FOCUS_LEFT} or {@link View#FOCUS_RIGHT}. This is the direction which
   5942      *        focus moved when requestFocus() is called. It may not always
   5943      *        apply, in which case use the default View.FOCUS_DOWN.
   5944      * @param previouslyFocusedRect The rectangle of the view that had focus
   5945      *        prior in this View's coordinate system.
   5946      */
   5947     void handleFocusGainInternal(@FocusRealDirection int direction, Rect previouslyFocusedRect) {
   5948         if (DBG) {
   5949             System.out.println(this + " requestFocus()");
   5950         }
   5951 
   5952         if ((mPrivateFlags & PFLAG_FOCUSED) == 0) {
   5953             mPrivateFlags |= PFLAG_FOCUSED;
   5954 
   5955             View oldFocus = (mAttachInfo != null) ? getRootView().findFocus() : null;
   5956 
   5957             if (mParent != null) {
   5958                 mParent.requestChildFocus(this, this);
   5959             }
   5960 
   5961             if (mAttachInfo != null) {
   5962                 mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(oldFocus, this);
   5963             }
   5964 
   5965             onFocusChanged(true, direction, previouslyFocusedRect);
   5966             refreshDrawableState();
   5967         }
   5968     }
   5969 
   5970     /**
   5971      * Sets this view's preference for reveal behavior when it gains focus.
   5972      *
   5973      * <p>When set to true, this is a signal to ancestor views in the hierarchy that
   5974      * this view would prefer to be brought fully into view when it gains focus.
   5975      * For example, a text field that a user is meant to type into. Other views such
   5976      * as scrolling containers may prefer to opt-out of this behavior.</p>
   5977      *
   5978      * <p>The default value for views is true, though subclasses may change this
   5979      * based on their preferred behavior.</p>
   5980      *
   5981      * @param revealOnFocus true to request reveal on focus in ancestors, false otherwise
   5982      *
   5983      * @see #getRevealOnFocusHint()
   5984      */
   5985     public final void setRevealOnFocusHint(boolean revealOnFocus) {
   5986         if (revealOnFocus) {
   5987             mPrivateFlags3 &= ~PFLAG3_NO_REVEAL_ON_FOCUS;
   5988         } else {
   5989             mPrivateFlags3 |= PFLAG3_NO_REVEAL_ON_FOCUS;
   5990         }
   5991     }
   5992 
   5993     /**
   5994      * Returns this view's preference for reveal behavior when it gains focus.
   5995      *
   5996      * <p>When this method returns true for a child view requesting focus, ancestor
   5997      * views responding to a focus change in {@link ViewParent#requestChildFocus(View, View)}
   5998      * should make a best effort to make the newly focused child fully visible to the user.
   5999      * When it returns false, ancestor views should preferably not disrupt scroll positioning or
   6000      * other properties affecting visibility to the user as part of the focus change.</p>
   6001      *
   6002      * @return true if this view would prefer to become fully visible when it gains focus,
   6003      *         false if it would prefer not to disrupt scroll positioning
   6004      *
   6005      * @see #setRevealOnFocusHint(boolean)
   6006      */
   6007     public final boolean getRevealOnFocusHint() {
   6008         return (mPrivateFlags3 & PFLAG3_NO_REVEAL_ON_FOCUS) == 0;
   6009     }
   6010 
   6011     /**
   6012      * Populates <code>outRect</code> with the hotspot bounds. By default,
   6013      * the hotspot bounds are identical to the screen bounds.
   6014      *
   6015      * @param outRect rect to populate with hotspot bounds
   6016      * @hide Only for internal use by views and widgets.
   6017      */
   6018     public void getHotspotBounds(Rect outRect) {
   6019         final Drawable background = getBackground();
   6020         if (background != null) {
   6021             background.getHotspotBounds(outRect);
   6022         } else {
   6023             getBoundsOnScreen(outRect);
   6024         }
   6025     }
   6026 
   6027     /**
   6028      * Request that a rectangle of this view be visible on the screen,
   6029      * scrolling if necessary just enough.
   6030      *
   6031      * <p>A View should call this if it maintains some notion of which part
   6032      * of its content is interesting.  For example, a text editing view
   6033      * should call this when its cursor moves.
   6034      * <p>The Rectangle passed into this method should be in the View's content coordinate space.
   6035      * It should not be affected by which part of the View is currently visible or its scroll
   6036      * position.
   6037      *
   6038      * @param rectangle The rectangle in the View's content coordinate space
   6039      * @return Whether any parent scrolled.
   6040      */
   6041     public boolean requestRectangleOnScreen(Rect rectangle) {
   6042         return requestRectangleOnScreen(rectangle, false);
   6043     }
   6044 
   6045     /**
   6046      * Request that a rectangle of this view be visible on the screen,
   6047      * scrolling if necessary just enough.
   6048      *
   6049      * <p>A View should call this if it maintains some notion of which part
   6050      * of its content is interesting.  For example, a text editing view
   6051      * should call this when its cursor moves.
   6052      * <p>The Rectangle passed into this method should be in the View's content coordinate space.
   6053      * It should not be affected by which part of the View is currently visible or its scroll
   6054      * position.
   6055      * <p>When <code>immediate</code> is set to true, scrolling will not be
   6056      * animated.
   6057      *
   6058      * @param rectangle The rectangle in the View's content coordinate space
   6059      * @param immediate True to forbid animated scrolling, false otherwise
   6060      * @return Whether any parent scrolled.
   6061      */
   6062     public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) {
   6063         if (mParent == null) {
   6064             return false;
   6065         }
   6066 
   6067         View child = this;
   6068 
   6069         RectF position = (mAttachInfo != null) ? mAttachInfo.mTmpTransformRect : new RectF();
   6070         position.set(rectangle);
   6071 
   6072         ViewParent parent = mParent;
   6073         boolean scrolled = false;
   6074         while (parent != null) {
   6075             rectangle.set((int) position.left, (int) position.top,
   6076                     (int) position.right, (int) position.bottom);
   6077 
   6078             scrolled |= parent.requestChildRectangleOnScreen(child, rectangle, immediate);
   6079 
   6080             if (!(parent instanceof View)) {
   6081                 break;
   6082             }
   6083 
   6084             // move it from child's content coordinate space to parent's content coordinate space
   6085             position.offset(child.mLeft - child.getScrollX(), child.mTop -child.getScrollY());
   6086 
   6087             child = (View) parent;
   6088             parent = child.getParent();
   6089         }
   6090 
   6091         return scrolled;
   6092     }
   6093 
   6094     /**
   6095      * Called when this view wants to give up focus. If focus is cleared
   6096      * {@link #onFocusChanged(boolean, int, android.graphics.Rect)} is called.
   6097      * <p>
   6098      * <strong>Note:</strong> When a View clears focus the framework is trying
   6099      * to give focus to the first focusable View from the top. Hence, if this
   6100      * View is the first from the top that can take focus, then all callbacks
   6101      * related to clearing focus will be invoked after which the framework will
   6102      * give focus to this view.
   6103      * </p>
   6104      */
   6105     public void clearFocus() {
   6106         if (DBG) {
   6107             System.out.println(this + " clearFocus()");
   6108         }
   6109 
   6110         clearFocusInternal(null, true, true);
   6111     }
   6112 
   6113     /**
   6114      * Clears focus from the view, optionally propagating the change up through
   6115      * the parent hierarchy and requesting that the root view place new focus.
   6116      *
   6117      * @param propagate whether to propagate the change up through the parent
   6118      *            hierarchy
   6119      * @param refocus when propagate is true, specifies whether to request the
   6120      *            root view place new focus
   6121      */
   6122     void clearFocusInternal(View focused, boolean propagate, boolean refocus) {
   6123         if ((mPrivateFlags & PFLAG_FOCUSED) != 0) {
   6124             mPrivateFlags &= ~PFLAG_FOCUSED;
   6125 
   6126             if (propagate && mParent != null) {
   6127                 mParent.clearChildFocus(this);
   6128             }
   6129 
   6130             onFocusChanged(false, 0, null);
   6131             refreshDrawableState();
   6132 
   6133             if (propagate && (!refocus || !rootViewRequestFocus())) {
   6134                 notifyGlobalFocusCleared(this);
   6135             }
   6136         }
   6137     }
   6138 
   6139     void notifyGlobalFocusCleared(View oldFocus) {
   6140         if (oldFocus != null && mAttachInfo != null) {
   6141             mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(oldFocus, null);
   6142         }
   6143     }
   6144 
   6145     boolean rootViewRequestFocus() {
   6146         final View root = getRootView();
   6147         return root != null && root.requestFocus();
   6148     }
   6149 
   6150     /**
   6151      * Called internally by the view system when a new view is getting focus.
   6152      * This is what clears the old focus.
   6153      * <p>
   6154      * <b>NOTE:</b> The parent view's focused child must be updated manually
   6155      * after calling this method. Otherwise, the view hierarchy may be left in
   6156      * an inconstent state.
   6157      */
   6158     void unFocus(View focused) {
   6159         if (DBG) {
   6160             System.out.println(this + " unFocus()");
   6161         }
   6162 
   6163         clearFocusInternal(focused, false, false);
   6164     }
   6165 
   6166     /**
   6167      * Returns true if this view has focus itself, or is the ancestor of the
   6168      * view that has focus.
   6169      *
   6170      * @return True if this view has or contains focus, false otherwise.
   6171      */
   6172     @ViewDebug.ExportedProperty(category = "focus")
   6173     public boolean hasFocus() {
   6174         return (mPrivateFlags & PFLAG_FOCUSED) != 0;
   6175     }
   6176 
   6177     /**
   6178      * Returns true if this view is focusable or if it contains a reachable View
   6179      * for which {@link #hasFocusable()} returns true. A "reachable hasFocusable()"
   6180      * is a View whose parents do not block descendants focus.
   6181      *
   6182      * Only {@link #VISIBLE} views are considered focusable.
   6183      *
   6184      * @return True if the view is focusable or if the view contains a focusable
   6185      *         View, false otherwise.
   6186      *
   6187      * @see ViewGroup#FOCUS_BLOCK_DESCENDANTS
   6188      * @see ViewGroup#getTouchscreenBlocksFocus()
   6189      */
   6190     public boolean hasFocusable() {
   6191         if (!isFocusableInTouchMode()) {
   6192             for (ViewParent p = mParent; p instanceof ViewGroup; p = p.getParent()) {
   6193                 final ViewGroup g = (ViewGroup) p;
   6194                 if (g.shouldBlockFocusForTouchscreen()) {
   6195                     return false;
   6196                 }
   6197             }
   6198         }
   6199         return (mViewFlags & VISIBILITY_MASK) == VISIBLE && isFocusable();
   6200     }
   6201 
   6202     /**
   6203      * Called by the view system when the focus state of this view changes.
   6204      * When the focus change event is caused by directional navigation, direction
   6205      * and previouslyFocusedRect provide insight into where the focus is coming from.
   6206      * When overriding, be sure to call up through to the super class so that
   6207      * the standard focus handling will occur.
   6208      *
   6209      * @param gainFocus True if the View has focus; false otherwise.
   6210      * @param direction The direction focus has moved when requestFocus()
   6211      *                  is called to give this view focus. Values are
   6212      *                  {@link #FOCUS_UP}, {@link #FOCUS_DOWN}, {@link #FOCUS_LEFT},
   6213      *                  {@link #FOCUS_RIGHT}, {@link #FOCUS_FORWARD}, or {@link #FOCUS_BACKWARD}.
   6214      *                  It may not always apply, in which case use the default.
   6215      * @param previouslyFocusedRect The rectangle, in this view's coordinate
   6216      *        system, of the previously focused view.  If applicable, this will be
   6217      *        passed in as finer grained information about where the focus is coming
   6218      *        from (in addition to direction).  Will be <code>null</code> otherwise.
   6219      */
   6220     @CallSuper
   6221     protected void onFocusChanged(boolean gainFocus, @FocusDirection int direction,
   6222             @Nullable Rect previouslyFocusedRect) {
   6223         if (gainFocus) {
   6224             sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
   6225         } else {
   6226             notifyViewAccessibilityStateChangedIfNeeded(
   6227                     AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED);
   6228         }
   6229 
   6230         InputMethodManager imm = InputMethodManager.peekInstance();
   6231         if (!gainFocus) {
   6232             if (isPressed()) {
   6233                 setPressed(false);
   6234             }
   6235             if (imm != null && mAttachInfo != null
   6236                     && mAttachInfo.mHasWindowFocus) {
   6237                 imm.focusOut(this);
   6238             }
   6239             onFocusLost();
   6240         } else if (imm != null && mAttachInfo != null
   6241                 && mAttachInfo.mHasWindowFocus) {
   6242             imm.focusIn(this);
   6243         }
   6244 
   6245         invalidate(true);
   6246         ListenerInfo li = mListenerInfo;
   6247         if (li != null && li.mOnFocusChangeListener != null) {
   6248             li.mOnFocusChangeListener.onFocusChange(this, gainFocus);
   6249         }
   6250 
   6251         if (mAttachInfo != null) {
   6252             mAttachInfo.mKeyDispatchState.reset(this);
   6253         }
   6254     }
   6255 
   6256     /**
   6257      * Sends an accessibility event of the given type. If accessibility is
   6258      * not enabled this method has no effect. The default implementation calls
   6259      * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)} first
   6260      * to populate information about the event source (this View), then calls
   6261      * {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} to
   6262      * populate the text content of the event source including its descendants,
   6263      * and last calls
   6264      * {@link ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)}
   6265      * on its parent to request sending of the event to interested parties.
   6266      * <p>
   6267      * If an {@link AccessibilityDelegate} has been specified via calling
   6268      * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its
   6269      * {@link AccessibilityDelegate#sendAccessibilityEvent(View, int)} is
   6270      * responsible for handling this call.
   6271      * </p>
   6272      *
   6273      * @param eventType The type of the event to send, as defined by several types from
   6274      * {@link android.view.accessibility.AccessibilityEvent}, such as
   6275      * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_CLICKED} or
   6276      * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_ENTER}.
   6277      *
   6278      * @see #onInitializeAccessibilityEvent(AccessibilityEvent)
   6279      * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent)
   6280      * @see ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)
   6281      * @see AccessibilityDelegate
   6282      */
   6283     public void sendAccessibilityEvent(int eventType) {
   6284         if (mAccessibilityDelegate != null) {
   6285             mAccessibilityDelegate.sendAccessibilityEvent(this, eventType);
   6286         } else {
   6287             sendAccessibilityEventInternal(eventType);
   6288         }
   6289     }
   6290 
   6291     /**
   6292      * Convenience method for sending a {@link AccessibilityEvent#TYPE_ANNOUNCEMENT}
   6293      * {@link AccessibilityEvent} to make an announcement which is related to some
   6294      * sort of a context change for which none of the events representing UI transitions
   6295      * is a good fit. For example, announcing a new page in a book. If accessibility
   6296      * is not enabled this method does nothing.
   6297      *
   6298      * @param text The announcement text.
   6299      */
   6300     public void announceForAccessibility(CharSequence text) {
   6301         if (AccessibilityManager.getInstance(mContext).isEnabled() && mParent != null) {
   6302             AccessibilityEvent event = AccessibilityEvent.obtain(
   6303                     AccessibilityEvent.TYPE_ANNOUNCEMENT);
   6304             onInitializeAccessibilityEvent(event);
   6305             event.getText().add(text);
   6306             event.setContentDescription(null);
   6307             mParent.requestSendAccessibilityEvent(this, event);
   6308         }
   6309     }
   6310 
   6311     /**
   6312      * @see #sendAccessibilityEvent(int)
   6313      *
   6314      * Note: Called from the default {@link AccessibilityDelegate}.
   6315      *
   6316      * @hide
   6317      */
   6318     public void sendAccessibilityEventInternal(int eventType) {
   6319         if (AccessibilityManager.getInstance(mContext).isEnabled()) {
   6320             sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType));
   6321         }
   6322     }
   6323 
   6324     /**
   6325      * This method behaves exactly as {@link #sendAccessibilityEvent(int)} but
   6326      * takes as an argument an empty {@link AccessibilityEvent} and does not
   6327      * perform a check whether accessibility is enabled.
   6328      * <p>
   6329      * If an {@link AccessibilityDelegate} has been specified via calling
   6330      * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its
   6331      * {@link AccessibilityDelegate#sendAccessibilityEventUnchecked(View, AccessibilityEvent)}
   6332      * is responsible for handling this call.
   6333      * </p>
   6334      *
   6335      * @param event The event to send.
   6336      *
   6337      * @see #sendAccessibilityEvent(int)
   6338      */
   6339     public void sendAccessibilityEventUnchecked(AccessibilityEvent event) {
   6340         if (mAccessibilityDelegate != null) {
   6341             mAccessibilityDelegate.sendAccessibilityEventUnchecked(this, event);
   6342         } else {
   6343             sendAccessibilityEventUncheckedInternal(event);
   6344         }
   6345     }
   6346 
   6347     /**
   6348      * @see #sendAccessibilityEventUnchecked(AccessibilityEvent)
   6349      *
   6350      * Note: Called from the default {@link AccessibilityDelegate}.
   6351      *
   6352      * @hide
   6353      */
   6354     public void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) {
   6355         if (!isShown()) {
   6356             return;
   6357         }
   6358         onInitializeAccessibilityEvent(event);
   6359         // Only a subset of accessibility events populates text content.
   6360         if ((event.getEventType() & POPULATING_ACCESSIBILITY_EVENT_TYPES) != 0) {
   6361             dispatchPopulateAccessibilityEvent(event);
   6362         }
   6363         // In the beginning we called #isShown(), so we know that getParent() is not null.
   6364         getParent().requestSendAccessibilityEvent(this, event);
   6365     }
   6366 
   6367     /**
   6368      * Dispatches an {@link AccessibilityEvent} to the {@link View} first and then
   6369      * to its children for adding their text content to the event. Note that the
   6370      * event text is populated in a separate dispatch path since we add to the
   6371      * event not only the text of the source but also the text of all its descendants.
   6372      * A typical implementation will call
   6373      * {@link #onPopulateAccessibilityEvent(AccessibilityEvent)} on the this view
   6374      * and then call the {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)}
   6375      * on each child. Override this method if custom population of the event text
   6376      * content is required.
   6377      * <p>
   6378      * If an {@link AccessibilityDelegate} has been specified via calling
   6379      * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its
   6380      * {@link AccessibilityDelegate#dispatchPopulateAccessibilityEvent(View, AccessibilityEvent)}
   6381      * is responsible for handling this call.
   6382      * </p>
   6383      * <p>
   6384      * <em>Note:</em> Accessibility events of certain types are not dispatched for
   6385      * populating the event text via this method. For details refer to {@link AccessibilityEvent}.
   6386      * </p>
   6387      *
   6388      * @param event The event.
   6389      *
   6390      * @return True if the event population was completed.
   6391      */
   6392     public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
   6393         if (mAccessibilityDelegate != null) {
   6394             return mAccessibilityDelegate.dispatchPopulateAccessibilityEvent(this, event);
   6395         } else {
   6396             return dispatchPopulateAccessibilityEventInternal(event);
   6397         }
   6398     }
   6399 
   6400     /**
   6401      * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent)
   6402      *
   6403      * Note: Called from the default {@link AccessibilityDelegate}.
   6404      *
   6405      * @hide
   6406      */
   6407     public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
   6408         onPopulateAccessibilityEvent(event);
   6409         return false;
   6410     }
   6411 
   6412     /**
   6413      * Called from {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)}
   6414      * giving a chance to this View to populate the accessibility event with its
   6415      * text content. While this method is free to modify event
   6416      * attributes other than text content, doing so should normally be performed in
   6417      * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)}.
   6418      * <p>
   6419      * Example: Adding formatted date string to an accessibility event in addition
   6420      *          to the text added by the super implementation:
   6421      * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
   6422      *     super.onPopulateAccessibilityEvent(event);
   6423      *     final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY;
   6424      *     String selectedDateUtterance = DateUtils.formatDateTime(mContext,
   6425      *         mCurrentDate.getTimeInMillis(), flags);
   6426      *     event.getText().add(selectedDateUtterance);
   6427      * }</pre>
   6428      * <p>
   6429      * If an {@link AccessibilityDelegate} has been specified via calling
   6430      * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its
   6431      * {@link AccessibilityDelegate#onPopulateAccessibilityEvent(View, AccessibilityEvent)}
   6432      * is responsible for handling this call.
   6433      * </p>
   6434      * <p class="note"><strong>Note:</strong> Always call the super implementation before adding
   6435      * information to the event, in case the default implementation has basic information to add.
   6436      * </p>
   6437      *
   6438      * @param event The accessibility event which to populate.
   6439      *
   6440      * @see #sendAccessibilityEvent(int)
   6441      * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent)
   6442      */
   6443     @CallSuper
   6444     public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
   6445         if (mAccessibilityDelegate != null) {
   6446             mAccessibilityDelegate.onPopulateAccessibilityEvent(this, event);
   6447         } else {
   6448             onPopulateAccessibilityEventInternal(event);
   6449         }
   6450     }
   6451 
   6452     /**
   6453      * @see #onPopulateAccessibilityEvent(AccessibilityEvent)
   6454      *
   6455      * Note: Called from the default {@link AccessibilityDelegate}.
   6456      *
   6457      * @hide
   6458      */
   6459     public void onPopulateAccessibilityEventInternal(AccessibilityEvent event) {
   6460     }
   6461 
   6462     /**
   6463      * Initializes an {@link AccessibilityEvent} with information about
   6464      * this View which is the event source. In other words, the source of
   6465      * an accessibility event is the view whose state change triggered firing
   6466      * the event.
   6467      * <p>
   6468      * Example: Setting the password property of an event in addition
   6469      *          to properties set by the super implementation:
   6470      * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
   6471      *     super.onInitializeAccessibilityEvent(event);
   6472      *     event.setPassword(true);
   6473      * }</pre>
   6474      * <p>
   6475      * If an {@link AccessibilityDelegate} has been specified via calling
   6476      * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its
   6477      * {@link AccessibilityDelegate#onInitializeAccessibilityEvent(View, AccessibilityEvent)}
   6478      * is responsible for handling this call.
   6479      * </p>
   6480      * <p class="note"><strong>Note:</strong> Always call the super implementation before adding
   6481      * information to the event, in case the default implementation has basic information to add.
   6482      * </p>
   6483      * @param event The event to initialize.
   6484      *
   6485      * @see #sendAccessibilityEvent(int)
   6486      * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent)
   6487      */
   6488     @CallSuper
   6489     public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
   6490         if (mAccessibilityDelegate != null) {
   6491             mAccessibilityDelegate.onInitializeAccessibilityEvent(this, event);
   6492         } else {
   6493             onInitializeAccessibilityEventInternal(event);
   6494         }
   6495     }
   6496 
   6497     /**
   6498      * @see #onInitializeAccessibilityEvent(AccessibilityEvent)
   6499      *
   6500      * Note: Called from the default {@link AccessibilityDelegate}.
   6501      *
   6502      * @hide
   6503      */
   6504     public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
   6505         event.setSource(this);
   6506         event.setClassName(getAccessibilityClassName());
   6507         event.setPackageName(getContext().getPackageName());
   6508         event.setEnabled(isEnabled());
   6509         event.setContentDescription(mContentDescription);
   6510 
   6511         switch (event.getEventType()) {
   6512             case AccessibilityEvent.TYPE_VIEW_FOCUSED: {
   6513                 ArrayList<View> focusablesTempList = (mAttachInfo != null)
   6514                         ? mAttachInfo.mTempArrayList : new ArrayList<View>();
   6515                 getRootView().addFocusables(focusablesTempList, View.FOCUS_FORWARD, FOCUSABLES_ALL);
   6516                 event.setItemCount(focusablesTempList.size());
   6517                 event.setCurrentItemIndex(focusablesTempList.indexOf(this));
   6518                 if (mAttachInfo != null) {
   6519                     focusablesTempList.clear();
   6520                 }
   6521             } break;
   6522             case AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED: {
   6523                 CharSequence text = getIterableTextForAccessibility();
   6524                 if (text != null && text.length() > 0) {
   6525                     event.setFromIndex(getAccessibilitySelectionStart());
   6526                     event.setToIndex(getAccessibilitySelectionEnd());
   6527                     event.setItemCount(text.length());
   6528                 }
   6529             } break;
   6530         }
   6531     }
   6532 
   6533     /**
   6534      * Returns an {@link AccessibilityNodeInfo} representing this view from the
   6535      * point of view of an {@link android.accessibilityservice.AccessibilityService}.
   6536      * This method is responsible for obtaining an accessibility node info from a
   6537      * pool of reusable instances and calling
   6538      * {@link #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} on this view to
   6539      * initialize the former.
   6540      * <p>
   6541      * Note: The client is responsible for recycling the obtained instance by calling
   6542      *       {@link AccessibilityNodeInfo#recycle()} to minimize object creation.
   6543      * </p>
   6544      *
   6545      * @return A populated {@link AccessibilityNodeInfo}.
   6546      *
   6547      * @see AccessibilityNodeInfo
   6548      */
   6549     public AccessibilityNodeInfo createAccessibilityNodeInfo() {
   6550         if (mAccessibilityDelegate != null) {
   6551             return mAccessibilityDelegate.createAccessibilityNodeInfo(this);
   6552         } else {
   6553             return createAccessibilityNodeInfoInternal();
   6554         }
   6555     }
   6556 
   6557     /**
   6558      * @see #createAccessibilityNodeInfo()
   6559      *
   6560      * @hide
   6561      */
   6562     public AccessibilityNodeInfo createAccessibilityNodeInfoInternal() {
   6563         AccessibilityNodeProvider provider = getAccessibilityNodeProvider();
   6564         if (provider != null) {
   6565             return provider.createAccessibilityNodeInfo(AccessibilityNodeProvider.HOST_VIEW_ID);
   6566         } else {
   6567             AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(this);
   6568             onInitializeAccessibilityNodeInfo(info);
   6569             return info;
   6570         }
   6571     }
   6572 
   6573     /**
   6574      * Initializes an {@link AccessibilityNodeInfo} with information about this view.
   6575      * The base implementation sets:
   6576      * <ul>
   6577      *   <li>{@link AccessibilityNodeInfo#setParent(View)},</li>
   6578      *   <li>{@link AccessibilityNodeInfo#setBoundsInParent(Rect)},</li>
   6579      *   <li>{@link AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li>
   6580      *   <li>{@link AccessibilityNodeInfo#setPackageName(CharSequence)},</li>
   6581      *   <li>{@link AccessibilityNodeInfo#setClassName(CharSequence)},</li>
   6582      *   <li>{@link AccessibilityNodeInfo#setContentDescription(CharSequence)},</li>
   6583      *   <li>{@link AccessibilityNodeInfo#setEnabled(boolean)},</li>
   6584      *   <li>{@link AccessibilityNodeInfo#setClickable(boolean)},</li>
   6585      *   <li>{@link AccessibilityNodeInfo#setFocusable(boolean)},</li>
   6586      *   <li>{@link AccessibilityNodeInfo#setFocused(boolean)},</li>
   6587      *   <li>{@link AccessibilityNodeInfo#setLongClickable(boolean)},</li>
   6588      *   <li>{@link AccessibilityNodeInfo#setSelected(boolean)},</li>
   6589      *   <li>{@link AccessibilityNodeInfo#setContextClickable(boolean)}</li>
   6590      * </ul>
   6591      * <p>
   6592      * Subclasses should override this method, call the super implementation,
   6593      * and set additional attributes.
   6594      * </p>
   6595      * <p>
   6596      * If an {@link AccessibilityDelegate} has been specified via calling
   6597      * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its
   6598      * {@link AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)}
   6599      * is responsible for handling this call.
   6600      * </p>
   6601      *
   6602      * @param info The instance to initialize.
   6603      */
   6604     @CallSuper
   6605     public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
   6606         if (mAccessibilityDelegate != null) {
   6607             mAccessibilityDelegate.onInitializeAccessibilityNodeInfo(this, info);
   6608         } else {
   6609             onInitializeAccessibilityNodeInfoInternal(info);
   6610         }
   6611     }
   6612 
   6613     /**
   6614      * Gets the location of this view in screen coordinates.
   6615      *
   6616      * @param outRect The output location
   6617      * @hide
   6618      */
   6619     public void getBoundsOnScreen(Rect outRect) {
   6620         getBoundsOnScreen(outRect, false);
   6621     }
   6622 
   6623     /**
   6624      * Gets the location of this view in screen coordinates.
   6625      *
   6626      * @param outRect The output location
   6627      * @param clipToParent Whether to clip child bounds to the parent ones.
   6628      * @hide
   6629      */
   6630     public void getBoundsOnScreen(Rect outRect, boolean clipToParent) {
   6631         if (mAttachInfo == null) {
   6632             return;
   6633         }
   6634 
   6635         RectF position = mAttachInfo.mTmpTransformRect;
   6636         position.set(0, 0, mRight - mLeft, mBottom - mTop);
   6637 
   6638         if (!hasIdentityMatrix()) {
   6639             getMatrix().mapRect(position);
   6640         }
   6641 
   6642         position.offset(mLeft, mTop);
   6643 
   6644         ViewParent parent = mParent;
   6645         while (parent instanceof View) {
   6646             View parentView = (View) parent;
   6647 
   6648             position.offset(-parentView.mScrollX, -parentView.mScrollY);
   6649 
   6650             if (clipToParent) {
   6651                 position.left = Math.max(position.left, 0);
   6652                 position.top = Math.max(position.top, 0);
   6653                 position.right = Math.min(position.right, parentView.getWidth());
   6654                 position.bottom = Math.min(position.bottom, parentView.getHeight());
   6655             }
   6656 
   6657             if (!parentView.hasIdentityMatrix()) {
   6658                 parentView.getMatrix().mapRect(position);
   6659             }
   6660 
   6661             position.offset(parentView.mLeft, parentView.mTop);
   6662 
   6663             parent = parentView.mParent;
   6664         }
   6665 
   6666         if (parent instanceof ViewRootImpl) {
   6667             ViewRootImpl viewRootImpl = (ViewRootImpl) parent;
   6668             position.offset(0, -viewRootImpl.mCurScrollY);
   6669         }
   6670 
   6671         position.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop);
   6672 
   6673         outRect.set(Math.round(position.left), Math.round(position.top),
   6674                 Math.round(position.right), Math.round(position.bottom));
   6675     }
   6676 
   6677     /**
   6678      * Return the class name of this object to be used for accessibility purposes.
   6679      * Subclasses should only override this if they are implementing something that
   6680      * should be seen as a completely new class of view when used by accessibility,
   6681      * unrelated to the class it is deriving from.  This is used to fill in
   6682      * {@link AccessibilityNodeInfo#setClassName AccessibilityNodeInfo.setClassName}.
   6683      */
   6684     public CharSequence getAccessibilityClassName() {
   6685         return View.class.getName();
   6686     }
   6687 
   6688     /**
   6689      * Called when assist structure is being retrieved from a view as part of
   6690      * {@link android.app.Activity#onProvideAssistData Activity.onProvideAssistData}.
   6691      * @param structure Fill in with structured view data.  The default implementation
   6692      * fills in all data that can be inferred from the view itself.
   6693      */
   6694     public void onProvideStructure(ViewStructure structure) {
   6695         final int id = mID;
   6696         if (id > 0 && (id&0xff000000) != 0 && (id&0x00ff0000) != 0
   6697                 && (id&0x0000ffff) != 0) {
   6698             String pkg, type, entry;
   6699             try {
   6700                 final Resources res = getResources();
   6701                 entry = res.getResourceEntryName(id);
   6702                 type = res.getResourceTypeName(id);
   6703                 pkg = res.getResourcePackageName(id);
   6704             } catch (Resources.NotFoundException e) {
   6705                 entry = type = pkg = null;
   6706             }
   6707             structure.setId(id, pkg, type, entry);
   6708         } else {
   6709             structure.setId(id, null, null, null);
   6710         }
   6711         structure.setDimens(mLeft, mTop, mScrollX, mScrollY, mRight - mLeft, mBottom - mTop);
   6712         if (!hasIdentityMatrix()) {
   6713             structure.setTransformation(getMatrix());
   6714         }
   6715         structure.setElevation(getZ());
   6716         structure.setVisibility(getVisibility());
   6717         structure.setEnabled(isEnabled());
   6718         if (isClickable()) {
   6719             structure.setClickable(true);
   6720         }
   6721         if (isFocusable()) {
   6722             structure.setFocusable(true);
   6723         }
   6724         if (isFocused()) {
   6725             structure.setFocused(true);
   6726         }
   6727         if (isAccessibilityFocused()) {
   6728             structure.setAccessibilityFocused(true);
   6729         }
   6730         if (isSelected()) {
   6731             structure.setSelected(true);
   6732         }
   6733         if (isActivated()) {
   6734             structure.setActivated(true);
   6735         }
   6736         if (isLongClickable()) {
   6737             structure.setLongClickable(true);
   6738         }
   6739         if (this instanceof Checkable) {
   6740             structure.setCheckable(true);
   6741             if (((Checkable)this).isChecked()) {
   6742                 structure.setChecked(true);
   6743             }
   6744         }
   6745         if (isContextClickable()) {
   6746             structure.setContextClickable(true);
   6747         }
   6748         structure.setClassName(getAccessibilityClassName().toString());
   6749         structure.setContentDescription(getContentDescription());
   6750     }
   6751 
   6752     /**
   6753      * Called when assist structure is being retrieved from a view as part of
   6754      * {@link android.app.Activity#onProvideAssistData Activity.onProvideAssistData} to
   6755      * generate additional virtual structure under this view.  The defaullt implementation
   6756      * uses {@link #getAccessibilityNodeProvider()} to try to generate this from the
   6757      * view's virtual accessibility nodes, if any.  You can override this for a more
   6758      * optimal implementation providing this data.
   6759      */
   6760     public void onProvideVirtualStructure(ViewStructure structure) {
   6761         AccessibilityNodeProvider provider = getAccessibilityNodeProvider();
   6762         if (provider != null) {
   6763             AccessibilityNodeInfo info = createAccessibilityNodeInfo();
   6764             structure.setChildCount(1);
   6765             ViewStructure root = structure.newChild(0);
   6766             populateVirtualStructure(root, provider, info);
   6767             info.recycle();
   6768         }
   6769     }
   6770 
   6771     private void populateVirtualStructure(ViewStructure structure,
   6772             AccessibilityNodeProvider provider, AccessibilityNodeInfo info) {
   6773         structure.setId(AccessibilityNodeInfo.getVirtualDescendantId(info.getSourceNodeId()),
   6774                 null, null, null);
   6775         Rect rect = structure.getTempRect();
   6776         info.getBoundsInParent(rect);
   6777         structure.setDimens(rect.left, rect.top, 0, 0, rect.width(), rect.height());
   6778         structure.setVisibility(VISIBLE);
   6779         structure.setEnabled(info.isEnabled());
   6780         if (info.isClickable()) {
   6781             structure.setClickable(true);
   6782         }
   6783         if (info.isFocusable()) {
   6784             structure.setFocusable(true);
   6785         }
   6786         if (info.isFocused()) {
   6787             structure.setFocused(true);
   6788         }
   6789         if (info.isAccessibilityFocused()) {
   6790             structure.setAccessibilityFocused(true);
   6791         }
   6792         if (info.isSelected()) {
   6793             structure.setSelected(true);
   6794         }
   6795         if (info.isLongClickable()) {
   6796             structure.setLongClickable(true);
   6797         }
   6798         if (info.isCheckable()) {
   6799             structure.setCheckable(true);
   6800             if (info.isChecked()) {
   6801                 structure.setChecked(true);
   6802             }
   6803         }
   6804         if (info.isContextClickable()) {
   6805             structure.setContextClickable(true);
   6806         }
   6807         CharSequence cname = info.getClassName();
   6808         structure.setClassName(cname != null ? cname.toString() : null);
   6809         structure.setContentDescription(info.getContentDescription());
   6810         if (info.getText() != null || info.getError() != null) {
   6811             structure.setText(info.getText(), info.getTextSelectionStart(),
   6812                     info.getTextSelectionEnd());
   6813         }
   6814         final int NCHILDREN = info.getChildCount();
   6815         if (NCHILDREN > 0) {
   6816             structure.setChildCount(NCHILDREN);
   6817             for (int i=0; i<NCHILDREN; i++) {
   6818                 AccessibilityNodeInfo cinfo = provider.createAccessibilityNodeInfo(
   6819                         AccessibilityNodeInfo.getVirtualDescendantId(info.getChildId(i)));
   6820                 ViewStructure child = structure.newChild(i);
   6821                 populateVirtualStructure(child, provider, cinfo);
   6822                 cinfo.recycle();
   6823             }
   6824         }
   6825     }
   6826 
   6827     /**
   6828      * Dispatch creation of {@link ViewStructure} down the hierarchy.  The default
   6829      * implementation calls {@link #onProvideStructure} and
   6830      * {@link #onProvideVirtualStructure}.
   6831      */
   6832     public void dispatchProvideStructure(ViewStructure structure) {
   6833         if (!isAssistBlocked()) {
   6834             onProvideStructure(structure);
   6835             onProvideVirtualStructure(structure);
   6836         } else {
   6837             structure.setClassName(getAccessibilityClassName().toString());
   6838             structure.setAssistBlocked(true);
   6839         }
   6840     }
   6841 
   6842     /**
   6843      * @see #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)
   6844      *
   6845      * Note: Called from the default {@link AccessibilityDelegate}.
   6846      *
   6847      * @hide
   6848      */
   6849     public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
   6850         if (mAttachInfo == null) {
   6851             return;
   6852         }
   6853 
   6854         Rect bounds = mAttachInfo.mTmpInvalRect;
   6855 
   6856         getDrawingRect(bounds);
   6857         info.setBoundsInParent(bounds);
   6858 
   6859         getBoundsOnScreen(bounds, true);
   6860         info.setBoundsInScreen(bounds);
   6861 
   6862         ViewParent parent = getParentForAccessibility();
   6863         if (parent instanceof View) {
   6864             info.setParent((View) parent);
   6865         }
   6866 
   6867         if (mID != View.NO_ID) {
   6868             View rootView = getRootView();
   6869             if (rootView == null) {
   6870                 rootView = this;
   6871             }
   6872 
   6873             View label = rootView.findLabelForView(this, mID);
   6874             if (label != null) {
   6875                 info.setLabeledBy(label);
   6876             }
   6877 
   6878             if ((mAttachInfo.mAccessibilityFetchFlags
   6879                     & AccessibilityNodeInfo.FLAG_REPORT_VIEW_IDS) != 0
   6880                     && Resources.resourceHasPackage(mID)) {
   6881                 try {
   6882                     String viewId = getResources().getResourceName(mID);
   6883                     info.setViewIdResourceName(viewId);
   6884                 } catch (Resources.NotFoundException nfe) {
   6885                     /* ignore */
   6886                 }
   6887             }
   6888         }
   6889 
   6890         if (mLabelForId != View.NO_ID) {
   6891             View rootView = getRootView();
   6892             if (rootView == null) {
   6893                 rootView = this;
   6894             }
   6895             View labeled = rootView.findViewInsideOutShouldExist(this, mLabelForId);
   6896             if (labeled != null) {
   6897                 info.setLabelFor(labeled);
   6898             }
   6899         }
   6900 
   6901         if (mAccessibilityTraversalBeforeId != View.NO_ID) {
   6902             View rootView = getRootView();
   6903             if (rootView == null) {
   6904                 rootView = this;
   6905             }
   6906             View next = rootView.findViewInsideOutShouldExist(this,
   6907                     mAccessibilityTraversalBeforeId);
   6908             if (next != null && next.includeForAccessibility()) {
   6909                 info.setTraversalBefore(next);
   6910             }
   6911         }
   6912 
   6913         if (mAccessibilityTraversalAfterId != View.NO_ID) {
   6914             View rootView = getRootView();
   6915             if (rootView == null) {
   6916                 rootView = this;
   6917             }
   6918             View next = rootView.findViewInsideOutShouldExist(this,
   6919                     mAccessibilityTraversalAfterId);
   6920             if (next != null && next.includeForAccessibility()) {
   6921                 info.setTraversalAfter(next);
   6922             }
   6923         }
   6924 
   6925         info.setVisibleToUser(isVisibleToUser());
   6926 
   6927         if ((mAttachInfo != null) && ((mAttachInfo.mAccessibilityFetchFlags
   6928                 & AccessibilityNodeInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS) != 0)) {
   6929             info.setImportantForAccessibility(isImportantForAccessibility());
   6930         } else {
   6931             info.setImportantForAccessibility(true);
   6932         }
   6933 
   6934         info.setPackageName(mContext.getPackageName());
   6935         info.setClassName(getAccessibilityClassName());
   6936         info.setContentDescription(getContentDescription());
   6937 
   6938         info.setEnabled(isEnabled());
   6939         info.setClickable(isClickable());
   6940         info.setFocusable(isFocusable());
   6941         info.setFocused(isFocused());
   6942         info.setAccessibilityFocused(isAccessibilityFocused());
   6943         info.setSelected(isSelected());
   6944         info.setLongClickable(isLongClickable());
   6945         info.setContextClickable(isContextClickable());
   6946         info.setLiveRegion(getAccessibilityLiveRegion());
   6947 
   6948         // TODO: These make sense only if we are in an AdapterView but all
   6949         // views can be selected. Maybe from accessibility perspective
   6950         // we should report as selectable view in an AdapterView.
   6951         info.addAction(AccessibilityNodeInfo.ACTION_SELECT);
   6952         info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_SELECTION);
   6953 
   6954         if (isFocusable()) {
   6955             if (isFocused()) {
   6956                 info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS);
   6957             } else {
   6958                 info.addAction(AccessibilityNodeInfo.ACTION_FOCUS);
   6959             }
   6960         }
   6961 
   6962         if (!isAccessibilityFocused()) {
   6963             info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
   6964         } else {
   6965             info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
   6966         }
   6967 
   6968         if (isClickable() && isEnabled()) {
   6969             info.addAction(AccessibilityNodeInfo.ACTION_CLICK);
   6970         }
   6971 
   6972         if (isLongClickable() && isEnabled()) {
   6973             info.addAction(AccessibilityNodeInfo.ACTION_LONG_CLICK);
   6974         }
   6975 
   6976         if (isContextClickable() && isEnabled()) {
   6977             info.addAction(AccessibilityAction.ACTION_CONTEXT_CLICK);
   6978         }
   6979 
   6980         CharSequence text = getIterableTextForAccessibility();
   6981         if (text != null && text.length() > 0) {
   6982             info.setTextSelection(getAccessibilitySelectionStart(), getAccessibilitySelectionEnd());
   6983 
   6984             info.addAction(AccessibilityNodeInfo.ACTION_SET_SELECTION);
   6985             info.addAction(AccessibilityNodeInfo.