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      * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when
    824      * calling setFlags.
    825      */
    826     private static final int NOT_FOCUSABLE = 0x00000000;
    827 
    828     /**
    829      * This view wants keystrokes. Use with TAKES_FOCUS_MASK when calling
    830      * setFlags.
    831      */
    832     private static final int FOCUSABLE = 0x00000001;
    833 
    834     /**
    835      * Mask for use with setFlags indicating bits used for focus.
    836      */
    837     private static final int FOCUSABLE_MASK = 0x00000001;
    838 
    839     /**
    840      * This view will adjust its padding to fit sytem windows (e.g. status bar)
    841      */
    842     private static final int FITS_SYSTEM_WINDOWS = 0x00000002;
    843 
    844     /** @hide */
    845     @IntDef({VISIBLE, INVISIBLE, GONE})
    846     @Retention(RetentionPolicy.SOURCE)
    847     public @interface Visibility {}
    848 
    849     /**
    850      * This view is visible.
    851      * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code
    852      * android:visibility}.
    853      */
    854     public static final int VISIBLE = 0x00000000;
    855 
    856     /**
    857      * This view is invisible, but it still takes up space for layout purposes.
    858      * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code
    859      * android:visibility}.
    860      */
    861     public static final int INVISIBLE = 0x00000004;
    862 
    863     /**
    864      * This view is invisible, and it doesn't take any space for layout
    865      * purposes. Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code
    866      * android:visibility}.
    867      */
    868     public static final int GONE = 0x00000008;
    869 
    870     /**
    871      * Mask for use with setFlags indicating bits used for visibility.
    872      * {@hide}
    873      */
    874     static final int VISIBILITY_MASK = 0x0000000C;
    875 
    876     private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE};
    877 
    878     /**
    879      * This view is enabled. Interpretation varies by subclass.
    880      * Use with ENABLED_MASK when calling setFlags.
    881      * {@hide}
    882      */
    883     static final int ENABLED = 0x00000000;
    884 
    885     /**
    886      * This view is disabled. Interpretation varies by subclass.
    887      * Use with ENABLED_MASK when calling setFlags.
    888      * {@hide}
    889      */
    890     static final int DISABLED = 0x00000020;
    891 
    892    /**
    893     * Mask for use with setFlags indicating bits used for indicating whether
    894     * this view is enabled
    895     * {@hide}
    896     */
    897     static final int ENABLED_MASK = 0x00000020;
    898 
    899     /**
    900      * This view won't draw. {@link #onDraw(android.graphics.Canvas)} won't be
    901      * called and further optimizations will be performed. It is okay to have
    902      * this flag set and a background. Use with DRAW_MASK when calling setFlags.
    903      * {@hide}
    904      */
    905     static final int WILL_NOT_DRAW = 0x00000080;
    906 
    907     /**
    908      * Mask for use with setFlags indicating bits used for indicating whether
    909      * this view is will draw
    910      * {@hide}
    911      */
    912     static final int DRAW_MASK = 0x00000080;
    913 
    914     /**
    915      * <p>This view doesn't show scrollbars.</p>
    916      * {@hide}
    917      */
    918     static final int SCROLLBARS_NONE = 0x00000000;
    919 
    920     /**
    921      * <p>This view shows horizontal scrollbars.</p>
    922      * {@hide}
    923      */
    924     static final int SCROLLBARS_HORIZONTAL = 0x00000100;
    925 
    926     /**
    927      * <p>This view shows vertical scrollbars.</p>
    928      * {@hide}
    929      */
    930     static final int SCROLLBARS_VERTICAL = 0x00000200;
    931 
    932     /**
    933      * <p>Mask for use with setFlags indicating bits used for indicating which
    934      * scrollbars are enabled.</p>
    935      * {@hide}
    936      */
    937     static final int SCROLLBARS_MASK = 0x00000300;
    938 
    939     /**
    940      * Indicates that the view should filter touches when its window is obscured.
    941      * Refer to the class comments for more information about this security feature.
    942      * {@hide}
    943      */
    944     static final int FILTER_TOUCHES_WHEN_OBSCURED = 0x00000400;
    945 
    946     /**
    947      * Set for framework elements that use FITS_SYSTEM_WINDOWS, to indicate
    948      * that they are optional and should be skipped if the window has
    949      * requested system UI flags that ignore those insets for layout.
    950      */
    951     static final int OPTIONAL_FITS_SYSTEM_WINDOWS = 0x00000800;
    952 
    953     /**
    954      * <p>This view doesn't show fading edges.</p>
    955      * {@hide}
    956      */
    957     static final int FADING_EDGE_NONE = 0x00000000;
    958 
    959     /**
    960      * <p>This view shows horizontal fading edges.</p>
    961      * {@hide}
    962      */
    963     static final int FADING_EDGE_HORIZONTAL = 0x00001000;
    964 
    965     /**
    966      * <p>This view shows vertical fading edges.</p>
    967      * {@hide}
    968      */
    969     static final int FADING_EDGE_VERTICAL = 0x00002000;
    970 
    971     /**
    972      * <p>Mask for use with setFlags indicating bits used for indicating which
    973      * fading edges are enabled.</p>
    974      * {@hide}
    975      */
    976     static final int FADING_EDGE_MASK = 0x00003000;
    977 
    978     /**
    979      * <p>Indicates this view can be clicked. When clickable, a View reacts
    980      * to clicks by notifying the OnClickListener.<p>
    981      * {@hide}
    982      */
    983     static final int CLICKABLE = 0x00004000;
    984 
    985     /**
    986      * <p>Indicates this view is caching its drawing into a bitmap.</p>
    987      * {@hide}
    988      */
    989     static final int DRAWING_CACHE_ENABLED = 0x00008000;
    990 
    991     /**
    992      * <p>Indicates that no icicle should be saved for this view.<p>
    993      * {@hide}
    994      */
    995     static final int SAVE_DISABLED = 0x000010000;
    996 
    997     /**
    998      * <p>Mask for use with setFlags indicating bits used for the saveEnabled
    999      * property.</p>
   1000      * {@hide}
   1001      */
   1002     static final int SAVE_DISABLED_MASK = 0x000010000;
   1003 
   1004     /**
   1005      * <p>Indicates that no drawing cache should ever be created for this view.<p>
   1006      * {@hide}
   1007      */
   1008     static final int WILL_NOT_CACHE_DRAWING = 0x000020000;
   1009 
   1010     /**
   1011      * <p>Indicates this view can take / keep focus when int touch mode.</p>
   1012      * {@hide}
   1013      */
   1014     static final int FOCUSABLE_IN_TOUCH_MODE = 0x00040000;
   1015 
   1016     /** @hide */
   1017     @Retention(RetentionPolicy.SOURCE)
   1018     @IntDef({DRAWING_CACHE_QUALITY_LOW, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_AUTO})
   1019     public @interface DrawingCacheQuality {}
   1020 
   1021     /**
   1022      * <p>Enables low quality mode for the drawing cache.</p>
   1023      */
   1024     public static final int DRAWING_CACHE_QUALITY_LOW = 0x00080000;
   1025 
   1026     /**
   1027      * <p>Enables high quality mode for the drawing cache.</p>
   1028      */
   1029     public static final int DRAWING_CACHE_QUALITY_HIGH = 0x00100000;
   1030 
   1031     /**
   1032      * <p>Enables automatic quality mode for the drawing cache.</p>
   1033      */
   1034     public static final int DRAWING_CACHE_QUALITY_AUTO = 0x00000000;
   1035 
   1036     private static final int[] DRAWING_CACHE_QUALITY_FLAGS = {
   1037             DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_LOW, DRAWING_CACHE_QUALITY_HIGH
   1038     };
   1039 
   1040     /**
   1041      * <p>Mask for use with setFlags indicating bits used for the cache
   1042      * quality property.</p>
   1043      * {@hide}
   1044      */
   1045     static final int DRAWING_CACHE_QUALITY_MASK = 0x00180000;
   1046 
   1047     /**
   1048      * <p>
   1049      * Indicates this view can be long clicked. When long clickable, a View
   1050      * reacts to long clicks by notifying the OnLongClickListener or showing a
   1051      * context menu.
   1052      * </p>
   1053      * {@hide}
   1054      */
   1055     static final int LONG_CLICKABLE = 0x00200000;
   1056 
   1057     /**
   1058      * <p>Indicates that this view gets its drawable states from its direct parent
   1059      * and ignores its original internal states.</p>
   1060      *
   1061      * @hide
   1062      */
   1063     static final int DUPLICATE_PARENT_STATE = 0x00400000;
   1064 
   1065     /**
   1066      * <p>
   1067      * Indicates this view can be context clicked. When context clickable, a View reacts to a
   1068      * context click (e.g. a primary stylus button press or right mouse click) by notifying the
   1069      * OnContextClickListener.
   1070      * </p>
   1071      * {@hide}
   1072      */
   1073     static final int CONTEXT_CLICKABLE = 0x00800000;
   1074 
   1075 
   1076     /** @hide */
   1077     @IntDef({
   1078         SCROLLBARS_INSIDE_OVERLAY,
   1079         SCROLLBARS_INSIDE_INSET,
   1080         SCROLLBARS_OUTSIDE_OVERLAY,
   1081         SCROLLBARS_OUTSIDE_INSET
   1082     })
   1083     @Retention(RetentionPolicy.SOURCE)
   1084     public @interface ScrollBarStyle {}
   1085 
   1086     /**
   1087      * The scrollbar style to display the scrollbars inside the content area,
   1088      * without increasing the padding. The scrollbars will be overlaid with
   1089      * translucency on the view's content.
   1090      */
   1091     public static final int SCROLLBARS_INSIDE_OVERLAY = 0;
   1092 
   1093     /**
   1094      * The scrollbar style to display the scrollbars inside the padded area,
   1095      * increasing the padding of the view. The scrollbars will not overlap the
   1096      * content area of the view.
   1097      */
   1098     public static final int SCROLLBARS_INSIDE_INSET = 0x01000000;
   1099 
   1100     /**
   1101      * The scrollbar style to display the scrollbars at the edge of the view,
   1102      * without increasing the padding. The scrollbars will be overlaid with
   1103      * translucency.
   1104      */
   1105     public static final int SCROLLBARS_OUTSIDE_OVERLAY = 0x02000000;
   1106 
   1107     /**
   1108      * The scrollbar style to display the scrollbars at the edge of the view,
   1109      * increasing the padding of the view. The scrollbars will only overlap the
   1110      * background, if any.
   1111      */
   1112     public static final int SCROLLBARS_OUTSIDE_INSET = 0x03000000;
   1113 
   1114     /**
   1115      * Mask to check if the scrollbar style is overlay or inset.
   1116      * {@hide}
   1117      */
   1118     static final int SCROLLBARS_INSET_MASK = 0x01000000;
   1119 
   1120     /**
   1121      * Mask to check if the scrollbar style is inside or outside.
   1122      * {@hide}
   1123      */
   1124     static final int SCROLLBARS_OUTSIDE_MASK = 0x02000000;
   1125 
   1126     /**
   1127      * Mask for scrollbar style.
   1128      * {@hide}
   1129      */
   1130     static final int SCROLLBARS_STYLE_MASK = 0x03000000;
   1131 
   1132     /**
   1133      * View flag indicating that the screen should remain on while the
   1134      * window containing this view is visible to the user.  This effectively
   1135      * takes care of automatically setting the WindowManager's
   1136      * {@link WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON}.
   1137      */
   1138     public static final int KEEP_SCREEN_ON = 0x04000000;
   1139 
   1140     /**
   1141      * View flag indicating whether this view should have sound effects enabled
   1142      * for events such as clicking and touching.
   1143      */
   1144     public static final int SOUND_EFFECTS_ENABLED = 0x08000000;
   1145 
   1146     /**
   1147      * View flag indicating whether this view should have haptic feedback
   1148      * enabled for events such as long presses.
   1149      */
   1150     public static final int HAPTIC_FEEDBACK_ENABLED = 0x10000000;
   1151 
   1152     /**
   1153      * <p>Indicates that the view hierarchy should stop saving state when
   1154      * it reaches this view.  If state saving is initiated immediately at
   1155      * the view, it will be allowed.
   1156      * {@hide}
   1157      */
   1158     static final int PARENT_SAVE_DISABLED = 0x20000000;
   1159 
   1160     /**
   1161      * <p>Mask for use with setFlags indicating bits used for PARENT_SAVE_DISABLED.</p>
   1162      * {@hide}
   1163      */
   1164     static final int PARENT_SAVE_DISABLED_MASK = 0x20000000;
   1165 
   1166     /** @hide */
   1167     @IntDef(flag = true,
   1168             value = {
   1169                 FOCUSABLES_ALL,
   1170                 FOCUSABLES_TOUCH_MODE
   1171             })
   1172     @Retention(RetentionPolicy.SOURCE)
   1173     public @interface FocusableMode {}
   1174 
   1175     /**
   1176      * View flag indicating whether {@link #addFocusables(ArrayList, int, int)}
   1177      * should add all focusable Views regardless if they are focusable in touch mode.
   1178      */
   1179     public static final int FOCUSABLES_ALL = 0x00000000;
   1180 
   1181     /**
   1182      * View flag indicating whether {@link #addFocusables(ArrayList, int, int)}
   1183      * should add only Views focusable in touch mode.
   1184      */
   1185     public static final int FOCUSABLES_TOUCH_MODE = 0x00000001;
   1186 
   1187     /** @hide */
   1188     @IntDef({
   1189             FOCUS_BACKWARD,
   1190             FOCUS_FORWARD,
   1191             FOCUS_LEFT,
   1192             FOCUS_UP,
   1193             FOCUS_RIGHT,
   1194             FOCUS_DOWN
   1195     })
   1196     @Retention(RetentionPolicy.SOURCE)
   1197     public @interface FocusDirection {}
   1198 
   1199     /** @hide */
   1200     @IntDef({
   1201             FOCUS_LEFT,
   1202             FOCUS_UP,
   1203             FOCUS_RIGHT,
   1204             FOCUS_DOWN
   1205     })
   1206     @Retention(RetentionPolicy.SOURCE)
   1207     public @interface FocusRealDirection {} // Like @FocusDirection, but without forward/backward
   1208 
   1209     /**
   1210      * Use with {@link #focusSearch(int)}. Move focus to the previous selectable
   1211      * item.
   1212      */
   1213     public static final int FOCUS_BACKWARD = 0x00000001;
   1214 
   1215     /**
   1216      * Use with {@link #focusSearch(int)}. Move focus to the next selectable
   1217      * item.
   1218      */
   1219     public static final int FOCUS_FORWARD = 0x00000002;
   1220 
   1221     /**
   1222      * Use with {@link #focusSearch(int)}. Move focus to the left.
   1223      */
   1224     public static final int FOCUS_LEFT = 0x00000011;
   1225 
   1226     /**
   1227      * Use with {@link #focusSearch(int)}. Move focus up.
   1228      */
   1229     public static final int FOCUS_UP = 0x00000021;
   1230 
   1231     /**
   1232      * Use with {@link #focusSearch(int)}. Move focus to the right.
   1233      */
   1234     public static final int FOCUS_RIGHT = 0x00000042;
   1235 
   1236     /**
   1237      * Use with {@link #focusSearch(int)}. Move focus down.
   1238      */
   1239     public static final int FOCUS_DOWN = 0x00000082;
   1240 
   1241     /**
   1242      * Bits of {@link #getMeasuredWidthAndState()} and
   1243      * {@link #getMeasuredWidthAndState()} that provide the actual measured size.
   1244      */
   1245     public static final int MEASURED_SIZE_MASK = 0x00ffffff;
   1246 
   1247     /**
   1248      * Bits of {@link #getMeasuredWidthAndState()} and
   1249      * {@link #getMeasuredWidthAndState()} that provide the additional state bits.
   1250      */
   1251     public static final int MEASURED_STATE_MASK = 0xff000000;
   1252 
   1253     /**
   1254      * Bit shift of {@link #MEASURED_STATE_MASK} to get to the height bits
   1255      * for functions that combine both width and height into a single int,
   1256      * such as {@link #getMeasuredState()} and the childState argument of
   1257      * {@link #resolveSizeAndState(int, int, int)}.
   1258      */
   1259     public static final int MEASURED_HEIGHT_STATE_SHIFT = 16;
   1260 
   1261     /**
   1262      * Bit of {@link #getMeasuredWidthAndState()} and
   1263      * {@link #getMeasuredWidthAndState()} that indicates the measured size
   1264      * is smaller that the space the view would like to have.
   1265      */
   1266     public static final int MEASURED_STATE_TOO_SMALL = 0x01000000;
   1267 
   1268     /**
   1269      * Base View state sets
   1270      */
   1271     // Singles
   1272     /**
   1273      * Indicates the view has no states set. States are used with
   1274      * {@link android.graphics.drawable.Drawable} to change the drawing of the
   1275      * view depending on its state.
   1276      *
   1277      * @see android.graphics.drawable.Drawable
   1278      * @see #getDrawableState()
   1279      */
   1280     protected static final int[] EMPTY_STATE_SET;
   1281     /**
   1282      * Indicates the view is enabled. States are used with
   1283      * {@link android.graphics.drawable.Drawable} to change the drawing of the
   1284      * view depending on its state.
   1285      *
   1286      * @see android.graphics.drawable.Drawable
   1287      * @see #getDrawableState()
   1288      */
   1289     protected static final int[] ENABLED_STATE_SET;
   1290     /**
   1291      * Indicates the view is focused. States are used with
   1292      * {@link android.graphics.drawable.Drawable} to change the drawing of the
   1293      * view depending on its state.
   1294      *
   1295      * @see android.graphics.drawable.Drawable
   1296      * @see #getDrawableState()
   1297      */
   1298     protected static final int[] FOCUSED_STATE_SET;
   1299     /**
   1300      * Indicates the view is selected. States are used with
   1301      * {@link android.graphics.drawable.Drawable} to change the drawing of the
   1302      * view depending on its state.
   1303      *
   1304      * @see android.graphics.drawable.Drawable
   1305      * @see #getDrawableState()
   1306      */
   1307     protected static final int[] SELECTED_STATE_SET;
   1308     /**
   1309      * Indicates the view is pressed. States are used with
   1310      * {@link android.graphics.drawable.Drawable} to change the drawing of the
   1311      * view depending on its state.
   1312      *
   1313      * @see android.graphics.drawable.Drawable
   1314      * @see #getDrawableState()
   1315      */
   1316     protected static final int[] PRESSED_STATE_SET;
   1317     /**
   1318      * Indicates the view's window has focus. States are used with
   1319      * {@link android.graphics.drawable.Drawable} to change the drawing of the
   1320      * view depending on its state.
   1321      *
   1322      * @see android.graphics.drawable.Drawable
   1323      * @see #getDrawableState()
   1324      */
   1325     protected static final int[] WINDOW_FOCUSED_STATE_SET;
   1326     // Doubles
   1327     /**
   1328      * Indicates the view is enabled and has the focus.
   1329      *
   1330      * @see #ENABLED_STATE_SET
   1331      * @see #FOCUSED_STATE_SET
   1332      */
   1333     protected static final int[] ENABLED_FOCUSED_STATE_SET;
   1334     /**
   1335      * Indicates the view is enabled and selected.
   1336      *
   1337      * @see #ENABLED_STATE_SET
   1338      * @see #SELECTED_STATE_SET
   1339      */
   1340     protected static final int[] ENABLED_SELECTED_STATE_SET;
   1341     /**
   1342      * Indicates the view is enabled and that its window has focus.
   1343      *
   1344      * @see #ENABLED_STATE_SET
   1345      * @see #WINDOW_FOCUSED_STATE_SET
   1346      */
   1347     protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET;
   1348     /**
   1349      * Indicates the view is focused and selected.
   1350      *
   1351      * @see #FOCUSED_STATE_SET
   1352      * @see #SELECTED_STATE_SET
   1353      */
   1354     protected static final int[] FOCUSED_SELECTED_STATE_SET;
   1355     /**
   1356      * Indicates the view has the focus and that its window has the focus.
   1357      *
   1358      * @see #FOCUSED_STATE_SET
   1359      * @see #WINDOW_FOCUSED_STATE_SET
   1360      */
   1361     protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET;
   1362     /**
   1363      * Indicates the view is selected and that its window has the focus.
   1364      *
   1365      * @see #SELECTED_STATE_SET
   1366      * @see #WINDOW_FOCUSED_STATE_SET
   1367      */
   1368     protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET;
   1369     // Triples
   1370     /**
   1371      * Indicates the view is enabled, focused and selected.
   1372      *
   1373      * @see #ENABLED_STATE_SET
   1374      * @see #FOCUSED_STATE_SET
   1375      * @see #SELECTED_STATE_SET
   1376      */
   1377     protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET;
   1378     /**
   1379      * Indicates the view is enabled, focused and its window has the focus.
   1380      *
   1381      * @see #ENABLED_STATE_SET
   1382      * @see #FOCUSED_STATE_SET
   1383      * @see #WINDOW_FOCUSED_STATE_SET
   1384      */
   1385     protected static final int[] ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET;
   1386     /**
   1387      * Indicates the view is enabled, selected and its window has the focus.
   1388      *
   1389      * @see #ENABLED_STATE_SET
   1390      * @see #SELECTED_STATE_SET
   1391      * @see #WINDOW_FOCUSED_STATE_SET
   1392      */
   1393     protected static final int[] ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET;
   1394     /**
   1395      * Indicates the view is focused, selected and its window has the focus.
   1396      *
   1397      * @see #FOCUSED_STATE_SET
   1398      * @see #SELECTED_STATE_SET
   1399      * @see #WINDOW_FOCUSED_STATE_SET
   1400      */
   1401     protected static final int[] FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
   1402     /**
   1403      * Indicates the view is enabled, focused, selected and its window
   1404      * has the focus.
   1405      *
   1406      * @see #ENABLED_STATE_SET
   1407      * @see #FOCUSED_STATE_SET
   1408      * @see #SELECTED_STATE_SET
   1409      * @see #WINDOW_FOCUSED_STATE_SET
   1410      */
   1411     protected static final int[] ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
   1412     /**
   1413      * Indicates the view is pressed and its window has the focus.
   1414      *
   1415      * @see #PRESSED_STATE_SET
   1416      * @see #WINDOW_FOCUSED_STATE_SET
   1417      */
   1418     protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET;
   1419     /**
   1420      * Indicates the view is pressed and selected.
   1421      *
   1422      * @see #PRESSED_STATE_SET
   1423      * @see #SELECTED_STATE_SET
   1424      */
   1425     protected static final int[] PRESSED_SELECTED_STATE_SET;
   1426     /**
   1427      * Indicates the view is pressed, selected and its window has the focus.
   1428      *
   1429      * @see #PRESSED_STATE_SET
   1430      * @see #SELECTED_STATE_SET
   1431      * @see #WINDOW_FOCUSED_STATE_SET
   1432      */
   1433     protected static final int[] PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
   1434     /**
   1435      * Indicates the view is pressed and focused.
   1436      *
   1437      * @see #PRESSED_STATE_SET
   1438      * @see #FOCUSED_STATE_SET
   1439      */
   1440     protected static final int[] PRESSED_FOCUSED_STATE_SET;
   1441     /**
   1442      * Indicates the view is pressed, focused and its window has the focus.
   1443      *
   1444      * @see #PRESSED_STATE_SET
   1445      * @see #FOCUSED_STATE_SET
   1446      * @see #WINDOW_FOCUSED_STATE_SET
   1447      */
   1448     protected static final int[] PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET;
   1449     /**
   1450      * Indicates the view is pressed, focused and selected.
   1451      *
   1452      * @see #PRESSED_STATE_SET
   1453      * @see #SELECTED_STATE_SET
   1454      * @see #FOCUSED_STATE_SET
   1455      */
   1456     protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET;
   1457     /**
   1458      * Indicates the view is pressed, focused, selected and its window has the focus.
   1459      *
   1460      * @see #PRESSED_STATE_SET
   1461      * @see #FOCUSED_STATE_SET
   1462      * @see #SELECTED_STATE_SET
   1463      * @see #WINDOW_FOCUSED_STATE_SET
   1464      */
   1465     protected static final int[] PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
   1466     /**
   1467      * Indicates the view is pressed and enabled.
   1468      *
   1469      * @see #PRESSED_STATE_SET
   1470      * @see #ENABLED_STATE_SET
   1471      */
   1472     protected static final int[] PRESSED_ENABLED_STATE_SET;
   1473     /**
   1474      * Indicates the view is pressed, enabled and its window has the focus.
   1475      *
   1476      * @see #PRESSED_STATE_SET
   1477      * @see #ENABLED_STATE_SET
   1478      * @see #WINDOW_FOCUSED_STATE_SET
   1479      */
   1480     protected static final int[] PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET;
   1481     /**
   1482      * Indicates the view is pressed, enabled and selected.
   1483      *
   1484      * @see #PRESSED_STATE_SET
   1485      * @see #ENABLED_STATE_SET
   1486      * @see #SELECTED_STATE_SET
   1487      */
   1488     protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET;
   1489     /**
   1490      * Indicates the view is pressed, enabled, selected and its window has the
   1491      * focus.
   1492      *
   1493      * @see #PRESSED_STATE_SET
   1494      * @see #ENABLED_STATE_SET
   1495      * @see #SELECTED_STATE_SET
   1496      * @see #WINDOW_FOCUSED_STATE_SET
   1497      */
   1498     protected static final int[] PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET;
   1499     /**
   1500      * Indicates the view is pressed, enabled and focused.
   1501      *
   1502      * @see #PRESSED_STATE_SET
   1503      * @see #ENABLED_STATE_SET
   1504      * @see #FOCUSED_STATE_SET
   1505      */
   1506     protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET;
   1507     /**
   1508      * Indicates the view is pressed, enabled, focused and its window has the
   1509      * focus.
   1510      *
   1511      * @see #PRESSED_STATE_SET
   1512      * @see #ENABLED_STATE_SET
   1513      * @see #FOCUSED_STATE_SET
   1514      * @see #WINDOW_FOCUSED_STATE_SET
   1515      */
   1516     protected static final int[] PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET;
   1517     /**
   1518      * Indicates the view is pressed, enabled, focused and selected.
   1519      *
   1520      * @see #PRESSED_STATE_SET
   1521      * @see #ENABLED_STATE_SET
   1522      * @see #SELECTED_STATE_SET
   1523      * @see #FOCUSED_STATE_SET
   1524      */
   1525     protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET;
   1526     /**
   1527      * Indicates the view is pressed, enabled, focused, selected and its window
   1528      * has the focus.
   1529      *
   1530      * @see #PRESSED_STATE_SET
   1531      * @see #ENABLED_STATE_SET
   1532      * @see #SELECTED_STATE_SET
   1533      * @see #FOCUSED_STATE_SET
   1534      * @see #WINDOW_FOCUSED_STATE_SET
   1535      */
   1536     protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
   1537 
   1538     static {
   1539         EMPTY_STATE_SET = StateSet.get(0);
   1540 
   1541         WINDOW_FOCUSED_STATE_SET = StateSet.get(StateSet.VIEW_STATE_WINDOW_FOCUSED);
   1542 
   1543         SELECTED_STATE_SET = StateSet.get(StateSet.VIEW_STATE_SELECTED);
   1544         SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1545                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED);
   1546 
   1547         FOCUSED_STATE_SET = StateSet.get(StateSet.VIEW_STATE_FOCUSED);
   1548         FOCUSED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1549                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_FOCUSED);
   1550         FOCUSED_SELECTED_STATE_SET = StateSet.get(
   1551                 StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_FOCUSED);
   1552         FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1553                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
   1554                         | StateSet.VIEW_STATE_FOCUSED);
   1555 
   1556         ENABLED_STATE_SET = StateSet.get(StateSet.VIEW_STATE_ENABLED);
   1557         ENABLED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1558                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_ENABLED);
   1559         ENABLED_SELECTED_STATE_SET = StateSet.get(
   1560                 StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_ENABLED);
   1561         ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1562                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
   1563                         | StateSet.VIEW_STATE_ENABLED);
   1564         ENABLED_FOCUSED_STATE_SET = StateSet.get(
   1565                 StateSet.VIEW_STATE_FOCUSED | StateSet.VIEW_STATE_ENABLED);
   1566         ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1567                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_FOCUSED
   1568                         | StateSet.VIEW_STATE_ENABLED);
   1569         ENABLED_FOCUSED_SELECTED_STATE_SET = StateSet.get(
   1570                 StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_FOCUSED
   1571                         | StateSet.VIEW_STATE_ENABLED);
   1572         ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1573                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
   1574                         | StateSet.VIEW_STATE_FOCUSED| StateSet.VIEW_STATE_ENABLED);
   1575 
   1576         PRESSED_STATE_SET = StateSet.get(StateSet.VIEW_STATE_PRESSED);
   1577         PRESSED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1578                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_PRESSED);
   1579         PRESSED_SELECTED_STATE_SET = StateSet.get(
   1580                 StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_PRESSED);
   1581         PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1582                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
   1583                         | StateSet.VIEW_STATE_PRESSED);
   1584         PRESSED_FOCUSED_STATE_SET = StateSet.get(
   1585                 StateSet.VIEW_STATE_FOCUSED | StateSet.VIEW_STATE_PRESSED);
   1586         PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1587                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_FOCUSED
   1588                         | StateSet.VIEW_STATE_PRESSED);
   1589         PRESSED_FOCUSED_SELECTED_STATE_SET = StateSet.get(
   1590                 StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_FOCUSED
   1591                         | StateSet.VIEW_STATE_PRESSED);
   1592         PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1593                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
   1594                         | StateSet.VIEW_STATE_FOCUSED | StateSet.VIEW_STATE_PRESSED);
   1595         PRESSED_ENABLED_STATE_SET = StateSet.get(
   1596                 StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_PRESSED);
   1597         PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1598                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_ENABLED
   1599                         | StateSet.VIEW_STATE_PRESSED);
   1600         PRESSED_ENABLED_SELECTED_STATE_SET = StateSet.get(
   1601                 StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_ENABLED
   1602                         | StateSet.VIEW_STATE_PRESSED);
   1603         PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1604                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
   1605                         | StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_PRESSED);
   1606         PRESSED_ENABLED_FOCUSED_STATE_SET = StateSet.get(
   1607                 StateSet.VIEW_STATE_FOCUSED | StateSet.VIEW_STATE_ENABLED
   1608                         | StateSet.VIEW_STATE_PRESSED);
   1609         PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1610                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_FOCUSED
   1611                         | StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_PRESSED);
   1612         PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET = StateSet.get(
   1613                 StateSet.VIEW_STATE_SELECTED | StateSet.VIEW_STATE_FOCUSED
   1614                         | StateSet.VIEW_STATE_ENABLED | StateSet.VIEW_STATE_PRESSED);
   1615         PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = StateSet.get(
   1616                 StateSet.VIEW_STATE_WINDOW_FOCUSED | StateSet.VIEW_STATE_SELECTED
   1617                         | StateSet.VIEW_STATE_FOCUSED| StateSet.VIEW_STATE_ENABLED
   1618                         | StateSet.VIEW_STATE_PRESSED);
   1619     }
   1620 
   1621     /**
   1622      * Accessibility event types that are dispatched for text population.
   1623      */
   1624     private static final int POPULATING_ACCESSIBILITY_EVENT_TYPES =
   1625             AccessibilityEvent.TYPE_VIEW_CLICKED
   1626             | AccessibilityEvent.TYPE_VIEW_LONG_CLICKED
   1627             | AccessibilityEvent.TYPE_VIEW_SELECTED
   1628             | AccessibilityEvent.TYPE_VIEW_FOCUSED
   1629             | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
   1630             | AccessibilityEvent.TYPE_VIEW_HOVER_ENTER
   1631             | AccessibilityEvent.TYPE_VIEW_HOVER_EXIT
   1632             | AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED
   1633             | AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED
   1634             | AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED
   1635             | AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY;
   1636 
   1637     /**
   1638      * Temporary Rect currently for use in setBackground().  This will probably
   1639      * be extended in the future to hold our own class with more than just
   1640      * a Rect. :)
   1641      */
   1642     static final ThreadLocal<Rect> sThreadLocal = new ThreadLocal<Rect>();
   1643 
   1644     /**
   1645      * Map used to store views' tags.
   1646      */
   1647     private SparseArray<Object> mKeyedTags;
   1648 
   1649     /**
   1650      * The next available accessibility id.
   1651      */
   1652     private static int sNextAccessibilityViewId;
   1653 
   1654     /**
   1655      * The animation currently associated with this view.
   1656      * @hide
   1657      */
   1658     protected Animation mCurrentAnimation = null;
   1659 
   1660     /**
   1661      * Width as measured during measure pass.
   1662      * {@hide}
   1663      */
   1664     @ViewDebug.ExportedProperty(category = "measurement")
   1665     int mMeasuredWidth;
   1666 
   1667     /**
   1668      * Height as measured during measure pass.
   1669      * {@hide}
   1670      */
   1671     @ViewDebug.ExportedProperty(category = "measurement")
   1672     int mMeasuredHeight;
   1673 
   1674     /**
   1675      * Flag to indicate that this view was marked INVALIDATED, or had its display list
   1676      * invalidated, prior to the current drawing iteration. If true, the view must re-draw
   1677      * its display list. This flag, used only when hw accelerated, allows us to clear the
   1678      * flag while retaining this information until it's needed (at getDisplayList() time and
   1679      * in drawChild(), when we decide to draw a view's children's display lists into our own).
   1680      *
   1681      * {@hide}
   1682      */
   1683     boolean mRecreateDisplayList = false;
   1684 
   1685     /**
   1686      * The view's identifier.
   1687      * {@hide}
   1688      *
   1689      * @see #setId(int)
   1690      * @see #getId()
   1691      */
   1692     @IdRes
   1693     @ViewDebug.ExportedProperty(resolveId = true)
   1694     int mID = NO_ID;
   1695 
   1696     /**
   1697      * The stable ID of this view for accessibility purposes.
   1698      */
   1699     int mAccessibilityViewId = NO_ID;
   1700 
   1701     private int mAccessibilityCursorPosition = ACCESSIBILITY_CURSOR_POSITION_UNDEFINED;
   1702 
   1703     SendViewStateChangedAccessibilityEvent mSendViewStateChangedAccessibilityEvent;
   1704 
   1705     /**
   1706      * The view's tag.
   1707      * {@hide}
   1708      *
   1709      * @see #setTag(Object)
   1710      * @see #getTag()
   1711      */
   1712     protected Object mTag = null;
   1713 
   1714     // for mPrivateFlags:
   1715     /** {@hide} */
   1716     static final int PFLAG_WANTS_FOCUS                 = 0x00000001;
   1717     /** {@hide} */
   1718     static final int PFLAG_FOCUSED                     = 0x00000002;
   1719     /** {@hide} */
   1720     static final int PFLAG_SELECTED                    = 0x00000004;
   1721     /** {@hide} */
   1722     static final int PFLAG_IS_ROOT_NAMESPACE           = 0x00000008;
   1723     /** {@hide} */
   1724     static final int PFLAG_HAS_BOUNDS                  = 0x00000010;
   1725     /** {@hide} */
   1726     static final int PFLAG_DRAWN                       = 0x00000020;
   1727     /**
   1728      * When this flag is set, this view is running an animation on behalf of its
   1729      * children and should therefore not cancel invalidate requests, even if they
   1730      * lie outside of this view's bounds.
   1731      *
   1732      * {@hide}
   1733      */
   1734     static final int PFLAG_DRAW_ANIMATION              = 0x00000040;
   1735     /** {@hide} */
   1736     static final int PFLAG_SKIP_DRAW                   = 0x00000080;
   1737     /** {@hide} */
   1738     static final int PFLAG_REQUEST_TRANSPARENT_REGIONS = 0x00000200;
   1739     /** {@hide} */
   1740     static final int PFLAG_DRAWABLE_STATE_DIRTY        = 0x00000400;
   1741     /** {@hide} */
   1742     static final int PFLAG_MEASURED_DIMENSION_SET      = 0x00000800;
   1743     /** {@hide} */
   1744     static final int PFLAG_FORCE_LAYOUT                = 0x00001000;
   1745     /** {@hide} */
   1746     static final int PFLAG_LAYOUT_REQUIRED             = 0x00002000;
   1747 
   1748     private static final int PFLAG_PRESSED             = 0x00004000;
   1749 
   1750     /** {@hide} */
   1751     static final int PFLAG_DRAWING_CACHE_VALID         = 0x00008000;
   1752     /**
   1753      * Flag used to indicate that this view should be drawn once more (and only once
   1754      * more) after its animation has completed.
   1755      * {@hide}
   1756      */
   1757     static final int PFLAG_ANIMATION_STARTED           = 0x00010000;
   1758 
   1759     private static final int PFLAG_SAVE_STATE_CALLED   = 0x00020000;
   1760 
   1761     /**
   1762      * Indicates that the View returned true when onSetAlpha() was called and that
   1763      * the alpha must be restored.
   1764      * {@hide}
   1765      */
   1766     static final int PFLAG_ALPHA_SET                   = 0x00040000;
   1767 
   1768     /**
   1769      * Set by {@link #setScrollContainer(boolean)}.
   1770      */
   1771     static final int PFLAG_SCROLL_CONTAINER            = 0x00080000;
   1772 
   1773     /**
   1774      * Set by {@link #setScrollContainer(boolean)}.
   1775      */
   1776     static final int PFLAG_SCROLL_CONTAINER_ADDED      = 0x00100000;
   1777 
   1778     /**
   1779      * View flag indicating whether this view was invalidated (fully or partially.)
   1780      *
   1781      * @hide
   1782      */
   1783     static final int PFLAG_DIRTY                       = 0x00200000;
   1784 
   1785     /**
   1786      * View flag indicating whether this view was invalidated by an opaque
   1787      * invalidate request.
   1788      *
   1789      * @hide
   1790      */
   1791     static final int PFLAG_DIRTY_OPAQUE                = 0x00400000;
   1792 
   1793     /**
   1794      * Mask for {@link #PFLAG_DIRTY} and {@link #PFLAG_DIRTY_OPAQUE}.
   1795      *
   1796      * @hide
   1797      */
   1798     static final int PFLAG_DIRTY_MASK                  = 0x00600000;
   1799 
   1800     /**
   1801      * Indicates whether the background is opaque.
   1802      *
   1803      * @hide
   1804      */
   1805     static final int PFLAG_OPAQUE_BACKGROUND           = 0x00800000;
   1806 
   1807     /**
   1808      * Indicates whether the scrollbars are opaque.
   1809      *
   1810      * @hide
   1811      */
   1812     static final int PFLAG_OPAQUE_SCROLLBARS           = 0x01000000;
   1813 
   1814     /**
   1815      * Indicates whether the view is opaque.
   1816      *
   1817      * @hide
   1818      */
   1819     static final int PFLAG_OPAQUE_MASK                 = 0x01800000;
   1820 
   1821     /**
   1822      * Indicates a prepressed state;
   1823      * the short time between ACTION_DOWN and recognizing
   1824      * a 'real' press. Prepressed is used to recognize quick taps
   1825      * even when they are shorter than ViewConfiguration.getTapTimeout().
   1826      *
   1827      * @hide
   1828      */
   1829     private static final int PFLAG_PREPRESSED          = 0x02000000;
   1830 
   1831     /**
   1832      * Indicates whether the view is temporarily detached.
   1833      *
   1834      * @hide
   1835      */
   1836     static final int PFLAG_CANCEL_NEXT_UP_EVENT        = 0x04000000;
   1837 
   1838     /**
   1839      * Indicates that we should awaken scroll bars once attached
   1840      *
   1841      * PLEASE NOTE: This flag is now unused as we now send onVisibilityChanged
   1842      * during window attachment and it is no longer needed. Feel free to repurpose it.
   1843      *
   1844      * @hide
   1845      */
   1846     private static final int PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH = 0x08000000;
   1847 
   1848     /**
   1849      * Indicates that the view has received HOVER_ENTER.  Cleared on HOVER_EXIT.
   1850      * @hide
   1851      */
   1852     private static final int PFLAG_HOVERED             = 0x10000000;
   1853 
   1854     /**
   1855      * no longer needed, should be reused
   1856      */
   1857     private static final int PFLAG_DOES_NOTHING_REUSE_PLEASE = 0x20000000;
   1858 
   1859     /** {@hide} */
   1860     static final int PFLAG_ACTIVATED                   = 0x40000000;
   1861 
   1862     /**
   1863      * Indicates that this view was specifically invalidated, not just dirtied because some
   1864      * child view was invalidated. The flag is used to determine when we need to recreate
   1865      * a view's display list (as opposed to just returning a reference to its existing
   1866      * display list).
   1867      *
   1868      * @hide
   1869      */
   1870     static final int PFLAG_INVALIDATED                 = 0x80000000;
   1871 
   1872     /**
   1873      * Masks for mPrivateFlags2, as generated by dumpFlags():
   1874      *
   1875      * |-------|-------|-------|-------|
   1876      *                                 1 PFLAG2_DRAG_CAN_ACCEPT
   1877      *                                1  PFLAG2_DRAG_HOVERED
   1878      *                              11   PFLAG2_LAYOUT_DIRECTION_MASK
   1879      *                             1     PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL
   1880      *                            1      PFLAG2_LAYOUT_DIRECTION_RESOLVED
   1881      *                            11     PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK
   1882      *                           1       PFLAG2_TEXT_DIRECTION_FLAGS[1]
   1883      *                          1        PFLAG2_TEXT_DIRECTION_FLAGS[2]
   1884      *                          11       PFLAG2_TEXT_DIRECTION_FLAGS[3]
   1885      *                         1         PFLAG2_TEXT_DIRECTION_FLAGS[4]
   1886      *                         1 1       PFLAG2_TEXT_DIRECTION_FLAGS[5]
   1887      *                         11        PFLAG2_TEXT_DIRECTION_FLAGS[6]
   1888      *                         111       PFLAG2_TEXT_DIRECTION_FLAGS[7]
   1889      *                         111       PFLAG2_TEXT_DIRECTION_MASK
   1890      *                        1          PFLAG2_TEXT_DIRECTION_RESOLVED
   1891      *                       1           PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT
   1892      *                     111           PFLAG2_TEXT_DIRECTION_RESOLVED_MASK
   1893      *                    1              PFLAG2_TEXT_ALIGNMENT_FLAGS[1]
   1894      *                   1               PFLAG2_TEXT_ALIGNMENT_FLAGS[2]
   1895      *                   11              PFLAG2_TEXT_ALIGNMENT_FLAGS[3]
   1896      *                  1                PFLAG2_TEXT_ALIGNMENT_FLAGS[4]
   1897      *                  1 1              PFLAG2_TEXT_ALIGNMENT_FLAGS[5]
   1898      *                  11               PFLAG2_TEXT_ALIGNMENT_FLAGS[6]
   1899      *                  111              PFLAG2_TEXT_ALIGNMENT_MASK
   1900      *                 1                 PFLAG2_TEXT_ALIGNMENT_RESOLVED
   1901      *                1                  PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT
   1902      *              111                  PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK
   1903      *           111                     PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK
   1904      *         11                        PFLAG2_ACCESSIBILITY_LIVE_REGION_MASK
   1905      *       1                           PFLAG2_ACCESSIBILITY_FOCUSED
   1906      *      1                            PFLAG2_SUBTREE_ACCESSIBILITY_STATE_CHANGED
   1907      *     1                             PFLAG2_VIEW_QUICK_REJECTED
   1908      *    1                              PFLAG2_PADDING_RESOLVED
   1909      *   1                               PFLAG2_DRAWABLE_RESOLVED
   1910      *  1                                PFLAG2_HAS_TRANSIENT_STATE
   1911      * |-------|-------|-------|-------|
   1912      */
   1913 
   1914     /**
   1915      * Indicates that this view has reported that it can accept the current drag's content.
   1916      * Cleared when the drag operation concludes.
   1917      * @hide
   1918      */
   1919     static final int PFLAG2_DRAG_CAN_ACCEPT            = 0x00000001;
   1920 
   1921     /**
   1922      * Indicates that this view is currently directly under the drag location in a
   1923      * drag-and-drop operation involving content that it can accept.  Cleared when
   1924      * the drag exits the view, or when the drag operation concludes.
   1925      * @hide
   1926      */
   1927     static final int PFLAG2_DRAG_HOVERED               = 0x00000002;
   1928 
   1929     /** @hide */
   1930     @IntDef({
   1931         LAYOUT_DIRECTION_LTR,
   1932         LAYOUT_DIRECTION_RTL,
   1933         LAYOUT_DIRECTION_INHERIT,
   1934         LAYOUT_DIRECTION_LOCALE
   1935     })
   1936     @Retention(RetentionPolicy.SOURCE)
   1937     // Not called LayoutDirection to avoid conflict with android.util.LayoutDirection
   1938     public @interface LayoutDir {}
   1939 
   1940     /** @hide */
   1941     @IntDef({
   1942         LAYOUT_DIRECTION_LTR,
   1943         LAYOUT_DIRECTION_RTL
   1944     })
   1945     @Retention(RetentionPolicy.SOURCE)
   1946     public @interface ResolvedLayoutDir {}
   1947 
   1948     /**
   1949      * A flag to indicate that the layout direction of this view has not been defined yet.
   1950      * @hide
   1951      */
   1952     public static final int LAYOUT_DIRECTION_UNDEFINED = LayoutDirection.UNDEFINED;
   1953 
   1954     /**
   1955      * Horizontal layout direction of this view is from Left to Right.
   1956      * Use with {@link #setLayoutDirection}.
   1957      */
   1958     public static final int LAYOUT_DIRECTION_LTR = LayoutDirection.LTR;
   1959 
   1960     /**
   1961      * Horizontal layout direction of this view is from Right to Left.
   1962      * Use with {@link #setLayoutDirection}.
   1963      */
   1964     public static final int LAYOUT_DIRECTION_RTL = LayoutDirection.RTL;
   1965 
   1966     /**
   1967      * Horizontal layout direction of this view is inherited from its parent.
   1968      * Use with {@link #setLayoutDirection}.
   1969      */
   1970     public static final int LAYOUT_DIRECTION_INHERIT = LayoutDirection.INHERIT;
   1971 
   1972     /**
   1973      * Horizontal layout direction of this view is from deduced from the default language
   1974      * script for the locale. Use with {@link #setLayoutDirection}.
   1975      */
   1976     public static final int LAYOUT_DIRECTION_LOCALE = LayoutDirection.LOCALE;
   1977 
   1978     /**
   1979      * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED)
   1980      * @hide
   1981      */
   1982     static final int PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT = 2;
   1983 
   1984     /**
   1985      * Mask for use with private flags indicating bits used for horizontal layout direction.
   1986      * @hide
   1987      */
   1988     static final int PFLAG2_LAYOUT_DIRECTION_MASK = 0x00000003 << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT;
   1989 
   1990     /**
   1991      * Indicates whether the view horizontal layout direction has been resolved and drawn to the
   1992      * right-to-left direction.
   1993      * @hide
   1994      */
   1995     static final int PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL = 4 << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT;
   1996 
   1997     /**
   1998      * Indicates whether the view horizontal layout direction has been resolved.
   1999      * @hide
   2000      */
   2001     static final int PFLAG2_LAYOUT_DIRECTION_RESOLVED = 8 << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT;
   2002 
   2003     /**
   2004      * Mask for use with private flags indicating bits used for resolved horizontal layout direction.
   2005      * @hide
   2006      */
   2007     static final int PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK = 0x0000000C
   2008             << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT;
   2009 
   2010     /*
   2011      * Array of horizontal layout direction flags for mapping attribute "layoutDirection" to correct
   2012      * flag value.
   2013      * @hide
   2014      */
   2015     private static final int[] LAYOUT_DIRECTION_FLAGS = {
   2016             LAYOUT_DIRECTION_LTR,
   2017             LAYOUT_DIRECTION_RTL,
   2018             LAYOUT_DIRECTION_INHERIT,
   2019             LAYOUT_DIRECTION_LOCALE
   2020     };
   2021 
   2022     /**
   2023      * Default horizontal layout direction.
   2024      */
   2025     private static final int LAYOUT_DIRECTION_DEFAULT = LAYOUT_DIRECTION_INHERIT;
   2026 
   2027     /**
   2028      * Default horizontal layout direction.
   2029      * @hide
   2030      */
   2031     static final int LAYOUT_DIRECTION_RESOLVED_DEFAULT = LAYOUT_DIRECTION_LTR;
   2032 
   2033     /**
   2034      * Text direction is inherited through {@link ViewGroup}
   2035      */
   2036     public static final int TEXT_DIRECTION_INHERIT = 0;
   2037 
   2038     /**
   2039      * Text direction is using "first strong algorithm". The first strong directional character
   2040      * determines the paragraph direction. If there is no strong directional character, the
   2041      * paragraph direction is the view's resolved layout direction.
   2042      */
   2043     public static final int TEXT_DIRECTION_FIRST_STRONG = 1;
   2044 
   2045     /**
   2046      * Text direction is using "any-RTL" algorithm. The paragraph direction is RTL if it contains
   2047      * any strong RTL character, otherwise it is LTR if it contains any strong LTR characters.
   2048      * If there are neither, the paragraph direction is the view's resolved layout direction.
   2049      */
   2050     public static final int TEXT_DIRECTION_ANY_RTL = 2;
   2051 
   2052     /**
   2053      * Text direction is forced to LTR.
   2054      */
   2055     public static final int TEXT_DIRECTION_LTR = 3;
   2056 
   2057     /**
   2058      * Text direction is forced to RTL.
   2059      */
   2060     public static final int TEXT_DIRECTION_RTL = 4;
   2061 
   2062     /**
   2063      * Text direction is coming from the system Locale.
   2064      */
   2065     public static final int TEXT_DIRECTION_LOCALE = 5;
   2066 
   2067     /**
   2068      * Text direction is using "first strong algorithm". The first strong directional character
   2069      * determines the paragraph direction. If there is no strong directional character, the
   2070      * paragraph direction is LTR.
   2071      */
   2072     public static final int TEXT_DIRECTION_FIRST_STRONG_LTR = 6;
   2073 
   2074     /**
   2075      * Text direction is using "first strong algorithm". The first strong directional character
   2076      * determines the paragraph direction. If there is no strong directional character, the
   2077      * paragraph direction is RTL.
   2078      */
   2079     public static final int TEXT_DIRECTION_FIRST_STRONG_RTL = 7;
   2080 
   2081     /**
   2082      * Default text direction is inherited
   2083      */
   2084     private static final int TEXT_DIRECTION_DEFAULT = TEXT_DIRECTION_INHERIT;
   2085 
   2086     /**
   2087      * Default resolved text direction
   2088      * @hide
   2089      */
   2090     static final int TEXT_DIRECTION_RESOLVED_DEFAULT = TEXT_DIRECTION_FIRST_STRONG;
   2091 
   2092     /**
   2093      * Bit shift to get the horizontal layout direction. (bits after LAYOUT_DIRECTION_RESOLVED)
   2094      * @hide
   2095      */
   2096     static final int PFLAG2_TEXT_DIRECTION_MASK_SHIFT = 6;
   2097 
   2098     /**
   2099      * Mask for use with private flags indicating bits used for text direction.
   2100      * @hide
   2101      */
   2102     static final int PFLAG2_TEXT_DIRECTION_MASK = 0x00000007
   2103             << PFLAG2_TEXT_DIRECTION_MASK_SHIFT;
   2104 
   2105     /**
   2106      * Array of text direction flags for mapping attribute "textDirection" to correct
   2107      * flag value.
   2108      * @hide
   2109      */
   2110     private static final int[] PFLAG2_TEXT_DIRECTION_FLAGS = {
   2111             TEXT_DIRECTION_INHERIT << PFLAG2_TEXT_DIRECTION_MASK_SHIFT,
   2112             TEXT_DIRECTION_FIRST_STRONG << PFLAG2_TEXT_DIRECTION_MASK_SHIFT,
   2113             TEXT_DIRECTION_ANY_RTL << PFLAG2_TEXT_DIRECTION_MASK_SHIFT,
   2114             TEXT_DIRECTION_LTR << PFLAG2_TEXT_DIRECTION_MASK_SHIFT,
   2115             TEXT_DIRECTION_RTL << PFLAG2_TEXT_DIRECTION_MASK_SHIFT,
   2116             TEXT_DIRECTION_LOCALE << PFLAG2_TEXT_DIRECTION_MASK_SHIFT,
   2117             TEXT_DIRECTION_FIRST_STRONG_LTR << PFLAG2_TEXT_DIRECTION_MASK_SHIFT,
   2118             TEXT_DIRECTION_FIRST_STRONG_RTL << PFLAG2_TEXT_DIRECTION_MASK_SHIFT
   2119     };
   2120 
   2121     /**
   2122      * Indicates whether the view text direction has been resolved.
   2123      * @hide
   2124      */
   2125     static final int PFLAG2_TEXT_DIRECTION_RESOLVED = 0x00000008
   2126             << PFLAG2_TEXT_DIRECTION_MASK_SHIFT;
   2127 
   2128     /**
   2129      * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED)
   2130      * @hide
   2131      */
   2132     static final int PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT = 10;
   2133 
   2134     /**
   2135      * Mask for use with private flags indicating bits used for resolved text direction.
   2136      * @hide
   2137      */
   2138     static final int PFLAG2_TEXT_DIRECTION_RESOLVED_MASK = 0x00000007
   2139             << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT;
   2140 
   2141     /**
   2142      * Indicates whether the view text direction has been resolved to the "first strong" heuristic.
   2143      * @hide
   2144      */
   2145     static final int PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT =
   2146             TEXT_DIRECTION_RESOLVED_DEFAULT << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT;
   2147 
   2148     /** @hide */
   2149     @IntDef({
   2150         TEXT_ALIGNMENT_INHERIT,
   2151         TEXT_ALIGNMENT_GRAVITY,
   2152         TEXT_ALIGNMENT_CENTER,
   2153         TEXT_ALIGNMENT_TEXT_START,
   2154         TEXT_ALIGNMENT_TEXT_END,
   2155         TEXT_ALIGNMENT_VIEW_START,
   2156         TEXT_ALIGNMENT_VIEW_END
   2157     })
   2158     @Retention(RetentionPolicy.SOURCE)
   2159     public @interface TextAlignment {}
   2160 
   2161     /**
   2162      * Default text alignment. The text alignment of this View is inherited from its parent.
   2163      * Use with {@link #setTextAlignment(int)}
   2164      */
   2165     public static final int TEXT_ALIGNMENT_INHERIT = 0;
   2166 
   2167     /**
   2168      * Default for the root view. The gravity determines the text alignment, ALIGN_NORMAL,
   2169      * ALIGN_CENTER, or ALIGN_OPPOSITE, which are relative to each paragraphs text direction.
   2170      *
   2171      * Use with {@link #setTextAlignment(int)}
   2172      */
   2173     public static final int TEXT_ALIGNMENT_GRAVITY = 1;
   2174 
   2175     /**
   2176      * Align to the start of the paragraph, e.g. ALIGN_NORMAL.
   2177      *
   2178      * Use with {@link #setTextAlignment(int)}
   2179      */
   2180     public static final int TEXT_ALIGNMENT_TEXT_START = 2;
   2181 
   2182     /**
   2183      * Align to the end of the paragraph, e.g. ALIGN_OPPOSITE.
   2184      *
   2185      * Use with {@link #setTextAlignment(int)}
   2186      */
   2187     public static final int TEXT_ALIGNMENT_TEXT_END = 3;
   2188 
   2189     /**
   2190      * Center the paragraph, e.g. ALIGN_CENTER.
   2191      *
   2192      * Use with {@link #setTextAlignment(int)}
   2193      */
   2194     public static final int TEXT_ALIGNMENT_CENTER = 4;
   2195 
   2196     /**
   2197      * Align to the start of the view, which is ALIGN_LEFT if the views resolved
   2198      * layoutDirection is LTR, and ALIGN_RIGHT otherwise.
   2199      *
   2200      * Use with {@link #setTextAlignment(int)}
   2201      */
   2202     public static final int TEXT_ALIGNMENT_VIEW_START = 5;
   2203 
   2204     /**
   2205      * Align to the end of the view, which is ALIGN_RIGHT if the views resolved
   2206      * layoutDirection is LTR, and ALIGN_LEFT otherwise.
   2207      *
   2208      * Use with {@link #setTextAlignment(int)}
   2209      */
   2210     public static final int TEXT_ALIGNMENT_VIEW_END = 6;
   2211 
   2212     /**
   2213      * Default text alignment is inherited
   2214      */
   2215     private static final int TEXT_ALIGNMENT_DEFAULT = TEXT_ALIGNMENT_GRAVITY;
   2216 
   2217     /**
   2218      * Default resolved text alignment
   2219      * @hide
   2220      */
   2221     static final int TEXT_ALIGNMENT_RESOLVED_DEFAULT = TEXT_ALIGNMENT_GRAVITY;
   2222 
   2223     /**
   2224       * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED)
   2225       * @hide
   2226       */
   2227     static final int PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT = 13;
   2228 
   2229     /**
   2230       * Mask for use with private flags indicating bits used for text alignment.
   2231       * @hide
   2232       */
   2233     static final int PFLAG2_TEXT_ALIGNMENT_MASK = 0x00000007 << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT;
   2234 
   2235     /**
   2236      * Array of text direction flags for mapping attribute "textAlignment" to correct
   2237      * flag value.
   2238      * @hide
   2239      */
   2240     private static final int[] PFLAG2_TEXT_ALIGNMENT_FLAGS = {
   2241             TEXT_ALIGNMENT_INHERIT << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT,
   2242             TEXT_ALIGNMENT_GRAVITY << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT,
   2243             TEXT_ALIGNMENT_TEXT_START << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT,
   2244             TEXT_ALIGNMENT_TEXT_END << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT,
   2245             TEXT_ALIGNMENT_CENTER << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT,
   2246             TEXT_ALIGNMENT_VIEW_START << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT,
   2247             TEXT_ALIGNMENT_VIEW_END << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT
   2248     };
   2249 
   2250     /**
   2251      * Indicates whether the view text alignment has been resolved.
   2252      * @hide
   2253      */
   2254     static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED = 0x00000008 << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT;
   2255 
   2256     /**
   2257      * Bit shift to get the resolved text alignment.
   2258      * @hide
   2259      */
   2260     static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT = 17;
   2261 
   2262     /**
   2263      * Mask for use with private flags indicating bits used for text alignment.
   2264      * @hide
   2265      */
   2266     static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK = 0x00000007
   2267             << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT;
   2268 
   2269     /**
   2270      * Indicates whether if the view text alignment has been resolved to gravity
   2271      */
   2272     private static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT =
   2273             TEXT_ALIGNMENT_RESOLVED_DEFAULT << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT;
   2274 
   2275     // Accessiblity constants for mPrivateFlags2
   2276 
   2277     /**
   2278      * Shift for the bits in {@link #mPrivateFlags2} related to the
   2279      * "importantForAccessibility" attribute.
   2280      */
   2281     static final int PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT = 20;
   2282 
   2283     /**
   2284      * Automatically determine whether a view is important for accessibility.
   2285      */
   2286     public static final int IMPORTANT_FOR_ACCESSIBILITY_AUTO = 0x00000000;
   2287 
   2288     /**
   2289      * The view is important for accessibility.
   2290      */
   2291     public static final int IMPORTANT_FOR_ACCESSIBILITY_YES = 0x00000001;
   2292 
   2293     /**
   2294      * The view is not important for accessibility.
   2295      */
   2296     public static final int IMPORTANT_FOR_ACCESSIBILITY_NO = 0x00000002;
   2297 
   2298     /**
   2299      * The view is not important for accessibility, nor are any of its
   2300      * descendant views.
   2301      */
   2302     public static final int IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS = 0x00000004;
   2303 
   2304     /**
   2305      * The default whether the view is important for accessibility.
   2306      */
   2307     static final int IMPORTANT_FOR_ACCESSIBILITY_DEFAULT = IMPORTANT_FOR_ACCESSIBILITY_AUTO;
   2308 
   2309     /**
   2310      * Mask for obtainig the bits which specify how to determine
   2311      * whether a view is important for accessibility.
   2312      */
   2313     static final int PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK = (IMPORTANT_FOR_ACCESSIBILITY_AUTO
   2314         | IMPORTANT_FOR_ACCESSIBILITY_YES | IMPORTANT_FOR_ACCESSIBILITY_NO
   2315         | IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS)
   2316         << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT;
   2317 
   2318     /**
   2319      * Shift for the bits in {@link #mPrivateFlags2} related to the
   2320      * "accessibilityLiveRegion" attribute.
   2321      */
   2322     static final int PFLAG2_ACCESSIBILITY_LIVE_REGION_SHIFT = 23;
   2323 
   2324     /**
   2325      * Live region mode specifying that accessibility services should not
   2326      * automatically announce changes to this view. This is the default live
   2327      * region mode for most views.
   2328      * <p>
   2329      * Use with {@link #setAccessibilityLiveRegion(int)}.
   2330      */
   2331     public static final int ACCESSIBILITY_LIVE_REGION_NONE = 0x00000000;
   2332 
   2333     /**
   2334      * Live region mode specifying that accessibility services should announce
   2335      * changes to this view.
   2336      * <p>
   2337      * Use with {@link #setAccessibilityLiveRegion(int)}.
   2338      */
   2339     public static final int ACCESSIBILITY_LIVE_REGION_POLITE = 0x00000001;
   2340 
   2341     /**
   2342      * Live region mode specifying that accessibility services should interrupt
   2343      * ongoing speech to immediately announce changes to this view.
   2344      * <p>
   2345      * Use with {@link #setAccessibilityLiveRegion(int)}.
   2346      */
   2347     public static final int ACCESSIBILITY_LIVE_REGION_ASSERTIVE = 0x00000002;
   2348 
   2349     /**
   2350      * The default whether the view is important for accessibility.
   2351      */
   2352     static final int ACCESSIBILITY_LIVE_REGION_DEFAULT = ACCESSIBILITY_LIVE_REGION_NONE;
   2353 
   2354     /**
   2355      * Mask for obtaining the bits which specify a view's accessibility live
   2356      * region mode.
   2357      */
   2358     static final int PFLAG2_ACCESSIBILITY_LIVE_REGION_MASK = (ACCESSIBILITY_LIVE_REGION_NONE
   2359             | ACCESSIBILITY_LIVE_REGION_POLITE | ACCESSIBILITY_LIVE_REGION_ASSERTIVE)
   2360             << PFLAG2_ACCESSIBILITY_LIVE_REGION_SHIFT;
   2361 
   2362     /**
   2363      * Flag indicating whether a view has accessibility focus.
   2364      */
   2365     static final int PFLAG2_ACCESSIBILITY_FOCUSED = 0x04000000;
   2366 
   2367     /**
   2368      * Flag whether the accessibility state of the subtree rooted at this view changed.
   2369      */
   2370     static final int PFLAG2_SUBTREE_ACCESSIBILITY_STATE_CHANGED = 0x08000000;
   2371 
   2372     /**
   2373      * Flag indicating whether a view failed the quickReject() check in draw(). This condition
   2374      * is used to check whether later changes to the view's transform should invalidate the
   2375      * view to force the quickReject test to run again.
   2376      */
   2377     static final int PFLAG2_VIEW_QUICK_REJECTED = 0x10000000;
   2378 
   2379     /**
   2380      * Flag indicating that start/end padding has been resolved into left/right padding
   2381      * for use in measurement, layout, drawing, etc. This is set by {@link #resolvePadding()}
   2382      * and checked by {@link #measure(int, int)} to determine if padding needs to be resolved
   2383      * during measurement. In some special cases this is required such as when an adapter-based
   2384      * view measures prospective children without attaching them to a window.
   2385      */
   2386     static final int PFLAG2_PADDING_RESOLVED = 0x20000000;
   2387 
   2388     /**
   2389      * Flag indicating that the start/end drawables has been resolved into left/right ones.
   2390      */
   2391     static final int PFLAG2_DRAWABLE_RESOLVED = 0x40000000;
   2392 
   2393     /**
   2394      * Indicates that the view is tracking some sort of transient state
   2395      * that the app should not need to be aware of, but that the framework
   2396      * should take special care to preserve.
   2397      */
   2398     static final int PFLAG2_HAS_TRANSIENT_STATE = 0x80000000;
   2399 
   2400     /**
   2401      * Group of bits indicating that RTL properties resolution is done.
   2402      */
   2403     static final int ALL_RTL_PROPERTIES_RESOLVED = PFLAG2_LAYOUT_DIRECTION_RESOLVED |
   2404             PFLAG2_TEXT_DIRECTION_RESOLVED |
   2405             PFLAG2_TEXT_ALIGNMENT_RESOLVED |
   2406             PFLAG2_PADDING_RESOLVED |
   2407             PFLAG2_DRAWABLE_RESOLVED;
   2408 
   2409     // There are a couple of flags left in mPrivateFlags2
   2410 
   2411     /* End of masks for mPrivateFlags2 */
   2412 
   2413     /**
   2414      * Masks for mPrivateFlags3, as generated by dumpFlags():
   2415      *
   2416      * |-------|-------|-------|-------|
   2417      *                                 1 PFLAG3_VIEW_IS_ANIMATING_TRANSFORM
   2418      *                                1  PFLAG3_VIEW_IS_ANIMATING_ALPHA
   2419      *                               1   PFLAG3_IS_LAID_OUT
   2420      *                              1    PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT
   2421      *                             1     PFLAG3_CALLED_SUPER
   2422      *                            1      PFLAG3_APPLYING_INSETS
   2423      *                           1       PFLAG3_FITTING_SYSTEM_WINDOWS
   2424      *                          1        PFLAG3_NESTED_SCROLLING_ENABLED
   2425      *                         1         PFLAG3_SCROLL_INDICATOR_TOP
   2426      *                        1          PFLAG3_SCROLL_INDICATOR_BOTTOM
   2427      *                       1           PFLAG3_SCROLL_INDICATOR_LEFT
   2428      *                      1            PFLAG3_SCROLL_INDICATOR_RIGHT
   2429      *                     1             PFLAG3_SCROLL_INDICATOR_START
   2430      *                    1              PFLAG3_SCROLL_INDICATOR_END
   2431      *                   1               PFLAG3_ASSIST_BLOCKED
   2432      *                  1                PFLAG3_POINTER_ICON_NULL
   2433      *                 1                 PFLAG3_POINTER_ICON_VALUE_START
   2434      *           11111111                PFLAG3_POINTER_ICON_MASK
   2435      *          1                        PFLAG3_OVERLAPPING_RENDERING_FORCED_VALUE
   2436      *         1                         PFLAG3_HAS_OVERLAPPING_RENDERING_FORCED
   2437      *        1                          PFLAG3_TEMPORARY_DETACH
   2438      * |-------|-------|-------|-------|
   2439      */
   2440 
   2441     /**
   2442      * Flag indicating that view has a transform animation set on it. This is used to track whether
   2443      * an animation is cleared between successive frames, in order to tell the associated
   2444      * DisplayList to clear its animation matrix.
   2445      */
   2446     static final int PFLAG3_VIEW_IS_ANIMATING_TRANSFORM = 0x1;
   2447 
   2448     /**
   2449      * Flag indicating that view has an alpha animation set on it. This is used to track whether an
   2450      * animation is cleared between successive frames, in order to tell the associated
   2451      * DisplayList to restore its alpha value.
   2452      */
   2453     static final int PFLAG3_VIEW_IS_ANIMATING_ALPHA = 0x2;
   2454 
   2455     /**
   2456      * Flag indicating that the view has been through at least one layout since it
   2457      * was last attached to a window.
   2458      */
   2459     static final int PFLAG3_IS_LAID_OUT = 0x4;
   2460 
   2461     /**
   2462      * Flag indicating that a call to measure() was skipped and should be done
   2463      * instead when layout() is invoked.
   2464      */
   2465     static final int PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT = 0x8;
   2466 
   2467     /**
   2468      * Flag indicating that an overridden method correctly called down to
   2469      * the superclass implementation as required by the API spec.
   2470      */
   2471     static final int PFLAG3_CALLED_SUPER = 0x10;
   2472 
   2473     /**
   2474      * Flag indicating that we're in the process of applying window insets.
   2475      */
   2476     static final int PFLAG3_APPLYING_INSETS = 0x20;
   2477 
   2478     /**
   2479      * Flag indicating that we're in the process of fitting system windows using the old method.
   2480      */
   2481     static final int PFLAG3_FITTING_SYSTEM_WINDOWS = 0x40;
   2482 
   2483     /**
   2484      * Flag indicating that nested scrolling is enabled for this view.
   2485      * The view will optionally cooperate with views up its parent chain to allow for
   2486      * integrated nested scrolling along the same axis.
   2487      */
   2488     static final int PFLAG3_NESTED_SCROLLING_ENABLED = 0x80;
   2489 
   2490     /**
   2491      * Flag indicating that the bottom scroll indicator should be displayed
   2492      * when this view can scroll up.
   2493      */
   2494     static final int PFLAG3_SCROLL_INDICATOR_TOP = 0x0100;
   2495 
   2496     /**
   2497      * Flag indicating that the bottom scroll indicator should be displayed
   2498      * when this view can scroll down.
   2499      */
   2500     static final int PFLAG3_SCROLL_INDICATOR_BOTTOM = 0x0200;
   2501 
   2502     /**
   2503      * Flag indicating that the left scroll indicator should be displayed
   2504      * when this view can scroll left.
   2505      */
   2506     static final int PFLAG3_SCROLL_INDICATOR_LEFT = 0x0400;
   2507 
   2508     /**
   2509      * Flag indicating that the right scroll indicator should be displayed
   2510      * when this view can scroll right.
   2511      */
   2512     static final int PFLAG3_SCROLL_INDICATOR_RIGHT = 0x0800;
   2513 
   2514     /**
   2515      * Flag indicating that the start scroll indicator should be displayed
   2516      * when this view can scroll in the start direction.
   2517      */
   2518     static final int PFLAG3_SCROLL_INDICATOR_START = 0x1000;
   2519 
   2520     /**
   2521      * Flag indicating that the end scroll indicator should be displayed
   2522      * when this view can scroll in the end direction.
   2523      */
   2524     static final int PFLAG3_SCROLL_INDICATOR_END = 0x2000;
   2525 
   2526     static final int DRAG_MASK = PFLAG2_DRAG_CAN_ACCEPT | PFLAG2_DRAG_HOVERED;
   2527 
   2528     static final int SCROLL_INDICATORS_NONE = 0x0000;
   2529 
   2530     /**
   2531      * Mask for use with setFlags indicating bits used for indicating which
   2532      * scroll indicators are enabled.
   2533      */
   2534     static final int SCROLL_INDICATORS_PFLAG3_MASK = PFLAG3_SCROLL_INDICATOR_TOP
   2535             | PFLAG3_SCROLL_INDICATOR_BOTTOM | PFLAG3_SCROLL_INDICATOR_LEFT
   2536             | PFLAG3_SCROLL_INDICATOR_RIGHT | PFLAG3_SCROLL_INDICATOR_START
   2537             | PFLAG3_SCROLL_INDICATOR_END;
   2538 
   2539     /**
   2540      * Left-shift required to translate between public scroll indicator flags
   2541      * and internal PFLAGS3 flags. When used as a right-shift, translates
   2542      * PFLAGS3 flags to public flags.
   2543      */
   2544     static final int SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT = 8;
   2545 
   2546     /** @hide */
   2547     @Retention(RetentionPolicy.SOURCE)
   2548     @IntDef(flag = true,
   2549             value = {
   2550                     SCROLL_INDICATOR_TOP,
   2551                     SCROLL_INDICATOR_BOTTOM,
   2552                     SCROLL_INDICATOR_LEFT,
   2553                     SCROLL_INDICATOR_RIGHT,
   2554                     SCROLL_INDICATOR_START,
   2555                     SCROLL_INDICATOR_END,
   2556             })
   2557     public @interface ScrollIndicators {}
   2558 
   2559     /**
   2560      * Scroll indicator direction for the top edge of the view.
   2561      *
   2562      * @see #setScrollIndicators(int)
   2563      * @see #setScrollIndicators(int, int)
   2564      * @see #getScrollIndicators()
   2565      */
   2566     public static final int SCROLL_INDICATOR_TOP =
   2567             PFLAG3_SCROLL_INDICATOR_TOP >> SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT;
   2568 
   2569     /**
   2570      * Scroll indicator direction for the bottom edge of the view.
   2571      *
   2572      * @see #setScrollIndicators(int)
   2573      * @see #setScrollIndicators(int, int)
   2574      * @see #getScrollIndicators()
   2575      */
   2576     public static final int SCROLL_INDICATOR_BOTTOM =
   2577             PFLAG3_SCROLL_INDICATOR_BOTTOM >> SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT;
   2578 
   2579     /**
   2580      * Scroll indicator direction for the left edge of the view.
   2581      *
   2582      * @see #setScrollIndicators(int)
   2583      * @see #setScrollIndicators(int, int)
   2584      * @see #getScrollIndicators()
   2585      */
   2586     public static final int SCROLL_INDICATOR_LEFT =
   2587             PFLAG3_SCROLL_INDICATOR_LEFT >> SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT;
   2588 
   2589     /**
   2590      * Scroll indicator direction for the right edge of the view.
   2591      *
   2592      * @see #setScrollIndicators(int)
   2593      * @see #setScrollIndicators(int, int)
   2594      * @see #getScrollIndicators()
   2595      */
   2596     public static final int SCROLL_INDICATOR_RIGHT =
   2597             PFLAG3_SCROLL_INDICATOR_RIGHT >> SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT;
   2598 
   2599     /**
   2600      * Scroll indicator direction for the starting edge of the view.
   2601      * <p>
   2602      * Resolved according to the view's layout direction, see
   2603      * {@link #getLayoutDirection()} for more information.
   2604      *
   2605      * @see #setScrollIndicators(int)
   2606      * @see #setScrollIndicators(int, int)
   2607      * @see #getScrollIndicators()
   2608      */
   2609     public static final int SCROLL_INDICATOR_START =
   2610             PFLAG3_SCROLL_INDICATOR_START >> SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT;
   2611 
   2612     /**
   2613      * Scroll indicator direction for the ending edge of the view.
   2614      * <p>
   2615      * Resolved according to the view's layout direction, see
   2616      * {@link #getLayoutDirection()} for more information.
   2617      *
   2618      * @see #setScrollIndicators(int)
   2619      * @see #setScrollIndicators(int, int)
   2620      * @see #getScrollIndicators()
   2621      */
   2622     public static final int SCROLL_INDICATOR_END =
   2623             PFLAG3_SCROLL_INDICATOR_END >> SCROLL_INDICATORS_TO_PFLAGS3_LSHIFT;
   2624 
   2625     /**
   2626      * <p>Indicates that we are allowing {@link ViewStructure} to traverse
   2627      * into this view.<p>
   2628      */
   2629     static final int PFLAG3_ASSIST_BLOCKED = 0x4000;
   2630 
   2631     /**
   2632      * The mask for use with private flags indicating bits used for pointer icon shapes.
   2633      */
   2634     static final int PFLAG3_POINTER_ICON_MASK = 0x7f8000;
   2635 
   2636     /**
   2637      * Left-shift used for pointer icon shape values in private flags.
   2638      */
   2639     static final int PFLAG3_POINTER_ICON_LSHIFT = 15;
   2640 
   2641     /**
   2642      * Value indicating no specific pointer icons.
   2643      */
   2644     private static final int PFLAG3_POINTER_ICON_NOT_SPECIFIED = 0 << PFLAG3_POINTER_ICON_LSHIFT;
   2645 
   2646     /**
   2647      * Value indicating {@link PointerIcon.TYPE_NULL}.
   2648      */
   2649     private static final int PFLAG3_POINTER_ICON_NULL = 1 << PFLAG3_POINTER_ICON_LSHIFT;
   2650 
   2651     /**
   2652      * The base value for other pointer icon shapes.
   2653      */
   2654     private static final int PFLAG3_POINTER_ICON_VALUE_START = 2 << PFLAG3_POINTER_ICON_LSHIFT;
   2655 
   2656     /**
   2657      * Whether this view has rendered elements that overlap (see {@link
   2658      * #hasOverlappingRendering()}, {@link #forceHasOverlappingRendering(boolean)}, and
   2659      * {@link #getHasOverlappingRendering()} ). The value in this bit is only valid when
   2660      * PFLAG3_HAS_OVERLAPPING_RENDERING_FORCED has been set. Otherwise, the value is
   2661      * determined by whatever {@link #hasOverlappingRendering()} returns.
   2662      */
   2663     private static final int PFLAG3_OVERLAPPING_RENDERING_FORCED_VALUE = 0x800000;
   2664 
   2665     /**
   2666      * Whether {@link #forceHasOverlappingRendering(boolean)} has been called. When true, value
   2667      * in PFLAG3_OVERLAPPING_RENDERING_FORCED_VALUE is valid.
   2668      */
   2669     private static final int PFLAG3_HAS_OVERLAPPING_RENDERING_FORCED = 0x1000000;
   2670 
   2671     /**
   2672      * Flag indicating that the view is temporarily detached from the parent view.
   2673      *
   2674      * @see #onStartTemporaryDetach()
   2675      * @see #onFinishTemporaryDetach()
   2676      */
   2677     static final int PFLAG3_TEMPORARY_DETACH = 0x2000000;
   2678 
   2679     /* End of masks for mPrivateFlags3 */
   2680 
   2681     /**
   2682      * Always allow a user to over-scroll this view, provided it is a
   2683      * view that can scroll.
   2684      *
   2685      * @see #getOverScrollMode()
   2686      * @see #setOverScrollMode(int)
   2687      */
   2688     public static final int OVER_SCROLL_ALWAYS = 0;
   2689 
   2690     /**
   2691      * Allow a user to over-scroll this view only if the content is large
   2692      * enough to meaningfully scroll, provided it is a view that can scroll.
   2693      *
   2694      * @see #getOverScrollMode()
   2695      * @see #setOverScrollMode(int)
   2696      */
   2697     public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1;
   2698 
   2699     /**
   2700      * Never allow a user to over-scroll this view.
   2701      *
   2702      * @see #getOverScrollMode()
   2703      * @see #setOverScrollMode(int)
   2704      */
   2705     public static final int OVER_SCROLL_NEVER = 2;
   2706 
   2707     /**
   2708      * Special constant for {@link #setSystemUiVisibility(int)}: View has
   2709      * requested the system UI (status bar) to be visible (the default).
   2710      *
   2711      * @see #setSystemUiVisibility(int)
   2712      */
   2713     public static final int SYSTEM_UI_FLAG_VISIBLE = 0;
   2714 
   2715     /**
   2716      * Flag for {@link #setSystemUiVisibility(int)}: View has requested the
   2717      * system UI to enter an unobtrusive "low profile" mode.
   2718      *
   2719      * <p>This is for use in games, book readers, video players, or any other
   2720      * "immersive" application where the usual system chrome is deemed too distracting.
   2721      *
   2722      * <p>In low profile mode, the status bar and/or navigation icons may dim.
   2723      *
   2724      * @see #setSystemUiVisibility(int)
   2725      */
   2726     public static final int SYSTEM_UI_FLAG_LOW_PROFILE = 0x00000001;
   2727 
   2728     /**
   2729      * Flag for {@link #setSystemUiVisibility(int)}: View has requested that the
   2730      * system navigation be temporarily hidden.
   2731      *
   2732      * <p>This is an even less obtrusive state than that called for by
   2733      * {@link #SYSTEM_UI_FLAG_LOW_PROFILE}; on devices that draw essential navigation controls
   2734      * (Home, Back, and the like) on screen, <code>SYSTEM_UI_FLAG_HIDE_NAVIGATION</code> will cause
   2735      * those to disappear. This is useful (in conjunction with the
   2736      * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN FLAG_FULLSCREEN} and
   2737      * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN FLAG_LAYOUT_IN_SCREEN}
   2738      * window flags) for displaying content using every last pixel on the display.
   2739      *
   2740      * <p>There is a limitation: because navigation controls are so important, the least user
   2741      * interaction will cause them to reappear immediately.  When this happens, both
   2742      * this flag and {@link #SYSTEM_UI_FLAG_FULLSCREEN} will be cleared automatically,
   2743      * so that both elements reappear at the same time.
   2744      *
   2745      * @see #setSystemUiVisibility(int)
   2746      */
   2747     public static final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 0x00000002;
   2748 
   2749     /**
   2750      * Flag for {@link #setSystemUiVisibility(int)}: View has requested to go
   2751      * into the normal fullscreen mode so that its content can take over the screen
   2752      * while still allowing the user to interact with the application.
   2753      *
   2754      * <p>This has the same visual effect as
   2755      * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN
   2756      * WindowManager.LayoutParams.FLAG_FULLSCREEN},
   2757      * meaning that non-critical screen decorations (such as the status bar) will be
   2758      * hidden while the user is in the View's window, focusing the experience on
   2759      * that content.  Unlike the window flag, if you are using ActionBar in
   2760      * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY
   2761      * Window.FEATURE_ACTION_BAR_OVERLAY}, then enabling this flag will also
   2762      * hide the action bar.
   2763      *
   2764      * <p>This approach to going fullscreen is best used over the window flag when
   2765      * it is a transient state -- that is, the application does this at certain
   2766      * points in its user interaction where it wants to allow the user to focus
   2767      * on content, but not as a continuous state.  For situations where the application
   2768      * would like to simply stay full screen the entire time (such as a game that
   2769      * wants to take over the screen), the
   2770      * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN window flag}
   2771      * is usually a better approach.  The state set here will be removed by the system
   2772      * in various situations (such as the user moving to another application) like
   2773      * the other system UI states.
   2774      *
   2775      * <p>When using this flag, the application should provide some easy facility
   2776      * for the user to go out of it.  A common example would be in an e-book
   2777      * reader, where tapping on the screen brings back whatever screen and UI
   2778      * decorations that had been hidden while the user was immersed in reading
   2779      * the book.
   2780      *
   2781      * @see #setSystemUiVisibility(int)
   2782      */
   2783     public static final int SYSTEM_UI_FLAG_FULLSCREEN = 0x00000004;
   2784 
   2785     /**
   2786      * Flag for {@link #setSystemUiVisibility(int)}: When using other layout
   2787      * flags, we would like a stable view of the content insets given to
   2788      * {@link #fitSystemWindows(Rect)}.  This means that the insets seen there
   2789      * will always represent the worst case that the application can expect
   2790      * as a continuous state.  In the stock Android UI this is the space for
   2791      * the system bar, nav bar, and status bar, but not more transient elements
   2792      * such as an input method.
   2793      *
   2794      * The stable layout your UI sees is based on the system UI modes you can
   2795      * switch to.  That is, if you specify {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}
   2796      * then you will get a stable layout for changes of the
   2797      * {@link #SYSTEM_UI_FLAG_FULLSCREEN} mode; if you specify
   2798      * {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} and
   2799      * {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, then you can transition
   2800      * to {@link #SYSTEM_UI_FLAG_FULLSCREEN} and {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}
   2801      * with a stable layout.  (Note that you should avoid using
   2802      * {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION} by itself.)
   2803      *
   2804      * If you have set the window flag {@link WindowManager.LayoutParams#FLAG_FULLSCREEN}
   2805      * to hide the status bar (instead of using {@link #SYSTEM_UI_FLAG_FULLSCREEN}),
   2806      * then a hidden status bar will be considered a "stable" state for purposes
   2807      * here.  This allows your UI to continually hide the status bar, while still
   2808      * using the system UI flags to hide the action bar while still retaining
   2809      * a stable layout.  Note that changing the window fullscreen flag will never
   2810      * provide a stable layout for a clean transition.
   2811      *
   2812      * <p>If you are using ActionBar in
   2813      * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY
   2814      * Window.FEATURE_ACTION_BAR_OVERLAY}, this flag will also impact the
   2815      * insets it adds to those given to the application.
   2816      */
   2817     public static final int SYSTEM_UI_FLAG_LAYOUT_STABLE = 0x00000100;
   2818 
   2819     /**
   2820      * Flag for {@link #setSystemUiVisibility(int)}: View would like its window
   2821      * to be laid out as if it has requested
   2822      * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, even if it currently hasn't.  This
   2823      * allows it to avoid artifacts when switching in and out of that mode, at
   2824      * the expense that some of its user interface may be covered by screen
   2825      * decorations when they are shown.  You can perform layout of your inner
   2826      * UI elements to account for the navigation system UI through the
   2827      * {@link #fitSystemWindows(Rect)} method.
   2828      */
   2829     public static final int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = 0x00000200;
   2830 
   2831     /**
   2832      * Flag for {@link #setSystemUiVisibility(int)}: View would like its window
   2833      * to be laid out as if it has requested
   2834      * {@link #SYSTEM_UI_FLAG_FULLSCREEN}, even if it currently hasn't.  This
   2835      * allows it to avoid artifacts when switching in and out of that mode, at
   2836      * the expense that some of its user interface may be covered by screen
   2837      * decorations when they are shown.  You can perform layout of your inner
   2838      * UI elements to account for non-fullscreen system UI through the
   2839      * {@link #fitSystemWindows(Rect)} method.
   2840      */
   2841     public static final int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 0x00000400;
   2842 
   2843     /**
   2844      * Flag for {@link #setSystemUiVisibility(int)}: View would like to remain interactive when
   2845      * hiding the navigation bar with {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}.  If this flag is
   2846      * not set, {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION} will be force cleared by the system on any
   2847      * user interaction.
   2848      * <p>Since this flag is a modifier for {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, it only
   2849      * has an effect when used in combination with that flag.</p>
   2850      */
   2851     public static final int SYSTEM_UI_FLAG_IMMERSIVE = 0x00000800;
   2852 
   2853     /**
   2854      * Flag for {@link #setSystemUiVisibility(int)}: View would like to remain interactive when
   2855      * hiding the status bar with {@link #SYSTEM_UI_FLAG_FULLSCREEN} and/or hiding the navigation
   2856      * bar with {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}.  Use this flag to create an immersive
   2857      * experience while also hiding the system bars.  If this flag is not set,
   2858      * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION} will be force cleared by the system on any user
   2859      * interaction, and {@link #SYSTEM_UI_FLAG_FULLSCREEN} will be force-cleared by the system
   2860      * if the user swipes from the top of the screen.
   2861      * <p>When system bars are hidden in immersive mode, they can be revealed temporarily with
   2862      * system gestures, such as swiping from the top of the screen.  These transient system bars
   2863      * will overlay apps content, may have some degree of transparency, and will automatically
   2864      * hide after a short timeout.
   2865      * </p><p>Since this flag is a modifier for {@link #SYSTEM_UI_FLAG_FULLSCREEN} and
   2866      * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, it only has an effect when used in combination
   2867      * with one or both of those flags.</p>
   2868      */
   2869     public static final int SYSTEM_UI_FLAG_IMMERSIVE_STICKY = 0x00001000;
   2870 
   2871     /**
   2872      * Flag for {@link #setSystemUiVisibility(int)}: Requests the status bar to draw in a mode that
   2873      * is compatible with light status bar backgrounds.
   2874      *
   2875      * <p>For this to take effect, the window must request
   2876      * {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
   2877      *         FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} but not
   2878      * {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_STATUS
   2879      *         FLAG_TRANSLUCENT_STATUS}.
   2880      *
   2881      * @see android.R.attr#windowLightStatusBar
   2882      */
   2883     public static final int SYSTEM_UI_FLAG_LIGHT_STATUS_BAR = 0x00002000;
   2884 
   2885     /**
   2886      * @deprecated Use {@link #SYSTEM_UI_FLAG_LOW_PROFILE} instead.
   2887      */
   2888     public static final int STATUS_BAR_HIDDEN = SYSTEM_UI_FLAG_LOW_PROFILE;
   2889 
   2890     /**
   2891      * @deprecated Use {@link #SYSTEM_UI_FLAG_VISIBLE} instead.
   2892      */
   2893     public static final int STATUS_BAR_VISIBLE = SYSTEM_UI_FLAG_VISIBLE;
   2894 
   2895     /**
   2896      * @hide
   2897      *
   2898      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   2899      * out of the public fields to keep the undefined bits out of the developer's way.
   2900      *
   2901      * Flag to make the status bar not expandable.  Unless you also
   2902      * set {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show.
   2903      */
   2904     public static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000;
   2905 
   2906     /**
   2907      * @hide
   2908      *
   2909      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   2910      * out of the public fields to keep the undefined bits out of the developer's way.
   2911      *
   2912      * Flag to hide notification icons and scrolling ticker text.
   2913      */
   2914     public static final int STATUS_BAR_DISABLE_NOTIFICATION_ICONS = 0x00020000;
   2915 
   2916     /**
   2917      * @hide
   2918      *
   2919      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   2920      * out of the public fields to keep the undefined bits out of the developer's way.
   2921      *
   2922      * Flag to disable incoming notification alerts.  This will not block
   2923      * icons, but it will block sound, vibrating and other visual or aural notifications.
   2924      */
   2925     public static final int STATUS_BAR_DISABLE_NOTIFICATION_ALERTS = 0x00040000;
   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 hide only the scrolling ticker.  Note that
   2934      * {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS} implies
   2935      * {@link #STATUS_BAR_DISABLE_NOTIFICATION_TICKER}.
   2936      */
   2937     public static final int STATUS_BAR_DISABLE_NOTIFICATION_TICKER = 0x00080000;
   2938 
   2939     /**
   2940      * @hide
   2941      *
   2942      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   2943      * out of the public fields to keep the undefined bits out of the developer's way.
   2944      *
   2945      * Flag to hide the center system info area.
   2946      */
   2947     public static final int STATUS_BAR_DISABLE_SYSTEM_INFO = 0x00100000;
   2948 
   2949     /**
   2950      * @hide
   2951      *
   2952      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   2953      * out of the public fields to keep the undefined bits out of the developer's way.
   2954      *
   2955      * Flag to hide only the home button.  Don't use this
   2956      * unless you're a special part of the system UI (i.e., setup wizard, keyguard).
   2957      */
   2958     public static final int STATUS_BAR_DISABLE_HOME = 0x00200000;
   2959 
   2960     /**
   2961      * @hide
   2962      *
   2963      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   2964      * out of the public fields to keep the undefined bits out of the developer's way.
   2965      *
   2966      * Flag to hide only the back button. Don't use this
   2967      * unless you're a special part of the system UI (i.e., setup wizard, keyguard).
   2968      */
   2969     public static final int STATUS_BAR_DISABLE_BACK = 0x00400000;
   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 only the clock.  You might use this if your activity has
   2978      * its own clock making the status bar's clock redundant.
   2979      */
   2980     public static final int STATUS_BAR_DISABLE_CLOCK = 0x00800000;
   2981 
   2982     /**
   2983      * @hide
   2984      *
   2985      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   2986      * out of the public fields to keep the undefined bits out of the developer's way.
   2987      *
   2988      * Flag to hide only the recent apps button. Don't use this
   2989      * unless you're a special part of the system UI (i.e., setup wizard, keyguard).
   2990      */
   2991     public static final int STATUS_BAR_DISABLE_RECENT = 0x01000000;
   2992 
   2993     /**
   2994      * @hide
   2995      *
   2996      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   2997      * out of the public fields to keep the undefined bits out of the developer's way.
   2998      *
   2999      * Flag to disable the global search gesture. Don't use this
   3000      * unless you're a special part of the system UI (i.e., setup wizard, keyguard).
   3001      */
   3002     public static final int STATUS_BAR_DISABLE_SEARCH = 0x02000000;
   3003 
   3004     /**
   3005      * @hide
   3006      *
   3007      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   3008      * out of the public fields to keep the undefined bits out of the developer's way.
   3009      *
   3010      * Flag to specify that the status bar is displayed in transient mode.
   3011      */
   3012     public static final int STATUS_BAR_TRANSIENT = 0x04000000;
   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 specify that the navigation bar is displayed in transient mode.
   3021      */
   3022     public static final int NAVIGATION_BAR_TRANSIENT = 0x08000000;
   3023 
   3024     /**
   3025      * @hide
   3026      *
   3027      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   3028      * out of the public fields to keep the undefined bits out of the developer's way.
   3029      *
   3030      * Flag to specify that the hidden status bar would like to be shown.
   3031      */
   3032     public static final int STATUS_BAR_UNHIDE = 0x10000000;
   3033 
   3034     /**
   3035      * @hide
   3036      *
   3037      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   3038      * out of the public fields to keep the undefined bits out of the developer's way.
   3039      *
   3040      * Flag to specify that the hidden navigation bar would like to be shown.
   3041      */
   3042     public static final int NAVIGATION_BAR_UNHIDE = 0x20000000;
   3043 
   3044     /**
   3045      * @hide
   3046      *
   3047      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   3048      * out of the public fields to keep the undefined bits out of the developer's way.
   3049      *
   3050      * Flag to specify that the status bar is displayed in translucent mode.
   3051      */
   3052     public static final int STATUS_BAR_TRANSLUCENT = 0x40000000;
   3053 
   3054     /**
   3055      * @hide
   3056      *
   3057      * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
   3058      * out of the public fields to keep the undefined bits out of the developer's way.
   3059      *
   3060      * Flag to specify that the navigation bar is displayed in translucent mode.
   3061      */
   3062     public static final int NAVIGATION_BAR_TRANSLUCENT = 0x80000000;
   3063 
   3064     /**
   3065      * @hide
   3066      *
   3067      * Whether Recents is visible or not.
   3068      */
   3069     public static final int RECENT_APPS_VISIBLE = 0x00004000;
   3070 
   3071     /**
   3072      * @hide
   3073      *
   3074      * Whether the TV's picture-in-picture is visible or not.
   3075      */
   3076     public static final int TV_PICTURE_IN_PICTURE_VISIBLE = 0x00010000;
   3077 
   3078     /**
   3079      * @hide
   3080      *
   3081      * Makes navigation bar transparent (but not the status bar).
   3082      */
   3083     public static final int NAVIGATION_BAR_TRANSPARENT = 0x00008000;
   3084 
   3085     /**
   3086      * @hide
   3087      *
   3088      * Makes status bar transparent (but not the navigation bar).
   3089      */
   3090     public static final int STATUS_BAR_TRANSPARENT = 0x0000008;
   3091 
   3092     /**
   3093      * @hide
   3094      *
   3095      * Makes both status bar and navigation bar transparent.
   3096      */
   3097     public static final int SYSTEM_UI_TRANSPARENT = NAVIGATION_BAR_TRANSPARENT
   3098             | STATUS_BAR_TRANSPARENT;
   3099 
   3100     /**
   3101      * @hide
   3102      */
   3103     public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK = 0x00003FF7;
   3104 
   3105     /**
   3106      * These are the system UI flags that can be cleared by events outside
   3107      * of an application.  Currently this is just the ability to tap on the
   3108      * screen while hiding the navigation bar to have it return.
   3109      * @hide
   3110      */
   3111     public static final int SYSTEM_UI_CLEARABLE_FLAGS =
   3112             SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_HIDE_NAVIGATION
   3113             | SYSTEM_UI_FLAG_FULLSCREEN;
   3114 
   3115     /**
   3116      * Flags that can impact the layout in relation to system UI.
   3117      */
   3118     public static final int SYSTEM_UI_LAYOUT_FLAGS =
   3119             SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
   3120             | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
   3121 
   3122     /** @hide */
   3123     @IntDef(flag = true,
   3124             value = { FIND_VIEWS_WITH_TEXT, FIND_VIEWS_WITH_CONTENT_DESCRIPTION })
   3125     @Retention(RetentionPolicy.SOURCE)
   3126     public @interface FindViewFlags {}
   3127 
   3128     /**
   3129      * Find views that render the specified text.
   3130      *
   3131      * @see #findViewsWithText(ArrayList, CharSequence, int)
   3132      */
   3133     public static final int FIND_VIEWS_WITH_TEXT = 0x00000001;
   3134 
   3135     /**
   3136      * Find find views that contain the specified content description.
   3137      *
   3138      * @see #findViewsWithText(ArrayList, CharSequence, int)
   3139      */
   3140     public static final int FIND_VIEWS_WITH_CONTENT_DESCRIPTION = 0x00000002;
   3141 
   3142     /**
   3143      * Find views that contain {@link AccessibilityNodeProvider}. Such
   3144      * a View is a root of virtual view hierarchy and may contain the searched
   3145      * text. If this flag is set Views with providers are automatically
   3146      * added and it is a responsibility of the client to call the APIs of
   3147      * the provider to determine whether the virtual tree rooted at this View
   3148      * contains the text, i.e. getting the list of {@link AccessibilityNodeInfo}s
   3149      * representing the virtual views with this text.
   3150      *
   3151      * @see #findViewsWithText(ArrayList, CharSequence, int)
   3152      *
   3153      * @hide
   3154      */
   3155     public static final int FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS = 0x00000004;
   3156 
   3157     /**
   3158      * The undefined cursor position.
   3159      *
   3160      * @hide
   3161      */
   3162     public static final int ACCESSIBILITY_CURSOR_POSITION_UNDEFINED = -1;
   3163 
   3164     /**
   3165      * Indicates that the screen has changed state and is now off.
   3166      *
   3167      * @see #onScreenStateChanged(int)
   3168      */
   3169     public static final int SCREEN_STATE_OFF = 0x0;
   3170 
   3171     /**
   3172      * Indicates that the screen has changed state and is now on.
   3173      *
   3174      * @see #onScreenStateChanged(int)
   3175      */
   3176     public static final int SCREEN_STATE_ON = 0x1;
   3177 
   3178     /**
   3179      * Indicates no axis of view scrolling.
   3180      */
   3181     public static final int SCROLL_AXIS_NONE = 0;
   3182 
   3183     /**
   3184      * Indicates scrolling along the horizontal axis.
   3185      */
   3186     public static final int SCROLL_AXIS_HORIZONTAL = 1 << 0;
   3187 
   3188     /**
   3189      * Indicates scrolling along the vertical axis.
   3190      */
   3191     public static final int SCROLL_AXIS_VERTICAL = 1 << 1;
   3192 
   3193     /**
   3194      * Controls the over-scroll mode for this view.
   3195      * See {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)},
   3196      * {@link #OVER_SCROLL_ALWAYS}, {@link #OVER_SCROLL_IF_CONTENT_SCROLLS},
   3197      * and {@link #OVER_SCROLL_NEVER}.
   3198      */
   3199     private int mOverScrollMode;
   3200 
   3201     /**
   3202      * The parent this view is attached to.
   3203      * {@hide}
   3204      *
   3205      * @see #getParent()
   3206      */
   3207     protected ViewParent mParent;
   3208 
   3209     /**
   3210      * {@hide}
   3211      */
   3212     AttachInfo mAttachInfo;
   3213 
   3214     /**
   3215      * {@hide}
   3216      */
   3217     @ViewDebug.ExportedProperty(flagMapping = {
   3218         @ViewDebug.FlagToString(mask = PFLAG_FORCE_LAYOUT, equals = PFLAG_FORCE_LAYOUT,
   3219                 name = "FORCE_LAYOUT"),
   3220         @ViewDebug.FlagToString(mask = PFLAG_LAYOUT_REQUIRED, equals = PFLAG_LAYOUT_REQUIRED,
   3221                 name = "LAYOUT_REQUIRED"),
   3222         @ViewDebug.FlagToString(mask = PFLAG_DRAWING_CACHE_VALID, equals = PFLAG_DRAWING_CACHE_VALID,
   3223             name = "DRAWING_CACHE_INVALID", outputIf = false),
   3224         @ViewDebug.FlagToString(mask = PFLAG_DRAWN, equals = PFLAG_DRAWN, name = "DRAWN", outputIf = true),
   3225         @ViewDebug.FlagToString(mask = PFLAG_DRAWN, equals = PFLAG_DRAWN, name = "NOT_DRAWN", outputIf = false),
   3226         @ViewDebug.FlagToString(mask = PFLAG_DIRTY_MASK, equals = PFLAG_DIRTY_OPAQUE, name = "DIRTY_OPAQUE"),
   3227         @ViewDebug.FlagToString(mask = PFLAG_DIRTY_MASK, equals = PFLAG_DIRTY, name = "DIRTY")
   3228     }, formatToHexString = true)
   3229     int mPrivateFlags;
   3230     int mPrivateFlags2;
   3231     int mPrivateFlags3;
   3232 
   3233     /**
   3234      * This view's request for the visibility of the status bar.
   3235      * @hide
   3236      */
   3237     @ViewDebug.ExportedProperty(flagMapping = {
   3238         @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_LOW_PROFILE,
   3239                                 equals = SYSTEM_UI_FLAG_LOW_PROFILE,
   3240                                 name = "SYSTEM_UI_FLAG_LOW_PROFILE", outputIf = true),
   3241         @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_HIDE_NAVIGATION,
   3242                                 equals = SYSTEM_UI_FLAG_HIDE_NAVIGATION,
   3243                                 name = "SYSTEM_UI_FLAG_HIDE_NAVIGATION", outputIf = true),
   3244         @ViewDebug.FlagToString(mask = PUBLIC_STATUS_BAR_VISIBILITY_MASK,
   3245                                 equals = SYSTEM_UI_FLAG_VISIBLE,
   3246                                 name = "SYSTEM_UI_FLAG_VISIBLE", outputIf = true)
   3247     }, formatToHexString = true)
   3248     int mSystemUiVisibility;
   3249 
   3250     /**
   3251      * Reference count for transient state.
   3252      * @see #setHasTransientState(boolean)
   3253      */
   3254     int mTransientStateCount = 0;
   3255 
   3256     /**
   3257      * Count of how many windows this view has been attached to.
   3258      */
   3259     int mWindowAttachCount;
   3260 
   3261     /**
   3262      * The layout parameters associated with this view and used by the parent
   3263      * {@link android.view.ViewGroup} to determine how this view should be
   3264      * laid out.
   3265      * {@hide}
   3266      */
   3267     protected ViewGroup.LayoutParams mLayoutParams;
   3268 
   3269     /**
   3270      * The view flags hold various views states.
   3271      * {@hide}
   3272      */
   3273     @ViewDebug.ExportedProperty(formatToHexString = true)
   3274     int mViewFlags;
   3275 
   3276     static class TransformationInfo {
   3277         /**
   3278          * The transform matrix for the View. This transform is calculated internally
   3279          * based on the translation, rotation, and scale properties.
   3280          *
   3281          * Do *not* use this variable directly; instead call getMatrix(), which will
   3282          * load the value from the View's RenderNode.
   3283          */
   3284         private final Matrix mMatrix = new Matrix();
   3285 
   3286         /**
   3287          * The inverse transform matrix for the View. This transform is calculated
   3288          * internally based on the translation, rotation, and scale properties.
   3289          *
   3290          * Do *not* use this variable directly; instead call getInverseMatrix(),
   3291          * which will load the value from the View's RenderNode.
   3292          */
   3293         private Matrix mInverseMatrix;
   3294 
   3295         /**
   3296          * The opacity of the View. This is a value from 0 to 1, where 0 means
   3297          * completely transparent and 1 means completely opaque.
   3298          */
   3299         @ViewDebug.ExportedProperty
   3300         float mAlpha = 1f;
   3301 
   3302         /**
   3303          * The opacity of the view as manipulated by the Fade transition. This is a hidden
   3304          * property only used by transitions, which is composited with the other alpha
   3305          * values to calculate the final visual alpha value.
   3306          */
   3307         float mTransitionAlpha = 1f;
   3308     }
   3309 
   3310     TransformationInfo mTransformationInfo;
   3311 
   3312     /**
   3313      * Current clip bounds. to which all drawing of this view are constrained.
   3314      */
   3315     Rect mClipBounds = null;
   3316 
   3317     private boolean mLastIsOpaque;
   3318 
   3319     /**
   3320      * The distance in pixels from the left edge of this view's parent
   3321      * to the left edge of this view.
   3322      * {@hide}
   3323      */
   3324     @ViewDebug.ExportedProperty(category = "layout")
   3325     protected int mLeft;
   3326     /**
   3327      * The distance in pixels from the left edge of this view's parent
   3328      * to the right edge of this view.
   3329      * {@hide}
   3330      */
   3331     @ViewDebug.ExportedProperty(category = "layout")
   3332     protected int mRight;
   3333     /**
   3334      * The distance in pixels from the top edge of this view's parent
   3335      * to the top edge of this view.
   3336      * {@hide}
   3337      */
   3338     @ViewDebug.ExportedProperty(category = "layout")
   3339     protected int mTop;
   3340     /**
   3341      * The distance in pixels from the top edge of this view's parent
   3342      * to the bottom edge of this view.
   3343      * {@hide}
   3344      */
   3345     @ViewDebug.ExportedProperty(category = "layout")
   3346     protected int mBottom;
   3347 
   3348     /**
   3349      * The offset, in pixels, by which the content of this view is scrolled
   3350      * horizontally.
   3351      * {@hide}
   3352      */
   3353     @ViewDebug.ExportedProperty(category = "scrolling")
   3354     protected int mScrollX;
   3355     /**
   3356      * The offset, in pixels, by which the content of this view is scrolled
   3357      * vertically.
   3358      * {@hide}
   3359      */
   3360     @ViewDebug.ExportedProperty(category = "scrolling")
   3361     protected int mScrollY;
   3362 
   3363     /**
   3364      * The left padding in pixels, that is the distance in pixels between the
   3365      * left edge of this view and the left edge of its content.
   3366      * {@hide}
   3367      */
   3368     @ViewDebug.ExportedProperty(category = "padding")
   3369     protected int mPaddingLeft = 0;
   3370     /**
   3371      * The right padding in pixels, that is the distance in pixels between the
   3372      * right edge of this view and the right edge of its content.
   3373      * {@hide}
   3374      */
   3375     @ViewDebug.ExportedProperty(category = "padding")
   3376     protected int mPaddingRight = 0;
   3377     /**
   3378      * The top padding in pixels, that is the distance in pixels between the
   3379      * top edge of this view and the top edge of its content.
   3380      * {@hide}
   3381      */
   3382     @ViewDebug.ExportedProperty(category = "padding")
   3383     protected int mPaddingTop;
   3384     /**
   3385      * The bottom padding in pixels, that is the distance in pixels between the
   3386      * bottom edge of this view and the bottom edge of its content.
   3387      * {@hide}
   3388      */
   3389     @ViewDebug.ExportedProperty(category = "padding")
   3390     protected int mPaddingBottom;
   3391 
   3392     /**
   3393      * The layout insets in pixels, that is the distance in pixels between the
   3394      * visible edges of this view its bounds.
   3395      */
   3396     private Insets mLayoutInsets;
   3397 
   3398     /**
   3399      * Briefly describes the view and is primarily used for accessibility support.
   3400      */
   3401     private CharSequence mContentDescription;
   3402 
   3403     /**
   3404      * Specifies the id of a view for which this view serves as a label for
   3405      * accessibility purposes.
   3406      */
   3407     private int mLabelForId = View.NO_ID;
   3408 
   3409     /**
   3410      * Predicate for matching labeled view id with its label for
   3411      * accessibility purposes.
   3412      */
   3413     private MatchLabelForPredicate mMatchLabelForPredicate;
   3414 
   3415     /**
   3416      * Specifies a view before which this one is visited in accessibility traversal.
   3417      */
   3418     private int mAccessibilityTraversalBeforeId = NO_ID;
   3419 
   3420     /**
   3421      * Specifies a view after which this one is visited in accessibility traversal.
   3422      */
   3423     private int mAccessibilityTraversalAfterId = NO_ID;
   3424 
   3425     /**
   3426      * Predicate for matching a view by its id.
   3427      */
   3428     private MatchIdPredicate mMatchIdPredicate;
   3429 
   3430     /**
   3431      * Cache the paddingRight set by the user to append to the scrollbar's size.
   3432      *
   3433      * @hide
   3434      */
   3435     @ViewDebug.ExportedProperty(category = "padding")
   3436     protected int mUserPaddingRight;
   3437 
   3438     /**
   3439      * Cache the paddingBottom set by the user to append to the scrollbar's size.
   3440      *
   3441      * @hide
   3442      */
   3443     @ViewDebug.ExportedProperty(category = "padding")
   3444     protected int mUserPaddingBottom;
   3445 
   3446     /**
   3447      * Cache the paddingLeft set by the user to append to the scrollbar's size.
   3448      *
   3449      * @hide
   3450      */
   3451     @ViewDebug.ExportedProperty(category = "padding")
   3452     protected int mUserPaddingLeft;
   3453 
   3454     /**
   3455      * Cache the paddingStart set by the user to append to the scrollbar's size.
   3456      *
   3457      */
   3458     @ViewDebug.ExportedProperty(category = "padding")
   3459     int mUserPaddingStart;
   3460 
   3461     /**
   3462      * Cache the paddingEnd set by the user to append to the scrollbar's size.
   3463      *
   3464      */
   3465     @ViewDebug.ExportedProperty(category = "padding")
   3466     int mUserPaddingEnd;
   3467 
   3468     /**
   3469      * Cache initial left padding.
   3470      *
   3471      * @hide
   3472      */
   3473     int mUserPaddingLeftInitial;
   3474 
   3475     /**
   3476      * Cache initial right padding.
   3477      *
   3478      * @hide
   3479      */
   3480     int mUserPaddingRightInitial;
   3481 
   3482     /**
   3483      * Default undefined padding
   3484      */
   3485     private static final int UNDEFINED_PADDING = Integer.MIN_VALUE;
   3486 
   3487     /**
   3488      * Cache if a left padding has been defined
   3489      */
   3490     private boolean mLeftPaddingDefined = false;
   3491 
   3492     /**
   3493      * Cache if a right padding has been defined
   3494      */
   3495     private boolean mRightPaddingDefined = false;
   3496 
   3497     /**
   3498      * @hide
   3499      */
   3500     int mOldWidthMeasureSpec = Integer.MIN_VALUE;
   3501     /**
   3502      * @hide
   3503      */
   3504     int mOldHeightMeasureSpec = Integer.MIN_VALUE;
   3505 
   3506     private LongSparseLongArray mMeasureCache;
   3507 
   3508     @ViewDebug.ExportedProperty(deepExport = true, prefix = "bg_")
   3509     private Drawable mBackground;
   3510     private TintInfo mBackgroundTint;
   3511 
   3512     @ViewDebug.ExportedProperty(deepExport = true, prefix = "fg_")
   3513     private ForegroundInfo mForegroundInfo;
   3514 
   3515     private Drawable mScrollIndicatorDrawable;
   3516 
   3517     /**
   3518      * RenderNode used for backgrounds.
   3519      * <p>
   3520      * When non-null and valid, this is expected to contain an up-to-date copy
   3521      * of the background drawable. It is cleared on temporary detach, and reset
   3522      * on cleanup.
   3523      */
   3524     private RenderNode mBackgroundRenderNode;
   3525 
   3526     private int mBackgroundResource;
   3527     private boolean mBackgroundSizeChanged;
   3528 
   3529     private String mTransitionName;
   3530 
   3531     static class TintInfo {
   3532         ColorStateList mTintList;
   3533         PorterDuff.Mode mTintMode;
   3534         boolean mHasTintMode;
   3535         boolean mHasTintList;
   3536     }
   3537 
   3538     private static class ForegroundInfo {
   3539         private Drawable mDrawable;
   3540         private TintInfo mTintInfo;
   3541         private int mGravity = Gravity.FILL;
   3542         private boolean mInsidePadding = true;
   3543         private boolean mBoundsChanged = true;
   3544         private final Rect mSelfBounds = new Rect();
   3545         private final Rect mOverlayBounds = new Rect();
   3546     }
   3547 
   3548     static class ListenerInfo {
   3549         /**
   3550          * Listener used to dispatch focus change events.
   3551          * This field should be made private, so it is hidden from the SDK.
   3552          * {@hide}
   3553          */
   3554         protected OnFocusChangeListener mOnFocusChangeListener;
   3555 
   3556         /**
   3557          * Listeners for layout change events.
   3558          */
   3559         private ArrayList<OnLayoutChangeListener> mOnLayoutChangeListeners;
   3560 
   3561         protected OnScrollChangeListener mOnScrollChangeListener;
   3562 
   3563         /**
   3564          * Listeners for attach events.
   3565          */
   3566         private CopyOnWriteArrayList<OnAttachStateChangeListener> mOnAttachStateChangeListeners;
   3567 
   3568         /**
   3569          * Listener used to dispatch click events.
   3570          * This field should be made private, so it is hidden from the SDK.
   3571          * {@hide}
   3572          */
   3573         public OnClickListener mOnClickListener;
   3574 
   3575         /**
   3576          * Listener used to dispatch long click events.
   3577          * This field should be made private, so it is hidden from the SDK.
   3578          * {@hide}
   3579          */
   3580         protected OnLongClickListener mOnLongClickListener;
   3581 
   3582         /**
   3583          * Listener used to dispatch context click events. This field should be made private, so it
   3584          * is hidden from the SDK.
   3585          * {@hide}
   3586          */
   3587         protected OnContextClickListener mOnContextClickListener;
   3588 
   3589         /**
   3590          * Listener used to build the context menu.
   3591          * This field should be made private, so it is hidden from the SDK.
   3592          * {@hide}
   3593          */
   3594         protected OnCreateContextMenuListener mOnCreateContextMenuListener;
   3595 
   3596         private OnKeyListener mOnKeyListener;
   3597 
   3598         private OnTouchListener mOnTouchListener;
   3599 
   3600         private OnHoverListener mOnHoverListener;
   3601 
   3602         private OnGenericMotionListener mOnGenericMotionListener;
   3603 
   3604         private OnDragListener mOnDragListener;
   3605 
   3606         private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener;
   3607 
   3608         OnApplyWindowInsetsListener mOnApplyWindowInsetsListener;
   3609     }
   3610 
   3611     ListenerInfo mListenerInfo;
   3612 
   3613     // Temporary values used to hold (x,y) coordinates when delegating from the
   3614     // two-arg performLongClick() method to the legacy no-arg version.
   3615     private float mLongClickX = Float.NaN;
   3616     private float mLongClickY = Float.NaN;
   3617 
   3618     /**
   3619      * The application environment this view lives in.
   3620      * This field should be made private, so it is hidden from the SDK.
   3621      * {@hide}
   3622      */
   3623     @ViewDebug.ExportedProperty(deepExport = true)
   3624     protected Context mContext;
   3625 
   3626     private final Resources mResources;
   3627 
   3628     private ScrollabilityCache mScrollCache;
   3629 
   3630     private int[] mDrawableState = null;
   3631 
   3632     ViewOutlineProvider mOutlineProvider = ViewOutlineProvider.BACKGROUND;
   3633 
   3634     /**
   3635      * Animator that automatically runs based on state changes.
   3636      */
   3637     private StateListAnimator mStateListAnimator;
   3638 
   3639     /**
   3640      * When this view has focus and the next focus is {@link #FOCUS_LEFT},
   3641      * the user may specify which view to go to next.
   3642      */
   3643     private int mNextFocusLeftId = View.NO_ID;
   3644 
   3645     /**
   3646      * When this view has focus and the next focus is {@link #FOCUS_RIGHT},
   3647      * the user may specify which view to go to next.
   3648      */
   3649     private int mNextFocusRightId = View.NO_ID;
   3650 
   3651     /**
   3652      * When this view has focus and the next focus is {@link #FOCUS_UP},
   3653      * the user may specify which view to go to next.
   3654      */
   3655     private int mNextFocusUpId = View.NO_ID;
   3656 
   3657     /**
   3658      * When this view has focus and the next focus is {@link #FOCUS_DOWN},
   3659      * the user may specify which view to go to next.
   3660      */
   3661     private int