The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 19 | import android.content.ClipData; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 21 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.res.Resources; |
| 23 | import android.content.res.TypedArray; |
| 24 | import android.graphics.Bitmap; |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 25 | import android.graphics.Camera; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.graphics.Canvas; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 27 | import android.graphics.Interpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.graphics.LinearGradient; |
| 29 | import android.graphics.Matrix; |
| 30 | import android.graphics.Paint; |
| 31 | import android.graphics.PixelFormat; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 32 | import android.graphics.Point; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.graphics.PorterDuff; |
| 34 | import android.graphics.PorterDuffXfermode; |
| 35 | import android.graphics.Rect; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 36 | import android.graphics.RectF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.graphics.Region; |
| 38 | import android.graphics.Shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.graphics.drawable.ColorDrawable; |
| 40 | import android.graphics.drawable.Drawable; |
| 41 | import android.os.Handler; |
| 42 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | import android.os.Parcel; |
| 44 | import android.os.Parcelable; |
| 45 | import android.os.RemoteException; |
| 46 | import android.os.SystemClock; |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 47 | import android.text.TextUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.util.AttributeSet; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 49 | import android.util.FloatProperty; |
| 50 | import android.util.LocaleUtil; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.util.Log; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 52 | import android.util.Pool; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 53 | import android.util.Poolable; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 54 | import android.util.PoolableManager; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 55 | import android.util.Pools; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 56 | import android.util.Property; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 57 | import android.util.SparseArray; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 58 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.view.ContextMenu.ContextMenuInfo; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 60 | import android.view.accessibility.AccessibilityEvent; |
| 61 | import android.view.accessibility.AccessibilityEventSource; |
| 62 | import android.view.accessibility.AccessibilityManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 63 | import android.view.accessibility.AccessibilityNodeInfo; |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 64 | import android.view.accessibility.AccessibilityNodeProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.view.animation.Animation; |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 66 | import android.view.animation.AnimationUtils; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 67 | import android.view.animation.Transformation; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 68 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.view.inputmethod.InputConnection; |
| 70 | import android.view.inputmethod.InputMethodManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.widget.ScrollBarDrawable; |
| 72 | |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 73 | import static android.os.Build.VERSION_CODES.*; |
| 74 | |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 75 | import com.android.internal.R; |
| 76 | import com.android.internal.util.Predicate; |
| 77 | import com.android.internal.view.menu.MenuBuilder; |
| 78 | |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 79 | import java.lang.ref.WeakReference; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 80 | import java.lang.reflect.InvocationTargetException; |
| 81 | import java.lang.reflect.Method; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import java.util.ArrayList; |
| 83 | import java.util.Arrays; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 84 | import java.util.Locale; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 85 | import java.util.concurrent.CopyOnWriteArrayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * <p> |
| 89 | * This class represents the basic building block for user interface components. A View |
| 90 | * occupies a rectangular area on the screen and is responsible for drawing and |
| 91 | * event handling. View is the base class for <em>widgets</em>, which are |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 92 | * used to create interactive UI components (buttons, text fields, etc.). The |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | * {@link android.view.ViewGroup} subclass is the base class for <em>layouts</em>, which |
| 94 | * are invisible containers that hold other Views (or other ViewGroups) and define |
| 95 | * their layout properties. |
| 96 | * </p> |
| 97 | * |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 98 | * <div class="special reference"> |
| 99 | * <h3>Developer Guides</h3> |
| 100 | * <p>For information about using this class to develop your application's user interface, |
| 101 | * read the <a href="{@docRoot}guide/topics/ui/index.html">User Interface</a> developer guide. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | * </div> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 103 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | * <a name="Using"></a> |
| 105 | * <h3>Using Views</h3> |
| 106 | * <p> |
| 107 | * All of the views in a window are arranged in a single tree. You can add views |
| 108 | * either from code or by specifying a tree of views in one or more XML layout |
| 109 | * files. There are many specialized subclasses of views that act as controls or |
| 110 | * are capable of displaying text, images, or other content. |
| 111 | * </p> |
| 112 | * <p> |
| 113 | * Once you have created a tree of views, there are typically a few types of |
| 114 | * common operations you may wish to perform: |
| 115 | * <ul> |
| 116 | * <li><strong>Set properties:</strong> for example setting the text of a |
| 117 | * {@link android.widget.TextView}. The available properties and the methods |
| 118 | * that set them will vary among the different subclasses of views. Note that |
| 119 | * properties that are known at build time can be set in the XML layout |
| 120 | * files.</li> |
| 121 | * <li><strong>Set focus:</strong> The framework will handled moving focus in |
| 122 | * response to user input. To force focus to a specific view, call |
| 123 | * {@link #requestFocus}.</li> |
| 124 | * <li><strong>Set up listeners:</strong> Views allow clients to set listeners |
| 125 | * that will be notified when something interesting happens to the view. For |
| 126 | * example, all views will let you set a listener to be notified when the view |
| 127 | * gains or loses focus. You can register such a listener using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 128 | * {@link #setOnFocusChangeListener(android.view.View.OnFocusChangeListener)}. |
| 129 | * Other view subclasses offer more specialized listeners. For example, a Button |
| 130 | * exposes a listener to notify clients when the button is clicked.</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | * <li><strong>Set visibility:</strong> You can hide or show views using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 132 | * {@link #setVisibility(int)}.</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | * </ul> |
| 134 | * </p> |
| 135 | * <p><em> |
| 136 | * Note: The Android framework is responsible for measuring, laying out and |
| 137 | * drawing views. You should not call methods that perform these actions on |
| 138 | * views yourself unless you are actually implementing a |
| 139 | * {@link android.view.ViewGroup}. |
| 140 | * </em></p> |
| 141 | * |
| 142 | * <a name="Lifecycle"></a> |
| 143 | * <h3>Implementing a Custom View</h3> |
| 144 | * |
| 145 | * <p> |
| 146 | * To implement a custom view, you will usually begin by providing overrides for |
| 147 | * some of the standard methods that the framework calls on all views. You do |
| 148 | * not need to override all of these methods. In fact, you can start by just |
| 149 | * overriding {@link #onDraw(android.graphics.Canvas)}. |
| 150 | * <table border="2" width="85%" align="center" cellpadding="5"> |
| 151 | * <thead> |
| 152 | * <tr><th>Category</th> <th>Methods</th> <th>Description</th></tr> |
| 153 | * </thead> |
| 154 | * |
| 155 | * <tbody> |
| 156 | * <tr> |
| 157 | * <td rowspan="2">Creation</td> |
| 158 | * <td>Constructors</td> |
| 159 | * <td>There is a form of the constructor that are called when the view |
| 160 | * is created from code and a form that is called when the view is |
| 161 | * inflated from a layout file. The second form should parse and apply |
| 162 | * any attributes defined in the layout file. |
| 163 | * </td> |
| 164 | * </tr> |
| 165 | * <tr> |
| 166 | * <td><code>{@link #onFinishInflate()}</code></td> |
| 167 | * <td>Called after a view and all of its children has been inflated |
| 168 | * from XML.</td> |
| 169 | * </tr> |
| 170 | * |
| 171 | * <tr> |
| 172 | * <td rowspan="3">Layout</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 173 | * <td><code>{@link #onMeasure(int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | * <td>Called to determine the size requirements for this view and all |
| 175 | * of its children. |
| 176 | * </td> |
| 177 | * </tr> |
| 178 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 179 | * <td><code>{@link #onLayout(boolean, int, int, int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | * <td>Called when this view should assign a size and position to all |
| 181 | * of its children. |
| 182 | * </td> |
| 183 | * </tr> |
| 184 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 185 | * <td><code>{@link #onSizeChanged(int, int, int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | * <td>Called when the size of this view has changed. |
| 187 | * </td> |
| 188 | * </tr> |
| 189 | * |
| 190 | * <tr> |
| 191 | * <td>Drawing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 192 | * <td><code>{@link #onDraw(android.graphics.Canvas)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | * <td>Called when the view should render its content. |
| 194 | * </td> |
| 195 | * </tr> |
| 196 | * |
| 197 | * <tr> |
| 198 | * <td rowspan="4">Event processing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 199 | * <td><code>{@link #onKeyDown(int, KeyEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | * <td>Called when a new key event occurs. |
| 201 | * </td> |
| 202 | * </tr> |
| 203 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 204 | * <td><code>{@link #onKeyUp(int, KeyEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | * <td>Called when a key up event occurs. |
| 206 | * </td> |
| 207 | * </tr> |
| 208 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 209 | * <td><code>{@link #onTrackballEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | * <td>Called when a trackball motion event occurs. |
| 211 | * </td> |
| 212 | * </tr> |
| 213 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 214 | * <td><code>{@link #onTouchEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | * <td>Called when a touch screen motion event occurs. |
| 216 | * </td> |
| 217 | * </tr> |
| 218 | * |
| 219 | * <tr> |
| 220 | * <td rowspan="2">Focus</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 221 | * <td><code>{@link #onFocusChanged(boolean, int, android.graphics.Rect)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | * <td>Called when the view gains or loses focus. |
| 223 | * </td> |
| 224 | * </tr> |
| 225 | * |
| 226 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 227 | * <td><code>{@link #onWindowFocusChanged(boolean)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | * <td>Called when the window containing the view gains or loses focus. |
| 229 | * </td> |
| 230 | * </tr> |
| 231 | * |
| 232 | * <tr> |
| 233 | * <td rowspan="3">Attaching</td> |
| 234 | * <td><code>{@link #onAttachedToWindow()}</code></td> |
| 235 | * <td>Called when the view is attached to a window. |
| 236 | * </td> |
| 237 | * </tr> |
| 238 | * |
| 239 | * <tr> |
| 240 | * <td><code>{@link #onDetachedFromWindow}</code></td> |
| 241 | * <td>Called when the view is detached from its window. |
| 242 | * </td> |
| 243 | * </tr> |
| 244 | * |
| 245 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 246 | * <td><code>{@link #onWindowVisibilityChanged(int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | * <td>Called when the visibility of the window containing the view |
| 248 | * has changed. |
| 249 | * </td> |
| 250 | * </tr> |
| 251 | * </tbody> |
| 252 | * |
| 253 | * </table> |
| 254 | * </p> |
| 255 | * |
| 256 | * <a name="IDs"></a> |
| 257 | * <h3>IDs</h3> |
| 258 | * Views may have an integer id associated with them. These ids are typically |
| 259 | * assigned in the layout XML files, and are used to find specific views within |
| 260 | * the view tree. A common pattern is to: |
| 261 | * <ul> |
| 262 | * <li>Define a Button in the layout file and assign it a unique ID. |
| 263 | * <pre> |
Gilles Debunne | 0243caf | 2010-08-24 23:06:35 -0700 | [diff] [blame] | 264 | * <Button |
| 265 | * android:id="@+id/my_button" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | * android:layout_width="wrap_content" |
| 267 | * android:layout_height="wrap_content" |
| 268 | * android:text="@string/my_button_text"/> |
| 269 | * </pre></li> |
| 270 | * <li>From the onCreate method of an Activity, find the Button |
| 271 | * <pre class="prettyprint"> |
| 272 | * Button myButton = (Button) findViewById(R.id.my_button); |
| 273 | * </pre></li> |
| 274 | * </ul> |
| 275 | * <p> |
| 276 | * View IDs need not be unique throughout the tree, but it is good practice to |
| 277 | * ensure that they are at least unique within the part of the tree you are |
| 278 | * searching. |
| 279 | * </p> |
| 280 | * |
| 281 | * <a name="Position"></a> |
| 282 | * <h3>Position</h3> |
| 283 | * <p> |
| 284 | * The geometry of a view is that of a rectangle. A view has a location, |
| 285 | * expressed as a pair of <em>left</em> and <em>top</em> coordinates, and |
| 286 | * two dimensions, expressed as a width and a height. The unit for location |
| 287 | * and dimensions is the pixel. |
| 288 | * </p> |
| 289 | * |
| 290 | * <p> |
| 291 | * It is possible to retrieve the location of a view by invoking the methods |
| 292 | * {@link #getLeft()} and {@link #getTop()}. The former returns the left, or X, |
| 293 | * coordinate of the rectangle representing the view. The latter returns the |
| 294 | * top, or Y, coordinate of the rectangle representing the view. These methods |
| 295 | * both return the location of the view relative to its parent. For instance, |
| 296 | * when getLeft() returns 20, that means the view is located 20 pixels to the |
| 297 | * right of the left edge of its direct parent. |
| 298 | * </p> |
| 299 | * |
| 300 | * <p> |
| 301 | * In addition, several convenience methods are offered to avoid unnecessary |
| 302 | * computations, namely {@link #getRight()} and {@link #getBottom()}. |
| 303 | * These methods return the coordinates of the right and bottom edges of the |
| 304 | * rectangle representing the view. For instance, calling {@link #getRight()} |
| 305 | * is similar to the following computation: <code>getLeft() + getWidth()</code> |
| 306 | * (see <a href="#SizePaddingMargins">Size</a> for more information about the width.) |
| 307 | * </p> |
| 308 | * |
| 309 | * <a name="SizePaddingMargins"></a> |
| 310 | * <h3>Size, padding and margins</h3> |
| 311 | * <p> |
| 312 | * The size of a view is expressed with a width and a height. A view actually |
| 313 | * possess two pairs of width and height values. |
| 314 | * </p> |
| 315 | * |
| 316 | * <p> |
| 317 | * The first pair is known as <em>measured width</em> and |
| 318 | * <em>measured height</em>. These dimensions define how big a view wants to be |
| 319 | * within its parent (see <a href="#Layout">Layout</a> for more details.) The |
| 320 | * measured dimensions can be obtained by calling {@link #getMeasuredWidth()} |
| 321 | * and {@link #getMeasuredHeight()}. |
| 322 | * </p> |
| 323 | * |
| 324 | * <p> |
| 325 | * The second pair is simply known as <em>width</em> and <em>height</em>, or |
| 326 | * sometimes <em>drawing width</em> and <em>drawing height</em>. These |
| 327 | * dimensions define the actual size of the view on screen, at drawing time and |
| 328 | * after layout. These values may, but do not have to, be different from the |
| 329 | * measured width and height. The width and height can be obtained by calling |
| 330 | * {@link #getWidth()} and {@link #getHeight()}. |
| 331 | * </p> |
| 332 | * |
| 333 | * <p> |
| 334 | * To measure its dimensions, a view takes into account its padding. The padding |
| 335 | * is expressed in pixels for the left, top, right and bottom parts of the view. |
| 336 | * Padding can be used to offset the content of the view by a specific amount of |
| 337 | * pixels. For instance, a left padding of 2 will push the view's content by |
| 338 | * 2 pixels to the right of the left edge. Padding can be set using the |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 339 | * {@link #setPadding(int, int, int, int)} or {@link #setPaddingRelative(int, int, int, int)} |
| 340 | * method and queried by calling {@link #getPaddingLeft()}, {@link #getPaddingTop()}, |
| 341 | * {@link #getPaddingRight()}, {@link #getPaddingBottom()}, {@link #getPaddingStart()}, |
| 342 | * {@link #getPaddingEnd()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | * </p> |
| 344 | * |
| 345 | * <p> |
| 346 | * Even though a view can define a padding, it does not provide any support for |
| 347 | * margins. However, view groups provide such a support. Refer to |
| 348 | * {@link android.view.ViewGroup} and |
| 349 | * {@link android.view.ViewGroup.MarginLayoutParams} for further information. |
| 350 | * </p> |
| 351 | * |
| 352 | * <a name="Layout"></a> |
| 353 | * <h3>Layout</h3> |
| 354 | * <p> |
| 355 | * Layout is a two pass process: a measure pass and a layout pass. The measuring |
| 356 | * pass is implemented in {@link #measure(int, int)} and is a top-down traversal |
| 357 | * of the view tree. Each view pushes dimension specifications down the tree |
| 358 | * during the recursion. At the end of the measure pass, every view has stored |
| 359 | * its measurements. The second pass happens in |
| 360 | * {@link #layout(int,int,int,int)} and is also top-down. During |
| 361 | * this pass each parent is responsible for positioning all of its children |
| 362 | * using the sizes computed in the measure pass. |
| 363 | * </p> |
| 364 | * |
| 365 | * <p> |
| 366 | * When a view's measure() method returns, its {@link #getMeasuredWidth()} and |
| 367 | * {@link #getMeasuredHeight()} values must be set, along with those for all of |
| 368 | * that view's descendants. A view's measured width and measured height values |
| 369 | * must respect the constraints imposed by the view's parents. This guarantees |
| 370 | * that at the end of the measure pass, all parents accept all of their |
| 371 | * children's measurements. A parent view may call measure() more than once on |
| 372 | * its children. For example, the parent may measure each child once with |
| 373 | * unspecified dimensions to find out how big they want to be, then call |
| 374 | * measure() on them again with actual numbers if the sum of all the children's |
| 375 | * unconstrained sizes is too big or too small. |
| 376 | * </p> |
| 377 | * |
| 378 | * <p> |
| 379 | * The measure pass uses two classes to communicate dimensions. The |
| 380 | * {@link MeasureSpec} class is used by views to tell their parents how they |
| 381 | * want to be measured and positioned. The base LayoutParams class just |
| 382 | * describes how big the view wants to be for both width and height. For each |
| 383 | * dimension, it can specify one of: |
| 384 | * <ul> |
| 385 | * <li> an exact number |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 386 | * <li>MATCH_PARENT, which means the view wants to be as big as its parent |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 387 | * (minus padding) |
| 388 | * <li> WRAP_CONTENT, which means that the view wants to be just big enough to |
| 389 | * enclose its content (plus padding). |
| 390 | * </ul> |
| 391 | * There are subclasses of LayoutParams for different subclasses of ViewGroup. |
| 392 | * For example, AbsoluteLayout has its own subclass of LayoutParams which adds |
| 393 | * an X and Y value. |
| 394 | * </p> |
| 395 | * |
| 396 | * <p> |
| 397 | * MeasureSpecs are used to push requirements down the tree from parent to |
| 398 | * child. A MeasureSpec can be in one of three modes: |
| 399 | * <ul> |
| 400 | * <li>UNSPECIFIED: This is used by a parent to determine the desired dimension |
| 401 | * of a child view. For example, a LinearLayout may call measure() on its child |
| 402 | * with the height set to UNSPECIFIED and a width of EXACTLY 240 to find out how |
| 403 | * tall the child view wants to be given a width of 240 pixels. |
| 404 | * <li>EXACTLY: This is used by the parent to impose an exact size on the |
| 405 | * child. The child must use this size, and guarantee that all of its |
| 406 | * descendants will fit within this size. |
| 407 | * <li>AT_MOST: This is used by the parent to impose a maximum size on the |
| 408 | * child. The child must gurantee that it and all of its descendants will fit |
| 409 | * within this size. |
| 410 | * </ul> |
| 411 | * </p> |
| 412 | * |
| 413 | * <p> |
| 414 | * To intiate a layout, call {@link #requestLayout}. This method is typically |
| 415 | * called by a view on itself when it believes that is can no longer fit within |
| 416 | * its current bounds. |
| 417 | * </p> |
| 418 | * |
| 419 | * <a name="Drawing"></a> |
| 420 | * <h3>Drawing</h3> |
| 421 | * <p> |
| 422 | * Drawing is handled by walking the tree and rendering each view that |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 423 | * intersects the invalid region. Because the tree is traversed in-order, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | * this means that parents will draw before (i.e., behind) their children, with |
| 425 | * siblings drawn in the order they appear in the tree. |
| 426 | * If you set a background drawable for a View, then the View will draw it for you |
| 427 | * before calling back to its <code>onDraw()</code> method. |
| 428 | * </p> |
| 429 | * |
| 430 | * <p> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 431 | * Note that the framework will not draw views that are not in the invalid region. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | * </p> |
| 433 | * |
| 434 | * <p> |
| 435 | * To force a view to draw, call {@link #invalidate()}. |
| 436 | * </p> |
| 437 | * |
| 438 | * <a name="EventHandlingThreading"></a> |
| 439 | * <h3>Event Handling and Threading</h3> |
| 440 | * <p> |
| 441 | * The basic cycle of a view is as follows: |
| 442 | * <ol> |
| 443 | * <li>An event comes in and is dispatched to the appropriate view. The view |
| 444 | * handles the event and notifies any listeners.</li> |
| 445 | * <li>If in the course of processing the event, the view's bounds may need |
| 446 | * to be changed, the view will call {@link #requestLayout()}.</li> |
| 447 | * <li>Similarly, if in the course of processing the event the view's appearance |
| 448 | * may need to be changed, the view will call {@link #invalidate()}.</li> |
| 449 | * <li>If either {@link #requestLayout()} or {@link #invalidate()} were called, |
| 450 | * the framework will take care of measuring, laying out, and drawing the tree |
| 451 | * as appropriate.</li> |
| 452 | * </ol> |
| 453 | * </p> |
| 454 | * |
| 455 | * <p><em>Note: The entire view tree is single threaded. You must always be on |
| 456 | * the UI thread when calling any method on any view.</em> |
| 457 | * If you are doing work on other threads and want to update the state of a view |
| 458 | * from that thread, you should use a {@link Handler}. |
| 459 | * </p> |
| 460 | * |
| 461 | * <a name="FocusHandling"></a> |
| 462 | * <h3>Focus Handling</h3> |
| 463 | * <p> |
| 464 | * The framework will handle routine focus movement in response to user input. |
| 465 | * This includes changing the focus as views are removed or hidden, or as new |
| 466 | * views become available. Views indicate their willingness to take focus |
| 467 | * through the {@link #isFocusable} method. To change whether a view can take |
| 468 | * focus, call {@link #setFocusable(boolean)}. When in touch mode (see notes below) |
| 469 | * views indicate whether they still would like focus via {@link #isFocusableInTouchMode} |
| 470 | * and can change this via {@link #setFocusableInTouchMode(boolean)}. |
| 471 | * </p> |
| 472 | * <p> |
| 473 | * Focus movement is based on an algorithm which finds the nearest neighbor in a |
| 474 | * given direction. In rare cases, the default algorithm may not match the |
| 475 | * intended behavior of the developer. In these situations, you can provide |
| 476 | * explicit overrides by using these XML attributes in the layout file: |
| 477 | * <pre> |
| 478 | * nextFocusDown |
| 479 | * nextFocusLeft |
| 480 | * nextFocusRight |
| 481 | * nextFocusUp |
| 482 | * </pre> |
| 483 | * </p> |
| 484 | * |
| 485 | * |
| 486 | * <p> |
| 487 | * To get a particular view to take focus, call {@link #requestFocus()}. |
| 488 | * </p> |
| 489 | * |
| 490 | * <a name="TouchMode"></a> |
| 491 | * <h3>Touch Mode</h3> |
| 492 | * <p> |
| 493 | * When a user is navigating a user interface via directional keys such as a D-pad, it is |
| 494 | * necessary to give focus to actionable items such as buttons so the user can see |
| 495 | * what will take input. If the device has touch capabilities, however, and the user |
| 496 | * begins interacting with the interface by touching it, it is no longer necessary to |
| 497 | * always highlight, or give focus to, a particular view. This motivates a mode |
| 498 | * for interaction named 'touch mode'. |
| 499 | * </p> |
| 500 | * <p> |
| 501 | * For a touch capable device, once the user touches the screen, the device |
| 502 | * will enter touch mode. From this point onward, only views for which |
| 503 | * {@link #isFocusableInTouchMode} is true will be focusable, such as text editing widgets. |
| 504 | * Other views that are touchable, like buttons, will not take focus when touched; they will |
| 505 | * only fire the on click listeners. |
| 506 | * </p> |
| 507 | * <p> |
| 508 | * Any time a user hits a directional key, such as a D-pad direction, the view device will |
| 509 | * exit touch mode, and find a view to take focus, so that the user may resume interacting |
| 510 | * with the user interface without touching the screen again. |
| 511 | * </p> |
| 512 | * <p> |
| 513 | * The touch mode state is maintained across {@link android.app.Activity}s. Call |
| 514 | * {@link #isInTouchMode} to see whether the device is currently in touch mode. |
| 515 | * </p> |
| 516 | * |
| 517 | * <a name="Scrolling"></a> |
| 518 | * <h3>Scrolling</h3> |
| 519 | * <p> |
| 520 | * The framework provides basic support for views that wish to internally |
| 521 | * scroll their content. This includes keeping track of the X and Y scroll |
| 522 | * offset as well as mechanisms for drawing scrollbars. See |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 523 | * {@link #scrollBy(int, int)}, {@link #scrollTo(int, int)}, and |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 524 | * {@link #awakenScrollBars()} for more details. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 525 | * </p> |
| 526 | * |
| 527 | * <a name="Tags"></a> |
| 528 | * <h3>Tags</h3> |
| 529 | * <p> |
| 530 | * Unlike IDs, tags are not used to identify views. Tags are essentially an |
| 531 | * extra piece of information that can be associated with a view. They are most |
| 532 | * often used as a convenience to store data related to views in the views |
| 533 | * themselves rather than by putting them in a separate structure. |
| 534 | * </p> |
| 535 | * |
| 536 | * <a name="Animation"></a> |
| 537 | * <h3>Animation</h3> |
| 538 | * <p> |
| 539 | * You can attach an {@link Animation} object to a view using |
| 540 | * {@link #setAnimation(Animation)} or |
| 541 | * {@link #startAnimation(Animation)}. The animation can alter the scale, |
| 542 | * rotation, translation and alpha of a view over time. If the animation is |
| 543 | * attached to a view that has children, the animation will affect the entire |
| 544 | * subtree rooted by that node. When an animation is started, the framework will |
| 545 | * take care of redrawing the appropriate views until the animation completes. |
| 546 | * </p> |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 547 | * <p> |
| 548 | * Starting with Android 3.0, the preferred way of animating views is to use the |
| 549 | * {@link android.animation} package APIs. |
| 550 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 552 | * <a name="Security"></a> |
| 553 | * <h3>Security</h3> |
| 554 | * <p> |
| 555 | * Sometimes it is essential that an application be able to verify that an action |
| 556 | * is being performed with the full knowledge and consent of the user, such as |
| 557 | * granting a permission request, making a purchase or clicking on an advertisement. |
| 558 | * Unfortunately, a malicious application could try to spoof the user into |
| 559 | * performing these actions, unaware, by concealing the intended purpose of the view. |
| 560 | * As a remedy, the framework offers a touch filtering mechanism that can be used to |
| 561 | * improve the security of views that provide access to sensitive functionality. |
| 562 | * </p><p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 563 | * To enable touch filtering, call {@link #setFilterTouchesWhenObscured(boolean)} or set the |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 564 | * android:filterTouchesWhenObscured layout attribute to true. When enabled, the framework |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 565 | * will discard touches that are received whenever the view's window is obscured by |
| 566 | * another visible window. As a result, the view will not receive touches whenever a |
| 567 | * toast, dialog or other window appears above the view's window. |
| 568 | * </p><p> |
| 569 | * For more fine-grained control over security, consider overriding the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 570 | * {@link #onFilterTouchEventForSecurity(MotionEvent)} method to implement your own |
| 571 | * security policy. See also {@link MotionEvent#FLAG_WINDOW_IS_OBSCURED}. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 572 | * </p> |
| 573 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 574 | * @attr ref android.R.styleable#View_alpha |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 575 | * @attr ref android.R.styleable#View_background |
| 576 | * @attr ref android.R.styleable#View_clickable |
| 577 | * @attr ref android.R.styleable#View_contentDescription |
| 578 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 579 | * @attr ref android.R.styleable#View_duplicateParentState |
| 580 | * @attr ref android.R.styleable#View_id |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 581 | * @attr ref android.R.styleable#View_requiresFadingEdge |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 582 | * @attr ref android.R.styleable#View_fadingEdgeLength |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 583 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 585 | * @attr ref android.R.styleable#View_isScrollContainer |
| 586 | * @attr ref android.R.styleable#View_focusable |
| 587 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 588 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 589 | * @attr ref android.R.styleable#View_keepScreenOn |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 590 | * @attr ref android.R.styleable#View_layerType |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 591 | * @attr ref android.R.styleable#View_longClickable |
| 592 | * @attr ref android.R.styleable#View_minHeight |
| 593 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | * @attr ref android.R.styleable#View_nextFocusDown |
| 595 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 596 | * @attr ref android.R.styleable#View_nextFocusRight |
| 597 | * @attr ref android.R.styleable#View_nextFocusUp |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 598 | * @attr ref android.R.styleable#View_onClick |
| 599 | * @attr ref android.R.styleable#View_padding |
| 600 | * @attr ref android.R.styleable#View_paddingBottom |
| 601 | * @attr ref android.R.styleable#View_paddingLeft |
| 602 | * @attr ref android.R.styleable#View_paddingRight |
| 603 | * @attr ref android.R.styleable#View_paddingTop |
Fabrice Di Meglio | 101d5aa | 2012-02-16 18:36:06 -0800 | [diff] [blame] | 604 | * @attr ref android.R.styleable#View_paddingStart |
| 605 | * @attr ref android.R.styleable#View_paddingEnd |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 606 | * @attr ref android.R.styleable#View_saveEnabled |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 607 | * @attr ref android.R.styleable#View_rotation |
| 608 | * @attr ref android.R.styleable#View_rotationX |
| 609 | * @attr ref android.R.styleable#View_rotationY |
| 610 | * @attr ref android.R.styleable#View_scaleX |
| 611 | * @attr ref android.R.styleable#View_scaleY |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | * @attr ref android.R.styleable#View_scrollX |
| 613 | * @attr ref android.R.styleable#View_scrollY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 614 | * @attr ref android.R.styleable#View_scrollbarSize |
| 615 | * @attr ref android.R.styleable#View_scrollbarStyle |
| 616 | * @attr ref android.R.styleable#View_scrollbars |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 617 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 618 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | * @attr ref android.R.styleable#View_scrollbarTrackHorizontal |
| 620 | * @attr ref android.R.styleable#View_scrollbarThumbHorizontal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | * @attr ref android.R.styleable#View_scrollbarThumbVertical |
| 622 | * @attr ref android.R.styleable#View_scrollbarTrackVertical |
| 623 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawHorizontalTrack |
| 624 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawVerticalTrack |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 625 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 626 | * @attr ref android.R.styleable#View_tag |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 627 | * @attr ref android.R.styleable#View_transformPivotX |
| 628 | * @attr ref android.R.styleable#View_transformPivotY |
| 629 | * @attr ref android.R.styleable#View_translationX |
| 630 | * @attr ref android.R.styleable#View_translationY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 631 | * @attr ref android.R.styleable#View_visibility |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | * |
| 633 | * @see android.view.ViewGroup |
| 634 | */ |
Adam Powell | 8fc54f9 | 2011-09-07 16:40:45 -0700 | [diff] [blame] | 635 | public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Callback, |
| 636 | AccessibilityEventSource { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 637 | private static final boolean DBG = false; |
| 638 | |
| 639 | /** |
| 640 | * The logging tag used by this class with android.util.Log. |
| 641 | */ |
| 642 | protected static final String VIEW_LOG_TAG = "View"; |
| 643 | |
| 644 | /** |
| 645 | * Used to mark a View that has no ID. |
| 646 | */ |
| 647 | public static final int NO_ID = -1; |
| 648 | |
| 649 | /** |
| 650 | * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when |
| 651 | * calling setFlags. |
| 652 | */ |
| 653 | private static final int NOT_FOCUSABLE = 0x00000000; |
| 654 | |
| 655 | /** |
| 656 | * This view wants keystrokes. Use with TAKES_FOCUS_MASK when calling |
| 657 | * setFlags. |
| 658 | */ |
| 659 | private static final int FOCUSABLE = 0x00000001; |
| 660 | |
| 661 | /** |
| 662 | * Mask for use with setFlags indicating bits used for focus. |
| 663 | */ |
| 664 | private static final int FOCUSABLE_MASK = 0x00000001; |
| 665 | |
| 666 | /** |
| 667 | * This view will adjust its padding to fit sytem windows (e.g. status bar) |
| 668 | */ |
| 669 | private static final int FITS_SYSTEM_WINDOWS = 0x00000002; |
| 670 | |
| 671 | /** |
Scott Main | 812634c2 | 2011-07-27 13:22:35 -0700 | [diff] [blame] | 672 | * This view is visible. |
| 673 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 674 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | */ |
| 676 | public static final int VISIBLE = 0x00000000; |
| 677 | |
| 678 | /** |
| 679 | * This view is invisible, but it still takes up space for layout purposes. |
Scott Main | 812634c2 | 2011-07-27 13:22:35 -0700 | [diff] [blame] | 680 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 681 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 682 | */ |
| 683 | public static final int INVISIBLE = 0x00000004; |
| 684 | |
| 685 | /** |
| 686 | * This view is invisible, and it doesn't take any space for layout |
Scott Main | 812634c2 | 2011-07-27 13:22:35 -0700 | [diff] [blame] | 687 | * purposes. Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 688 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 689 | */ |
| 690 | public static final int GONE = 0x00000008; |
| 691 | |
| 692 | /** |
| 693 | * Mask for use with setFlags indicating bits used for visibility. |
| 694 | * {@hide} |
| 695 | */ |
| 696 | static final int VISIBILITY_MASK = 0x0000000C; |
| 697 | |
| 698 | private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE}; |
| 699 | |
| 700 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 701 | * This view is enabled. Interpretation varies by subclass. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 702 | * Use with ENABLED_MASK when calling setFlags. |
| 703 | * {@hide} |
| 704 | */ |
| 705 | static final int ENABLED = 0x00000000; |
| 706 | |
| 707 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 708 | * This view is disabled. Interpretation varies by subclass. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 709 | * Use with ENABLED_MASK when calling setFlags. |
| 710 | * {@hide} |
| 711 | */ |
| 712 | static final int DISABLED = 0x00000020; |
| 713 | |
| 714 | /** |
| 715 | * Mask for use with setFlags indicating bits used for indicating whether |
| 716 | * this view is enabled |
| 717 | * {@hide} |
| 718 | */ |
| 719 | static final int ENABLED_MASK = 0x00000020; |
| 720 | |
| 721 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 722 | * This view won't draw. {@link #onDraw(android.graphics.Canvas)} won't be |
| 723 | * called and further optimizations will be performed. It is okay to have |
| 724 | * this flag set and a background. Use with DRAW_MASK when calling setFlags. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 725 | * {@hide} |
| 726 | */ |
| 727 | static final int WILL_NOT_DRAW = 0x00000080; |
| 728 | |
| 729 | /** |
| 730 | * Mask for use with setFlags indicating bits used for indicating whether |
| 731 | * this view is will draw |
| 732 | * {@hide} |
| 733 | */ |
| 734 | static final int DRAW_MASK = 0x00000080; |
| 735 | |
| 736 | /** |
| 737 | * <p>This view doesn't show scrollbars.</p> |
| 738 | * {@hide} |
| 739 | */ |
| 740 | static final int SCROLLBARS_NONE = 0x00000000; |
| 741 | |
| 742 | /** |
| 743 | * <p>This view shows horizontal scrollbars.</p> |
| 744 | * {@hide} |
| 745 | */ |
| 746 | static final int SCROLLBARS_HORIZONTAL = 0x00000100; |
| 747 | |
| 748 | /** |
| 749 | * <p>This view shows vertical scrollbars.</p> |
| 750 | * {@hide} |
| 751 | */ |
| 752 | static final int SCROLLBARS_VERTICAL = 0x00000200; |
| 753 | |
| 754 | /** |
| 755 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 756 | * scrollbars are enabled.</p> |
| 757 | * {@hide} |
| 758 | */ |
| 759 | static final int SCROLLBARS_MASK = 0x00000300; |
| 760 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 761 | /** |
| 762 | * Indicates that the view should filter touches when its window is obscured. |
| 763 | * Refer to the class comments for more information about this security feature. |
| 764 | * {@hide} |
| 765 | */ |
| 766 | static final int FILTER_TOUCHES_WHEN_OBSCURED = 0x00000400; |
| 767 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 768 | /** |
| 769 | * Set for framework elements that use FITS_SYSTEM_WINDOWS, to indicate |
| 770 | * that they are optional and should be skipped if the window has |
| 771 | * requested system UI flags that ignore those insets for layout. |
| 772 | */ |
| 773 | static final int OPTIONAL_FITS_SYSTEM_WINDOWS = 0x00000800; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 774 | |
| 775 | /** |
| 776 | * <p>This view doesn't show fading edges.</p> |
| 777 | * {@hide} |
| 778 | */ |
| 779 | static final int FADING_EDGE_NONE = 0x00000000; |
| 780 | |
| 781 | /** |
| 782 | * <p>This view shows horizontal fading edges.</p> |
| 783 | * {@hide} |
| 784 | */ |
| 785 | static final int FADING_EDGE_HORIZONTAL = 0x00001000; |
| 786 | |
| 787 | /** |
| 788 | * <p>This view shows vertical fading edges.</p> |
| 789 | * {@hide} |
| 790 | */ |
| 791 | static final int FADING_EDGE_VERTICAL = 0x00002000; |
| 792 | |
| 793 | /** |
| 794 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 795 | * fading edges are enabled.</p> |
| 796 | * {@hide} |
| 797 | */ |
| 798 | static final int FADING_EDGE_MASK = 0x00003000; |
| 799 | |
| 800 | /** |
| 801 | * <p>Indicates this view can be clicked. When clickable, a View reacts |
| 802 | * to clicks by notifying the OnClickListener.<p> |
| 803 | * {@hide} |
| 804 | */ |
| 805 | static final int CLICKABLE = 0x00004000; |
| 806 | |
| 807 | /** |
| 808 | * <p>Indicates this view is caching its drawing into a bitmap.</p> |
| 809 | * {@hide} |
| 810 | */ |
| 811 | static final int DRAWING_CACHE_ENABLED = 0x00008000; |
| 812 | |
| 813 | /** |
| 814 | * <p>Indicates that no icicle should be saved for this view.<p> |
| 815 | * {@hide} |
| 816 | */ |
| 817 | static final int SAVE_DISABLED = 0x000010000; |
| 818 | |
| 819 | /** |
| 820 | * <p>Mask for use with setFlags indicating bits used for the saveEnabled |
| 821 | * property.</p> |
| 822 | * {@hide} |
| 823 | */ |
| 824 | static final int SAVE_DISABLED_MASK = 0x000010000; |
| 825 | |
| 826 | /** |
| 827 | * <p>Indicates that no drawing cache should ever be created for this view.<p> |
| 828 | * {@hide} |
| 829 | */ |
| 830 | static final int WILL_NOT_CACHE_DRAWING = 0x000020000; |
| 831 | |
| 832 | /** |
| 833 | * <p>Indicates this view can take / keep focus when int touch mode.</p> |
| 834 | * {@hide} |
| 835 | */ |
| 836 | static final int FOCUSABLE_IN_TOUCH_MODE = 0x00040000; |
| 837 | |
| 838 | /** |
| 839 | * <p>Enables low quality mode for the drawing cache.</p> |
| 840 | */ |
| 841 | public static final int DRAWING_CACHE_QUALITY_LOW = 0x00080000; |
| 842 | |
| 843 | /** |
| 844 | * <p>Enables high quality mode for the drawing cache.</p> |
| 845 | */ |
| 846 | public static final int DRAWING_CACHE_QUALITY_HIGH = 0x00100000; |
| 847 | |
| 848 | /** |
| 849 | * <p>Enables automatic quality mode for the drawing cache.</p> |
| 850 | */ |
| 851 | public static final int DRAWING_CACHE_QUALITY_AUTO = 0x00000000; |
| 852 | |
| 853 | private static final int[] DRAWING_CACHE_QUALITY_FLAGS = { |
| 854 | DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_LOW, DRAWING_CACHE_QUALITY_HIGH |
| 855 | }; |
| 856 | |
| 857 | /** |
| 858 | * <p>Mask for use with setFlags indicating bits used for the cache |
| 859 | * quality property.</p> |
| 860 | * {@hide} |
| 861 | */ |
| 862 | static final int DRAWING_CACHE_QUALITY_MASK = 0x00180000; |
| 863 | |
| 864 | /** |
| 865 | * <p> |
| 866 | * Indicates this view can be long clicked. When long clickable, a View |
| 867 | * reacts to long clicks by notifying the OnLongClickListener or showing a |
| 868 | * context menu. |
| 869 | * </p> |
| 870 | * {@hide} |
| 871 | */ |
| 872 | static final int LONG_CLICKABLE = 0x00200000; |
| 873 | |
| 874 | /** |
| 875 | * <p>Indicates that this view gets its drawable states from its direct parent |
| 876 | * and ignores its original internal states.</p> |
| 877 | * |
| 878 | * @hide |
| 879 | */ |
| 880 | static final int DUPLICATE_PARENT_STATE = 0x00400000; |
| 881 | |
| 882 | /** |
| 883 | * The scrollbar style to display the scrollbars inside the content area, |
| 884 | * without increasing the padding. The scrollbars will be overlaid with |
| 885 | * translucency on the view's content. |
| 886 | */ |
| 887 | public static final int SCROLLBARS_INSIDE_OVERLAY = 0; |
| 888 | |
| 889 | /** |
| 890 | * The scrollbar style to display the scrollbars inside the padded area, |
| 891 | * increasing the padding of the view. The scrollbars will not overlap the |
| 892 | * content area of the view. |
| 893 | */ |
| 894 | public static final int SCROLLBARS_INSIDE_INSET = 0x01000000; |
| 895 | |
| 896 | /** |
| 897 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 898 | * without increasing the padding. The scrollbars will be overlaid with |
| 899 | * translucency. |
| 900 | */ |
| 901 | public static final int SCROLLBARS_OUTSIDE_OVERLAY = 0x02000000; |
| 902 | |
| 903 | /** |
| 904 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 905 | * increasing the padding of the view. The scrollbars will only overlap the |
| 906 | * background, if any. |
| 907 | */ |
| 908 | public static final int SCROLLBARS_OUTSIDE_INSET = 0x03000000; |
| 909 | |
| 910 | /** |
| 911 | * Mask to check if the scrollbar style is overlay or inset. |
| 912 | * {@hide} |
| 913 | */ |
| 914 | static final int SCROLLBARS_INSET_MASK = 0x01000000; |
| 915 | |
| 916 | /** |
| 917 | * Mask to check if the scrollbar style is inside or outside. |
| 918 | * {@hide} |
| 919 | */ |
| 920 | static final int SCROLLBARS_OUTSIDE_MASK = 0x02000000; |
| 921 | |
| 922 | /** |
| 923 | * Mask for scrollbar style. |
| 924 | * {@hide} |
| 925 | */ |
| 926 | static final int SCROLLBARS_STYLE_MASK = 0x03000000; |
| 927 | |
| 928 | /** |
| 929 | * View flag indicating that the screen should remain on while the |
| 930 | * window containing this view is visible to the user. This effectively |
| 931 | * takes care of automatically setting the WindowManager's |
| 932 | * {@link WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON}. |
| 933 | */ |
| 934 | public static final int KEEP_SCREEN_ON = 0x04000000; |
| 935 | |
| 936 | /** |
| 937 | * View flag indicating whether this view should have sound effects enabled |
| 938 | * for events such as clicking and touching. |
| 939 | */ |
| 940 | public static final int SOUND_EFFECTS_ENABLED = 0x08000000; |
| 941 | |
| 942 | /** |
| 943 | * View flag indicating whether this view should have haptic feedback |
| 944 | * enabled for events such as long presses. |
| 945 | */ |
| 946 | public static final int HAPTIC_FEEDBACK_ENABLED = 0x10000000; |
| 947 | |
| 948 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 949 | * <p>Indicates that the view hierarchy should stop saving state when |
| 950 | * it reaches this view. If state saving is initiated immediately at |
| 951 | * the view, it will be allowed. |
| 952 | * {@hide} |
| 953 | */ |
| 954 | static final int PARENT_SAVE_DISABLED = 0x20000000; |
| 955 | |
| 956 | /** |
| 957 | * <p>Mask for use with setFlags indicating bits used for PARENT_SAVE_DISABLED.</p> |
| 958 | * {@hide} |
| 959 | */ |
| 960 | static final int PARENT_SAVE_DISABLED_MASK = 0x20000000; |
| 961 | |
| 962 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 963 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 964 | * should add all focusable Views regardless if they are focusable in touch mode. |
| 965 | */ |
| 966 | public static final int FOCUSABLES_ALL = 0x00000000; |
| 967 | |
| 968 | /** |
| 969 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 970 | * should add only Views focusable in touch mode. |
| 971 | */ |
| 972 | public static final int FOCUSABLES_TOUCH_MODE = 0x00000001; |
| 973 | |
| 974 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 975 | * Use with {@link #focusSearch(int)}. Move focus to the previous selectable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 976 | * item. |
| 977 | */ |
| 978 | public static final int FOCUS_BACKWARD = 0x00000001; |
| 979 | |
| 980 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 981 | * Use with {@link #focusSearch(int)}. Move focus to the next selectable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 982 | * item. |
| 983 | */ |
| 984 | public static final int FOCUS_FORWARD = 0x00000002; |
| 985 | |
| 986 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 987 | * Use with {@link #focusSearch(int)}. Move focus to the left. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 988 | */ |
| 989 | public static final int FOCUS_LEFT = 0x00000011; |
| 990 | |
| 991 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 992 | * Use with {@link #focusSearch(int)}. Move focus up. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 993 | */ |
| 994 | public static final int FOCUS_UP = 0x00000021; |
| 995 | |
| 996 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 997 | * Use with {@link #focusSearch(int)}. Move focus to the right. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 998 | */ |
| 999 | public static final int FOCUS_RIGHT = 0x00000042; |
| 1000 | |
| 1001 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1002 | * Use with {@link #focusSearch(int)}. Move focus down. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | */ |
| 1004 | public static final int FOCUS_DOWN = 0x00000082; |
| 1005 | |
| 1006 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1007 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1008 | * {@link #getMeasuredWidthAndState()} that provide the actual measured size. |
| 1009 | */ |
| 1010 | public static final int MEASURED_SIZE_MASK = 0x00ffffff; |
| 1011 | |
| 1012 | /** |
| 1013 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1014 | * {@link #getMeasuredWidthAndState()} that provide the additional state bits. |
| 1015 | */ |
| 1016 | public static final int MEASURED_STATE_MASK = 0xff000000; |
| 1017 | |
| 1018 | /** |
| 1019 | * Bit shift of {@link #MEASURED_STATE_MASK} to get to the height bits |
| 1020 | * for functions that combine both width and height into a single int, |
| 1021 | * such as {@link #getMeasuredState()} and the childState argument of |
| 1022 | * {@link #resolveSizeAndState(int, int, int)}. |
| 1023 | */ |
| 1024 | public static final int MEASURED_HEIGHT_STATE_SHIFT = 16; |
| 1025 | |
| 1026 | /** |
| 1027 | * Bit of {@link #getMeasuredWidthAndState()} and |
| 1028 | * {@link #getMeasuredWidthAndState()} that indicates the measured size |
| 1029 | * is smaller that the space the view would like to have. |
| 1030 | */ |
| 1031 | public static final int MEASURED_STATE_TOO_SMALL = 0x01000000; |
| 1032 | |
| 1033 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1034 | * Base View state sets |
| 1035 | */ |
| 1036 | // Singles |
| 1037 | /** |
| 1038 | * Indicates the view has no states set. States are used with |
| 1039 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1040 | * view depending on its state. |
| 1041 | * |
| 1042 | * @see android.graphics.drawable.Drawable |
| 1043 | * @see #getDrawableState() |
| 1044 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1045 | protected static final int[] EMPTY_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | /** |
| 1047 | * Indicates the view is enabled. States are used with |
| 1048 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1049 | * view depending on its state. |
| 1050 | * |
| 1051 | * @see android.graphics.drawable.Drawable |
| 1052 | * @see #getDrawableState() |
| 1053 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1054 | protected static final int[] ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1055 | /** |
| 1056 | * Indicates the view is focused. States are used with |
| 1057 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1058 | * view depending on its state. |
| 1059 | * |
| 1060 | * @see android.graphics.drawable.Drawable |
| 1061 | * @see #getDrawableState() |
| 1062 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1063 | protected static final int[] FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1064 | /** |
| 1065 | * Indicates the view is selected. States are used with |
| 1066 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1067 | * view depending on its state. |
| 1068 | * |
| 1069 | * @see android.graphics.drawable.Drawable |
| 1070 | * @see #getDrawableState() |
| 1071 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1072 | protected static final int[] SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1073 | /** |
| 1074 | * Indicates the view is pressed. States are used with |
| 1075 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1076 | * view depending on its state. |
| 1077 | * |
| 1078 | * @see android.graphics.drawable.Drawable |
| 1079 | * @see #getDrawableState() |
| 1080 | * @hide |
| 1081 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1082 | protected static final int[] PRESSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1083 | /** |
| 1084 | * Indicates the view's window has focus. States are used with |
| 1085 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1086 | * view depending on its state. |
| 1087 | * |
| 1088 | * @see android.graphics.drawable.Drawable |
| 1089 | * @see #getDrawableState() |
| 1090 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1091 | protected static final int[] WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | // Doubles |
| 1093 | /** |
| 1094 | * Indicates the view is enabled and has the focus. |
| 1095 | * |
| 1096 | * @see #ENABLED_STATE_SET |
| 1097 | * @see #FOCUSED_STATE_SET |
| 1098 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1099 | protected static final int[] ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1100 | /** |
| 1101 | * Indicates the view is enabled and selected. |
| 1102 | * |
| 1103 | * @see #ENABLED_STATE_SET |
| 1104 | * @see #SELECTED_STATE_SET |
| 1105 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1106 | protected static final int[] ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1107 | /** |
| 1108 | * Indicates the view is enabled and that its window has focus. |
| 1109 | * |
| 1110 | * @see #ENABLED_STATE_SET |
| 1111 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1112 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1113 | protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1114 | /** |
| 1115 | * Indicates the view is focused and selected. |
| 1116 | * |
| 1117 | * @see #FOCUSED_STATE_SET |
| 1118 | * @see #SELECTED_STATE_SET |
| 1119 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1120 | protected static final int[] FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | /** |
| 1122 | * Indicates the view has the focus and that its window has the focus. |
| 1123 | * |
| 1124 | * @see #FOCUSED_STATE_SET |
| 1125 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1126 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1127 | protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | /** |
| 1129 | * Indicates the view is selected and that its window has the focus. |
| 1130 | * |
| 1131 | * @see #SELECTED_STATE_SET |
| 1132 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1133 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1134 | protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1135 | // Triples |
| 1136 | /** |
| 1137 | * Indicates the view is enabled, focused and selected. |
| 1138 | * |
| 1139 | * @see #ENABLED_STATE_SET |
| 1140 | * @see #FOCUSED_STATE_SET |
| 1141 | * @see #SELECTED_STATE_SET |
| 1142 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1143 | protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1144 | /** |
| 1145 | * Indicates the view is enabled, focused and its window has the focus. |
| 1146 | * |
| 1147 | * @see #ENABLED_STATE_SET |
| 1148 | * @see #FOCUSED_STATE_SET |
| 1149 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1150 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1151 | protected static final int[] ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1152 | /** |
| 1153 | * Indicates the view is enabled, selected and its window has the focus. |
| 1154 | * |
| 1155 | * @see #ENABLED_STATE_SET |
| 1156 | * @see #SELECTED_STATE_SET |
| 1157 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1158 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1159 | protected static final int[] ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | /** |
| 1161 | * Indicates the view is focused, selected and its window has the focus. |
| 1162 | * |
| 1163 | * @see #FOCUSED_STATE_SET |
| 1164 | * @see #SELECTED_STATE_SET |
| 1165 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1166 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1167 | protected static final int[] FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1168 | /** |
| 1169 | * Indicates the view is enabled, focused, selected and its window |
| 1170 | * has the focus. |
| 1171 | * |
| 1172 | * @see #ENABLED_STATE_SET |
| 1173 | * @see #FOCUSED_STATE_SET |
| 1174 | * @see #SELECTED_STATE_SET |
| 1175 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1176 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1177 | protected static final int[] ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1178 | /** |
| 1179 | * Indicates the view is pressed and its window has the focus. |
| 1180 | * |
| 1181 | * @see #PRESSED_STATE_SET |
| 1182 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1183 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1184 | protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1185 | /** |
| 1186 | * Indicates the view is pressed and selected. |
| 1187 | * |
| 1188 | * @see #PRESSED_STATE_SET |
| 1189 | * @see #SELECTED_STATE_SET |
| 1190 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1191 | protected static final int[] PRESSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | /** |
| 1193 | * Indicates the view is pressed, selected and its window has the focus. |
| 1194 | * |
| 1195 | * @see #PRESSED_STATE_SET |
| 1196 | * @see #SELECTED_STATE_SET |
| 1197 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1198 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1199 | protected static final int[] PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1200 | /** |
| 1201 | * Indicates the view is pressed and focused. |
| 1202 | * |
| 1203 | * @see #PRESSED_STATE_SET |
| 1204 | * @see #FOCUSED_STATE_SET |
| 1205 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1206 | protected static final int[] PRESSED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1207 | /** |
| 1208 | * Indicates the view is pressed, focused and its window has the focus. |
| 1209 | * |
| 1210 | * @see #PRESSED_STATE_SET |
| 1211 | * @see #FOCUSED_STATE_SET |
| 1212 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1213 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1214 | protected static final int[] PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1215 | /** |
| 1216 | * Indicates the view is pressed, focused and selected. |
| 1217 | * |
| 1218 | * @see #PRESSED_STATE_SET |
| 1219 | * @see #SELECTED_STATE_SET |
| 1220 | * @see #FOCUSED_STATE_SET |
| 1221 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1222 | protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1223 | /** |
| 1224 | * Indicates the view is pressed, focused, selected and its window has the focus. |
| 1225 | * |
| 1226 | * @see #PRESSED_STATE_SET |
| 1227 | * @see #FOCUSED_STATE_SET |
| 1228 | * @see #SELECTED_STATE_SET |
| 1229 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1230 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1231 | protected static final int[] PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | /** |
| 1233 | * Indicates the view is pressed and enabled. |
| 1234 | * |
| 1235 | * @see #PRESSED_STATE_SET |
| 1236 | * @see #ENABLED_STATE_SET |
| 1237 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1238 | protected static final int[] PRESSED_ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1239 | /** |
| 1240 | * Indicates the view is pressed, enabled and its window has the focus. |
| 1241 | * |
| 1242 | * @see #PRESSED_STATE_SET |
| 1243 | * @see #ENABLED_STATE_SET |
| 1244 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1245 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1246 | protected static final int[] PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1247 | /** |
| 1248 | * Indicates the view is pressed, enabled and selected. |
| 1249 | * |
| 1250 | * @see #PRESSED_STATE_SET |
| 1251 | * @see #ENABLED_STATE_SET |
| 1252 | * @see #SELECTED_STATE_SET |
| 1253 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1254 | protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1255 | /** |
| 1256 | * Indicates the view is pressed, enabled, selected and its window has the |
| 1257 | * focus. |
| 1258 | * |
| 1259 | * @see #PRESSED_STATE_SET |
| 1260 | * @see #ENABLED_STATE_SET |
| 1261 | * @see #SELECTED_STATE_SET |
| 1262 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1263 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1264 | protected static final int[] PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1265 | /** |
| 1266 | * Indicates the view is pressed, enabled and focused. |
| 1267 | * |
| 1268 | * @see #PRESSED_STATE_SET |
| 1269 | * @see #ENABLED_STATE_SET |
| 1270 | * @see #FOCUSED_STATE_SET |
| 1271 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1272 | protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1273 | /** |
| 1274 | * Indicates the view is pressed, enabled, focused and its window has the |
| 1275 | * focus. |
| 1276 | * |
| 1277 | * @see #PRESSED_STATE_SET |
| 1278 | * @see #ENABLED_STATE_SET |
| 1279 | * @see #FOCUSED_STATE_SET |
| 1280 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1281 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1282 | protected static final int[] PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1283 | /** |
| 1284 | * Indicates the view is pressed, enabled, focused and selected. |
| 1285 | * |
| 1286 | * @see #PRESSED_STATE_SET |
| 1287 | * @see #ENABLED_STATE_SET |
| 1288 | * @see #SELECTED_STATE_SET |
| 1289 | * @see #FOCUSED_STATE_SET |
| 1290 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1291 | protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1292 | /** |
| 1293 | * Indicates the view is pressed, enabled, focused, selected and its window |
| 1294 | * has the focus. |
| 1295 | * |
| 1296 | * @see #PRESSED_STATE_SET |
| 1297 | * @see #ENABLED_STATE_SET |
| 1298 | * @see #SELECTED_STATE_SET |
| 1299 | * @see #FOCUSED_STATE_SET |
| 1300 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1301 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1302 | protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1303 | |
| 1304 | /** |
| 1305 | * The order here is very important to {@link #getDrawableState()} |
| 1306 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1307 | private static final int[][] VIEW_STATE_SETS; |
| 1308 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1309 | static final int VIEW_STATE_WINDOW_FOCUSED = 1; |
| 1310 | static final int VIEW_STATE_SELECTED = 1 << 1; |
| 1311 | static final int VIEW_STATE_FOCUSED = 1 << 2; |
| 1312 | static final int VIEW_STATE_ENABLED = 1 << 3; |
| 1313 | static final int VIEW_STATE_PRESSED = 1 << 4; |
| 1314 | static final int VIEW_STATE_ACTIVATED = 1 << 5; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1315 | static final int VIEW_STATE_ACCELERATED = 1 << 6; |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1316 | static final int VIEW_STATE_HOVERED = 1 << 7; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1317 | static final int VIEW_STATE_DRAG_CAN_ACCEPT = 1 << 8; |
| 1318 | static final int VIEW_STATE_DRAG_HOVERED = 1 << 9; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1319 | |
| 1320 | static final int[] VIEW_STATE_IDS = new int[] { |
| 1321 | R.attr.state_window_focused, VIEW_STATE_WINDOW_FOCUSED, |
| 1322 | R.attr.state_selected, VIEW_STATE_SELECTED, |
| 1323 | R.attr.state_focused, VIEW_STATE_FOCUSED, |
| 1324 | R.attr.state_enabled, VIEW_STATE_ENABLED, |
| 1325 | R.attr.state_pressed, VIEW_STATE_PRESSED, |
| 1326 | R.attr.state_activated, VIEW_STATE_ACTIVATED, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1327 | R.attr.state_accelerated, VIEW_STATE_ACCELERATED, |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1328 | R.attr.state_hovered, VIEW_STATE_HOVERED, |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1329 | R.attr.state_drag_can_accept, VIEW_STATE_DRAG_CAN_ACCEPT, |
| 1330 | R.attr.state_drag_hovered, VIEW_STATE_DRAG_HOVERED, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1331 | }; |
| 1332 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1333 | static { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1334 | if ((VIEW_STATE_IDS.length/2) != R.styleable.ViewDrawableStates.length) { |
| 1335 | throw new IllegalStateException( |
| 1336 | "VIEW_STATE_IDs array length does not match ViewDrawableStates style array"); |
| 1337 | } |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1338 | int[] orderedIds = new int[VIEW_STATE_IDS.length]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1339 | for (int i = 0; i < R.styleable.ViewDrawableStates.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1340 | int viewState = R.styleable.ViewDrawableStates[i]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1341 | for (int j = 0; j<VIEW_STATE_IDS.length; j += 2) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1342 | if (VIEW_STATE_IDS[j] == viewState) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1343 | orderedIds[i * 2] = viewState; |
| 1344 | orderedIds[i * 2 + 1] = VIEW_STATE_IDS[j + 1]; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1345 | } |
| 1346 | } |
| 1347 | } |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1348 | final int NUM_BITS = VIEW_STATE_IDS.length / 2; |
| 1349 | VIEW_STATE_SETS = new int[1 << NUM_BITS][]; |
| 1350 | for (int i = 0; i < VIEW_STATE_SETS.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1351 | int numBits = Integer.bitCount(i); |
| 1352 | int[] set = new int[numBits]; |
| 1353 | int pos = 0; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1354 | for (int j = 0; j < orderedIds.length; j += 2) { |
| 1355 | if ((i & orderedIds[j+1]) != 0) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1356 | set[pos++] = orderedIds[j]; |
| 1357 | } |
| 1358 | } |
| 1359 | VIEW_STATE_SETS[i] = set; |
| 1360 | } |
| 1361 | |
| 1362 | EMPTY_STATE_SET = VIEW_STATE_SETS[0]; |
| 1363 | WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_WINDOW_FOCUSED]; |
| 1364 | SELECTED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_SELECTED]; |
| 1365 | SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1366 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED]; |
| 1367 | FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_FOCUSED]; |
| 1368 | FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1369 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED]; |
| 1370 | FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1371 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED]; |
| 1372 | FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1373 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1374 | | VIEW_STATE_FOCUSED]; |
| 1375 | ENABLED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_ENABLED]; |
| 1376 | ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1377 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED]; |
| 1378 | ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1379 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED]; |
| 1380 | ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1381 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1382 | | VIEW_STATE_ENABLED]; |
| 1383 | ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1384 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED]; |
| 1385 | ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1386 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1387 | | VIEW_STATE_ENABLED]; |
| 1388 | ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1389 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1390 | | VIEW_STATE_ENABLED]; |
| 1391 | ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1392 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1393 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED]; |
| 1394 | |
| 1395 | PRESSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_PRESSED]; |
| 1396 | PRESSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1397 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_PRESSED]; |
| 1398 | PRESSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1399 | VIEW_STATE_SELECTED | VIEW_STATE_PRESSED]; |
| 1400 | PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1401 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1402 | | VIEW_STATE_PRESSED]; |
| 1403 | PRESSED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1404 | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1405 | PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1406 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1407 | | VIEW_STATE_PRESSED]; |
| 1408 | PRESSED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1409 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1410 | | VIEW_STATE_PRESSED]; |
| 1411 | PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1412 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1413 | | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1414 | PRESSED_ENABLED_STATE_SET = VIEW_STATE_SETS[ |
| 1415 | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1416 | PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1417 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED |
| 1418 | | VIEW_STATE_PRESSED]; |
| 1419 | PRESSED_ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1420 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED |
| 1421 | | VIEW_STATE_PRESSED]; |
| 1422 | PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1423 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1424 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1425 | PRESSED_ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1426 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED |
| 1427 | | VIEW_STATE_PRESSED]; |
| 1428 | PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1429 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1430 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1431 | PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1432 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1433 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1434 | PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1435 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1436 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED |
| 1437 | | VIEW_STATE_PRESSED]; |
| 1438 | } |
| 1439 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1440 | /** |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1441 | * Accessibility event types that are dispatched for text population. |
| 1442 | */ |
| 1443 | private static final int POPULATING_ACCESSIBILITY_EVENT_TYPES = |
| 1444 | AccessibilityEvent.TYPE_VIEW_CLICKED |
| 1445 | | AccessibilityEvent.TYPE_VIEW_LONG_CLICKED |
| 1446 | | AccessibilityEvent.TYPE_VIEW_SELECTED |
| 1447 | | AccessibilityEvent.TYPE_VIEW_FOCUSED |
| 1448 | | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED |
| 1449 | | AccessibilityEvent.TYPE_VIEW_HOVER_ENTER |
Svetoslav Ganov | 9920f4f | 2011-10-07 18:39:11 -0700 | [diff] [blame] | 1450 | | AccessibilityEvent.TYPE_VIEW_HOVER_EXIT |
Svetoslav Ganov | 84dd52e | 2011-11-18 10:24:00 -0800 | [diff] [blame] | 1451 | | AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED |
| 1452 | | AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED; |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1453 | |
| 1454 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1455 | * Temporary Rect currently for use in setBackground(). This will probably |
| 1456 | * be extended in the future to hold our own class with more than just |
| 1457 | * a Rect. :) |
| 1458 | */ |
| 1459 | static final ThreadLocal<Rect> sThreadLocal = new ThreadLocal<Rect>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1460 | |
| 1461 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 1462 | * Temporary flag, used to enable processing of View properties in the native DisplayList |
| 1463 | * object instead of during draw(). Soon to be enabled by default for hardware-accelerated |
| 1464 | * apps. |
| 1465 | * @hide |
| 1466 | */ |
Chet Haase | 76240da | 2012-03-29 09:42:34 -0700 | [diff] [blame] | 1467 | public static final boolean USE_DISPLAY_LIST_PROPERTIES = false; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 1468 | |
| 1469 | /** |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1470 | * Map used to store views' tags. |
| 1471 | */ |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 1472 | private SparseArray<Object> mKeyedTags; |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1473 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1474 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1475 | * The next available accessiiblity id. |
| 1476 | */ |
| 1477 | private static int sNextAccessibilityViewId; |
| 1478 | |
| 1479 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1480 | * The animation currently associated with this view. |
| 1481 | * @hide |
| 1482 | */ |
| 1483 | protected Animation mCurrentAnimation = null; |
| 1484 | |
| 1485 | /** |
| 1486 | * Width as measured during measure pass. |
| 1487 | * {@hide} |
| 1488 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1489 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1490 | int mMeasuredWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1491 | |
| 1492 | /** |
| 1493 | * Height as measured during measure pass. |
| 1494 | * {@hide} |
| 1495 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1496 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1497 | int mMeasuredHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1498 | |
| 1499 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1500 | * Flag to indicate that this view was marked INVALIDATED, or had its display list |
| 1501 | * invalidated, prior to the current drawing iteration. If true, the view must re-draw |
| 1502 | * its display list. This flag, used only when hw accelerated, allows us to clear the |
| 1503 | * flag while retaining this information until it's needed (at getDisplayList() time and |
| 1504 | * in drawChild(), when we decide to draw a view's children's display lists into our own). |
| 1505 | * |
| 1506 | * {@hide} |
| 1507 | */ |
| 1508 | boolean mRecreateDisplayList = false; |
| 1509 | |
| 1510 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | * The view's identifier. |
| 1512 | * {@hide} |
| 1513 | * |
| 1514 | * @see #setId(int) |
| 1515 | * @see #getId() |
| 1516 | */ |
| 1517 | @ViewDebug.ExportedProperty(resolveId = true) |
| 1518 | int mID = NO_ID; |
| 1519 | |
| 1520 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 1521 | * The stable ID of this view for accessibility purposes. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1522 | */ |
| 1523 | int mAccessibilityViewId = NO_ID; |
| 1524 | |
| 1525 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1526 | * The view's tag. |
| 1527 | * {@hide} |
| 1528 | * |
| 1529 | * @see #setTag(Object) |
| 1530 | * @see #getTag() |
| 1531 | */ |
| 1532 | protected Object mTag; |
| 1533 | |
| 1534 | // for mPrivateFlags: |
| 1535 | /** {@hide} */ |
| 1536 | static final int WANTS_FOCUS = 0x00000001; |
| 1537 | /** {@hide} */ |
| 1538 | static final int FOCUSED = 0x00000002; |
| 1539 | /** {@hide} */ |
| 1540 | static final int SELECTED = 0x00000004; |
| 1541 | /** {@hide} */ |
| 1542 | static final int IS_ROOT_NAMESPACE = 0x00000008; |
| 1543 | /** {@hide} */ |
| 1544 | static final int HAS_BOUNDS = 0x00000010; |
| 1545 | /** {@hide} */ |
| 1546 | static final int DRAWN = 0x00000020; |
| 1547 | /** |
| 1548 | * When this flag is set, this view is running an animation on behalf of its |
| 1549 | * children and should therefore not cancel invalidate requests, even if they |
| 1550 | * lie outside of this view's bounds. |
| 1551 | * |
| 1552 | * {@hide} |
| 1553 | */ |
| 1554 | static final int DRAW_ANIMATION = 0x00000040; |
| 1555 | /** {@hide} */ |
| 1556 | static final int SKIP_DRAW = 0x00000080; |
| 1557 | /** {@hide} */ |
| 1558 | static final int ONLY_DRAWS_BACKGROUND = 0x00000100; |
| 1559 | /** {@hide} */ |
| 1560 | static final int REQUEST_TRANSPARENT_REGIONS = 0x00000200; |
| 1561 | /** {@hide} */ |
| 1562 | static final int DRAWABLE_STATE_DIRTY = 0x00000400; |
| 1563 | /** {@hide} */ |
| 1564 | static final int MEASURED_DIMENSION_SET = 0x00000800; |
| 1565 | /** {@hide} */ |
| 1566 | static final int FORCE_LAYOUT = 0x00001000; |
Konstantin Lopyrev | c6dc457 | 2010-08-06 15:01:52 -0700 | [diff] [blame] | 1567 | /** {@hide} */ |
| 1568 | static final int LAYOUT_REQUIRED = 0x00002000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1569 | |
| 1570 | private static final int PRESSED = 0x00004000; |
| 1571 | |
| 1572 | /** {@hide} */ |
| 1573 | static final int DRAWING_CACHE_VALID = 0x00008000; |
| 1574 | /** |
| 1575 | * Flag used to indicate that this view should be drawn once more (and only once |
| 1576 | * more) after its animation has completed. |
| 1577 | * {@hide} |
| 1578 | */ |
| 1579 | static final int ANIMATION_STARTED = 0x00010000; |
| 1580 | |
| 1581 | private static final int SAVE_STATE_CALLED = 0x00020000; |
| 1582 | |
| 1583 | /** |
| 1584 | * Indicates that the View returned true when onSetAlpha() was called and that |
| 1585 | * the alpha must be restored. |
| 1586 | * {@hide} |
| 1587 | */ |
| 1588 | static final int ALPHA_SET = 0x00040000; |
| 1589 | |
| 1590 | /** |
| 1591 | * Set by {@link #setScrollContainer(boolean)}. |
| 1592 | */ |
| 1593 | static final int SCROLL_CONTAINER = 0x00080000; |
| 1594 | |
| 1595 | /** |
| 1596 | * Set by {@link #setScrollContainer(boolean)}. |
| 1597 | */ |
| 1598 | static final int SCROLL_CONTAINER_ADDED = 0x00100000; |
| 1599 | |
| 1600 | /** |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1601 | * View flag indicating whether this view was invalidated (fully or partially.) |
| 1602 | * |
| 1603 | * @hide |
| 1604 | */ |
| 1605 | static final int DIRTY = 0x00200000; |
| 1606 | |
| 1607 | /** |
| 1608 | * View flag indicating whether this view was invalidated by an opaque |
| 1609 | * invalidate request. |
| 1610 | * |
| 1611 | * @hide |
| 1612 | */ |
| 1613 | static final int DIRTY_OPAQUE = 0x00400000; |
| 1614 | |
| 1615 | /** |
| 1616 | * Mask for {@link #DIRTY} and {@link #DIRTY_OPAQUE}. |
| 1617 | * |
| 1618 | * @hide |
| 1619 | */ |
| 1620 | static final int DIRTY_MASK = 0x00600000; |
| 1621 | |
| 1622 | /** |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1623 | * Indicates whether the background is opaque. |
| 1624 | * |
| 1625 | * @hide |
| 1626 | */ |
| 1627 | static final int OPAQUE_BACKGROUND = 0x00800000; |
| 1628 | |
| 1629 | /** |
| 1630 | * Indicates whether the scrollbars are opaque. |
| 1631 | * |
| 1632 | * @hide |
| 1633 | */ |
| 1634 | static final int OPAQUE_SCROLLBARS = 0x01000000; |
| 1635 | |
| 1636 | /** |
| 1637 | * Indicates whether the view is opaque. |
| 1638 | * |
| 1639 | * @hide |
| 1640 | */ |
| 1641 | static final int OPAQUE_MASK = 0x01800000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1642 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1643 | /** |
| 1644 | * Indicates a prepressed state; |
| 1645 | * the short time between ACTION_DOWN and recognizing |
| 1646 | * a 'real' press. Prepressed is used to recognize quick taps |
| 1647 | * even when they are shorter than ViewConfiguration.getTapTimeout(). |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1648 | * |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1649 | * @hide |
| 1650 | */ |
| 1651 | private static final int PREPRESSED = 0x02000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1652 | |
Adam Powell | c9fbaab | 2010-02-16 17:16:19 -0800 | [diff] [blame] | 1653 | /** |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 1654 | * Indicates whether the view is temporarily detached. |
| 1655 | * |
| 1656 | * @hide |
| 1657 | */ |
| 1658 | static final int CANCEL_NEXT_UP_EVENT = 0x04000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1659 | |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1660 | /** |
| 1661 | * Indicates that we should awaken scroll bars once attached |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1662 | * |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1663 | * @hide |
| 1664 | */ |
| 1665 | private static final int AWAKEN_SCROLL_BARS_ON_ATTACH = 0x08000000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1666 | |
| 1667 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1668 | * Indicates that the view has received HOVER_ENTER. Cleared on HOVER_EXIT. |
| 1669 | * @hide |
| 1670 | */ |
| 1671 | private static final int HOVERED = 0x10000000; |
| 1672 | |
| 1673 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1674 | * Indicates that pivotX or pivotY were explicitly set and we should not assume the center |
| 1675 | * for transform operations |
| 1676 | * |
| 1677 | * @hide |
| 1678 | */ |
Adam Powell | f37df07 | 2010-09-17 16:22:49 -0700 | [diff] [blame] | 1679 | private static final int PIVOT_EXPLICITLY_SET = 0x20000000; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1680 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1681 | /** {@hide} */ |
Adam Powell | f37df07 | 2010-09-17 16:22:49 -0700 | [diff] [blame] | 1682 | static final int ACTIVATED = 0x40000000; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1683 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1684 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1685 | * Indicates that this view was specifically invalidated, not just dirtied because some |
| 1686 | * child view was invalidated. The flag is used to determine when we need to recreate |
| 1687 | * a view's display list (as opposed to just returning a reference to its existing |
| 1688 | * display list). |
| 1689 | * |
| 1690 | * @hide |
| 1691 | */ |
| 1692 | static final int INVALIDATED = 0x80000000; |
| 1693 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1694 | /* Masks for mPrivateFlags2 */ |
| 1695 | |
| 1696 | /** |
| 1697 | * Indicates that this view has reported that it can accept the current drag's content. |
| 1698 | * Cleared when the drag operation concludes. |
| 1699 | * @hide |
| 1700 | */ |
| 1701 | static final int DRAG_CAN_ACCEPT = 0x00000001; |
| 1702 | |
| 1703 | /** |
| 1704 | * Indicates that this view is currently directly under the drag location in a |
| 1705 | * drag-and-drop operation involving content that it can accept. Cleared when |
| 1706 | * the drag exits the view, or when the drag operation concludes. |
| 1707 | * @hide |
| 1708 | */ |
| 1709 | static final int DRAG_HOVERED = 0x00000002; |
| 1710 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1711 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1712 | * Horizontal layout direction of this view is from Left to Right. |
| 1713 | * Use with {@link #setLayoutDirection}. |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1714 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1715 | public static final int LAYOUT_DIRECTION_LTR = 0; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1716 | |
| 1717 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1718 | * Horizontal layout direction of this view is from Right to Left. |
| 1719 | * Use with {@link #setLayoutDirection}. |
| 1720 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1721 | public static final int LAYOUT_DIRECTION_RTL = 1; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1722 | |
| 1723 | /** |
| 1724 | * Horizontal layout direction of this view is inherited from its parent. |
| 1725 | * Use with {@link #setLayoutDirection}. |
| 1726 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1727 | public static final int LAYOUT_DIRECTION_INHERIT = 2; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1728 | |
| 1729 | /** |
| 1730 | * Horizontal layout direction of this view is from deduced from the default language |
| 1731 | * script for the locale. Use with {@link #setLayoutDirection}. |
| 1732 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1733 | public static final int LAYOUT_DIRECTION_LOCALE = 3; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1734 | |
| 1735 | /** |
| 1736 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1737 | * @hide |
| 1738 | */ |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1739 | static final int LAYOUT_DIRECTION_MASK_SHIFT = 2; |
| 1740 | |
| 1741 | /** |
| 1742 | * Mask for use with private flags indicating bits used for horizontal layout direction. |
| 1743 | * @hide |
| 1744 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1745 | static final int LAYOUT_DIRECTION_MASK = 0x00000003 << LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1746 | |
| 1747 | /** |
| 1748 | * Indicates whether the view horizontal layout direction has been resolved and drawn to the |
| 1749 | * right-to-left direction. |
| 1750 | * @hide |
| 1751 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1752 | static final int LAYOUT_DIRECTION_RESOLVED_RTL = 4 << LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1753 | |
| 1754 | /** |
| 1755 | * Indicates whether the view horizontal layout direction has been resolved. |
| 1756 | * @hide |
| 1757 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1758 | static final int LAYOUT_DIRECTION_RESOLVED = 8 << LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1759 | |
| 1760 | /** |
| 1761 | * Mask for use with private flags indicating bits used for resolved horizontal layout direction. |
| 1762 | * @hide |
| 1763 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1764 | static final int LAYOUT_DIRECTION_RESOLVED_MASK = 0x0000000C << LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1765 | |
| 1766 | /* |
| 1767 | * Array of horizontal layout direction flags for mapping attribute "layoutDirection" to correct |
| 1768 | * flag value. |
| 1769 | * @hide |
| 1770 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1771 | private static final int[] LAYOUT_DIRECTION_FLAGS = { |
| 1772 | LAYOUT_DIRECTION_LTR, |
| 1773 | LAYOUT_DIRECTION_RTL, |
| 1774 | LAYOUT_DIRECTION_INHERIT, |
| 1775 | LAYOUT_DIRECTION_LOCALE |
| 1776 | }; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1777 | |
| 1778 | /** |
| 1779 | * Default horizontal layout direction. |
| 1780 | * @hide |
| 1781 | */ |
| 1782 | private static final int LAYOUT_DIRECTION_DEFAULT = LAYOUT_DIRECTION_INHERIT; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1783 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1784 | |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1785 | /** |
| 1786 | * Indicates that the view is tracking some sort of transient state |
| 1787 | * that the app should not need to be aware of, but that the framework |
| 1788 | * should take special care to preserve. |
| 1789 | * |
| 1790 | * @hide |
| 1791 | */ |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1792 | static final int HAS_TRANSIENT_STATE = 0x00000100; |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1793 | |
| 1794 | |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1795 | /** |
| 1796 | * Text direction is inherited thru {@link ViewGroup} |
| 1797 | */ |
| 1798 | public static final int TEXT_DIRECTION_INHERIT = 0; |
| 1799 | |
| 1800 | /** |
| 1801 | * Text direction is using "first strong algorithm". The first strong directional character |
| 1802 | * determines the paragraph direction. If there is no strong directional character, the |
| 1803 | * paragraph direction is the view's resolved layout direction. |
| 1804 | */ |
| 1805 | public static final int TEXT_DIRECTION_FIRST_STRONG = 1; |
| 1806 | |
| 1807 | /** |
| 1808 | * Text direction is using "any-RTL" algorithm. The paragraph direction is RTL if it contains |
| 1809 | * any strong RTL character, otherwise it is LTR if it contains any strong LTR characters. |
| 1810 | * If there are neither, the paragraph direction is the view's resolved layout direction. |
| 1811 | */ |
| 1812 | public static final int TEXT_DIRECTION_ANY_RTL = 2; |
| 1813 | |
| 1814 | /** |
| 1815 | * Text direction is forced to LTR. |
| 1816 | */ |
| 1817 | public static final int TEXT_DIRECTION_LTR = 3; |
| 1818 | |
| 1819 | /** |
| 1820 | * Text direction is forced to RTL. |
| 1821 | */ |
| 1822 | public static final int TEXT_DIRECTION_RTL = 4; |
| 1823 | |
| 1824 | /** |
| 1825 | * Text direction is coming from the system Locale. |
| 1826 | */ |
| 1827 | public static final int TEXT_DIRECTION_LOCALE = 5; |
| 1828 | |
| 1829 | /** |
| 1830 | * Bit shift to get the horizontal layout direction. (bits after LAYOUT_DIRECTION_RESOLVED) |
| 1831 | * @hide |
| 1832 | */ |
| 1833 | static final int TEXT_DIRECTION_MASK_SHIFT = 6; |
| 1834 | |
| 1835 | /** |
| 1836 | * Default text direction is inherited |
| 1837 | */ |
| 1838 | protected static int TEXT_DIRECTION_DEFAULT = TEXT_DIRECTION_INHERIT; |
| 1839 | |
| 1840 | /** |
| 1841 | * Mask for use with private flags indicating bits used for text direction. |
| 1842 | * @hide |
| 1843 | */ |
| 1844 | static final int TEXT_DIRECTION_MASK = 0x00000007 << TEXT_DIRECTION_MASK_SHIFT; |
| 1845 | |
| 1846 | /** |
| 1847 | * Array of text direction flags for mapping attribute "textDirection" to correct |
| 1848 | * flag value. |
| 1849 | * @hide |
| 1850 | */ |
| 1851 | private static final int[] TEXT_DIRECTION_FLAGS = { |
| 1852 | TEXT_DIRECTION_INHERIT << TEXT_DIRECTION_MASK_SHIFT, |
| 1853 | TEXT_DIRECTION_FIRST_STRONG << TEXT_DIRECTION_MASK_SHIFT, |
| 1854 | TEXT_DIRECTION_ANY_RTL << TEXT_DIRECTION_MASK_SHIFT, |
| 1855 | TEXT_DIRECTION_LTR << TEXT_DIRECTION_MASK_SHIFT, |
| 1856 | TEXT_DIRECTION_RTL << TEXT_DIRECTION_MASK_SHIFT, |
| 1857 | TEXT_DIRECTION_LOCALE << TEXT_DIRECTION_MASK_SHIFT |
| 1858 | }; |
| 1859 | |
| 1860 | /** |
| 1861 | * Indicates whether the view text direction has been resolved. |
| 1862 | * @hide |
| 1863 | */ |
| 1864 | static final int TEXT_DIRECTION_RESOLVED = 0x00000008 << TEXT_DIRECTION_MASK_SHIFT; |
| 1865 | |
| 1866 | /** |
| 1867 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
| 1868 | * @hide |
| 1869 | */ |
| 1870 | static final int TEXT_DIRECTION_RESOLVED_MASK_SHIFT = 10; |
| 1871 | |
| 1872 | /** |
| 1873 | * Mask for use with private flags indicating bits used for resolved text direction. |
| 1874 | * @hide |
| 1875 | */ |
| 1876 | static final int TEXT_DIRECTION_RESOLVED_MASK = 0x00000007 << TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
| 1877 | |
| 1878 | /** |
| 1879 | * Indicates whether the view text direction has been resolved to the "first strong" heuristic. |
| 1880 | * @hide |
| 1881 | */ |
| 1882 | static final int TEXT_DIRECTION_RESOLVED_DEFAULT = |
| 1883 | TEXT_DIRECTION_FIRST_STRONG << TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
| 1884 | |
| 1885 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1886 | /* End of masks for mPrivateFlags2 */ |
| 1887 | |
| 1888 | static final int DRAG_MASK = DRAG_CAN_ACCEPT | DRAG_HOVERED; |
| 1889 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1890 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 1891 | * Always allow a user to over-scroll this view, provided it is a |
| 1892 | * view that can scroll. |
| 1893 | * |
| 1894 | * @see #getOverScrollMode() |
| 1895 | * @see #setOverScrollMode(int) |
| 1896 | */ |
| 1897 | public static final int OVER_SCROLL_ALWAYS = 0; |
| 1898 | |
| 1899 | /** |
| 1900 | * Allow a user to over-scroll this view only if the content is large |
| 1901 | * enough to meaningfully scroll, provided it is a view that can scroll. |
| 1902 | * |
| 1903 | * @see #getOverScrollMode() |
| 1904 | * @see #setOverScrollMode(int) |
| 1905 | */ |
| 1906 | public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1; |
| 1907 | |
| 1908 | /** |
| 1909 | * Never allow a user to over-scroll this view. |
| 1910 | * |
| 1911 | * @see #getOverScrollMode() |
| 1912 | * @see #setOverScrollMode(int) |
| 1913 | */ |
| 1914 | public static final int OVER_SCROLL_NEVER = 2; |
| 1915 | |
| 1916 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 1917 | * Special constant for {@link #setSystemUiVisibility(int)}: View has |
| 1918 | * requested the system UI (status bar) to be visible (the default). |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1919 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1920 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1921 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1922 | public static final int SYSTEM_UI_FLAG_VISIBLE = 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1923 | |
| 1924 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 1925 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested the |
| 1926 | * system UI to enter an unobtrusive "low profile" mode. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1927 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 1928 | * <p>This is for use in games, book readers, video players, or any other |
| 1929 | * "immersive" application where the usual system chrome is deemed too distracting. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1930 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 1931 | * <p>In low profile mode, the status bar and/or navigation icons may dim. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1932 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1933 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1934 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1935 | public static final int SYSTEM_UI_FLAG_LOW_PROFILE = 0x00000001; |
| 1936 | |
| 1937 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 1938 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested that the |
| 1939 | * system navigation be temporarily hidden. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1940 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 1941 | * <p>This is an even less obtrusive state than that called for by |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1942 | * {@link #SYSTEM_UI_FLAG_LOW_PROFILE}; on devices that draw essential navigation controls |
| 1943 | * (Home, Back, and the like) on screen, <code>SYSTEM_UI_FLAG_HIDE_NAVIGATION</code> will cause |
| 1944 | * those to disappear. This is useful (in conjunction with the |
| 1945 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN FLAG_FULLSCREEN} and |
| 1946 | * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN FLAG_LAYOUT_IN_SCREEN} |
| 1947 | * window flags) for displaying content using every last pixel on the display. |
| 1948 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 1949 | * <p>There is a limitation: because navigation controls are so important, the least user |
| 1950 | * interaction will cause them to reappear immediately. When this happens, both |
| 1951 | * this flag and {@link #SYSTEM_UI_FLAG_FULLSCREEN} will be cleared automatically, |
| 1952 | * so that both elements reappear at the same time. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1953 | * |
| 1954 | * @see #setSystemUiVisibility(int) |
| 1955 | */ |
| 1956 | public static final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 0x00000002; |
| 1957 | |
| 1958 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 1959 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested to go |
| 1960 | * into the normal fullscreen mode so that its content can take over the screen |
| 1961 | * while still allowing the user to interact with the application. |
| 1962 | * |
| 1963 | * <p>This has the same visual effect as |
| 1964 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN |
| 1965 | * WindowManager.LayoutParams.FLAG_FULLSCREEN}, |
| 1966 | * meaning that non-critical screen decorations (such as the status bar) will be |
| 1967 | * hidden while the user is in the View's window, focusing the experience on |
| 1968 | * that content. Unlike the window flag, if you are using ActionBar in |
| 1969 | * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 1970 | * Window.FEATURE_ACTION_BAR_OVERLAY}, then enabling this flag will also |
| 1971 | * hide the action bar. |
| 1972 | * |
| 1973 | * <p>This approach to going fullscreen is best used over the window flag when |
| 1974 | * it is a transient state -- that is, the application does this at certain |
| 1975 | * points in its user interaction where it wants to allow the user to focus |
| 1976 | * on content, but not as a continuous state. For situations where the application |
| 1977 | * would like to simply stay full screen the entire time (such as a game that |
| 1978 | * wants to take over the screen), the |
| 1979 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN window flag} |
| 1980 | * is usually a better approach. The state set here will be removed by the system |
| 1981 | * in various situations (such as the user moving to another application) like |
| 1982 | * the other system UI states. |
| 1983 | * |
| 1984 | * <p>When using this flag, the application should provide some easy facility |
| 1985 | * for the user to go out of it. A common example would be in an e-book |
| 1986 | * reader, where tapping on the screen brings back whatever screen and UI |
| 1987 | * decorations that had been hidden while the user was immersed in reading |
| 1988 | * the book. |
| 1989 | * |
| 1990 | * @see #setSystemUiVisibility(int) |
| 1991 | */ |
| 1992 | public static final int SYSTEM_UI_FLAG_FULLSCREEN = 0x00000004; |
| 1993 | |
| 1994 | /** |
| 1995 | * Flag for {@link #setSystemUiVisibility(int)}: When using other layout |
| 1996 | * flags, we would like a stable view of the content insets given to |
| 1997 | * {@link #fitSystemWindows(Rect)}. This means that the insets seen there |
| 1998 | * will always represent the worst case that the application can expect |
| 1999 | * as a continue state. In practice this means with any of system bar, |
| 2000 | * nav bar, and status bar shown, but not the space that would be needed |
| 2001 | * for an input method. |
| 2002 | * |
| 2003 | * <p>If you are using ActionBar in |
| 2004 | * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 2005 | * Window.FEATURE_ACTION_BAR_OVERLAY}, this flag will also impact the |
| 2006 | * insets it adds to those given to the application. |
| 2007 | */ |
| 2008 | public static final int SYSTEM_UI_FLAG_LAYOUT_STABLE = 0x00000100; |
| 2009 | |
| 2010 | /** |
| 2011 | * Flag for {@link #setSystemUiVisibility(int)}: View would like its window |
| 2012 | * to be layed out as if it has requested |
| 2013 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, even if it currently hasn't. This |
| 2014 | * allows it to avoid artifacts when switching in and out of that mode, at |
| 2015 | * the expense that some of its user interface may be covered by screen |
| 2016 | * decorations when they are shown. You can perform layout of your inner |
| 2017 | * UI elements to account for the navagation system UI through the |
| 2018 | * {@link #fitSystemWindows(Rect)} method. |
| 2019 | */ |
| 2020 | public static final int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = 0x00000200; |
| 2021 | |
| 2022 | /** |
| 2023 | * Flag for {@link #setSystemUiVisibility(int)}: View would like its window |
| 2024 | * to be layed out as if it has requested |
| 2025 | * {@link #SYSTEM_UI_FLAG_FULLSCREEN}, even if it currently hasn't. This |
| 2026 | * allows it to avoid artifacts when switching in and out of that mode, at |
| 2027 | * the expense that some of its user interface may be covered by screen |
| 2028 | * decorations when they are shown. You can perform layout of your inner |
| 2029 | * UI elements to account for non-fullscreen system UI through the |
| 2030 | * {@link #fitSystemWindows(Rect)} method. |
| 2031 | */ |
| 2032 | public static final int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 0x00000400; |
| 2033 | |
| 2034 | /** |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2035 | * @deprecated Use {@link #SYSTEM_UI_FLAG_LOW_PROFILE} instead. |
| 2036 | */ |
| 2037 | public static final int STATUS_BAR_HIDDEN = SYSTEM_UI_FLAG_LOW_PROFILE; |
| 2038 | |
| 2039 | /** |
| 2040 | * @deprecated Use {@link #SYSTEM_UI_FLAG_VISIBLE} instead. |
| 2041 | */ |
| 2042 | public static final int STATUS_BAR_VISIBLE = SYSTEM_UI_FLAG_VISIBLE; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2043 | |
| 2044 | /** |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2045 | * @hide |
| 2046 | * |
| 2047 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2048 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2049 | * |
| 2050 | * Flag to make the status bar not expandable. Unless you also |
| 2051 | * set {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show. |
| 2052 | */ |
| 2053 | public static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000; |
| 2054 | |
| 2055 | /** |
| 2056 | * @hide |
| 2057 | * |
| 2058 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2059 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2060 | * |
| 2061 | * Flag to hide notification icons and scrolling ticker text. |
| 2062 | */ |
| 2063 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ICONS = 0x00020000; |
| 2064 | |
| 2065 | /** |
| 2066 | * @hide |
| 2067 | * |
| 2068 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2069 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2070 | * |
| 2071 | * Flag to disable incoming notification alerts. This will not block |
| 2072 | * icons, but it will block sound, vibrating and other visual or aural notifications. |
| 2073 | */ |
| 2074 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ALERTS = 0x00040000; |
| 2075 | |
| 2076 | /** |
| 2077 | * @hide |
| 2078 | * |
| 2079 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2080 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2081 | * |
| 2082 | * Flag to hide only the scrolling ticker. Note that |
| 2083 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS} implies |
| 2084 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_TICKER}. |
| 2085 | */ |
| 2086 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_TICKER = 0x00080000; |
| 2087 | |
| 2088 | /** |
| 2089 | * @hide |
| 2090 | * |
| 2091 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2092 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2093 | * |
| 2094 | * Flag to hide the center system info area. |
| 2095 | */ |
| 2096 | public static final int STATUS_BAR_DISABLE_SYSTEM_INFO = 0x00100000; |
| 2097 | |
| 2098 | /** |
| 2099 | * @hide |
| 2100 | * |
| 2101 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2102 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2103 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2104 | * Flag to hide only the home button. Don't use this |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2105 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2106 | */ |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2107 | public static final int STATUS_BAR_DISABLE_HOME = 0x00200000; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2108 | |
| 2109 | /** |
| 2110 | * @hide |
| 2111 | * |
| 2112 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2113 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2114 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2115 | * Flag to hide only the back button. Don't use this |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 2116 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2117 | */ |
| 2118 | public static final int STATUS_BAR_DISABLE_BACK = 0x00400000; |
| 2119 | |
| 2120 | /** |
| 2121 | * @hide |
| 2122 | * |
| 2123 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2124 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2125 | * |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2126 | * Flag to hide only the clock. You might use this if your activity has |
| 2127 | * its own clock making the status bar's clock redundant. |
| 2128 | */ |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 2129 | public static final int STATUS_BAR_DISABLE_CLOCK = 0x00800000; |
| 2130 | |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2131 | /** |
| 2132 | * @hide |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2133 | * |
| 2134 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2135 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2136 | * |
| 2137 | * Flag to hide only the recent apps button. Don't use this |
| 2138 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2139 | */ |
| 2140 | public static final int STATUS_BAR_DISABLE_RECENT = 0x01000000; |
| 2141 | |
| 2142 | /** |
| 2143 | * @hide |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2144 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2145 | public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK = 0x0000FFFF; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2146 | |
| 2147 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2148 | * These are the system UI flags that can be cleared by events outside |
| 2149 | * of an application. Currently this is just the ability to tap on the |
| 2150 | * screen while hiding the navigation bar to have it return. |
| 2151 | * @hide |
| 2152 | */ |
| 2153 | public static final int SYSTEM_UI_CLEARABLE_FLAGS = |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 2154 | SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_HIDE_NAVIGATION |
| 2155 | | SYSTEM_UI_FLAG_FULLSCREEN; |
| 2156 | |
| 2157 | /** |
| 2158 | * Flags that can impact the layout in relation to system UI. |
| 2159 | */ |
| 2160 | public static final int SYSTEM_UI_LAYOUT_FLAGS = |
| 2161 | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
| 2162 | | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2163 | |
| 2164 | /** |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 2165 | * Find views that render the specified text. |
| 2166 | * |
| 2167 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2168 | */ |
| 2169 | public static final int FIND_VIEWS_WITH_TEXT = 0x00000001; |
| 2170 | |
| 2171 | /** |
| 2172 | * Find find views that contain the specified content description. |
| 2173 | * |
| 2174 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2175 | */ |
| 2176 | public static final int FIND_VIEWS_WITH_CONTENT_DESCRIPTION = 0x00000002; |
| 2177 | |
| 2178 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 2179 | * Find views that contain {@link AccessibilityNodeProvider}. Such |
| 2180 | * a View is a root of virtual view hierarchy and may contain the searched |
| 2181 | * text. If this flag is set Views with providers are automatically |
| 2182 | * added and it is a responsibility of the client to call the APIs of |
| 2183 | * the provider to determine whether the virtual tree rooted at this View |
| 2184 | * contains the text, i.e. getting the list of {@link AccessibilityNodeInfo}s |
| 2185 | * represeting the virtual views with this text. |
| 2186 | * |
| 2187 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2188 | * |
| 2189 | * @hide |
| 2190 | */ |
| 2191 | public static final int FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS = 0x00000004; |
| 2192 | |
| 2193 | /** |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 2194 | * Indicates that the screen has changed state and is now off. |
| 2195 | * |
| 2196 | * @see #onScreenStateChanged(int) |
| 2197 | */ |
| 2198 | public static final int SCREEN_STATE_OFF = 0x0; |
| 2199 | |
| 2200 | /** |
| 2201 | * Indicates that the screen has changed state and is now on. |
| 2202 | * |
Romain Guy | 1e3d313 | 2012-03-08 15:55:56 -0800 | [diff] [blame] | 2203 | * @see #onScreenStateChanged(int) |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 2204 | */ |
| 2205 | public static final int SCREEN_STATE_ON = 0x1; |
| 2206 | |
| 2207 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2208 | * Controls the over-scroll mode for this view. |
| 2209 | * See {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)}, |
| 2210 | * {@link #OVER_SCROLL_ALWAYS}, {@link #OVER_SCROLL_IF_CONTENT_SCROLLS}, |
| 2211 | * and {@link #OVER_SCROLL_NEVER}. |
| 2212 | */ |
| 2213 | private int mOverScrollMode; |
| 2214 | |
| 2215 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2216 | * The parent this view is attached to. |
| 2217 | * {@hide} |
| 2218 | * |
| 2219 | * @see #getParent() |
| 2220 | */ |
| 2221 | protected ViewParent mParent; |
| 2222 | |
| 2223 | /** |
| 2224 | * {@hide} |
| 2225 | */ |
| 2226 | AttachInfo mAttachInfo; |
| 2227 | |
| 2228 | /** |
| 2229 | * {@hide} |
| 2230 | */ |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2231 | @ViewDebug.ExportedProperty(flagMapping = { |
| 2232 | @ViewDebug.FlagToString(mask = FORCE_LAYOUT, equals = FORCE_LAYOUT, |
| 2233 | name = "FORCE_LAYOUT"), |
| 2234 | @ViewDebug.FlagToString(mask = LAYOUT_REQUIRED, equals = LAYOUT_REQUIRED, |
| 2235 | name = "LAYOUT_REQUIRED"), |
| 2236 | @ViewDebug.FlagToString(mask = DRAWING_CACHE_VALID, equals = DRAWING_CACHE_VALID, |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 2237 | name = "DRAWING_CACHE_INVALID", outputIf = false), |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2238 | @ViewDebug.FlagToString(mask = DRAWN, equals = DRAWN, name = "DRAWN", outputIf = true), |
| 2239 | @ViewDebug.FlagToString(mask = DRAWN, equals = DRAWN, name = "NOT_DRAWN", outputIf = false), |
| 2240 | @ViewDebug.FlagToString(mask = DIRTY_MASK, equals = DIRTY_OPAQUE, name = "DIRTY_OPAQUE"), |
| 2241 | @ViewDebug.FlagToString(mask = DIRTY_MASK, equals = DIRTY, name = "DIRTY") |
| 2242 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2243 | int mPrivateFlags; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2244 | int mPrivateFlags2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2245 | |
| 2246 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2247 | * This view's request for the visibility of the status bar. |
| 2248 | * @hide |
| 2249 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2250 | @ViewDebug.ExportedProperty(flagMapping = { |
| 2251 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2252 | equals = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2253 | name = "SYSTEM_UI_FLAG_LOW_PROFILE", outputIf = true), |
| 2254 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2255 | equals = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2256 | name = "SYSTEM_UI_FLAG_HIDE_NAVIGATION", outputIf = true), |
| 2257 | @ViewDebug.FlagToString(mask = PUBLIC_STATUS_BAR_VISIBILITY_MASK, |
| 2258 | equals = SYSTEM_UI_FLAG_VISIBLE, |
| 2259 | name = "SYSTEM_UI_FLAG_VISIBLE", outputIf = true) |
| 2260 | }) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2261 | int mSystemUiVisibility; |
| 2262 | |
| 2263 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2264 | * Count of how many windows this view has been attached to. |
| 2265 | */ |
| 2266 | int mWindowAttachCount; |
| 2267 | |
| 2268 | /** |
| 2269 | * The layout parameters associated with this view and used by the parent |
| 2270 | * {@link android.view.ViewGroup} to determine how this view should be |
| 2271 | * laid out. |
| 2272 | * {@hide} |
| 2273 | */ |
| 2274 | protected ViewGroup.LayoutParams mLayoutParams; |
| 2275 | |
| 2276 | /** |
| 2277 | * The view flags hold various views states. |
| 2278 | * {@hide} |
| 2279 | */ |
| 2280 | @ViewDebug.ExportedProperty |
| 2281 | int mViewFlags; |
| 2282 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2283 | static class TransformationInfo { |
| 2284 | /** |
| 2285 | * The transform matrix for the View. This transform is calculated internally |
| 2286 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2287 | * is used by default. Do *not* use this variable directly; instead call |
| 2288 | * getMatrix(), which will automatically recalculate the matrix if necessary |
| 2289 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2290 | */ |
| 2291 | private final Matrix mMatrix = new Matrix(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2292 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2293 | /** |
| 2294 | * The transform matrix for the View. This transform is calculated internally |
| 2295 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2296 | * is used by default. Do *not* use this variable directly; instead call |
| 2297 | * getInverseMatrix(), which will automatically recalculate the matrix if necessary |
| 2298 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2299 | */ |
| 2300 | private Matrix mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2301 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2302 | /** |
| 2303 | * An internal variable that tracks whether we need to recalculate the |
| 2304 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2305 | * have changed since the matrix was last calculated. |
| 2306 | */ |
| 2307 | boolean mMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2308 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2309 | /** |
| 2310 | * An internal variable that tracks whether we need to recalculate the |
| 2311 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2312 | * have changed since the matrix was last calculated. |
| 2313 | */ |
| 2314 | private boolean mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2315 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2316 | /** |
| 2317 | * A variable that tracks whether we need to recalculate the |
| 2318 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2319 | * have changed since the matrix was last calculated. This variable |
| 2320 | * is only valid after a call to updateMatrix() or to a function that |
| 2321 | * calls it such as getMatrix(), hasIdentityMatrix() and getInverseMatrix(). |
| 2322 | */ |
| 2323 | private boolean mMatrixIsIdentity = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2324 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2325 | /** |
| 2326 | * The Camera object is used to compute a 3D matrix when rotationX or rotationY are set. |
| 2327 | */ |
| 2328 | private Camera mCamera = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2329 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2330 | /** |
| 2331 | * This matrix is used when computing the matrix for 3D rotations. |
| 2332 | */ |
| 2333 | private Matrix matrix3D = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2334 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2335 | /** |
| 2336 | * These prev values are used to recalculate a centered pivot point when necessary. The |
| 2337 | * pivot point is only used in matrix operations (when rotation, scale, or translation are |
| 2338 | * set), so thes values are only used then as well. |
| 2339 | */ |
| 2340 | private int mPrevWidth = -1; |
| 2341 | private int mPrevHeight = -1; |
| 2342 | |
| 2343 | /** |
| 2344 | * The degrees rotation around the vertical axis through the pivot point. |
| 2345 | */ |
| 2346 | @ViewDebug.ExportedProperty |
| 2347 | float mRotationY = 0f; |
| 2348 | |
| 2349 | /** |
| 2350 | * The degrees rotation around the horizontal axis through the pivot point. |
| 2351 | */ |
| 2352 | @ViewDebug.ExportedProperty |
| 2353 | float mRotationX = 0f; |
| 2354 | |
| 2355 | /** |
| 2356 | * The degrees rotation around the pivot point. |
| 2357 | */ |
| 2358 | @ViewDebug.ExportedProperty |
| 2359 | float mRotation = 0f; |
| 2360 | |
| 2361 | /** |
| 2362 | * The amount of translation of the object away from its left property (post-layout). |
| 2363 | */ |
| 2364 | @ViewDebug.ExportedProperty |
| 2365 | float mTranslationX = 0f; |
| 2366 | |
| 2367 | /** |
| 2368 | * The amount of translation of the object away from its top property (post-layout). |
| 2369 | */ |
| 2370 | @ViewDebug.ExportedProperty |
| 2371 | float mTranslationY = 0f; |
| 2372 | |
| 2373 | /** |
| 2374 | * The amount of scale in the x direction around the pivot point. A |
| 2375 | * value of 1 means no scaling is applied. |
| 2376 | */ |
| 2377 | @ViewDebug.ExportedProperty |
| 2378 | float mScaleX = 1f; |
| 2379 | |
| 2380 | /** |
| 2381 | * The amount of scale in the y direction around the pivot point. A |
| 2382 | * value of 1 means no scaling is applied. |
| 2383 | */ |
| 2384 | @ViewDebug.ExportedProperty |
| 2385 | float mScaleY = 1f; |
| 2386 | |
| 2387 | /** |
Chet Haase | a33de55 | 2012-02-03 16:28:24 -0800 | [diff] [blame] | 2388 | * The x location of the point around which the view is rotated and scaled. |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2389 | */ |
| 2390 | @ViewDebug.ExportedProperty |
| 2391 | float mPivotX = 0f; |
| 2392 | |
| 2393 | /** |
Chet Haase | a33de55 | 2012-02-03 16:28:24 -0800 | [diff] [blame] | 2394 | * The y location of the point around which the view is rotated and scaled. |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2395 | */ |
| 2396 | @ViewDebug.ExportedProperty |
| 2397 | float mPivotY = 0f; |
| 2398 | |
| 2399 | /** |
| 2400 | * The opacity of the View. This is a value from 0 to 1, where 0 means |
| 2401 | * completely transparent and 1 means completely opaque. |
| 2402 | */ |
| 2403 | @ViewDebug.ExportedProperty |
| 2404 | float mAlpha = 1f; |
| 2405 | } |
| 2406 | |
| 2407 | TransformationInfo mTransformationInfo; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2408 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2409 | private boolean mLastIsOpaque; |
| 2410 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2411 | /** |
| 2412 | * Convenience value to check for float values that are close enough to zero to be considered |
| 2413 | * zero. |
| 2414 | */ |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame] | 2415 | private static final float NONZERO_EPSILON = .001f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2416 | |
| 2417 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2418 | * The distance in pixels from the left edge of this view's parent |
| 2419 | * to the left edge of this view. |
| 2420 | * {@hide} |
| 2421 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2422 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2423 | protected int mLeft; |
| 2424 | /** |
| 2425 | * The distance in pixels from the left edge of this view's parent |
| 2426 | * to the right edge of this view. |
| 2427 | * {@hide} |
| 2428 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2429 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2430 | protected int mRight; |
| 2431 | /** |
| 2432 | * The distance in pixels from the top edge of this view's parent |
| 2433 | * to the top edge of this view. |
| 2434 | * {@hide} |
| 2435 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2436 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2437 | protected int mTop; |
| 2438 | /** |
| 2439 | * The distance in pixels from the top edge of this view's parent |
| 2440 | * to the bottom edge of this view. |
| 2441 | * {@hide} |
| 2442 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2443 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2444 | protected int mBottom; |
| 2445 | |
| 2446 | /** |
| 2447 | * The offset, in pixels, by which the content of this view is scrolled |
| 2448 | * horizontally. |
| 2449 | * {@hide} |
| 2450 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2451 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2452 | protected int mScrollX; |
| 2453 | /** |
| 2454 | * The offset, in pixels, by which the content of this view is scrolled |
| 2455 | * vertically. |
| 2456 | * {@hide} |
| 2457 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2458 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2459 | protected int mScrollY; |
| 2460 | |
| 2461 | /** |
| 2462 | * The left padding in pixels, that is the distance in pixels between the |
| 2463 | * left edge of this view and the left edge of its content. |
| 2464 | * {@hide} |
| 2465 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2466 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2467 | protected int mPaddingLeft; |
| 2468 | /** |
| 2469 | * The right padding in pixels, that is the distance in pixels between the |
| 2470 | * right edge of this view and the right edge of its content. |
| 2471 | * {@hide} |
| 2472 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2473 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2474 | protected int mPaddingRight; |
| 2475 | /** |
| 2476 | * The top padding in pixels, that is the distance in pixels between the |
| 2477 | * top edge of this view and the top edge of its content. |
| 2478 | * {@hide} |
| 2479 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2480 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2481 | protected int mPaddingTop; |
| 2482 | /** |
| 2483 | * The bottom padding in pixels, that is the distance in pixels between the |
| 2484 | * bottom edge of this view and the bottom edge of its content. |
| 2485 | * {@hide} |
| 2486 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2487 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2488 | protected int mPaddingBottom; |
| 2489 | |
| 2490 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2491 | * Briefly describes the view and is primarily used for accessibility support. |
| 2492 | */ |
| 2493 | private CharSequence mContentDescription; |
| 2494 | |
| 2495 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2496 | * Cache the paddingRight set by the user to append to the scrollbar's size. |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2497 | * |
| 2498 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2499 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2500 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2501 | protected int mUserPaddingRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | |
| 2503 | /** |
| 2504 | * Cache the paddingBottom set by the user to append to the scrollbar's size. |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2505 | * |
| 2506 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2507 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2508 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2509 | protected int mUserPaddingBottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2510 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2511 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2512 | * Cache the paddingLeft set by the user to append to the scrollbar's size. |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2513 | * |
| 2514 | * @hide |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2515 | */ |
| 2516 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2517 | protected int mUserPaddingLeft; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2518 | |
| 2519 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 2520 | * Cache if the user padding is relative. |
| 2521 | * |
| 2522 | */ |
| 2523 | @ViewDebug.ExportedProperty(category = "padding") |
| 2524 | boolean mUserPaddingRelative; |
| 2525 | |
| 2526 | /** |
| 2527 | * Cache the paddingStart set by the user to append to the scrollbar's size. |
| 2528 | * |
| 2529 | */ |
| 2530 | @ViewDebug.ExportedProperty(category = "padding") |
| 2531 | int mUserPaddingStart; |
| 2532 | |
| 2533 | /** |
| 2534 | * Cache the paddingEnd set by the user to append to the scrollbar's size. |
| 2535 | * |
| 2536 | */ |
| 2537 | @ViewDebug.ExportedProperty(category = "padding") |
| 2538 | int mUserPaddingEnd; |
| 2539 | |
| 2540 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2541 | * @hide |
| 2542 | */ |
| 2543 | int mOldWidthMeasureSpec = Integer.MIN_VALUE; |
| 2544 | /** |
| 2545 | * @hide |
| 2546 | */ |
| 2547 | int mOldHeightMeasureSpec = Integer.MIN_VALUE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2548 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2549 | private Drawable mBGDrawable; |
| 2550 | |
| 2551 | private int mBackgroundResource; |
| 2552 | private boolean mBackgroundSizeChanged; |
| 2553 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2554 | static class ListenerInfo { |
| 2555 | /** |
| 2556 | * Listener used to dispatch focus change events. |
| 2557 | * This field should be made private, so it is hidden from the SDK. |
| 2558 | * {@hide} |
| 2559 | */ |
| 2560 | protected OnFocusChangeListener mOnFocusChangeListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2561 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2562 | /** |
| 2563 | * Listeners for layout change events. |
| 2564 | */ |
| 2565 | private ArrayList<OnLayoutChangeListener> mOnLayoutChangeListeners; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 2566 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2567 | /** |
| 2568 | * Listeners for attach events. |
| 2569 | */ |
| 2570 | private CopyOnWriteArrayList<OnAttachStateChangeListener> mOnAttachStateChangeListeners; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 2571 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2572 | /** |
| 2573 | * Listener used to dispatch click events. |
| 2574 | * This field should be made private, so it is hidden from the SDK. |
| 2575 | * {@hide} |
| 2576 | */ |
| 2577 | public OnClickListener mOnClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2578 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2579 | /** |
| 2580 | * Listener used to dispatch long click events. |
| 2581 | * This field should be made private, so it is hidden from the SDK. |
| 2582 | * {@hide} |
| 2583 | */ |
| 2584 | protected OnLongClickListener mOnLongClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2585 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2586 | /** |
| 2587 | * Listener used to build the context menu. |
| 2588 | * This field should be made private, so it is hidden from the SDK. |
| 2589 | * {@hide} |
| 2590 | */ |
| 2591 | protected OnCreateContextMenuListener mOnCreateContextMenuListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2592 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2593 | private OnKeyListener mOnKeyListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2594 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2595 | private OnTouchListener mOnTouchListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2596 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2597 | private OnHoverListener mOnHoverListener; |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2598 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2599 | private OnGenericMotionListener mOnGenericMotionListener; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2600 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2601 | private OnDragListener mOnDragListener; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 2602 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2603 | private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener; |
| 2604 | } |
| 2605 | |
| 2606 | ListenerInfo mListenerInfo; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2607 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2608 | /** |
| 2609 | * The application environment this view lives in. |
| 2610 | * This field should be made private, so it is hidden from the SDK. |
| 2611 | * {@hide} |
| 2612 | */ |
| 2613 | protected Context mContext; |
| 2614 | |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 2615 | private final Resources mResources; |
| 2616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | private ScrollabilityCache mScrollCache; |
| 2618 | |
| 2619 | private int[] mDrawableState = null; |
| 2620 | |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2621 | /** |
| 2622 | * Set to true when drawing cache is enabled and cannot be created. |
| 2623 | * |
| 2624 | * @hide |
| 2625 | */ |
| 2626 | public boolean mCachingFailed; |
| 2627 | |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 2628 | private Bitmap mDrawingCache; |
| 2629 | private Bitmap mUnscaledDrawingCache; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 2630 | private HardwareLayer mHardwareLayer; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2631 | DisplayList mDisplayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2632 | |
| 2633 | /** |
| 2634 | * When this view has focus and the next focus is {@link #FOCUS_LEFT}, |
| 2635 | * the user may specify which view to go to next. |
| 2636 | */ |
| 2637 | private int mNextFocusLeftId = View.NO_ID; |
| 2638 | |
| 2639 | /** |
| 2640 | * When this view has focus and the next focus is {@link #FOCUS_RIGHT}, |
| 2641 | * the user may specify which view to go to next. |
| 2642 | */ |
| 2643 | private int mNextFocusRightId = View.NO_ID; |
| 2644 | |
| 2645 | /** |
| 2646 | * When this view has focus and the next focus is {@link #FOCUS_UP}, |
| 2647 | * the user may specify which view to go to next. |
| 2648 | */ |
| 2649 | private int mNextFocusUpId = View.NO_ID; |
| 2650 | |
| 2651 | /** |
| 2652 | * When this view has focus and the next focus is {@link #FOCUS_DOWN}, |
| 2653 | * the user may specify which view to go to next. |
| 2654 | */ |
| 2655 | private int mNextFocusDownId = View.NO_ID; |
| 2656 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 2657 | /** |
| 2658 | * When this view has focus and the next focus is {@link #FOCUS_FORWARD}, |
| 2659 | * the user may specify which view to go to next. |
| 2660 | */ |
| 2661 | int mNextFocusForwardId = View.NO_ID; |
| 2662 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2663 | private CheckForLongPress mPendingCheckForLongPress; |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2664 | private CheckForTap mPendingCheckForTap = null; |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 2665 | private PerformClick mPerformClick; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 2666 | private SendViewScrolledAccessibilityEvent mSendViewScrolledAccessibilityEvent; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2667 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2668 | private UnsetPressedState mUnsetPressedState; |
| 2669 | |
| 2670 | /** |
| 2671 | * Whether the long press's action has been invoked. The tap's action is invoked on the |
| 2672 | * up event while a long press is invoked as soon as the long press duration is reached, so |
| 2673 | * a long press could be performed before the tap is checked, in which case the tap's action |
| 2674 | * should not be invoked. |
| 2675 | */ |
| 2676 | private boolean mHasPerformedLongPress; |
| 2677 | |
| 2678 | /** |
| 2679 | * The minimum height of the view. We'll try our best to have the height |
| 2680 | * of this view to at least this amount. |
| 2681 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2682 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2683 | private int mMinHeight; |
| 2684 | |
| 2685 | /** |
| 2686 | * The minimum width of the view. We'll try our best to have the width |
| 2687 | * of this view to at least this amount. |
| 2688 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2689 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2690 | private int mMinWidth; |
| 2691 | |
| 2692 | /** |
| 2693 | * The delegate to handle touch events that are physically in this view |
| 2694 | * but should be handled by another view. |
| 2695 | */ |
| 2696 | private TouchDelegate mTouchDelegate = null; |
| 2697 | |
| 2698 | /** |
| 2699 | * Solid color to use as a background when creating the drawing cache. Enables |
| 2700 | * the cache to use 16 bit bitmaps instead of 32 bit. |
| 2701 | */ |
| 2702 | private int mDrawingCacheBackgroundColor = 0; |
| 2703 | |
| 2704 | /** |
| 2705 | * Special tree observer used when mAttachInfo is null. |
| 2706 | */ |
| 2707 | private ViewTreeObserver mFloatingTreeObserver; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2708 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2709 | /** |
| 2710 | * Cache the touch slop from the context that created the view. |
| 2711 | */ |
| 2712 | private int mTouchSlop; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2713 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2714 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2715 | * Object that handles automatic animation of view properties. |
| 2716 | */ |
| 2717 | private ViewPropertyAnimator mAnimator = null; |
| 2718 | |
| 2719 | /** |
Christopher Tate | 251602f | 2011-01-28 17:54:12 -0800 | [diff] [blame] | 2720 | * Flag indicating that a drag can cross window boundaries. When |
| 2721 | * {@link #startDrag(ClipData, DragShadowBuilder, Object, int)} is called |
| 2722 | * with this flag set, all visible applications will be able to participate |
| 2723 | * in the drag operation and receive the dragged content. |
Christopher Tate | 7f9ff9d | 2011-02-14 17:31:13 -0800 | [diff] [blame] | 2724 | * |
| 2725 | * @hide |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 2726 | */ |
| 2727 | public static final int DRAG_FLAG_GLOBAL = 1; |
| 2728 | |
| 2729 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2730 | * Vertical scroll factor cached by {@link #getVerticalScrollFactor}. |
| 2731 | */ |
| 2732 | private float mVerticalScrollFactor; |
| 2733 | |
| 2734 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2735 | * Position of the vertical scroll bar. |
| 2736 | */ |
| 2737 | private int mVerticalScrollbarPosition; |
| 2738 | |
| 2739 | /** |
| 2740 | * Position the scroll bar at the default position as determined by the system. |
| 2741 | */ |
| 2742 | public static final int SCROLLBAR_POSITION_DEFAULT = 0; |
| 2743 | |
| 2744 | /** |
| 2745 | * Position the scroll bar along the left edge. |
| 2746 | */ |
| 2747 | public static final int SCROLLBAR_POSITION_LEFT = 1; |
| 2748 | |
| 2749 | /** |
| 2750 | * Position the scroll bar along the right edge. |
| 2751 | */ |
| 2752 | public static final int SCROLLBAR_POSITION_RIGHT = 2; |
| 2753 | |
| 2754 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2755 | * Indicates that the view does not have a layer. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2756 | * |
| 2757 | * @see #getLayerType() |
| 2758 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2759 | * @see #LAYER_TYPE_SOFTWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2760 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2761 | */ |
| 2762 | public static final int LAYER_TYPE_NONE = 0; |
| 2763 | |
| 2764 | /** |
| 2765 | * <p>Indicates that the view has a software layer. A software layer is backed |
| 2766 | * by a bitmap and causes the view to be rendered using Android's software |
| 2767 | * rendering pipeline, even if hardware acceleration is enabled.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2768 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2769 | * <p>Software layers have various usages:</p> |
| 2770 | * <p>When the application is not using hardware acceleration, a software layer |
| 2771 | * is useful to apply a specific color filter and/or blending mode and/or |
| 2772 | * translucency to a view and all its children.</p> |
| 2773 | * <p>When the application is using hardware acceleration, a software layer |
| 2774 | * is useful to render drawing primitives not supported by the hardware |
| 2775 | * accelerated pipeline. It can also be used to cache a complex view tree |
| 2776 | * into a texture and reduce the complexity of drawing operations. For instance, |
| 2777 | * when animating a complex view tree with a translation, a software layer can |
| 2778 | * be used to render the view tree only once.</p> |
| 2779 | * <p>Software layers should be avoided when the affected view tree updates |
| 2780 | * often. Every update will require to re-render the software layer, which can |
| 2781 | * potentially be slow (particularly when hardware acceleration is turned on |
| 2782 | * since the layer will have to be uploaded into a hardware texture after every |
| 2783 | * update.)</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2784 | * |
| 2785 | * @see #getLayerType() |
| 2786 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2787 | * @see #LAYER_TYPE_NONE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2788 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2789 | */ |
| 2790 | public static final int LAYER_TYPE_SOFTWARE = 1; |
| 2791 | |
| 2792 | /** |
| 2793 | * <p>Indicates that the view has a hardware layer. A hardware layer is backed |
| 2794 | * by a hardware specific texture (generally Frame Buffer Objects or FBO on |
| 2795 | * OpenGL hardware) and causes the view to be rendered using Android's hardware |
| 2796 | * rendering pipeline, but only if hardware acceleration is turned on for the |
| 2797 | * view hierarchy. When hardware acceleration is turned off, hardware layers |
| 2798 | * behave exactly as {@link #LAYER_TYPE_SOFTWARE software layers}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2799 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2800 | * <p>A hardware layer is useful to apply a specific color filter and/or |
| 2801 | * blending mode and/or translucency to a view and all its children.</p> |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 2802 | * <p>A hardware layer can be used to cache a complex view tree into a |
| 2803 | * texture and reduce the complexity of drawing operations. For instance, |
| 2804 | * when animating a complex view tree with a translation, a hardware layer can |
| 2805 | * be used to render the view tree only once.</p> |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2806 | * <p>A hardware layer can also be used to increase the rendering quality when |
| 2807 | * rotation transformations are applied on a view. It can also be used to |
| 2808 | * prevent potential clipping issues when applying 3D transforms on a view.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2809 | * |
| 2810 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2811 | * @see #setLayerType(int, android.graphics.Paint) |
| 2812 | * @see #LAYER_TYPE_NONE |
| 2813 | * @see #LAYER_TYPE_SOFTWARE |
| 2814 | */ |
| 2815 | public static final int LAYER_TYPE_HARDWARE = 2; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2816 | |
Romain Guy | 3aaff3a | 2011-01-12 14:18:47 -0800 | [diff] [blame] | 2817 | @ViewDebug.ExportedProperty(category = "drawing", mapping = { |
| 2818 | @ViewDebug.IntToString(from = LAYER_TYPE_NONE, to = "NONE"), |
| 2819 | @ViewDebug.IntToString(from = LAYER_TYPE_SOFTWARE, to = "SOFTWARE"), |
| 2820 | @ViewDebug.IntToString(from = LAYER_TYPE_HARDWARE, to = "HARDWARE") |
| 2821 | }) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2822 | int mLayerType = LAYER_TYPE_NONE; |
| 2823 | Paint mLayerPaint; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 2824 | Rect mLocalDirtyRect; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2825 | |
| 2826 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 2827 | * Set to true when the view is sending hover accessibility events because it |
| 2828 | * is the innermost hovered view. |
| 2829 | */ |
| 2830 | private boolean mSendingHoverAccessibilityEvents; |
| 2831 | |
| 2832 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 2833 | * Delegate for injecting accessiblity functionality. |
| 2834 | */ |
| 2835 | AccessibilityDelegate mAccessibilityDelegate; |
| 2836 | |
| 2837 | /** |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 2838 | * Consistency verifier for debugging purposes. |
| 2839 | * @hide |
| 2840 | */ |
| 2841 | protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = |
| 2842 | InputEventConsistencyVerifier.isInstrumentationEnabled() ? |
| 2843 | new InputEventConsistencyVerifier(this, 0) : null; |
| 2844 | |
| 2845 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2846 | * Simple constructor to use when creating a view from code. |
| 2847 | * |
| 2848 | * @param context The Context the view is running in, through which it can |
| 2849 | * access the current theme, resources, etc. |
| 2850 | */ |
| 2851 | public View(Context context) { |
| 2852 | mContext = context; |
| 2853 | mResources = context != null ? context.getResources() : null; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 2854 | mViewFlags = SOUND_EFFECTS_ENABLED | HAPTIC_FEEDBACK_ENABLED; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 2855 | // Set layout and text direction defaults |
| 2856 | mPrivateFlags2 = (LAYOUT_DIRECTION_DEFAULT << LAYOUT_DIRECTION_MASK_SHIFT) | |
| 2857 | (TEXT_DIRECTION_DEFAULT << TEXT_DIRECTION_MASK_SHIFT); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2858 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2859 | setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS); |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 2860 | mUserPaddingStart = -1; |
| 2861 | mUserPaddingEnd = -1; |
| 2862 | mUserPaddingRelative = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | /** |
| 2866 | * Constructor that is called when inflating a view from XML. This is called |
| 2867 | * when a view is being constructed from an XML file, supplying attributes |
| 2868 | * that were specified in the XML file. This version uses a default style of |
| 2869 | * 0, so the only attribute values applied are those in the Context's Theme |
| 2870 | * and the given AttributeSet. |
| 2871 | * |
| 2872 | * <p> |
| 2873 | * The method onFinishInflate() will be called after all children have been |
| 2874 | * added. |
| 2875 | * |
| 2876 | * @param context The Context the view is running in, through which it can |
| 2877 | * access the current theme, resources, etc. |
| 2878 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 2879 | * @see #View(Context, AttributeSet, int) |
| 2880 | */ |
| 2881 | public View(Context context, AttributeSet attrs) { |
| 2882 | this(context, attrs, 0); |
| 2883 | } |
| 2884 | |
| 2885 | /** |
| 2886 | * Perform inflation from XML and apply a class-specific base style. This |
| 2887 | * constructor of View allows subclasses to use their own base style when |
| 2888 | * they are inflating. For example, a Button class's constructor would call |
| 2889 | * this version of the super class constructor and supply |
| 2890 | * <code>R.attr.buttonStyle</code> for <var>defStyle</var>; this allows |
| 2891 | * the theme's button style to modify all of the base view attributes (in |
| 2892 | * particular its background) as well as the Button class's attributes. |
| 2893 | * |
| 2894 | * @param context The Context the view is running in, through which it can |
| 2895 | * access the current theme, resources, etc. |
| 2896 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 2897 | * @param defStyle The default style to apply to this view. If 0, no style |
| 2898 | * will be applied (beyond what is included in the theme). This may |
| 2899 | * either be an attribute resource, whose value will be retrieved |
| 2900 | * from the current theme, or an explicit style resource. |
| 2901 | * @see #View(Context, AttributeSet) |
| 2902 | */ |
| 2903 | public View(Context context, AttributeSet attrs, int defStyle) { |
| 2904 | this(context); |
| 2905 | |
| 2906 | TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View, |
| 2907 | defStyle, 0); |
| 2908 | |
| 2909 | Drawable background = null; |
| 2910 | |
| 2911 | int leftPadding = -1; |
| 2912 | int topPadding = -1; |
| 2913 | int rightPadding = -1; |
| 2914 | int bottomPadding = -1; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 2915 | int startPadding = -1; |
| 2916 | int endPadding = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2917 | |
| 2918 | int padding = -1; |
| 2919 | |
| 2920 | int viewFlagValues = 0; |
| 2921 | int viewFlagMasks = 0; |
| 2922 | |
| 2923 | boolean setScrollContainer = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2925 | int x = 0; |
| 2926 | int y = 0; |
| 2927 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 2928 | float tx = 0; |
| 2929 | float ty = 0; |
| 2930 | float rotation = 0; |
| 2931 | float rotationX = 0; |
| 2932 | float rotationY = 0; |
| 2933 | float sx = 1f; |
| 2934 | float sy = 1f; |
| 2935 | boolean transformSet = false; |
| 2936 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2937 | int scrollbarStyle = SCROLLBARS_INSIDE_OVERLAY; |
| 2938 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2939 | int overScrollMode = mOverScrollMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2940 | final int N = a.getIndexCount(); |
| 2941 | for (int i = 0; i < N; i++) { |
| 2942 | int attr = a.getIndex(i); |
| 2943 | switch (attr) { |
| 2944 | case com.android.internal.R.styleable.View_background: |
| 2945 | background = a.getDrawable(attr); |
| 2946 | break; |
| 2947 | case com.android.internal.R.styleable.View_padding: |
| 2948 | padding = a.getDimensionPixelSize(attr, -1); |
| 2949 | break; |
| 2950 | case com.android.internal.R.styleable.View_paddingLeft: |
| 2951 | leftPadding = a.getDimensionPixelSize(attr, -1); |
| 2952 | break; |
| 2953 | case com.android.internal.R.styleable.View_paddingTop: |
| 2954 | topPadding = a.getDimensionPixelSize(attr, -1); |
| 2955 | break; |
| 2956 | case com.android.internal.R.styleable.View_paddingRight: |
| 2957 | rightPadding = a.getDimensionPixelSize(attr, -1); |
| 2958 | break; |
| 2959 | case com.android.internal.R.styleable.View_paddingBottom: |
| 2960 | bottomPadding = a.getDimensionPixelSize(attr, -1); |
| 2961 | break; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 2962 | case com.android.internal.R.styleable.View_paddingStart: |
| 2963 | startPadding = a.getDimensionPixelSize(attr, -1); |
| 2964 | break; |
| 2965 | case com.android.internal.R.styleable.View_paddingEnd: |
| 2966 | endPadding = a.getDimensionPixelSize(attr, -1); |
| 2967 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2968 | case com.android.internal.R.styleable.View_scrollX: |
| 2969 | x = a.getDimensionPixelOffset(attr, 0); |
| 2970 | break; |
| 2971 | case com.android.internal.R.styleable.View_scrollY: |
| 2972 | y = a.getDimensionPixelOffset(attr, 0); |
| 2973 | break; |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 2974 | case com.android.internal.R.styleable.View_alpha: |
| 2975 | setAlpha(a.getFloat(attr, 1f)); |
| 2976 | break; |
| 2977 | case com.android.internal.R.styleable.View_transformPivotX: |
| 2978 | setPivotX(a.getDimensionPixelOffset(attr, 0)); |
| 2979 | break; |
| 2980 | case com.android.internal.R.styleable.View_transformPivotY: |
| 2981 | setPivotY(a.getDimensionPixelOffset(attr, 0)); |
| 2982 | break; |
| 2983 | case com.android.internal.R.styleable.View_translationX: |
| 2984 | tx = a.getDimensionPixelOffset(attr, 0); |
| 2985 | transformSet = true; |
| 2986 | break; |
| 2987 | case com.android.internal.R.styleable.View_translationY: |
| 2988 | ty = a.getDimensionPixelOffset(attr, 0); |
| 2989 | transformSet = true; |
| 2990 | break; |
| 2991 | case com.android.internal.R.styleable.View_rotation: |
| 2992 | rotation = a.getFloat(attr, 0); |
| 2993 | transformSet = true; |
| 2994 | break; |
| 2995 | case com.android.internal.R.styleable.View_rotationX: |
| 2996 | rotationX = a.getFloat(attr, 0); |
| 2997 | transformSet = true; |
| 2998 | break; |
| 2999 | case com.android.internal.R.styleable.View_rotationY: |
| 3000 | rotationY = a.getFloat(attr, 0); |
| 3001 | transformSet = true; |
| 3002 | break; |
| 3003 | case com.android.internal.R.styleable.View_scaleX: |
| 3004 | sx = a.getFloat(attr, 1f); |
| 3005 | transformSet = true; |
| 3006 | break; |
| 3007 | case com.android.internal.R.styleable.View_scaleY: |
| 3008 | sy = a.getFloat(attr, 1f); |
| 3009 | transformSet = true; |
| 3010 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3011 | case com.android.internal.R.styleable.View_id: |
| 3012 | mID = a.getResourceId(attr, NO_ID); |
| 3013 | break; |
| 3014 | case com.android.internal.R.styleable.View_tag: |
| 3015 | mTag = a.getText(attr); |
| 3016 | break; |
| 3017 | case com.android.internal.R.styleable.View_fitsSystemWindows: |
| 3018 | if (a.getBoolean(attr, false)) { |
| 3019 | viewFlagValues |= FITS_SYSTEM_WINDOWS; |
| 3020 | viewFlagMasks |= FITS_SYSTEM_WINDOWS; |
| 3021 | } |
| 3022 | break; |
| 3023 | case com.android.internal.R.styleable.View_focusable: |
| 3024 | if (a.getBoolean(attr, false)) { |
| 3025 | viewFlagValues |= FOCUSABLE; |
| 3026 | viewFlagMasks |= FOCUSABLE_MASK; |
| 3027 | } |
| 3028 | break; |
| 3029 | case com.android.internal.R.styleable.View_focusableInTouchMode: |
| 3030 | if (a.getBoolean(attr, false)) { |
| 3031 | viewFlagValues |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE; |
| 3032 | viewFlagMasks |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE_MASK; |
| 3033 | } |
| 3034 | break; |
| 3035 | case com.android.internal.R.styleable.View_clickable: |
| 3036 | if (a.getBoolean(attr, false)) { |
| 3037 | viewFlagValues |= CLICKABLE; |
| 3038 | viewFlagMasks |= CLICKABLE; |
| 3039 | } |
| 3040 | break; |
| 3041 | case com.android.internal.R.styleable.View_longClickable: |
| 3042 | if (a.getBoolean(attr, false)) { |
| 3043 | viewFlagValues |= LONG_CLICKABLE; |
| 3044 | viewFlagMasks |= LONG_CLICKABLE; |
| 3045 | } |
| 3046 | break; |
| 3047 | case com.android.internal.R.styleable.View_saveEnabled: |
| 3048 | if (!a.getBoolean(attr, true)) { |
| 3049 | viewFlagValues |= SAVE_DISABLED; |
| 3050 | viewFlagMasks |= SAVE_DISABLED_MASK; |
| 3051 | } |
| 3052 | break; |
| 3053 | case com.android.internal.R.styleable.View_duplicateParentState: |
| 3054 | if (a.getBoolean(attr, false)) { |
| 3055 | viewFlagValues |= DUPLICATE_PARENT_STATE; |
| 3056 | viewFlagMasks |= DUPLICATE_PARENT_STATE; |
| 3057 | } |
| 3058 | break; |
| 3059 | case com.android.internal.R.styleable.View_visibility: |
| 3060 | final int visibility = a.getInt(attr, 0); |
| 3061 | if (visibility != 0) { |
| 3062 | viewFlagValues |= VISIBILITY_FLAGS[visibility]; |
| 3063 | viewFlagMasks |= VISIBILITY_MASK; |
| 3064 | } |
| 3065 | break; |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 3066 | case com.android.internal.R.styleable.View_layoutDirection: |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3067 | // Clear any layout direction flags (included resolved bits) already set |
| 3068 | mPrivateFlags2 &= ~(LAYOUT_DIRECTION_MASK | LAYOUT_DIRECTION_RESOLVED_MASK); |
| 3069 | // Set the layout direction flags depending on the value of the attribute |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 3070 | final int layoutDirection = a.getInt(attr, -1); |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3071 | final int value = (layoutDirection != -1) ? |
| 3072 | LAYOUT_DIRECTION_FLAGS[layoutDirection] : LAYOUT_DIRECTION_DEFAULT; |
| 3073 | mPrivateFlags2 |= (value << LAYOUT_DIRECTION_MASK_SHIFT); |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 3074 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3075 | case com.android.internal.R.styleable.View_drawingCacheQuality: |
| 3076 | final int cacheQuality = a.getInt(attr, 0); |
| 3077 | if (cacheQuality != 0) { |
| 3078 | viewFlagValues |= DRAWING_CACHE_QUALITY_FLAGS[cacheQuality]; |
| 3079 | viewFlagMasks |= DRAWING_CACHE_QUALITY_MASK; |
| 3080 | } |
| 3081 | break; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3082 | case com.android.internal.R.styleable.View_contentDescription: |
| 3083 | mContentDescription = a.getString(attr); |
| 3084 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3085 | case com.android.internal.R.styleable.View_soundEffectsEnabled: |
| 3086 | if (!a.getBoolean(attr, true)) { |
| 3087 | viewFlagValues &= ~SOUND_EFFECTS_ENABLED; |
| 3088 | viewFlagMasks |= SOUND_EFFECTS_ENABLED; |
| 3089 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 3090 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3091 | case com.android.internal.R.styleable.View_hapticFeedbackEnabled: |
| 3092 | if (!a.getBoolean(attr, true)) { |
| 3093 | viewFlagValues &= ~HAPTIC_FEEDBACK_ENABLED; |
| 3094 | viewFlagMasks |= HAPTIC_FEEDBACK_ENABLED; |
| 3095 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 3096 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3097 | case R.styleable.View_scrollbars: |
| 3098 | final int scrollbars = a.getInt(attr, SCROLLBARS_NONE); |
| 3099 | if (scrollbars != SCROLLBARS_NONE) { |
| 3100 | viewFlagValues |= scrollbars; |
| 3101 | viewFlagMasks |= SCROLLBARS_MASK; |
| 3102 | initializeScrollbars(a); |
| 3103 | } |
| 3104 | break; |
Romain Guy | 2a9fa89 | 2011-09-28 16:50:02 -0700 | [diff] [blame] | 3105 | //noinspection deprecation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3106 | case R.styleable.View_fadingEdge: |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 3107 | if (context.getApplicationInfo().targetSdkVersion >= ICE_CREAM_SANDWICH) { |
| 3108 | // Ignore the attribute starting with ICS |
| 3109 | break; |
| 3110 | } |
| 3111 | // With builds < ICS, fall through and apply fading edges |
| 3112 | case R.styleable.View_requiresFadingEdge: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3113 | final int fadingEdge = a.getInt(attr, FADING_EDGE_NONE); |
| 3114 | if (fadingEdge != FADING_EDGE_NONE) { |
| 3115 | viewFlagValues |= fadingEdge; |
| 3116 | viewFlagMasks |= FADING_EDGE_MASK; |
| 3117 | initializeFadingEdge(a); |
| 3118 | } |
| 3119 | break; |
| 3120 | case R.styleable.View_scrollbarStyle: |
| 3121 | scrollbarStyle = a.getInt(attr, SCROLLBARS_INSIDE_OVERLAY); |
| 3122 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3123 | viewFlagValues |= scrollbarStyle & SCROLLBARS_STYLE_MASK; |
| 3124 | viewFlagMasks |= SCROLLBARS_STYLE_MASK; |
| 3125 | } |
| 3126 | break; |
| 3127 | case R.styleable.View_isScrollContainer: |
| 3128 | setScrollContainer = true; |
| 3129 | if (a.getBoolean(attr, false)) { |
| 3130 | setScrollContainer(true); |
| 3131 | } |
| 3132 | break; |
| 3133 | case com.android.internal.R.styleable.View_keepScreenOn: |
| 3134 | if (a.getBoolean(attr, false)) { |
| 3135 | viewFlagValues |= KEEP_SCREEN_ON; |
| 3136 | viewFlagMasks |= KEEP_SCREEN_ON; |
| 3137 | } |
| 3138 | break; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 3139 | case R.styleable.View_filterTouchesWhenObscured: |
| 3140 | if (a.getBoolean(attr, false)) { |
| 3141 | viewFlagValues |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3142 | viewFlagMasks |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3143 | } |
| 3144 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3145 | case R.styleable.View_nextFocusLeft: |
| 3146 | mNextFocusLeftId = a.getResourceId(attr, View.NO_ID); |
| 3147 | break; |
| 3148 | case R.styleable.View_nextFocusRight: |
| 3149 | mNextFocusRightId = a.getResourceId(attr, View.NO_ID); |
| 3150 | break; |
| 3151 | case R.styleable.View_nextFocusUp: |
| 3152 | mNextFocusUpId = a.getResourceId(attr, View.NO_ID); |
| 3153 | break; |
| 3154 | case R.styleable.View_nextFocusDown: |
| 3155 | mNextFocusDownId = a.getResourceId(attr, View.NO_ID); |
| 3156 | break; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 3157 | case R.styleable.View_nextFocusForward: |
| 3158 | mNextFocusForwardId = a.getResourceId(attr, View.NO_ID); |
| 3159 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3160 | case R.styleable.View_minWidth: |
| 3161 | mMinWidth = a.getDimensionPixelSize(attr, 0); |
| 3162 | break; |
| 3163 | case R.styleable.View_minHeight: |
| 3164 | mMinHeight = a.getDimensionPixelSize(attr, 0); |
| 3165 | break; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3166 | case R.styleable.View_onClick: |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3167 | if (context.isRestricted()) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3168 | throw new IllegalStateException("The android:onClick attribute cannot " |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3169 | + "be used within a restricted context"); |
| 3170 | } |
| 3171 | |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3172 | final String handlerName = a.getString(attr); |
| 3173 | if (handlerName != null) { |
| 3174 | setOnClickListener(new OnClickListener() { |
| 3175 | private Method mHandler; |
| 3176 | |
| 3177 | public void onClick(View v) { |
| 3178 | if (mHandler == null) { |
| 3179 | try { |
| 3180 | mHandler = getContext().getClass().getMethod(handlerName, |
| 3181 | View.class); |
| 3182 | } catch (NoSuchMethodException e) { |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3183 | int id = getId(); |
| 3184 | String idText = id == NO_ID ? "" : " with id '" |
| 3185 | + getContext().getResources().getResourceEntryName( |
| 3186 | id) + "'"; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3187 | throw new IllegalStateException("Could not find a method " + |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3188 | handlerName + "(View) in the activity " |
| 3189 | + getContext().getClass() + " for onClick handler" |
| 3190 | + " on view " + View.this.getClass() + idText, e); |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3191 | } |
| 3192 | } |
| 3193 | |
| 3194 | try { |
| 3195 | mHandler.invoke(getContext(), View.this); |
| 3196 | } catch (IllegalAccessException e) { |
| 3197 | throw new IllegalStateException("Could not execute non " |
| 3198 | + "public method of the activity", e); |
| 3199 | } catch (InvocationTargetException e) { |
| 3200 | throw new IllegalStateException("Could not execute " |
| 3201 | + "method of the activity", e); |
| 3202 | } |
| 3203 | } |
| 3204 | }); |
| 3205 | } |
| 3206 | break; |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3207 | case R.styleable.View_overScrollMode: |
| 3208 | overScrollMode = a.getInt(attr, OVER_SCROLL_IF_CONTENT_SCROLLS); |
| 3209 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3210 | case R.styleable.View_verticalScrollbarPosition: |
| 3211 | mVerticalScrollbarPosition = a.getInt(attr, SCROLLBAR_POSITION_DEFAULT); |
| 3212 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3213 | case R.styleable.View_layerType: |
| 3214 | setLayerType(a.getInt(attr, LAYER_TYPE_NONE), null); |
| 3215 | break; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3216 | case R.styleable.View_textDirection: |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3217 | // Clear any text direction flag already set |
| 3218 | mPrivateFlags2 &= ~TEXT_DIRECTION_MASK; |
| 3219 | // Set the text direction flags depending on the value of the attribute |
| 3220 | final int textDirection = a.getInt(attr, -1); |
| 3221 | if (textDirection != -1) { |
| 3222 | mPrivateFlags2 |= TEXT_DIRECTION_FLAGS[textDirection]; |
| 3223 | } |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3224 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3225 | } |
| 3226 | } |
| 3227 | |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 3228 | a.recycle(); |
| 3229 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3230 | setOverScrollMode(overScrollMode); |
| 3231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3232 | if (background != null) { |
| 3233 | setBackgroundDrawable(background); |
| 3234 | } |
| 3235 | |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 3236 | // Cache user padding as we cannot fully resolve padding here (we dont have yet the resolved |
| 3237 | // layout direction). Those cached values will be used later during padding resolution. |
| 3238 | mUserPaddingStart = startPadding; |
| 3239 | mUserPaddingEnd = endPadding; |
| 3240 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 3241 | updateUserPaddingRelative(); |
| 3242 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3243 | if (padding >= 0) { |
| 3244 | leftPadding = padding; |
| 3245 | topPadding = padding; |
| 3246 | rightPadding = padding; |
| 3247 | bottomPadding = padding; |
| 3248 | } |
| 3249 | |
| 3250 | // If the user specified the padding (either with android:padding or |
| 3251 | // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise |
| 3252 | // use the default padding or the padding from the background drawable |
| 3253 | // (stored at this point in mPadding*) |
| 3254 | setPadding(leftPadding >= 0 ? leftPadding : mPaddingLeft, |
| 3255 | topPadding >= 0 ? topPadding : mPaddingTop, |
| 3256 | rightPadding >= 0 ? rightPadding : mPaddingRight, |
| 3257 | bottomPadding >= 0 ? bottomPadding : mPaddingBottom); |
| 3258 | |
| 3259 | if (viewFlagMasks != 0) { |
| 3260 | setFlags(viewFlagValues, viewFlagMasks); |
| 3261 | } |
| 3262 | |
| 3263 | // Needs to be called after mViewFlags is set |
| 3264 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3265 | recomputePadding(); |
| 3266 | } |
| 3267 | |
| 3268 | if (x != 0 || y != 0) { |
| 3269 | scrollTo(x, y); |
| 3270 | } |
| 3271 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3272 | if (transformSet) { |
| 3273 | setTranslationX(tx); |
| 3274 | setTranslationY(ty); |
| 3275 | setRotation(rotation); |
| 3276 | setRotationX(rotationX); |
| 3277 | setRotationY(rotationY); |
| 3278 | setScaleX(sx); |
| 3279 | setScaleY(sy); |
| 3280 | } |
| 3281 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3282 | if (!setScrollContainer && (viewFlagValues&SCROLLBARS_VERTICAL) != 0) { |
| 3283 | setScrollContainer(true); |
| 3284 | } |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 3285 | |
| 3286 | computeOpaqueFlags(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3287 | } |
| 3288 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 3289 | private void updateUserPaddingRelative() { |
| 3290 | mUserPaddingRelative = (mUserPaddingStart >= 0 || mUserPaddingEnd >= 0); |
| 3291 | } |
| 3292 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3293 | /** |
| 3294 | * Non-public constructor for use in testing |
| 3295 | */ |
| 3296 | View() { |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 3297 | mResources = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3298 | } |
| 3299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3300 | /** |
| 3301 | * <p> |
| 3302 | * Initializes the fading edges from a given set of styled attributes. This |
| 3303 | * method should be called by subclasses that need fading edges and when an |
| 3304 | * instance of these subclasses is created programmatically rather than |
| 3305 | * being inflated from XML. This method is automatically called when the XML |
| 3306 | * is inflated. |
| 3307 | * </p> |
| 3308 | * |
| 3309 | * @param a the styled attributes set to initialize the fading edges from |
| 3310 | */ |
| 3311 | protected void initializeFadingEdge(TypedArray a) { |
| 3312 | initScrollCache(); |
| 3313 | |
| 3314 | mScrollCache.fadingEdgeLength = a.getDimensionPixelSize( |
| 3315 | R.styleable.View_fadingEdgeLength, |
| 3316 | ViewConfiguration.get(mContext).getScaledFadingEdgeLength()); |
| 3317 | } |
| 3318 | |
| 3319 | /** |
| 3320 | * Returns the size of the vertical faded edges used to indicate that more |
| 3321 | * content in this view is visible. |
| 3322 | * |
| 3323 | * @return The size in pixels of the vertical faded edge or 0 if vertical |
| 3324 | * faded edges are not enabled for this view. |
| 3325 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3326 | */ |
| 3327 | public int getVerticalFadingEdgeLength() { |
| 3328 | if (isVerticalFadingEdgeEnabled()) { |
| 3329 | ScrollabilityCache cache = mScrollCache; |
| 3330 | if (cache != null) { |
| 3331 | return cache.fadingEdgeLength; |
| 3332 | } |
| 3333 | } |
| 3334 | return 0; |
| 3335 | } |
| 3336 | |
| 3337 | /** |
| 3338 | * Set the size of the faded edge used to indicate that more content in this |
| 3339 | * view is available. Will not change whether the fading edge is enabled; use |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 3340 | * {@link #setVerticalFadingEdgeEnabled(boolean)} or |
| 3341 | * {@link #setHorizontalFadingEdgeEnabled(boolean)} to enable the fading edge |
| 3342 | * for the vertical or horizontal fading edges. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | * |
| 3344 | * @param length The size in pixels of the faded edge used to indicate that more |
| 3345 | * content in this view is visible. |
| 3346 | */ |
| 3347 | public void setFadingEdgeLength(int length) { |
| 3348 | initScrollCache(); |
| 3349 | mScrollCache.fadingEdgeLength = length; |
| 3350 | } |
| 3351 | |
| 3352 | /** |
| 3353 | * Returns the size of the horizontal faded edges used to indicate that more |
| 3354 | * content in this view is visible. |
| 3355 | * |
| 3356 | * @return The size in pixels of the horizontal faded edge or 0 if horizontal |
| 3357 | * faded edges are not enabled for this view. |
| 3358 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3359 | */ |
| 3360 | public int getHorizontalFadingEdgeLength() { |
| 3361 | if (isHorizontalFadingEdgeEnabled()) { |
| 3362 | ScrollabilityCache cache = mScrollCache; |
| 3363 | if (cache != null) { |
| 3364 | return cache.fadingEdgeLength; |
| 3365 | } |
| 3366 | } |
| 3367 | return 0; |
| 3368 | } |
| 3369 | |
| 3370 | /** |
| 3371 | * Returns the width of the vertical scrollbar. |
| 3372 | * |
| 3373 | * @return The width in pixels of the vertical scrollbar or 0 if there |
| 3374 | * is no vertical scrollbar. |
| 3375 | */ |
| 3376 | public int getVerticalScrollbarWidth() { |
| 3377 | ScrollabilityCache cache = mScrollCache; |
| 3378 | if (cache != null) { |
| 3379 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3380 | if (scrollBar != null) { |
| 3381 | int size = scrollBar.getSize(true); |
| 3382 | if (size <= 0) { |
| 3383 | size = cache.scrollBarSize; |
| 3384 | } |
| 3385 | return size; |
| 3386 | } |
| 3387 | return 0; |
| 3388 | } |
| 3389 | return 0; |
| 3390 | } |
| 3391 | |
| 3392 | /** |
| 3393 | * Returns the height of the horizontal scrollbar. |
| 3394 | * |
| 3395 | * @return The height in pixels of the horizontal scrollbar or 0 if |
| 3396 | * there is no horizontal scrollbar. |
| 3397 | */ |
| 3398 | protected int getHorizontalScrollbarHeight() { |
| 3399 | ScrollabilityCache cache = mScrollCache; |
| 3400 | if (cache != null) { |
| 3401 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3402 | if (scrollBar != null) { |
| 3403 | int size = scrollBar.getSize(false); |
| 3404 | if (size <= 0) { |
| 3405 | size = cache.scrollBarSize; |
| 3406 | } |
| 3407 | return size; |
| 3408 | } |
| 3409 | return 0; |
| 3410 | } |
| 3411 | return 0; |
| 3412 | } |
| 3413 | |
| 3414 | /** |
| 3415 | * <p> |
| 3416 | * Initializes the scrollbars from a given set of styled attributes. This |
| 3417 | * method should be called by subclasses that need scrollbars and when an |
| 3418 | * instance of these subclasses is created programmatically rather than |
| 3419 | * being inflated from XML. This method is automatically called when the XML |
| 3420 | * is inflated. |
| 3421 | * </p> |
| 3422 | * |
| 3423 | * @param a the styled attributes set to initialize the scrollbars from |
| 3424 | */ |
| 3425 | protected void initializeScrollbars(TypedArray a) { |
| 3426 | initScrollCache(); |
| 3427 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3428 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3429 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3430 | if (scrollabilityCache.scrollBar == null) { |
| 3431 | scrollabilityCache.scrollBar = new ScrollBarDrawable(); |
| 3432 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3433 | |
Romain Guy | 8bda248 | 2010-03-02 11:42:11 -0800 | [diff] [blame] | 3434 | final boolean fadeScrollbars = a.getBoolean(R.styleable.View_fadeScrollbars, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3435 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3436 | if (!fadeScrollbars) { |
| 3437 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 3438 | } |
| 3439 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3440 | |
| 3441 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3442 | scrollabilityCache.scrollBarFadeDuration = a.getInt( |
| 3443 | R.styleable.View_scrollbarFadeDuration, ViewConfiguration |
| 3444 | .getScrollBarFadeDuration()); |
| 3445 | scrollabilityCache.scrollBarDefaultDelayBeforeFade = a.getInt( |
| 3446 | R.styleable.View_scrollbarDefaultDelayBeforeFade, |
| 3447 | ViewConfiguration.getScrollDefaultDelay()); |
| 3448 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3449 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3450 | scrollabilityCache.scrollBarSize = a.getDimensionPixelSize( |
| 3451 | com.android.internal.R.styleable.View_scrollbarSize, |
| 3452 | ViewConfiguration.get(mContext).getScaledScrollBarSize()); |
| 3453 | |
| 3454 | Drawable track = a.getDrawable(R.styleable.View_scrollbarTrackHorizontal); |
| 3455 | scrollabilityCache.scrollBar.setHorizontalTrackDrawable(track); |
| 3456 | |
| 3457 | Drawable thumb = a.getDrawable(R.styleable.View_scrollbarThumbHorizontal); |
| 3458 | if (thumb != null) { |
| 3459 | scrollabilityCache.scrollBar.setHorizontalThumbDrawable(thumb); |
| 3460 | } |
| 3461 | |
| 3462 | boolean alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawHorizontalTrack, |
| 3463 | false); |
| 3464 | if (alwaysDraw) { |
| 3465 | scrollabilityCache.scrollBar.setAlwaysDrawHorizontalTrack(true); |
| 3466 | } |
| 3467 | |
| 3468 | track = a.getDrawable(R.styleable.View_scrollbarTrackVertical); |
| 3469 | scrollabilityCache.scrollBar.setVerticalTrackDrawable(track); |
| 3470 | |
| 3471 | thumb = a.getDrawable(R.styleable.View_scrollbarThumbVertical); |
| 3472 | if (thumb != null) { |
| 3473 | scrollabilityCache.scrollBar.setVerticalThumbDrawable(thumb); |
| 3474 | } |
| 3475 | |
| 3476 | alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawVerticalTrack, |
| 3477 | false); |
| 3478 | if (alwaysDraw) { |
| 3479 | scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true); |
| 3480 | } |
| 3481 | |
| 3482 | // Re-apply user/background padding so that scrollbar(s) get added |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3483 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3484 | } |
| 3485 | |
| 3486 | /** |
| 3487 | * <p> |
| 3488 | * Initalizes the scrollability cache if necessary. |
| 3489 | * </p> |
| 3490 | */ |
| 3491 | private void initScrollCache() { |
| 3492 | if (mScrollCache == null) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3493 | mScrollCache = new ScrollabilityCache(ViewConfiguration.get(mContext), this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3498 | * Set the position of the vertical scroll bar. Should be one of |
| 3499 | * {@link #SCROLLBAR_POSITION_DEFAULT}, {@link #SCROLLBAR_POSITION_LEFT} or |
| 3500 | * {@link #SCROLLBAR_POSITION_RIGHT}. |
| 3501 | * |
| 3502 | * @param position Where the vertical scroll bar should be positioned. |
| 3503 | */ |
| 3504 | public void setVerticalScrollbarPosition(int position) { |
| 3505 | if (mVerticalScrollbarPosition != position) { |
| 3506 | mVerticalScrollbarPosition = position; |
| 3507 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3508 | resolvePadding(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3509 | } |
| 3510 | } |
| 3511 | |
| 3512 | /** |
| 3513 | * @return The position where the vertical scroll bar will show, if applicable. |
| 3514 | * @see #setVerticalScrollbarPosition(int) |
| 3515 | */ |
| 3516 | public int getVerticalScrollbarPosition() { |
| 3517 | return mVerticalScrollbarPosition; |
| 3518 | } |
| 3519 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3520 | ListenerInfo getListenerInfo() { |
| 3521 | if (mListenerInfo != null) { |
| 3522 | return mListenerInfo; |
| 3523 | } |
| 3524 | mListenerInfo = new ListenerInfo(); |
| 3525 | return mListenerInfo; |
| 3526 | } |
| 3527 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3528 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3529 | * Register a callback to be invoked when focus of this view changed. |
| 3530 | * |
| 3531 | * @param l The callback that will run. |
| 3532 | */ |
| 3533 | public void setOnFocusChangeListener(OnFocusChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3534 | getListenerInfo().mOnFocusChangeListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3535 | } |
| 3536 | |
| 3537 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3538 | * Add a listener that will be called when the bounds of the view change due to |
| 3539 | * layout processing. |
| 3540 | * |
| 3541 | * @param listener The listener that will be called when layout bounds change. |
| 3542 | */ |
| 3543 | public void addOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3544 | ListenerInfo li = getListenerInfo(); |
| 3545 | if (li.mOnLayoutChangeListeners == null) { |
| 3546 | li.mOnLayoutChangeListeners = new ArrayList<OnLayoutChangeListener>(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3547 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3548 | if (!li.mOnLayoutChangeListeners.contains(listener)) { |
| 3549 | li.mOnLayoutChangeListeners.add(listener); |
Chet Haase | 1a76dcd | 2011-10-06 11:16:40 -0700 | [diff] [blame] | 3550 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3551 | } |
| 3552 | |
| 3553 | /** |
| 3554 | * Remove a listener for layout changes. |
| 3555 | * |
| 3556 | * @param listener The listener for layout bounds change. |
| 3557 | */ |
| 3558 | public void removeOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3559 | ListenerInfo li = mListenerInfo; |
| 3560 | if (li == null || li.mOnLayoutChangeListeners == null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3561 | return; |
| 3562 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3563 | li.mOnLayoutChangeListeners.remove(listener); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | /** |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3567 | * Add a listener for attach state changes. |
| 3568 | * |
| 3569 | * This listener will be called whenever this view is attached or detached |
| 3570 | * from a window. Remove the listener using |
| 3571 | * {@link #removeOnAttachStateChangeListener(OnAttachStateChangeListener)}. |
| 3572 | * |
| 3573 | * @param listener Listener to attach |
| 3574 | * @see #removeOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 3575 | */ |
| 3576 | public void addOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3577 | ListenerInfo li = getListenerInfo(); |
| 3578 | if (li.mOnAttachStateChangeListeners == null) { |
| 3579 | li.mOnAttachStateChangeListeners |
| 3580 | = new CopyOnWriteArrayList<OnAttachStateChangeListener>(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3581 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3582 | li.mOnAttachStateChangeListeners.add(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3583 | } |
| 3584 | |
| 3585 | /** |
| 3586 | * Remove a listener for attach state changes. The listener will receive no further |
| 3587 | * notification of window attach/detach events. |
| 3588 | * |
| 3589 | * @param listener Listener to remove |
| 3590 | * @see #addOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 3591 | */ |
| 3592 | public void removeOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3593 | ListenerInfo li = mListenerInfo; |
| 3594 | if (li == null || li.mOnAttachStateChangeListeners == null) { |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3595 | return; |
| 3596 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3597 | li.mOnAttachStateChangeListeners.remove(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3601 | * Returns the focus-change callback registered for this view. |
| 3602 | * |
| 3603 | * @return The callback, or null if one is not registered. |
| 3604 | */ |
| 3605 | public OnFocusChangeListener getOnFocusChangeListener() { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3606 | ListenerInfo li = mListenerInfo; |
| 3607 | return li != null ? li.mOnFocusChangeListener : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3608 | } |
| 3609 | |
| 3610 | /** |
| 3611 | * Register a callback to be invoked when this view is clicked. If this view is not |
| 3612 | * clickable, it becomes clickable. |
| 3613 | * |
| 3614 | * @param l The callback that will run |
| 3615 | * |
| 3616 | * @see #setClickable(boolean) |
| 3617 | */ |
| 3618 | public void setOnClickListener(OnClickListener l) { |
| 3619 | if (!isClickable()) { |
| 3620 | setClickable(true); |
| 3621 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3622 | getListenerInfo().mOnClickListener = l; |
| 3623 | } |
| 3624 | |
| 3625 | /** |
| 3626 | * Return whether this view has an attached OnClickListener. Returns |
| 3627 | * true if there is a listener, false if there is none. |
| 3628 | */ |
| 3629 | public boolean hasOnClickListeners() { |
| 3630 | ListenerInfo li = mListenerInfo; |
| 3631 | return (li != null && li.mOnClickListener != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3632 | } |
| 3633 | |
| 3634 | /** |
| 3635 | * Register a callback to be invoked when this view is clicked and held. If this view is not |
| 3636 | * long clickable, it becomes long clickable. |
| 3637 | * |
| 3638 | * @param l The callback that will run |
| 3639 | * |
| 3640 | * @see #setLongClickable(boolean) |
| 3641 | */ |
| 3642 | public void setOnLongClickListener(OnLongClickListener l) { |
| 3643 | if (!isLongClickable()) { |
| 3644 | setLongClickable(true); |
| 3645 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3646 | getListenerInfo().mOnLongClickListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | /** |
| 3650 | * Register a callback to be invoked when the context menu for this view is |
| 3651 | * being built. If this view is not long clickable, it becomes long clickable. |
| 3652 | * |
| 3653 | * @param l The callback that will run |
| 3654 | * |
| 3655 | */ |
| 3656 | public void setOnCreateContextMenuListener(OnCreateContextMenuListener l) { |
| 3657 | if (!isLongClickable()) { |
| 3658 | setLongClickable(true); |
| 3659 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3660 | getListenerInfo().mOnCreateContextMenuListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3664 | * Call this view's OnClickListener, if it is defined. Performs all normal |
| 3665 | * actions associated with clicking: reporting accessibility event, playing |
| 3666 | * a sound, etc. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3667 | * |
| 3668 | * @return True there was an assigned OnClickListener that was called, false |
| 3669 | * otherwise is returned. |
| 3670 | */ |
| 3671 | public boolean performClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3672 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); |
| 3673 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3674 | ListenerInfo li = mListenerInfo; |
| 3675 | if (li != null && li.mOnClickListener != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3676 | playSoundEffect(SoundEffectConstants.CLICK); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3677 | li.mOnClickListener.onClick(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3678 | return true; |
| 3679 | } |
| 3680 | |
| 3681 | return false; |
| 3682 | } |
| 3683 | |
| 3684 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3685 | * Directly call any attached OnClickListener. Unlike {@link #performClick()}, |
| 3686 | * this only calls the listener, and does not do any associated clicking |
| 3687 | * actions like reporting an accessibility event. |
| 3688 | * |
| 3689 | * @return True there was an assigned OnClickListener that was called, false |
| 3690 | * otherwise is returned. |
| 3691 | */ |
| 3692 | public boolean callOnClick() { |
| 3693 | ListenerInfo li = mListenerInfo; |
| 3694 | if (li != null && li.mOnClickListener != null) { |
| 3695 | li.mOnClickListener.onClick(this); |
| 3696 | return true; |
| 3697 | } |
| 3698 | return false; |
| 3699 | } |
| 3700 | |
| 3701 | /** |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 3702 | * Call this view's OnLongClickListener, if it is defined. Invokes the context menu if the |
| 3703 | * OnLongClickListener did not consume the event. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3704 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 3705 | * @return True if one of the above receivers consumed the event, false otherwise. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3706 | */ |
| 3707 | public boolean performLongClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3708 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); |
| 3709 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3710 | boolean handled = false; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3711 | ListenerInfo li = mListenerInfo; |
| 3712 | if (li != null && li.mOnLongClickListener != null) { |
| 3713 | handled = li.mOnLongClickListener.onLongClick(View.this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3714 | } |
| 3715 | if (!handled) { |
| 3716 | handled = showContextMenu(); |
| 3717 | } |
| 3718 | if (handled) { |
| 3719 | performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); |
| 3720 | } |
| 3721 | return handled; |
| 3722 | } |
| 3723 | |
| 3724 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3725 | * Performs button-related actions during a touch down event. |
| 3726 | * |
| 3727 | * @param event The event. |
| 3728 | * @return True if the down was consumed. |
| 3729 | * |
| 3730 | * @hide |
| 3731 | */ |
| 3732 | protected boolean performButtonActionOnTouchDown(MotionEvent event) { |
| 3733 | if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) { |
| 3734 | if (showContextMenu(event.getX(), event.getY(), event.getMetaState())) { |
| 3735 | return true; |
| 3736 | } |
| 3737 | } |
| 3738 | return false; |
| 3739 | } |
| 3740 | |
| 3741 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3742 | * Bring up the context menu for this view. |
| 3743 | * |
| 3744 | * @return Whether a context menu was displayed. |
| 3745 | */ |
| 3746 | public boolean showContextMenu() { |
| 3747 | return getParent().showContextMenuForChild(this); |
| 3748 | } |
| 3749 | |
| 3750 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3751 | * Bring up the context menu for this view, referring to the item under the specified point. |
| 3752 | * |
| 3753 | * @param x The referenced x coordinate. |
| 3754 | * @param y The referenced y coordinate. |
| 3755 | * @param metaState The keyboard modifiers that were pressed. |
| 3756 | * @return Whether a context menu was displayed. |
| 3757 | * |
| 3758 | * @hide |
| 3759 | */ |
| 3760 | public boolean showContextMenu(float x, float y, int metaState) { |
| 3761 | return showContextMenu(); |
| 3762 | } |
| 3763 | |
| 3764 | /** |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 3765 | * Start an action mode. |
| 3766 | * |
| 3767 | * @param callback Callback that will control the lifecycle of the action mode |
| 3768 | * @return The new action mode if it is started, null otherwise |
| 3769 | * |
| 3770 | * @see ActionMode |
| 3771 | */ |
| 3772 | public ActionMode startActionMode(ActionMode.Callback callback) { |
John Reck | 5160e2a | 2012-02-22 09:35:12 -0800 | [diff] [blame] | 3773 | ViewParent parent = getParent(); |
| 3774 | if (parent == null) return null; |
| 3775 | return parent.startActionModeForChild(this, callback); |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 3776 | } |
| 3777 | |
| 3778 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3779 | * Register a callback to be invoked when a key is pressed in this view. |
| 3780 | * @param l the key listener to attach to this view |
| 3781 | */ |
| 3782 | public void setOnKeyListener(OnKeyListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3783 | getListenerInfo().mOnKeyListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | /** |
| 3787 | * Register a callback to be invoked when a touch event is sent to this view. |
| 3788 | * @param l the touch listener to attach to this view |
| 3789 | */ |
| 3790 | public void setOnTouchListener(OnTouchListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3791 | getListenerInfo().mOnTouchListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3795 | * Register a callback to be invoked when a generic motion event is sent to this view. |
| 3796 | * @param l the generic motion listener to attach to this view |
| 3797 | */ |
| 3798 | public void setOnGenericMotionListener(OnGenericMotionListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3799 | getListenerInfo().mOnGenericMotionListener = l; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | /** |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 3803 | * Register a callback to be invoked when a hover event is sent to this view. |
| 3804 | * @param l the hover listener to attach to this view |
| 3805 | */ |
| 3806 | public void setOnHoverListener(OnHoverListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3807 | getListenerInfo().mOnHoverListener = l; |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3811 | * Register a drag event listener callback object for this View. The parameter is |
| 3812 | * an implementation of {@link android.view.View.OnDragListener}. To send a drag event to a |
| 3813 | * View, the system calls the |
| 3814 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent)} method. |
| 3815 | * @param l An implementation of {@link android.view.View.OnDragListener}. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 3816 | */ |
| 3817 | public void setOnDragListener(OnDragListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3818 | getListenerInfo().mOnDragListener = l; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 3819 | } |
| 3820 | |
| 3821 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 3822 | * Give this view focus. This will cause |
| 3823 | * {@link #onFocusChanged(boolean, int, android.graphics.Rect)} to be called. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3824 | * |
| 3825 | * Note: this does not check whether this {@link View} should get focus, it just |
| 3826 | * gives it focus no matter what. It should only be called internally by framework |
| 3827 | * code that knows what it is doing, namely {@link #requestFocus(int, Rect)}. |
| 3828 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 3829 | * @param direction values are {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN}, |
| 3830 | * {@link View#FOCUS_LEFT} or {@link View#FOCUS_RIGHT}. This is the direction which |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3831 | * focus moved when requestFocus() is called. It may not always |
| 3832 | * apply, in which case use the default View.FOCUS_DOWN. |
| 3833 | * @param previouslyFocusedRect The rectangle of the view that had focus |
| 3834 | * prior in this View's coordinate system. |
| 3835 | */ |
| 3836 | void handleFocusGainInternal(int direction, Rect previouslyFocusedRect) { |
| 3837 | if (DBG) { |
| 3838 | System.out.println(this + " requestFocus()"); |
| 3839 | } |
| 3840 | |
| 3841 | if ((mPrivateFlags & FOCUSED) == 0) { |
| 3842 | mPrivateFlags |= FOCUSED; |
| 3843 | |
| 3844 | if (mParent != null) { |
| 3845 | mParent.requestChildFocus(this, this); |
| 3846 | } |
| 3847 | |
| 3848 | onFocusChanged(true, direction, previouslyFocusedRect); |
| 3849 | refreshDrawableState(); |
| 3850 | } |
| 3851 | } |
| 3852 | |
| 3853 | /** |
| 3854 | * Request that a rectangle of this view be visible on the screen, |
| 3855 | * scrolling if necessary just enough. |
| 3856 | * |
| 3857 | * <p>A View should call this if it maintains some notion of which part |
| 3858 | * of its content is interesting. For example, a text editing view |
| 3859 | * should call this when its cursor moves. |
| 3860 | * |
| 3861 | * @param rectangle The rectangle. |
| 3862 | * @return Whether any parent scrolled. |
| 3863 | */ |
| 3864 | public boolean requestRectangleOnScreen(Rect rectangle) { |
| 3865 | return requestRectangleOnScreen(rectangle, false); |
| 3866 | } |
| 3867 | |
| 3868 | /** |
| 3869 | * Request that a rectangle of this view be visible on the screen, |
| 3870 | * scrolling if necessary just enough. |
| 3871 | * |
| 3872 | * <p>A View should call this if it maintains some notion of which part |
| 3873 | * of its content is interesting. For example, a text editing view |
| 3874 | * should call this when its cursor moves. |
| 3875 | * |
| 3876 | * <p>When <code>immediate</code> is set to true, scrolling will not be |
| 3877 | * animated. |
| 3878 | * |
| 3879 | * @param rectangle The rectangle. |
| 3880 | * @param immediate True to forbid animated scrolling, false otherwise |
| 3881 | * @return Whether any parent scrolled. |
| 3882 | */ |
| 3883 | public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) { |
| 3884 | View child = this; |
| 3885 | ViewParent parent = mParent; |
| 3886 | boolean scrolled = false; |
| 3887 | while (parent != null) { |
| 3888 | scrolled |= parent.requestChildRectangleOnScreen(child, |
| 3889 | rectangle, immediate); |
| 3890 | |
| 3891 | // offset rect so next call has the rectangle in the |
| 3892 | // coordinate system of its direct child. |
| 3893 | rectangle.offset(child.getLeft(), child.getTop()); |
| 3894 | rectangle.offset(-child.getScrollX(), -child.getScrollY()); |
| 3895 | |
| 3896 | if (!(parent instanceof View)) { |
| 3897 | break; |
| 3898 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3899 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3900 | child = (View) parent; |
| 3901 | parent = child.getParent(); |
| 3902 | } |
| 3903 | return scrolled; |
| 3904 | } |
| 3905 | |
| 3906 | /** |
Svetoslav Ganov | 13fd561 | 2012-02-01 17:01:12 -0800 | [diff] [blame] | 3907 | * Called when this view wants to give up focus. If focus is cleared |
| 3908 | * {@link #onFocusChanged(boolean, int, android.graphics.Rect)} is called. |
| 3909 | * <p> |
| 3910 | * <strong>Note:</strong> When a View clears focus the framework is trying |
| 3911 | * to give focus to the first focusable View from the top. Hence, if this |
| 3912 | * View is the first from the top that can take focus, then its focus will |
| 3913 | * not be cleared nor will the focus change callback be invoked. |
| 3914 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3915 | */ |
| 3916 | public void clearFocus() { |
| 3917 | if (DBG) { |
| 3918 | System.out.println(this + " clearFocus()"); |
| 3919 | } |
| 3920 | |
| 3921 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 3922 | mPrivateFlags &= ~FOCUSED; |
| 3923 | |
| 3924 | if (mParent != null) { |
| 3925 | mParent.clearChildFocus(this); |
| 3926 | } |
| 3927 | |
| 3928 | onFocusChanged(false, 0, null); |
| 3929 | refreshDrawableState(); |
| 3930 | } |
| 3931 | } |
| 3932 | |
| 3933 | /** |
| 3934 | * Called to clear the focus of a view that is about to be removed. |
| 3935 | * Doesn't call clearChildFocus, which prevents this view from taking |
| 3936 | * focus again before it has been removed from the parent |
| 3937 | */ |
| 3938 | void clearFocusForRemoval() { |
| 3939 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 3940 | mPrivateFlags &= ~FOCUSED; |
| 3941 | |
| 3942 | onFocusChanged(false, 0, null); |
| 3943 | refreshDrawableState(); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3944 | |
| 3945 | // The view cleared focus and invoked the callbacks, so now is the |
| 3946 | // time to give focus to the the first focusable from the top to |
| 3947 | // ensure that the gain focus is announced after clear focus. |
| 3948 | getRootView().requestFocus(FOCUS_FORWARD); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3949 | } |
| 3950 | } |
| 3951 | |
| 3952 | /** |
| 3953 | * Called internally by the view system when a new view is getting focus. |
| 3954 | * This is what clears the old focus. |
| 3955 | */ |
| 3956 | void unFocus() { |
| 3957 | if (DBG) { |
| 3958 | System.out.println(this + " unFocus()"); |
| 3959 | } |
| 3960 | |
| 3961 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 3962 | mPrivateFlags &= ~FOCUSED; |
| 3963 | |
| 3964 | onFocusChanged(false, 0, null); |
| 3965 | refreshDrawableState(); |
| 3966 | } |
| 3967 | } |
| 3968 | |
| 3969 | /** |
| 3970 | * Returns true if this view has focus iteself, or is the ancestor of the |
| 3971 | * view that has focus. |
| 3972 | * |
| 3973 | * @return True if this view has or contains focus, false otherwise. |
| 3974 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 3975 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3976 | public boolean hasFocus() { |
| 3977 | return (mPrivateFlags & FOCUSED) != 0; |
| 3978 | } |
| 3979 | |
| 3980 | /** |
| 3981 | * Returns true if this view is focusable or if it contains a reachable View |
| 3982 | * for which {@link #hasFocusable()} returns true. A "reachable hasFocusable()" |
| 3983 | * is a View whose parents do not block descendants focus. |
| 3984 | * |
| 3985 | * Only {@link #VISIBLE} views are considered focusable. |
| 3986 | * |
| 3987 | * @return True if the view is focusable or if the view contains a focusable |
| 3988 | * View, false otherwise. |
| 3989 | * |
| 3990 | * @see ViewGroup#FOCUS_BLOCK_DESCENDANTS |
| 3991 | */ |
| 3992 | public boolean hasFocusable() { |
| 3993 | return (mViewFlags & VISIBILITY_MASK) == VISIBLE && isFocusable(); |
| 3994 | } |
| 3995 | |
| 3996 | /** |
| 3997 | * Called by the view system when the focus state of this view changes. |
| 3998 | * When the focus change event is caused by directional navigation, direction |
| 3999 | * and previouslyFocusedRect provide insight into where the focus is coming from. |
| 4000 | * When overriding, be sure to call up through to the super class so that |
| 4001 | * the standard focus handling will occur. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4002 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4003 | * @param gainFocus True if the View has focus; false otherwise. |
| 4004 | * @param direction The direction focus has moved when requestFocus() |
| 4005 | * is called to give this view focus. Values are |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4006 | * {@link #FOCUS_UP}, {@link #FOCUS_DOWN}, {@link #FOCUS_LEFT}, |
| 4007 | * {@link #FOCUS_RIGHT}, {@link #FOCUS_FORWARD}, or {@link #FOCUS_BACKWARD}. |
| 4008 | * It may not always apply, in which case use the default. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4009 | * @param previouslyFocusedRect The rectangle, in this view's coordinate |
| 4010 | * system, of the previously focused view. If applicable, this will be |
| 4011 | * passed in as finer grained information about where the focus is coming |
| 4012 | * from (in addition to direction). Will be <code>null</code> otherwise. |
| 4013 | */ |
| 4014 | protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4015 | if (gainFocus) { |
| 4016 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 4017 | } |
| 4018 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4019 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 4020 | if (!gainFocus) { |
| 4021 | if (isPressed()) { |
| 4022 | setPressed(false); |
| 4023 | } |
| 4024 | if (imm != null && mAttachInfo != null |
| 4025 | && mAttachInfo.mHasWindowFocus) { |
| 4026 | imm.focusOut(this); |
| 4027 | } |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4028 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4029 | } else if (imm != null && mAttachInfo != null |
| 4030 | && mAttachInfo.mHasWindowFocus) { |
| 4031 | imm.focusIn(this); |
| 4032 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4033 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 4034 | invalidate(true); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4035 | ListenerInfo li = mListenerInfo; |
| 4036 | if (li != null && li.mOnFocusChangeListener != null) { |
| 4037 | li.mOnFocusChangeListener.onFocusChange(this, gainFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4038 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 4039 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 4040 | if (mAttachInfo != null) { |
| 4041 | mAttachInfo.mKeyDispatchState.reset(this); |
| 4042 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4046 | * Sends an accessibility event of the given type. If accessiiblity is |
| 4047 | * not enabled this method has no effect. The default implementation calls |
| 4048 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)} first |
| 4049 | * to populate information about the event source (this View), then calls |
| 4050 | * {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} to |
| 4051 | * populate the text content of the event source including its descendants, |
| 4052 | * and last calls |
| 4053 | * {@link ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)} |
| 4054 | * on its parent to resuest sending of the event to interested parties. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4055 | * <p> |
| 4056 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4057 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4058 | * {@link AccessibilityDelegate#sendAccessibilityEvent(View, int)} is |
| 4059 | * responsible for handling this call. |
| 4060 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4061 | * |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4062 | * @param eventType The type of the event to send, as defined by several types from |
| 4063 | * {@link android.view.accessibility.AccessibilityEvent}, such as |
| 4064 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_CLICKED} or |
| 4065 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_ENTER}. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4066 | * |
| 4067 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4068 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4069 | * @see ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent) |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4070 | * @see AccessibilityDelegate |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4071 | */ |
| 4072 | public void sendAccessibilityEvent(int eventType) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4073 | if (mAccessibilityDelegate != null) { |
| 4074 | mAccessibilityDelegate.sendAccessibilityEvent(this, eventType); |
| 4075 | } else { |
| 4076 | sendAccessibilityEventInternal(eventType); |
| 4077 | } |
| 4078 | } |
| 4079 | |
| 4080 | /** |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4081 | * Convenience method for sending a {@link AccessibilityEvent#TYPE_ANNOUNCEMENT} |
| 4082 | * {@link AccessibilityEvent} to make an announcement which is related to some |
| 4083 | * sort of a context change for which none of the events representing UI transitions |
| 4084 | * is a good fit. For example, announcing a new page in a book. If accessibility |
| 4085 | * is not enabled this method does nothing. |
| 4086 | * |
| 4087 | * @param text The announcement text. |
| 4088 | */ |
| 4089 | public void announceForAccessibility(CharSequence text) { |
| 4090 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4091 | AccessibilityEvent event = AccessibilityEvent.obtain( |
| 4092 | AccessibilityEvent.TYPE_ANNOUNCEMENT); |
| 4093 | event.getText().add(text); |
| 4094 | sendAccessibilityEventUnchecked(event); |
| 4095 | } |
| 4096 | } |
| 4097 | |
| 4098 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4099 | * @see #sendAccessibilityEvent(int) |
| 4100 | * |
| 4101 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4102 | */ |
| 4103 | void sendAccessibilityEventInternal(int eventType) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4104 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4105 | sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType)); |
| 4106 | } |
| 4107 | } |
| 4108 | |
| 4109 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4110 | * This method behaves exactly as {@link #sendAccessibilityEvent(int)} but |
| 4111 | * takes as an argument an empty {@link AccessibilityEvent} and does not |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4112 | * perform a check whether accessibility is enabled. |
| 4113 | * <p> |
| 4114 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4115 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4116 | * {@link AccessibilityDelegate#sendAccessibilityEventUnchecked(View, AccessibilityEvent)} |
| 4117 | * is responsible for handling this call. |
| 4118 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4119 | * |
| 4120 | * @param event The event to send. |
| 4121 | * |
| 4122 | * @see #sendAccessibilityEvent(int) |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4123 | */ |
| 4124 | public void sendAccessibilityEventUnchecked(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4125 | if (mAccessibilityDelegate != null) { |
| 4126 | mAccessibilityDelegate.sendAccessibilityEventUnchecked(this, event); |
| 4127 | } else { |
| 4128 | sendAccessibilityEventUncheckedInternal(event); |
| 4129 | } |
| 4130 | } |
| 4131 | |
| 4132 | /** |
| 4133 | * @see #sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 4134 | * |
| 4135 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4136 | */ |
| 4137 | void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 9cd1eca | 2011-01-13 14:24:02 -0800 | [diff] [blame] | 4138 | if (!isShown()) { |
| 4139 | return; |
| 4140 | } |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4141 | onInitializeAccessibilityEvent(event); |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4142 | // Only a subset of accessibility events populates text content. |
| 4143 | if ((event.getEventType() & POPULATING_ACCESSIBILITY_EVENT_TYPES) != 0) { |
| 4144 | dispatchPopulateAccessibilityEvent(event); |
| 4145 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4146 | // In the beginning we called #isShown(), so we know that getParent() is not null. |
| 4147 | getParent().requestSendAccessibilityEvent(this, event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4148 | } |
| 4149 | |
| 4150 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4151 | * Dispatches an {@link AccessibilityEvent} to the {@link View} first and then |
| 4152 | * to its children for adding their text content to the event. Note that the |
| 4153 | * event text is populated in a separate dispatch path since we add to the |
| 4154 | * event not only the text of the source but also the text of all its descendants. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4155 | * A typical implementation will call |
| 4156 | * {@link #onPopulateAccessibilityEvent(AccessibilityEvent)} on the this view |
| 4157 | * and then call the {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
| 4158 | * on each child. Override this method if custom population of the event text |
| 4159 | * content is required. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4160 | * <p> |
| 4161 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4162 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4163 | * {@link AccessibilityDelegate#dispatchPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4164 | * is responsible for handling this call. |
| 4165 | * </p> |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4166 | * <p> |
| 4167 | * <em>Note:</em> Accessibility events of certain types are not dispatched for |
| 4168 | * populating the event text via this method. For details refer to {@link AccessibilityEvent}. |
| 4169 | * </p> |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4170 | * |
| 4171 | * @param event The event. |
| 4172 | * |
| 4173 | * @return True if the event population was completed. |
| 4174 | */ |
| 4175 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4176 | if (mAccessibilityDelegate != null) { |
| 4177 | return mAccessibilityDelegate.dispatchPopulateAccessibilityEvent(this, event); |
| 4178 | } else { |
| 4179 | return dispatchPopulateAccessibilityEventInternal(event); |
| 4180 | } |
| 4181 | } |
| 4182 | |
| 4183 | /** |
| 4184 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4185 | * |
| 4186 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4187 | */ |
| 4188 | boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4189 | onPopulateAccessibilityEvent(event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4190 | return false; |
| 4191 | } |
| 4192 | |
| 4193 | /** |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4194 | * Called from {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4195 | * giving a chance to this View to populate the accessibility event with its |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4196 | * text content. While this method is free to modify event |
| 4197 | * attributes other than text content, doing so should normally be performed in |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4198 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)}. |
| 4199 | * <p> |
| 4200 | * Example: Adding formatted date string to an accessibility event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4201 | * to the text added by the super implementation: |
| 4202 | * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4203 | * super.onPopulateAccessibilityEvent(event); |
| 4204 | * final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; |
| 4205 | * String selectedDateUtterance = DateUtils.formatDateTime(mContext, |
| 4206 | * mCurrentDate.getTimeInMillis(), flags); |
| 4207 | * event.getText().add(selectedDateUtterance); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4208 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4209 | * <p> |
| 4210 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4211 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4212 | * {@link AccessibilityDelegate#onPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4213 | * is responsible for handling this call. |
| 4214 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4215 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4216 | * information to the event, in case the default implementation has basic information to add. |
| 4217 | * </p> |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4218 | * |
| 4219 | * @param event The accessibility event which to populate. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4220 | * |
| 4221 | * @see #sendAccessibilityEvent(int) |
| 4222 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4223 | */ |
| 4224 | public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4225 | if (mAccessibilityDelegate != null) { |
| 4226 | mAccessibilityDelegate.onPopulateAccessibilityEvent(this, event); |
| 4227 | } else { |
| 4228 | onPopulateAccessibilityEventInternal(event); |
| 4229 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4233 | * @see #onPopulateAccessibilityEvent(AccessibilityEvent) |
| 4234 | * |
| 4235 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4236 | */ |
| 4237 | void onPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
| 4238 | |
| 4239 | } |
| 4240 | |
| 4241 | /** |
| 4242 | * Initializes an {@link AccessibilityEvent} with information about |
| 4243 | * this View which is the event source. In other words, the source of |
| 4244 | * an accessibility event is the view whose state change triggered firing |
| 4245 | * the event. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4246 | * <p> |
| 4247 | * Example: Setting the password property of an event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4248 | * to properties set by the super implementation: |
| 4249 | * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 4250 | * super.onInitializeAccessibilityEvent(event); |
| 4251 | * event.setPassword(true); |
| 4252 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4253 | * <p> |
| 4254 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4255 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4256 | * {@link AccessibilityDelegate#onInitializeAccessibilityEvent(View, AccessibilityEvent)} |
| 4257 | * is responsible for handling this call. |
| 4258 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4259 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4260 | * information to the event, in case the default implementation has basic information to add. |
| 4261 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4262 | * @param event The event to initialize. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4263 | * |
| 4264 | * @see #sendAccessibilityEvent(int) |
| 4265 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4266 | */ |
| 4267 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4268 | if (mAccessibilityDelegate != null) { |
| 4269 | mAccessibilityDelegate.onInitializeAccessibilityEvent(this, event); |
| 4270 | } else { |
| 4271 | onInitializeAccessibilityEventInternal(event); |
| 4272 | } |
| 4273 | } |
| 4274 | |
| 4275 | /** |
| 4276 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4277 | * |
| 4278 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4279 | */ |
| 4280 | void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4281 | event.setSource(this); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 4282 | event.setClassName(View.class.getName()); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4283 | event.setPackageName(getContext().getPackageName()); |
| 4284 | event.setEnabled(isEnabled()); |
| 4285 | event.setContentDescription(mContentDescription); |
| 4286 | |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 4287 | if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && mAttachInfo != null) { |
| 4288 | ArrayList<View> focusablesTempList = mAttachInfo.mFocusablesTempList; |
| 4289 | getRootView().addFocusables(focusablesTempList, View.FOCUS_FORWARD, |
| 4290 | FOCUSABLES_ALL); |
| 4291 | event.setItemCount(focusablesTempList.size()); |
| 4292 | event.setCurrentItemIndex(focusablesTempList.indexOf(this)); |
| 4293 | focusablesTempList.clear(); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4294 | } |
| 4295 | } |
| 4296 | |
| 4297 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4298 | * Returns an {@link AccessibilityNodeInfo} representing this view from the |
| 4299 | * point of view of an {@link android.accessibilityservice.AccessibilityService}. |
| 4300 | * This method is responsible for obtaining an accessibility node info from a |
| 4301 | * pool of reusable instances and calling |
| 4302 | * {@link #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} on this view to |
| 4303 | * initialize the former. |
| 4304 | * <p> |
| 4305 | * Note: The client is responsible for recycling the obtained instance by calling |
| 4306 | * {@link AccessibilityNodeInfo#recycle()} to minimize object creation. |
| 4307 | * </p> |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4308 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4309 | * @return A populated {@link AccessibilityNodeInfo}. |
| 4310 | * |
| 4311 | * @see AccessibilityNodeInfo |
| 4312 | */ |
| 4313 | public AccessibilityNodeInfo createAccessibilityNodeInfo() { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4314 | AccessibilityNodeProvider provider = getAccessibilityNodeProvider(); |
| 4315 | if (provider != null) { |
| 4316 | return provider.createAccessibilityNodeInfo(View.NO_ID); |
| 4317 | } else { |
| 4318 | AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(this); |
| 4319 | onInitializeAccessibilityNodeInfo(info); |
| 4320 | return info; |
| 4321 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4322 | } |
| 4323 | |
| 4324 | /** |
| 4325 | * Initializes an {@link AccessibilityNodeInfo} with information about this view. |
| 4326 | * The base implementation sets: |
| 4327 | * <ul> |
| 4328 | * <li>{@link AccessibilityNodeInfo#setParent(View)},</li> |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4329 | * <li>{@link AccessibilityNodeInfo#setBoundsInParent(Rect)},</li> |
| 4330 | * <li>{@link AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li> |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4331 | * <li>{@link AccessibilityNodeInfo#setPackageName(CharSequence)},</li> |
| 4332 | * <li>{@link AccessibilityNodeInfo#setClassName(CharSequence)},</li> |
| 4333 | * <li>{@link AccessibilityNodeInfo#setContentDescription(CharSequence)},</li> |
| 4334 | * <li>{@link AccessibilityNodeInfo#setEnabled(boolean)},</li> |
| 4335 | * <li>{@link AccessibilityNodeInfo#setClickable(boolean)},</li> |
| 4336 | * <li>{@link AccessibilityNodeInfo#setFocusable(boolean)},</li> |
| 4337 | * <li>{@link AccessibilityNodeInfo#setFocused(boolean)},</li> |
| 4338 | * <li>{@link AccessibilityNodeInfo#setLongClickable(boolean)},</li> |
| 4339 | * <li>{@link AccessibilityNodeInfo#setSelected(boolean)},</li> |
| 4340 | * </ul> |
| 4341 | * <p> |
| 4342 | * Subclasses should override this method, call the super implementation, |
| 4343 | * and set additional attributes. |
| 4344 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4345 | * <p> |
| 4346 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4347 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4348 | * {@link AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)} |
| 4349 | * is responsible for handling this call. |
| 4350 | * </p> |
| 4351 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4352 | * @param info The instance to initialize. |
| 4353 | */ |
| 4354 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4355 | if (mAccessibilityDelegate != null) { |
| 4356 | mAccessibilityDelegate.onInitializeAccessibilityNodeInfo(this, info); |
| 4357 | } else { |
| 4358 | onInitializeAccessibilityNodeInfoInternal(info); |
| 4359 | } |
| 4360 | } |
| 4361 | |
| 4362 | /** |
| 4363 | * @see #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 4364 | * |
| 4365 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4366 | */ |
| 4367 | void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4368 | Rect bounds = mAttachInfo.mTmpInvalRect; |
| 4369 | getDrawingRect(bounds); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4370 | info.setBoundsInParent(bounds); |
| 4371 | |
| 4372 | int[] locationOnScreen = mAttachInfo.mInvalidateChildLocation; |
| 4373 | getLocationOnScreen(locationOnScreen); |
Alan Viverette | 326804f | 2011-07-22 16:20:41 -0700 | [diff] [blame] | 4374 | bounds.offsetTo(0, 0); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4375 | bounds.offset(locationOnScreen[0], locationOnScreen[1]); |
| 4376 | info.setBoundsInScreen(bounds); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4377 | |
Svetoslav Ganov | 57f3b566db | 2011-10-31 17:59:14 -0700 | [diff] [blame] | 4378 | if ((mPrivateFlags & IS_ROOT_NAMESPACE) == 0) { |
| 4379 | ViewParent parent = getParent(); |
| 4380 | if (parent instanceof View) { |
| 4381 | View parentView = (View) parent; |
| 4382 | info.setParent(parentView); |
| 4383 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4384 | } |
| 4385 | |
| 4386 | info.setPackageName(mContext.getPackageName()); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 4387 | info.setClassName(View.class.getName()); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4388 | info.setContentDescription(getContentDescription()); |
| 4389 | |
| 4390 | info.setEnabled(isEnabled()); |
| 4391 | info.setClickable(isClickable()); |
| 4392 | info.setFocusable(isFocusable()); |
| 4393 | info.setFocused(isFocused()); |
| 4394 | info.setSelected(isSelected()); |
| 4395 | info.setLongClickable(isLongClickable()); |
| 4396 | |
| 4397 | // TODO: These make sense only if we are in an AdapterView but all |
| 4398 | // views can be selected. Maybe from accessiiblity perspective |
| 4399 | // we should report as selectable view in an AdapterView. |
| 4400 | info.addAction(AccessibilityNodeInfo.ACTION_SELECT); |
| 4401 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_SELECTION); |
| 4402 | |
| 4403 | if (isFocusable()) { |
| 4404 | if (isFocused()) { |
| 4405 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS); |
| 4406 | } else { |
| 4407 | info.addAction(AccessibilityNodeInfo.ACTION_FOCUS); |
| 4408 | } |
| 4409 | } |
| 4410 | } |
| 4411 | |
| 4412 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4413 | * Sets a delegate for implementing accessibility support via compositon as |
| 4414 | * opposed to inheritance. The delegate's primary use is for implementing |
| 4415 | * backwards compatible widgets. For more details see {@link AccessibilityDelegate}. |
| 4416 | * |
| 4417 | * @param delegate The delegate instance. |
| 4418 | * |
| 4419 | * @see AccessibilityDelegate |
| 4420 | */ |
| 4421 | public void setAccessibilityDelegate(AccessibilityDelegate delegate) { |
| 4422 | mAccessibilityDelegate = delegate; |
| 4423 | } |
| 4424 | |
| 4425 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4426 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 4427 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 4428 | * that explore the window content. |
| 4429 | * <p> |
| 4430 | * If this method returns an instance, this instance is responsible for managing |
| 4431 | * {@link AccessibilityNodeInfo}s describing the virtual sub-tree rooted at this |
| 4432 | * View including the one representing the View itself. Similarly the returned |
| 4433 | * instance is responsible for performing accessibility actions on any virtual |
| 4434 | * view or the root view itself. |
| 4435 | * </p> |
| 4436 | * <p> |
| 4437 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4438 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4439 | * {@link AccessibilityDelegate#getAccessibilityNodeProvider(View)} |
| 4440 | * is responsible for handling this call. |
| 4441 | * </p> |
| 4442 | * |
| 4443 | * @return The provider. |
| 4444 | * |
| 4445 | * @see AccessibilityNodeProvider |
| 4446 | */ |
| 4447 | public AccessibilityNodeProvider getAccessibilityNodeProvider() { |
| 4448 | if (mAccessibilityDelegate != null) { |
| 4449 | return mAccessibilityDelegate.getAccessibilityNodeProvider(this); |
| 4450 | } else { |
| 4451 | return null; |
| 4452 | } |
| 4453 | } |
| 4454 | |
| 4455 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4456 | * Gets the unique identifier of this view on the screen for accessibility purposes. |
| 4457 | * If this {@link View} is not attached to any window, {@value #NO_ID} is returned. |
| 4458 | * |
| 4459 | * @return The view accessibility id. |
| 4460 | * |
| 4461 | * @hide |
| 4462 | */ |
| 4463 | public int getAccessibilityViewId() { |
| 4464 | if (mAccessibilityViewId == NO_ID) { |
| 4465 | mAccessibilityViewId = sNextAccessibilityViewId++; |
| 4466 | } |
| 4467 | return mAccessibilityViewId; |
| 4468 | } |
| 4469 | |
| 4470 | /** |
| 4471 | * Gets the unique identifier of the window in which this View reseides. |
| 4472 | * |
| 4473 | * @return The window accessibility id. |
| 4474 | * |
| 4475 | * @hide |
| 4476 | */ |
| 4477 | public int getAccessibilityWindowId() { |
| 4478 | return mAttachInfo != null ? mAttachInfo.mAccessibilityWindowId : NO_ID; |
| 4479 | } |
| 4480 | |
| 4481 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4482 | * Gets the {@link View} description. It briefly describes the view and is |
| 4483 | * primarily used for accessibility support. Set this property to enable |
| 4484 | * better accessibility support for your application. This is especially |
| 4485 | * true for views that do not have textual representation (For example, |
| 4486 | * ImageButton). |
| 4487 | * |
| 4488 | * @return The content descriptiopn. |
| 4489 | * |
| 4490 | * @attr ref android.R.styleable#View_contentDescription |
| 4491 | */ |
| 4492 | public CharSequence getContentDescription() { |
| 4493 | return mContentDescription; |
| 4494 | } |
| 4495 | |
| 4496 | /** |
| 4497 | * Sets the {@link View} description. It briefly describes the view and is |
| 4498 | * primarily used for accessibility support. Set this property to enable |
| 4499 | * better accessibility support for your application. This is especially |
| 4500 | * true for views that do not have textual representation (For example, |
| 4501 | * ImageButton). |
| 4502 | * |
| 4503 | * @param contentDescription The content description. |
| 4504 | * |
| 4505 | * @attr ref android.R.styleable#View_contentDescription |
| 4506 | */ |
Svetoslav Ganov | e261e28 | 2011-10-18 17:47:04 -0700 | [diff] [blame] | 4507 | @RemotableViewMethod |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4508 | public void setContentDescription(CharSequence contentDescription) { |
| 4509 | mContentDescription = contentDescription; |
| 4510 | } |
| 4511 | |
| 4512 | /** |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4513 | * Invoked whenever this view loses focus, either by losing window focus or by losing |
| 4514 | * focus within its window. This method can be used to clear any state tied to the |
| 4515 | * focus. For instance, if a button is held pressed with the trackball and the window |
| 4516 | * loses focus, this method can be used to cancel the press. |
| 4517 | * |
| 4518 | * Subclasses of View overriding this method should always call super.onFocusLost(). |
| 4519 | * |
| 4520 | * @see #onFocusChanged(boolean, int, android.graphics.Rect) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4521 | * @see #onWindowFocusChanged(boolean) |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4522 | * |
| 4523 | * @hide pending API council approval |
| 4524 | */ |
| 4525 | protected void onFocusLost() { |
| 4526 | resetPressedState(); |
| 4527 | } |
| 4528 | |
| 4529 | private void resetPressedState() { |
| 4530 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 4531 | return; |
| 4532 | } |
| 4533 | |
| 4534 | if (isPressed()) { |
| 4535 | setPressed(false); |
| 4536 | |
| 4537 | if (!mHasPerformedLongPress) { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 4538 | removeLongPressCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4539 | } |
| 4540 | } |
| 4541 | } |
| 4542 | |
| 4543 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4544 | * Returns true if this view has focus |
| 4545 | * |
| 4546 | * @return True if this view has focus, false otherwise. |
| 4547 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4548 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4549 | public boolean isFocused() { |
| 4550 | return (mPrivateFlags & FOCUSED) != 0; |
| 4551 | } |
| 4552 | |
| 4553 | /** |
| 4554 | * Find the view in the hierarchy rooted at this view that currently has |
| 4555 | * focus. |
| 4556 | * |
| 4557 | * @return The view that currently has focus, or null if no focused view can |
| 4558 | * be found. |
| 4559 | */ |
| 4560 | public View findFocus() { |
| 4561 | return (mPrivateFlags & FOCUSED) != 0 ? this : null; |
| 4562 | } |
| 4563 | |
| 4564 | /** |
| 4565 | * Change whether this view is one of the set of scrollable containers in |
| 4566 | * its window. This will be used to determine whether the window can |
| 4567 | * resize or must pan when a soft input area is open -- scrollable |
| 4568 | * containers allow the window to use resize mode since the container |
| 4569 | * will appropriately shrink. |
| 4570 | */ |
| 4571 | public void setScrollContainer(boolean isScrollContainer) { |
| 4572 | if (isScrollContainer) { |
| 4573 | if (mAttachInfo != null && (mPrivateFlags&SCROLL_CONTAINER_ADDED) == 0) { |
| 4574 | mAttachInfo.mScrollContainers.add(this); |
| 4575 | mPrivateFlags |= SCROLL_CONTAINER_ADDED; |
| 4576 | } |
| 4577 | mPrivateFlags |= SCROLL_CONTAINER; |
| 4578 | } else { |
| 4579 | if ((mPrivateFlags&SCROLL_CONTAINER_ADDED) != 0) { |
| 4580 | mAttachInfo.mScrollContainers.remove(this); |
| 4581 | } |
| 4582 | mPrivateFlags &= ~(SCROLL_CONTAINER|SCROLL_CONTAINER_ADDED); |
| 4583 | } |
| 4584 | } |
| 4585 | |
| 4586 | /** |
| 4587 | * Returns the quality of the drawing cache. |
| 4588 | * |
| 4589 | * @return One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 4590 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 4591 | * |
| 4592 | * @see #setDrawingCacheQuality(int) |
| 4593 | * @see #setDrawingCacheEnabled(boolean) |
| 4594 | * @see #isDrawingCacheEnabled() |
| 4595 | * |
| 4596 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 4597 | */ |
| 4598 | public int getDrawingCacheQuality() { |
| 4599 | return mViewFlags & DRAWING_CACHE_QUALITY_MASK; |
| 4600 | } |
| 4601 | |
| 4602 | /** |
| 4603 | * Set the drawing cache quality of this view. This value is used only when the |
| 4604 | * drawing cache is enabled |
| 4605 | * |
| 4606 | * @param quality One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 4607 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 4608 | * |
| 4609 | * @see #getDrawingCacheQuality() |
| 4610 | * @see #setDrawingCacheEnabled(boolean) |
| 4611 | * @see #isDrawingCacheEnabled() |
| 4612 | * |
| 4613 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 4614 | */ |
| 4615 | public void setDrawingCacheQuality(int quality) { |
| 4616 | setFlags(quality, DRAWING_CACHE_QUALITY_MASK); |
| 4617 | } |
| 4618 | |
| 4619 | /** |
| 4620 | * Returns whether the screen should remain on, corresponding to the current |
| 4621 | * value of {@link #KEEP_SCREEN_ON}. |
| 4622 | * |
| 4623 | * @return Returns true if {@link #KEEP_SCREEN_ON} is set. |
| 4624 | * |
| 4625 | * @see #setKeepScreenOn(boolean) |
| 4626 | * |
| 4627 | * @attr ref android.R.styleable#View_keepScreenOn |
| 4628 | */ |
| 4629 | public boolean getKeepScreenOn() { |
| 4630 | return (mViewFlags & KEEP_SCREEN_ON) != 0; |
| 4631 | } |
| 4632 | |
| 4633 | /** |
| 4634 | * Controls whether the screen should remain on, modifying the |
| 4635 | * value of {@link #KEEP_SCREEN_ON}. |
| 4636 | * |
| 4637 | * @param keepScreenOn Supply true to set {@link #KEEP_SCREEN_ON}. |
| 4638 | * |
| 4639 | * @see #getKeepScreenOn() |
| 4640 | * |
| 4641 | * @attr ref android.R.styleable#View_keepScreenOn |
| 4642 | */ |
| 4643 | public void setKeepScreenOn(boolean keepScreenOn) { |
| 4644 | setFlags(keepScreenOn ? KEEP_SCREEN_ON : 0, KEEP_SCREEN_ON); |
| 4645 | } |
| 4646 | |
| 4647 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4648 | * Gets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 4649 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4650 | * |
| 4651 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 4652 | */ |
| 4653 | public int getNextFocusLeftId() { |
| 4654 | return mNextFocusLeftId; |
| 4655 | } |
| 4656 | |
| 4657 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4658 | * Sets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 4659 | * @param nextFocusLeftId The next focus ID, or {@link #NO_ID} if the framework should |
| 4660 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4661 | * |
| 4662 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 4663 | */ |
| 4664 | public void setNextFocusLeftId(int nextFocusLeftId) { |
| 4665 | mNextFocusLeftId = nextFocusLeftId; |
| 4666 | } |
| 4667 | |
| 4668 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4669 | * Gets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 4670 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4671 | * |
| 4672 | * @attr ref android.R.styleable#View_nextFocusRight |
| 4673 | */ |
| 4674 | public int getNextFocusRightId() { |
| 4675 | return mNextFocusRightId; |
| 4676 | } |
| 4677 | |
| 4678 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4679 | * Sets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 4680 | * @param nextFocusRightId The next focus ID, or {@link #NO_ID} if the framework should |
| 4681 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4682 | * |
| 4683 | * @attr ref android.R.styleable#View_nextFocusRight |
| 4684 | */ |
| 4685 | public void setNextFocusRightId(int nextFocusRightId) { |
| 4686 | mNextFocusRightId = nextFocusRightId; |
| 4687 | } |
| 4688 | |
| 4689 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4690 | * Gets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 4691 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4692 | * |
| 4693 | * @attr ref android.R.styleable#View_nextFocusUp |
| 4694 | */ |
| 4695 | public int getNextFocusUpId() { |
| 4696 | return mNextFocusUpId; |
| 4697 | } |
| 4698 | |
| 4699 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4700 | * Sets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 4701 | * @param nextFocusUpId The next focus ID, or {@link #NO_ID} if the framework should |
| 4702 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4703 | * |
| 4704 | * @attr ref android.R.styleable#View_nextFocusUp |
| 4705 | */ |
| 4706 | public void setNextFocusUpId(int nextFocusUpId) { |
| 4707 | mNextFocusUpId = nextFocusUpId; |
| 4708 | } |
| 4709 | |
| 4710 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4711 | * Gets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 4712 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4713 | * |
| 4714 | * @attr ref android.R.styleable#View_nextFocusDown |
| 4715 | */ |
| 4716 | public int getNextFocusDownId() { |
| 4717 | return mNextFocusDownId; |
| 4718 | } |
| 4719 | |
| 4720 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4721 | * Sets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 4722 | * @param nextFocusDownId The next focus ID, or {@link #NO_ID} if the framework should |
| 4723 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4724 | * |
| 4725 | * @attr ref android.R.styleable#View_nextFocusDown |
| 4726 | */ |
| 4727 | public void setNextFocusDownId(int nextFocusDownId) { |
| 4728 | mNextFocusDownId = nextFocusDownId; |
| 4729 | } |
| 4730 | |
| 4731 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4732 | * Gets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 4733 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
| 4734 | * |
| 4735 | * @attr ref android.R.styleable#View_nextFocusForward |
| 4736 | */ |
| 4737 | public int getNextFocusForwardId() { |
| 4738 | return mNextFocusForwardId; |
| 4739 | } |
| 4740 | |
| 4741 | /** |
| 4742 | * Sets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 4743 | * @param nextFocusForwardId The next focus ID, or {@link #NO_ID} if the framework should |
| 4744 | * decide automatically. |
| 4745 | * |
| 4746 | * @attr ref android.R.styleable#View_nextFocusForward |
| 4747 | */ |
| 4748 | public void setNextFocusForwardId(int nextFocusForwardId) { |
| 4749 | mNextFocusForwardId = nextFocusForwardId; |
| 4750 | } |
| 4751 | |
| 4752 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4753 | * Returns the visibility of this view and all of its ancestors |
| 4754 | * |
| 4755 | * @return True if this view and all of its ancestors are {@link #VISIBLE} |
| 4756 | */ |
| 4757 | public boolean isShown() { |
| 4758 | View current = this; |
| 4759 | //noinspection ConstantConditions |
| 4760 | do { |
| 4761 | if ((current.mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 4762 | return false; |
| 4763 | } |
| 4764 | ViewParent parent = current.mParent; |
| 4765 | if (parent == null) { |
| 4766 | return false; // We are not attached to the view root |
| 4767 | } |
| 4768 | if (!(parent instanceof View)) { |
| 4769 | return true; |
| 4770 | } |
| 4771 | current = (View) parent; |
| 4772 | } while (current != null); |
| 4773 | |
| 4774 | return false; |
| 4775 | } |
| 4776 | |
| 4777 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 4778 | * Called by the view hierarchy when the content insets for a window have |
| 4779 | * changed, to allow it to adjust its content to fit within those windows. |
| 4780 | * The content insets tell you the space that the status bar, input method, |
| 4781 | * and other system windows infringe on the application's window. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4782 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 4783 | * <p>You do not normally need to deal with this function, since the default |
| 4784 | * window decoration given to applications takes care of applying it to the |
| 4785 | * content of the window. If you use {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} |
| 4786 | * or {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION} this will not be the case, |
| 4787 | * and your content can be placed under those system elements. You can then |
| 4788 | * use this method within your view hierarchy if you have parts of your UI |
| 4789 | * which you would like to ensure are not being covered. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4790 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 4791 | * <p>The default implementation of this method simply applies the content |
| 4792 | * inset's to the view's padding. This can be enabled through |
| 4793 | * {@link #setFitsSystemWindows(boolean)}. Alternatively, you can override |
| 4794 | * the method and handle the insets however you would like. Note that the |
| 4795 | * insets provided by the framework are always relative to the far edges |
| 4796 | * of the window, not accounting for the location of the called view within |
| 4797 | * that window. (In fact when this method is called you do not yet know |
| 4798 | * where the layout will place the view, as it is done before layout happens.) |
| 4799 | * |
| 4800 | * <p>Note: unlike many View methods, there is no dispatch phase to this |
| 4801 | * call. If you are overriding it in a ViewGroup and want to allow the |
| 4802 | * call to continue to your children, you must be sure to call the super |
| 4803 | * implementation. |
| 4804 | * |
| 4805 | * @param insets Current content insets of the window. Prior to |
| 4806 | * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} you must not modify |
| 4807 | * the insets or else you and Android will be unhappy. |
| 4808 | * |
| 4809 | * @return Return true if this view applied the insets and it should not |
| 4810 | * continue propagating further down the hierarchy, false otherwise. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4811 | */ |
| 4812 | protected boolean fitSystemWindows(Rect insets) { |
| 4813 | if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 4814 | mUserPaddingStart = -1; |
| 4815 | mUserPaddingEnd = -1; |
| 4816 | mUserPaddingRelative = false; |
| 4817 | if ((mViewFlags & OPTIONAL_FITS_SYSTEM_WINDOWS) == 0 |
| 4818 | || mAttachInfo == null |
| 4819 | || (mAttachInfo.mSystemUiVisibility & SYSTEM_UI_LAYOUT_FLAGS) == 0) { |
| 4820 | internalSetPadding(insets.left, insets.top, insets.right, insets.bottom); |
| 4821 | return true; |
| 4822 | } else { |
| 4823 | internalSetPadding(0, 0, 0, 0); |
| 4824 | return false; |
| 4825 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4826 | } |
| 4827 | return false; |
| 4828 | } |
| 4829 | |
| 4830 | /** |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 4831 | * Set whether or not this view should account for system screen decorations |
| 4832 | * such as the status bar and inset its content. This allows this view to be |
| 4833 | * positioned in absolute screen coordinates and remain visible to the user. |
| 4834 | * |
| 4835 | * <p>This should only be used by top-level window decor views. |
| 4836 | * |
| 4837 | * @param fitSystemWindows true to inset content for system screen decorations, false for |
| 4838 | * default behavior. |
| 4839 | * |
| 4840 | * @attr ref android.R.styleable#View_fitsSystemWindows |
| 4841 | */ |
| 4842 | public void setFitsSystemWindows(boolean fitSystemWindows) { |
| 4843 | setFlags(fitSystemWindows ? FITS_SYSTEM_WINDOWS : 0, FITS_SYSTEM_WINDOWS); |
| 4844 | } |
| 4845 | |
| 4846 | /** |
| 4847 | * Check for the FITS_SYSTEM_WINDOWS flag. If this method returns true, this view |
| 4848 | * will account for system screen decorations such as the status bar and inset its |
| 4849 | * content. This allows the view to be positioned in absolute screen coordinates |
| 4850 | * and remain visible to the user. |
| 4851 | * |
| 4852 | * @return true if this view will adjust its content bounds for system screen decorations. |
| 4853 | * |
| 4854 | * @attr ref android.R.styleable#View_fitsSystemWindows |
| 4855 | */ |
| 4856 | public boolean fitsSystemWindows() { |
| 4857 | return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS; |
| 4858 | } |
| 4859 | |
| 4860 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 4861 | * Ask that a new dispatch of {@link #fitSystemWindows(Rect)} be performed. |
| 4862 | */ |
| 4863 | public void requestFitSystemWindows() { |
| 4864 | if (mParent != null) { |
| 4865 | mParent.requestFitSystemWindows(); |
| 4866 | } |
| 4867 | } |
| 4868 | |
| 4869 | /** |
| 4870 | * For use by PhoneWindow to make its own system window fitting optional. |
| 4871 | * @hide |
| 4872 | */ |
| 4873 | public void makeOptionalFitsSystemWindows() { |
| 4874 | setFlags(OPTIONAL_FITS_SYSTEM_WINDOWS, OPTIONAL_FITS_SYSTEM_WINDOWS); |
| 4875 | } |
| 4876 | |
| 4877 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4878 | * Returns the visibility status for this view. |
| 4879 | * |
| 4880 | * @return One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 4881 | * @attr ref android.R.styleable#View_visibility |
| 4882 | */ |
| 4883 | @ViewDebug.ExportedProperty(mapping = { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 4884 | @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), |
| 4885 | @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), |
| 4886 | @ViewDebug.IntToString(from = GONE, to = "GONE") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4887 | }) |
| 4888 | public int getVisibility() { |
| 4889 | return mViewFlags & VISIBILITY_MASK; |
| 4890 | } |
| 4891 | |
| 4892 | /** |
| 4893 | * Set the enabled state of this view. |
| 4894 | * |
| 4895 | * @param visibility One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 4896 | * @attr ref android.R.styleable#View_visibility |
| 4897 | */ |
| 4898 | @RemotableViewMethod |
| 4899 | public void setVisibility(int visibility) { |
| 4900 | setFlags(visibility, VISIBILITY_MASK); |
| 4901 | if (mBGDrawable != null) mBGDrawable.setVisible(visibility == VISIBLE, false); |
| 4902 | } |
| 4903 | |
| 4904 | /** |
| 4905 | * Returns the enabled status for this view. The interpretation of the |
| 4906 | * enabled state varies by subclass. |
| 4907 | * |
| 4908 | * @return True if this view is enabled, false otherwise. |
| 4909 | */ |
| 4910 | @ViewDebug.ExportedProperty |
| 4911 | public boolean isEnabled() { |
| 4912 | return (mViewFlags & ENABLED_MASK) == ENABLED; |
| 4913 | } |
| 4914 | |
| 4915 | /** |
| 4916 | * Set the enabled state of this view. The interpretation of the enabled |
| 4917 | * state varies by subclass. |
| 4918 | * |
| 4919 | * @param enabled True if this view is enabled, false otherwise. |
| 4920 | */ |
Jeff Sharkey | 2b95c24 | 2010-02-08 17:40:30 -0800 | [diff] [blame] | 4921 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4922 | public void setEnabled(boolean enabled) { |
Amith Yamasani | a2ef00b | 2009-07-30 16:14:34 -0700 | [diff] [blame] | 4923 | if (enabled == isEnabled()) return; |
| 4924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4925 | setFlags(enabled ? ENABLED : DISABLED, ENABLED_MASK); |
| 4926 | |
| 4927 | /* |
| 4928 | * The View most likely has to change its appearance, so refresh |
| 4929 | * the drawable state. |
| 4930 | */ |
| 4931 | refreshDrawableState(); |
| 4932 | |
| 4933 | // Invalidate too, since the default behavior for views is to be |
| 4934 | // be drawn at 50% alpha rather than to change the drawable. |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 4935 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4936 | } |
| 4937 | |
| 4938 | /** |
| 4939 | * Set whether this view can receive the focus. |
| 4940 | * |
| 4941 | * Setting this to false will also ensure that this view is not focusable |
| 4942 | * in touch mode. |
| 4943 | * |
| 4944 | * @param focusable If true, this view can receive the focus. |
| 4945 | * |
| 4946 | * @see #setFocusableInTouchMode(boolean) |
| 4947 | * @attr ref android.R.styleable#View_focusable |
| 4948 | */ |
| 4949 | public void setFocusable(boolean focusable) { |
| 4950 | if (!focusable) { |
| 4951 | setFlags(0, FOCUSABLE_IN_TOUCH_MODE); |
| 4952 | } |
| 4953 | setFlags(focusable ? FOCUSABLE : NOT_FOCUSABLE, FOCUSABLE_MASK); |
| 4954 | } |
| 4955 | |
| 4956 | /** |
| 4957 | * Set whether this view can receive focus while in touch mode. |
| 4958 | * |
| 4959 | * Setting this to true will also ensure that this view is focusable. |
| 4960 | * |
| 4961 | * @param focusableInTouchMode If true, this view can receive the focus while |
| 4962 | * in touch mode. |
| 4963 | * |
| 4964 | * @see #setFocusable(boolean) |
| 4965 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 4966 | */ |
| 4967 | public void setFocusableInTouchMode(boolean focusableInTouchMode) { |
| 4968 | // Focusable in touch mode should always be set before the focusable flag |
| 4969 | // otherwise, setting the focusable flag will trigger a focusableViewAvailable() |
| 4970 | // which, in touch mode, will not successfully request focus on this view |
| 4971 | // because the focusable in touch mode flag is not set |
| 4972 | setFlags(focusableInTouchMode ? FOCUSABLE_IN_TOUCH_MODE : 0, FOCUSABLE_IN_TOUCH_MODE); |
| 4973 | if (focusableInTouchMode) { |
| 4974 | setFlags(FOCUSABLE, FOCUSABLE_MASK); |
| 4975 | } |
| 4976 | } |
| 4977 | |
| 4978 | /** |
| 4979 | * Set whether this view should have sound effects enabled for events such as |
| 4980 | * clicking and touching. |
| 4981 | * |
| 4982 | * <p>You may wish to disable sound effects for a view if you already play sounds, |
| 4983 | * for instance, a dial key that plays dtmf tones. |
| 4984 | * |
| 4985 | * @param soundEffectsEnabled whether sound effects are enabled for this view. |
| 4986 | * @see #isSoundEffectsEnabled() |
| 4987 | * @see #playSoundEffect(int) |
| 4988 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 4989 | */ |
| 4990 | public void setSoundEffectsEnabled(boolean soundEffectsEnabled) { |
| 4991 | setFlags(soundEffectsEnabled ? SOUND_EFFECTS_ENABLED: 0, SOUND_EFFECTS_ENABLED); |
| 4992 | } |
| 4993 | |
| 4994 | /** |
| 4995 | * @return whether this view should have sound effects enabled for events such as |
| 4996 | * clicking and touching. |
| 4997 | * |
| 4998 | * @see #setSoundEffectsEnabled(boolean) |
| 4999 | * @see #playSoundEffect(int) |
| 5000 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 5001 | */ |
| 5002 | @ViewDebug.ExportedProperty |
| 5003 | public boolean isSoundEffectsEnabled() { |
| 5004 | return SOUND_EFFECTS_ENABLED == (mViewFlags & SOUND_EFFECTS_ENABLED); |
| 5005 | } |
| 5006 | |
| 5007 | /** |
| 5008 | * Set whether this view should have haptic feedback for events such as |
| 5009 | * long presses. |
| 5010 | * |
| 5011 | * <p>You may wish to disable haptic feedback if your view already controls |
| 5012 | * its own haptic feedback. |
| 5013 | * |
| 5014 | * @param hapticFeedbackEnabled whether haptic feedback enabled for this view. |
| 5015 | * @see #isHapticFeedbackEnabled() |
| 5016 | * @see #performHapticFeedback(int) |
| 5017 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 5018 | */ |
| 5019 | public void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled) { |
| 5020 | setFlags(hapticFeedbackEnabled ? HAPTIC_FEEDBACK_ENABLED: 0, HAPTIC_FEEDBACK_ENABLED); |
| 5021 | } |
| 5022 | |
| 5023 | /** |
| 5024 | * @return whether this view should have haptic feedback enabled for events |
| 5025 | * long presses. |
| 5026 | * |
| 5027 | * @see #setHapticFeedbackEnabled(boolean) |
| 5028 | * @see #performHapticFeedback(int) |
| 5029 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 5030 | */ |
| 5031 | @ViewDebug.ExportedProperty |
| 5032 | public boolean isHapticFeedbackEnabled() { |
| 5033 | return HAPTIC_FEEDBACK_ENABLED == (mViewFlags & HAPTIC_FEEDBACK_ENABLED); |
| 5034 | } |
| 5035 | |
| 5036 | /** |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5037 | * Returns the layout direction for this view. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5038 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5039 | * @return One of {@link #LAYOUT_DIRECTION_LTR}, |
| 5040 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 5041 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 5042 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
| 5043 | * @attr ref android.R.styleable#View_layoutDirection |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5044 | */ |
Fabrice Di Meglio | bce84d2 | 2011-06-02 15:57:01 -0700 | [diff] [blame] | 5045 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5046 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "LTR"), |
| 5047 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RTL"), |
| 5048 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"), |
| 5049 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE, to = "LOCALE") |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5050 | }) |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5051 | public int getLayoutDirection() { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5052 | return (mPrivateFlags2 & LAYOUT_DIRECTION_MASK) >> LAYOUT_DIRECTION_MASK_SHIFT; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5053 | } |
| 5054 | |
| 5055 | /** |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5056 | * Set the layout direction for this view. This will propagate a reset of layout direction |
| 5057 | * resolution to the view's children and resolve layout direction for this view. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5058 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5059 | * @param layoutDirection One of {@link #LAYOUT_DIRECTION_LTR}, |
| 5060 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 5061 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 5062 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5063 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5064 | * @attr ref android.R.styleable#View_layoutDirection |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5065 | */ |
| 5066 | @RemotableViewMethod |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5067 | public void setLayoutDirection(int layoutDirection) { |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5068 | if (getLayoutDirection() != layoutDirection) { |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 5069 | // Reset the current layout direction and the resolved one |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5070 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_MASK; |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 5071 | resetResolvedLayoutDirection(); |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5072 | // Set the new layout direction (filtered) and ask for a layout pass |
| 5073 | mPrivateFlags2 |= |
| 5074 | ((layoutDirection << LAYOUT_DIRECTION_MASK_SHIFT) & LAYOUT_DIRECTION_MASK); |
| 5075 | requestLayout(); |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5076 | } |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5077 | } |
| 5078 | |
| 5079 | /** |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5080 | * Returns the resolved layout direction for this view. |
| 5081 | * |
| 5082 | * @return {@link #LAYOUT_DIRECTION_RTL} if the layout direction is RTL or returns |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5083 | * {@link #LAYOUT_DIRECTION_LTR} if the layout direction is not RTL. |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5084 | */ |
| 5085 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5086 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"), |
| 5087 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL") |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5088 | }) |
| 5089 | public int getResolvedLayoutDirection() { |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 5090 | // The layout diretion will be resolved only if needed |
| 5091 | if ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED) != LAYOUT_DIRECTION_RESOLVED) { |
| 5092 | resolveLayoutDirection(); |
| 5093 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 5094 | return ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED_RTL) == LAYOUT_DIRECTION_RESOLVED_RTL) ? |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5095 | LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR; |
| 5096 | } |
| 5097 | |
| 5098 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5099 | * Indicates whether or not this view's layout is right-to-left. This is resolved from |
| 5100 | * layout attribute and/or the inherited value from the parent |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5101 | * |
| 5102 | * @return true if the layout is right-to-left. |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5103 | */ |
| 5104 | @ViewDebug.ExportedProperty(category = "layout") |
| 5105 | public boolean isLayoutRtl() { |
| 5106 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL); |
| 5107 | } |
| 5108 | |
| 5109 | /** |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5110 | * Indicates whether the view is currently tracking transient state that the |
| 5111 | * app should not need to concern itself with saving and restoring, but that |
| 5112 | * the framework should take special note to preserve when possible. |
| 5113 | * |
| 5114 | * @return true if the view has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5115 | */ |
| 5116 | @ViewDebug.ExportedProperty(category = "layout") |
| 5117 | public boolean hasTransientState() { |
| 5118 | return (mPrivateFlags2 & HAS_TRANSIENT_STATE) == HAS_TRANSIENT_STATE; |
| 5119 | } |
| 5120 | |
| 5121 | /** |
| 5122 | * Set whether this view is currently tracking transient state that the |
| 5123 | * framework should attempt to preserve when possible. |
| 5124 | * |
| 5125 | * @param hasTransientState true if this view has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5126 | */ |
| 5127 | public void setHasTransientState(boolean hasTransientState) { |
| 5128 | if (hasTransientState() == hasTransientState) return; |
| 5129 | |
| 5130 | mPrivateFlags2 = (mPrivateFlags2 & ~HAS_TRANSIENT_STATE) | |
| 5131 | (hasTransientState ? HAS_TRANSIENT_STATE : 0); |
| 5132 | if (mParent != null) { |
| 5133 | try { |
| 5134 | mParent.childHasTransientStateChanged(this, hasTransientState); |
| 5135 | } catch (AbstractMethodError e) { |
| 5136 | Log.e(VIEW_LOG_TAG, mParent.getClass().getSimpleName() + |
| 5137 | " does not fully implement ViewParent", e); |
| 5138 | } |
| 5139 | } |
| 5140 | } |
| 5141 | |
| 5142 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5143 | * If this view doesn't do any drawing on its own, set this flag to |
| 5144 | * allow further optimizations. By default, this flag is not set on |
| 5145 | * View, but could be set on some View subclasses such as ViewGroup. |
| 5146 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5147 | * Typically, if you override {@link #onDraw(android.graphics.Canvas)} |
| 5148 | * you should clear this flag. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5149 | * |
| 5150 | * @param willNotDraw whether or not this View draw on its own |
| 5151 | */ |
| 5152 | public void setWillNotDraw(boolean willNotDraw) { |
| 5153 | setFlags(willNotDraw ? WILL_NOT_DRAW : 0, DRAW_MASK); |
| 5154 | } |
| 5155 | |
| 5156 | /** |
| 5157 | * Returns whether or not this View draws on its own. |
| 5158 | * |
| 5159 | * @return true if this view has nothing to draw, false otherwise |
| 5160 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5161 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5162 | public boolean willNotDraw() { |
| 5163 | return (mViewFlags & DRAW_MASK) == WILL_NOT_DRAW; |
| 5164 | } |
| 5165 | |
| 5166 | /** |
| 5167 | * When a View's drawing cache is enabled, drawing is redirected to an |
| 5168 | * offscreen bitmap. Some views, like an ImageView, must be able to |
| 5169 | * bypass this mechanism if they already draw a single bitmap, to avoid |
| 5170 | * unnecessary usage of the memory. |
| 5171 | * |
| 5172 | * @param willNotCacheDrawing true if this view does not cache its |
| 5173 | * drawing, false otherwise |
| 5174 | */ |
| 5175 | public void setWillNotCacheDrawing(boolean willNotCacheDrawing) { |
| 5176 | setFlags(willNotCacheDrawing ? WILL_NOT_CACHE_DRAWING : 0, WILL_NOT_CACHE_DRAWING); |
| 5177 | } |
| 5178 | |
| 5179 | /** |
| 5180 | * Returns whether or not this View can cache its drawing or not. |
| 5181 | * |
| 5182 | * @return true if this view does not cache its drawing, false otherwise |
| 5183 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5184 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5185 | public boolean willNotCacheDrawing() { |
| 5186 | return (mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING; |
| 5187 | } |
| 5188 | |
| 5189 | /** |
| 5190 | * Indicates whether this view reacts to click events or not. |
| 5191 | * |
| 5192 | * @return true if the view is clickable, false otherwise |
| 5193 | * |
| 5194 | * @see #setClickable(boolean) |
| 5195 | * @attr ref android.R.styleable#View_clickable |
| 5196 | */ |
| 5197 | @ViewDebug.ExportedProperty |
| 5198 | public boolean isClickable() { |
| 5199 | return (mViewFlags & CLICKABLE) == CLICKABLE; |
| 5200 | } |
| 5201 | |
| 5202 | /** |
| 5203 | * Enables or disables click events for this view. When a view |
| 5204 | * is clickable it will change its state to "pressed" on every click. |
| 5205 | * Subclasses should set the view clickable to visually react to |
| 5206 | * user's clicks. |
| 5207 | * |
| 5208 | * @param clickable true to make the view clickable, false otherwise |
| 5209 | * |
| 5210 | * @see #isClickable() |
| 5211 | * @attr ref android.R.styleable#View_clickable |
| 5212 | */ |
| 5213 | public void setClickable(boolean clickable) { |
| 5214 | setFlags(clickable ? CLICKABLE : 0, CLICKABLE); |
| 5215 | } |
| 5216 | |
| 5217 | /** |
| 5218 | * Indicates whether this view reacts to long click events or not. |
| 5219 | * |
| 5220 | * @return true if the view is long clickable, false otherwise |
| 5221 | * |
| 5222 | * @see #setLongClickable(boolean) |
| 5223 | * @attr ref android.R.styleable#View_longClickable |
| 5224 | */ |
| 5225 | public boolean isLongClickable() { |
| 5226 | return (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 5227 | } |
| 5228 | |
| 5229 | /** |
| 5230 | * Enables or disables long click events for this view. When a view is long |
| 5231 | * clickable it reacts to the user holding down the button for a longer |
| 5232 | * duration than a tap. This event can either launch the listener or a |
| 5233 | * context menu. |
| 5234 | * |
| 5235 | * @param longClickable true to make the view long clickable, false otherwise |
| 5236 | * @see #isLongClickable() |
| 5237 | * @attr ref android.R.styleable#View_longClickable |
| 5238 | */ |
| 5239 | public void setLongClickable(boolean longClickable) { |
| 5240 | setFlags(longClickable ? LONG_CLICKABLE : 0, LONG_CLICKABLE); |
| 5241 | } |
| 5242 | |
| 5243 | /** |
Chet Haase | 49afa5b | 2010-08-23 11:39:53 -0700 | [diff] [blame] | 5244 | * Sets the pressed state for this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5245 | * |
| 5246 | * @see #isClickable() |
| 5247 | * @see #setClickable(boolean) |
| 5248 | * |
| 5249 | * @param pressed Pass true to set the View's internal state to "pressed", or false to reverts |
| 5250 | * the View's internal state from a previously set "pressed" state. |
| 5251 | */ |
| 5252 | public void setPressed(boolean pressed) { |
Adam Powell | 035a1fc | 2012-02-27 15:23:50 -0800 | [diff] [blame] | 5253 | final boolean needsRefresh = pressed != ((mPrivateFlags & PRESSED) == PRESSED); |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 5254 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5255 | if (pressed) { |
| 5256 | mPrivateFlags |= PRESSED; |
| 5257 | } else { |
| 5258 | mPrivateFlags &= ~PRESSED; |
| 5259 | } |
Adam Powell | 035a1fc | 2012-02-27 15:23:50 -0800 | [diff] [blame] | 5260 | |
| 5261 | if (needsRefresh) { |
| 5262 | refreshDrawableState(); |
| 5263 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5264 | dispatchSetPressed(pressed); |
| 5265 | } |
| 5266 | |
| 5267 | /** |
| 5268 | * Dispatch setPressed to all of this View's children. |
| 5269 | * |
| 5270 | * @see #setPressed(boolean) |
| 5271 | * |
| 5272 | * @param pressed The new pressed state |
| 5273 | */ |
| 5274 | protected void dispatchSetPressed(boolean pressed) { |
| 5275 | } |
| 5276 | |
| 5277 | /** |
| 5278 | * Indicates whether the view is currently in pressed state. Unless |
| 5279 | * {@link #setPressed(boolean)} is explicitly called, only clickable views can enter |
| 5280 | * the pressed state. |
| 5281 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5282 | * @see #setPressed(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5283 | * @see #isClickable() |
| 5284 | * @see #setClickable(boolean) |
| 5285 | * |
| 5286 | * @return true if the view is currently pressed, false otherwise |
| 5287 | */ |
| 5288 | public boolean isPressed() { |
| 5289 | return (mPrivateFlags & PRESSED) == PRESSED; |
| 5290 | } |
| 5291 | |
| 5292 | /** |
| 5293 | * Indicates whether this view will save its state (that is, |
| 5294 | * whether its {@link #onSaveInstanceState} method will be called). |
| 5295 | * |
| 5296 | * @return Returns true if the view state saving is enabled, else false. |
| 5297 | * |
| 5298 | * @see #setSaveEnabled(boolean) |
| 5299 | * @attr ref android.R.styleable#View_saveEnabled |
| 5300 | */ |
| 5301 | public boolean isSaveEnabled() { |
| 5302 | return (mViewFlags & SAVE_DISABLED_MASK) != SAVE_DISABLED; |
| 5303 | } |
| 5304 | |
| 5305 | /** |
| 5306 | * Controls whether the saving of this view's state is |
| 5307 | * enabled (that is, whether its {@link #onSaveInstanceState} method |
| 5308 | * will be called). Note that even if freezing is enabled, the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5309 | * view still must have an id assigned to it (via {@link #setId(int)}) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5310 | * for its state to be saved. This flag can only disable the |
| 5311 | * saving of this view; any child views may still have their state saved. |
| 5312 | * |
| 5313 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 5314 | * (the default) to allow it. |
| 5315 | * |
| 5316 | * @see #isSaveEnabled() |
| 5317 | * @see #setId(int) |
| 5318 | * @see #onSaveInstanceState() |
| 5319 | * @attr ref android.R.styleable#View_saveEnabled |
| 5320 | */ |
| 5321 | public void setSaveEnabled(boolean enabled) { |
| 5322 | setFlags(enabled ? 0 : SAVE_DISABLED, SAVE_DISABLED_MASK); |
| 5323 | } |
| 5324 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5325 | /** |
| 5326 | * Gets whether the framework should discard touches when the view's |
| 5327 | * window is obscured by another visible window. |
| 5328 | * Refer to the {@link View} security documentation for more details. |
| 5329 | * |
| 5330 | * @return True if touch filtering is enabled. |
| 5331 | * |
| 5332 | * @see #setFilterTouchesWhenObscured(boolean) |
| 5333 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 5334 | */ |
| 5335 | @ViewDebug.ExportedProperty |
| 5336 | public boolean getFilterTouchesWhenObscured() { |
| 5337 | return (mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0; |
| 5338 | } |
| 5339 | |
| 5340 | /** |
| 5341 | * Sets whether the framework should discard touches when the view's |
| 5342 | * window is obscured by another visible window. |
| 5343 | * Refer to the {@link View} security documentation for more details. |
| 5344 | * |
| 5345 | * @param enabled True if touch filtering should be enabled. |
| 5346 | * |
| 5347 | * @see #getFilterTouchesWhenObscured |
| 5348 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 5349 | */ |
| 5350 | public void setFilterTouchesWhenObscured(boolean enabled) { |
| 5351 | setFlags(enabled ? 0 : FILTER_TOUCHES_WHEN_OBSCURED, |
| 5352 | FILTER_TOUCHES_WHEN_OBSCURED); |
| 5353 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5354 | |
| 5355 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 5356 | * Indicates whether the entire hierarchy under this view will save its |
| 5357 | * state when a state saving traversal occurs from its parent. The default |
| 5358 | * is true; if false, these views will not be saved unless |
| 5359 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 5360 | * |
| 5361 | * @return Returns true if the view state saving from parent is enabled, else false. |
| 5362 | * |
| 5363 | * @see #setSaveFromParentEnabled(boolean) |
| 5364 | */ |
| 5365 | public boolean isSaveFromParentEnabled() { |
| 5366 | return (mViewFlags & PARENT_SAVE_DISABLED_MASK) != PARENT_SAVE_DISABLED; |
| 5367 | } |
| 5368 | |
| 5369 | /** |
| 5370 | * Controls whether the entire hierarchy under this view will save its |
| 5371 | * state when a state saving traversal occurs from its parent. The default |
| 5372 | * is true; if false, these views will not be saved unless |
| 5373 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 5374 | * |
| 5375 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 5376 | * (the default) to allow it. |
| 5377 | * |
| 5378 | * @see #isSaveFromParentEnabled() |
| 5379 | * @see #setId(int) |
| 5380 | * @see #onSaveInstanceState() |
| 5381 | */ |
| 5382 | public void setSaveFromParentEnabled(boolean enabled) { |
| 5383 | setFlags(enabled ? 0 : PARENT_SAVE_DISABLED, PARENT_SAVE_DISABLED_MASK); |
| 5384 | } |
| 5385 | |
| 5386 | |
| 5387 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5388 | * Returns whether this View is able to take focus. |
| 5389 | * |
| 5390 | * @return True if this view can take focus, or false otherwise. |
| 5391 | * @attr ref android.R.styleable#View_focusable |
| 5392 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5393 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5394 | public final boolean isFocusable() { |
| 5395 | return FOCUSABLE == (mViewFlags & FOCUSABLE_MASK); |
| 5396 | } |
| 5397 | |
| 5398 | /** |
| 5399 | * When a view is focusable, it may not want to take focus when in touch mode. |
| 5400 | * For example, a button would like focus when the user is navigating via a D-pad |
| 5401 | * so that the user can click on it, but once the user starts touching the screen, |
| 5402 | * the button shouldn't take focus |
| 5403 | * @return Whether the view is focusable in touch mode. |
| 5404 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 5405 | */ |
| 5406 | @ViewDebug.ExportedProperty |
| 5407 | public final boolean isFocusableInTouchMode() { |
| 5408 | return FOCUSABLE_IN_TOUCH_MODE == (mViewFlags & FOCUSABLE_IN_TOUCH_MODE); |
| 5409 | } |
| 5410 | |
| 5411 | /** |
| 5412 | * Find the nearest view in the specified direction that can take focus. |
| 5413 | * This does not actually give focus to that view. |
| 5414 | * |
| 5415 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 5416 | * |
| 5417 | * @return The nearest focusable in the specified direction, or null if none |
| 5418 | * can be found. |
| 5419 | */ |
| 5420 | public View focusSearch(int direction) { |
| 5421 | if (mParent != null) { |
| 5422 | return mParent.focusSearch(this, direction); |
| 5423 | } else { |
| 5424 | return null; |
| 5425 | } |
| 5426 | } |
| 5427 | |
| 5428 | /** |
| 5429 | * This method is the last chance for the focused view and its ancestors to |
| 5430 | * respond to an arrow key. This is called when the focused view did not |
| 5431 | * consume the key internally, nor could the view system find a new view in |
| 5432 | * the requested direction to give focus to. |
| 5433 | * |
| 5434 | * @param focused The currently focused view. |
| 5435 | * @param direction The direction focus wants to move. One of FOCUS_UP, |
| 5436 | * FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT. |
| 5437 | * @return True if the this view consumed this unhandled move. |
| 5438 | */ |
| 5439 | public boolean dispatchUnhandledMove(View focused, int direction) { |
| 5440 | return false; |
| 5441 | } |
| 5442 | |
| 5443 | /** |
| 5444 | * If a user manually specified the next view id for a particular direction, |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5445 | * use the root to look up the view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5446 | * @param root The root view of the hierarchy containing this view. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5447 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, |
| 5448 | * or FOCUS_BACKWARD. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5449 | * @return The user specified next view, or null if there is none. |
| 5450 | */ |
| 5451 | View findUserSetNextFocus(View root, int direction) { |
| 5452 | switch (direction) { |
| 5453 | case FOCUS_LEFT: |
| 5454 | if (mNextFocusLeftId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5455 | return findViewInsideOutShouldExist(root, mNextFocusLeftId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5456 | case FOCUS_RIGHT: |
| 5457 | if (mNextFocusRightId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5458 | return findViewInsideOutShouldExist(root, mNextFocusRightId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5459 | case FOCUS_UP: |
| 5460 | if (mNextFocusUpId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5461 | return findViewInsideOutShouldExist(root, mNextFocusUpId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5462 | case FOCUS_DOWN: |
| 5463 | if (mNextFocusDownId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5464 | return findViewInsideOutShouldExist(root, mNextFocusDownId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5465 | case FOCUS_FORWARD: |
| 5466 | if (mNextFocusForwardId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5467 | return findViewInsideOutShouldExist(root, mNextFocusForwardId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5468 | case FOCUS_BACKWARD: { |
John Reck | 1ecebbb | 2012-03-06 16:08:54 -0800 | [diff] [blame] | 5469 | if (mID == View.NO_ID) return null; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5470 | final int id = mID; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5471 | return root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5472 | @Override |
| 5473 | public boolean apply(View t) { |
| 5474 | return t.mNextFocusForwardId == id; |
| 5475 | } |
| 5476 | }); |
| 5477 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5478 | } |
| 5479 | return null; |
| 5480 | } |
| 5481 | |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5482 | private View findViewInsideOutShouldExist(View root, final int childViewId) { |
| 5483 | View result = root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
| 5484 | @Override |
| 5485 | public boolean apply(View t) { |
| 5486 | return t.mID == childViewId; |
| 5487 | } |
| 5488 | }); |
| 5489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5490 | if (result == null) { |
| 5491 | Log.w(VIEW_LOG_TAG, "couldn't find next focus view specified " |
| 5492 | + "by user for id " + childViewId); |
| 5493 | } |
| 5494 | return result; |
| 5495 | } |
| 5496 | |
| 5497 | /** |
| 5498 | * Find and return all focusable views that are descendants of this view, |
| 5499 | * possibly including this view if it is focusable itself. |
| 5500 | * |
| 5501 | * @param direction The direction of the focus |
| 5502 | * @return A list of focusable views |
| 5503 | */ |
| 5504 | public ArrayList<View> getFocusables(int direction) { |
| 5505 | ArrayList<View> result = new ArrayList<View>(24); |
| 5506 | addFocusables(result, direction); |
| 5507 | return result; |
| 5508 | } |
| 5509 | |
| 5510 | /** |
| 5511 | * Add any focusable views that are descendants of this view (possibly |
| 5512 | * including this view if it is focusable itself) to views. If we are in touch mode, |
| 5513 | * only add views that are also focusable in touch mode. |
| 5514 | * |
| 5515 | * @param views Focusable views found so far |
| 5516 | * @param direction The direction of the focus |
| 5517 | */ |
| 5518 | public void addFocusables(ArrayList<View> views, int direction) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5519 | addFocusables(views, direction, FOCUSABLES_TOUCH_MODE); |
| 5520 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5521 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5522 | /** |
| 5523 | * Adds any focusable views that are descendants of this view (possibly |
| 5524 | * including this view if it is focusable itself) to views. This method |
| 5525 | * adds all focusable views regardless if we are in touch mode or |
| 5526 | * only views focusable in touch mode if we are in touch mode depending on |
| 5527 | * the focusable mode paramater. |
| 5528 | * |
| 5529 | * @param views Focusable views found so far or null if all we are interested is |
| 5530 | * the number of focusables. |
| 5531 | * @param direction The direction of the focus. |
| 5532 | * @param focusableMode The type of focusables to be added. |
| 5533 | * |
| 5534 | * @see #FOCUSABLES_ALL |
| 5535 | * @see #FOCUSABLES_TOUCH_MODE |
| 5536 | */ |
| 5537 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
| 5538 | if (!isFocusable()) { |
| 5539 | return; |
| 5540 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5541 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5542 | if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && |
| 5543 | isInTouchMode() && !isFocusableInTouchMode()) { |
| 5544 | return; |
| 5545 | } |
| 5546 | |
| 5547 | if (views != null) { |
| 5548 | views.add(this); |
| 5549 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5550 | } |
| 5551 | |
| 5552 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5553 | * Finds the Views that contain given text. The containment is case insensitive. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5554 | * The search is performed by either the text that the View renders or the content |
| 5555 | * description that describes the view for accessibility purposes and the view does |
| 5556 | * not render or both. Clients can specify how the search is to be performed via |
| 5557 | * passing the {@link #FIND_VIEWS_WITH_TEXT} and |
| 5558 | * {@link #FIND_VIEWS_WITH_CONTENT_DESCRIPTION} flags. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5559 | * |
| 5560 | * @param outViews The output list of matching Views. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5561 | * @param searched The text to match against. |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 5562 | * |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5563 | * @see #FIND_VIEWS_WITH_TEXT |
| 5564 | * @see #FIND_VIEWS_WITH_CONTENT_DESCRIPTION |
| 5565 | * @see #setContentDescription(CharSequence) |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5566 | */ |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5567 | public void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 5568 | if (getAccessibilityNodeProvider() != null) { |
| 5569 | if ((flags & FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS) != 0) { |
| 5570 | outViews.add(this); |
| 5571 | } |
| 5572 | } else if ((flags & FIND_VIEWS_WITH_CONTENT_DESCRIPTION) != 0 |
| 5573 | && !TextUtils.isEmpty(searched) && !TextUtils.isEmpty(mContentDescription)) { |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5574 | String searchedLowerCase = searched.toString().toLowerCase(); |
| 5575 | String contentDescriptionLowerCase = mContentDescription.toString().toLowerCase(); |
| 5576 | if (contentDescriptionLowerCase.contains(searchedLowerCase)) { |
| 5577 | outViews.add(this); |
| 5578 | } |
| 5579 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5580 | } |
| 5581 | |
| 5582 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5583 | * Find and return all touchable views that are descendants of this view, |
| 5584 | * possibly including this view if it is touchable itself. |
| 5585 | * |
| 5586 | * @return A list of touchable views |
| 5587 | */ |
| 5588 | public ArrayList<View> getTouchables() { |
| 5589 | ArrayList<View> result = new ArrayList<View>(); |
| 5590 | addTouchables(result); |
| 5591 | return result; |
| 5592 | } |
| 5593 | |
| 5594 | /** |
| 5595 | * Add any touchable views that are descendants of this view (possibly |
| 5596 | * including this view if it is touchable itself) to views. |
| 5597 | * |
| 5598 | * @param views Touchable views found so far |
| 5599 | */ |
| 5600 | public void addTouchables(ArrayList<View> views) { |
| 5601 | final int viewFlags = mViewFlags; |
| 5602 | |
| 5603 | if (((viewFlags & CLICKABLE) == CLICKABLE || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) |
| 5604 | && (viewFlags & ENABLED_MASK) == ENABLED) { |
| 5605 | views.add(this); |
| 5606 | } |
| 5607 | } |
| 5608 | |
| 5609 | /** |
| 5610 | * Call this to try to give focus to a specific view or to one of its |
| 5611 | * descendants. |
| 5612 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5613 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 5614 | * false), or if it is focusable and it is not focusable in touch mode |
| 5615 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5616 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5617 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5618 | * have focus, and you want your parent to look for the next one. |
| 5619 | * |
| 5620 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with arguments |
| 5621 | * {@link #FOCUS_DOWN} and <code>null</code>. |
| 5622 | * |
| 5623 | * @return Whether this view or one of its descendants actually took focus. |
| 5624 | */ |
| 5625 | public final boolean requestFocus() { |
| 5626 | return requestFocus(View.FOCUS_DOWN); |
| 5627 | } |
| 5628 | |
| 5629 | |
| 5630 | /** |
| 5631 | * Call this to try to give focus to a specific view or to one of its |
| 5632 | * descendants and give it a hint about what direction focus is heading. |
| 5633 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5634 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 5635 | * false), or if it is focusable and it is not focusable in touch mode |
| 5636 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5637 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5638 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5639 | * have focus, and you want your parent to look for the next one. |
| 5640 | * |
| 5641 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with |
| 5642 | * <code>null</code> set for the previously focused rectangle. |
| 5643 | * |
| 5644 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 5645 | * @return Whether this view or one of its descendants actually took focus. |
| 5646 | */ |
| 5647 | public final boolean requestFocus(int direction) { |
| 5648 | return requestFocus(direction, null); |
| 5649 | } |
| 5650 | |
| 5651 | /** |
| 5652 | * Call this to try to give focus to a specific view or to one of its descendants |
| 5653 | * and give it hints about the direction and a specific rectangle that the focus |
| 5654 | * is coming from. The rectangle can help give larger views a finer grained hint |
| 5655 | * about where focus is coming from, and therefore, where to show selection, or |
| 5656 | * forward focus change internally. |
| 5657 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5658 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 5659 | * false), or if it is focusable and it is not focusable in touch mode |
| 5660 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5661 | * |
| 5662 | * A View will not take focus if it is not visible. |
| 5663 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5664 | * A View will not take focus if one of its parents has |
| 5665 | * {@link android.view.ViewGroup#getDescendantFocusability()} equal to |
| 5666 | * {@link ViewGroup#FOCUS_BLOCK_DESCENDANTS}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5667 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5668 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5669 | * have focus, and you want your parent to look for the next one. |
| 5670 | * |
| 5671 | * You may wish to override this method if your custom {@link View} has an internal |
| 5672 | * {@link View} that it wishes to forward the request to. |
| 5673 | * |
| 5674 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 5675 | * @param previouslyFocusedRect The rectangle (in this View's coordinate system) |
| 5676 | * to give a finer grained hint about where focus is coming from. May be null |
| 5677 | * if there is no hint. |
| 5678 | * @return Whether this view or one of its descendants actually took focus. |
| 5679 | */ |
| 5680 | public boolean requestFocus(int direction, Rect previouslyFocusedRect) { |
| 5681 | // need to be focusable |
| 5682 | if ((mViewFlags & FOCUSABLE_MASK) != FOCUSABLE || |
| 5683 | (mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 5684 | return false; |
| 5685 | } |
| 5686 | |
| 5687 | // need to be focusable in touch mode if in touch mode |
| 5688 | if (isInTouchMode() && |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5689 | (FOCUSABLE_IN_TOUCH_MODE != (mViewFlags & FOCUSABLE_IN_TOUCH_MODE))) { |
| 5690 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5691 | } |
| 5692 | |
| 5693 | // need to not have any parents blocking us |
| 5694 | if (hasAncestorThatBlocksDescendantFocus()) { |
| 5695 | return false; |
| 5696 | } |
| 5697 | |
| 5698 | handleFocusGainInternal(direction, previouslyFocusedRect); |
| 5699 | return true; |
| 5700 | } |
| 5701 | |
| 5702 | /** |
| 5703 | * Call this to try to give focus to a specific view or to one of its descendants. This is a |
| 5704 | * special variant of {@link #requestFocus() } that will allow views that are not focuable in |
| 5705 | * touch mode to request focus when they are touched. |
| 5706 | * |
| 5707 | * @return Whether this view or one of its descendants actually took focus. |
| 5708 | * |
| 5709 | * @see #isInTouchMode() |
| 5710 | * |
| 5711 | */ |
| 5712 | public final boolean requestFocusFromTouch() { |
| 5713 | // Leave touch mode if we need to |
| 5714 | if (isInTouchMode()) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 5715 | ViewRootImpl viewRoot = getViewRootImpl(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5716 | if (viewRoot != null) { |
| 5717 | viewRoot.ensureTouchMode(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5718 | } |
| 5719 | } |
| 5720 | return requestFocus(View.FOCUS_DOWN); |
| 5721 | } |
| 5722 | |
| 5723 | /** |
| 5724 | * @return Whether any ancestor of this view blocks descendant focus. |
| 5725 | */ |
| 5726 | private boolean hasAncestorThatBlocksDescendantFocus() { |
| 5727 | ViewParent ancestor = mParent; |
| 5728 | while (ancestor instanceof ViewGroup) { |
| 5729 | final ViewGroup vgAncestor = (ViewGroup) ancestor; |
| 5730 | if (vgAncestor.getDescendantFocusability() == ViewGroup.FOCUS_BLOCK_DESCENDANTS) { |
| 5731 | return true; |
| 5732 | } else { |
| 5733 | ancestor = vgAncestor.getParent(); |
| 5734 | } |
| 5735 | } |
| 5736 | return false; |
| 5737 | } |
| 5738 | |
| 5739 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5740 | * @hide |
| 5741 | */ |
| 5742 | public void dispatchStartTemporaryDetach() { |
| 5743 | onStartTemporaryDetach(); |
| 5744 | } |
| 5745 | |
| 5746 | /** |
| 5747 | * This is called when a container is going to temporarily detach a child, with |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5748 | * {@link ViewGroup#detachViewFromParent(View) ViewGroup.detachViewFromParent}. |
| 5749 | * It will either be followed by {@link #onFinishTemporaryDetach()} or |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5750 | * {@link #onDetachedFromWindow()} when the container is done. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5751 | */ |
| 5752 | public void onStartTemporaryDetach() { |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5753 | removeUnsetPressCallback(); |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 5754 | mPrivateFlags |= CANCEL_NEXT_UP_EVENT; |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5755 | } |
| 5756 | |
| 5757 | /** |
| 5758 | * @hide |
| 5759 | */ |
| 5760 | public void dispatchFinishTemporaryDetach() { |
| 5761 | onFinishTemporaryDetach(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5762 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5763 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5764 | /** |
| 5765 | * Called after {@link #onStartTemporaryDetach} when the container is done |
| 5766 | * changing the view. |
| 5767 | */ |
| 5768 | public void onFinishTemporaryDetach() { |
| 5769 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5770 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5771 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5772 | * Return the global {@link KeyEvent.DispatcherState KeyEvent.DispatcherState} |
| 5773 | * for this view's window. Returns null if the view is not currently attached |
| 5774 | * to the window. Normally you will not need to use this directly, but |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5775 | * just use the standard high-level event callbacks like |
| 5776 | * {@link #onKeyDown(int, KeyEvent)}. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5777 | */ |
| 5778 | public KeyEvent.DispatcherState getKeyDispatcherState() { |
| 5779 | return mAttachInfo != null ? mAttachInfo.mKeyDispatchState : null; |
| 5780 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 5781 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5782 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5783 | * Dispatch a key event before it is processed by any input method |
| 5784 | * associated with the view hierarchy. This can be used to intercept |
| 5785 | * key events in special situations before the IME consumes them; a |
| 5786 | * typical example would be handling the BACK key to update the application's |
| 5787 | * UI instead of allowing the IME to see it and close itself. |
| 5788 | * |
| 5789 | * @param event The key event to be dispatched. |
| 5790 | * @return True if the event was handled, false otherwise. |
| 5791 | */ |
| 5792 | public boolean dispatchKeyEventPreIme(KeyEvent event) { |
| 5793 | return onKeyPreIme(event.getKeyCode(), event); |
| 5794 | } |
| 5795 | |
| 5796 | /** |
| 5797 | * Dispatch a key event to the next view on the focus path. This path runs |
| 5798 | * from the top of the view tree down to the currently focused view. If this |
| 5799 | * view has focus, it will dispatch to itself. Otherwise it will dispatch |
| 5800 | * the next node down the focus path. This method also fires any key |
| 5801 | * listeners. |
| 5802 | * |
| 5803 | * @param event The key event to be dispatched. |
| 5804 | * @return True if the event was handled, false otherwise. |
| 5805 | */ |
| 5806 | public boolean dispatchKeyEvent(KeyEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5807 | if (mInputEventConsistencyVerifier != null) { |
| 5808 | mInputEventConsistencyVerifier.onKeyEvent(event, 0); |
| 5809 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5810 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5811 | // Give any attached key listener a first crack at the event. |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 5812 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 5813 | ListenerInfo li = mListenerInfo; |
| 5814 | if (li != null && li.mOnKeyListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5815 | && li.mOnKeyListener.onKey(this, event.getKeyCode(), event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5816 | return true; |
| 5817 | } |
| 5818 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5819 | if (event.dispatch(this, mAttachInfo != null |
| 5820 | ? mAttachInfo.mKeyDispatchState : null, this)) { |
| 5821 | return true; |
| 5822 | } |
| 5823 | |
| 5824 | if (mInputEventConsistencyVerifier != null) { |
| 5825 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 5826 | } |
| 5827 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5828 | } |
| 5829 | |
| 5830 | /** |
| 5831 | * Dispatches a key shortcut event. |
| 5832 | * |
| 5833 | * @param event The key event to be dispatched. |
| 5834 | * @return True if the event was handled by the view, false otherwise. |
| 5835 | */ |
| 5836 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 5837 | return onKeyShortcut(event.getKeyCode(), event); |
| 5838 | } |
| 5839 | |
| 5840 | /** |
| 5841 | * Pass the touch screen motion event down to the target view, or this |
| 5842 | * view if it is the target. |
| 5843 | * |
| 5844 | * @param event The motion event to be dispatched. |
| 5845 | * @return True if the event was handled by the view, false otherwise. |
| 5846 | */ |
| 5847 | public boolean dispatchTouchEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5848 | if (mInputEventConsistencyVerifier != null) { |
| 5849 | mInputEventConsistencyVerifier.onTouchEvent(event, 0); |
| 5850 | } |
| 5851 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5852 | if (onFilterTouchEventForSecurity(event)) { |
| 5853 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 5854 | ListenerInfo li = mListenerInfo; |
| 5855 | if (li != null && li.mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5856 | && li.mOnTouchListener.onTouch(this, event)) { |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5857 | return true; |
| 5858 | } |
| 5859 | |
| 5860 | if (onTouchEvent(event)) { |
| 5861 | return true; |
| 5862 | } |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5863 | } |
| 5864 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5865 | if (mInputEventConsistencyVerifier != null) { |
| 5866 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5867 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5868 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5869 | } |
| 5870 | |
| 5871 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5872 | * Filter the touch event to apply security policies. |
| 5873 | * |
| 5874 | * @param event The motion event to be filtered. |
| 5875 | * @return True if the event should be dispatched, false if the event should be dropped. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 5876 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5877 | * @see #getFilterTouchesWhenObscured |
| 5878 | */ |
| 5879 | public boolean onFilterTouchEventForSecurity(MotionEvent event) { |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 5880 | //noinspection RedundantIfStatement |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5881 | if ((mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0 |
| 5882 | && (event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) { |
| 5883 | // Window is obscured, drop this touch. |
| 5884 | return false; |
| 5885 | } |
| 5886 | return true; |
| 5887 | } |
| 5888 | |
| 5889 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5890 | * Pass a trackball motion event down to the focused view. |
| 5891 | * |
| 5892 | * @param event The motion event to be dispatched. |
| 5893 | * @return True if the event was handled by the view, false otherwise. |
| 5894 | */ |
| 5895 | public boolean dispatchTrackballEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5896 | if (mInputEventConsistencyVerifier != null) { |
| 5897 | mInputEventConsistencyVerifier.onTrackballEvent(event, 0); |
| 5898 | } |
| 5899 | |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 5900 | return onTrackballEvent(event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5901 | } |
| 5902 | |
| 5903 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5904 | * Dispatch a generic motion event. |
| 5905 | * <p> |
| 5906 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 5907 | * are delivered to the view under the pointer. All other generic motion events are |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5908 | * delivered to the focused view. Hover events are handled specially and are delivered |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5909 | * to {@link #onHoverEvent(MotionEvent)}. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5910 | * </p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5911 | * |
| 5912 | * @param event The motion event to be dispatched. |
| 5913 | * @return True if the event was handled by the view, false otherwise. |
| 5914 | */ |
| 5915 | public boolean dispatchGenericMotionEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5916 | if (mInputEventConsistencyVerifier != null) { |
| 5917 | mInputEventConsistencyVerifier.onGenericMotionEvent(event, 0); |
| 5918 | } |
| 5919 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5920 | final int source = event.getSource(); |
| 5921 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 5922 | final int action = event.getAction(); |
| 5923 | if (action == MotionEvent.ACTION_HOVER_ENTER |
| 5924 | || action == MotionEvent.ACTION_HOVER_MOVE |
| 5925 | || action == MotionEvent.ACTION_HOVER_EXIT) { |
| 5926 | if (dispatchHoverEvent(event)) { |
| 5927 | return true; |
| 5928 | } |
| 5929 | } else if (dispatchGenericPointerEvent(event)) { |
| 5930 | return true; |
| 5931 | } |
| 5932 | } else if (dispatchGenericFocusedEvent(event)) { |
| 5933 | return true; |
| 5934 | } |
| 5935 | |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 5936 | if (dispatchGenericMotionEventInternal(event)) { |
| 5937 | return true; |
| 5938 | } |
| 5939 | |
| 5940 | if (mInputEventConsistencyVerifier != null) { |
| 5941 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 5942 | } |
| 5943 | return false; |
| 5944 | } |
| 5945 | |
| 5946 | private boolean dispatchGenericMotionEventInternal(MotionEvent event) { |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 5947 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 5948 | ListenerInfo li = mListenerInfo; |
| 5949 | if (li != null && li.mOnGenericMotionListener != null |
| 5950 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5951 | && li.mOnGenericMotionListener.onGenericMotion(this, event)) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5952 | return true; |
| 5953 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5954 | |
| 5955 | if (onGenericMotionEvent(event)) { |
| 5956 | return true; |
| 5957 | } |
| 5958 | |
| 5959 | if (mInputEventConsistencyVerifier != null) { |
| 5960 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 5961 | } |
| 5962 | return false; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5963 | } |
| 5964 | |
| 5965 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5966 | * Dispatch a hover event. |
| 5967 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5968 | * Do not call this method directly. |
| 5969 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5970 | * </p> |
| 5971 | * |
| 5972 | * @param event The motion event to be dispatched. |
| 5973 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5974 | */ |
| 5975 | protected boolean dispatchHoverEvent(MotionEvent event) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 5976 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 5977 | ListenerInfo li = mListenerInfo; |
| 5978 | if (li != null && li.mOnHoverListener != null |
| 5979 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5980 | && li.mOnHoverListener.onHover(this, event)) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 5981 | return true; |
| 5982 | } |
| 5983 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5984 | return onHoverEvent(event); |
| 5985 | } |
| 5986 | |
| 5987 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 5988 | * Returns true if the view has a child to which it has recently sent |
| 5989 | * {@link MotionEvent#ACTION_HOVER_ENTER}. If this view is hovered and |
| 5990 | * it does not have a hovered child, then it must be the innermost hovered view. |
| 5991 | * @hide |
| 5992 | */ |
| 5993 | protected boolean hasHoveredChild() { |
| 5994 | return false; |
| 5995 | } |
| 5996 | |
| 5997 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5998 | * Dispatch a generic motion event to the view under the first pointer. |
| 5999 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6000 | * Do not call this method directly. |
| 6001 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6002 | * </p> |
| 6003 | * |
| 6004 | * @param event The motion event to be dispatched. |
| 6005 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6006 | */ |
| 6007 | protected boolean dispatchGenericPointerEvent(MotionEvent event) { |
| 6008 | return false; |
| 6009 | } |
| 6010 | |
| 6011 | /** |
| 6012 | * Dispatch a generic motion event to the currently focused view. |
| 6013 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6014 | * Do not call this method directly. |
| 6015 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6016 | * </p> |
| 6017 | * |
| 6018 | * @param event The motion event to be dispatched. |
| 6019 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6020 | */ |
| 6021 | protected boolean dispatchGenericFocusedEvent(MotionEvent event) { |
| 6022 | return false; |
| 6023 | } |
| 6024 | |
| 6025 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6026 | * Dispatch a pointer event. |
| 6027 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6028 | * Dispatches touch related pointer events to {@link #onTouchEvent(MotionEvent)} and all |
| 6029 | * other events to {@link #onGenericMotionEvent(MotionEvent)}. This separation of concerns |
| 6030 | * reinforces the invariant that {@link #onTouchEvent(MotionEvent)} is really about touches |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6031 | * and should not be expected to handle other pointing device features. |
| 6032 | * </p> |
| 6033 | * |
| 6034 | * @param event The motion event to be dispatched. |
| 6035 | * @return True if the event was handled by the view, false otherwise. |
| 6036 | * @hide |
| 6037 | */ |
| 6038 | public final boolean dispatchPointerEvent(MotionEvent event) { |
| 6039 | if (event.isTouchEvent()) { |
| 6040 | return dispatchTouchEvent(event); |
| 6041 | } else { |
| 6042 | return dispatchGenericMotionEvent(event); |
| 6043 | } |
| 6044 | } |
| 6045 | |
| 6046 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6047 | * Called when the window containing this view gains or loses window focus. |
| 6048 | * ViewGroups should override to route to their children. |
| 6049 | * |
| 6050 | * @param hasFocus True if the window containing this view now has focus, |
| 6051 | * false otherwise. |
| 6052 | */ |
| 6053 | public void dispatchWindowFocusChanged(boolean hasFocus) { |
| 6054 | onWindowFocusChanged(hasFocus); |
| 6055 | } |
| 6056 | |
| 6057 | /** |
| 6058 | * Called when the window containing this view gains or loses focus. Note |
| 6059 | * that this is separate from view focus: to receive key events, both |
| 6060 | * your view and its window must have focus. If a window is displayed |
| 6061 | * on top of yours that takes input focus, then your own window will lose |
| 6062 | * focus but the view focus will remain unchanged. |
| 6063 | * |
| 6064 | * @param hasWindowFocus True if the window containing this view now has |
| 6065 | * focus, false otherwise. |
| 6066 | */ |
| 6067 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 6068 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 6069 | if (!hasWindowFocus) { |
| 6070 | if (isPressed()) { |
| 6071 | setPressed(false); |
| 6072 | } |
| 6073 | if (imm != null && (mPrivateFlags & FOCUSED) != 0) { |
| 6074 | imm.focusOut(this); |
| 6075 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6076 | removeLongPressCallback(); |
Tony Wu | 26edf20 | 2010-09-13 19:54:00 +0800 | [diff] [blame] | 6077 | removeTapCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 6078 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6079 | } else if (imm != null && (mPrivateFlags & FOCUSED) != 0) { |
| 6080 | imm.focusIn(this); |
| 6081 | } |
| 6082 | refreshDrawableState(); |
| 6083 | } |
| 6084 | |
| 6085 | /** |
| 6086 | * Returns true if this view is in a window that currently has window focus. |
| 6087 | * Note that this is not the same as the view itself having focus. |
| 6088 | * |
| 6089 | * @return True if this view is in a window that currently has window focus. |
| 6090 | */ |
| 6091 | public boolean hasWindowFocus() { |
| 6092 | return mAttachInfo != null && mAttachInfo.mHasWindowFocus; |
| 6093 | } |
| 6094 | |
| 6095 | /** |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6096 | * Dispatch a view visibility change down the view hierarchy. |
| 6097 | * ViewGroups should override to route to their children. |
| 6098 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 6099 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6100 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 6101 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6102 | */ |
| 6103 | protected void dispatchVisibilityChanged(View changedView, int visibility) { |
| 6104 | onVisibilityChanged(changedView, visibility); |
| 6105 | } |
| 6106 | |
| 6107 | /** |
| 6108 | * Called when the visibility of the view or an ancestor of the view is changed. |
| 6109 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 6110 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6111 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 6112 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6113 | */ |
| 6114 | protected void onVisibilityChanged(View changedView, int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 6115 | if (visibility == VISIBLE) { |
| 6116 | if (mAttachInfo != null) { |
| 6117 | initialAwakenScrollBars(); |
| 6118 | } else { |
| 6119 | mPrivateFlags |= AWAKEN_SCROLL_BARS_ON_ATTACH; |
| 6120 | } |
| 6121 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6122 | } |
| 6123 | |
| 6124 | /** |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6125 | * Dispatch a hint about whether this view is displayed. For instance, when |
| 6126 | * a View moves out of the screen, it might receives a display hint indicating |
| 6127 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 6128 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6129 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6130 | * @param hint A hint about whether or not this view is displayed: |
| 6131 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 6132 | */ |
| 6133 | public void dispatchDisplayHint(int hint) { |
| 6134 | onDisplayHint(hint); |
| 6135 | } |
| 6136 | |
| 6137 | /** |
| 6138 | * Gives this view a hint about whether is displayed or not. For instance, when |
| 6139 | * a View moves out of the screen, it might receives a display hint indicating |
| 6140 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 6141 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6142 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6143 | * @param hint A hint about whether or not this view is displayed: |
| 6144 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 6145 | */ |
| 6146 | protected void onDisplayHint(int hint) { |
| 6147 | } |
| 6148 | |
| 6149 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6150 | * Dispatch a window visibility change down the view hierarchy. |
| 6151 | * ViewGroups should override to route to their children. |
| 6152 | * |
| 6153 | * @param visibility The new visibility of the window. |
| 6154 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6155 | * @see #onWindowVisibilityChanged(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6156 | */ |
| 6157 | public void dispatchWindowVisibilityChanged(int visibility) { |
| 6158 | onWindowVisibilityChanged(visibility); |
| 6159 | } |
| 6160 | |
| 6161 | /** |
| 6162 | * Called when the window containing has change its visibility |
| 6163 | * (between {@link #GONE}, {@link #INVISIBLE}, and {@link #VISIBLE}). Note |
| 6164 | * that this tells you whether or not your window is being made visible |
| 6165 | * to the window manager; this does <em>not</em> tell you whether or not |
| 6166 | * your window is obscured by other windows on the screen, even if it |
| 6167 | * is itself visible. |
| 6168 | * |
| 6169 | * @param visibility The new visibility of the window. |
| 6170 | */ |
| 6171 | protected void onWindowVisibilityChanged(int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 6172 | if (visibility == VISIBLE) { |
| 6173 | initialAwakenScrollBars(); |
| 6174 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6175 | } |
| 6176 | |
| 6177 | /** |
| 6178 | * Returns the current visibility of the window this view is attached to |
| 6179 | * (either {@link #GONE}, {@link #INVISIBLE}, or {@link #VISIBLE}). |
| 6180 | * |
| 6181 | * @return Returns the current visibility of the view's window. |
| 6182 | */ |
| 6183 | public int getWindowVisibility() { |
| 6184 | return mAttachInfo != null ? mAttachInfo.mWindowVisibility : GONE; |
| 6185 | } |
| 6186 | |
| 6187 | /** |
| 6188 | * Retrieve the overall visible display size in which the window this view is |
| 6189 | * attached to has been positioned in. This takes into account screen |
| 6190 | * decorations above the window, for both cases where the window itself |
| 6191 | * is being position inside of them or the window is being placed under |
| 6192 | * then and covered insets are used for the window to position its content |
| 6193 | * inside. In effect, this tells you the available area where content can |
| 6194 | * be placed and remain visible to users. |
| 6195 | * |
| 6196 | * <p>This function requires an IPC back to the window manager to retrieve |
| 6197 | * the requested information, so should not be used in performance critical |
| 6198 | * code like drawing. |
| 6199 | * |
| 6200 | * @param outRect Filled in with the visible display frame. If the view |
| 6201 | * is not attached to a window, this is simply the raw display size. |
| 6202 | */ |
| 6203 | public void getWindowVisibleDisplayFrame(Rect outRect) { |
| 6204 | if (mAttachInfo != null) { |
| 6205 | try { |
| 6206 | mAttachInfo.mSession.getDisplayFrame(mAttachInfo.mWindow, outRect); |
| 6207 | } catch (RemoteException e) { |
| 6208 | return; |
| 6209 | } |
| 6210 | // XXX This is really broken, and probably all needs to be done |
| 6211 | // in the window manager, and we need to know more about whether |
| 6212 | // we want the area behind or in front of the IME. |
| 6213 | final Rect insets = mAttachInfo.mVisibleInsets; |
| 6214 | outRect.left += insets.left; |
| 6215 | outRect.top += insets.top; |
| 6216 | outRect.right -= insets.right; |
| 6217 | outRect.bottom -= insets.bottom; |
| 6218 | return; |
| 6219 | } |
| 6220 | Display d = WindowManagerImpl.getDefault().getDefaultDisplay(); |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 6221 | d.getRectSize(outRect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6222 | } |
| 6223 | |
| 6224 | /** |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6225 | * Dispatch a notification about a resource configuration change down |
| 6226 | * the view hierarchy. |
| 6227 | * ViewGroups should override to route to their children. |
| 6228 | * |
| 6229 | * @param newConfig The new resource configuration. |
| 6230 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6231 | * @see #onConfigurationChanged(android.content.res.Configuration) |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6232 | */ |
| 6233 | public void dispatchConfigurationChanged(Configuration newConfig) { |
| 6234 | onConfigurationChanged(newConfig); |
| 6235 | } |
| 6236 | |
| 6237 | /** |
| 6238 | * Called when the current configuration of the resources being used |
| 6239 | * by the application have changed. You can use this to decide when |
| 6240 | * to reload resources that can changed based on orientation and other |
| 6241 | * configuration characterstics. You only need to use this if you are |
| 6242 | * not relying on the normal {@link android.app.Activity} mechanism of |
| 6243 | * recreating the activity instance upon a configuration change. |
| 6244 | * |
| 6245 | * @param newConfig The new resource configuration. |
| 6246 | */ |
| 6247 | protected void onConfigurationChanged(Configuration newConfig) { |
| 6248 | } |
| 6249 | |
| 6250 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6251 | * Private function to aggregate all per-view attributes in to the view |
| 6252 | * root. |
| 6253 | */ |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 6254 | void dispatchCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 6255 | performCollectViewAttributes(attachInfo, visibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6256 | } |
| 6257 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 6258 | void performCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 6259 | if ((visibility & VISIBILITY_MASK) == VISIBLE) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6260 | if ((mViewFlags & KEEP_SCREEN_ON) == KEEP_SCREEN_ON) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 6261 | attachInfo.mKeepScreenOn = true; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6262 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 6263 | attachInfo.mSystemUiVisibility |= mSystemUiVisibility; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6264 | ListenerInfo li = mListenerInfo; |
| 6265 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 6266 | attachInfo.mHasSystemUiListeners = true; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6267 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6268 | } |
| 6269 | } |
| 6270 | |
| 6271 | void needGlobalAttributesUpdate(boolean force) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6272 | final AttachInfo ai = mAttachInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6273 | if (ai != null) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6274 | if (force || ai.mKeepScreenOn || (ai.mSystemUiVisibility != 0) |
| 6275 | || ai.mHasSystemUiListeners) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6276 | ai.mRecomputeGlobalAttributes = true; |
| 6277 | } |
| 6278 | } |
| 6279 | } |
| 6280 | |
| 6281 | /** |
| 6282 | * Returns whether the device is currently in touch mode. Touch mode is entered |
| 6283 | * once the user begins interacting with the device by touch, and affects various |
| 6284 | * things like whether focus is always visible to the user. |
| 6285 | * |
| 6286 | * @return Whether the device is in touch mode. |
| 6287 | */ |
| 6288 | @ViewDebug.ExportedProperty |
| 6289 | public boolean isInTouchMode() { |
| 6290 | if (mAttachInfo != null) { |
| 6291 | return mAttachInfo.mInTouchMode; |
| 6292 | } else { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6293 | return ViewRootImpl.isInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6294 | } |
| 6295 | } |
| 6296 | |
| 6297 | /** |
| 6298 | * Returns the context the view is running in, through which it can |
| 6299 | * access the current theme, resources, etc. |
| 6300 | * |
| 6301 | * @return The view's Context. |
| 6302 | */ |
| 6303 | @ViewDebug.CapturedViewProperty |
| 6304 | public final Context getContext() { |
| 6305 | return mContext; |
| 6306 | } |
| 6307 | |
| 6308 | /** |
| 6309 | * Handle a key event before it is processed by any input method |
| 6310 | * associated with the view hierarchy. This can be used to intercept |
| 6311 | * key events in special situations before the IME consumes them; a |
| 6312 | * typical example would be handling the BACK key to update the application's |
| 6313 | * UI instead of allowing the IME to see it and close itself. |
| 6314 | * |
| 6315 | * @param keyCode The value in event.getKeyCode(). |
| 6316 | * @param event Description of the key event. |
| 6317 | * @return If you handled the event, return true. If you want to allow the |
| 6318 | * event to be handled by the next receiver, return false. |
| 6319 | */ |
| 6320 | public boolean onKeyPreIme(int keyCode, KeyEvent event) { |
| 6321 | return false; |
| 6322 | } |
| 6323 | |
| 6324 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 6325 | * Default implementation of {@link KeyEvent.Callback#onKeyDown(int, KeyEvent) |
| 6326 | * KeyEvent.Callback.onKeyDown()}: perform press of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6327 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or {@link KeyEvent#KEYCODE_ENTER} |
| 6328 | * is released, if the view is enabled and clickable. |
| 6329 | * |
| 6330 | * @param keyCode A key code that represents the button pressed, from |
| 6331 | * {@link android.view.KeyEvent}. |
| 6332 | * @param event The KeyEvent object that defines the button action. |
| 6333 | */ |
| 6334 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 6335 | boolean result = false; |
| 6336 | |
| 6337 | switch (keyCode) { |
| 6338 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 6339 | case KeyEvent.KEYCODE_ENTER: { |
| 6340 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 6341 | return true; |
| 6342 | } |
| 6343 | // Long clickable items don't necessarily have to be clickable |
| 6344 | if (((mViewFlags & CLICKABLE) == CLICKABLE || |
| 6345 | (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) && |
| 6346 | (event.getRepeatCount() == 0)) { |
| 6347 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6348 | checkForLongClick(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6349 | return true; |
| 6350 | } |
| 6351 | break; |
| 6352 | } |
| 6353 | } |
| 6354 | return result; |
| 6355 | } |
| 6356 | |
| 6357 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6358 | * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
| 6359 | * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle |
| 6360 | * the event). |
| 6361 | */ |
| 6362 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 6363 | return false; |
| 6364 | } |
| 6365 | |
| 6366 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 6367 | * Default implementation of {@link KeyEvent.Callback#onKeyUp(int, KeyEvent) |
| 6368 | * KeyEvent.Callback.onKeyUp()}: perform clicking of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6369 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or |
| 6370 | * {@link KeyEvent#KEYCODE_ENTER} is released. |
| 6371 | * |
| 6372 | * @param keyCode A key code that represents the button pressed, from |
| 6373 | * {@link android.view.KeyEvent}. |
| 6374 | * @param event The KeyEvent object that defines the button action. |
| 6375 | */ |
| 6376 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 6377 | boolean result = false; |
| 6378 | |
| 6379 | switch (keyCode) { |
| 6380 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 6381 | case KeyEvent.KEYCODE_ENTER: { |
| 6382 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 6383 | return true; |
| 6384 | } |
| 6385 | if ((mViewFlags & CLICKABLE) == CLICKABLE && isPressed()) { |
| 6386 | setPressed(false); |
| 6387 | |
| 6388 | if (!mHasPerformedLongPress) { |
| 6389 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6390 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6391 | |
| 6392 | result = performClick(); |
| 6393 | } |
| 6394 | } |
| 6395 | break; |
| 6396 | } |
| 6397 | } |
| 6398 | return result; |
| 6399 | } |
| 6400 | |
| 6401 | /** |
| 6402 | * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) |
| 6403 | * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle |
| 6404 | * the event). |
| 6405 | * |
| 6406 | * @param keyCode A key code that represents the button pressed, from |
| 6407 | * {@link android.view.KeyEvent}. |
| 6408 | * @param repeatCount The number of times the action was made. |
| 6409 | * @param event The KeyEvent object that defines the button action. |
| 6410 | */ |
| 6411 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 6412 | return false; |
| 6413 | } |
| 6414 | |
| 6415 | /** |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 6416 | * Called on the focused view when a key shortcut event is not handled. |
| 6417 | * Override this method to implement local key shortcuts for the View. |
| 6418 | * Key shortcuts can also be implemented by setting the |
| 6419 | * {@link MenuItem#setShortcut(char, char) shortcut} property of menu items. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6420 | * |
| 6421 | * @param keyCode The value in event.getKeyCode(). |
| 6422 | * @param event Description of the key event. |
| 6423 | * @return If you handled the event, return true. If you want to allow the |
| 6424 | * event to be handled by the next receiver, return false. |
| 6425 | */ |
| 6426 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
| 6427 | return false; |
| 6428 | } |
| 6429 | |
| 6430 | /** |
| 6431 | * Check whether the called view is a text editor, in which case it |
| 6432 | * would make sense to automatically display a soft input window for |
| 6433 | * it. Subclasses should override this if they implement |
| 6434 | * {@link #onCreateInputConnection(EditorInfo)} to return true if |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 6435 | * a call on that method would return a non-null InputConnection, and |
| 6436 | * they are really a first-class editor that the user would normally |
| 6437 | * start typing on when the go into a window containing your view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6438 | * |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 6439 | * <p>The default implementation always returns false. This does |
| 6440 | * <em>not</em> mean that its {@link #onCreateInputConnection(EditorInfo)} |
| 6441 | * will not be called or the user can not otherwise perform edits on your |
| 6442 | * view; it is just a hint to the system that this is not the primary |
| 6443 | * purpose of this view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6444 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6445 | * @return Returns true if this view is a text editor, else false. |
| 6446 | */ |
| 6447 | public boolean onCheckIsTextEditor() { |
| 6448 | return false; |
| 6449 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6451 | /** |
| 6452 | * Create a new InputConnection for an InputMethod to interact |
| 6453 | * with the view. The default implementation returns null, since it doesn't |
| 6454 | * support input methods. You can override this to implement such support. |
| 6455 | * This is only needed for views that take focus and text input. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6456 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6457 | * <p>When implementing this, you probably also want to implement |
| 6458 | * {@link #onCheckIsTextEditor()} to indicate you will return a |
| 6459 | * non-null InputConnection. |
| 6460 | * |
| 6461 | * @param outAttrs Fill in with attribute information about the connection. |
| 6462 | */ |
| 6463 | public InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
| 6464 | return null; |
| 6465 | } |
| 6466 | |
| 6467 | /** |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 6468 | * Called by the {@link android.view.inputmethod.InputMethodManager} |
| 6469 | * when a view who is not the current |
| 6470 | * input connection target is trying to make a call on the manager. The |
| 6471 | * default implementation returns false; you can override this to return |
| 6472 | * true for certain views if you are performing InputConnection proxying |
| 6473 | * to them. |
| 6474 | * @param view The View that is making the InputMethodManager call. |
| 6475 | * @return Return true to allow the call, false to reject. |
| 6476 | */ |
| 6477 | public boolean checkInputConnectionProxy(View view) { |
| 6478 | return false; |
| 6479 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6480 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 6481 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6482 | * Show the context menu for this view. It is not safe to hold on to the |
| 6483 | * menu after returning from this method. |
| 6484 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 6485 | * You should normally not overload this method. Overload |
| 6486 | * {@link #onCreateContextMenu(ContextMenu)} or define an |
| 6487 | * {@link OnCreateContextMenuListener} to add items to the context menu. |
| 6488 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6489 | * @param menu The context menu to populate |
| 6490 | */ |
| 6491 | public void createContextMenu(ContextMenu menu) { |
| 6492 | ContextMenuInfo menuInfo = getContextMenuInfo(); |
| 6493 | |
| 6494 | // Sets the current menu info so all items added to menu will have |
| 6495 | // my extra info set. |
| 6496 | ((MenuBuilder)menu).setCurrentMenuInfo(menuInfo); |
| 6497 | |
| 6498 | onCreateContextMenu(menu); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6499 | ListenerInfo li = mListenerInfo; |
| 6500 | if (li != null && li.mOnCreateContextMenuListener != null) { |
| 6501 | li.mOnCreateContextMenuListener.onCreateContextMenu(menu, this, menuInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6502 | } |
| 6503 | |
| 6504 | // Clear the extra information so subsequent items that aren't mine don't |
| 6505 | // have my extra info. |
| 6506 | ((MenuBuilder)menu).setCurrentMenuInfo(null); |
| 6507 | |
| 6508 | if (mParent != null) { |
| 6509 | mParent.createContextMenu(menu); |
| 6510 | } |
| 6511 | } |
| 6512 | |
| 6513 | /** |
| 6514 | * Views should implement this if they have extra information to associate |
| 6515 | * with the context menu. The return result is supplied as a parameter to |
| 6516 | * the {@link OnCreateContextMenuListener#onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} |
| 6517 | * callback. |
| 6518 | * |
| 6519 | * @return Extra information about the item for which the context menu |
| 6520 | * should be shown. This information will vary across different |
| 6521 | * subclasses of View. |
| 6522 | */ |
| 6523 | protected ContextMenuInfo getContextMenuInfo() { |
| 6524 | return null; |
| 6525 | } |
| 6526 | |
| 6527 | /** |
| 6528 | * Views should implement this if the view itself is going to add items to |
| 6529 | * the context menu. |
| 6530 | * |
| 6531 | * @param menu the context menu to populate |
| 6532 | */ |
| 6533 | protected void onCreateContextMenu(ContextMenu menu) { |
| 6534 | } |
| 6535 | |
| 6536 | /** |
| 6537 | * Implement this method to handle trackball motion events. The |
| 6538 | * <em>relative</em> movement of the trackball since the last event |
| 6539 | * can be retrieve with {@link MotionEvent#getX MotionEvent.getX()} and |
| 6540 | * {@link MotionEvent#getY MotionEvent.getY()}. These are normalized so |
| 6541 | * that a movement of 1 corresponds to the user pressing one DPAD key (so |
| 6542 | * they will often be fractional values, representing the more fine-grained |
| 6543 | * movement information available from a trackball). |
| 6544 | * |
| 6545 | * @param event The motion event. |
| 6546 | * @return True if the event was handled, false otherwise. |
| 6547 | */ |
| 6548 | public boolean onTrackballEvent(MotionEvent event) { |
| 6549 | return false; |
| 6550 | } |
| 6551 | |
| 6552 | /** |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6553 | * Implement this method to handle generic motion events. |
| 6554 | * <p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6555 | * Generic motion events describe joystick movements, mouse hovers, track pad |
| 6556 | * touches, scroll wheel movements and other input events. The |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6557 | * {@link MotionEvent#getSource() source} of the motion event specifies |
| 6558 | * the class of input that was received. Implementations of this method |
| 6559 | * must examine the bits in the source before processing the event. |
| 6560 | * The following code example shows how this is done. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6561 | * </p><p> |
| 6562 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 6563 | * are delivered to the view under the pointer. All other generic motion events are |
| 6564 | * delivered to the focused view. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6565 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 6566 | * <pre> public boolean onGenericMotionEvent(MotionEvent event) { |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6567 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6568 | * if (event.getAction() == MotionEvent.ACTION_MOVE) { |
| 6569 | * // process the joystick movement... |
| 6570 | * return true; |
| 6571 | * } |
| 6572 | * } |
| 6573 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 6574 | * switch (event.getAction()) { |
| 6575 | * case MotionEvent.ACTION_HOVER_MOVE: |
| 6576 | * // process the mouse hover movement... |
| 6577 | * return true; |
| 6578 | * case MotionEvent.ACTION_SCROLL: |
| 6579 | * // process the scroll wheel movement... |
| 6580 | * return true; |
| 6581 | * } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6582 | * } |
| 6583 | * return super.onGenericMotionEvent(event); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 6584 | * }</pre> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6585 | * |
| 6586 | * @param event The generic motion event being processed. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6587 | * @return True if the event was handled, false otherwise. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6588 | */ |
| 6589 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 6590 | return false; |
| 6591 | } |
| 6592 | |
| 6593 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6594 | * Implement this method to handle hover events. |
| 6595 | * <p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6596 | * This method is called whenever a pointer is hovering into, over, or out of the |
| 6597 | * bounds of a view and the view is not currently being touched. |
| 6598 | * Hover events are represented as pointer events with action |
| 6599 | * {@link MotionEvent#ACTION_HOVER_ENTER}, {@link MotionEvent#ACTION_HOVER_MOVE}, |
| 6600 | * or {@link MotionEvent#ACTION_HOVER_EXIT}. |
| 6601 | * </p> |
| 6602 | * <ul> |
| 6603 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_ENTER} |
| 6604 | * when the pointer enters the bounds of the view.</li> |
| 6605 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_MOVE} |
| 6606 | * when the pointer has already entered the bounds of the view and has moved.</li> |
| 6607 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_EXIT} |
| 6608 | * when the pointer has exited the bounds of the view or when the pointer is |
| 6609 | * about to go down due to a button click, tap, or similar user action that |
| 6610 | * causes the view to be touched.</li> |
| 6611 | * </ul> |
| 6612 | * <p> |
| 6613 | * The view should implement this method to return true to indicate that it is |
| 6614 | * handling the hover event, such as by changing its drawable state. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6615 | * </p><p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6616 | * The default implementation calls {@link #setHovered} to update the hovered state |
| 6617 | * of the view when a hover enter or hover exit event is received, if the view |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 6618 | * is enabled and is clickable. The default implementation also sends hover |
| 6619 | * accessibility events. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6620 | * </p> |
| 6621 | * |
| 6622 | * @param event The motion event that describes the hover. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6623 | * @return True if the view handled the hover event. |
| 6624 | * |
| 6625 | * @see #isHovered |
| 6626 | * @see #setHovered |
| 6627 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6628 | */ |
| 6629 | public boolean onHoverEvent(MotionEvent event) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 6630 | // The root view may receive hover (or touch) events that are outside the bounds of |
| 6631 | // the window. This code ensures that we only send accessibility events for |
| 6632 | // hovers that are actually within the bounds of the root view. |
| 6633 | final int action = event.getAction(); |
| 6634 | if (!mSendingHoverAccessibilityEvents) { |
| 6635 | if ((action == MotionEvent.ACTION_HOVER_ENTER |
| 6636 | || action == MotionEvent.ACTION_HOVER_MOVE) |
| 6637 | && !hasHoveredChild() |
| 6638 | && pointInView(event.getX(), event.getY())) { |
| 6639 | mSendingHoverAccessibilityEvents = true; |
| 6640 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER); |
| 6641 | } |
| 6642 | } else { |
| 6643 | if (action == MotionEvent.ACTION_HOVER_EXIT |
| 6644 | || (action == MotionEvent.ACTION_HOVER_MOVE |
| 6645 | && !pointInView(event.getX(), event.getY()))) { |
| 6646 | mSendingHoverAccessibilityEvents = false; |
| 6647 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT); |
| 6648 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 6649 | } |
| 6650 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6651 | if (isHoverable()) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 6652 | switch (action) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6653 | case MotionEvent.ACTION_HOVER_ENTER: |
| 6654 | setHovered(true); |
| 6655 | break; |
| 6656 | case MotionEvent.ACTION_HOVER_EXIT: |
| 6657 | setHovered(false); |
| 6658 | break; |
| 6659 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 6660 | |
| 6661 | // Dispatch the event to onGenericMotionEvent before returning true. |
| 6662 | // This is to provide compatibility with existing applications that |
| 6663 | // handled HOVER_MOVE events in onGenericMotionEvent and that would |
| 6664 | // break because of the new default handling for hoverable views |
| 6665 | // in onHoverEvent. |
| 6666 | // Note that onGenericMotionEvent will be called by default when |
| 6667 | // onHoverEvent returns false (refer to dispatchGenericMotionEvent). |
| 6668 | dispatchGenericMotionEventInternal(event); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6669 | return true; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6670 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6671 | return false; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6672 | } |
| 6673 | |
| 6674 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6675 | * Returns true if the view should handle {@link #onHoverEvent} |
| 6676 | * by calling {@link #setHovered} to change its hovered state. |
| 6677 | * |
| 6678 | * @return True if the view is hoverable. |
| 6679 | */ |
| 6680 | private boolean isHoverable() { |
| 6681 | final int viewFlags = mViewFlags; |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 6682 | //noinspection SimplifiableIfStatement |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6683 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
| 6684 | return false; |
| 6685 | } |
| 6686 | |
| 6687 | return (viewFlags & CLICKABLE) == CLICKABLE |
| 6688 | || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 6689 | } |
| 6690 | |
| 6691 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6692 | * Returns true if the view is currently hovered. |
| 6693 | * |
| 6694 | * @return True if the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6695 | * |
| 6696 | * @see #setHovered |
| 6697 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6698 | */ |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6699 | @ViewDebug.ExportedProperty |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6700 | public boolean isHovered() { |
| 6701 | return (mPrivateFlags & HOVERED) != 0; |
| 6702 | } |
| 6703 | |
| 6704 | /** |
| 6705 | * Sets whether the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6706 | * <p> |
| 6707 | * Calling this method also changes the drawable state of the view. This |
| 6708 | * enables the view to react to hover by using different drawable resources |
| 6709 | * to change its appearance. |
| 6710 | * </p><p> |
| 6711 | * The {@link #onHoverChanged} method is called when the hovered state changes. |
| 6712 | * </p> |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6713 | * |
| 6714 | * @param hovered True if the view is hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6715 | * |
| 6716 | * @see #isHovered |
| 6717 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6718 | */ |
| 6719 | public void setHovered(boolean hovered) { |
| 6720 | if (hovered) { |
| 6721 | if ((mPrivateFlags & HOVERED) == 0) { |
| 6722 | mPrivateFlags |= HOVERED; |
| 6723 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6724 | onHoverChanged(true); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6725 | } |
| 6726 | } else { |
| 6727 | if ((mPrivateFlags & HOVERED) != 0) { |
| 6728 | mPrivateFlags &= ~HOVERED; |
| 6729 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6730 | onHoverChanged(false); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6731 | } |
| 6732 | } |
| 6733 | } |
| 6734 | |
| 6735 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6736 | * Implement this method to handle hover state changes. |
| 6737 | * <p> |
| 6738 | * This method is called whenever the hover state changes as a result of a |
| 6739 | * call to {@link #setHovered}. |
| 6740 | * </p> |
| 6741 | * |
| 6742 | * @param hovered The current hover state, as returned by {@link #isHovered}. |
| 6743 | * |
| 6744 | * @see #isHovered |
| 6745 | * @see #setHovered |
| 6746 | */ |
| 6747 | public void onHoverChanged(boolean hovered) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6748 | } |
| 6749 | |
| 6750 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6751 | * Implement this method to handle touch screen motion events. |
| 6752 | * |
| 6753 | * @param event The motion event. |
| 6754 | * @return True if the event was handled, false otherwise. |
| 6755 | */ |
| 6756 | public boolean onTouchEvent(MotionEvent event) { |
| 6757 | final int viewFlags = mViewFlags; |
| 6758 | |
| 6759 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
Svetoslav Ganov | 77b80c0 | 2011-03-15 20:52:58 -0700 | [diff] [blame] | 6760 | if (event.getAction() == MotionEvent.ACTION_UP && (mPrivateFlags & PRESSED) != 0) { |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 6761 | setPressed(false); |
Svetoslav Ganov | 77b80c0 | 2011-03-15 20:52:58 -0700 | [diff] [blame] | 6762 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6763 | // A disabled view that is clickable still consumes the touch |
| 6764 | // events, it just doesn't respond to them. |
| 6765 | return (((viewFlags & CLICKABLE) == CLICKABLE || |
| 6766 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)); |
| 6767 | } |
| 6768 | |
| 6769 | if (mTouchDelegate != null) { |
| 6770 | if (mTouchDelegate.onTouchEvent(event)) { |
| 6771 | return true; |
| 6772 | } |
| 6773 | } |
| 6774 | |
| 6775 | if (((viewFlags & CLICKABLE) == CLICKABLE || |
| 6776 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)) { |
| 6777 | switch (event.getAction()) { |
| 6778 | case MotionEvent.ACTION_UP: |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6779 | boolean prepressed = (mPrivateFlags & PREPRESSED) != 0; |
| 6780 | if ((mPrivateFlags & PRESSED) != 0 || prepressed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6781 | // take focus if we don't have it already and we should in |
| 6782 | // touch mode. |
| 6783 | boolean focusTaken = false; |
| 6784 | if (isFocusable() && isFocusableInTouchMode() && !isFocused()) { |
| 6785 | focusTaken = requestFocus(); |
| 6786 | } |
| 6787 | |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 6788 | if (prepressed) { |
| 6789 | // The button is being released before we actually |
| 6790 | // showed it as pressed. Make it show the pressed |
| 6791 | // state now (before scheduling the click) to ensure |
| 6792 | // the user sees it. |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 6793 | setPressed(true); |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 6794 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6795 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6796 | if (!mHasPerformedLongPress) { |
| 6797 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6798 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6799 | |
| 6800 | // Only perform take click actions if we were in the pressed state |
| 6801 | if (!focusTaken) { |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 6802 | // Use a Runnable and post this rather than calling |
| 6803 | // performClick directly. This lets other visual state |
| 6804 | // of the view update before click actions start. |
| 6805 | if (mPerformClick == null) { |
| 6806 | mPerformClick = new PerformClick(); |
| 6807 | } |
| 6808 | if (!post(mPerformClick)) { |
| 6809 | performClick(); |
| 6810 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6811 | } |
| 6812 | } |
| 6813 | |
| 6814 | if (mUnsetPressedState == null) { |
| 6815 | mUnsetPressedState = new UnsetPressedState(); |
| 6816 | } |
| 6817 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6818 | if (prepressed) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6819 | postDelayed(mUnsetPressedState, |
| 6820 | ViewConfiguration.getPressedStateDuration()); |
| 6821 | } else if (!post(mUnsetPressedState)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6822 | // If the post failed, unpress right now |
| 6823 | mUnsetPressedState.run(); |
| 6824 | } |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6825 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6826 | } |
| 6827 | break; |
| 6828 | |
| 6829 | case MotionEvent.ACTION_DOWN: |
Adam Powell | 3b02339 | 2010-03-11 16:30:28 -0800 | [diff] [blame] | 6830 | mHasPerformedLongPress = false; |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6831 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 6832 | if (performButtonActionOnTouchDown(event)) { |
| 6833 | break; |
| 6834 | } |
| 6835 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6836 | // Walk up the hierarchy to determine if we're inside a scrolling container. |
Adam Powell | 1029866 | 2011-08-14 18:26:30 -0700 | [diff] [blame] | 6837 | boolean isInScrollingContainer = isInScrollingContainer(); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6838 | |
| 6839 | // For views inside a scrolling container, delay the pressed feedback for |
| 6840 | // a short period in case this is a scroll. |
| 6841 | if (isInScrollingContainer) { |
| 6842 | mPrivateFlags |= PREPRESSED; |
| 6843 | if (mPendingCheckForTap == null) { |
| 6844 | mPendingCheckForTap = new CheckForTap(); |
| 6845 | } |
| 6846 | postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); |
| 6847 | } else { |
| 6848 | // Not inside a scrolling container, so show the feedback right away |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 6849 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6850 | checkForLongClick(0); |
| 6851 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6852 | break; |
| 6853 | |
| 6854 | case MotionEvent.ACTION_CANCEL: |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 6855 | setPressed(false); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6856 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6857 | break; |
| 6858 | |
| 6859 | case MotionEvent.ACTION_MOVE: |
| 6860 | final int x = (int) event.getX(); |
| 6861 | final int y = (int) event.getY(); |
| 6862 | |
| 6863 | // Be lenient about moving outside of buttons |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6864 | if (!pointInView(x, y, mTouchSlop)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6865 | // Outside button |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6866 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6867 | if ((mPrivateFlags & PRESSED) != 0) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6868 | // Remove any future long press/tap checks |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6869 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6870 | |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 6871 | setPressed(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6872 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6873 | } |
| 6874 | break; |
| 6875 | } |
| 6876 | return true; |
| 6877 | } |
| 6878 | |
| 6879 | return false; |
| 6880 | } |
| 6881 | |
| 6882 | /** |
Adam Powell | 1029866 | 2011-08-14 18:26:30 -0700 | [diff] [blame] | 6883 | * @hide |
| 6884 | */ |
| 6885 | public boolean isInScrollingContainer() { |
| 6886 | ViewParent p = getParent(); |
| 6887 | while (p != null && p instanceof ViewGroup) { |
| 6888 | if (((ViewGroup) p).shouldDelayChildPressedState()) { |
| 6889 | return true; |
| 6890 | } |
| 6891 | p = p.getParent(); |
| 6892 | } |
| 6893 | return false; |
| 6894 | } |
| 6895 | |
| 6896 | /** |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6897 | * Remove the longpress detection timer. |
| 6898 | */ |
| 6899 | private void removeLongPressCallback() { |
| 6900 | if (mPendingCheckForLongPress != null) { |
| 6901 | removeCallbacks(mPendingCheckForLongPress); |
| 6902 | } |
| 6903 | } |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 6904 | |
| 6905 | /** |
| 6906 | * Remove the pending click action |
| 6907 | */ |
| 6908 | private void removePerformClickCallback() { |
| 6909 | if (mPerformClick != null) { |
| 6910 | removeCallbacks(mPerformClick); |
| 6911 | } |
| 6912 | } |
| 6913 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6914 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6915 | * Remove the prepress detection timer. |
| 6916 | */ |
| 6917 | private void removeUnsetPressCallback() { |
| 6918 | if ((mPrivateFlags & PRESSED) != 0 && mUnsetPressedState != null) { |
| 6919 | setPressed(false); |
| 6920 | removeCallbacks(mUnsetPressedState); |
| 6921 | } |
| 6922 | } |
| 6923 | |
| 6924 | /** |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6925 | * Remove the tap detection timer. |
| 6926 | */ |
| 6927 | private void removeTapCallback() { |
| 6928 | if (mPendingCheckForTap != null) { |
| 6929 | mPrivateFlags &= ~PREPRESSED; |
| 6930 | removeCallbacks(mPendingCheckForTap); |
| 6931 | } |
| 6932 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6933 | |
| 6934 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6935 | * Cancels a pending long press. Your subclass can use this if you |
| 6936 | * want the context menu to come up if the user presses and holds |
| 6937 | * at the same place, but you don't want it to come up if they press |
| 6938 | * and then move around enough to cause scrolling. |
| 6939 | */ |
| 6940 | public void cancelLongPress() { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6941 | removeLongPressCallback(); |
Adam Powell | 732ebb1 | 2010-02-02 15:28:14 -0800 | [diff] [blame] | 6942 | |
| 6943 | /* |
| 6944 | * The prepressed state handled by the tap callback is a display |
| 6945 | * construct, but the tap callback will post a long press callback |
| 6946 | * less its own timeout. Remove it here. |
| 6947 | */ |
| 6948 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6949 | } |
| 6950 | |
| 6951 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6952 | * Remove the pending callback for sending a |
| 6953 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 6954 | */ |
| 6955 | private void removeSendViewScrolledAccessibilityEventCallback() { |
| 6956 | if (mSendViewScrolledAccessibilityEvent != null) { |
| 6957 | removeCallbacks(mSendViewScrolledAccessibilityEvent); |
| 6958 | } |
| 6959 | } |
| 6960 | |
| 6961 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6962 | * Sets the TouchDelegate for this View. |
| 6963 | */ |
| 6964 | public void setTouchDelegate(TouchDelegate delegate) { |
| 6965 | mTouchDelegate = delegate; |
| 6966 | } |
| 6967 | |
| 6968 | /** |
| 6969 | * Gets the TouchDelegate for this View. |
| 6970 | */ |
| 6971 | public TouchDelegate getTouchDelegate() { |
| 6972 | return mTouchDelegate; |
| 6973 | } |
| 6974 | |
| 6975 | /** |
| 6976 | * Set flags controlling behavior of this view. |
| 6977 | * |
| 6978 | * @param flags Constant indicating the value which should be set |
| 6979 | * @param mask Constant indicating the bit range that should be changed |
| 6980 | */ |
| 6981 | void setFlags(int flags, int mask) { |
| 6982 | int old = mViewFlags; |
| 6983 | mViewFlags = (mViewFlags & ~mask) | (flags & mask); |
| 6984 | |
| 6985 | int changed = mViewFlags ^ old; |
| 6986 | if (changed == 0) { |
| 6987 | return; |
| 6988 | } |
| 6989 | int privateFlags = mPrivateFlags; |
| 6990 | |
| 6991 | /* Check if the FOCUSABLE bit has changed */ |
| 6992 | if (((changed & FOCUSABLE_MASK) != 0) && |
| 6993 | ((privateFlags & HAS_BOUNDS) !=0)) { |
| 6994 | if (((old & FOCUSABLE_MASK) == FOCUSABLE) |
| 6995 | && ((privateFlags & FOCUSED) != 0)) { |
| 6996 | /* Give up focus if we are no longer focusable */ |
| 6997 | clearFocus(); |
| 6998 | } else if (((old & FOCUSABLE_MASK) == NOT_FOCUSABLE) |
| 6999 | && ((privateFlags & FOCUSED) == 0)) { |
| 7000 | /* |
| 7001 | * Tell the view system that we are now available to take focus |
| 7002 | * if no one else already has it. |
| 7003 | */ |
| 7004 | if (mParent != null) mParent.focusableViewAvailable(this); |
| 7005 | } |
| 7006 | } |
| 7007 | |
| 7008 | if ((flags & VISIBILITY_MASK) == VISIBLE) { |
| 7009 | if ((changed & VISIBILITY_MASK) != 0) { |
| 7010 | /* |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 7011 | * If this view is becoming visible, invalidate it in case it changed while |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 7012 | * it was not visible. Marking it drawn ensures that the invalidation will |
| 7013 | * go through. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7014 | */ |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 7015 | mPrivateFlags |= DRAWN; |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 7016 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7017 | |
| 7018 | needGlobalAttributesUpdate(true); |
| 7019 | |
| 7020 | // a view becoming visible is worth notifying the parent |
| 7021 | // about in case nothing has focus. even if this specific view |
| 7022 | // isn't focusable, it may contain something that is, so let |
| 7023 | // the root view try to give this focus if nothing else does. |
| 7024 | if ((mParent != null) && (mBottom > mTop) && (mRight > mLeft)) { |
| 7025 | mParent.focusableViewAvailable(this); |
| 7026 | } |
| 7027 | } |
| 7028 | } |
| 7029 | |
| 7030 | /* Check if the GONE bit has changed */ |
| 7031 | if ((changed & GONE) != 0) { |
| 7032 | needGlobalAttributesUpdate(false); |
| 7033 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7034 | |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 7035 | if (((mViewFlags & VISIBILITY_MASK) == GONE)) { |
| 7036 | if (hasFocus()) clearFocus(); |
| 7037 | destroyDrawingCache(); |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 7038 | if (mParent instanceof View) { |
| 7039 | // GONE views noop invalidation, so invalidate the parent |
| 7040 | ((View) mParent).invalidate(true); |
| 7041 | } |
| 7042 | // Mark the view drawn to ensure that it gets invalidated properly the next |
| 7043 | // time it is visible and gets invalidated |
| 7044 | mPrivateFlags |= DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7045 | } |
| 7046 | if (mAttachInfo != null) { |
| 7047 | mAttachInfo.mViewVisibilityChanged = true; |
| 7048 | } |
| 7049 | } |
| 7050 | |
| 7051 | /* Check if the VISIBLE bit has changed */ |
| 7052 | if ((changed & INVISIBLE) != 0) { |
| 7053 | needGlobalAttributesUpdate(false); |
Chet Haase | c8a9a70 | 2011-06-17 12:13:42 -0700 | [diff] [blame] | 7054 | /* |
| 7055 | * If this view is becoming invisible, set the DRAWN flag so that |
| 7056 | * the next invalidate() will not be skipped. |
| 7057 | */ |
| 7058 | mPrivateFlags |= DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7059 | |
| 7060 | if (((mViewFlags & VISIBILITY_MASK) == INVISIBLE) && hasFocus()) { |
| 7061 | // root view becoming invisible shouldn't clear focus |
| 7062 | if (getRootView() != this) { |
| 7063 | clearFocus(); |
| 7064 | } |
| 7065 | } |
| 7066 | if (mAttachInfo != null) { |
| 7067 | mAttachInfo.mViewVisibilityChanged = true; |
| 7068 | } |
| 7069 | } |
| 7070 | |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7071 | if ((changed & VISIBILITY_MASK) != 0) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 7072 | if (mParent instanceof ViewGroup) { |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 7073 | ((ViewGroup) mParent).onChildVisibilityChanged(this, |
| 7074 | (changed & VISIBILITY_MASK), (flags & VISIBILITY_MASK)); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7075 | ((View) mParent).invalidate(true); |
Chet Haase | e4e6e20 | 2011-08-29 14:34:30 -0700 | [diff] [blame] | 7076 | } else if (mParent != null) { |
| 7077 | mParent.invalidateChild(this, null); |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 7078 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7079 | dispatchVisibilityChanged(this, (flags & VISIBILITY_MASK)); |
| 7080 | } |
| 7081 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7082 | if ((changed & WILL_NOT_CACHE_DRAWING) != 0) { |
| 7083 | destroyDrawingCache(); |
| 7084 | } |
| 7085 | |
| 7086 | if ((changed & DRAWING_CACHE_ENABLED) != 0) { |
| 7087 | destroyDrawingCache(); |
| 7088 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7089 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7090 | } |
| 7091 | |
| 7092 | if ((changed & DRAWING_CACHE_QUALITY_MASK) != 0) { |
| 7093 | destroyDrawingCache(); |
| 7094 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 7095 | } |
| 7096 | |
| 7097 | if ((changed & DRAW_MASK) != 0) { |
| 7098 | if ((mViewFlags & WILL_NOT_DRAW) != 0) { |
| 7099 | if (mBGDrawable != null) { |
| 7100 | mPrivateFlags &= ~SKIP_DRAW; |
| 7101 | mPrivateFlags |= ONLY_DRAWS_BACKGROUND; |
| 7102 | } else { |
| 7103 | mPrivateFlags |= SKIP_DRAW; |
| 7104 | } |
| 7105 | } else { |
| 7106 | mPrivateFlags &= ~SKIP_DRAW; |
| 7107 | } |
| 7108 | requestLayout(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7109 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7110 | } |
| 7111 | |
| 7112 | if ((changed & KEEP_SCREEN_ON) != 0) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7113 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7114 | mParent.recomputeViewAttributes(this); |
| 7115 | } |
| 7116 | } |
| 7117 | } |
| 7118 | |
| 7119 | /** |
| 7120 | * Change the view's z order in the tree, so it's on top of other sibling |
| 7121 | * views |
| 7122 | */ |
| 7123 | public void bringToFront() { |
| 7124 | if (mParent != null) { |
| 7125 | mParent.bringChildToFront(this); |
| 7126 | } |
| 7127 | } |
| 7128 | |
| 7129 | /** |
| 7130 | * This is called in response to an internal scroll in this view (i.e., the |
| 7131 | * view scrolled its own contents). This is typically as a result of |
| 7132 | * {@link #scrollBy(int, int)} or {@link #scrollTo(int, int)} having been |
| 7133 | * called. |
| 7134 | * |
| 7135 | * @param l Current horizontal scroll origin. |
| 7136 | * @param t Current vertical scroll origin. |
| 7137 | * @param oldl Previous horizontal scroll origin. |
| 7138 | * @param oldt Previous vertical scroll origin. |
| 7139 | */ |
| 7140 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7141 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 7142 | postSendViewScrolledAccessibilityEventCallback(); |
| 7143 | } |
| 7144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7145 | mBackgroundSizeChanged = true; |
| 7146 | |
| 7147 | final AttachInfo ai = mAttachInfo; |
| 7148 | if (ai != null) { |
| 7149 | ai.mViewScrollChanged = true; |
| 7150 | } |
| 7151 | } |
| 7152 | |
| 7153 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7154 | * Interface definition for a callback to be invoked when the layout bounds of a view |
| 7155 | * changes due to layout processing. |
| 7156 | */ |
| 7157 | public interface OnLayoutChangeListener { |
| 7158 | /** |
| 7159 | * Called when the focus state of a view has changed. |
| 7160 | * |
| 7161 | * @param v The view whose state has changed. |
| 7162 | * @param left The new value of the view's left property. |
| 7163 | * @param top The new value of the view's top property. |
| 7164 | * @param right The new value of the view's right property. |
| 7165 | * @param bottom The new value of the view's bottom property. |
| 7166 | * @param oldLeft The previous value of the view's left property. |
| 7167 | * @param oldTop The previous value of the view's top property. |
| 7168 | * @param oldRight The previous value of the view's right property. |
| 7169 | * @param oldBottom The previous value of the view's bottom property. |
| 7170 | */ |
| 7171 | void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 7172 | int oldLeft, int oldTop, int oldRight, int oldBottom); |
| 7173 | } |
| 7174 | |
| 7175 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7176 | * This is called during layout when the size of this view has changed. If |
| 7177 | * you were just added to the view hierarchy, you're called with the old |
| 7178 | * values of 0. |
| 7179 | * |
| 7180 | * @param w Current width of this view. |
| 7181 | * @param h Current height of this view. |
| 7182 | * @param oldw Old width of this view. |
| 7183 | * @param oldh Old height of this view. |
| 7184 | */ |
| 7185 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 7186 | } |
| 7187 | |
| 7188 | /** |
| 7189 | * Called by draw to draw the child views. This may be overridden |
| 7190 | * by derived classes to gain control just before its children are drawn |
| 7191 | * (but after its own view has been drawn). |
| 7192 | * @param canvas the canvas on which to draw the view |
| 7193 | */ |
| 7194 | protected void dispatchDraw(Canvas canvas) { |
| 7195 | } |
| 7196 | |
| 7197 | /** |
| 7198 | * Gets the parent of this view. Note that the parent is a |
| 7199 | * ViewParent and not necessarily a View. |
| 7200 | * |
| 7201 | * @return Parent of this view. |
| 7202 | */ |
| 7203 | public final ViewParent getParent() { |
| 7204 | return mParent; |
| 7205 | } |
| 7206 | |
| 7207 | /** |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 7208 | * Set the horizontal scrolled position of your view. This will cause a call to |
| 7209 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 7210 | * invalidated. |
| 7211 | * @param value the x position to scroll to |
| 7212 | */ |
| 7213 | public void setScrollX(int value) { |
| 7214 | scrollTo(value, mScrollY); |
| 7215 | } |
| 7216 | |
| 7217 | /** |
| 7218 | * Set the vertical scrolled position of your view. This will cause a call to |
| 7219 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 7220 | * invalidated. |
| 7221 | * @param value the y position to scroll to |
| 7222 | */ |
| 7223 | public void setScrollY(int value) { |
| 7224 | scrollTo(mScrollX, value); |
| 7225 | } |
| 7226 | |
| 7227 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7228 | * Return the scrolled left position of this view. This is the left edge of |
| 7229 | * the displayed part of your view. You do not need to draw any pixels |
| 7230 | * farther left, since those are outside of the frame of your view on |
| 7231 | * screen. |
| 7232 | * |
| 7233 | * @return The left edge of the displayed part of your view, in pixels. |
| 7234 | */ |
| 7235 | public final int getScrollX() { |
| 7236 | return mScrollX; |
| 7237 | } |
| 7238 | |
| 7239 | /** |
| 7240 | * Return the scrolled top position of this view. This is the top edge of |
| 7241 | * the displayed part of your view. You do not need to draw any pixels above |
| 7242 | * it, since those are outside of the frame of your view on screen. |
| 7243 | * |
| 7244 | * @return The top edge of the displayed part of your view, in pixels. |
| 7245 | */ |
| 7246 | public final int getScrollY() { |
| 7247 | return mScrollY; |
| 7248 | } |
| 7249 | |
| 7250 | /** |
| 7251 | * Return the width of the your view. |
| 7252 | * |
| 7253 | * @return The width of your view, in pixels. |
| 7254 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 7255 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7256 | public final int getWidth() { |
| 7257 | return mRight - mLeft; |
| 7258 | } |
| 7259 | |
| 7260 | /** |
| 7261 | * Return the height of your view. |
| 7262 | * |
| 7263 | * @return The height of your view, in pixels. |
| 7264 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 7265 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7266 | public final int getHeight() { |
| 7267 | return mBottom - mTop; |
| 7268 | } |
| 7269 | |
| 7270 | /** |
| 7271 | * Return the visible drawing bounds of your view. Fills in the output |
| 7272 | * rectangle with the values from getScrollX(), getScrollY(), |
| 7273 | * getWidth(), and getHeight(). |
| 7274 | * |
| 7275 | * @param outRect The (scrolled) drawing bounds of the view. |
| 7276 | */ |
| 7277 | public void getDrawingRect(Rect outRect) { |
| 7278 | outRect.left = mScrollX; |
| 7279 | outRect.top = mScrollY; |
| 7280 | outRect.right = mScrollX + (mRight - mLeft); |
| 7281 | outRect.bottom = mScrollY + (mBottom - mTop); |
| 7282 | } |
| 7283 | |
| 7284 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7285 | * Like {@link #getMeasuredWidthAndState()}, but only returns the |
| 7286 | * raw width component (that is the result is masked by |
| 7287 | * {@link #MEASURED_SIZE_MASK}). |
| 7288 | * |
| 7289 | * @return The raw measured width of this view. |
| 7290 | */ |
| 7291 | public final int getMeasuredWidth() { |
| 7292 | return mMeasuredWidth & MEASURED_SIZE_MASK; |
| 7293 | } |
| 7294 | |
| 7295 | /** |
| 7296 | * Return the full width measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7297 | * by the most recent call to {@link #measure(int, int)}. This result is a bit mask |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7298 | * as defined by {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7299 | * This should be used during measurement and layout calculations only. Use |
| 7300 | * {@link #getWidth()} to see how wide a view is after layout. |
| 7301 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7302 | * @return The measured width of this view as a bit mask. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7303 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7304 | public final int getMeasuredWidthAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7305 | return mMeasuredWidth; |
| 7306 | } |
| 7307 | |
| 7308 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7309 | * Like {@link #getMeasuredHeightAndState()}, but only returns the |
| 7310 | * raw width component (that is the result is masked by |
| 7311 | * {@link #MEASURED_SIZE_MASK}). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7312 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7313 | * @return The raw measured height of this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7314 | */ |
| 7315 | public final int getMeasuredHeight() { |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7316 | return mMeasuredHeight & MEASURED_SIZE_MASK; |
| 7317 | } |
| 7318 | |
| 7319 | /** |
| 7320 | * Return the full height measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7321 | * by the most recent call to {@link #measure(int, int)}. This result is a bit mask |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7322 | * as defined by {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. |
| 7323 | * This should be used during measurement and layout calculations only. Use |
| 7324 | * {@link #getHeight()} to see how wide a view is after layout. |
| 7325 | * |
| 7326 | * @return The measured width of this view as a bit mask. |
| 7327 | */ |
| 7328 | public final int getMeasuredHeightAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7329 | return mMeasuredHeight; |
| 7330 | } |
| 7331 | |
| 7332 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7333 | * Return only the state bits of {@link #getMeasuredWidthAndState()} |
| 7334 | * and {@link #getMeasuredHeightAndState()}, combined into one integer. |
| 7335 | * The width component is in the regular bits {@link #MEASURED_STATE_MASK} |
| 7336 | * and the height component is at the shifted bits |
| 7337 | * {@link #MEASURED_HEIGHT_STATE_SHIFT}>>{@link #MEASURED_STATE_MASK}. |
| 7338 | */ |
| 7339 | public final int getMeasuredState() { |
| 7340 | return (mMeasuredWidth&MEASURED_STATE_MASK) |
| 7341 | | ((mMeasuredHeight>>MEASURED_HEIGHT_STATE_SHIFT) |
| 7342 | & (MEASURED_STATE_MASK>>MEASURED_HEIGHT_STATE_SHIFT)); |
| 7343 | } |
| 7344 | |
| 7345 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7346 | * The transform matrix of this view, which is calculated based on the current |
| 7347 | * roation, scale, and pivot properties. |
| 7348 | * |
| 7349 | * @see #getRotation() |
| 7350 | * @see #getScaleX() |
| 7351 | * @see #getScaleY() |
| 7352 | * @see #getPivotX() |
| 7353 | * @see #getPivotY() |
| 7354 | * @return The current transform matrix for the view |
| 7355 | */ |
| 7356 | public Matrix getMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7357 | if (mTransformationInfo != null) { |
| 7358 | updateMatrix(); |
| 7359 | return mTransformationInfo.mMatrix; |
| 7360 | } |
| 7361 | return Matrix.IDENTITY_MATRIX; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7362 | } |
| 7363 | |
| 7364 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7365 | * Utility function to determine if the value is far enough away from zero to be |
| 7366 | * considered non-zero. |
| 7367 | * @param value A floating point value to check for zero-ness |
| 7368 | * @return whether the passed-in value is far enough away from zero to be considered non-zero |
| 7369 | */ |
| 7370 | private static boolean nonzero(float value) { |
| 7371 | return (value < -NONZERO_EPSILON || value > NONZERO_EPSILON); |
| 7372 | } |
| 7373 | |
| 7374 | /** |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7375 | * Returns true if the transform matrix is the identity matrix. |
| 7376 | * Recomputes the matrix if necessary. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7377 | * |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7378 | * @return True if the transform matrix is the identity matrix, false otherwise. |
| 7379 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7380 | final boolean hasIdentityMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7381 | if (mTransformationInfo != null) { |
| 7382 | updateMatrix(); |
| 7383 | return mTransformationInfo.mMatrixIsIdentity; |
| 7384 | } |
| 7385 | return true; |
| 7386 | } |
| 7387 | |
| 7388 | void ensureTransformationInfo() { |
| 7389 | if (mTransformationInfo == null) { |
| 7390 | mTransformationInfo = new TransformationInfo(); |
| 7391 | } |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7392 | } |
| 7393 | |
| 7394 | /** |
| 7395 | * Recomputes the transform matrix if necessary. |
| 7396 | */ |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 7397 | private void updateMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7398 | final TransformationInfo info = mTransformationInfo; |
| 7399 | if (info == null) { |
| 7400 | return; |
| 7401 | } |
| 7402 | if (info.mMatrixDirty) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7403 | // transform-related properties have changed since the last time someone |
| 7404 | // asked for the matrix; recalculate it with the current values |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7405 | |
| 7406 | // Figure out if we need to update the pivot point |
| 7407 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7408 | if ((mRight - mLeft) != info.mPrevWidth || (mBottom - mTop) != info.mPrevHeight) { |
| 7409 | info.mPrevWidth = mRight - mLeft; |
| 7410 | info.mPrevHeight = mBottom - mTop; |
| 7411 | info.mPivotX = info.mPrevWidth / 2f; |
| 7412 | info.mPivotY = info.mPrevHeight / 2f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7413 | } |
| 7414 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7415 | info.mMatrix.reset(); |
| 7416 | if (!nonzero(info.mRotationX) && !nonzero(info.mRotationY)) { |
| 7417 | info.mMatrix.setTranslate(info.mTranslationX, info.mTranslationY); |
| 7418 | info.mMatrix.preRotate(info.mRotation, info.mPivotX, info.mPivotY); |
| 7419 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7420 | } else { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7421 | if (info.mCamera == null) { |
| 7422 | info.mCamera = new Camera(); |
| 7423 | info.matrix3D = new Matrix(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7424 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7425 | info.mCamera.save(); |
| 7426 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
| 7427 | info.mCamera.rotate(info.mRotationX, info.mRotationY, -info.mRotation); |
| 7428 | info.mCamera.getMatrix(info.matrix3D); |
| 7429 | info.matrix3D.preTranslate(-info.mPivotX, -info.mPivotY); |
| 7430 | info.matrix3D.postTranslate(info.mPivotX + info.mTranslationX, |
| 7431 | info.mPivotY + info.mTranslationY); |
| 7432 | info.mMatrix.postConcat(info.matrix3D); |
| 7433 | info.mCamera.restore(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7434 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7435 | info.mMatrixDirty = false; |
| 7436 | info.mMatrixIsIdentity = info.mMatrix.isIdentity(); |
| 7437 | info.mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7438 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7439 | } |
| 7440 | |
| 7441 | /** |
| 7442 | * Utility method to retrieve the inverse of the current mMatrix property. |
| 7443 | * We cache the matrix to avoid recalculating it when transform properties |
| 7444 | * have not changed. |
| 7445 | * |
| 7446 | * @return The inverse of the current matrix of this view. |
| 7447 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7448 | final Matrix getInverseMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7449 | final TransformationInfo info = mTransformationInfo; |
| 7450 | if (info != null) { |
| 7451 | updateMatrix(); |
| 7452 | if (info.mInverseMatrixDirty) { |
| 7453 | if (info.mInverseMatrix == null) { |
| 7454 | info.mInverseMatrix = new Matrix(); |
| 7455 | } |
| 7456 | info.mMatrix.invert(info.mInverseMatrix); |
| 7457 | info.mInverseMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7458 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7459 | return info.mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7460 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7461 | return Matrix.IDENTITY_MATRIX; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7462 | } |
| 7463 | |
| 7464 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7465 | * Gets the distance along the Z axis from the camera to this view. |
| 7466 | * |
| 7467 | * @see #setCameraDistance(float) |
| 7468 | * |
| 7469 | * @return The distance along the Z axis. |
| 7470 | */ |
| 7471 | public float getCameraDistance() { |
| 7472 | ensureTransformationInfo(); |
| 7473 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
| 7474 | final TransformationInfo info = mTransformationInfo; |
| 7475 | if (info.mCamera == null) { |
| 7476 | info.mCamera = new Camera(); |
| 7477 | info.matrix3D = new Matrix(); |
| 7478 | } |
| 7479 | return -(info.mCamera.getLocationZ() * dpi); |
| 7480 | } |
| 7481 | |
| 7482 | /** |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7483 | * <p>Sets the distance along the Z axis (orthogonal to the X/Y plane on which |
| 7484 | * views are drawn) from the camera to this view. The camera's distance |
| 7485 | * affects 3D transformations, for instance rotations around the X and Y |
| 7486 | * axis. If the rotationX or rotationY properties are changed and this view is |
| 7487 | * large (more than half the size of the screen), it is recommended to always |
| 7488 | * use a camera distance that's greater than the height (X axis rotation) or |
| 7489 | * the width (Y axis rotation) of this view.</p> |
| 7490 | * |
| 7491 | * <p>The distance of the camera from the view plane can have an affect on the |
| 7492 | * perspective distortion of the view when it is rotated around the x or y axis. |
| 7493 | * For example, a large distance will result in a large viewing angle, and there |
| 7494 | * will not be much perspective distortion of the view as it rotates. A short |
| 7495 | * distance may cause much more perspective distortion upon rotation, and can |
| 7496 | * also result in some drawing artifacts if the rotated view ends up partially |
| 7497 | * behind the camera (which is why the recommendation is to use a distance at |
| 7498 | * least as far as the size of the view, if the view is to be rotated.)</p> |
| 7499 | * |
| 7500 | * <p>The distance is expressed in "depth pixels." The default distance depends |
| 7501 | * on the screen density. For instance, on a medium density display, the |
| 7502 | * default distance is 1280. On a high density display, the default distance |
| 7503 | * is 1920.</p> |
| 7504 | * |
| 7505 | * <p>If you want to specify a distance that leads to visually consistent |
| 7506 | * results across various densities, use the following formula:</p> |
| 7507 | * <pre> |
| 7508 | * float scale = context.getResources().getDisplayMetrics().density; |
| 7509 | * view.setCameraDistance(distance * scale); |
| 7510 | * </pre> |
| 7511 | * |
| 7512 | * <p>The density scale factor of a high density display is 1.5, |
| 7513 | * and 1920 = 1280 * 1.5.</p> |
| 7514 | * |
| 7515 | * @param distance The distance in "depth pixels", if negative the opposite |
| 7516 | * value is used |
| 7517 | * |
| 7518 | * @see #setRotationX(float) |
| 7519 | * @see #setRotationY(float) |
| 7520 | */ |
| 7521 | public void setCameraDistance(float distance) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7522 | invalidateViewProperty(true, false); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7523 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7524 | ensureTransformationInfo(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7525 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7526 | final TransformationInfo info = mTransformationInfo; |
| 7527 | if (info.mCamera == null) { |
| 7528 | info.mCamera = new Camera(); |
| 7529 | info.matrix3D = new Matrix(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7530 | } |
| 7531 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7532 | info.mCamera.setLocation(0.0f, 0.0f, -Math.abs(distance) / dpi); |
| 7533 | info.mMatrixDirty = true; |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7534 | |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7535 | invalidateViewProperty(false, false); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7536 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 7537 | mDisplayList.setCameraDistance(-Math.abs(distance) / dpi); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7538 | } |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7539 | } |
| 7540 | |
| 7541 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7542 | * The degrees that the view is rotated around the pivot point. |
| 7543 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7544 | * @see #setRotation(float) |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7545 | * @see #getPivotX() |
| 7546 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7547 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7548 | * @return The degrees of rotation. |
| 7549 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7550 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7551 | public float getRotation() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7552 | return mTransformationInfo != null ? mTransformationInfo.mRotation : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7553 | } |
| 7554 | |
| 7555 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7556 | * Sets the degrees that the view is rotated around the pivot point. Increasing values |
| 7557 | * result in clockwise rotation. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7558 | * |
| 7559 | * @param rotation The degrees of rotation. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7560 | * |
| 7561 | * @see #getRotation() |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7562 | * @see #getPivotX() |
| 7563 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7564 | * @see #setRotationX(float) |
| 7565 | * @see #setRotationY(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7566 | * |
| 7567 | * @attr ref android.R.styleable#View_rotation |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7568 | */ |
| 7569 | public void setRotation(float rotation) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7570 | ensureTransformationInfo(); |
| 7571 | final TransformationInfo info = mTransformationInfo; |
| 7572 | if (info.mRotation != rotation) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7573 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7574 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7575 | info.mRotation = rotation; |
| 7576 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7577 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7578 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7579 | mDisplayList.setRotation(rotation); |
| 7580 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7581 | } |
| 7582 | } |
| 7583 | |
| 7584 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7585 | * The degrees that the view is rotated around the vertical axis through the pivot point. |
| 7586 | * |
| 7587 | * @see #getPivotX() |
| 7588 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7589 | * @see #setRotationY(float) |
| 7590 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7591 | * @return The degrees of Y rotation. |
| 7592 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7593 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7594 | public float getRotationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7595 | return mTransformationInfo != null ? mTransformationInfo.mRotationY : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7596 | } |
| 7597 | |
| 7598 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7599 | * Sets the degrees that the view is rotated around the vertical axis through the pivot point. |
| 7600 | * Increasing values result in counter-clockwise rotation from the viewpoint of looking |
| 7601 | * down the y axis. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7602 | * |
| 7603 | * When rotating large views, it is recommended to adjust the camera distance |
| 7604 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7605 | * |
| 7606 | * @param rotationY The degrees of Y rotation. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7607 | * |
| 7608 | * @see #getRotationY() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7609 | * @see #getPivotX() |
| 7610 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7611 | * @see #setRotation(float) |
| 7612 | * @see #setRotationX(float) |
| 7613 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7614 | * |
| 7615 | * @attr ref android.R.styleable#View_rotationY |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7616 | */ |
| 7617 | public void setRotationY(float rotationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7618 | ensureTransformationInfo(); |
| 7619 | final TransformationInfo info = mTransformationInfo; |
| 7620 | if (info.mRotationY != rotationY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7621 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7622 | info.mRotationY = rotationY; |
| 7623 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7624 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7625 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7626 | mDisplayList.setRotationY(rotationY); |
| 7627 | } |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7628 | } |
| 7629 | } |
| 7630 | |
| 7631 | /** |
| 7632 | * The degrees that the view is rotated around the horizontal axis through the pivot point. |
| 7633 | * |
| 7634 | * @see #getPivotX() |
| 7635 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7636 | * @see #setRotationX(float) |
| 7637 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7638 | * @return The degrees of X rotation. |
| 7639 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7640 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7641 | public float getRotationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7642 | return mTransformationInfo != null ? mTransformationInfo.mRotationX : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7643 | } |
| 7644 | |
| 7645 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7646 | * Sets the degrees that the view is rotated around the horizontal axis through the pivot point. |
| 7647 | * Increasing values result in clockwise rotation from the viewpoint of looking down the |
| 7648 | * x axis. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7649 | * |
| 7650 | * When rotating large views, it is recommended to adjust the camera distance |
| 7651 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7652 | * |
| 7653 | * @param rotationX The degrees of X rotation. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7654 | * |
| 7655 | * @see #getRotationX() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7656 | * @see #getPivotX() |
| 7657 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7658 | * @see #setRotation(float) |
| 7659 | * @see #setRotationY(float) |
| 7660 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7661 | * |
| 7662 | * @attr ref android.R.styleable#View_rotationX |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7663 | */ |
| 7664 | public void setRotationX(float rotationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7665 | ensureTransformationInfo(); |
| 7666 | final TransformationInfo info = mTransformationInfo; |
| 7667 | if (info.mRotationX != rotationX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7668 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7669 | info.mRotationX = rotationX; |
| 7670 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7671 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7672 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7673 | mDisplayList.setRotationX(rotationX); |
| 7674 | } |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7675 | } |
| 7676 | } |
| 7677 | |
| 7678 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7679 | * The amount that the view is scaled in x around the pivot point, as a proportion of |
| 7680 | * the view's unscaled width. A value of 1, the default, means that no scaling is applied. |
| 7681 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 7682 | * <p>By default, this is 1.0f. |
| 7683 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7684 | * @see #getPivotX() |
| 7685 | * @see #getPivotY() |
| 7686 | * @return The scaling factor. |
| 7687 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7688 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7689 | public float getScaleX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7690 | return mTransformationInfo != null ? mTransformationInfo.mScaleX : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7691 | } |
| 7692 | |
| 7693 | /** |
| 7694 | * Sets the amount that the view is scaled in x around the pivot point, as a proportion of |
| 7695 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 7696 | * |
| 7697 | * @param scaleX The scaling factor. |
| 7698 | * @see #getPivotX() |
| 7699 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7700 | * |
| 7701 | * @attr ref android.R.styleable#View_scaleX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7702 | */ |
| 7703 | public void setScaleX(float scaleX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7704 | ensureTransformationInfo(); |
| 7705 | final TransformationInfo info = mTransformationInfo; |
| 7706 | if (info.mScaleX != scaleX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7707 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7708 | info.mScaleX = scaleX; |
| 7709 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7710 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7711 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7712 | mDisplayList.setScaleX(scaleX); |
| 7713 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7714 | } |
| 7715 | } |
| 7716 | |
| 7717 | /** |
| 7718 | * The amount that the view is scaled in y around the pivot point, as a proportion of |
| 7719 | * the view's unscaled height. A value of 1, the default, means that no scaling is applied. |
| 7720 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 7721 | * <p>By default, this is 1.0f. |
| 7722 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7723 | * @see #getPivotX() |
| 7724 | * @see #getPivotY() |
| 7725 | * @return The scaling factor. |
| 7726 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7727 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7728 | public float getScaleY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7729 | return mTransformationInfo != null ? mTransformationInfo.mScaleY : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7730 | } |
| 7731 | |
| 7732 | /** |
| 7733 | * Sets the amount that the view is scaled in Y around the pivot point, as a proportion of |
| 7734 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 7735 | * |
| 7736 | * @param scaleY The scaling factor. |
| 7737 | * @see #getPivotX() |
| 7738 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7739 | * |
| 7740 | * @attr ref android.R.styleable#View_scaleY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7741 | */ |
| 7742 | public void setScaleY(float scaleY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7743 | ensureTransformationInfo(); |
| 7744 | final TransformationInfo info = mTransformationInfo; |
| 7745 | if (info.mScaleY != scaleY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7746 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7747 | info.mScaleY = scaleY; |
| 7748 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7749 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7750 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7751 | mDisplayList.setScaleY(scaleY); |
| 7752 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7753 | } |
| 7754 | } |
| 7755 | |
| 7756 | /** |
| 7757 | * The x location of the point around which the view is {@link #setRotation(float) rotated} |
| 7758 | * and {@link #setScaleX(float) scaled}. |
| 7759 | * |
| 7760 | * @see #getRotation() |
| 7761 | * @see #getScaleX() |
| 7762 | * @see #getScaleY() |
| 7763 | * @see #getPivotY() |
| 7764 | * @return The x location of the pivot point. |
| 7765 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7766 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7767 | public float getPivotX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7768 | return mTransformationInfo != null ? mTransformationInfo.mPivotX : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7769 | } |
| 7770 | |
| 7771 | /** |
| 7772 | * Sets the x location of the point around which the view is |
| 7773 | * {@link #setRotation(float) rotated} and {@link #setScaleX(float) scaled}. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7774 | * By default, the pivot point is centered on the object. |
| 7775 | * Setting this property disables this behavior and causes the view to use only the |
| 7776 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7777 | * |
| 7778 | * @param pivotX The x location of the pivot point. |
| 7779 | * @see #getRotation() |
| 7780 | * @see #getScaleX() |
| 7781 | * @see #getScaleY() |
| 7782 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7783 | * |
| 7784 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7785 | */ |
| 7786 | public void setPivotX(float pivotX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7787 | ensureTransformationInfo(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7788 | mPrivateFlags |= PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7789 | final TransformationInfo info = mTransformationInfo; |
| 7790 | if (info.mPivotX != pivotX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7791 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7792 | info.mPivotX = pivotX; |
| 7793 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7794 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7795 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7796 | mDisplayList.setPivotX(pivotX); |
| 7797 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7798 | } |
| 7799 | } |
| 7800 | |
| 7801 | /** |
| 7802 | * The y location of the point around which the view is {@link #setRotation(float) rotated} |
| 7803 | * and {@link #setScaleY(float) scaled}. |
| 7804 | * |
| 7805 | * @see #getRotation() |
| 7806 | * @see #getScaleX() |
| 7807 | * @see #getScaleY() |
| 7808 | * @see #getPivotY() |
| 7809 | * @return The y location of the pivot point. |
| 7810 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7811 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7812 | public float getPivotY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7813 | return mTransformationInfo != null ? mTransformationInfo.mPivotY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7814 | } |
| 7815 | |
| 7816 | /** |
| 7817 | * Sets the y location of the point around which the view is {@link #setRotation(float) rotated} |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7818 | * and {@link #setScaleY(float) scaled}. By default, the pivot point is centered on the object. |
| 7819 | * Setting this property disables this behavior and causes the view to use only the |
| 7820 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7821 | * |
| 7822 | * @param pivotY The y location of the pivot point. |
| 7823 | * @see #getRotation() |
| 7824 | * @see #getScaleX() |
| 7825 | * @see #getScaleY() |
| 7826 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7827 | * |
| 7828 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7829 | */ |
| 7830 | public void setPivotY(float pivotY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7831 | ensureTransformationInfo(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7832 | mPrivateFlags |= PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7833 | final TransformationInfo info = mTransformationInfo; |
| 7834 | if (info.mPivotY != pivotY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7835 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7836 | info.mPivotY = pivotY; |
| 7837 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7838 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7839 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7840 | mDisplayList.setPivotY(pivotY); |
| 7841 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7842 | } |
| 7843 | } |
| 7844 | |
| 7845 | /** |
| 7846 | * The opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 7847 | * completely transparent and 1 means the view is completely opaque. |
| 7848 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 7849 | * <p>By default this is 1.0f. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7850 | * @return The opacity of the view. |
| 7851 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7852 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7853 | public float getAlpha() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7854 | return mTransformationInfo != null ? mTransformationInfo.mAlpha : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7855 | } |
| 7856 | |
| 7857 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 7858 | * <p>Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 7859 | * completely transparent and 1 means the view is completely opaque.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7860 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 7861 | * <p>If this view overrides {@link #onSetAlpha(int)} to return true, then this view is |
| 7862 | * responsible for applying the opacity itself. Otherwise, calling this method is |
| 7863 | * equivalent to calling {@link #setLayerType(int, android.graphics.Paint)} and |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7864 | * setting a hardware layer.</p> |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7865 | * |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7866 | * <p>Note that setting alpha to a translucent value (0 < alpha < 1) may have |
| 7867 | * performance implications. It is generally best to use the alpha property sparingly and |
| 7868 | * transiently, as in the case of fading animations.</p> |
| 7869 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7870 | * @param alpha The opacity of the view. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7871 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7872 | * @see #setLayerType(int, android.graphics.Paint) |
| 7873 | * |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7874 | * @attr ref android.R.styleable#View_alpha |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7875 | */ |
| 7876 | public void setAlpha(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7877 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 7878 | if (mTransformationInfo.mAlpha != alpha) { |
| 7879 | mTransformationInfo.mAlpha = alpha; |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 7880 | if (onSetAlpha((int) (alpha * 255))) { |
| 7881 | mPrivateFlags |= ALPHA_SET; |
| 7882 | // subclass is handling alpha - don't optimize rendering cache invalidation |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7883 | invalidateParentCaches(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 7884 | invalidate(true); |
| 7885 | } else { |
| 7886 | mPrivateFlags &= ~ALPHA_SET; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7887 | invalidateViewProperty(true, false); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7888 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7889 | mDisplayList.setAlpha(alpha); |
| 7890 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 7891 | } |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7892 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7893 | } |
| 7894 | |
| 7895 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 7896 | * Faster version of setAlpha() which performs the same steps except there are |
| 7897 | * no calls to invalidate(). The caller of this function should perform proper invalidation |
| 7898 | * on the parent and this object. The return value indicates whether the subclass handles |
| 7899 | * alpha (the return value for onSetAlpha()). |
| 7900 | * |
| 7901 | * @param alpha The new value for the alpha property |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 7902 | * @return true if the View subclass handles alpha (the return value for onSetAlpha()) and |
| 7903 | * the new value for the alpha property is different from the old value |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 7904 | */ |
| 7905 | boolean setAlphaNoInvalidation(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7906 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 7907 | if (mTransformationInfo.mAlpha != alpha) { |
| 7908 | mTransformationInfo.mAlpha = alpha; |
| 7909 | boolean subclassHandlesAlpha = onSetAlpha((int) (alpha * 255)); |
| 7910 | if (subclassHandlesAlpha) { |
| 7911 | mPrivateFlags |= ALPHA_SET; |
| 7912 | return true; |
| 7913 | } else { |
| 7914 | mPrivateFlags &= ~ALPHA_SET; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7915 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7916 | mDisplayList.setAlpha(alpha); |
| 7917 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 7918 | } |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 7919 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 7920 | return false; |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 7921 | } |
| 7922 | |
| 7923 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7924 | * Top position of this view relative to its parent. |
| 7925 | * |
| 7926 | * @return The top of this view, in pixels. |
| 7927 | */ |
| 7928 | @ViewDebug.CapturedViewProperty |
| 7929 | public final int getTop() { |
| 7930 | return mTop; |
| 7931 | } |
| 7932 | |
| 7933 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7934 | * Sets the top position of this view relative to its parent. This method is meant to be called |
| 7935 | * by the layout system and should not generally be called otherwise, because the property |
| 7936 | * may be changed at any time by the layout. |
| 7937 | * |
| 7938 | * @param top The top of this view, in pixels. |
| 7939 | */ |
| 7940 | public final void setTop(int top) { |
| 7941 | if (top != mTop) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7942 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7943 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 7944 | || mTransformationInfo.mMatrixIsIdentity; |
| 7945 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7946 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7947 | int minTop; |
| 7948 | int yLoc; |
| 7949 | if (top < mTop) { |
| 7950 | minTop = top; |
| 7951 | yLoc = top - mTop; |
| 7952 | } else { |
| 7953 | minTop = mTop; |
| 7954 | yLoc = 0; |
| 7955 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7956 | invalidate(0, yLoc, mRight - mLeft, mBottom - minTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7957 | } |
| 7958 | } else { |
| 7959 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7960 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7961 | } |
| 7962 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7963 | int width = mRight - mLeft; |
| 7964 | int oldHeight = mBottom - mTop; |
| 7965 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7966 | mTop = top; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7967 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7968 | mDisplayList.setTop(mTop); |
| 7969 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7970 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7971 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 7972 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7973 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7974 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 7975 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7976 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7977 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7978 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7979 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7980 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 7981 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 7982 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7983 | } |
| 7984 | } |
| 7985 | |
| 7986 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7987 | * Bottom position of this view relative to its parent. |
| 7988 | * |
| 7989 | * @return The bottom of this view, in pixels. |
| 7990 | */ |
| 7991 | @ViewDebug.CapturedViewProperty |
| 7992 | public final int getBottom() { |
| 7993 | return mBottom; |
| 7994 | } |
| 7995 | |
| 7996 | /** |
Michael Jurka | dab559a | 2011-01-04 20:31:51 -0800 | [diff] [blame] | 7997 | * True if this view has changed since the last time being drawn. |
| 7998 | * |
| 7999 | * @return The dirty state of this view. |
| 8000 | */ |
| 8001 | public boolean isDirty() { |
| 8002 | return (mPrivateFlags & DIRTY_MASK) != 0; |
| 8003 | } |
| 8004 | |
| 8005 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8006 | * Sets the bottom position of this view relative to its parent. This method is meant to be |
| 8007 | * called by the layout system and should not generally be called otherwise, because the |
| 8008 | * property may be changed at any time by the layout. |
| 8009 | * |
| 8010 | * @param bottom The bottom of this view, in pixels. |
| 8011 | */ |
| 8012 | public final void setBottom(int bottom) { |
| 8013 | if (bottom != mBottom) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8014 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8015 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8016 | || mTransformationInfo.mMatrixIsIdentity; |
| 8017 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8018 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8019 | int maxBottom; |
| 8020 | if (bottom < mBottom) { |
| 8021 | maxBottom = mBottom; |
| 8022 | } else { |
| 8023 | maxBottom = bottom; |
| 8024 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8025 | invalidate(0, 0, mRight - mLeft, maxBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8026 | } |
| 8027 | } else { |
| 8028 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8029 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8030 | } |
| 8031 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8032 | int width = mRight - mLeft; |
| 8033 | int oldHeight = mBottom - mTop; |
| 8034 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8035 | mBottom = bottom; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8036 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8037 | mDisplayList.setBottom(mBottom); |
| 8038 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8039 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8040 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 8041 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8042 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8043 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 8044 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8045 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8046 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8047 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8048 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8049 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 8050 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8051 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8052 | } |
| 8053 | } |
| 8054 | |
| 8055 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8056 | * Left position of this view relative to its parent. |
| 8057 | * |
| 8058 | * @return The left edge of this view, in pixels. |
| 8059 | */ |
| 8060 | @ViewDebug.CapturedViewProperty |
| 8061 | public final int getLeft() { |
| 8062 | return mLeft; |
| 8063 | } |
| 8064 | |
| 8065 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8066 | * Sets the left position of this view relative to its parent. This method is meant to be called |
| 8067 | * by the layout system and should not generally be called otherwise, because the property |
| 8068 | * may be changed at any time by the layout. |
| 8069 | * |
| 8070 | * @param left The bottom of this view, in pixels. |
| 8071 | */ |
| 8072 | public final void setLeft(int left) { |
| 8073 | if (left != mLeft) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8074 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8075 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8076 | || mTransformationInfo.mMatrixIsIdentity; |
| 8077 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8078 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8079 | int minLeft; |
| 8080 | int xLoc; |
| 8081 | if (left < mLeft) { |
| 8082 | minLeft = left; |
| 8083 | xLoc = left - mLeft; |
| 8084 | } else { |
| 8085 | minLeft = mLeft; |
| 8086 | xLoc = 0; |
| 8087 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8088 | invalidate(xLoc, 0, mRight - minLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8089 | } |
| 8090 | } else { |
| 8091 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8092 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8093 | } |
| 8094 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8095 | int oldWidth = mRight - mLeft; |
| 8096 | int height = mBottom - mTop; |
| 8097 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8098 | mLeft = left; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8099 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8100 | mDisplayList.setLeft(left); |
| 8101 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8102 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8103 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 8104 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8105 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8106 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 8107 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8108 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8109 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8110 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8111 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8112 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 8113 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8114 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8115 | if (USE_DISPLAY_LIST_PROPERTIES) { |
| 8116 | |
| 8117 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8118 | } |
| 8119 | } |
| 8120 | |
| 8121 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8122 | * Right position of this view relative to its parent. |
| 8123 | * |
| 8124 | * @return The right edge of this view, in pixels. |
| 8125 | */ |
| 8126 | @ViewDebug.CapturedViewProperty |
| 8127 | public final int getRight() { |
| 8128 | return mRight; |
| 8129 | } |
| 8130 | |
| 8131 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8132 | * Sets the right position of this view relative to its parent. This method is meant to be called |
| 8133 | * by the layout system and should not generally be called otherwise, because the property |
| 8134 | * may be changed at any time by the layout. |
| 8135 | * |
| 8136 | * @param right The bottom of this view, in pixels. |
| 8137 | */ |
| 8138 | public final void setRight(int right) { |
| 8139 | if (right != mRight) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8140 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8141 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8142 | || mTransformationInfo.mMatrixIsIdentity; |
| 8143 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8144 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8145 | int maxRight; |
| 8146 | if (right < mRight) { |
| 8147 | maxRight = mRight; |
| 8148 | } else { |
| 8149 | maxRight = right; |
| 8150 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8151 | invalidate(0, 0, maxRight - mLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8152 | } |
| 8153 | } else { |
| 8154 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8155 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8156 | } |
| 8157 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8158 | int oldWidth = mRight - mLeft; |
| 8159 | int height = mBottom - mTop; |
| 8160 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8161 | mRight = right; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8162 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8163 | mDisplayList.setRight(mRight); |
| 8164 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8165 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8166 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 8167 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8168 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8169 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 8170 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8171 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8172 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8173 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8174 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8175 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 8176 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8177 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8178 | } |
| 8179 | } |
| 8180 | |
| 8181 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8182 | * The visual x position of this view, in pixels. This is equivalent to the |
| 8183 | * {@link #setTranslationX(float) translationX} property plus the current |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8184 | * {@link #getLeft() left} property. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8185 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8186 | * @return The visual x position of this view, in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8187 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8188 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8189 | public float getX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8190 | return mLeft + (mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8191 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8192 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8193 | /** |
| 8194 | * Sets the visual x position of this view, in pixels. This is equivalent to setting the |
| 8195 | * {@link #setTranslationX(float) translationX} property to be the difference between |
| 8196 | * the x value passed in and the current {@link #getLeft() left} property. |
| 8197 | * |
| 8198 | * @param x The visual x position of this view, in pixels. |
| 8199 | */ |
| 8200 | public void setX(float x) { |
| 8201 | setTranslationX(x - mLeft); |
| 8202 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8203 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8204 | /** |
| 8205 | * The visual y position of this view, in pixels. This is equivalent to the |
| 8206 | * {@link #setTranslationY(float) translationY} property plus the current |
| 8207 | * {@link #getTop() top} property. |
| 8208 | * |
| 8209 | * @return The visual y position of this view, in pixels. |
| 8210 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8211 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8212 | public float getY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8213 | return mTop + (mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8214 | } |
| 8215 | |
| 8216 | /** |
| 8217 | * Sets the visual y position of this view, in pixels. This is equivalent to setting the |
| 8218 | * {@link #setTranslationY(float) translationY} property to be the difference between |
| 8219 | * the y value passed in and the current {@link #getTop() top} property. |
| 8220 | * |
| 8221 | * @param y The visual y position of this view, in pixels. |
| 8222 | */ |
| 8223 | public void setY(float y) { |
| 8224 | setTranslationY(y - mTop); |
| 8225 | } |
| 8226 | |
| 8227 | |
| 8228 | /** |
| 8229 | * The horizontal location of this view relative to its {@link #getLeft() left} position. |
| 8230 | * This position is post-layout, in addition to wherever the object's |
| 8231 | * layout placed it. |
| 8232 | * |
| 8233 | * @return The horizontal position of this view relative to its left position, in pixels. |
| 8234 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8235 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8236 | public float getTranslationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8237 | return mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0; |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8238 | } |
| 8239 | |
| 8240 | /** |
| 8241 | * Sets the horizontal location of this view relative to its {@link #getLeft() left} position. |
| 8242 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 8243 | * layout placed it. |
| 8244 | * |
| 8245 | * @param translationX The horizontal position of this view relative to its left position, |
| 8246 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8247 | * |
| 8248 | * @attr ref android.R.styleable#View_translationX |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8249 | */ |
| 8250 | public void setTranslationX(float translationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8251 | ensureTransformationInfo(); |
| 8252 | final TransformationInfo info = mTransformationInfo; |
| 8253 | if (info.mTranslationX != translationX) { |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8254 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8255 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8256 | info.mTranslationX = translationX; |
| 8257 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8258 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8259 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8260 | mDisplayList.setTranslationX(translationX); |
| 8261 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8262 | } |
| 8263 | } |
| 8264 | |
| 8265 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8266 | * The horizontal location of this view relative to its {@link #getTop() top} position. |
| 8267 | * This position is post-layout, in addition to wherever the object's |
| 8268 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8269 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8270 | * @return The vertical position of this view relative to its top position, |
| 8271 | * in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8272 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8273 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8274 | public float getTranslationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8275 | return mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8276 | } |
| 8277 | |
| 8278 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8279 | * Sets the vertical location of this view relative to its {@link #getTop() top} position. |
| 8280 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 8281 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8282 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8283 | * @param translationY The vertical position of this view relative to its top position, |
| 8284 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8285 | * |
| 8286 | * @attr ref android.R.styleable#View_translationY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8287 | */ |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8288 | public void setTranslationY(float translationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8289 | ensureTransformationInfo(); |
| 8290 | final TransformationInfo info = mTransformationInfo; |
| 8291 | if (info.mTranslationY != translationY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8292 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8293 | info.mTranslationY = translationY; |
| 8294 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8295 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8296 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8297 | mDisplayList.setTranslationY(translationY); |
| 8298 | } |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8299 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8300 | } |
| 8301 | |
| 8302 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8303 | * Hit rectangle in parent's coordinates |
| 8304 | * |
| 8305 | * @param outRect The hit rectangle of the view. |
| 8306 | */ |
| 8307 | public void getHitRect(Rect outRect) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8308 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8309 | final TransformationInfo info = mTransformationInfo; |
| 8310 | if (info == null || info.mMatrixIsIdentity || mAttachInfo == null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8311 | outRect.set(mLeft, mTop, mRight, mBottom); |
| 8312 | } else { |
| 8313 | final RectF tmpRect = mAttachInfo.mTmpTransformRect; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8314 | tmpRect.set(-info.mPivotX, -info.mPivotY, |
| 8315 | getWidth() - info.mPivotX, getHeight() - info.mPivotY); |
| 8316 | info.mMatrix.mapRect(tmpRect); |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8317 | outRect.set((int) tmpRect.left + mLeft, (int) tmpRect.top + mTop, |
| 8318 | (int) tmpRect.right + mLeft, (int) tmpRect.bottom + mTop); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8319 | } |
| 8320 | } |
| 8321 | |
| 8322 | /** |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8323 | * Determines whether the given point, in local coordinates is inside the view. |
| 8324 | */ |
| 8325 | /*package*/ final boolean pointInView(float localX, float localY) { |
| 8326 | return localX >= 0 && localX < (mRight - mLeft) |
| 8327 | && localY >= 0 && localY < (mBottom - mTop); |
| 8328 | } |
| 8329 | |
| 8330 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8331 | * Utility method to determine whether the given point, in local coordinates, |
| 8332 | * is inside the view, where the area of the view is expanded by the slop factor. |
| 8333 | * This method is called while processing touch-move events to determine if the event |
| 8334 | * is still within the view. |
| 8335 | */ |
| 8336 | private boolean pointInView(float localX, float localY, float slop) { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8337 | return localX >= -slop && localY >= -slop && localX < ((mRight - mLeft) + slop) && |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8338 | localY < ((mBottom - mTop) + slop); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8339 | } |
| 8340 | |
| 8341 | /** |
| 8342 | * When a view has focus and the user navigates away from it, the next view is searched for |
| 8343 | * starting from the rectangle filled in by this method. |
| 8344 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8345 | * By default, the rectange is the {@link #getDrawingRect(android.graphics.Rect)}) |
| 8346 | * of the view. However, if your view maintains some idea of internal selection, |
| 8347 | * such as a cursor, or a selected row or column, you should override this method and |
| 8348 | * fill in a more specific rectangle. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8349 | * |
| 8350 | * @param r The rectangle to fill in, in this view's coordinates. |
| 8351 | */ |
| 8352 | public void getFocusedRect(Rect r) { |
| 8353 | getDrawingRect(r); |
| 8354 | } |
| 8355 | |
| 8356 | /** |
| 8357 | * If some part of this view is not clipped by any of its parents, then |
| 8358 | * return that area in r in global (root) coordinates. To convert r to local |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 8359 | * coordinates (without taking possible View rotations into account), offset |
| 8360 | * it by -globalOffset (e.g. r.offset(-globalOffset.x, -globalOffset.y)). |
| 8361 | * If the view is completely clipped or translated out, return false. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8362 | * |
| 8363 | * @param r If true is returned, r holds the global coordinates of the |
| 8364 | * visible portion of this view. |
| 8365 | * @param globalOffset If true is returned, globalOffset holds the dx,dy |
| 8366 | * between this view and its root. globalOffet may be null. |
| 8367 | * @return true if r is non-empty (i.e. part of the view is visible at the |
| 8368 | * root level. |
| 8369 | */ |
| 8370 | public boolean getGlobalVisibleRect(Rect r, Point globalOffset) { |
| 8371 | int width = mRight - mLeft; |
| 8372 | int height = mBottom - mTop; |
| 8373 | if (width > 0 && height > 0) { |
| 8374 | r.set(0, 0, width, height); |
| 8375 | if (globalOffset != null) { |
| 8376 | globalOffset.set(-mScrollX, -mScrollY); |
| 8377 | } |
| 8378 | return mParent == null || mParent.getChildVisibleRect(this, r, globalOffset); |
| 8379 | } |
| 8380 | return false; |
| 8381 | } |
| 8382 | |
| 8383 | public final boolean getGlobalVisibleRect(Rect r) { |
| 8384 | return getGlobalVisibleRect(r, null); |
| 8385 | } |
| 8386 | |
| 8387 | public final boolean getLocalVisibleRect(Rect r) { |
| 8388 | Point offset = new Point(); |
| 8389 | if (getGlobalVisibleRect(r, offset)) { |
| 8390 | r.offset(-offset.x, -offset.y); // make r local |
| 8391 | return true; |
| 8392 | } |
| 8393 | return false; |
| 8394 | } |
| 8395 | |
| 8396 | /** |
| 8397 | * Offset this view's vertical location by the specified number of pixels. |
| 8398 | * |
| 8399 | * @param offset the number of pixels to offset the view by |
| 8400 | */ |
| 8401 | public void offsetTopAndBottom(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8402 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8403 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8404 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8405 | || mTransformationInfo.mMatrixIsIdentity; |
| 8406 | if (matrixIsIdentity) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8407 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8408 | invalidateViewProperty(false, false); |
| 8409 | } else { |
| 8410 | final ViewParent p = mParent; |
| 8411 | if (p != null && mAttachInfo != null) { |
| 8412 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 8413 | int minTop; |
| 8414 | int maxBottom; |
| 8415 | int yLoc; |
| 8416 | if (offset < 0) { |
| 8417 | minTop = mTop + offset; |
| 8418 | maxBottom = mBottom; |
| 8419 | yLoc = offset; |
| 8420 | } else { |
| 8421 | minTop = mTop; |
| 8422 | maxBottom = mBottom + offset; |
| 8423 | yLoc = 0; |
| 8424 | } |
| 8425 | r.set(0, yLoc, mRight - mLeft, maxBottom - minTop); |
| 8426 | p.invalidateChild(this, r); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 8427 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8428 | } |
| 8429 | } else { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8430 | invalidateViewProperty(false, false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8431 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8432 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8433 | mTop += offset; |
| 8434 | mBottom += offset; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8435 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8436 | mDisplayList.offsetTopBottom(offset); |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8437 | invalidateViewProperty(false, false); |
| 8438 | } else { |
| 8439 | if (!matrixIsIdentity) { |
| 8440 | invalidateViewProperty(false, true); |
| 8441 | } |
| 8442 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8443 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8444 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8445 | } |
| 8446 | |
| 8447 | /** |
| 8448 | * Offset this view's horizontal location by the specified amount of pixels. |
| 8449 | * |
| 8450 | * @param offset the numer of pixels to offset the view by |
| 8451 | */ |
| 8452 | public void offsetLeftAndRight(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8453 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8454 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8455 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8456 | || mTransformationInfo.mMatrixIsIdentity; |
| 8457 | if (matrixIsIdentity) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8458 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8459 | invalidateViewProperty(false, false); |
| 8460 | } else { |
| 8461 | final ViewParent p = mParent; |
| 8462 | if (p != null && mAttachInfo != null) { |
| 8463 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 8464 | int minLeft; |
| 8465 | int maxRight; |
| 8466 | if (offset < 0) { |
| 8467 | minLeft = mLeft + offset; |
| 8468 | maxRight = mRight; |
| 8469 | } else { |
| 8470 | minLeft = mLeft; |
| 8471 | maxRight = mRight + offset; |
| 8472 | } |
| 8473 | r.set(0, 0, maxRight - minLeft, mBottom - mTop); |
| 8474 | p.invalidateChild(this, r); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 8475 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8476 | } |
| 8477 | } else { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8478 | invalidateViewProperty(false, false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8479 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8480 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8481 | mLeft += offset; |
| 8482 | mRight += offset; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8483 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8484 | mDisplayList.offsetLeftRight(offset); |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8485 | invalidateViewProperty(false, false); |
| 8486 | } else { |
| 8487 | if (!matrixIsIdentity) { |
| 8488 | invalidateViewProperty(false, true); |
| 8489 | } |
| 8490 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8491 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8492 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8493 | } |
| 8494 | |
| 8495 | /** |
| 8496 | * Get the LayoutParams associated with this view. All views should have |
| 8497 | * layout parameters. These supply parameters to the <i>parent</i> of this |
| 8498 | * view specifying how it should be arranged. There are many subclasses of |
| 8499 | * ViewGroup.LayoutParams, and these correspond to the different subclasses |
| 8500 | * of ViewGroup that are responsible for arranging their children. |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 8501 | * |
| 8502 | * This method may return null if this View is not attached to a parent |
| 8503 | * ViewGroup or {@link #setLayoutParams(android.view.ViewGroup.LayoutParams)} |
| 8504 | * was not invoked successfully. When a View is attached to a parent |
| 8505 | * ViewGroup, this method must not return null. |
| 8506 | * |
| 8507 | * @return The LayoutParams associated with this view, or null if no |
| 8508 | * parameters have been set yet |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8509 | */ |
Konstantin Lopyrev | 91a7f5f | 2010-08-10 18:54:54 -0700 | [diff] [blame] | 8510 | @ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8511 | public ViewGroup.LayoutParams getLayoutParams() { |
| 8512 | return mLayoutParams; |
| 8513 | } |
| 8514 | |
| 8515 | /** |
| 8516 | * Set the layout parameters associated with this view. These supply |
| 8517 | * parameters to the <i>parent</i> of this view specifying how it should be |
| 8518 | * arranged. There are many subclasses of ViewGroup.LayoutParams, and these |
| 8519 | * correspond to the different subclasses of ViewGroup that are responsible |
| 8520 | * for arranging their children. |
| 8521 | * |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 8522 | * @param params The layout parameters for this view, cannot be null |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8523 | */ |
| 8524 | public void setLayoutParams(ViewGroup.LayoutParams params) { |
| 8525 | if (params == null) { |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 8526 | throw new NullPointerException("Layout parameters cannot be null"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8527 | } |
| 8528 | mLayoutParams = params; |
Philip Milne | d7dd890 | 2012-01-26 16:55:30 -0800 | [diff] [blame] | 8529 | if (mParent instanceof ViewGroup) { |
| 8530 | ((ViewGroup) mParent).onSetLayoutParams(this, params); |
| 8531 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8532 | requestLayout(); |
| 8533 | } |
| 8534 | |
| 8535 | /** |
| 8536 | * Set the scrolled position of your view. This will cause a call to |
| 8537 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8538 | * invalidated. |
| 8539 | * @param x the x position to scroll to |
| 8540 | * @param y the y position to scroll to |
| 8541 | */ |
| 8542 | public void scrollTo(int x, int y) { |
| 8543 | if (mScrollX != x || mScrollY != y) { |
| 8544 | int oldX = mScrollX; |
| 8545 | int oldY = mScrollY; |
| 8546 | mScrollX = x; |
| 8547 | mScrollY = y; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8548 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8549 | onScrollChanged(mScrollX, mScrollY, oldX, oldY); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8550 | if (!awakenScrollBars()) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8551 | invalidate(true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8552 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8553 | } |
| 8554 | } |
| 8555 | |
| 8556 | /** |
| 8557 | * Move the scrolled position of your view. This will cause a call to |
| 8558 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8559 | * invalidated. |
| 8560 | * @param x the amount of pixels to scroll by horizontally |
| 8561 | * @param y the amount of pixels to scroll by vertically |
| 8562 | */ |
| 8563 | public void scrollBy(int x, int y) { |
| 8564 | scrollTo(mScrollX + x, mScrollY + y); |
| 8565 | } |
| 8566 | |
| 8567 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8568 | * <p>Trigger the scrollbars to draw. When invoked this method starts an |
| 8569 | * animation to fade the scrollbars out after a default delay. If a subclass |
| 8570 | * provides animated scrolling, the start delay should equal the duration |
| 8571 | * of the scrolling animation.</p> |
| 8572 | * |
| 8573 | * <p>The animation starts only if at least one of the scrollbars is |
| 8574 | * enabled, as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 8575 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 8576 | * this method returns true, and false otherwise. If the animation is |
| 8577 | * started, this method calls {@link #invalidate()}; in that case the |
| 8578 | * caller should not call {@link #invalidate()}.</p> |
| 8579 | * |
| 8580 | * <p>This method should be invoked every time a subclass directly updates |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 8581 | * the scroll parameters.</p> |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8582 | * |
| 8583 | * <p>This method is automatically invoked by {@link #scrollBy(int, int)} |
| 8584 | * and {@link #scrollTo(int, int)}.</p> |
| 8585 | * |
| 8586 | * @return true if the animation is played, false otherwise |
| 8587 | * |
| 8588 | * @see #awakenScrollBars(int) |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8589 | * @see #scrollBy(int, int) |
| 8590 | * @see #scrollTo(int, int) |
| 8591 | * @see #isHorizontalScrollBarEnabled() |
| 8592 | * @see #isVerticalScrollBarEnabled() |
| 8593 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 8594 | * @see #setVerticalScrollBarEnabled(boolean) |
| 8595 | */ |
| 8596 | protected boolean awakenScrollBars() { |
| 8597 | return mScrollCache != null && |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8598 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade, true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8599 | } |
| 8600 | |
| 8601 | /** |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 8602 | * Trigger the scrollbars to draw. |
| 8603 | * This method differs from awakenScrollBars() only in its default duration. |
| 8604 | * initialAwakenScrollBars() will show the scroll bars for longer than |
| 8605 | * usual to give the user more of a chance to notice them. |
| 8606 | * |
| 8607 | * @return true if the animation is played, false otherwise. |
| 8608 | */ |
| 8609 | private boolean initialAwakenScrollBars() { |
| 8610 | return mScrollCache != null && |
| 8611 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade * 4, true); |
| 8612 | } |
| 8613 | |
| 8614 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8615 | * <p> |
| 8616 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 8617 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 8618 | * provides animated scrolling, the start delay should equal the duration of |
| 8619 | * the scrolling animation. |
| 8620 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8621 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8622 | * <p> |
| 8623 | * The animation starts only if at least one of the scrollbars is enabled, |
| 8624 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 8625 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 8626 | * this method returns true, and false otherwise. If the animation is |
| 8627 | * started, this method calls {@link #invalidate()}; in that case the caller |
| 8628 | * should not call {@link #invalidate()}. |
| 8629 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8630 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8631 | * <p> |
| 8632 | * This method should be invoked everytime a subclass directly updates the |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 8633 | * scroll parameters. |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8634 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8635 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8636 | * @param startDelay the delay, in milliseconds, after which the animation |
| 8637 | * should start; when the delay is 0, the animation starts |
| 8638 | * immediately |
| 8639 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8640 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8641 | * @see #scrollBy(int, int) |
| 8642 | * @see #scrollTo(int, int) |
| 8643 | * @see #isHorizontalScrollBarEnabled() |
| 8644 | * @see #isVerticalScrollBarEnabled() |
| 8645 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 8646 | * @see #setVerticalScrollBarEnabled(boolean) |
| 8647 | */ |
| 8648 | protected boolean awakenScrollBars(int startDelay) { |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8649 | return awakenScrollBars(startDelay, true); |
| 8650 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8651 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8652 | /** |
| 8653 | * <p> |
| 8654 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 8655 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 8656 | * provides animated scrolling, the start delay should equal the duration of |
| 8657 | * the scrolling animation. |
| 8658 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8659 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8660 | * <p> |
| 8661 | * The animation starts only if at least one of the scrollbars is enabled, |
| 8662 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 8663 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 8664 | * this method returns true, and false otherwise. If the animation is |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8665 | * started, this method calls {@link #invalidate()} if the invalidate parameter |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8666 | * is set to true; in that case the caller |
| 8667 | * should not call {@link #invalidate()}. |
| 8668 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8669 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8670 | * <p> |
| 8671 | * This method should be invoked everytime a subclass directly updates the |
| 8672 | * scroll parameters. |
| 8673 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8674 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8675 | * @param startDelay the delay, in milliseconds, after which the animation |
| 8676 | * should start; when the delay is 0, the animation starts |
| 8677 | * immediately |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8678 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8679 | * @param invalidate Wheter this method should call invalidate |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8680 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8681 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8682 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8683 | * @see #scrollBy(int, int) |
| 8684 | * @see #scrollTo(int, int) |
| 8685 | * @see #isHorizontalScrollBarEnabled() |
| 8686 | * @see #isVerticalScrollBarEnabled() |
| 8687 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 8688 | * @see #setVerticalScrollBarEnabled(boolean) |
| 8689 | */ |
| 8690 | protected boolean awakenScrollBars(int startDelay, boolean invalidate) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8691 | final ScrollabilityCache scrollCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8692 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8693 | if (scrollCache == null || !scrollCache.fadeScrollBars) { |
| 8694 | return false; |
| 8695 | } |
| 8696 | |
| 8697 | if (scrollCache.scrollBar == null) { |
| 8698 | scrollCache.scrollBar = new ScrollBarDrawable(); |
| 8699 | } |
| 8700 | |
| 8701 | if (isHorizontalScrollBarEnabled() || isVerticalScrollBarEnabled()) { |
| 8702 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8703 | if (invalidate) { |
| 8704 | // Invalidate to show the scrollbars |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8705 | invalidate(true); |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8706 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8707 | |
| 8708 | if (scrollCache.state == ScrollabilityCache.OFF) { |
| 8709 | // FIXME: this is copied from WindowManagerService. |
| 8710 | // We should get this value from the system when it |
| 8711 | // is possible to do so. |
| 8712 | final int KEY_REPEAT_FIRST_DELAY = 750; |
| 8713 | startDelay = Math.max(KEY_REPEAT_FIRST_DELAY, startDelay); |
| 8714 | } |
| 8715 | |
| 8716 | // Tell mScrollCache when we should start fading. This may |
| 8717 | // extend the fade start time if one was already scheduled |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 8718 | long fadeStartTime = AnimationUtils.currentAnimationTimeMillis() + startDelay; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8719 | scrollCache.fadeStartTime = fadeStartTime; |
| 8720 | scrollCache.state = ScrollabilityCache.ON; |
| 8721 | |
| 8722 | // Schedule our fader to run, unscheduling any old ones first |
| 8723 | if (mAttachInfo != null) { |
| 8724 | mAttachInfo.mHandler.removeCallbacks(scrollCache); |
| 8725 | mAttachInfo.mHandler.postAtTime(scrollCache, fadeStartTime); |
| 8726 | } |
| 8727 | |
| 8728 | return true; |
| 8729 | } |
| 8730 | |
| 8731 | return false; |
| 8732 | } |
| 8733 | |
| 8734 | /** |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8735 | * Do not invalidate views which are not visible and which are not running an animation. They |
| 8736 | * will not get drawn and they should not set dirty flags as if they will be drawn |
| 8737 | */ |
| 8738 | private boolean skipInvalidate() { |
| 8739 | return (mViewFlags & VISIBILITY_MASK) != VISIBLE && mCurrentAnimation == null && |
| 8740 | (!(mParent instanceof ViewGroup) || |
| 8741 | !((ViewGroup) mParent).isViewTransitioning(this)); |
| 8742 | } |
| 8743 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 8744 | * Mark the area defined by dirty as needing to be drawn. If the view is |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8745 | * visible, {@link #onDraw(android.graphics.Canvas)} will be called at some point |
| 8746 | * in the future. This must be called from a UI thread. To call from a non-UI |
| 8747 | * thread, call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8748 | * |
| 8749 | * WARNING: This method is destructive to dirty. |
| 8750 | * @param dirty the rectangle representing the bounds of the dirty region |
| 8751 | */ |
| 8752 | public void invalidate(Rect dirty) { |
| 8753 | if (ViewDebug.TRACE_HIERARCHY) { |
| 8754 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 8755 | } |
| 8756 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8757 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 8758 | return; |
| 8759 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8760 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8761 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || |
| 8762 | (mPrivateFlags & INVALIDATED) != INVALIDATED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8763 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8764 | mPrivateFlags |= INVALIDATED; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 8765 | mPrivateFlags |= DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8766 | final ViewParent p = mParent; |
| 8767 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8768 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 8769 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 8770 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 8771 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 8772 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8773 | p.invalidateChild(this, null); |
| 8774 | return; |
| 8775 | } |
Romain Guy | af636eb | 2010-12-09 17:47:21 -0800 | [diff] [blame] | 8776 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8777 | if (p != null && ai != null) { |
| 8778 | final int scrollX = mScrollX; |
| 8779 | final int scrollY = mScrollY; |
| 8780 | final Rect r = ai.mTmpInvalRect; |
| 8781 | r.set(dirty.left - scrollX, dirty.top - scrollY, |
| 8782 | dirty.right - scrollX, dirty.bottom - scrollY); |
| 8783 | mParent.invalidateChild(this, r); |
| 8784 | } |
| 8785 | } |
| 8786 | } |
| 8787 | |
| 8788 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 8789 | * Mark the area defined by the rect (l,t,r,b) as needing to be drawn. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8790 | * The coordinates of the dirty rect are relative to the view. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8791 | * If the view is visible, {@link #onDraw(android.graphics.Canvas)} |
| 8792 | * will be called at some point in the future. This must be called from |
| 8793 | * a UI thread. To call from a non-UI thread, call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8794 | * @param l the left position of the dirty region |
| 8795 | * @param t the top position of the dirty region |
| 8796 | * @param r the right position of the dirty region |
| 8797 | * @param b the bottom position of the dirty region |
| 8798 | */ |
| 8799 | public void invalidate(int l, int t, int r, int b) { |
| 8800 | if (ViewDebug.TRACE_HIERARCHY) { |
| 8801 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 8802 | } |
| 8803 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8804 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 8805 | return; |
| 8806 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8807 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8808 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || |
| 8809 | (mPrivateFlags & INVALIDATED) != INVALIDATED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8810 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8811 | mPrivateFlags |= INVALIDATED; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 8812 | mPrivateFlags |= DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8813 | final ViewParent p = mParent; |
| 8814 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8815 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 8816 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 8817 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 8818 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 8819 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8820 | p.invalidateChild(this, null); |
| 8821 | return; |
| 8822 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 8823 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8824 | if (p != null && ai != null && l < r && t < b) { |
| 8825 | final int scrollX = mScrollX; |
| 8826 | final int scrollY = mScrollY; |
| 8827 | final Rect tmpr = ai.mTmpInvalRect; |
| 8828 | tmpr.set(l - scrollX, t - scrollY, r - scrollX, b - scrollY); |
| 8829 | p.invalidateChild(this, tmpr); |
| 8830 | } |
| 8831 | } |
| 8832 | } |
| 8833 | |
| 8834 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8835 | * Invalidate the whole view. If the view is visible, |
| 8836 | * {@link #onDraw(android.graphics.Canvas)} will be called at some point in |
| 8837 | * the future. This must be called from a UI thread. To call from a non-UI thread, |
| 8838 | * call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8839 | */ |
| 8840 | public void invalidate() { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8841 | invalidate(true); |
| 8842 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8843 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8844 | /** |
| 8845 | * This is where the invalidate() work actually happens. A full invalidate() |
| 8846 | * causes the drawing cache to be invalidated, but this function can be called with |
| 8847 | * invalidateCache set to false to skip that invalidation step for cases that do not |
| 8848 | * need it (for example, a component that remains at the same dimensions with the same |
| 8849 | * content). |
| 8850 | * |
| 8851 | * @param invalidateCache Whether the drawing cache for this view should be invalidated as |
| 8852 | * well. This is usually true for a full invalidate, but may be set to false if the |
| 8853 | * View's contents or dimensions have not changed. |
| 8854 | */ |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 8855 | void invalidate(boolean invalidateCache) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8856 | if (ViewDebug.TRACE_HIERARCHY) { |
| 8857 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 8858 | } |
| 8859 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8860 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 8861 | return; |
| 8862 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8863 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Romain Guy | c5d5586 | 2011-01-21 19:01:46 -0800 | [diff] [blame] | 8864 | (invalidateCache && (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) || |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8865 | (mPrivateFlags & INVALIDATED) != INVALIDATED || isOpaque() != mLastIsOpaque) { |
| 8866 | mLastIsOpaque = isOpaque(); |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8867 | mPrivateFlags &= ~DRAWN; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 8868 | mPrivateFlags |= DIRTY; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8869 | if (invalidateCache) { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8870 | mPrivateFlags |= INVALIDATED; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8871 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 8872 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8873 | final AttachInfo ai = mAttachInfo; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 8874 | final ViewParent p = mParent; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8875 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 8876 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 8877 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 8878 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 8879 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8880 | p.invalidateChild(this, null); |
| 8881 | return; |
| 8882 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 8883 | } |
Michael Jurka | ebefea4 | 2010-11-15 16:04:01 -0800 | [diff] [blame] | 8884 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8885 | if (p != null && ai != null) { |
| 8886 | final Rect r = ai.mTmpInvalRect; |
| 8887 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 8888 | // Don't call invalidate -- we don't want to internally scroll |
| 8889 | // our own bounds |
| 8890 | p.invalidateChild(this, r); |
| 8891 | } |
| 8892 | } |
| 8893 | } |
| 8894 | |
| 8895 | /** |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8896 | * Quick invalidation for View property changes (alpha, translationXY, etc.). We don't want to |
| 8897 | * set any flags or handle all of the cases handled by the default invalidation methods. |
| 8898 | * Instead, we just want to schedule a traversal in ViewRootImpl with the appropriate |
| 8899 | * dirty rect. This method calls into fast invalidation methods in ViewGroup that |
| 8900 | * walk up the hierarchy, transforming the dirty rect as necessary. |
| 8901 | * |
| 8902 | * The method also handles normal invalidation logic if display list properties are not |
| 8903 | * being used in this view. The invalidateParent and forceRedraw flags are used by that |
| 8904 | * backup approach, to handle these cases used in the various property-setting methods. |
| 8905 | * |
| 8906 | * @param invalidateParent Force a call to invalidateParentCaches() if display list properties |
| 8907 | * are not being used in this view |
| 8908 | * @param forceRedraw Mark the view as DRAWN to force the invalidation to propagate, if display |
| 8909 | * list properties are not being used in this view |
| 8910 | */ |
| 8911 | void invalidateViewProperty(boolean invalidateParent, boolean forceRedraw) { |
| 8912 | if (!USE_DISPLAY_LIST_PROPERTIES || mDisplayList == null || |
| 8913 | (mPrivateFlags & DRAW_ANIMATION) == DRAW_ANIMATION) { |
| 8914 | if (invalidateParent) { |
| 8915 | invalidateParentCaches(); |
| 8916 | } |
| 8917 | if (forceRedraw) { |
| 8918 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
| 8919 | } |
| 8920 | invalidate(false); |
| 8921 | } else { |
| 8922 | final AttachInfo ai = mAttachInfo; |
| 8923 | final ViewParent p = mParent; |
| 8924 | if (p != null && ai != null) { |
| 8925 | final Rect r = ai.mTmpInvalRect; |
| 8926 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 8927 | if (mParent instanceof ViewGroup) { |
| 8928 | ((ViewGroup) mParent).invalidateChildFast(this, r); |
| 8929 | } else { |
| 8930 | mParent.invalidateChild(this, r); |
| 8931 | } |
| 8932 | } |
| 8933 | } |
| 8934 | } |
| 8935 | |
| 8936 | /** |
| 8937 | * Utility method to transform a given Rect by the current matrix of this view. |
| 8938 | */ |
| 8939 | void transformRect(final Rect rect) { |
| 8940 | if (!getMatrix().isIdentity()) { |
| 8941 | RectF boundingRect = mAttachInfo.mTmpTransformRect; |
| 8942 | boundingRect.set(rect); |
| 8943 | getMatrix().mapRect(boundingRect); |
| 8944 | rect.set((int) (boundingRect.left - 0.5f), |
| 8945 | (int) (boundingRect.top - 0.5f), |
| 8946 | (int) (boundingRect.right + 0.5f), |
| 8947 | (int) (boundingRect.bottom + 0.5f)); |
| 8948 | } |
| 8949 | } |
| 8950 | |
| 8951 | /** |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8952 | * Used to indicate that the parent of this view should clear its caches. This functionality |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8953 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 8954 | * which is necessary when various parent-managed properties of the view change, such as |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8955 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method only |
| 8956 | * clears the parent caches and does not causes an invalidate event. |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8957 | * |
| 8958 | * @hide |
| 8959 | */ |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8960 | protected void invalidateParentCaches() { |
| 8961 | if (mParent instanceof View) { |
| 8962 | ((View) mParent).mPrivateFlags |= INVALIDATED; |
| 8963 | } |
| 8964 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8965 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8966 | /** |
| 8967 | * Used to indicate that the parent of this view should be invalidated. This functionality |
| 8968 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 8969 | * which is necessary when various parent-managed properties of the view change, such as |
| 8970 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method will propagate |
| 8971 | * an invalidation event to the parent. |
| 8972 | * |
| 8973 | * @hide |
| 8974 | */ |
| 8975 | protected void invalidateParentIfNeeded() { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8976 | if (isHardwareAccelerated() && mParent instanceof View) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8977 | ((View) mParent).invalidate(true); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8978 | } |
| 8979 | } |
| 8980 | |
| 8981 | /** |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 8982 | * Indicates whether this View is opaque. An opaque View guarantees that it will |
| 8983 | * draw all the pixels overlapping its bounds using a fully opaque color. |
| 8984 | * |
| 8985 | * Subclasses of View should override this method whenever possible to indicate |
| 8986 | * whether an instance is opaque. Opaque Views are treated in a special way by |
| 8987 | * the View hierarchy, possibly allowing it to perform optimizations during |
| 8988 | * invalidate/draw passes. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 8989 | * |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 8990 | * @return True if this View is guaranteed to be fully opaque, false otherwise. |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 8991 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 8992 | @ViewDebug.ExportedProperty(category = "drawing") |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 8993 | public boolean isOpaque() { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 8994 | return (mPrivateFlags & OPAQUE_MASK) == OPAQUE_MASK && |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8995 | ((mTransformationInfo != null ? mTransformationInfo.mAlpha : 1) |
| 8996 | >= 1.0f - ViewConfiguration.ALPHA_THRESHOLD); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 8997 | } |
| 8998 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 8999 | /** |
| 9000 | * @hide |
| 9001 | */ |
| 9002 | protected void computeOpaqueFlags() { |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9003 | // Opaque if: |
| 9004 | // - Has a background |
| 9005 | // - Background is opaque |
| 9006 | // - Doesn't have scrollbars or scrollbars are inside overlay |
| 9007 | |
| 9008 | if (mBGDrawable != null && mBGDrawable.getOpacity() == PixelFormat.OPAQUE) { |
| 9009 | mPrivateFlags |= OPAQUE_BACKGROUND; |
| 9010 | } else { |
| 9011 | mPrivateFlags &= ~OPAQUE_BACKGROUND; |
| 9012 | } |
| 9013 | |
| 9014 | final int flags = mViewFlags; |
| 9015 | if (((flags & SCROLLBARS_VERTICAL) == 0 && (flags & SCROLLBARS_HORIZONTAL) == 0) || |
| 9016 | (flags & SCROLLBARS_STYLE_MASK) == SCROLLBARS_INSIDE_OVERLAY) { |
| 9017 | mPrivateFlags |= OPAQUE_SCROLLBARS; |
| 9018 | } else { |
| 9019 | mPrivateFlags &= ~OPAQUE_SCROLLBARS; |
| 9020 | } |
| 9021 | } |
| 9022 | |
| 9023 | /** |
| 9024 | * @hide |
| 9025 | */ |
| 9026 | protected boolean hasOpaqueScrollbars() { |
| 9027 | return (mPrivateFlags & OPAQUE_SCROLLBARS) == OPAQUE_SCROLLBARS; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 9028 | } |
| 9029 | |
| 9030 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9031 | * @return A handler associated with the thread running the View. This |
| 9032 | * handler can be used to pump events in the UI events queue. |
| 9033 | */ |
| 9034 | public Handler getHandler() { |
| 9035 | if (mAttachInfo != null) { |
| 9036 | return mAttachInfo.mHandler; |
| 9037 | } |
| 9038 | return null; |
| 9039 | } |
| 9040 | |
| 9041 | /** |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9042 | * Gets the view root associated with the View. |
| 9043 | * @return The view root, or null if none. |
| 9044 | * @hide |
| 9045 | */ |
| 9046 | public ViewRootImpl getViewRootImpl() { |
| 9047 | if (mAttachInfo != null) { |
| 9048 | return mAttachInfo.mViewRootImpl; |
| 9049 | } |
| 9050 | return null; |
| 9051 | } |
| 9052 | |
| 9053 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9054 | * <p>Causes the Runnable to be added to the message queue. |
| 9055 | * The runnable will be run on the user interface thread.</p> |
| 9056 | * |
| 9057 | * <p>This method can be invoked from outside of the UI thread |
| 9058 | * only when this View is attached to a window.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9059 | * |
| 9060 | * @param action The Runnable that will be executed. |
| 9061 | * |
| 9062 | * @return Returns true if the Runnable was successfully placed in to the |
| 9063 | * message queue. Returns false on failure, usually because the |
| 9064 | * looper processing the message queue is exiting. |
| 9065 | */ |
| 9066 | public boolean post(Runnable action) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9067 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 9068 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9069 | return attachInfo.mHandler.post(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9070 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9071 | // Assume that post will succeed later |
| 9072 | ViewRootImpl.getRunQueue().post(action); |
| 9073 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9074 | } |
| 9075 | |
| 9076 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9077 | * <p>Causes the Runnable to be added to the message queue, to be run |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9078 | * after the specified amount of time elapses. |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9079 | * The runnable will be run on the user interface thread.</p> |
| 9080 | * |
| 9081 | * <p>This method can be invoked from outside of the UI thread |
| 9082 | * only when this View is attached to a window.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9083 | * |
| 9084 | * @param action The Runnable that will be executed. |
| 9085 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 9086 | * will be executed. |
| 9087 | * |
| 9088 | * @return true if the Runnable was successfully placed in to the |
| 9089 | * message queue. Returns false on failure, usually because the |
| 9090 | * looper processing the message queue is exiting. Note that a |
| 9091 | * result of true does not mean the Runnable will be processed -- |
| 9092 | * if the looper is quit before the delivery time of the message |
| 9093 | * occurs then the message will be dropped. |
| 9094 | */ |
| 9095 | public boolean postDelayed(Runnable action, long delayMillis) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9096 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 9097 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9098 | return attachInfo.mHandler.postDelayed(action, delayMillis); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9099 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9100 | // Assume that post will succeed later |
| 9101 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
| 9102 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9103 | } |
| 9104 | |
| 9105 | /** |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 9106 | * <p>Causes the Runnable to execute on the next animation time step. |
| 9107 | * The runnable will be run on the user interface thread.</p> |
| 9108 | * |
| 9109 | * <p>This method can be invoked from outside of the UI thread |
| 9110 | * only when this View is attached to a window.</p> |
| 9111 | * |
| 9112 | * @param action The Runnable that will be executed. |
| 9113 | * |
| 9114 | * @hide |
| 9115 | */ |
| 9116 | public void postOnAnimation(Runnable action) { |
| 9117 | final AttachInfo attachInfo = mAttachInfo; |
| 9118 | if (attachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 9119 | attachInfo.mViewRootImpl.mChoreographer.postCallback( |
| 9120 | Choreographer.CALLBACK_ANIMATION, action, null); |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 9121 | } else { |
| 9122 | // Assume that post will succeed later |
| 9123 | ViewRootImpl.getRunQueue().post(action); |
| 9124 | } |
| 9125 | } |
| 9126 | |
| 9127 | /** |
| 9128 | * <p>Causes the Runnable to execute on the next animation time step, |
| 9129 | * after the specified amount of time elapses. |
| 9130 | * The runnable will be run on the user interface thread.</p> |
| 9131 | * |
| 9132 | * <p>This method can be invoked from outside of the UI thread |
| 9133 | * only when this View is attached to a window.</p> |
| 9134 | * |
| 9135 | * @param action The Runnable that will be executed. |
| 9136 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 9137 | * will be executed. |
| 9138 | * |
| 9139 | * @hide |
| 9140 | */ |
| 9141 | public void postOnAnimationDelayed(Runnable action, long delayMillis) { |
| 9142 | final AttachInfo attachInfo = mAttachInfo; |
| 9143 | if (attachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 9144 | attachInfo.mViewRootImpl.mChoreographer.postCallbackDelayed( |
| 9145 | Choreographer.CALLBACK_ANIMATION, action, null, delayMillis); |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 9146 | } else { |
| 9147 | // Assume that post will succeed later |
| 9148 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
| 9149 | } |
| 9150 | } |
| 9151 | |
| 9152 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9153 | * <p>Removes the specified Runnable from the message queue.</p> |
| 9154 | * |
| 9155 | * <p>This method can be invoked from outside of the UI thread |
| 9156 | * only when this View is attached to a window.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9157 | * |
| 9158 | * @param action The Runnable to remove from the message handling queue |
| 9159 | * |
| 9160 | * @return true if this view could ask the Handler to remove the Runnable, |
| 9161 | * false otherwise. When the returned value is true, the Runnable |
| 9162 | * may or may not have been actually removed from the message queue |
| 9163 | * (for instance, if the Runnable was not in the queue already.) |
| 9164 | */ |
| 9165 | public boolean removeCallbacks(Runnable action) { |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 9166 | if (action != null) { |
| 9167 | final AttachInfo attachInfo = mAttachInfo; |
| 9168 | if (attachInfo != null) { |
| 9169 | attachInfo.mHandler.removeCallbacks(action); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 9170 | attachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 9171 | Choreographer.CALLBACK_ANIMATION, action, null); |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 9172 | } else { |
| 9173 | // Assume that post will succeed later |
| 9174 | ViewRootImpl.getRunQueue().removeCallbacks(action); |
| 9175 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9176 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9177 | return true; |
| 9178 | } |
| 9179 | |
| 9180 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9181 | * <p>Cause an invalidate to happen on a subsequent cycle through the event loop. |
| 9182 | * Use this to invalidate the View from a non-UI thread.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9183 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9184 | * <p>This method can be invoked from outside of the UI thread |
| 9185 | * only when this View is attached to a window.</p> |
| 9186 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9187 | * @see #invalidate() |
| 9188 | */ |
| 9189 | public void postInvalidate() { |
| 9190 | postInvalidateDelayed(0); |
| 9191 | } |
| 9192 | |
| 9193 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9194 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 9195 | * through the event loop. Use this to invalidate the View from a non-UI thread.</p> |
| 9196 | * |
| 9197 | * <p>This method can be invoked from outside of the UI thread |
| 9198 | * only when this View is attached to a window.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9199 | * |
| 9200 | * @param left The left coordinate of the rectangle to invalidate. |
| 9201 | * @param top The top coordinate of the rectangle to invalidate. |
| 9202 | * @param right The right coordinate of the rectangle to invalidate. |
| 9203 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 9204 | * |
| 9205 | * @see #invalidate(int, int, int, int) |
| 9206 | * @see #invalidate(Rect) |
| 9207 | */ |
| 9208 | public void postInvalidate(int left, int top, int right, int bottom) { |
| 9209 | postInvalidateDelayed(0, left, top, right, bottom); |
| 9210 | } |
| 9211 | |
| 9212 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9213 | * <p>Cause an invalidate to happen on a subsequent cycle through the event |
| 9214 | * loop. Waits for the specified amount of time.</p> |
| 9215 | * |
| 9216 | * <p>This method can be invoked from outside of the UI thread |
| 9217 | * only when this View is attached to a window.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9218 | * |
| 9219 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 9220 | * invalidation by |
| 9221 | */ |
| 9222 | public void postInvalidateDelayed(long delayMilliseconds) { |
| 9223 | // We try only with the AttachInfo because there's no point in invalidating |
| 9224 | // if we are not attached to our window |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9225 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 9226 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9227 | attachInfo.mViewRootImpl.dispatchInvalidateDelayed(this, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9228 | } |
| 9229 | } |
| 9230 | |
| 9231 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9232 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 9233 | * through the event loop. Waits for the specified amount of time.</p> |
| 9234 | * |
| 9235 | * <p>This method can be invoked from outside of the UI thread |
| 9236 | * only when this View is attached to a window.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9237 | * |
| 9238 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 9239 | * invalidation by |
| 9240 | * @param left The left coordinate of the rectangle to invalidate. |
| 9241 | * @param top The top coordinate of the rectangle to invalidate. |
| 9242 | * @param right The right coordinate of the rectangle to invalidate. |
| 9243 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 9244 | */ |
| 9245 | public void postInvalidateDelayed(long delayMilliseconds, int left, int top, |
| 9246 | int right, int bottom) { |
| 9247 | |
| 9248 | // We try only with the AttachInfo because there's no point in invalidating |
| 9249 | // if we are not attached to our window |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9250 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 9251 | if (attachInfo != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9252 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire(); |
| 9253 | info.target = this; |
| 9254 | info.left = left; |
| 9255 | info.top = top; |
| 9256 | info.right = right; |
| 9257 | info.bottom = bottom; |
| 9258 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9259 | attachInfo.mViewRootImpl.dispatchInvalidateRectDelayed(info, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9260 | } |
| 9261 | } |
| 9262 | |
| 9263 | /** |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 9264 | * <p>Cause an invalidate to happen on the next animation time step, typically the |
| 9265 | * next display frame.</p> |
| 9266 | * |
| 9267 | * <p>This method can be invoked from outside of the UI thread |
| 9268 | * only when this View is attached to a window.</p> |
| 9269 | * |
| 9270 | * @hide |
| 9271 | */ |
| 9272 | public void postInvalidateOnAnimation() { |
| 9273 | // We try only with the AttachInfo because there's no point in invalidating |
| 9274 | // if we are not attached to our window |
| 9275 | final AttachInfo attachInfo = mAttachInfo; |
| 9276 | if (attachInfo != null) { |
| 9277 | attachInfo.mViewRootImpl.dispatchInvalidateOnAnimation(this); |
| 9278 | } |
| 9279 | } |
| 9280 | |
| 9281 | /** |
| 9282 | * <p>Cause an invalidate of the specified area to happen on the next animation |
| 9283 | * time step, typically the next display frame.</p> |
| 9284 | * |
| 9285 | * <p>This method can be invoked from outside of the UI thread |
| 9286 | * only when this View is attached to a window.</p> |
| 9287 | * |
| 9288 | * @param left The left coordinate of the rectangle to invalidate. |
| 9289 | * @param top The top coordinate of the rectangle to invalidate. |
| 9290 | * @param right The right coordinate of the rectangle to invalidate. |
| 9291 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 9292 | * |
| 9293 | * @hide |
| 9294 | */ |
| 9295 | public void postInvalidateOnAnimation(int left, int top, int right, int bottom) { |
| 9296 | // We try only with the AttachInfo because there's no point in invalidating |
| 9297 | // if we are not attached to our window |
| 9298 | final AttachInfo attachInfo = mAttachInfo; |
| 9299 | if (attachInfo != null) { |
| 9300 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire(); |
| 9301 | info.target = this; |
| 9302 | info.left = left; |
| 9303 | info.top = top; |
| 9304 | info.right = right; |
| 9305 | info.bottom = bottom; |
| 9306 | |
| 9307 | attachInfo.mViewRootImpl.dispatchInvalidateRectOnAnimation(info); |
| 9308 | } |
| 9309 | } |
| 9310 | |
| 9311 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 9312 | * Post a callback to send a {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} event. |
| 9313 | * This event is sent at most once every |
| 9314 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
| 9315 | */ |
| 9316 | private void postSendViewScrolledAccessibilityEventCallback() { |
| 9317 | if (mSendViewScrolledAccessibilityEvent == null) { |
| 9318 | mSendViewScrolledAccessibilityEvent = new SendViewScrolledAccessibilityEvent(); |
| 9319 | } |
| 9320 | if (!mSendViewScrolledAccessibilityEvent.mIsPending) { |
| 9321 | mSendViewScrolledAccessibilityEvent.mIsPending = true; |
| 9322 | postDelayed(mSendViewScrolledAccessibilityEvent, |
| 9323 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval()); |
| 9324 | } |
| 9325 | } |
| 9326 | |
| 9327 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9328 | * Called by a parent to request that a child update its values for mScrollX |
| 9329 | * and mScrollY if necessary. This will typically be done if the child is |
| 9330 | * animating a scroll using a {@link android.widget.Scroller Scroller} |
| 9331 | * object. |
| 9332 | */ |
| 9333 | public void computeScroll() { |
| 9334 | } |
| 9335 | |
| 9336 | /** |
| 9337 | * <p>Indicate whether the horizontal edges are faded when the view is |
| 9338 | * scrolled horizontally.</p> |
| 9339 | * |
| 9340 | * @return true if the horizontal edges should are faded on scroll, false |
| 9341 | * otherwise |
| 9342 | * |
| 9343 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 9344 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9345 | */ |
| 9346 | public boolean isHorizontalFadingEdgeEnabled() { |
| 9347 | return (mViewFlags & FADING_EDGE_HORIZONTAL) == FADING_EDGE_HORIZONTAL; |
| 9348 | } |
| 9349 | |
| 9350 | /** |
| 9351 | * <p>Define whether the horizontal edges should be faded when this view |
| 9352 | * is scrolled horizontally.</p> |
| 9353 | * |
| 9354 | * @param horizontalFadingEdgeEnabled true if the horizontal edges should |
| 9355 | * be faded when the view is scrolled |
| 9356 | * horizontally |
| 9357 | * |
| 9358 | * @see #isHorizontalFadingEdgeEnabled() |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 9359 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9360 | */ |
| 9361 | public void setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled) { |
| 9362 | if (isHorizontalFadingEdgeEnabled() != horizontalFadingEdgeEnabled) { |
| 9363 | if (horizontalFadingEdgeEnabled) { |
| 9364 | initScrollCache(); |
| 9365 | } |
| 9366 | |
| 9367 | mViewFlags ^= FADING_EDGE_HORIZONTAL; |
| 9368 | } |
| 9369 | } |
| 9370 | |
| 9371 | /** |
| 9372 | * <p>Indicate whether the vertical edges are faded when the view is |
| 9373 | * scrolled horizontally.</p> |
| 9374 | * |
| 9375 | * @return true if the vertical edges should are faded on scroll, false |
| 9376 | * otherwise |
| 9377 | * |
| 9378 | * @see #setVerticalFadingEdgeEnabled(boolean) |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 9379 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9380 | */ |
| 9381 | public boolean isVerticalFadingEdgeEnabled() { |
| 9382 | return (mViewFlags & FADING_EDGE_VERTICAL) == FADING_EDGE_VERTICAL; |
| 9383 | } |
| 9384 | |
| 9385 | /** |
| 9386 | * <p>Define whether the vertical edges should be faded when this view |
| 9387 | * is scrolled vertically.</p> |
| 9388 | * |
| 9389 | * @param verticalFadingEdgeEnabled true if the vertical edges should |
| 9390 | * be faded when the view is scrolled |
| 9391 | * vertically |
| 9392 | * |
| 9393 | * @see #isVerticalFadingEdgeEnabled() |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 9394 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9395 | */ |
| 9396 | public void setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled) { |
| 9397 | if (isVerticalFadingEdgeEnabled() != verticalFadingEdgeEnabled) { |
| 9398 | if (verticalFadingEdgeEnabled) { |
| 9399 | initScrollCache(); |
| 9400 | } |
| 9401 | |
| 9402 | mViewFlags ^= FADING_EDGE_VERTICAL; |
| 9403 | } |
| 9404 | } |
| 9405 | |
| 9406 | /** |
| 9407 | * Returns the strength, or intensity, of the top faded edge. The strength is |
| 9408 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 9409 | * returns 0.0 or 1.0 but no value in between. |
| 9410 | * |
| 9411 | * Subclasses should override this method to provide a smoother fade transition |
| 9412 | * when scrolling occurs. |
| 9413 | * |
| 9414 | * @return the intensity of the top fade as a float between 0.0f and 1.0f |
| 9415 | */ |
| 9416 | protected float getTopFadingEdgeStrength() { |
| 9417 | return computeVerticalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 9418 | } |
| 9419 | |
| 9420 | /** |
| 9421 | * Returns the strength, or intensity, of the bottom faded edge. The strength is |
| 9422 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 9423 | * returns 0.0 or 1.0 but no value in between. |
| 9424 | * |
| 9425 | * Subclasses should override this method to provide a smoother fade transition |
| 9426 | * when scrolling occurs. |
| 9427 | * |
| 9428 | * @return the intensity of the bottom fade as a float between 0.0f and 1.0f |
| 9429 | */ |
| 9430 | protected float getBottomFadingEdgeStrength() { |
| 9431 | return computeVerticalScrollOffset() + computeVerticalScrollExtent() < |
| 9432 | computeVerticalScrollRange() ? 1.0f : 0.0f; |
| 9433 | } |
| 9434 | |
| 9435 | /** |
| 9436 | * Returns the strength, or intensity, of the left faded edge. The strength is |
| 9437 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 9438 | * returns 0.0 or 1.0 but no value in between. |
| 9439 | * |
| 9440 | * Subclasses should override this method to provide a smoother fade transition |
| 9441 | * when scrolling occurs. |
| 9442 | * |
| 9443 | * @return the intensity of the left fade as a float between 0.0f and 1.0f |
| 9444 | */ |
| 9445 | protected float getLeftFadingEdgeStrength() { |
| 9446 | return computeHorizontalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 9447 | } |
| 9448 | |
| 9449 | /** |
| 9450 | * Returns the strength, or intensity, of the right faded edge. The strength is |
| 9451 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 9452 | * returns 0.0 or 1.0 but no value in between. |
| 9453 | * |
| 9454 | * Subclasses should override this method to provide a smoother fade transition |
| 9455 | * when scrolling occurs. |
| 9456 | * |
| 9457 | * @return the intensity of the right fade as a float between 0.0f and 1.0f |
| 9458 | */ |
| 9459 | protected float getRightFadingEdgeStrength() { |
| 9460 | return computeHorizontalScrollOffset() + computeHorizontalScrollExtent() < |
| 9461 | computeHorizontalScrollRange() ? 1.0f : 0.0f; |
| 9462 | } |
| 9463 | |
| 9464 | /** |
| 9465 | * <p>Indicate whether the horizontal scrollbar should be drawn or not. The |
| 9466 | * scrollbar is not drawn by default.</p> |
| 9467 | * |
| 9468 | * @return true if the horizontal scrollbar should be painted, false |
| 9469 | * otherwise |
| 9470 | * |
| 9471 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 9472 | */ |
| 9473 | public boolean isHorizontalScrollBarEnabled() { |
| 9474 | return (mViewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 9475 | } |
| 9476 | |
| 9477 | /** |
| 9478 | * <p>Define whether the horizontal scrollbar should be drawn or not. The |
| 9479 | * scrollbar is not drawn by default.</p> |
| 9480 | * |
| 9481 | * @param horizontalScrollBarEnabled true if the horizontal scrollbar should |
| 9482 | * be painted |
| 9483 | * |
| 9484 | * @see #isHorizontalScrollBarEnabled() |
| 9485 | */ |
| 9486 | public void setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled) { |
| 9487 | if (isHorizontalScrollBarEnabled() != horizontalScrollBarEnabled) { |
| 9488 | mViewFlags ^= SCROLLBARS_HORIZONTAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9489 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9490 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9491 | } |
| 9492 | } |
| 9493 | |
| 9494 | /** |
| 9495 | * <p>Indicate whether the vertical scrollbar should be drawn or not. The |
| 9496 | * scrollbar is not drawn by default.</p> |
| 9497 | * |
| 9498 | * @return true if the vertical scrollbar should be painted, false |
| 9499 | * otherwise |
| 9500 | * |
| 9501 | * @see #setVerticalScrollBarEnabled(boolean) |
| 9502 | */ |
| 9503 | public boolean isVerticalScrollBarEnabled() { |
| 9504 | return (mViewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL; |
| 9505 | } |
| 9506 | |
| 9507 | /** |
| 9508 | * <p>Define whether the vertical scrollbar should be drawn or not. The |
| 9509 | * scrollbar is not drawn by default.</p> |
| 9510 | * |
| 9511 | * @param verticalScrollBarEnabled true if the vertical scrollbar should |
| 9512 | * be painted |
| 9513 | * |
| 9514 | * @see #isVerticalScrollBarEnabled() |
| 9515 | */ |
| 9516 | public void setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled) { |
| 9517 | if (isVerticalScrollBarEnabled() != verticalScrollBarEnabled) { |
| 9518 | mViewFlags ^= SCROLLBARS_VERTICAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9519 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9520 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9521 | } |
| 9522 | } |
| 9523 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 9524 | /** |
| 9525 | * @hide |
| 9526 | */ |
| 9527 | protected void recomputePadding() { |
| 9528 | setPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, mUserPaddingBottom); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9529 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9530 | |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9531 | /** |
| 9532 | * Define whether scrollbars will fade when the view is not scrolling. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9533 | * |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9534 | * @param fadeScrollbars wheter to enable fading |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9535 | * |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9536 | */ |
| 9537 | public void setScrollbarFadingEnabled(boolean fadeScrollbars) { |
| 9538 | initScrollCache(); |
| 9539 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
| 9540 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9541 | if (fadeScrollbars) { |
| 9542 | scrollabilityCache.state = ScrollabilityCache.OFF; |
| 9543 | } else { |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9544 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 9545 | } |
| 9546 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9548 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9549 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9550 | * Returns true if scrollbars will fade when this view is not scrolling |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9551 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9552 | * @return true if scrollbar fading is enabled |
| 9553 | */ |
| 9554 | public boolean isScrollbarFadingEnabled() { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9555 | return mScrollCache != null && mScrollCache.fadeScrollBars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9556 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9557 | |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9558 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9559 | * <p>Specify the style of the scrollbars. The scrollbars can be overlaid or |
| 9560 | * inset. When inset, they add to the padding of the view. And the scrollbars |
| 9561 | * can be drawn inside the padding area or on the edge of the view. For example, |
| 9562 | * if a view has a background drawable and you want to draw the scrollbars |
| 9563 | * inside the padding specified by the drawable, you can use |
| 9564 | * SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to |
| 9565 | * appear at the edge of the view, ignoring the padding, then you can use |
| 9566 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.</p> |
| 9567 | * @param style the style of the scrollbars. Should be one of |
| 9568 | * SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, |
| 9569 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET. |
| 9570 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 9571 | * @see #SCROLLBARS_INSIDE_INSET |
| 9572 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 9573 | * @see #SCROLLBARS_OUTSIDE_INSET |
| 9574 | */ |
| 9575 | public void setScrollBarStyle(int style) { |
| 9576 | if (style != (mViewFlags & SCROLLBARS_STYLE_MASK)) { |
| 9577 | mViewFlags = (mViewFlags & ~SCROLLBARS_STYLE_MASK) | (style & SCROLLBARS_STYLE_MASK); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9578 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9579 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9580 | } |
| 9581 | } |
| 9582 | |
| 9583 | /** |
| 9584 | * <p>Returns the current scrollbar style.</p> |
| 9585 | * @return the current scrollbar style |
| 9586 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 9587 | * @see #SCROLLBARS_INSIDE_INSET |
| 9588 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 9589 | * @see #SCROLLBARS_OUTSIDE_INSET |
| 9590 | */ |
Jeff Sharkey | 010d7e5 | 2011-08-08 21:05:02 -0700 | [diff] [blame] | 9591 | @ViewDebug.ExportedProperty(mapping = { |
| 9592 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_OVERLAY, to = "INSIDE_OVERLAY"), |
| 9593 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_INSET, to = "INSIDE_INSET"), |
| 9594 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_OVERLAY, to = "OUTSIDE_OVERLAY"), |
| 9595 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_INSET, to = "OUTSIDE_INSET") |
| 9596 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9597 | public int getScrollBarStyle() { |
| 9598 | return mViewFlags & SCROLLBARS_STYLE_MASK; |
| 9599 | } |
| 9600 | |
| 9601 | /** |
| 9602 | * <p>Compute the horizontal range that the horizontal scrollbar |
| 9603 | * represents.</p> |
| 9604 | * |
| 9605 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9606 | * units used by {@link #computeHorizontalScrollExtent()} and |
| 9607 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 9608 | * |
| 9609 | * <p>The default range is the drawing width of this view.</p> |
| 9610 | * |
| 9611 | * @return the total horizontal range represented by the horizontal |
| 9612 | * scrollbar |
| 9613 | * |
| 9614 | * @see #computeHorizontalScrollExtent() |
| 9615 | * @see #computeHorizontalScrollOffset() |
| 9616 | * @see android.widget.ScrollBarDrawable |
| 9617 | */ |
| 9618 | protected int computeHorizontalScrollRange() { |
| 9619 | return getWidth(); |
| 9620 | } |
| 9621 | |
| 9622 | /** |
| 9623 | * <p>Compute the horizontal offset of the horizontal scrollbar's thumb |
| 9624 | * within the horizontal range. This value is used to compute the position |
| 9625 | * of the thumb within the scrollbar's track.</p> |
| 9626 | * |
| 9627 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9628 | * units used by {@link #computeHorizontalScrollRange()} and |
| 9629 | * {@link #computeHorizontalScrollExtent()}.</p> |
| 9630 | * |
| 9631 | * <p>The default offset is the scroll offset of this view.</p> |
| 9632 | * |
| 9633 | * @return the horizontal offset of the scrollbar's thumb |
| 9634 | * |
| 9635 | * @see #computeHorizontalScrollRange() |
| 9636 | * @see #computeHorizontalScrollExtent() |
| 9637 | * @see android.widget.ScrollBarDrawable |
| 9638 | */ |
| 9639 | protected int computeHorizontalScrollOffset() { |
| 9640 | return mScrollX; |
| 9641 | } |
| 9642 | |
| 9643 | /** |
| 9644 | * <p>Compute the horizontal extent of the horizontal scrollbar's thumb |
| 9645 | * within the horizontal range. This value is used to compute the length |
| 9646 | * of the thumb within the scrollbar's track.</p> |
| 9647 | * |
| 9648 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9649 | * units used by {@link #computeHorizontalScrollRange()} and |
| 9650 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 9651 | * |
| 9652 | * <p>The default extent is the drawing width of this view.</p> |
| 9653 | * |
| 9654 | * @return the horizontal extent of the scrollbar's thumb |
| 9655 | * |
| 9656 | * @see #computeHorizontalScrollRange() |
| 9657 | * @see #computeHorizontalScrollOffset() |
| 9658 | * @see android.widget.ScrollBarDrawable |
| 9659 | */ |
| 9660 | protected int computeHorizontalScrollExtent() { |
| 9661 | return getWidth(); |
| 9662 | } |
| 9663 | |
| 9664 | /** |
| 9665 | * <p>Compute the vertical range that the vertical scrollbar represents.</p> |
| 9666 | * |
| 9667 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9668 | * units used by {@link #computeVerticalScrollExtent()} and |
| 9669 | * {@link #computeVerticalScrollOffset()}.</p> |
| 9670 | * |
| 9671 | * @return the total vertical range represented by the vertical scrollbar |
| 9672 | * |
| 9673 | * <p>The default range is the drawing height of this view.</p> |
| 9674 | * |
| 9675 | * @see #computeVerticalScrollExtent() |
| 9676 | * @see #computeVerticalScrollOffset() |
| 9677 | * @see android.widget.ScrollBarDrawable |
| 9678 | */ |
| 9679 | protected int computeVerticalScrollRange() { |
| 9680 | return getHeight(); |
| 9681 | } |
| 9682 | |
| 9683 | /** |
| 9684 | * <p>Compute the vertical offset of the vertical scrollbar's thumb |
| 9685 | * within the horizontal range. This value is used to compute the position |
| 9686 | * of the thumb within the scrollbar's track.</p> |
| 9687 | * |
| 9688 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9689 | * units used by {@link #computeVerticalScrollRange()} and |
| 9690 | * {@link #computeVerticalScrollExtent()}.</p> |
| 9691 | * |
| 9692 | * <p>The default offset is the scroll offset of this view.</p> |
| 9693 | * |
| 9694 | * @return the vertical offset of the scrollbar's thumb |
| 9695 | * |
| 9696 | * @see #computeVerticalScrollRange() |
| 9697 | * @see #computeVerticalScrollExtent() |
| 9698 | * @see android.widget.ScrollBarDrawable |
| 9699 | */ |
| 9700 | protected int computeVerticalScrollOffset() { |
| 9701 | return mScrollY; |
| 9702 | } |
| 9703 | |
| 9704 | /** |
| 9705 | * <p>Compute the vertical extent of the horizontal scrollbar's thumb |
| 9706 | * within the vertical range. This value is used to compute the length |
| 9707 | * of the thumb within the scrollbar's track.</p> |
| 9708 | * |
| 9709 | * <p>The range is expressed in arbitrary units that must be the same as the |
Gilles Debunne | 5296424 | 2010-02-24 11:05:19 -0800 | [diff] [blame] | 9710 | * units used by {@link #computeVerticalScrollRange()} and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9711 | * {@link #computeVerticalScrollOffset()}.</p> |
| 9712 | * |
| 9713 | * <p>The default extent is the drawing height of this view.</p> |
| 9714 | * |
| 9715 | * @return the vertical extent of the scrollbar's thumb |
| 9716 | * |
| 9717 | * @see #computeVerticalScrollRange() |
| 9718 | * @see #computeVerticalScrollOffset() |
| 9719 | * @see android.widget.ScrollBarDrawable |
| 9720 | */ |
| 9721 | protected int computeVerticalScrollExtent() { |
| 9722 | return getHeight(); |
| 9723 | } |
| 9724 | |
| 9725 | /** |
Adam Powell | 6915944 | 2011-06-13 17:53:06 -0700 | [diff] [blame] | 9726 | * Check if this view can be scrolled horizontally in a certain direction. |
| 9727 | * |
| 9728 | * @param direction Negative to check scrolling left, positive to check scrolling right. |
| 9729 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 9730 | */ |
| 9731 | public boolean canScrollHorizontally(int direction) { |
| 9732 | final int offset = computeHorizontalScrollOffset(); |
| 9733 | final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent(); |
| 9734 | if (range == 0) return false; |
| 9735 | if (direction < 0) { |
| 9736 | return offset > 0; |
| 9737 | } else { |
| 9738 | return offset < range - 1; |
| 9739 | } |
| 9740 | } |
| 9741 | |
| 9742 | /** |
| 9743 | * Check if this view can be scrolled vertically in a certain direction. |
| 9744 | * |
| 9745 | * @param direction Negative to check scrolling up, positive to check scrolling down. |
| 9746 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 9747 | */ |
| 9748 | public boolean canScrollVertically(int direction) { |
| 9749 | final int offset = computeVerticalScrollOffset(); |
| 9750 | final int range = computeVerticalScrollRange() - computeVerticalScrollExtent(); |
| 9751 | if (range == 0) return false; |
| 9752 | if (direction < 0) { |
| 9753 | return offset > 0; |
| 9754 | } else { |
| 9755 | return offset < range - 1; |
| 9756 | } |
| 9757 | } |
| 9758 | |
| 9759 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9760 | * <p>Request the drawing of the horizontal and the vertical scrollbar. The |
| 9761 | * scrollbars are painted only if they have been awakened first.</p> |
| 9762 | * |
| 9763 | * @param canvas the canvas on which to draw the scrollbars |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9764 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9765 | * @see #awakenScrollBars(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9766 | */ |
Romain Guy | 1d5b3a6 | 2009-11-05 18:44:12 -0800 | [diff] [blame] | 9767 | protected final void onDrawScrollBars(Canvas canvas) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9768 | // scrollbars are drawn only when the animation is running |
| 9769 | final ScrollabilityCache cache = mScrollCache; |
| 9770 | if (cache != null) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9771 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9772 | int state = cache.state; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9773 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9774 | if (state == ScrollabilityCache.OFF) { |
| 9775 | return; |
| 9776 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9777 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9778 | boolean invalidate = false; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9779 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9780 | if (state == ScrollabilityCache.FADING) { |
| 9781 | // We're fading -- get our fade interpolation |
| 9782 | if (cache.interpolatorValues == null) { |
| 9783 | cache.interpolatorValues = new float[1]; |
| 9784 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9785 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9786 | float[] values = cache.interpolatorValues; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9787 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9788 | // Stops the animation if we're done |
| 9789 | if (cache.scrollBarInterpolator.timeToValues(values) == |
| 9790 | Interpolator.Result.FREEZE_END) { |
| 9791 | cache.state = ScrollabilityCache.OFF; |
| 9792 | } else { |
| 9793 | cache.scrollBar.setAlpha(Math.round(values[0])); |
| 9794 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9795 | |
| 9796 | // This will make the scroll bars inval themselves after |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9797 | // drawing. We only want this when we're fading so that |
| 9798 | // we prevent excessive redraws |
| 9799 | invalidate = true; |
| 9800 | } else { |
| 9801 | // We're just on -- but we may have been fading before so |
| 9802 | // reset alpha |
| 9803 | cache.scrollBar.setAlpha(255); |
| 9804 | } |
| 9805 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9807 | final int viewFlags = mViewFlags; |
| 9808 | |
| 9809 | final boolean drawHorizontalScrollBar = |
| 9810 | (viewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 9811 | final boolean drawVerticalScrollBar = |
| 9812 | (viewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL |
| 9813 | && !isVerticalScrollBarHidden(); |
| 9814 | |
| 9815 | if (drawVerticalScrollBar || drawHorizontalScrollBar) { |
| 9816 | final int width = mRight - mLeft; |
| 9817 | final int height = mBottom - mTop; |
| 9818 | |
| 9819 | final ScrollBarDrawable scrollBar = cache.scrollBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9820 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9821 | final int scrollX = mScrollX; |
| 9822 | final int scrollY = mScrollY; |
| 9823 | final int inside = (viewFlags & SCROLLBARS_OUTSIDE_MASK) == 0 ? ~0 : 0; |
| 9824 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9825 | int left, top, right, bottom; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9826 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9827 | if (drawHorizontalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 9828 | int size = scrollBar.getSize(false); |
| 9829 | if (size <= 0) { |
| 9830 | size = cache.scrollBarSize; |
| 9831 | } |
| 9832 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9833 | scrollBar.setParameters(computeHorizontalScrollRange(), |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9834 | computeHorizontalScrollOffset(), |
| 9835 | computeHorizontalScrollExtent(), false); |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9836 | final int verticalScrollBarGap = drawVerticalScrollBar ? |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9837 | getVerticalScrollbarWidth() : 0; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9838 | top = scrollY + height - size - (mUserPaddingBottom & inside); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9839 | left = scrollX + (mPaddingLeft & inside); |
| 9840 | right = scrollX + width - (mUserPaddingRight & inside) - verticalScrollBarGap; |
| 9841 | bottom = top + size; |
| 9842 | onDrawHorizontalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 9843 | if (invalidate) { |
| 9844 | invalidate(left, top, right, bottom); |
| 9845 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9846 | } |
| 9847 | |
| 9848 | if (drawVerticalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 9849 | int size = scrollBar.getSize(true); |
| 9850 | if (size <= 0) { |
| 9851 | size = cache.scrollBarSize; |
| 9852 | } |
| 9853 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9854 | scrollBar.setParameters(computeVerticalScrollRange(), |
| 9855 | computeVerticalScrollOffset(), |
| 9856 | computeVerticalScrollExtent(), true); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 9857 | switch (mVerticalScrollbarPosition) { |
| 9858 | default: |
| 9859 | case SCROLLBAR_POSITION_DEFAULT: |
| 9860 | case SCROLLBAR_POSITION_RIGHT: |
| 9861 | left = scrollX + width - size - (mUserPaddingRight & inside); |
| 9862 | break; |
| 9863 | case SCROLLBAR_POSITION_LEFT: |
| 9864 | left = scrollX + (mUserPaddingLeft & inside); |
| 9865 | break; |
| 9866 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9867 | top = scrollY + (mPaddingTop & inside); |
| 9868 | right = left + size; |
| 9869 | bottom = scrollY + height - (mUserPaddingBottom & inside); |
| 9870 | onDrawVerticalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 9871 | if (invalidate) { |
| 9872 | invalidate(left, top, right, bottom); |
| 9873 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9874 | } |
| 9875 | } |
| 9876 | } |
| 9877 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 9878 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9879 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 9880 | * Override this if the vertical scrollbar needs to be hidden in a subclass, like when |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9881 | * FastScroller is visible. |
| 9882 | * @return whether to temporarily hide the vertical scrollbar |
| 9883 | * @hide |
| 9884 | */ |
| 9885 | protected boolean isVerticalScrollBarHidden() { |
| 9886 | return false; |
| 9887 | } |
| 9888 | |
| 9889 | /** |
| 9890 | * <p>Draw the horizontal scrollbar if |
| 9891 | * {@link #isHorizontalScrollBarEnabled()} returns true.</p> |
| 9892 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9893 | * @param canvas the canvas on which to draw the scrollbar |
| 9894 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9895 | * |
| 9896 | * @see #isHorizontalScrollBarEnabled() |
| 9897 | * @see #computeHorizontalScrollRange() |
| 9898 | * @see #computeHorizontalScrollExtent() |
| 9899 | * @see #computeHorizontalScrollOffset() |
| 9900 | * @see android.widget.ScrollBarDrawable |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9901 | * @hide |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 9902 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 9903 | protected void onDrawHorizontalScrollBar(Canvas canvas, Drawable scrollBar, |
| 9904 | int l, int t, int r, int b) { |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 9905 | scrollBar.setBounds(l, t, r, b); |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 9906 | scrollBar.draw(canvas); |
| 9907 | } |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9908 | |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 9909 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9910 | * <p>Draw the vertical scrollbar if {@link #isVerticalScrollBarEnabled()} |
| 9911 | * returns true.</p> |
| 9912 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9913 | * @param canvas the canvas on which to draw the scrollbar |
| 9914 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9915 | * |
| 9916 | * @see #isVerticalScrollBarEnabled() |
| 9917 | * @see #computeVerticalScrollRange() |
| 9918 | * @see #computeVerticalScrollExtent() |
| 9919 | * @see #computeVerticalScrollOffset() |
| 9920 | * @see android.widget.ScrollBarDrawable |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9921 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9922 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 9923 | protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, |
| 9924 | int l, int t, int r, int b) { |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9925 | scrollBar.setBounds(l, t, r, b); |
| 9926 | scrollBar.draw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9927 | } |
| 9928 | |
| 9929 | /** |
| 9930 | * Implement this to do your drawing. |
| 9931 | * |
| 9932 | * @param canvas the canvas on which the background will be drawn |
| 9933 | */ |
| 9934 | protected void onDraw(Canvas canvas) { |
| 9935 | } |
| 9936 | |
| 9937 | /* |
| 9938 | * Caller is responsible for calling requestLayout if necessary. |
| 9939 | * (This allows addViewInLayout to not request a new layout.) |
| 9940 | */ |
| 9941 | void assignParent(ViewParent parent) { |
| 9942 | if (mParent == null) { |
| 9943 | mParent = parent; |
| 9944 | } else if (parent == null) { |
| 9945 | mParent = null; |
| 9946 | } else { |
| 9947 | throw new RuntimeException("view " + this + " being added, but" |
| 9948 | + " it already has a parent"); |
| 9949 | } |
| 9950 | } |
| 9951 | |
| 9952 | /** |
| 9953 | * This is called when the view is attached to a window. At this point it |
| 9954 | * has a Surface and will start drawing. Note that this function is |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9955 | * guaranteed to be called before {@link #onDraw(android.graphics.Canvas)}, |
| 9956 | * however it may be called any time before the first onDraw -- including |
| 9957 | * before or after {@link #onMeasure(int, int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9958 | * |
| 9959 | * @see #onDetachedFromWindow() |
| 9960 | */ |
| 9961 | protected void onAttachedToWindow() { |
| 9962 | if ((mPrivateFlags & REQUEST_TRANSPARENT_REGIONS) != 0) { |
| 9963 | mParent.requestTransparentRegion(this); |
| 9964 | } |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 9965 | if ((mPrivateFlags & AWAKEN_SCROLL_BARS_ON_ATTACH) != 0) { |
| 9966 | initialAwakenScrollBars(); |
| 9967 | mPrivateFlags &= ~AWAKEN_SCROLL_BARS_ON_ATTACH; |
| 9968 | } |
Chet Haase | a9b61ac | 2010-12-20 07:40:25 -0800 | [diff] [blame] | 9969 | jumpDrawablesToCurrentState(); |
Fabrice Di Meglio | a646145 | 2011-08-19 15:42:04 -0700 | [diff] [blame] | 9970 | // Order is important here: LayoutDirection MUST be resolved before Padding |
| 9971 | // and TextDirection |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 9972 | resolveLayoutDirection(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9973 | resolvePadding(); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 9974 | resolveTextDirection(); |
Amith Yamasani | 4503c8d | 2011-06-17 12:36:14 -0700 | [diff] [blame] | 9975 | if (isFocused()) { |
| 9976 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 9977 | imm.focusIn(this); |
| 9978 | } |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 9979 | } |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 9980 | |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 9981 | /** |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 9982 | * @see #onScreenStateChanged(int) |
| 9983 | */ |
| 9984 | void dispatchScreenStateChanged(int screenState) { |
| 9985 | onScreenStateChanged(screenState); |
| 9986 | } |
| 9987 | |
| 9988 | /** |
| 9989 | * This method is called whenever the state of the screen this view is |
| 9990 | * attached to changes. A state change will usually occurs when the screen |
| 9991 | * turns on or off (whether it happens automatically or the user does it |
| 9992 | * manually.) |
| 9993 | * |
| 9994 | * @param screenState The new state of the screen. Can be either |
| 9995 | * {@link #SCREEN_STATE_ON} or {@link #SCREEN_STATE_OFF} |
| 9996 | */ |
| 9997 | public void onScreenStateChanged(int screenState) { |
| 9998 | } |
| 9999 | |
| 10000 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10001 | * Resolve and cache the layout direction. LTR is set initially. This is implicitly supposing |
| 10002 | * that the parent directionality can and will be resolved before its children. |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10003 | * Will call {@link View#onResolvedLayoutDirectionChanged} when resolution is done. |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 10004 | */ |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10005 | public void resolveLayoutDirection() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10006 | // Clear any previous layout direction resolution |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 10007 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_MASK; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10008 | |
| 10009 | // Set resolved depending on layout direction |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 10010 | switch (getLayoutDirection()) { |
| 10011 | case LAYOUT_DIRECTION_INHERIT: |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 10012 | // If this is root view, no need to look at parent's layout dir. |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10013 | if (canResolveLayoutDirection()) { |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 10014 | ViewGroup viewGroup = ((ViewGroup) mParent); |
| 10015 | |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 10016 | if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
| 10017 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
| 10018 | } |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10019 | } else { |
| 10020 | // Nothing to do, LTR by default |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 10021 | } |
| 10022 | break; |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 10023 | case LAYOUT_DIRECTION_RTL: |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10024 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 10025 | break; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 10026 | case LAYOUT_DIRECTION_LOCALE: |
| 10027 | if(isLayoutDirectionRtl(Locale.getDefault())) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10028 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 10029 | } |
| 10030 | break; |
| 10031 | default: |
| 10032 | // Nothing to do, LTR by default |
| 10033 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10034 | |
| 10035 | // Set to resolved |
| 10036 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10037 | onResolvedLayoutDirectionChanged(); |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 10038 | // Resolve padding |
| 10039 | resolvePadding(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10040 | } |
| 10041 | |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 10042 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10043 | * Called when layout direction has been resolved. |
| 10044 | * |
| 10045 | * The default implementation does nothing. |
| 10046 | */ |
| 10047 | public void onResolvedLayoutDirectionChanged() { |
| 10048 | } |
| 10049 | |
| 10050 | /** |
| 10051 | * Resolve padding depending on layout direction. |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 10052 | */ |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 10053 | public void resolvePadding() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10054 | // If the user specified the absolute padding (either with android:padding or |
| 10055 | // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise |
| 10056 | // use the default padding or the padding from the background drawable |
| 10057 | // (stored at this point in mPadding*) |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 10058 | int resolvedLayoutDirection = getResolvedLayoutDirection(); |
| 10059 | switch (resolvedLayoutDirection) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10060 | case LAYOUT_DIRECTION_RTL: |
| 10061 | // Start user padding override Right user padding. Otherwise, if Right user |
| 10062 | // padding is not defined, use the default Right padding. If Right user padding |
| 10063 | // is defined, just use it. |
| 10064 | if (mUserPaddingStart >= 0) { |
| 10065 | mUserPaddingRight = mUserPaddingStart; |
| 10066 | } else if (mUserPaddingRight < 0) { |
| 10067 | mUserPaddingRight = mPaddingRight; |
| 10068 | } |
| 10069 | if (mUserPaddingEnd >= 0) { |
| 10070 | mUserPaddingLeft = mUserPaddingEnd; |
| 10071 | } else if (mUserPaddingLeft < 0) { |
| 10072 | mUserPaddingLeft = mPaddingLeft; |
| 10073 | } |
| 10074 | break; |
| 10075 | case LAYOUT_DIRECTION_LTR: |
| 10076 | default: |
| 10077 | // Start user padding override Left user padding. Otherwise, if Left user |
| 10078 | // padding is not defined, use the default left padding. If Left user padding |
| 10079 | // is defined, just use it. |
Fabrice Di Meglio | f3e1a93 | 2011-07-15 17:15:39 -0700 | [diff] [blame] | 10080 | if (mUserPaddingStart >= 0) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10081 | mUserPaddingLeft = mUserPaddingStart; |
| 10082 | } else if (mUserPaddingLeft < 0) { |
| 10083 | mUserPaddingLeft = mPaddingLeft; |
| 10084 | } |
Fabrice Di Meglio | f3e1a93 | 2011-07-15 17:15:39 -0700 | [diff] [blame] | 10085 | if (mUserPaddingEnd >= 0) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10086 | mUserPaddingRight = mUserPaddingEnd; |
| 10087 | } else if (mUserPaddingRight < 0) { |
| 10088 | mUserPaddingRight = mPaddingRight; |
| 10089 | } |
| 10090 | } |
| 10091 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10092 | mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom; |
| 10093 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 10094 | if(isPaddingRelative()) { |
| 10095 | setPaddingRelative(mUserPaddingStart, mPaddingTop, mUserPaddingEnd, mUserPaddingBottom); |
| 10096 | } else { |
| 10097 | recomputePadding(); |
| 10098 | } |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10099 | onPaddingChanged(resolvedLayoutDirection); |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 10100 | } |
| 10101 | |
| 10102 | /** |
| 10103 | * Resolve padding depending on the layout direction. Subclasses that care about |
| 10104 | * padding resolution should override this method. The default implementation does |
| 10105 | * nothing. |
| 10106 | * |
| 10107 | * @param layoutDirection the direction of the layout |
| 10108 | * |
Fabrice Di Meglio | e8dc07d | 2012-03-09 17:10:19 -0800 | [diff] [blame] | 10109 | * @see {@link #LAYOUT_DIRECTION_LTR} |
| 10110 | * @see {@link #LAYOUT_DIRECTION_RTL} |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 10111 | */ |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10112 | public void onPaddingChanged(int layoutDirection) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10113 | } |
| 10114 | |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 10115 | /** |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10116 | * Check if layout direction resolution can be done. |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 10117 | * |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10118 | * @return true if layout direction resolution can be done otherwise return false. |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 10119 | */ |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10120 | public boolean canResolveLayoutDirection() { |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 10121 | switch (getLayoutDirection()) { |
| 10122 | case LAYOUT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10123 | return (mParent != null) && (mParent instanceof ViewGroup); |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 10124 | default: |
| 10125 | return true; |
| 10126 | } |
| 10127 | } |
| 10128 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10129 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10130 | * Reset the resolved layout direction. Will call {@link View#onResolvedLayoutDirectionReset} |
| 10131 | * when reset is done. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10132 | */ |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10133 | public void resetResolvedLayoutDirection() { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 10134 | // Reset the current resolved bits |
| 10135 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_MASK; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10136 | onResolvedLayoutDirectionReset(); |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 10137 | // Reset also the text direction |
| 10138 | resetResolvedTextDirection(); |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 10139 | } |
| 10140 | |
| 10141 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10142 | * Called during reset of resolved layout direction. |
| 10143 | * |
| 10144 | * Subclasses need to override this method to clear cached information that depends on the |
| 10145 | * resolved layout direction, or to inform child views that inherit their layout direction. |
| 10146 | * |
| 10147 | * The default implementation does nothing. |
| 10148 | */ |
| 10149 | public void onResolvedLayoutDirectionReset() { |
| 10150 | } |
| 10151 | |
| 10152 | /** |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10153 | * Check if a Locale uses an RTL script. |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 10154 | * |
| 10155 | * @param locale Locale to check |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10156 | * @return true if the Locale uses an RTL script. |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 10157 | */ |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 10158 | protected static boolean isLayoutDirectionRtl(Locale locale) { |
Fabrice Di Meglio | 3fb824b | 2012-02-28 17:58:31 -0800 | [diff] [blame] | 10159 | return (LAYOUT_DIRECTION_RTL == LocaleUtil.getLayoutDirectionFromLocale(locale)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10160 | } |
| 10161 | |
| 10162 | /** |
| 10163 | * This is called when the view is detached from a window. At this point it |
| 10164 | * no longer has a surface for drawing. |
| 10165 | * |
| 10166 | * @see #onAttachedToWindow() |
| 10167 | */ |
| 10168 | protected void onDetachedFromWindow() { |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 10169 | mPrivateFlags &= ~CANCEL_NEXT_UP_EVENT; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10170 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 10171 | removeUnsetPressCallback(); |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 10172 | removeLongPressCallback(); |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 10173 | removePerformClickCallback(); |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 10174 | removeSendViewScrolledAccessibilityEventCallback(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10175 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10176 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10177 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 10178 | destroyLayer(false); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 10179 | |
| 10180 | if (mAttachInfo != null) { |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 10181 | if (mDisplayList != null) { |
| 10182 | mAttachInfo.mViewRootImpl.invalidateDisplayList(mDisplayList); |
| 10183 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10184 | mAttachInfo.mViewRootImpl.cancelInvalidate(this); |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 10185 | } else { |
| 10186 | if (mDisplayList != null) { |
| 10187 | // Should never happen |
| 10188 | mDisplayList.invalidate(); |
| 10189 | } |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 10190 | } |
| 10191 | |
Patrick Dubroy | ec84c3a | 2011-01-13 17:55:37 -0800 | [diff] [blame] | 10192 | mCurrentAnimation = null; |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 10193 | |
| 10194 | resetResolvedLayoutDirection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10195 | } |
| 10196 | |
| 10197 | /** |
| 10198 | * @return The number of times this view has been attached to a window |
| 10199 | */ |
| 10200 | protected int getWindowAttachCount() { |
| 10201 | return mWindowAttachCount; |
| 10202 | } |
| 10203 | |
| 10204 | /** |
| 10205 | * Retrieve a unique token identifying the window this view is attached to. |
| 10206 | * @return Return the window's token for use in |
| 10207 | * {@link WindowManager.LayoutParams#token WindowManager.LayoutParams.token}. |
| 10208 | */ |
| 10209 | public IBinder getWindowToken() { |
| 10210 | return mAttachInfo != null ? mAttachInfo.mWindowToken : null; |
| 10211 | } |
| 10212 | |
| 10213 | /** |
| 10214 | * Retrieve a unique token identifying the top-level "real" window of |
| 10215 | * the window that this view is attached to. That is, this is like |
| 10216 | * {@link #getWindowToken}, except if the window this view in is a panel |
| 10217 | * window (attached to another containing window), then the token of |
| 10218 | * the containing window is returned instead. |
| 10219 | * |
| 10220 | * @return Returns the associated window token, either |
| 10221 | * {@link #getWindowToken()} or the containing window's token. |
| 10222 | */ |
| 10223 | public IBinder getApplicationWindowToken() { |
| 10224 | AttachInfo ai = mAttachInfo; |
| 10225 | if (ai != null) { |
| 10226 | IBinder appWindowToken = ai.mPanelParentWindowToken; |
| 10227 | if (appWindowToken == null) { |
| 10228 | appWindowToken = ai.mWindowToken; |
| 10229 | } |
| 10230 | return appWindowToken; |
| 10231 | } |
| 10232 | return null; |
| 10233 | } |
| 10234 | |
| 10235 | /** |
| 10236 | * Retrieve private session object this view hierarchy is using to |
| 10237 | * communicate with the window manager. |
| 10238 | * @return the session object to communicate with the window manager |
| 10239 | */ |
| 10240 | /*package*/ IWindowSession getWindowSession() { |
| 10241 | return mAttachInfo != null ? mAttachInfo.mSession : null; |
| 10242 | } |
| 10243 | |
| 10244 | /** |
| 10245 | * @param info the {@link android.view.View.AttachInfo} to associated with |
| 10246 | * this view |
| 10247 | */ |
| 10248 | void dispatchAttachedToWindow(AttachInfo info, int visibility) { |
| 10249 | //System.out.println("Attached! " + this); |
| 10250 | mAttachInfo = info; |
| 10251 | mWindowAttachCount++; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 10252 | // We will need to evaluate the drawable state at least once. |
| 10253 | mPrivateFlags |= DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10254 | if (mFloatingTreeObserver != null) { |
| 10255 | info.mTreeObserver.merge(mFloatingTreeObserver); |
| 10256 | mFloatingTreeObserver = null; |
| 10257 | } |
| 10258 | if ((mPrivateFlags&SCROLL_CONTAINER) != 0) { |
| 10259 | mAttachInfo.mScrollContainers.add(this); |
| 10260 | mPrivateFlags |= SCROLL_CONTAINER_ADDED; |
| 10261 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 10262 | performCollectViewAttributes(mAttachInfo, visibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10263 | onAttachedToWindow(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 10264 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 10265 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 10266 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 10267 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 10268 | if (listeners != null && listeners.size() > 0) { |
| 10269 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 10270 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 10271 | // could mutate the list by calling the various add/remove methods. This prevents |
| 10272 | // the array from being modified while we iterate it. |
| 10273 | for (OnAttachStateChangeListener listener : listeners) { |
| 10274 | listener.onViewAttachedToWindow(this); |
| 10275 | } |
| 10276 | } |
| 10277 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10278 | int vis = info.mWindowVisibility; |
| 10279 | if (vis != GONE) { |
| 10280 | onWindowVisibilityChanged(vis); |
| 10281 | } |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 10282 | if ((mPrivateFlags&DRAWABLE_STATE_DIRTY) != 0) { |
| 10283 | // If nobody has evaluated the drawable state yet, then do it now. |
| 10284 | refreshDrawableState(); |
| 10285 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10286 | } |
| 10287 | |
| 10288 | void dispatchDetachedFromWindow() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10289 | AttachInfo info = mAttachInfo; |
| 10290 | if (info != null) { |
| 10291 | int vis = info.mWindowVisibility; |
| 10292 | if (vis != GONE) { |
| 10293 | onWindowVisibilityChanged(GONE); |
| 10294 | } |
| 10295 | } |
| 10296 | |
| 10297 | onDetachedFromWindow(); |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 10298 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 10299 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 10300 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 10301 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 10302 | if (listeners != null && listeners.size() > 0) { |
| 10303 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 10304 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 10305 | // could mutate the list by calling the various add/remove methods. This prevents |
| 10306 | // the array from being modified while we iterate it. |
| 10307 | for (OnAttachStateChangeListener listener : listeners) { |
| 10308 | listener.onViewDetachedFromWindow(this); |
| 10309 | } |
| 10310 | } |
| 10311 | |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 10312 | if ((mPrivateFlags & SCROLL_CONTAINER_ADDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10313 | mAttachInfo.mScrollContainers.remove(this); |
| 10314 | mPrivateFlags &= ~SCROLL_CONTAINER_ADDED; |
| 10315 | } |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 10316 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10317 | mAttachInfo = null; |
| 10318 | } |
| 10319 | |
| 10320 | /** |
| 10321 | * Store this view hierarchy's frozen state into the given container. |
| 10322 | * |
| 10323 | * @param container The SparseArray in which to save the view's state. |
| 10324 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10325 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 10326 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 10327 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10328 | */ |
| 10329 | public void saveHierarchyState(SparseArray<Parcelable> container) { |
| 10330 | dispatchSaveInstanceState(container); |
| 10331 | } |
| 10332 | |
| 10333 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10334 | * Called by {@link #saveHierarchyState(android.util.SparseArray)} to store the state for |
| 10335 | * this view and its children. May be overridden to modify how freezing happens to a |
| 10336 | * view's children; for example, some views may want to not store state for their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10337 | * |
| 10338 | * @param container The SparseArray in which to save the view's state. |
| 10339 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10340 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 10341 | * @see #saveHierarchyState(android.util.SparseArray) |
| 10342 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10343 | */ |
| 10344 | protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { |
| 10345 | if (mID != NO_ID && (mViewFlags & SAVE_DISABLED_MASK) == 0) { |
| 10346 | mPrivateFlags &= ~SAVE_STATE_CALLED; |
| 10347 | Parcelable state = onSaveInstanceState(); |
| 10348 | if ((mPrivateFlags & SAVE_STATE_CALLED) == 0) { |
| 10349 | throw new IllegalStateException( |
| 10350 | "Derived class did not call super.onSaveInstanceState()"); |
| 10351 | } |
| 10352 | if (state != null) { |
| 10353 | // Log.i("View", "Freezing #" + Integer.toHexString(mID) |
| 10354 | // + ": " + state); |
| 10355 | container.put(mID, state); |
| 10356 | } |
| 10357 | } |
| 10358 | } |
| 10359 | |
| 10360 | /** |
| 10361 | * Hook allowing a view to generate a representation of its internal state |
| 10362 | * that can later be used to create a new instance with that same state. |
| 10363 | * This state should only contain information that is not persistent or can |
| 10364 | * not be reconstructed later. For example, you will never store your |
| 10365 | * current position on screen because that will be computed again when a |
| 10366 | * new instance of the view is placed in its view hierarchy. |
| 10367 | * <p> |
| 10368 | * Some examples of things you may store here: the current cursor position |
| 10369 | * in a text view (but usually not the text itself since that is stored in a |
| 10370 | * content provider or other persistent storage), the currently selected |
| 10371 | * item in a list view. |
| 10372 | * |
| 10373 | * @return Returns a Parcelable object containing the view's current dynamic |
| 10374 | * state, or null if there is nothing interesting to save. The |
| 10375 | * default implementation returns null. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10376 | * @see #onRestoreInstanceState(android.os.Parcelable) |
| 10377 | * @see #saveHierarchyState(android.util.SparseArray) |
| 10378 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10379 | * @see #setSaveEnabled(boolean) |
| 10380 | */ |
| 10381 | protected Parcelable onSaveInstanceState() { |
| 10382 | mPrivateFlags |= SAVE_STATE_CALLED; |
| 10383 | return BaseSavedState.EMPTY_STATE; |
| 10384 | } |
| 10385 | |
| 10386 | /** |
| 10387 | * Restore this view hierarchy's frozen state from the given container. |
| 10388 | * |
| 10389 | * @param container The SparseArray which holds previously frozen states. |
| 10390 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10391 | * @see #saveHierarchyState(android.util.SparseArray) |
| 10392 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 10393 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10394 | */ |
| 10395 | public void restoreHierarchyState(SparseArray<Parcelable> container) { |
| 10396 | dispatchRestoreInstanceState(container); |
| 10397 | } |
| 10398 | |
| 10399 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10400 | * Called by {@link #restoreHierarchyState(android.util.SparseArray)} to retrieve the |
| 10401 | * state for this view and its children. May be overridden to modify how restoring |
| 10402 | * happens to a view's children; for example, some views may want to not store state |
| 10403 | * for their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10404 | * |
| 10405 | * @param container The SparseArray which holds previously saved state. |
| 10406 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10407 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 10408 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 10409 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10410 | */ |
| 10411 | protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 10412 | if (mID != NO_ID) { |
| 10413 | Parcelable state = container.get(mID); |
| 10414 | if (state != null) { |
| 10415 | // Log.i("View", "Restoreing #" + Integer.toHexString(mID) |
| 10416 | // + ": " + state); |
| 10417 | mPrivateFlags &= ~SAVE_STATE_CALLED; |
| 10418 | onRestoreInstanceState(state); |
| 10419 | if ((mPrivateFlags & SAVE_STATE_CALLED) == 0) { |
| 10420 | throw new IllegalStateException( |
| 10421 | "Derived class did not call super.onRestoreInstanceState()"); |
| 10422 | } |
| 10423 | } |
| 10424 | } |
| 10425 | } |
| 10426 | |
| 10427 | /** |
| 10428 | * Hook allowing a view to re-apply a representation of its internal state that had previously |
| 10429 | * been generated by {@link #onSaveInstanceState}. This function will never be called with a |
| 10430 | * null state. |
| 10431 | * |
| 10432 | * @param state The frozen state that had previously been returned by |
| 10433 | * {@link #onSaveInstanceState}. |
| 10434 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10435 | * @see #onSaveInstanceState() |
| 10436 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 10437 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10438 | */ |
| 10439 | protected void onRestoreInstanceState(Parcelable state) { |
| 10440 | mPrivateFlags |= SAVE_STATE_CALLED; |
| 10441 | if (state != BaseSavedState.EMPTY_STATE && state != null) { |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 10442 | throw new IllegalArgumentException("Wrong state class, expecting View State but " |
| 10443 | + "received " + state.getClass().toString() + " instead. This usually happens " |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10444 | + "when two views of different type have the same id in the same hierarchy. " |
| 10445 | + "This view's id is " + ViewDebug.resolveId(mContext, getId()) + ". Make sure " |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 10446 | + "other views do not use the same id."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10447 | } |
| 10448 | } |
| 10449 | |
| 10450 | /** |
| 10451 | * <p>Return the time at which the drawing of the view hierarchy started.</p> |
| 10452 | * |
| 10453 | * @return the drawing start time in milliseconds |
| 10454 | */ |
| 10455 | public long getDrawingTime() { |
| 10456 | return mAttachInfo != null ? mAttachInfo.mDrawingTime : 0; |
| 10457 | } |
| 10458 | |
| 10459 | /** |
| 10460 | * <p>Enables or disables the duplication of the parent's state into this view. When |
| 10461 | * duplication is enabled, this view gets its drawable state from its parent rather |
| 10462 | * than from its own internal properties.</p> |
| 10463 | * |
| 10464 | * <p>Note: in the current implementation, setting this property to true after the |
| 10465 | * view was added to a ViewGroup might have no effect at all. This property should |
| 10466 | * always be used from XML or set to true before adding this view to a ViewGroup.</p> |
| 10467 | * |
| 10468 | * <p>Note: if this view's parent addStateFromChildren property is enabled and this |
| 10469 | * property is enabled, an exception will be thrown.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10470 | * |
Gilles Debunne | fb81703 | 2011-01-13 13:52:49 -0800 | [diff] [blame] | 10471 | * <p>Note: if the child view uses and updates additionnal states which are unknown to the |
| 10472 | * parent, these states should not be affected by this method.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10473 | * |
| 10474 | * @param enabled True to enable duplication of the parent's drawable state, false |
| 10475 | * to disable it. |
| 10476 | * |
| 10477 | * @see #getDrawableState() |
| 10478 | * @see #isDuplicateParentStateEnabled() |
| 10479 | */ |
| 10480 | public void setDuplicateParentStateEnabled(boolean enabled) { |
| 10481 | setFlags(enabled ? DUPLICATE_PARENT_STATE : 0, DUPLICATE_PARENT_STATE); |
| 10482 | } |
| 10483 | |
| 10484 | /** |
| 10485 | * <p>Indicates whether this duplicates its drawable state from its parent.</p> |
| 10486 | * |
| 10487 | * @return True if this view's drawable state is duplicated from the parent, |
| 10488 | * false otherwise |
| 10489 | * |
| 10490 | * @see #getDrawableState() |
| 10491 | * @see #setDuplicateParentStateEnabled(boolean) |
| 10492 | */ |
| 10493 | public boolean isDuplicateParentStateEnabled() { |
| 10494 | return (mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE; |
| 10495 | } |
| 10496 | |
| 10497 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10498 | * <p>Specifies the type of layer backing this view. The layer can be |
| 10499 | * {@link #LAYER_TYPE_NONE disabled}, {@link #LAYER_TYPE_SOFTWARE software} or |
| 10500 | * {@link #LAYER_TYPE_HARDWARE hardware}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10501 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10502 | * <p>A layer is associated with an optional {@link android.graphics.Paint} |
| 10503 | * instance that controls how the layer is composed on screen. The following |
| 10504 | * properties of the paint are taken into account when composing the layer:</p> |
| 10505 | * <ul> |
| 10506 | * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> |
| 10507 | * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> |
| 10508 | * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> |
| 10509 | * </ul> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10510 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10511 | * <p>If this view has an alpha value set to < 1.0 by calling |
| 10512 | * {@link #setAlpha(float)}, the alpha value of the layer's paint is replaced by |
| 10513 | * this view's alpha value. Calling {@link #setAlpha(float)} is therefore |
| 10514 | * equivalent to setting a hardware layer on this view and providing a paint with |
| 10515 | * the desired alpha value.<p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10516 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10517 | * <p>Refer to the documentation of {@link #LAYER_TYPE_NONE disabled}, |
| 10518 | * {@link #LAYER_TYPE_SOFTWARE software} and {@link #LAYER_TYPE_HARDWARE hardware} |
| 10519 | * for more information on when and how to use layers.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10520 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10521 | * @param layerType The ype of layer to use with this view, must be one of |
| 10522 | * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 10523 | * {@link #LAYER_TYPE_HARDWARE} |
| 10524 | * @param paint The paint used to compose the layer. This argument is optional |
| 10525 | * and can be null. It is ignored when the layer type is |
| 10526 | * {@link #LAYER_TYPE_NONE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10527 | * |
| 10528 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10529 | * @see #LAYER_TYPE_NONE |
| 10530 | * @see #LAYER_TYPE_SOFTWARE |
| 10531 | * @see #LAYER_TYPE_HARDWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10532 | * @see #setAlpha(float) |
| 10533 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10534 | * @attr ref android.R.styleable#View_layerType |
| 10535 | */ |
| 10536 | public void setLayerType(int layerType, Paint paint) { |
| 10537 | if (layerType < LAYER_TYPE_NONE || layerType > LAYER_TYPE_HARDWARE) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10538 | throw new IllegalArgumentException("Layer type can only be one of: LAYER_TYPE_NONE, " |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10539 | + "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE"); |
| 10540 | } |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10541 | |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 10542 | if (layerType == mLayerType) { |
| 10543 | if (layerType != LAYER_TYPE_NONE && paint != mLayerPaint) { |
| 10544 | mLayerPaint = paint == null ? new Paint() : paint; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10545 | invalidateParentCaches(); |
| 10546 | invalidate(true); |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 10547 | } |
| 10548 | return; |
| 10549 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10550 | |
| 10551 | // Destroy any previous software drawing cache if needed |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10552 | switch (mLayerType) { |
Chet Haase | 6f33e81 | 2011-05-17 12:42:19 -0700 | [diff] [blame] | 10553 | case LAYER_TYPE_HARDWARE: |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 10554 | destroyLayer(false); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 10555 | // fall through - non-accelerated views may use software layer mechanism instead |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10556 | case LAYER_TYPE_SOFTWARE: |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10557 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10558 | break; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10559 | default: |
| 10560 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10561 | } |
| 10562 | |
| 10563 | mLayerType = layerType; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 10564 | final boolean layerDisabled = mLayerType == LAYER_TYPE_NONE; |
| 10565 | mLayerPaint = layerDisabled ? null : (paint == null ? new Paint() : paint); |
| 10566 | mLocalDirtyRect = layerDisabled ? null : new Rect(); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10567 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10568 | invalidateParentCaches(); |
| 10569 | invalidate(true); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10570 | } |
| 10571 | |
| 10572 | /** |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 10573 | * Indicates whether this view has a static layer. A view with layer type |
| 10574 | * {@link #LAYER_TYPE_NONE} is a static layer. Other types of layers are |
| 10575 | * dynamic. |
| 10576 | */ |
| 10577 | boolean hasStaticLayer() { |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 10578 | return true; |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 10579 | } |
| 10580 | |
| 10581 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10582 | * Indicates what type of layer is currently associated with this view. By default |
| 10583 | * a view does not have a layer, and the layer type is {@link #LAYER_TYPE_NONE}. |
| 10584 | * Refer to the documentation of {@link #setLayerType(int, android.graphics.Paint)} |
| 10585 | * for more information on the different types of layers. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10586 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10587 | * @return {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 10588 | * {@link #LAYER_TYPE_HARDWARE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10589 | * |
| 10590 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10591 | * @see #buildLayer() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10592 | * @see #LAYER_TYPE_NONE |
| 10593 | * @see #LAYER_TYPE_SOFTWARE |
| 10594 | * @see #LAYER_TYPE_HARDWARE |
| 10595 | */ |
| 10596 | public int getLayerType() { |
| 10597 | return mLayerType; |
| 10598 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10599 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10600 | /** |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10601 | * Forces this view's layer to be created and this view to be rendered |
| 10602 | * into its layer. If this view's layer type is set to {@link #LAYER_TYPE_NONE}, |
| 10603 | * invoking this method will have no effect. |
| 10604 | * |
| 10605 | * This method can for instance be used to render a view into its layer before |
| 10606 | * starting an animation. If this view is complex, rendering into the layer |
| 10607 | * before starting the animation will avoid skipping frames. |
| 10608 | * |
| 10609 | * @throws IllegalStateException If this view is not attached to a window |
| 10610 | * |
| 10611 | * @see #setLayerType(int, android.graphics.Paint) |
| 10612 | */ |
| 10613 | public void buildLayer() { |
| 10614 | if (mLayerType == LAYER_TYPE_NONE) return; |
| 10615 | |
| 10616 | if (mAttachInfo == null) { |
| 10617 | throw new IllegalStateException("This view must be attached to a window first"); |
| 10618 | } |
| 10619 | |
| 10620 | switch (mLayerType) { |
| 10621 | case LAYER_TYPE_HARDWARE: |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 10622 | if (mAttachInfo.mHardwareRenderer != null && |
| 10623 | mAttachInfo.mHardwareRenderer.isEnabled() && |
| 10624 | mAttachInfo.mHardwareRenderer.validate()) { |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 10625 | getHardwareLayer(); |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 10626 | } |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10627 | break; |
| 10628 | case LAYER_TYPE_SOFTWARE: |
| 10629 | buildDrawingCache(true); |
| 10630 | break; |
| 10631 | } |
| 10632 | } |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10633 | |
| 10634 | // Make sure the HardwareRenderer.validate() was invoked before calling this method |
| 10635 | void flushLayer() { |
| 10636 | if (mLayerType == LAYER_TYPE_HARDWARE && mHardwareLayer != null) { |
| 10637 | mHardwareLayer.flush(); |
| 10638 | } |
| 10639 | } |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10640 | |
| 10641 | /** |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10642 | * <p>Returns a hardware layer that can be used to draw this view again |
| 10643 | * without executing its draw method.</p> |
| 10644 | * |
| 10645 | * @return A HardwareLayer ready to render, or null if an error occurred. |
| 10646 | */ |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 10647 | HardwareLayer getHardwareLayer() { |
Romain Guy | ea83503 | 2011-07-28 19:24:37 -0700 | [diff] [blame] | 10648 | if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null || |
| 10649 | !mAttachInfo.mHardwareRenderer.isEnabled()) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10650 | return null; |
| 10651 | } |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10652 | |
| 10653 | if (!mAttachInfo.mHardwareRenderer.validate()) return null; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10654 | |
| 10655 | final int width = mRight - mLeft; |
| 10656 | final int height = mBottom - mTop; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10657 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10658 | if (width == 0 || height == 0) { |
| 10659 | return null; |
| 10660 | } |
| 10661 | |
| 10662 | if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || mHardwareLayer == null) { |
| 10663 | if (mHardwareLayer == null) { |
| 10664 | mHardwareLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer( |
| 10665 | width, height, isOpaque()); |
Michael Jurka | 952e02b | 2012-03-13 18:34:35 -0700 | [diff] [blame] | 10666 | mLocalDirtyRect.set(0, 0, width, height); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10667 | } else if (mHardwareLayer.getWidth() != width || mHardwareLayer.getHeight() != height) { |
| 10668 | mHardwareLayer.resize(width, height); |
Michael Jurka | 952e02b | 2012-03-13 18:34:35 -0700 | [diff] [blame] | 10669 | mLocalDirtyRect.set(0, 0, width, height); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10670 | } |
| 10671 | |
Romain Guy | 5cd5c3f | 2011-10-17 17:10:02 -0700 | [diff] [blame] | 10672 | // The layer is not valid if the underlying GPU resources cannot be allocated |
| 10673 | if (!mHardwareLayer.isValid()) { |
| 10674 | return null; |
| 10675 | } |
| 10676 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 10677 | mHardwareLayer.redraw(getHardwareLayerDisplayList(mHardwareLayer), mLocalDirtyRect); |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 10678 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10679 | } |
| 10680 | |
| 10681 | return mHardwareLayer; |
| 10682 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10683 | |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 10684 | /** |
| 10685 | * Destroys this View's hardware layer if possible. |
| 10686 | * |
| 10687 | * @return True if the layer was destroyed, false otherwise. |
| 10688 | * |
| 10689 | * @see #setLayerType(int, android.graphics.Paint) |
| 10690 | * @see #LAYER_TYPE_HARDWARE |
| 10691 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 10692 | boolean destroyLayer(boolean valid) { |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10693 | if (mHardwareLayer != null) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10694 | AttachInfo info = mAttachInfo; |
| 10695 | if (info != null && info.mHardwareRenderer != null && |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 10696 | info.mHardwareRenderer.isEnabled() && |
| 10697 | (valid || info.mHardwareRenderer.validate())) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10698 | mHardwareLayer.destroy(); |
| 10699 | mHardwareLayer = null; |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 10700 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10701 | invalidate(true); |
| 10702 | invalidateParentCaches(); |
| 10703 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 10704 | return true; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10705 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 10706 | return false; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10707 | } |
| 10708 | |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10709 | /** |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 10710 | * Destroys all hardware rendering resources. This method is invoked |
| 10711 | * when the system needs to reclaim resources. Upon execution of this |
| 10712 | * method, you should free any OpenGL resources created by the view. |
| 10713 | * |
| 10714 | * Note: you <strong>must</strong> call |
| 10715 | * <code>super.destroyHardwareResources()</code> when overriding |
| 10716 | * this method. |
| 10717 | * |
| 10718 | * @hide |
| 10719 | */ |
| 10720 | protected void destroyHardwareResources() { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 10721 | destroyLayer(true); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 10722 | } |
| 10723 | |
| 10724 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10725 | * <p>Enables or disables the drawing cache. When the drawing cache is enabled, the next call |
| 10726 | * to {@link #getDrawingCache()} or {@link #buildDrawingCache()} will draw the view in a |
| 10727 | * bitmap. Calling {@link #draw(android.graphics.Canvas)} will not draw from the cache when |
| 10728 | * the cache is enabled. To benefit from the cache, you must request the drawing cache by |
| 10729 | * calling {@link #getDrawingCache()} and draw it on screen if the returned bitmap is not |
| 10730 | * null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10731 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10732 | * <p>Enabling the drawing cache is similar to |
| 10733 | * {@link #setLayerType(int, android.graphics.Paint) setting a layer} when hardware |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10734 | * acceleration is turned off. When hardware acceleration is turned on, enabling the |
| 10735 | * drawing cache has no effect on rendering because the system uses a different mechanism |
| 10736 | * for acceleration which ignores the flag. If you want to use a Bitmap for the view, even |
| 10737 | * when hardware acceleration is enabled, see {@link #setLayerType(int, android.graphics.Paint)} |
| 10738 | * for information on how to enable software and hardware layers.</p> |
| 10739 | * |
| 10740 | * <p>This API can be used to manually generate |
| 10741 | * a bitmap copy of this view, by setting the flag to <code>true</code> and calling |
| 10742 | * {@link #getDrawingCache()}.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10743 | * |
| 10744 | * @param enabled true to enable the drawing cache, false otherwise |
| 10745 | * |
| 10746 | * @see #isDrawingCacheEnabled() |
| 10747 | * @see #getDrawingCache() |
| 10748 | * @see #buildDrawingCache() |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10749 | * @see #setLayerType(int, android.graphics.Paint) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10750 | */ |
| 10751 | public void setDrawingCacheEnabled(boolean enabled) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 10752 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10753 | setFlags(enabled ? DRAWING_CACHE_ENABLED : 0, DRAWING_CACHE_ENABLED); |
| 10754 | } |
| 10755 | |
| 10756 | /** |
| 10757 | * <p>Indicates whether the drawing cache is enabled for this view.</p> |
| 10758 | * |
| 10759 | * @return true if the drawing cache is enabled |
| 10760 | * |
| 10761 | * @see #setDrawingCacheEnabled(boolean) |
| 10762 | * @see #getDrawingCache() |
| 10763 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 10764 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10765 | public boolean isDrawingCacheEnabled() { |
| 10766 | return (mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED; |
| 10767 | } |
| 10768 | |
| 10769 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10770 | * Debugging utility which recursively outputs the dirty state of a view and its |
| 10771 | * descendants. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10772 | * |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10773 | * @hide |
| 10774 | */ |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 10775 | @SuppressWarnings({"UnusedDeclaration"}) |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10776 | public void outputDirtyFlags(String indent, boolean clear, int clearMask) { |
| 10777 | Log.d("View", indent + this + " DIRTY(" + (mPrivateFlags & View.DIRTY_MASK) + |
| 10778 | ") DRAWN(" + (mPrivateFlags & DRAWN) + ")" + " CACHE_VALID(" + |
| 10779 | (mPrivateFlags & View.DRAWING_CACHE_VALID) + |
| 10780 | ") INVALIDATED(" + (mPrivateFlags & INVALIDATED) + ")"); |
| 10781 | if (clear) { |
| 10782 | mPrivateFlags &= clearMask; |
| 10783 | } |
| 10784 | if (this instanceof ViewGroup) { |
| 10785 | ViewGroup parent = (ViewGroup) this; |
| 10786 | final int count = parent.getChildCount(); |
| 10787 | for (int i = 0; i < count; i++) { |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10788 | final View child = parent.getChildAt(i); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10789 | child.outputDirtyFlags(indent + " ", clear, clearMask); |
| 10790 | } |
| 10791 | } |
| 10792 | } |
| 10793 | |
| 10794 | /** |
| 10795 | * This method is used by ViewGroup to cause its children to restore or recreate their |
| 10796 | * display lists. It is called by getDisplayList() when the parent ViewGroup does not need |
| 10797 | * to recreate its own display list, which would happen if it went through the normal |
| 10798 | * draw/dispatchDraw mechanisms. |
| 10799 | * |
| 10800 | * @hide |
| 10801 | */ |
| 10802 | protected void dispatchGetDisplayList() {} |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 10803 | |
| 10804 | /** |
| 10805 | * A view that is not attached or hardware accelerated cannot create a display list. |
| 10806 | * This method checks these conditions and returns the appropriate result. |
| 10807 | * |
| 10808 | * @return true if view has the ability to create a display list, false otherwise. |
| 10809 | * |
| 10810 | * @hide |
| 10811 | */ |
| 10812 | public boolean canHaveDisplayList() { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 10813 | return !(mAttachInfo == null || mAttachInfo.mHardwareRenderer == null); |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 10814 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10815 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10816 | /** |
Gilles Debunne | b35ab7b | 2011-12-05 15:54:00 -0800 | [diff] [blame] | 10817 | * @return The HardwareRenderer associated with that view or null if hardware rendering |
| 10818 | * is not supported or this this has not been attached to a window. |
| 10819 | * |
| 10820 | * @hide |
| 10821 | */ |
| 10822 | public HardwareRenderer getHardwareRenderer() { |
| 10823 | if (mAttachInfo != null) { |
| 10824 | return mAttachInfo.mHardwareRenderer; |
| 10825 | } |
| 10826 | return null; |
| 10827 | } |
| 10828 | |
| 10829 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 10830 | * Returns a DisplayList. If the incoming displayList is null, one will be created. |
| 10831 | * Otherwise, the same display list will be returned (after having been rendered into |
| 10832 | * along the way, depending on the invalidation state of the view). |
| 10833 | * |
| 10834 | * @param displayList The previous version of this displayList, could be null. |
| 10835 | * @param isLayer Whether the requester of the display list is a layer. If so, |
| 10836 | * the view will avoid creating a layer inside the resulting display list. |
| 10837 | * @return A new or reused DisplayList object. |
| 10838 | */ |
| 10839 | private DisplayList getDisplayList(DisplayList displayList, boolean isLayer) { |
| 10840 | if (!canHaveDisplayList()) { |
| 10841 | return null; |
| 10842 | } |
| 10843 | |
| 10844 | if (((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || |
| 10845 | displayList == null || !displayList.isValid() || |
| 10846 | (!isLayer && mRecreateDisplayList))) { |
| 10847 | // Don't need to recreate the display list, just need to tell our |
| 10848 | // children to restore/recreate theirs |
| 10849 | if (displayList != null && displayList.isValid() && |
| 10850 | !isLayer && !mRecreateDisplayList) { |
| 10851 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 10852 | mPrivateFlags &= ~DIRTY_MASK; |
| 10853 | dispatchGetDisplayList(); |
| 10854 | |
| 10855 | return displayList; |
| 10856 | } |
| 10857 | |
| 10858 | if (!isLayer) { |
| 10859 | // If we got here, we're recreating it. Mark it as such to ensure that |
| 10860 | // we copy in child display lists into ours in drawChild() |
| 10861 | mRecreateDisplayList = true; |
| 10862 | } |
| 10863 | if (displayList == null) { |
| 10864 | final String name = getClass().getSimpleName(); |
| 10865 | displayList = mAttachInfo.mHardwareRenderer.createDisplayList(name); |
| 10866 | // If we're creating a new display list, make sure our parent gets invalidated |
| 10867 | // since they will need to recreate their display list to account for this |
| 10868 | // new child display list. |
| 10869 | invalidateParentCaches(); |
| 10870 | } |
| 10871 | |
| 10872 | boolean caching = false; |
| 10873 | final HardwareCanvas canvas = displayList.start(); |
| 10874 | int restoreCount = 0; |
| 10875 | int width = mRight - mLeft; |
| 10876 | int height = mBottom - mTop; |
| 10877 | |
| 10878 | try { |
| 10879 | canvas.setViewport(width, height); |
| 10880 | // The dirty rect should always be null for a display list |
| 10881 | canvas.onPreDraw(null); |
| 10882 | int layerType = ( |
| 10883 | !(mParent instanceof ViewGroup) || ((ViewGroup)mParent).mDrawLayers) ? |
| 10884 | getLayerType() : LAYER_TYPE_NONE; |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 10885 | if (!isLayer && layerType != LAYER_TYPE_NONE && USE_DISPLAY_LIST_PROPERTIES) { |
| 10886 | if (layerType == LAYER_TYPE_HARDWARE) { |
| 10887 | final HardwareLayer layer = getHardwareLayer(); |
| 10888 | if (layer != null && layer.isValid()) { |
| 10889 | canvas.drawHardwareLayer(layer, 0, 0, mLayerPaint); |
| 10890 | } else { |
| 10891 | canvas.saveLayer(0, 0, mRight - mLeft, mBottom - mTop, mLayerPaint, |
| 10892 | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | |
| 10893 | Canvas.CLIP_TO_LAYER_SAVE_FLAG); |
| 10894 | } |
| 10895 | caching = true; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 10896 | } else { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 10897 | buildDrawingCache(true); |
| 10898 | Bitmap cache = getDrawingCache(true); |
| 10899 | if (cache != null) { |
| 10900 | canvas.drawBitmap(cache, 0, 0, mLayerPaint); |
| 10901 | caching = true; |
| 10902 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 10903 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 10904 | } else { |
| 10905 | |
| 10906 | computeScroll(); |
| 10907 | |
| 10908 | if (!USE_DISPLAY_LIST_PROPERTIES) { |
| 10909 | restoreCount = canvas.save(); |
| 10910 | } |
| 10911 | canvas.translate(-mScrollX, -mScrollY); |
| 10912 | if (!isLayer) { |
| 10913 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 10914 | mPrivateFlags &= ~DIRTY_MASK; |
| 10915 | } |
| 10916 | |
| 10917 | // Fast path for layouts with no backgrounds |
| 10918 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 10919 | dispatchDraw(canvas); |
| 10920 | } else { |
| 10921 | draw(canvas); |
| 10922 | } |
| 10923 | } |
| 10924 | } finally { |
| 10925 | if (USE_DISPLAY_LIST_PROPERTIES) { |
| 10926 | canvas.restoreToCount(restoreCount); |
| 10927 | } |
| 10928 | canvas.onPostDraw(); |
| 10929 | |
| 10930 | displayList.end(); |
| 10931 | if (USE_DISPLAY_LIST_PROPERTIES) { |
| 10932 | displayList.setCaching(caching); |
| 10933 | } |
| 10934 | if (isLayer && USE_DISPLAY_LIST_PROPERTIES) { |
| 10935 | displayList.setLeftTopRightBottom(0, 0, width, height); |
| 10936 | } else { |
| 10937 | setDisplayListProperties(displayList); |
| 10938 | } |
| 10939 | } |
| 10940 | } else if (!isLayer) { |
| 10941 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 10942 | mPrivateFlags &= ~DIRTY_MASK; |
| 10943 | } |
| 10944 | |
| 10945 | return displayList; |
| 10946 | } |
| 10947 | |
| 10948 | /** |
| 10949 | * Get the DisplayList for the HardwareLayer |
| 10950 | * |
| 10951 | * @param layer The HardwareLayer whose DisplayList we want |
| 10952 | * @return A DisplayList fopr the specified HardwareLayer |
| 10953 | */ |
| 10954 | private DisplayList getHardwareLayerDisplayList(HardwareLayer layer) { |
| 10955 | DisplayList displayList = getDisplayList(layer.getDisplayList(), true); |
| 10956 | layer.setDisplayList(displayList); |
| 10957 | return displayList; |
| 10958 | } |
| 10959 | |
| 10960 | |
| 10961 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10962 | * <p>Returns a display list that can be used to draw this view again |
| 10963 | * without executing its draw method.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10964 | * |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10965 | * @return A DisplayList ready to replay, or null if caching is not enabled. |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10966 | * |
| 10967 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10968 | */ |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10969 | public DisplayList getDisplayList() { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 10970 | mDisplayList = getDisplayList(mDisplayList, false); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10971 | return mDisplayList; |
| 10972 | } |
| 10973 | |
| 10974 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10975 | * <p>Calling this method is equivalent to calling <code>getDrawingCache(false)</code>.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10976 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10977 | * @return A non-scaled bitmap representing this view or null if cache is disabled. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10978 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10979 | * @see #getDrawingCache(boolean) |
| 10980 | */ |
| 10981 | public Bitmap getDrawingCache() { |
| 10982 | return getDrawingCache(false); |
| 10983 | } |
| 10984 | |
| 10985 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10986 | * <p>Returns the bitmap in which this view drawing is cached. The returned bitmap |
| 10987 | * is null when caching is disabled. If caching is enabled and the cache is not ready, |
| 10988 | * this method will create it. Calling {@link #draw(android.graphics.Canvas)} will not |
| 10989 | * draw from the cache when the cache is enabled. To benefit from the cache, you must |
| 10990 | * request the drawing cache by calling this method and draw it on screen if the |
| 10991 | * returned bitmap is not null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10992 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10993 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 10994 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 10995 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 10996 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 10997 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 10998 | * size than the view. This implies that your application must be able to handle this |
| 10999 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11000 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11001 | * @param autoScale Indicates whether the generated bitmap should be scaled based on |
| 11002 | * the current density of the screen when the application is in compatibility |
| 11003 | * mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11004 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11005 | * @return A bitmap representing this view or null if cache is disabled. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11006 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11007 | * @see #setDrawingCacheEnabled(boolean) |
| 11008 | * @see #isDrawingCacheEnabled() |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11009 | * @see #buildDrawingCache(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11010 | * @see #destroyDrawingCache() |
| 11011 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11012 | public Bitmap getDrawingCache(boolean autoScale) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11013 | if ((mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING) { |
| 11014 | return null; |
| 11015 | } |
| 11016 | if ((mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11017 | buildDrawingCache(autoScale); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11018 | } |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11019 | return autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11020 | } |
| 11021 | |
| 11022 | /** |
| 11023 | * <p>Frees the resources used by the drawing cache. If you call |
| 11024 | * {@link #buildDrawingCache()} manually without calling |
| 11025 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 11026 | * should cleanup the cache with this method afterwards.</p> |
| 11027 | * |
| 11028 | * @see #setDrawingCacheEnabled(boolean) |
| 11029 | * @see #buildDrawingCache() |
| 11030 | * @see #getDrawingCache() |
| 11031 | */ |
| 11032 | public void destroyDrawingCache() { |
| 11033 | if (mDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11034 | mDrawingCache.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11035 | mDrawingCache = null; |
| 11036 | } |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11037 | if (mUnscaledDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11038 | mUnscaledDrawingCache.recycle(); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11039 | mUnscaledDrawingCache = null; |
| 11040 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11041 | } |
| 11042 | |
| 11043 | /** |
| 11044 | * Setting a solid background color for the drawing cache's bitmaps will improve |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 11045 | * performance and memory usage. Note, though that this should only be used if this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11046 | * view will always be drawn on top of a solid color. |
| 11047 | * |
| 11048 | * @param color The background color to use for the drawing cache's bitmap |
| 11049 | * |
| 11050 | * @see #setDrawingCacheEnabled(boolean) |
| 11051 | * @see #buildDrawingCache() |
| 11052 | * @see #getDrawingCache() |
| 11053 | */ |
| 11054 | public void setDrawingCacheBackgroundColor(int color) { |
Romain Guy | 52e2ef8 | 2010-01-14 12:11:48 -0800 | [diff] [blame] | 11055 | if (color != mDrawingCacheBackgroundColor) { |
| 11056 | mDrawingCacheBackgroundColor = color; |
| 11057 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 11058 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11059 | } |
| 11060 | |
| 11061 | /** |
| 11062 | * @see #setDrawingCacheBackgroundColor(int) |
| 11063 | * |
| 11064 | * @return The background color to used for the drawing cache's bitmap |
| 11065 | */ |
| 11066 | public int getDrawingCacheBackgroundColor() { |
| 11067 | return mDrawingCacheBackgroundColor; |
| 11068 | } |
| 11069 | |
| 11070 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11071 | * <p>Calling this method is equivalent to calling <code>buildDrawingCache(false)</code>.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11072 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11073 | * @see #buildDrawingCache(boolean) |
| 11074 | */ |
| 11075 | public void buildDrawingCache() { |
| 11076 | buildDrawingCache(false); |
| 11077 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 11078 | |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11079 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11080 | * <p>Forces the drawing cache to be built if the drawing cache is invalid.</p> |
| 11081 | * |
| 11082 | * <p>If you call {@link #buildDrawingCache()} manually without calling |
| 11083 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 11084 | * should cleanup the cache by calling {@link #destroyDrawingCache()} afterwards.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11085 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11086 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 11087 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 11088 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 11089 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 11090 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 11091 | * size than the view. This implies that your application must be able to handle this |
| 11092 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11093 | * |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 11094 | * <p>You should avoid calling this method when hardware acceleration is enabled. If |
| 11095 | * you do not need the drawing cache bitmap, calling this method will increase memory |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11096 | * usage and cause the view to be rendered in software once, thus negatively impacting |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 11097 | * performance.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11098 | * |
| 11099 | * @see #getDrawingCache() |
| 11100 | * @see #destroyDrawingCache() |
| 11101 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11102 | public void buildDrawingCache(boolean autoScale) { |
| 11103 | if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || (autoScale ? |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11104 | mDrawingCache == null : mUnscaledDrawingCache == null)) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 11105 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11106 | |
| 11107 | if (ViewDebug.TRACE_HIERARCHY) { |
| 11108 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.BUILD_CACHE); |
| 11109 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11110 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11111 | int width = mRight - mLeft; |
| 11112 | int height = mBottom - mTop; |
| 11113 | |
| 11114 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 11115 | final boolean scalingRequired = attachInfo != null && attachInfo.mScalingRequired; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11116 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 11117 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11118 | width = (int) ((width * attachInfo.mApplicationScale) + 0.5f); |
| 11119 | height = (int) ((height * attachInfo.mApplicationScale) + 0.5f); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11120 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11121 | |
| 11122 | final int drawingCacheBackgroundColor = mDrawingCacheBackgroundColor; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 11123 | final boolean opaque = drawingCacheBackgroundColor != 0 || isOpaque(); |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 11124 | final boolean use32BitCache = attachInfo != null && attachInfo.mUse32BitDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11125 | |
| 11126 | if (width <= 0 || height <= 0 || |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 11127 | // Projected bitmap size in bytes |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 11128 | (width * height * (opaque && !use32BitCache ? 2 : 4) > |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11129 | ViewConfiguration.get(mContext).getScaledMaximumDrawingCacheSize())) { |
| 11130 | destroyDrawingCache(); |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 11131 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11132 | return; |
| 11133 | } |
| 11134 | |
| 11135 | boolean clear = true; |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11136 | Bitmap bitmap = autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11137 | |
| 11138 | if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11139 | Bitmap.Config quality; |
| 11140 | if (!opaque) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 11141 | // Never pick ARGB_4444 because it looks awful |
| 11142 | // Keep the DRAWING_CACHE_QUALITY_LOW flag just in case |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11143 | switch (mViewFlags & DRAWING_CACHE_QUALITY_MASK) { |
| 11144 | case DRAWING_CACHE_QUALITY_AUTO: |
| 11145 | quality = Bitmap.Config.ARGB_8888; |
| 11146 | break; |
| 11147 | case DRAWING_CACHE_QUALITY_LOW: |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 11148 | quality = Bitmap.Config.ARGB_8888; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11149 | break; |
| 11150 | case DRAWING_CACHE_QUALITY_HIGH: |
| 11151 | quality = Bitmap.Config.ARGB_8888; |
| 11152 | break; |
| 11153 | default: |
| 11154 | quality = Bitmap.Config.ARGB_8888; |
| 11155 | break; |
| 11156 | } |
| 11157 | } else { |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 11158 | // Optimization for translucent windows |
| 11159 | // If the window is translucent, use a 32 bits bitmap to benefit from memcpy() |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 11160 | quality = use32BitCache ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11161 | } |
| 11162 | |
| 11163 | // Try to cleanup memory |
| 11164 | if (bitmap != null) bitmap.recycle(); |
| 11165 | |
| 11166 | try { |
| 11167 | bitmap = Bitmap.createBitmap(width, height, quality); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 11168 | bitmap.setDensity(getResources().getDisplayMetrics().densityDpi); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11169 | if (autoScale) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11170 | mDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11171 | } else { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11172 | mUnscaledDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11173 | } |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 11174 | if (opaque && use32BitCache) bitmap.setHasAlpha(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11175 | } catch (OutOfMemoryError e) { |
| 11176 | // If there is not enough memory to create the bitmap cache, just |
| 11177 | // ignore the issue as bitmap caches are not required to draw the |
| 11178 | // view hierarchy |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11179 | if (autoScale) { |
| 11180 | mDrawingCache = null; |
| 11181 | } else { |
| 11182 | mUnscaledDrawingCache = null; |
| 11183 | } |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 11184 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11185 | return; |
| 11186 | } |
| 11187 | |
| 11188 | clear = drawingCacheBackgroundColor != 0; |
| 11189 | } |
| 11190 | |
| 11191 | Canvas canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11192 | if (attachInfo != null) { |
| 11193 | canvas = attachInfo.mCanvas; |
| 11194 | if (canvas == null) { |
| 11195 | canvas = new Canvas(); |
| 11196 | } |
| 11197 | canvas.setBitmap(bitmap); |
| 11198 | // Temporarily clobber the cached Canvas in case one of our children |
| 11199 | // is also using a drawing cache. Without this, the children would |
| 11200 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 11201 | // thing would happen (invisible views, corrupted drawings, etc.) |
| 11202 | attachInfo.mCanvas = null; |
| 11203 | } else { |
| 11204 | // This case should hopefully never or seldom happen |
| 11205 | canvas = new Canvas(bitmap); |
| 11206 | } |
| 11207 | |
| 11208 | if (clear) { |
| 11209 | bitmap.eraseColor(drawingCacheBackgroundColor); |
| 11210 | } |
| 11211 | |
| 11212 | computeScroll(); |
| 11213 | final int restoreCount = canvas.save(); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11214 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 11215 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11216 | final float scale = attachInfo.mApplicationScale; |
| 11217 | canvas.scale(scale, scale); |
| 11218 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11220 | canvas.translate(-mScrollX, -mScrollY); |
| 11221 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 11222 | mPrivateFlags |= DRAWN; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11223 | if (mAttachInfo == null || !mAttachInfo.mHardwareAccelerated || |
| 11224 | mLayerType != LAYER_TYPE_NONE) { |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 11225 | mPrivateFlags |= DRAWING_CACHE_VALID; |
| 11226 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11227 | |
| 11228 | // Fast path for layouts with no backgrounds |
| 11229 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 11230 | if (ViewDebug.TRACE_HIERARCHY) { |
| 11231 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW); |
| 11232 | } |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 11233 | mPrivateFlags &= ~DIRTY_MASK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11234 | dispatchDraw(canvas); |
| 11235 | } else { |
| 11236 | draw(canvas); |
| 11237 | } |
| 11238 | |
| 11239 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 11240 | canvas.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11241 | |
| 11242 | if (attachInfo != null) { |
| 11243 | // Restore the cached Canvas for our siblings |
| 11244 | attachInfo.mCanvas = canvas; |
| 11245 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11246 | } |
| 11247 | } |
| 11248 | |
| 11249 | /** |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11250 | * Create a snapshot of the view into a bitmap. We should probably make |
| 11251 | * some form of this public, but should think about the API. |
| 11252 | */ |
Romain Guy | 223ff5c | 2010-03-02 17:07:47 -0800 | [diff] [blame] | 11253 | Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipChildren) { |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 11254 | int width = mRight - mLeft; |
| 11255 | int height = mBottom - mTop; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11256 | |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 11257 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 11258 | final float scale = attachInfo != null ? attachInfo.mApplicationScale : 1.0f; |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 11259 | width = (int) ((width * scale) + 0.5f); |
| 11260 | height = (int) ((height * scale) + 0.5f); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11261 | |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 11262 | Bitmap bitmap = Bitmap.createBitmap(width > 0 ? width : 1, height > 0 ? height : 1, quality); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11263 | if (bitmap == null) { |
| 11264 | throw new OutOfMemoryError(); |
| 11265 | } |
| 11266 | |
Romain Guy | c529d8d | 2011-09-06 15:01:39 -0700 | [diff] [blame] | 11267 | Resources resources = getResources(); |
| 11268 | if (resources != null) { |
| 11269 | bitmap.setDensity(resources.getDisplayMetrics().densityDpi); |
| 11270 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11271 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11272 | Canvas canvas; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11273 | if (attachInfo != null) { |
| 11274 | canvas = attachInfo.mCanvas; |
| 11275 | if (canvas == null) { |
| 11276 | canvas = new Canvas(); |
| 11277 | } |
| 11278 | canvas.setBitmap(bitmap); |
| 11279 | // Temporarily clobber the cached Canvas in case one of our children |
| 11280 | // is also using a drawing cache. Without this, the children would |
| 11281 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 11282 | // things would happen (invisible views, corrupted drawings, etc.) |
| 11283 | attachInfo.mCanvas = null; |
| 11284 | } else { |
| 11285 | // This case should hopefully never or seldom happen |
| 11286 | canvas = new Canvas(bitmap); |
| 11287 | } |
| 11288 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 11289 | if ((backgroundColor & 0xff000000) != 0) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11290 | bitmap.eraseColor(backgroundColor); |
| 11291 | } |
| 11292 | |
| 11293 | computeScroll(); |
| 11294 | final int restoreCount = canvas.save(); |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 11295 | canvas.scale(scale, scale); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11296 | canvas.translate(-mScrollX, -mScrollY); |
| 11297 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 11298 | // Temporarily remove the dirty mask |
| 11299 | int flags = mPrivateFlags; |
| 11300 | mPrivateFlags &= ~DIRTY_MASK; |
| 11301 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11302 | // Fast path for layouts with no backgrounds |
| 11303 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 11304 | dispatchDraw(canvas); |
| 11305 | } else { |
| 11306 | draw(canvas); |
| 11307 | } |
| 11308 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 11309 | mPrivateFlags = flags; |
| 11310 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11311 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 11312 | canvas.setBitmap(null); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11313 | |
| 11314 | if (attachInfo != null) { |
| 11315 | // Restore the cached Canvas for our siblings |
| 11316 | attachInfo.mCanvas = canvas; |
| 11317 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11318 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11319 | return bitmap; |
| 11320 | } |
| 11321 | |
| 11322 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11323 | * Indicates whether this View is currently in edit mode. A View is usually |
| 11324 | * in edit mode when displayed within a developer tool. For instance, if |
| 11325 | * this View is being drawn by a visual user interface builder, this method |
| 11326 | * should return true. |
| 11327 | * |
| 11328 | * Subclasses should check the return value of this method to provide |
| 11329 | * different behaviors if their normal behavior might interfere with the |
| 11330 | * host environment. For instance: the class spawns a thread in its |
| 11331 | * constructor, the drawing code relies on device-specific features, etc. |
| 11332 | * |
| 11333 | * This method is usually checked in the drawing code of custom widgets. |
| 11334 | * |
| 11335 | * @return True if this View is in edit mode, false otherwise. |
| 11336 | */ |
| 11337 | public boolean isInEditMode() { |
| 11338 | return false; |
| 11339 | } |
| 11340 | |
| 11341 | /** |
| 11342 | * If the View draws content inside its padding and enables fading edges, |
| 11343 | * it needs to support padding offsets. Padding offsets are added to the |
| 11344 | * fading edges to extend the length of the fade so that it covers pixels |
| 11345 | * drawn inside the padding. |
| 11346 | * |
| 11347 | * Subclasses of this class should override this method if they need |
| 11348 | * to draw content inside the padding. |
| 11349 | * |
| 11350 | * @return True if padding offset must be applied, false otherwise. |
| 11351 | * |
| 11352 | * @see #getLeftPaddingOffset() |
| 11353 | * @see #getRightPaddingOffset() |
| 11354 | * @see #getTopPaddingOffset() |
| 11355 | * @see #getBottomPaddingOffset() |
| 11356 | * |
| 11357 | * @since CURRENT |
| 11358 | */ |
| 11359 | protected boolean isPaddingOffsetRequired() { |
| 11360 | return false; |
| 11361 | } |
| 11362 | |
| 11363 | /** |
| 11364 | * Amount by which to extend the left fading region. Called only when |
| 11365 | * {@link #isPaddingOffsetRequired()} returns true. |
| 11366 | * |
| 11367 | * @return The left padding offset in pixels. |
| 11368 | * |
| 11369 | * @see #isPaddingOffsetRequired() |
| 11370 | * |
| 11371 | * @since CURRENT |
| 11372 | */ |
| 11373 | protected int getLeftPaddingOffset() { |
| 11374 | return 0; |
| 11375 | } |
| 11376 | |
| 11377 | /** |
| 11378 | * Amount by which to extend the right fading region. Called only when |
| 11379 | * {@link #isPaddingOffsetRequired()} returns true. |
| 11380 | * |
| 11381 | * @return The right padding offset in pixels. |
| 11382 | * |
| 11383 | * @see #isPaddingOffsetRequired() |
| 11384 | * |
| 11385 | * @since CURRENT |
| 11386 | */ |
| 11387 | protected int getRightPaddingOffset() { |
| 11388 | return 0; |
| 11389 | } |
| 11390 | |
| 11391 | /** |
| 11392 | * Amount by which to extend the top fading region. Called only when |
| 11393 | * {@link #isPaddingOffsetRequired()} returns true. |
| 11394 | * |
| 11395 | * @return The top padding offset in pixels. |
| 11396 | * |
| 11397 | * @see #isPaddingOffsetRequired() |
| 11398 | * |
| 11399 | * @since CURRENT |
| 11400 | */ |
| 11401 | protected int getTopPaddingOffset() { |
| 11402 | return 0; |
| 11403 | } |
| 11404 | |
| 11405 | /** |
| 11406 | * Amount by which to extend the bottom fading region. Called only when |
| 11407 | * {@link #isPaddingOffsetRequired()} returns true. |
| 11408 | * |
| 11409 | * @return The bottom padding offset in pixels. |
| 11410 | * |
| 11411 | * @see #isPaddingOffsetRequired() |
| 11412 | * |
| 11413 | * @since CURRENT |
| 11414 | */ |
| 11415 | protected int getBottomPaddingOffset() { |
| 11416 | return 0; |
| 11417 | } |
| 11418 | |
| 11419 | /** |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 11420 | * @hide |
| 11421 | * @param offsetRequired |
| 11422 | */ |
| 11423 | protected int getFadeTop(boolean offsetRequired) { |
| 11424 | int top = mPaddingTop; |
| 11425 | if (offsetRequired) top += getTopPaddingOffset(); |
| 11426 | return top; |
| 11427 | } |
| 11428 | |
| 11429 | /** |
| 11430 | * @hide |
| 11431 | * @param offsetRequired |
| 11432 | */ |
| 11433 | protected int getFadeHeight(boolean offsetRequired) { |
| 11434 | int padding = mPaddingTop; |
| 11435 | if (offsetRequired) padding += getTopPaddingOffset(); |
| 11436 | return mBottom - mTop - mPaddingBottom - padding; |
| 11437 | } |
| 11438 | |
| 11439 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 11440 | * <p>Indicates whether this view is attached to a hardware accelerated |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 11441 | * window or not.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11442 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 11443 | * <p>Even if this method returns true, it does not mean that every call |
| 11444 | * to {@link #draw(android.graphics.Canvas)} will be made with an hardware |
| 11445 | * accelerated {@link android.graphics.Canvas}. For instance, if this view |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 11446 | * is drawn onto an offscreen {@link android.graphics.Bitmap} and its |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 11447 | * window is hardware accelerated, |
| 11448 | * {@link android.graphics.Canvas#isHardwareAccelerated()} will likely |
| 11449 | * return false, and this method will return true.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11450 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 11451 | * @return True if the view is attached to a window and the window is |
| 11452 | * hardware accelerated; false in any other case. |
| 11453 | */ |
| 11454 | public boolean isHardwareAccelerated() { |
| 11455 | return mAttachInfo != null && mAttachInfo.mHardwareAccelerated; |
| 11456 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11457 | |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 11458 | /** |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11459 | * Utility function, called by draw(canvas, parent, drawingTime) to handle the less common |
| 11460 | * case of an active Animation being run on the view. |
| 11461 | */ |
| 11462 | private boolean drawAnimation(ViewGroup parent, long drawingTime, |
| 11463 | Animation a, boolean scalingRequired) { |
| 11464 | Transformation invalidationTransform; |
| 11465 | final int flags = parent.mGroupFlags; |
| 11466 | final boolean initialized = a.isInitialized(); |
| 11467 | if (!initialized) { |
| 11468 | a.initialize(mRight - mLeft, mBottom - mTop, getWidth(), getHeight()); |
| 11469 | a.initializeInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop); |
| 11470 | onAnimationStart(); |
| 11471 | } |
| 11472 | |
| 11473 | boolean more = a.getTransformation(drawingTime, parent.mChildTransformation, 1f); |
| 11474 | if (scalingRequired && mAttachInfo.mApplicationScale != 1f) { |
| 11475 | if (parent.mInvalidationTransformation == null) { |
| 11476 | parent.mInvalidationTransformation = new Transformation(); |
| 11477 | } |
| 11478 | invalidationTransform = parent.mInvalidationTransformation; |
| 11479 | a.getTransformation(drawingTime, invalidationTransform, 1f); |
| 11480 | } else { |
| 11481 | invalidationTransform = parent.mChildTransformation; |
| 11482 | } |
| 11483 | if (more) { |
| 11484 | if (!a.willChangeBounds()) { |
| 11485 | if ((flags & (parent.FLAG_OPTIMIZE_INVALIDATE | parent.FLAG_ANIMATION_DONE)) == |
| 11486 | parent.FLAG_OPTIMIZE_INVALIDATE) { |
| 11487 | parent.mGroupFlags |= parent.FLAG_INVALIDATE_REQUIRED; |
| 11488 | } else if ((flags & parent.FLAG_INVALIDATE_REQUIRED) == 0) { |
| 11489 | // The child need to draw an animation, potentially offscreen, so |
| 11490 | // make sure we do not cancel invalidate requests |
| 11491 | parent.mPrivateFlags |= DRAW_ANIMATION; |
| 11492 | parent.invalidate(mLeft, mTop, mRight, mBottom); |
| 11493 | } |
| 11494 | } else { |
| 11495 | if (parent.mInvalidateRegion == null) { |
| 11496 | parent.mInvalidateRegion = new RectF(); |
| 11497 | } |
| 11498 | final RectF region = parent.mInvalidateRegion; |
| 11499 | a.getInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop, region, |
| 11500 | invalidationTransform); |
| 11501 | |
| 11502 | // The child need to draw an animation, potentially offscreen, so |
| 11503 | // make sure we do not cancel invalidate requests |
| 11504 | parent.mPrivateFlags |= DRAW_ANIMATION; |
| 11505 | |
| 11506 | final int left = mLeft + (int) region.left; |
| 11507 | final int top = mTop + (int) region.top; |
| 11508 | parent.invalidate(left, top, left + (int) (region.width() + .5f), |
| 11509 | top + (int) (region.height() + .5f)); |
| 11510 | } |
| 11511 | } |
| 11512 | return more; |
| 11513 | } |
| 11514 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11515 | void setDisplayListProperties() { |
| 11516 | setDisplayListProperties(mDisplayList); |
| 11517 | } |
| 11518 | |
| 11519 | /** |
| 11520 | * This method is called by getDisplayList() when a display list is created or re-rendered. |
| 11521 | * It sets or resets the current value of all properties on that display list (resetting is |
| 11522 | * necessary when a display list is being re-created, because we need to make sure that |
| 11523 | * previously-set transform values |
| 11524 | */ |
| 11525 | void setDisplayListProperties(DisplayList displayList) { |
| 11526 | if (USE_DISPLAY_LIST_PROPERTIES && displayList != null) { |
| 11527 | displayList.setLeftTopRightBottom(mLeft, mTop, mRight, mBottom); |
| 11528 | if (mParent instanceof ViewGroup) { |
| 11529 | displayList.setClipChildren( |
| 11530 | (((ViewGroup)mParent).mGroupFlags & ViewGroup.FLAG_CLIP_CHILDREN) != 0); |
| 11531 | } |
| 11532 | if (mAttachInfo != null && mAttachInfo.mScalingRequired && |
| 11533 | mAttachInfo.mApplicationScale != 1.0f) { |
| 11534 | displayList.setApplicationScale(1f / mAttachInfo.mApplicationScale); |
| 11535 | } |
| 11536 | if (mTransformationInfo != null) { |
| 11537 | displayList.setTransformationInfo(mTransformationInfo.mAlpha, |
| 11538 | mTransformationInfo.mTranslationX, mTransformationInfo.mTranslationY, |
| 11539 | mTransformationInfo.mRotation, mTransformationInfo.mRotationX, |
| 11540 | mTransformationInfo.mRotationY, mTransformationInfo.mScaleX, |
| 11541 | mTransformationInfo.mScaleY); |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 11542 | if (mTransformationInfo.mCamera == null) { |
| 11543 | mTransformationInfo.mCamera = new Camera(); |
| 11544 | mTransformationInfo.matrix3D = new Matrix(); |
| 11545 | } |
| 11546 | displayList.setCameraDistance(mTransformationInfo.mCamera.getLocationZ()); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11547 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == PIVOT_EXPLICITLY_SET) { |
| 11548 | displayList.setPivotX(getPivotX()); |
| 11549 | displayList.setPivotY(getPivotY()); |
| 11550 | } |
| 11551 | } |
| 11552 | } |
| 11553 | } |
| 11554 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11555 | /** |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11556 | * This method is called by ViewGroup.drawChild() to have each child view draw itself. |
| 11557 | * This draw() method is an implementation detail and is not intended to be overridden or |
| 11558 | * to be called from anywhere else other than ViewGroup.drawChild(). |
| 11559 | */ |
| 11560 | boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11561 | boolean useDisplayListProperties = USE_DISPLAY_LIST_PROPERTIES && mAttachInfo != null && |
| 11562 | mAttachInfo.mHardwareAccelerated; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11563 | boolean more = false; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11564 | final boolean childHasIdentityMatrix = hasIdentityMatrix(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11565 | final int flags = parent.mGroupFlags; |
| 11566 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11567 | if ((flags & ViewGroup.FLAG_CLEAR_TRANSFORMATION) == ViewGroup.FLAG_CLEAR_TRANSFORMATION) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11568 | parent.mChildTransformation.clear(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11569 | parent.mGroupFlags &= ~ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11570 | } |
| 11571 | |
| 11572 | Transformation transformToApply = null; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11573 | boolean concatMatrix = false; |
| 11574 | |
| 11575 | boolean scalingRequired = false; |
| 11576 | boolean caching; |
| 11577 | int layerType = parent.mDrawLayers ? getLayerType() : LAYER_TYPE_NONE; |
| 11578 | |
| 11579 | final boolean hardwareAccelerated = canvas.isHardwareAccelerated(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11580 | if ((flags & ViewGroup.FLAG_CHILDREN_DRAWN_WITH_CACHE) != 0 || |
| 11581 | (flags & ViewGroup.FLAG_ALWAYS_DRAWN_WITH_CACHE) != 0) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11582 | caching = true; |
| 11583 | if (mAttachInfo != null) scalingRequired = mAttachInfo.mScalingRequired; |
| 11584 | } else { |
| 11585 | caching = (layerType != LAYER_TYPE_NONE) || hardwareAccelerated; |
| 11586 | } |
| 11587 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11588 | final Animation a = getAnimation(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11589 | if (a != null) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11590 | more = drawAnimation(parent, drawingTime, a, scalingRequired); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11591 | concatMatrix = a.willChangeTransformationMatrix(); |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11592 | transformToApply = parent.mChildTransformation; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11593 | } else if ((flags & ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11594 | final boolean hasTransform = |
| 11595 | parent.getChildStaticTransformation(this, parent.mChildTransformation); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11596 | if (hasTransform) { |
| 11597 | final int transformType = parent.mChildTransformation.getTransformationType(); |
| 11598 | transformToApply = transformType != Transformation.TYPE_IDENTITY ? |
| 11599 | parent.mChildTransformation : null; |
| 11600 | concatMatrix = (transformType & Transformation.TYPE_MATRIX) != 0; |
| 11601 | } |
| 11602 | } |
| 11603 | |
| 11604 | concatMatrix |= !childHasIdentityMatrix; |
| 11605 | |
| 11606 | // Sets the flag as early as possible to allow draw() implementations |
| 11607 | // to call invalidate() successfully when doing animations |
| 11608 | mPrivateFlags |= DRAWN; |
| 11609 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11610 | if (!concatMatrix && canvas.quickReject(mLeft, mTop, mRight, mBottom, Canvas.EdgeType.BW) && |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11611 | (mPrivateFlags & DRAW_ANIMATION) == 0) { |
| 11612 | return more; |
| 11613 | } |
| 11614 | |
| 11615 | if (hardwareAccelerated) { |
| 11616 | // Clear INVALIDATED flag to allow invalidation to occur during rendering, but |
| 11617 | // retain the flag's value temporarily in the mRecreateDisplayList flag |
| 11618 | mRecreateDisplayList = (mPrivateFlags & INVALIDATED) == INVALIDATED; |
| 11619 | mPrivateFlags &= ~INVALIDATED; |
| 11620 | } |
| 11621 | |
| 11622 | computeScroll(); |
| 11623 | |
| 11624 | final int sx = mScrollX; |
| 11625 | final int sy = mScrollY; |
| 11626 | |
| 11627 | DisplayList displayList = null; |
| 11628 | Bitmap cache = null; |
| 11629 | boolean hasDisplayList = false; |
| 11630 | if (caching) { |
| 11631 | if (!hardwareAccelerated) { |
| 11632 | if (layerType != LAYER_TYPE_NONE) { |
| 11633 | layerType = LAYER_TYPE_SOFTWARE; |
| 11634 | buildDrawingCache(true); |
| 11635 | } |
| 11636 | cache = getDrawingCache(true); |
| 11637 | } else { |
| 11638 | switch (layerType) { |
| 11639 | case LAYER_TYPE_SOFTWARE: |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 11640 | if (useDisplayListProperties) { |
| 11641 | hasDisplayList = canHaveDisplayList(); |
| 11642 | } else { |
| 11643 | buildDrawingCache(true); |
| 11644 | cache = getDrawingCache(true); |
| 11645 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11646 | break; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11647 | case LAYER_TYPE_HARDWARE: |
| 11648 | if (useDisplayListProperties) { |
| 11649 | hasDisplayList = canHaveDisplayList(); |
| 11650 | } |
| 11651 | break; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11652 | case LAYER_TYPE_NONE: |
| 11653 | // Delay getting the display list until animation-driven alpha values are |
| 11654 | // set up and possibly passed on to the view |
| 11655 | hasDisplayList = canHaveDisplayList(); |
| 11656 | break; |
| 11657 | } |
| 11658 | } |
| 11659 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11660 | useDisplayListProperties &= hasDisplayList; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11661 | |
| 11662 | final boolean hasNoCache = cache == null || hasDisplayList; |
| 11663 | final boolean offsetForScroll = cache == null && !hasDisplayList && |
| 11664 | layerType != LAYER_TYPE_HARDWARE; |
| 11665 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11666 | int restoreTo = -1; |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 11667 | if (!useDisplayListProperties || transformToApply != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11668 | restoreTo = canvas.save(); |
| 11669 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11670 | if (offsetForScroll) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11671 | canvas.translate(mLeft - sx, mTop - sy); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11672 | } else { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11673 | if (!useDisplayListProperties) { |
| 11674 | canvas.translate(mLeft, mTop); |
| 11675 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11676 | if (scalingRequired) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11677 | if (useDisplayListProperties) { |
| 11678 | restoreTo = canvas.save(); |
| 11679 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11680 | // mAttachInfo cannot be null, otherwise scalingRequired == false |
| 11681 | final float scale = 1.0f / mAttachInfo.mApplicationScale; |
| 11682 | canvas.scale(scale, scale); |
| 11683 | } |
| 11684 | } |
| 11685 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11686 | float alpha = useDisplayListProperties ? 1 : getAlpha(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11687 | if (transformToApply != null || alpha < 1.0f || !hasIdentityMatrix()) { |
| 11688 | if (transformToApply != null || !childHasIdentityMatrix) { |
| 11689 | int transX = 0; |
| 11690 | int transY = 0; |
| 11691 | |
| 11692 | if (offsetForScroll) { |
| 11693 | transX = -sx; |
| 11694 | transY = -sy; |
| 11695 | } |
| 11696 | |
| 11697 | if (transformToApply != null) { |
| 11698 | if (concatMatrix) { |
| 11699 | // Undo the scroll translation, apply the transformation matrix, |
| 11700 | // then redo the scroll translate to get the correct result. |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 11701 | canvas.translate(-transX, -transY); |
| 11702 | canvas.concat(transformToApply.getMatrix()); |
| 11703 | canvas.translate(transX, transY); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11704 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11705 | } |
| 11706 | |
| 11707 | float transformAlpha = transformToApply.getAlpha(); |
| 11708 | if (transformAlpha < 1.0f) { |
| 11709 | alpha *= transformToApply.getAlpha(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11710 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11711 | } |
| 11712 | } |
| 11713 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11714 | if (!childHasIdentityMatrix && !useDisplayListProperties) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11715 | canvas.translate(-transX, -transY); |
| 11716 | canvas.concat(getMatrix()); |
| 11717 | canvas.translate(transX, transY); |
| 11718 | } |
| 11719 | } |
| 11720 | |
| 11721 | if (alpha < 1.0f) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11722 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11723 | if (hasNoCache) { |
| 11724 | final int multipliedAlpha = (int) (255 * alpha); |
| 11725 | if (!onSetAlpha(multipliedAlpha)) { |
| 11726 | int layerFlags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11727 | if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) != 0 || |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11728 | layerType != LAYER_TYPE_NONE) { |
| 11729 | layerFlags |= Canvas.CLIP_TO_LAYER_SAVE_FLAG; |
| 11730 | } |
| 11731 | if (layerType == LAYER_TYPE_NONE) { |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 11732 | final int scrollX = hasDisplayList ? 0 : sx; |
| 11733 | final int scrollY = hasDisplayList ? 0 : sy; |
| 11734 | canvas.saveLayerAlpha(scrollX, scrollY, scrollX + mRight - mLeft, |
| 11735 | scrollY + mBottom - mTop, multipliedAlpha, layerFlags); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11736 | } |
| 11737 | } else { |
| 11738 | // Alpha is handled by the child directly, clobber the layer's alpha |
| 11739 | mPrivateFlags |= ALPHA_SET; |
| 11740 | } |
| 11741 | } |
| 11742 | } |
| 11743 | } else if ((mPrivateFlags & ALPHA_SET) == ALPHA_SET) { |
| 11744 | onSetAlpha(255); |
| 11745 | mPrivateFlags &= ~ALPHA_SET; |
| 11746 | } |
| 11747 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11748 | if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) == ViewGroup.FLAG_CLIP_CHILDREN && |
| 11749 | !useDisplayListProperties) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11750 | if (offsetForScroll) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11751 | canvas.clipRect(sx, sy, sx + (mRight - mLeft), sy + (mBottom - mTop)); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11752 | } else { |
| 11753 | if (!scalingRequired || cache == null) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11754 | canvas.clipRect(0, 0, mRight - mLeft, mBottom - mTop); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11755 | } else { |
| 11756 | canvas.clipRect(0, 0, cache.getWidth(), cache.getHeight()); |
| 11757 | } |
| 11758 | } |
| 11759 | } |
| 11760 | |
| 11761 | if (hasDisplayList) { |
| 11762 | displayList = getDisplayList(); |
| 11763 | if (!displayList.isValid()) { |
| 11764 | // Uncommon, but possible. If a view is removed from the hierarchy during the call |
| 11765 | // to getDisplayList(), the display list will be marked invalid and we should not |
| 11766 | // try to use it again. |
| 11767 | displayList = null; |
| 11768 | hasDisplayList = false; |
| 11769 | } |
| 11770 | } |
| 11771 | |
| 11772 | if (hasNoCache) { |
| 11773 | boolean layerRendered = false; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11774 | if (layerType == LAYER_TYPE_HARDWARE && !useDisplayListProperties) { |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 11775 | final HardwareLayer layer = getHardwareLayer(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11776 | if (layer != null && layer.isValid()) { |
| 11777 | mLayerPaint.setAlpha((int) (alpha * 255)); |
| 11778 | ((HardwareCanvas) canvas).drawHardwareLayer(layer, 0, 0, mLayerPaint); |
| 11779 | layerRendered = true; |
| 11780 | } else { |
| 11781 | final int scrollX = hasDisplayList ? 0 : sx; |
| 11782 | final int scrollY = hasDisplayList ? 0 : sy; |
| 11783 | canvas.saveLayer(scrollX, scrollY, |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11784 | scrollX + mRight - mLeft, scrollY + mBottom - mTop, mLayerPaint, |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11785 | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); |
| 11786 | } |
| 11787 | } |
| 11788 | |
| 11789 | if (!layerRendered) { |
| 11790 | if (!hasDisplayList) { |
| 11791 | // Fast path for layouts with no backgrounds |
| 11792 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 11793 | if (ViewDebug.TRACE_HIERARCHY) { |
| 11794 | ViewDebug.trace(parent, ViewDebug.HierarchyTraceType.DRAW); |
| 11795 | } |
| 11796 | mPrivateFlags &= ~DIRTY_MASK; |
| 11797 | dispatchDraw(canvas); |
| 11798 | } else { |
| 11799 | draw(canvas); |
| 11800 | } |
| 11801 | } else { |
| 11802 | mPrivateFlags &= ~DIRTY_MASK; |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11803 | ((HardwareCanvas) canvas).drawDisplayList(displayList, |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 11804 | mRight - mLeft, mBottom - mTop, null, flags); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11805 | } |
| 11806 | } |
| 11807 | } else if (cache != null) { |
| 11808 | mPrivateFlags &= ~DIRTY_MASK; |
| 11809 | Paint cachePaint; |
| 11810 | |
| 11811 | if (layerType == LAYER_TYPE_NONE) { |
| 11812 | cachePaint = parent.mCachePaint; |
| 11813 | if (cachePaint == null) { |
| 11814 | cachePaint = new Paint(); |
| 11815 | cachePaint.setDither(false); |
| 11816 | parent.mCachePaint = cachePaint; |
| 11817 | } |
| 11818 | if (alpha < 1.0f) { |
| 11819 | cachePaint.setAlpha((int) (alpha * 255)); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11820 | parent.mGroupFlags |= ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE; |
| 11821 | } else if ((flags & ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE) != 0) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11822 | cachePaint.setAlpha(255); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11823 | parent.mGroupFlags &= ~ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11824 | } |
| 11825 | } else { |
| 11826 | cachePaint = mLayerPaint; |
| 11827 | cachePaint.setAlpha((int) (alpha * 255)); |
| 11828 | } |
| 11829 | canvas.drawBitmap(cache, 0.0f, 0.0f, cachePaint); |
| 11830 | } |
| 11831 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11832 | if (restoreTo >= 0) { |
| 11833 | canvas.restoreToCount(restoreTo); |
| 11834 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11835 | |
| 11836 | if (a != null && !more) { |
| 11837 | if (!hardwareAccelerated && !a.getFillAfter()) { |
| 11838 | onSetAlpha(255); |
| 11839 | } |
| 11840 | parent.finishAnimatingView(this, a); |
| 11841 | } |
| 11842 | |
| 11843 | if (more && hardwareAccelerated) { |
| 11844 | // invalidation is the trigger to recreate display lists, so if we're using |
| 11845 | // display lists to render, force an invalidate to allow the animation to |
| 11846 | // continue drawing another frame |
| 11847 | parent.invalidate(true); |
| 11848 | if (a.hasAlpha() && (mPrivateFlags & ALPHA_SET) == ALPHA_SET) { |
| 11849 | // alpha animations should cause the child to recreate its display list |
| 11850 | invalidate(true); |
| 11851 | } |
| 11852 | } |
| 11853 | |
| 11854 | mRecreateDisplayList = false; |
| 11855 | |
| 11856 | return more; |
| 11857 | } |
| 11858 | |
| 11859 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11860 | * Manually render this view (and all of its children) to the given Canvas. |
| 11861 | * The view must have already done a full layout before this function is |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11862 | * called. When implementing a view, implement |
| 11863 | * {@link #onDraw(android.graphics.Canvas)} instead of overriding this method. |
| 11864 | * If you do need to override this method, call the superclass version. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11865 | * |
| 11866 | * @param canvas The Canvas to which the View is rendered. |
| 11867 | */ |
| 11868 | public void draw(Canvas canvas) { |
| 11869 | if (ViewDebug.TRACE_HIERARCHY) { |
| 11870 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW); |
| 11871 | } |
| 11872 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 11873 | final int privateFlags = mPrivateFlags; |
| 11874 | final boolean dirtyOpaque = (privateFlags & DIRTY_MASK) == DIRTY_OPAQUE && |
| 11875 | (mAttachInfo == null || !mAttachInfo.mIgnoreDirtyState); |
| 11876 | mPrivateFlags = (privateFlags & ~DIRTY_MASK) | DRAWN; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 11877 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11878 | /* |
| 11879 | * Draw traversal performs several drawing steps which must be executed |
| 11880 | * in the appropriate order: |
| 11881 | * |
| 11882 | * 1. Draw the background |
| 11883 | * 2. If necessary, save the canvas' layers to prepare for fading |
| 11884 | * 3. Draw view's content |
| 11885 | * 4. Draw children |
| 11886 | * 5. If necessary, draw the fading edges and restore layers |
| 11887 | * 6. Draw decorations (scrollbars for instance) |
| 11888 | */ |
| 11889 | |
| 11890 | // Step 1, draw the background, if needed |
| 11891 | int saveCount; |
| 11892 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 11893 | if (!dirtyOpaque) { |
| 11894 | final Drawable background = mBGDrawable; |
| 11895 | if (background != null) { |
| 11896 | final int scrollX = mScrollX; |
| 11897 | final int scrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11898 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 11899 | if (mBackgroundSizeChanged) { |
| 11900 | background.setBounds(0, 0, mRight - mLeft, mBottom - mTop); |
| 11901 | mBackgroundSizeChanged = false; |
| 11902 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11903 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 11904 | if ((scrollX | scrollY) == 0) { |
| 11905 | background.draw(canvas); |
| 11906 | } else { |
| 11907 | canvas.translate(scrollX, scrollY); |
| 11908 | background.draw(canvas); |
| 11909 | canvas.translate(-scrollX, -scrollY); |
| 11910 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11911 | } |
| 11912 | } |
| 11913 | |
| 11914 | // skip step 2 & 5 if possible (common case) |
| 11915 | final int viewFlags = mViewFlags; |
| 11916 | boolean horizontalEdges = (viewFlags & FADING_EDGE_HORIZONTAL) != 0; |
| 11917 | boolean verticalEdges = (viewFlags & FADING_EDGE_VERTICAL) != 0; |
| 11918 | if (!verticalEdges && !horizontalEdges) { |
| 11919 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 11920 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11921 | |
| 11922 | // Step 4, draw the children |
| 11923 | dispatchDraw(canvas); |
| 11924 | |
| 11925 | // Step 6, draw decorations (scrollbars) |
| 11926 | onDrawScrollBars(canvas); |
| 11927 | |
| 11928 | // we're done... |
| 11929 | return; |
| 11930 | } |
| 11931 | |
| 11932 | /* |
| 11933 | * Here we do the full fledged routine... |
| 11934 | * (this is an uncommon case where speed matters less, |
| 11935 | * this is why we repeat some of the tests that have been |
| 11936 | * done above) |
| 11937 | */ |
| 11938 | |
| 11939 | boolean drawTop = false; |
| 11940 | boolean drawBottom = false; |
| 11941 | boolean drawLeft = false; |
| 11942 | boolean drawRight = false; |
| 11943 | |
| 11944 | float topFadeStrength = 0.0f; |
| 11945 | float bottomFadeStrength = 0.0f; |
| 11946 | float leftFadeStrength = 0.0f; |
| 11947 | float rightFadeStrength = 0.0f; |
| 11948 | |
| 11949 | // Step 2, save the canvas' layers |
| 11950 | int paddingLeft = mPaddingLeft; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11951 | |
| 11952 | final boolean offsetRequired = isPaddingOffsetRequired(); |
| 11953 | if (offsetRequired) { |
| 11954 | paddingLeft += getLeftPaddingOffset(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11955 | } |
| 11956 | |
| 11957 | int left = mScrollX + paddingLeft; |
| 11958 | int right = left + mRight - mLeft - mPaddingRight - paddingLeft; |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 11959 | int top = mScrollY + getFadeTop(offsetRequired); |
| 11960 | int bottom = top + getFadeHeight(offsetRequired); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11961 | |
| 11962 | if (offsetRequired) { |
| 11963 | right += getRightPaddingOffset(); |
| 11964 | bottom += getBottomPaddingOffset(); |
| 11965 | } |
| 11966 | |
| 11967 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11968 | final float fadeHeight = scrollabilityCache.fadingEdgeLength; |
| 11969 | int length = (int) fadeHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11970 | |
| 11971 | // clip the fade length if top and bottom fades overlap |
| 11972 | // overlapping fades produce odd-looking artifacts |
| 11973 | if (verticalEdges && (top + length > bottom - length)) { |
| 11974 | length = (bottom - top) / 2; |
| 11975 | } |
| 11976 | |
| 11977 | // also clip horizontal fades if necessary |
| 11978 | if (horizontalEdges && (left + length > right - length)) { |
| 11979 | length = (right - left) / 2; |
| 11980 | } |
| 11981 | |
| 11982 | if (verticalEdges) { |
| 11983 | topFadeStrength = Math.max(0.0f, Math.min(1.0f, getTopFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11984 | drawTop = topFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11985 | bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, getBottomFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11986 | drawBottom = bottomFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11987 | } |
| 11988 | |
| 11989 | if (horizontalEdges) { |
| 11990 | leftFadeStrength = Math.max(0.0f, Math.min(1.0f, getLeftFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11991 | drawLeft = leftFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11992 | rightFadeStrength = Math.max(0.0f, Math.min(1.0f, getRightFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11993 | drawRight = rightFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11994 | } |
| 11995 | |
| 11996 | saveCount = canvas.getSaveCount(); |
| 11997 | |
| 11998 | int solidColor = getSolidColor(); |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 11999 | if (solidColor == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12000 | final int flags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
| 12001 | |
| 12002 | if (drawTop) { |
| 12003 | canvas.saveLayer(left, top, right, top + length, null, flags); |
| 12004 | } |
| 12005 | |
| 12006 | if (drawBottom) { |
| 12007 | canvas.saveLayer(left, bottom - length, right, bottom, null, flags); |
| 12008 | } |
| 12009 | |
| 12010 | if (drawLeft) { |
| 12011 | canvas.saveLayer(left, top, left + length, bottom, null, flags); |
| 12012 | } |
| 12013 | |
| 12014 | if (drawRight) { |
| 12015 | canvas.saveLayer(right - length, top, right, bottom, null, flags); |
| 12016 | } |
| 12017 | } else { |
| 12018 | scrollabilityCache.setFadeColor(solidColor); |
| 12019 | } |
| 12020 | |
| 12021 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12022 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12023 | |
| 12024 | // Step 4, draw the children |
| 12025 | dispatchDraw(canvas); |
| 12026 | |
| 12027 | // Step 5, draw the fade effect and restore layers |
| 12028 | final Paint p = scrollabilityCache.paint; |
| 12029 | final Matrix matrix = scrollabilityCache.matrix; |
| 12030 | final Shader fade = scrollabilityCache.shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12031 | |
| 12032 | if (drawTop) { |
| 12033 | matrix.setScale(1, fadeHeight * topFadeStrength); |
| 12034 | matrix.postTranslate(left, top); |
| 12035 | fade.setLocalMatrix(matrix); |
| 12036 | canvas.drawRect(left, top, right, top + length, p); |
| 12037 | } |
| 12038 | |
| 12039 | if (drawBottom) { |
| 12040 | matrix.setScale(1, fadeHeight * bottomFadeStrength); |
| 12041 | matrix.postRotate(180); |
| 12042 | matrix.postTranslate(left, bottom); |
| 12043 | fade.setLocalMatrix(matrix); |
| 12044 | canvas.drawRect(left, bottom - length, right, bottom, p); |
| 12045 | } |
| 12046 | |
| 12047 | if (drawLeft) { |
| 12048 | matrix.setScale(1, fadeHeight * leftFadeStrength); |
| 12049 | matrix.postRotate(-90); |
| 12050 | matrix.postTranslate(left, top); |
| 12051 | fade.setLocalMatrix(matrix); |
| 12052 | canvas.drawRect(left, top, left + length, bottom, p); |
| 12053 | } |
| 12054 | |
| 12055 | if (drawRight) { |
| 12056 | matrix.setScale(1, fadeHeight * rightFadeStrength); |
| 12057 | matrix.postRotate(90); |
| 12058 | matrix.postTranslate(right, top); |
| 12059 | fade.setLocalMatrix(matrix); |
| 12060 | canvas.drawRect(right - length, top, right, bottom, p); |
| 12061 | } |
| 12062 | |
| 12063 | canvas.restoreToCount(saveCount); |
| 12064 | |
| 12065 | // Step 6, draw decorations (scrollbars) |
| 12066 | onDrawScrollBars(canvas); |
| 12067 | } |
| 12068 | |
| 12069 | /** |
| 12070 | * Override this if your view is known to always be drawn on top of a solid color background, |
| 12071 | * and needs to draw fading edges. Returning a non-zero color enables the view system to |
| 12072 | * optimize the drawing of the fading edges. If you do return a non-zero color, the alpha |
| 12073 | * should be set to 0xFF. |
| 12074 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12075 | * @see #setVerticalFadingEdgeEnabled(boolean) |
| 12076 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12077 | * |
| 12078 | * @return The known solid color background for this view, or 0 if the color may vary |
| 12079 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12080 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12081 | public int getSolidColor() { |
| 12082 | return 0; |
| 12083 | } |
| 12084 | |
| 12085 | /** |
| 12086 | * Build a human readable string representation of the specified view flags. |
| 12087 | * |
| 12088 | * @param flags the view flags to convert to a string |
| 12089 | * @return a String representing the supplied flags |
| 12090 | */ |
| 12091 | private static String printFlags(int flags) { |
| 12092 | String output = ""; |
| 12093 | int numFlags = 0; |
| 12094 | if ((flags & FOCUSABLE_MASK) == FOCUSABLE) { |
| 12095 | output += "TAKES_FOCUS"; |
| 12096 | numFlags++; |
| 12097 | } |
| 12098 | |
| 12099 | switch (flags & VISIBILITY_MASK) { |
| 12100 | case INVISIBLE: |
| 12101 | if (numFlags > 0) { |
| 12102 | output += " "; |
| 12103 | } |
| 12104 | output += "INVISIBLE"; |
| 12105 | // USELESS HERE numFlags++; |
| 12106 | break; |
| 12107 | case GONE: |
| 12108 | if (numFlags > 0) { |
| 12109 | output += " "; |
| 12110 | } |
| 12111 | output += "GONE"; |
| 12112 | // USELESS HERE numFlags++; |
| 12113 | break; |
| 12114 | default: |
| 12115 | break; |
| 12116 | } |
| 12117 | return output; |
| 12118 | } |
| 12119 | |
| 12120 | /** |
| 12121 | * Build a human readable string representation of the specified private |
| 12122 | * view flags. |
| 12123 | * |
| 12124 | * @param privateFlags the private view flags to convert to a string |
| 12125 | * @return a String representing the supplied flags |
| 12126 | */ |
| 12127 | private static String printPrivateFlags(int privateFlags) { |
| 12128 | String output = ""; |
| 12129 | int numFlags = 0; |
| 12130 | |
| 12131 | if ((privateFlags & WANTS_FOCUS) == WANTS_FOCUS) { |
| 12132 | output += "WANTS_FOCUS"; |
| 12133 | numFlags++; |
| 12134 | } |
| 12135 | |
| 12136 | if ((privateFlags & FOCUSED) == FOCUSED) { |
| 12137 | if (numFlags > 0) { |
| 12138 | output += " "; |
| 12139 | } |
| 12140 | output += "FOCUSED"; |
| 12141 | numFlags++; |
| 12142 | } |
| 12143 | |
| 12144 | if ((privateFlags & SELECTED) == SELECTED) { |
| 12145 | if (numFlags > 0) { |
| 12146 | output += " "; |
| 12147 | } |
| 12148 | output += "SELECTED"; |
| 12149 | numFlags++; |
| 12150 | } |
| 12151 | |
| 12152 | if ((privateFlags & IS_ROOT_NAMESPACE) == IS_ROOT_NAMESPACE) { |
| 12153 | if (numFlags > 0) { |
| 12154 | output += " "; |
| 12155 | } |
| 12156 | output += "IS_ROOT_NAMESPACE"; |
| 12157 | numFlags++; |
| 12158 | } |
| 12159 | |
| 12160 | if ((privateFlags & HAS_BOUNDS) == HAS_BOUNDS) { |
| 12161 | if (numFlags > 0) { |
| 12162 | output += " "; |
| 12163 | } |
| 12164 | output += "HAS_BOUNDS"; |
| 12165 | numFlags++; |
| 12166 | } |
| 12167 | |
| 12168 | if ((privateFlags & DRAWN) == DRAWN) { |
| 12169 | if (numFlags > 0) { |
| 12170 | output += " "; |
| 12171 | } |
| 12172 | output += "DRAWN"; |
| 12173 | // USELESS HERE numFlags++; |
| 12174 | } |
| 12175 | return output; |
| 12176 | } |
| 12177 | |
| 12178 | /** |
| 12179 | * <p>Indicates whether or not this view's layout will be requested during |
| 12180 | * the next hierarchy layout pass.</p> |
| 12181 | * |
| 12182 | * @return true if the layout will be forced during next layout pass |
| 12183 | */ |
| 12184 | public boolean isLayoutRequested() { |
| 12185 | return (mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT; |
| 12186 | } |
| 12187 | |
| 12188 | /** |
| 12189 | * Assign a size and position to a view and all of its |
| 12190 | * descendants |
| 12191 | * |
| 12192 | * <p>This is the second phase of the layout mechanism. |
| 12193 | * (The first is measuring). In this phase, each parent calls |
| 12194 | * layout on all of its children to position them. |
| 12195 | * This is typically done using the child measurements |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 12196 | * that were stored in the measure pass().</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12197 | * |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 12198 | * <p>Derived classes should not override this method. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12199 | * Derived classes with children should override |
| 12200 | * onLayout. In that method, they should |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 12201 | * call layout on each of their children.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12202 | * |
| 12203 | * @param l Left position, relative to parent |
| 12204 | * @param t Top position, relative to parent |
| 12205 | * @param r Right position, relative to parent |
| 12206 | * @param b Bottom position, relative to parent |
| 12207 | */ |
Romain Guy | 5429e1d | 2010-09-07 12:38:00 -0700 | [diff] [blame] | 12208 | @SuppressWarnings({"unchecked"}) |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 12209 | public void layout(int l, int t, int r, int b) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 12210 | int oldL = mLeft; |
| 12211 | int oldT = mTop; |
| 12212 | int oldB = mBottom; |
| 12213 | int oldR = mRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12214 | boolean changed = setFrame(l, t, r, b); |
| 12215 | if (changed || (mPrivateFlags & LAYOUT_REQUIRED) == LAYOUT_REQUIRED) { |
| 12216 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12217 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_LAYOUT); |
| 12218 | } |
| 12219 | |
| 12220 | onLayout(changed, l, t, r, b); |
| 12221 | mPrivateFlags &= ~LAYOUT_REQUIRED; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 12222 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 12223 | ListenerInfo li = mListenerInfo; |
| 12224 | if (li != null && li.mOnLayoutChangeListeners != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 12225 | ArrayList<OnLayoutChangeListener> listenersCopy = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 12226 | (ArrayList<OnLayoutChangeListener>)li.mOnLayoutChangeListeners.clone(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 12227 | int numListeners = listenersCopy.size(); |
| 12228 | for (int i = 0; i < numListeners; ++i) { |
Chet Haase | 7c608f2 | 2010-10-22 17:54:04 -0700 | [diff] [blame] | 12229 | listenersCopy.get(i).onLayoutChange(this, l, t, r, b, oldL, oldT, oldR, oldB); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 12230 | } |
| 12231 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12232 | } |
| 12233 | mPrivateFlags &= ~FORCE_LAYOUT; |
| 12234 | } |
| 12235 | |
| 12236 | /** |
| 12237 | * Called from layout when this view should |
| 12238 | * assign a size and position to each of its children. |
| 12239 | * |
| 12240 | * Derived classes with children should override |
| 12241 | * this method and call layout on each of |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 12242 | * their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12243 | * @param changed This is a new size or position for this view |
| 12244 | * @param left Left position, relative to parent |
| 12245 | * @param top Top position, relative to parent |
| 12246 | * @param right Right position, relative to parent |
| 12247 | * @param bottom Bottom position, relative to parent |
| 12248 | */ |
| 12249 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 12250 | } |
| 12251 | |
| 12252 | /** |
| 12253 | * Assign a size and position to this view. |
| 12254 | * |
| 12255 | * This is called from layout. |
| 12256 | * |
| 12257 | * @param left Left position, relative to parent |
| 12258 | * @param top Top position, relative to parent |
| 12259 | * @param right Right position, relative to parent |
| 12260 | * @param bottom Bottom position, relative to parent |
| 12261 | * @return true if the new size and position are different than the |
| 12262 | * previous ones |
| 12263 | * {@hide} |
| 12264 | */ |
| 12265 | protected boolean setFrame(int left, int top, int right, int bottom) { |
| 12266 | boolean changed = false; |
| 12267 | |
| 12268 | if (DBG) { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 12269 | Log.d("View", this + " View.setFrame(" + left + "," + top + "," |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12270 | + right + "," + bottom + ")"); |
| 12271 | } |
| 12272 | |
| 12273 | if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) { |
| 12274 | changed = true; |
| 12275 | |
| 12276 | // Remember our drawn bit |
| 12277 | int drawn = mPrivateFlags & DRAWN; |
| 12278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12279 | int oldWidth = mRight - mLeft; |
| 12280 | int oldHeight = mBottom - mTop; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 12281 | int newWidth = right - left; |
| 12282 | int newHeight = bottom - top; |
| 12283 | boolean sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight); |
| 12284 | |
| 12285 | // Invalidate our old position |
| 12286 | invalidate(sizeChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12287 | |
| 12288 | mLeft = left; |
| 12289 | mTop = top; |
| 12290 | mRight = right; |
| 12291 | mBottom = bottom; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12292 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 12293 | mDisplayList.setLeftTopRightBottom(mLeft, mTop, mRight, mBottom); |
| 12294 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12295 | |
| 12296 | mPrivateFlags |= HAS_BOUNDS; |
| 12297 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12298 | |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 12299 | if (sizeChanged) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 12300 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 12301 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 12302 | if (mTransformationInfo != null) { |
| 12303 | mTransformationInfo.mMatrixDirty = true; |
| 12304 | } |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 12305 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12306 | onSizeChanged(newWidth, newHeight, oldWidth, oldHeight); |
| 12307 | } |
| 12308 | |
| 12309 | if ((mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 12310 | // If we are visible, force the DRAWN bit to on so that |
| 12311 | // this invalidate will go through (at least to our parent). |
| 12312 | // This is because someone may have invalidated this view |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 12313 | // before this call to setFrame came in, thereby clearing |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12314 | // the DRAWN bit. |
| 12315 | mPrivateFlags |= DRAWN; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 12316 | invalidate(sizeChanged); |
Chet Haase | f28595e | 2011-01-31 18:52:12 -0800 | [diff] [blame] | 12317 | // parent display list may need to be recreated based on a change in the bounds |
| 12318 | // of any child |
| 12319 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12320 | } |
| 12321 | |
| 12322 | // Reset drawn bit to original value (invalidate turns it off) |
| 12323 | mPrivateFlags |= drawn; |
| 12324 | |
| 12325 | mBackgroundSizeChanged = true; |
| 12326 | } |
| 12327 | return changed; |
| 12328 | } |
| 12329 | |
| 12330 | /** |
| 12331 | * Finalize inflating a view from XML. This is called as the last phase |
| 12332 | * of inflation, after all child views have been added. |
| 12333 | * |
| 12334 | * <p>Even if the subclass overrides onFinishInflate, they should always be |
| 12335 | * sure to call the super method, so that we get called. |
| 12336 | */ |
| 12337 | protected void onFinishInflate() { |
| 12338 | } |
| 12339 | |
| 12340 | /** |
| 12341 | * Returns the resources associated with this view. |
| 12342 | * |
| 12343 | * @return Resources object. |
| 12344 | */ |
| 12345 | public Resources getResources() { |
| 12346 | return mResources; |
| 12347 | } |
| 12348 | |
| 12349 | /** |
| 12350 | * Invalidates the specified Drawable. |
| 12351 | * |
| 12352 | * @param drawable the drawable to invalidate |
| 12353 | */ |
| 12354 | public void invalidateDrawable(Drawable drawable) { |
| 12355 | if (verifyDrawable(drawable)) { |
| 12356 | final Rect dirty = drawable.getBounds(); |
| 12357 | final int scrollX = mScrollX; |
| 12358 | final int scrollY = mScrollY; |
| 12359 | |
| 12360 | invalidate(dirty.left + scrollX, dirty.top + scrollY, |
| 12361 | dirty.right + scrollX, dirty.bottom + scrollY); |
| 12362 | } |
| 12363 | } |
| 12364 | |
| 12365 | /** |
| 12366 | * Schedules an action on a drawable to occur at a specified time. |
| 12367 | * |
| 12368 | * @param who the recipient of the action |
| 12369 | * @param what the action to run on the drawable |
| 12370 | * @param when the time at which the action must occur. Uses the |
| 12371 | * {@link SystemClock#uptimeMillis} timebase. |
| 12372 | */ |
| 12373 | public void scheduleDrawable(Drawable who, Runnable what, long when) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 12374 | if (verifyDrawable(who) && what != null) { |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 12375 | final long delay = when - SystemClock.uptimeMillis(); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 12376 | if (mAttachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 12377 | mAttachInfo.mViewRootImpl.mChoreographer.postCallbackDelayed( |
| 12378 | Choreographer.CALLBACK_ANIMATION, what, who, |
| 12379 | Choreographer.subtractFrameDelay(delay)); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 12380 | } else { |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 12381 | ViewRootImpl.getRunQueue().postDelayed(what, delay); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 12382 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12383 | } |
| 12384 | } |
| 12385 | |
| 12386 | /** |
| 12387 | * Cancels a scheduled action on a drawable. |
| 12388 | * |
| 12389 | * @param who the recipient of the action |
| 12390 | * @param what the action to cancel |
| 12391 | */ |
| 12392 | public void unscheduleDrawable(Drawable who, Runnable what) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 12393 | if (verifyDrawable(who) && what != null) { |
| 12394 | if (mAttachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 12395 | mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 12396 | Choreographer.CALLBACK_ANIMATION, what, who); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 12397 | } else { |
| 12398 | ViewRootImpl.getRunQueue().removeCallbacks(what); |
| 12399 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12400 | } |
| 12401 | } |
| 12402 | |
| 12403 | /** |
| 12404 | * Unschedule any events associated with the given Drawable. This can be |
| 12405 | * used when selecting a new Drawable into a view, so that the previous |
| 12406 | * one is completely unscheduled. |
| 12407 | * |
| 12408 | * @param who The Drawable to unschedule. |
| 12409 | * |
| 12410 | * @see #drawableStateChanged |
| 12411 | */ |
| 12412 | public void unscheduleDrawable(Drawable who) { |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 12413 | if (mAttachInfo != null && who != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 12414 | mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 12415 | Choreographer.CALLBACK_ANIMATION, null, who); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12416 | } |
| 12417 | } |
| 12418 | |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 12419 | /** |
| 12420 | * Return the layout direction of a given Drawable. |
| 12421 | * |
| 12422 | * @param who the Drawable to query |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 12423 | */ |
| 12424 | public int getResolvedLayoutDirection(Drawable who) { |
| 12425 | return (who == mBGDrawable) ? getResolvedLayoutDirection() : LAYOUT_DIRECTION_DEFAULT; |
Fabrice Di Meglio | 6a03640 | 2011-05-23 14:43:23 -0700 | [diff] [blame] | 12426 | } |
| 12427 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12428 | /** |
| 12429 | * If your view subclass is displaying its own Drawable objects, it should |
| 12430 | * override this function and return true for any Drawable it is |
| 12431 | * displaying. This allows animations for those drawables to be |
| 12432 | * scheduled. |
| 12433 | * |
| 12434 | * <p>Be sure to call through to the super class when overriding this |
| 12435 | * function. |
| 12436 | * |
| 12437 | * @param who The Drawable to verify. Return true if it is one you are |
| 12438 | * displaying, else return the result of calling through to the |
| 12439 | * super class. |
| 12440 | * |
| 12441 | * @return boolean If true than the Drawable is being displayed in the |
| 12442 | * view; else false and it is not allowed to animate. |
| 12443 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12444 | * @see #unscheduleDrawable(android.graphics.drawable.Drawable) |
| 12445 | * @see #drawableStateChanged() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12446 | */ |
| 12447 | protected boolean verifyDrawable(Drawable who) { |
| 12448 | return who == mBGDrawable; |
| 12449 | } |
| 12450 | |
| 12451 | /** |
| 12452 | * This function is called whenever the state of the view changes in such |
| 12453 | * a way that it impacts the state of drawables being shown. |
| 12454 | * |
| 12455 | * <p>Be sure to call through to the superclass when overriding this |
| 12456 | * function. |
| 12457 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12458 | * @see Drawable#setState(int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12459 | */ |
| 12460 | protected void drawableStateChanged() { |
| 12461 | Drawable d = mBGDrawable; |
| 12462 | if (d != null && d.isStateful()) { |
| 12463 | d.setState(getDrawableState()); |
| 12464 | } |
| 12465 | } |
| 12466 | |
| 12467 | /** |
| 12468 | * Call this to force a view to update its drawable state. This will cause |
| 12469 | * drawableStateChanged to be called on this view. Views that are interested |
| 12470 | * in the new state should call getDrawableState. |
| 12471 | * |
| 12472 | * @see #drawableStateChanged |
| 12473 | * @see #getDrawableState |
| 12474 | */ |
| 12475 | public void refreshDrawableState() { |
| 12476 | mPrivateFlags |= DRAWABLE_STATE_DIRTY; |
| 12477 | drawableStateChanged(); |
| 12478 | |
| 12479 | ViewParent parent = mParent; |
| 12480 | if (parent != null) { |
| 12481 | parent.childDrawableStateChanged(this); |
| 12482 | } |
| 12483 | } |
| 12484 | |
| 12485 | /** |
| 12486 | * Return an array of resource IDs of the drawable states representing the |
| 12487 | * current state of the view. |
| 12488 | * |
| 12489 | * @return The current drawable state |
| 12490 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12491 | * @see Drawable#setState(int[]) |
| 12492 | * @see #drawableStateChanged() |
| 12493 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12494 | */ |
| 12495 | public final int[] getDrawableState() { |
| 12496 | if ((mDrawableState != null) && ((mPrivateFlags & DRAWABLE_STATE_DIRTY) == 0)) { |
| 12497 | return mDrawableState; |
| 12498 | } else { |
| 12499 | mDrawableState = onCreateDrawableState(0); |
| 12500 | mPrivateFlags &= ~DRAWABLE_STATE_DIRTY; |
| 12501 | return mDrawableState; |
| 12502 | } |
| 12503 | } |
| 12504 | |
| 12505 | /** |
| 12506 | * Generate the new {@link android.graphics.drawable.Drawable} state for |
| 12507 | * this view. This is called by the view |
| 12508 | * system when the cached Drawable state is determined to be invalid. To |
| 12509 | * retrieve the current state, you should use {@link #getDrawableState}. |
| 12510 | * |
| 12511 | * @param extraSpace if non-zero, this is the number of extra entries you |
| 12512 | * would like in the returned array in which you can place your own |
| 12513 | * states. |
| 12514 | * |
| 12515 | * @return Returns an array holding the current {@link Drawable} state of |
| 12516 | * the view. |
| 12517 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12518 | * @see #mergeDrawableStates(int[], int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12519 | */ |
| 12520 | protected int[] onCreateDrawableState(int extraSpace) { |
| 12521 | if ((mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE && |
| 12522 | mParent instanceof View) { |
| 12523 | return ((View) mParent).onCreateDrawableState(extraSpace); |
| 12524 | } |
| 12525 | |
| 12526 | int[] drawableState; |
| 12527 | |
| 12528 | int privateFlags = mPrivateFlags; |
| 12529 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 12530 | int viewStateIndex = 0; |
| 12531 | if ((privateFlags & PRESSED) != 0) viewStateIndex |= VIEW_STATE_PRESSED; |
| 12532 | if ((mViewFlags & ENABLED_MASK) == ENABLED) viewStateIndex |= VIEW_STATE_ENABLED; |
| 12533 | if (isFocused()) viewStateIndex |= VIEW_STATE_FOCUSED; |
Neel Parekh | e537858 | 2010-10-06 11:36:50 -0700 | [diff] [blame] | 12534 | if ((privateFlags & SELECTED) != 0) viewStateIndex |= VIEW_STATE_SELECTED; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 12535 | if (hasWindowFocus()) viewStateIndex |= VIEW_STATE_WINDOW_FOCUSED; |
| 12536 | if ((privateFlags & ACTIVATED) != 0) viewStateIndex |= VIEW_STATE_ACTIVATED; |
Adam Powell | 5a7e94e | 2011-04-25 15:30:43 -0700 | [diff] [blame] | 12537 | if (mAttachInfo != null && mAttachInfo.mHardwareAccelerationRequested && |
| 12538 | HardwareRenderer.isAvailable()) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 12539 | // This is set if HW acceleration is requested, even if the current |
| 12540 | // process doesn't allow it. This is just to allow app preview |
| 12541 | // windows to better match their app. |
| 12542 | viewStateIndex |= VIEW_STATE_ACCELERATED; |
| 12543 | } |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 12544 | if ((privateFlags & HOVERED) != 0) viewStateIndex |= VIEW_STATE_HOVERED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12545 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 12546 | final int privateFlags2 = mPrivateFlags2; |
| 12547 | if ((privateFlags2 & DRAG_CAN_ACCEPT) != 0) viewStateIndex |= VIEW_STATE_DRAG_CAN_ACCEPT; |
| 12548 | if ((privateFlags2 & DRAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_DRAG_HOVERED; |
| 12549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12550 | drawableState = VIEW_STATE_SETS[viewStateIndex]; |
| 12551 | |
| 12552 | //noinspection ConstantIfStatement |
| 12553 | if (false) { |
| 12554 | Log.i("View", "drawableStateIndex=" + viewStateIndex); |
| 12555 | Log.i("View", toString() |
| 12556 | + " pressed=" + ((privateFlags & PRESSED) != 0) |
| 12557 | + " en=" + ((mViewFlags & ENABLED_MASK) == ENABLED) |
| 12558 | + " fo=" + hasFocus() |
| 12559 | + " sl=" + ((privateFlags & SELECTED) != 0) |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 12560 | + " wf=" + hasWindowFocus() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12561 | + ": " + Arrays.toString(drawableState)); |
| 12562 | } |
| 12563 | |
| 12564 | if (extraSpace == 0) { |
| 12565 | return drawableState; |
| 12566 | } |
| 12567 | |
| 12568 | final int[] fullState; |
| 12569 | if (drawableState != null) { |
| 12570 | fullState = new int[drawableState.length + extraSpace]; |
| 12571 | System.arraycopy(drawableState, 0, fullState, 0, drawableState.length); |
| 12572 | } else { |
| 12573 | fullState = new int[extraSpace]; |
| 12574 | } |
| 12575 | |
| 12576 | return fullState; |
| 12577 | } |
| 12578 | |
| 12579 | /** |
| 12580 | * Merge your own state values in <var>additionalState</var> into the base |
| 12581 | * state values <var>baseState</var> that were returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12582 | * {@link #onCreateDrawableState(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12583 | * |
| 12584 | * @param baseState The base state values returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12585 | * {@link #onCreateDrawableState(int)}, which will be modified to also hold your |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12586 | * own additional state values. |
| 12587 | * |
| 12588 | * @param additionalState The additional state values you would like |
| 12589 | * added to <var>baseState</var>; this array is not modified. |
| 12590 | * |
| 12591 | * @return As a convenience, the <var>baseState</var> array you originally |
| 12592 | * passed into the function is returned. |
| 12593 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12594 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12595 | */ |
| 12596 | protected static int[] mergeDrawableStates(int[] baseState, int[] additionalState) { |
| 12597 | final int N = baseState.length; |
| 12598 | int i = N - 1; |
| 12599 | while (i >= 0 && baseState[i] == 0) { |
| 12600 | i--; |
| 12601 | } |
| 12602 | System.arraycopy(additionalState, 0, baseState, i + 1, additionalState.length); |
| 12603 | return baseState; |
| 12604 | } |
| 12605 | |
| 12606 | /** |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 12607 | * Call {@link Drawable#jumpToCurrentState() Drawable.jumpToCurrentState()} |
| 12608 | * on all Drawable objects associated with this view. |
| 12609 | */ |
| 12610 | public void jumpDrawablesToCurrentState() { |
| 12611 | if (mBGDrawable != null) { |
| 12612 | mBGDrawable.jumpToCurrentState(); |
| 12613 | } |
| 12614 | } |
| 12615 | |
| 12616 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12617 | * Sets the background color for this view. |
| 12618 | * @param color the color of the background |
| 12619 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 12620 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12621 | public void setBackgroundColor(int color) { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 12622 | if (mBGDrawable instanceof ColorDrawable) { |
| 12623 | ((ColorDrawable) mBGDrawable).setColor(color); |
| 12624 | } else { |
| 12625 | setBackgroundDrawable(new ColorDrawable(color)); |
| 12626 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12627 | } |
| 12628 | |
| 12629 | /** |
| 12630 | * Set the background to a given resource. The resource should refer to |
Wink Saville | 7cd88e1 | 2009-08-04 14:45:10 -0700 | [diff] [blame] | 12631 | * a Drawable object or 0 to remove the background. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12632 | * @param resid The identifier of the resource. |
| 12633 | * @attr ref android.R.styleable#View_background |
| 12634 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 12635 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12636 | public void setBackgroundResource(int resid) { |
| 12637 | if (resid != 0 && resid == mBackgroundResource) { |
| 12638 | return; |
| 12639 | } |
| 12640 | |
| 12641 | Drawable d= null; |
| 12642 | if (resid != 0) { |
| 12643 | d = mResources.getDrawable(resid); |
| 12644 | } |
| 12645 | setBackgroundDrawable(d); |
| 12646 | |
| 12647 | mBackgroundResource = resid; |
| 12648 | } |
| 12649 | |
| 12650 | /** |
| 12651 | * Set the background to a given Drawable, or remove the background. If the |
| 12652 | * background has padding, this View's padding is set to the background's |
| 12653 | * padding. However, when a background is removed, this View's padding isn't |
| 12654 | * touched. If setting the padding is desired, please use |
| 12655 | * {@link #setPadding(int, int, int, int)}. |
| 12656 | * |
| 12657 | * @param d The Drawable to use as the background, or null to remove the |
| 12658 | * background |
| 12659 | */ |
| 12660 | public void setBackgroundDrawable(Drawable d) { |
Adam Powell | 4d36ec1 | 2011-07-17 16:44:16 -0700 | [diff] [blame] | 12661 | if (d == mBGDrawable) { |
| 12662 | return; |
| 12663 | } |
| 12664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12665 | boolean requestLayout = false; |
| 12666 | |
| 12667 | mBackgroundResource = 0; |
| 12668 | |
| 12669 | /* |
| 12670 | * Regardless of whether we're setting a new background or not, we want |
| 12671 | * to clear the previous drawable. |
| 12672 | */ |
| 12673 | if (mBGDrawable != null) { |
| 12674 | mBGDrawable.setCallback(null); |
| 12675 | unscheduleDrawable(mBGDrawable); |
| 12676 | } |
| 12677 | |
| 12678 | if (d != null) { |
| 12679 | Rect padding = sThreadLocal.get(); |
| 12680 | if (padding == null) { |
| 12681 | padding = new Rect(); |
| 12682 | sThreadLocal.set(padding); |
| 12683 | } |
| 12684 | if (d.getPadding(padding)) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12685 | switch (d.getResolvedLayoutDirectionSelf()) { |
| 12686 | case LAYOUT_DIRECTION_RTL: |
| 12687 | setPadding(padding.right, padding.top, padding.left, padding.bottom); |
| 12688 | break; |
| 12689 | case LAYOUT_DIRECTION_LTR: |
| 12690 | default: |
| 12691 | setPadding(padding.left, padding.top, padding.right, padding.bottom); |
| 12692 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12693 | } |
| 12694 | |
| 12695 | // Compare the minimum sizes of the old Drawable and the new. If there isn't an old or |
| 12696 | // if it has a different minimum size, we should layout again |
| 12697 | if (mBGDrawable == null || mBGDrawable.getMinimumHeight() != d.getMinimumHeight() || |
| 12698 | mBGDrawable.getMinimumWidth() != d.getMinimumWidth()) { |
| 12699 | requestLayout = true; |
| 12700 | } |
| 12701 | |
| 12702 | d.setCallback(this); |
| 12703 | if (d.isStateful()) { |
| 12704 | d.setState(getDrawableState()); |
| 12705 | } |
| 12706 | d.setVisible(getVisibility() == VISIBLE, false); |
| 12707 | mBGDrawable = d; |
| 12708 | |
| 12709 | if ((mPrivateFlags & SKIP_DRAW) != 0) { |
| 12710 | mPrivateFlags &= ~SKIP_DRAW; |
| 12711 | mPrivateFlags |= ONLY_DRAWS_BACKGROUND; |
| 12712 | requestLayout = true; |
| 12713 | } |
| 12714 | } else { |
| 12715 | /* Remove the background */ |
| 12716 | mBGDrawable = null; |
| 12717 | |
| 12718 | if ((mPrivateFlags & ONLY_DRAWS_BACKGROUND) != 0) { |
| 12719 | /* |
| 12720 | * This view ONLY drew the background before and we're removing |
| 12721 | * the background, so now it won't draw anything |
| 12722 | * (hence we SKIP_DRAW) |
| 12723 | */ |
| 12724 | mPrivateFlags &= ~ONLY_DRAWS_BACKGROUND; |
| 12725 | mPrivateFlags |= SKIP_DRAW; |
| 12726 | } |
| 12727 | |
| 12728 | /* |
| 12729 | * When the background is set, we try to apply its padding to this |
| 12730 | * View. When the background is removed, we don't touch this View's |
| 12731 | * padding. This is noted in the Javadocs. Hence, we don't need to |
| 12732 | * requestLayout(), the invalidate() below is sufficient. |
| 12733 | */ |
| 12734 | |
| 12735 | // The old background's minimum size could have affected this |
| 12736 | // View's layout, so let's requestLayout |
| 12737 | requestLayout = true; |
| 12738 | } |
| 12739 | |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 12740 | computeOpaqueFlags(); |
| 12741 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12742 | if (requestLayout) { |
| 12743 | requestLayout(); |
| 12744 | } |
| 12745 | |
| 12746 | mBackgroundSizeChanged = true; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 12747 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12748 | } |
| 12749 | |
| 12750 | /** |
| 12751 | * Gets the background drawable |
| 12752 | * @return The drawable used as the background for this view, if any. |
| 12753 | */ |
| 12754 | public Drawable getBackground() { |
| 12755 | return mBGDrawable; |
| 12756 | } |
| 12757 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12758 | /** |
| 12759 | * Sets the padding. The view may add on the space required to display |
| 12760 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 12761 | * So the values returned from {@link #getPaddingLeft}, {@link #getPaddingTop}, |
| 12762 | * {@link #getPaddingRight} and {@link #getPaddingBottom} may be different |
| 12763 | * from the values set in this call. |
| 12764 | * |
| 12765 | * @attr ref android.R.styleable#View_padding |
| 12766 | * @attr ref android.R.styleable#View_paddingBottom |
| 12767 | * @attr ref android.R.styleable#View_paddingLeft |
| 12768 | * @attr ref android.R.styleable#View_paddingRight |
| 12769 | * @attr ref android.R.styleable#View_paddingTop |
| 12770 | * @param left the left padding in pixels |
| 12771 | * @param top the top padding in pixels |
| 12772 | * @param right the right padding in pixels |
| 12773 | * @param bottom the bottom padding in pixels |
| 12774 | */ |
| 12775 | public void setPadding(int left, int top, int right, int bottom) { |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 12776 | mUserPaddingStart = -1; |
| 12777 | mUserPaddingEnd = -1; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12778 | mUserPaddingRelative = false; |
| 12779 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 12780 | internalSetPadding(left, top, right, bottom); |
| 12781 | } |
| 12782 | |
| 12783 | private void internalSetPadding(int left, int top, int right, int bottom) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 12784 | mUserPaddingLeft = left; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12785 | mUserPaddingRight = right; |
| 12786 | mUserPaddingBottom = bottom; |
| 12787 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 12788 | final int viewFlags = mViewFlags; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 12789 | boolean changed = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12790 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 12791 | // Common case is there are no scroll bars. |
| 12792 | if ((viewFlags & (SCROLLBARS_VERTICAL|SCROLLBARS_HORIZONTAL)) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 12793 | if ((viewFlags & SCROLLBARS_VERTICAL) != 0) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 12794 | final int offset = (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 12795 | ? 0 : getVerticalScrollbarWidth(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 12796 | switch (mVerticalScrollbarPosition) { |
| 12797 | case SCROLLBAR_POSITION_DEFAULT: |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12798 | if (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
| 12799 | left += offset; |
| 12800 | } else { |
| 12801 | right += offset; |
| 12802 | } |
| 12803 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 12804 | case SCROLLBAR_POSITION_RIGHT: |
| 12805 | right += offset; |
| 12806 | break; |
| 12807 | case SCROLLBAR_POSITION_LEFT: |
| 12808 | left += offset; |
| 12809 | break; |
| 12810 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 12811 | } |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 12812 | if ((viewFlags & SCROLLBARS_HORIZONTAL) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 12813 | bottom += (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
| 12814 | ? 0 : getHorizontalScrollbarHeight(); |
| 12815 | } |
| 12816 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12817 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 12818 | if (mPaddingLeft != left) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12819 | changed = true; |
| 12820 | mPaddingLeft = left; |
| 12821 | } |
| 12822 | if (mPaddingTop != top) { |
| 12823 | changed = true; |
| 12824 | mPaddingTop = top; |
| 12825 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 12826 | if (mPaddingRight != right) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12827 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 12828 | mPaddingRight = right; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12829 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 12830 | if (mPaddingBottom != bottom) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12831 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 12832 | mPaddingBottom = bottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12833 | } |
| 12834 | |
| 12835 | if (changed) { |
| 12836 | requestLayout(); |
| 12837 | } |
| 12838 | } |
| 12839 | |
| 12840 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12841 | * Sets the relative padding. The view may add on the space required to display |
| 12842 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 12843 | * So the values returned from {@link #getPaddingStart}, {@link #getPaddingTop}, |
| 12844 | * {@link #getPaddingEnd} and {@link #getPaddingBottom} may be different |
| 12845 | * from the values set in this call. |
| 12846 | * |
| 12847 | * @attr ref android.R.styleable#View_padding |
| 12848 | * @attr ref android.R.styleable#View_paddingBottom |
| 12849 | * @attr ref android.R.styleable#View_paddingStart |
| 12850 | * @attr ref android.R.styleable#View_paddingEnd |
| 12851 | * @attr ref android.R.styleable#View_paddingTop |
| 12852 | * @param start the start padding in pixels |
| 12853 | * @param top the top padding in pixels |
| 12854 | * @param end the end padding in pixels |
| 12855 | * @param bottom the bottom padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12856 | */ |
| 12857 | public void setPaddingRelative(int start, int top, int end, int bottom) { |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 12858 | mUserPaddingStart = start; |
| 12859 | mUserPaddingEnd = end; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 12860 | mUserPaddingRelative = true; |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 12861 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12862 | switch(getResolvedLayoutDirection()) { |
| 12863 | case LAYOUT_DIRECTION_RTL: |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 12864 | internalSetPadding(end, top, start, bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12865 | break; |
| 12866 | case LAYOUT_DIRECTION_LTR: |
| 12867 | default: |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 12868 | internalSetPadding(start, top, end, bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12869 | } |
| 12870 | } |
| 12871 | |
| 12872 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12873 | * Returns the top padding of this view. |
| 12874 | * |
| 12875 | * @return the top padding in pixels |
| 12876 | */ |
| 12877 | public int getPaddingTop() { |
| 12878 | return mPaddingTop; |
| 12879 | } |
| 12880 | |
| 12881 | /** |
| 12882 | * Returns the bottom padding of this view. If there are inset and enabled |
| 12883 | * scrollbars, this value may include the space required to display the |
| 12884 | * scrollbars as well. |
| 12885 | * |
| 12886 | * @return the bottom padding in pixels |
| 12887 | */ |
| 12888 | public int getPaddingBottom() { |
| 12889 | return mPaddingBottom; |
| 12890 | } |
| 12891 | |
| 12892 | /** |
| 12893 | * Returns the left padding of this view. If there are inset and enabled |
| 12894 | * scrollbars, this value may include the space required to display the |
| 12895 | * scrollbars as well. |
| 12896 | * |
| 12897 | * @return the left padding in pixels |
| 12898 | */ |
| 12899 | public int getPaddingLeft() { |
| 12900 | return mPaddingLeft; |
| 12901 | } |
| 12902 | |
| 12903 | /** |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 12904 | * Returns the start padding of this view depending on its resolved layout direction. |
| 12905 | * If there are inset and enabled scrollbars, this value may include the space |
| 12906 | * required to display the scrollbars as well. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12907 | * |
| 12908 | * @return the start padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12909 | */ |
| 12910 | public int getPaddingStart() { |
| 12911 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
| 12912 | mPaddingRight : mPaddingLeft; |
| 12913 | } |
| 12914 | |
| 12915 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12916 | * Returns the right padding of this view. If there are inset and enabled |
| 12917 | * scrollbars, this value may include the space required to display the |
| 12918 | * scrollbars as well. |
| 12919 | * |
| 12920 | * @return the right padding in pixels |
| 12921 | */ |
| 12922 | public int getPaddingRight() { |
| 12923 | return mPaddingRight; |
| 12924 | } |
| 12925 | |
| 12926 | /** |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 12927 | * Returns the end padding of this view depending on its resolved layout direction. |
| 12928 | * If there are inset and enabled scrollbars, this value may include the space |
| 12929 | * required to display the scrollbars as well. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12930 | * |
| 12931 | * @return the end padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12932 | */ |
| 12933 | public int getPaddingEnd() { |
| 12934 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
| 12935 | mPaddingLeft : mPaddingRight; |
| 12936 | } |
| 12937 | |
| 12938 | /** |
| 12939 | * Return if the padding as been set thru relative values |
| 12940 | * {@link #setPaddingRelative(int, int, int, int)} or thru |
| 12941 | * @attr ref android.R.styleable#View_paddingStart or |
| 12942 | * @attr ref android.R.styleable#View_paddingEnd |
| 12943 | * |
| 12944 | * @return true if the padding is relative or false if it is not. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12945 | */ |
| 12946 | public boolean isPaddingRelative() { |
| 12947 | return mUserPaddingRelative; |
| 12948 | } |
| 12949 | |
| 12950 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12951 | * Changes the selection state of this view. A view can be selected or not. |
| 12952 | * Note that selection is not the same as focus. Views are typically |
| 12953 | * selected in the context of an AdapterView like ListView or GridView; |
| 12954 | * the selected view is the view that is highlighted. |
| 12955 | * |
| 12956 | * @param selected true if the view must be selected, false otherwise |
| 12957 | */ |
| 12958 | public void setSelected(boolean selected) { |
| 12959 | if (((mPrivateFlags & SELECTED) != 0) != selected) { |
| 12960 | mPrivateFlags = (mPrivateFlags & ~SELECTED) | (selected ? SELECTED : 0); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 12961 | if (!selected) resetPressedState(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 12962 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12963 | refreshDrawableState(); |
| 12964 | dispatchSetSelected(selected); |
| 12965 | } |
| 12966 | } |
| 12967 | |
| 12968 | /** |
| 12969 | * Dispatch setSelected to all of this View's children. |
| 12970 | * |
| 12971 | * @see #setSelected(boolean) |
| 12972 | * |
| 12973 | * @param selected The new selected state |
| 12974 | */ |
| 12975 | protected void dispatchSetSelected(boolean selected) { |
| 12976 | } |
| 12977 | |
| 12978 | /** |
| 12979 | * Indicates the selection state of this view. |
| 12980 | * |
| 12981 | * @return true if the view is selected, false otherwise |
| 12982 | */ |
| 12983 | @ViewDebug.ExportedProperty |
| 12984 | public boolean isSelected() { |
| 12985 | return (mPrivateFlags & SELECTED) != 0; |
| 12986 | } |
| 12987 | |
| 12988 | /** |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 12989 | * Changes the activated state of this view. A view can be activated or not. |
| 12990 | * Note that activation is not the same as selection. Selection is |
| 12991 | * a transient property, representing the view (hierarchy) the user is |
| 12992 | * currently interacting with. Activation is a longer-term state that the |
| 12993 | * user can move views in and out of. For example, in a list view with |
| 12994 | * single or multiple selection enabled, the views in the current selection |
| 12995 | * set are activated. (Um, yeah, we are deeply sorry about the terminology |
| 12996 | * here.) The activated state is propagated down to children of the view it |
| 12997 | * is set on. |
| 12998 | * |
| 12999 | * @param activated true if the view must be activated, false otherwise |
| 13000 | */ |
| 13001 | public void setActivated(boolean activated) { |
| 13002 | if (((mPrivateFlags & ACTIVATED) != 0) != activated) { |
| 13003 | mPrivateFlags = (mPrivateFlags & ~ACTIVATED) | (activated ? ACTIVATED : 0); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 13004 | invalidate(true); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 13005 | refreshDrawableState(); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 13006 | dispatchSetActivated(activated); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 13007 | } |
| 13008 | } |
| 13009 | |
| 13010 | /** |
| 13011 | * Dispatch setActivated to all of this View's children. |
| 13012 | * |
| 13013 | * @see #setActivated(boolean) |
| 13014 | * |
| 13015 | * @param activated The new activated state |
| 13016 | */ |
| 13017 | protected void dispatchSetActivated(boolean activated) { |
| 13018 | } |
| 13019 | |
| 13020 | /** |
| 13021 | * Indicates the activation state of this view. |
| 13022 | * |
| 13023 | * @return true if the view is activated, false otherwise |
| 13024 | */ |
| 13025 | @ViewDebug.ExportedProperty |
| 13026 | public boolean isActivated() { |
| 13027 | return (mPrivateFlags & ACTIVATED) != 0; |
| 13028 | } |
| 13029 | |
| 13030 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13031 | * Returns the ViewTreeObserver for this view's hierarchy. The view tree |
| 13032 | * observer can be used to get notifications when global events, like |
| 13033 | * layout, happen. |
| 13034 | * |
| 13035 | * The returned ViewTreeObserver observer is not guaranteed to remain |
| 13036 | * valid for the lifetime of this View. If the caller of this method keeps |
| 13037 | * a long-lived reference to ViewTreeObserver, it should always check for |
| 13038 | * the return value of {@link ViewTreeObserver#isAlive()}. |
| 13039 | * |
| 13040 | * @return The ViewTreeObserver for this view's hierarchy. |
| 13041 | */ |
| 13042 | public ViewTreeObserver getViewTreeObserver() { |
| 13043 | if (mAttachInfo != null) { |
| 13044 | return mAttachInfo.mTreeObserver; |
| 13045 | } |
| 13046 | if (mFloatingTreeObserver == null) { |
| 13047 | mFloatingTreeObserver = new ViewTreeObserver(); |
| 13048 | } |
| 13049 | return mFloatingTreeObserver; |
| 13050 | } |
| 13051 | |
| 13052 | /** |
| 13053 | * <p>Finds the topmost view in the current view hierarchy.</p> |
| 13054 | * |
| 13055 | * @return the topmost view containing this view |
| 13056 | */ |
| 13057 | public View getRootView() { |
| 13058 | if (mAttachInfo != null) { |
| 13059 | final View v = mAttachInfo.mRootView; |
| 13060 | if (v != null) { |
| 13061 | return v; |
| 13062 | } |
| 13063 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13064 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13065 | View parent = this; |
| 13066 | |
| 13067 | while (parent.mParent != null && parent.mParent instanceof View) { |
| 13068 | parent = (View) parent.mParent; |
| 13069 | } |
| 13070 | |
| 13071 | return parent; |
| 13072 | } |
| 13073 | |
| 13074 | /** |
| 13075 | * <p>Computes the coordinates of this view on the screen. The argument |
| 13076 | * must be an array of two integers. After the method returns, the array |
| 13077 | * contains the x and y location in that order.</p> |
| 13078 | * |
| 13079 | * @param location an array of two integers in which to hold the coordinates |
| 13080 | */ |
| 13081 | public void getLocationOnScreen(int[] location) { |
| 13082 | getLocationInWindow(location); |
| 13083 | |
| 13084 | final AttachInfo info = mAttachInfo; |
Romain Guy | 779398e | 2009-06-16 13:17:50 -0700 | [diff] [blame] | 13085 | if (info != null) { |
| 13086 | location[0] += info.mWindowLeft; |
| 13087 | location[1] += info.mWindowTop; |
| 13088 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13089 | } |
| 13090 | |
| 13091 | /** |
| 13092 | * <p>Computes the coordinates of this view in its window. The argument |
| 13093 | * must be an array of two integers. After the method returns, the array |
| 13094 | * contains the x and y location in that order.</p> |
| 13095 | * |
| 13096 | * @param location an array of two integers in which to hold the coordinates |
| 13097 | */ |
| 13098 | public void getLocationInWindow(int[] location) { |
| 13099 | if (location == null || location.length < 2) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 13100 | throw new IllegalArgumentException("location must be an array of two integers"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13101 | } |
| 13102 | |
Gilles Debunne | 6583ce5 | 2011-12-06 18:09:02 -0800 | [diff] [blame] | 13103 | if (mAttachInfo == null) { |
| 13104 | // When the view is not attached to a window, this method does not make sense |
| 13105 | location[0] = location[1] = 0; |
| 13106 | return; |
| 13107 | } |
| 13108 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 13109 | float[] position = mAttachInfo.mTmpTransformLocation; |
| 13110 | position[0] = position[1] = 0.0f; |
| 13111 | |
| 13112 | if (!hasIdentityMatrix()) { |
| 13113 | getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 13114 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13115 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 13116 | position[0] += mLeft; |
| 13117 | position[1] += mTop; |
| 13118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13119 | ViewParent viewParent = mParent; |
| 13120 | while (viewParent instanceof View) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 13121 | final View view = (View) viewParent; |
| 13122 | |
| 13123 | position[0] -= view.mScrollX; |
| 13124 | position[1] -= view.mScrollY; |
| 13125 | |
| 13126 | if (!view.hasIdentityMatrix()) { |
| 13127 | view.getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 13128 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 13129 | |
| 13130 | position[0] += view.mLeft; |
| 13131 | position[1] += view.mTop; |
| 13132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13133 | viewParent = view.mParent; |
| 13134 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13135 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 13136 | if (viewParent instanceof ViewRootImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13137 | // *cough* |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 13138 | final ViewRootImpl vr = (ViewRootImpl) viewParent; |
| 13139 | position[1] -= vr.mCurScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13140 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 13141 | |
| 13142 | location[0] = (int) (position[0] + 0.5f); |
| 13143 | location[1] = (int) (position[1] + 0.5f); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13144 | } |
| 13145 | |
| 13146 | /** |
| 13147 | * {@hide} |
| 13148 | * @param id the id of the view to be found |
| 13149 | * @return the view of the specified id, null if cannot be found |
| 13150 | */ |
| 13151 | protected View findViewTraversal(int id) { |
| 13152 | if (id == mID) { |
| 13153 | return this; |
| 13154 | } |
| 13155 | return null; |
| 13156 | } |
| 13157 | |
| 13158 | /** |
| 13159 | * {@hide} |
| 13160 | * @param tag the tag of the view to be found |
| 13161 | * @return the view of specified tag, null if cannot be found |
| 13162 | */ |
| 13163 | protected View findViewWithTagTraversal(Object tag) { |
| 13164 | if (tag != null && tag.equals(mTag)) { |
| 13165 | return this; |
| 13166 | } |
| 13167 | return null; |
| 13168 | } |
| 13169 | |
| 13170 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 13171 | * {@hide} |
| 13172 | * @param predicate The predicate to evaluate. |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 13173 | * @param childToSkip If not null, ignores this child during the recursive traversal. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 13174 | * @return The first view that matches the predicate or null. |
| 13175 | */ |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 13176 | protected View findViewByPredicateTraversal(Predicate<View> predicate, View childToSkip) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 13177 | if (predicate.apply(this)) { |
| 13178 | return this; |
| 13179 | } |
| 13180 | return null; |
| 13181 | } |
| 13182 | |
| 13183 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13184 | * Look for a child view with the given id. If this view has the given |
| 13185 | * id, return this view. |
| 13186 | * |
| 13187 | * @param id The id to search for. |
| 13188 | * @return The view that has the given id in the hierarchy or null |
| 13189 | */ |
| 13190 | public final View findViewById(int id) { |
| 13191 | if (id < 0) { |
| 13192 | return null; |
| 13193 | } |
| 13194 | return findViewTraversal(id); |
| 13195 | } |
| 13196 | |
| 13197 | /** |
Svetoslav Ganov | 2cdedff | 2011-10-03 14:18:42 -0700 | [diff] [blame] | 13198 | * Finds a view by its unuque and stable accessibility id. |
| 13199 | * |
| 13200 | * @param accessibilityId The searched accessibility id. |
| 13201 | * @return The found view. |
| 13202 | */ |
| 13203 | final View findViewByAccessibilityId(int accessibilityId) { |
| 13204 | if (accessibilityId < 0) { |
| 13205 | return null; |
| 13206 | } |
| 13207 | return findViewByAccessibilityIdTraversal(accessibilityId); |
| 13208 | } |
| 13209 | |
| 13210 | /** |
| 13211 | * Performs the traversal to find a view by its unuque and stable accessibility id. |
| 13212 | * |
| 13213 | * <strong>Note:</strong>This method does not stop at the root namespace |
| 13214 | * boundary since the user can touch the screen at an arbitrary location |
| 13215 | * potentially crossing the root namespace bounday which will send an |
| 13216 | * accessibility event to accessibility services and they should be able |
| 13217 | * to obtain the event source. Also accessibility ids are guaranteed to be |
| 13218 | * unique in the window. |
| 13219 | * |
| 13220 | * @param accessibilityId The accessibility id. |
| 13221 | * @return The found view. |
| 13222 | */ |
| 13223 | View findViewByAccessibilityIdTraversal(int accessibilityId) { |
| 13224 | if (getAccessibilityViewId() == accessibilityId) { |
| 13225 | return this; |
| 13226 | } |
| 13227 | return null; |
| 13228 | } |
| 13229 | |
| 13230 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13231 | * Look for a child view with the given tag. If this view has the given |
| 13232 | * tag, return this view. |
| 13233 | * |
| 13234 | * @param tag The tag to search for, using "tag.equals(getTag())". |
| 13235 | * @return The View that has the given tag in the hierarchy or null |
| 13236 | */ |
| 13237 | public final View findViewWithTag(Object tag) { |
| 13238 | if (tag == null) { |
| 13239 | return null; |
| 13240 | } |
| 13241 | return findViewWithTagTraversal(tag); |
| 13242 | } |
| 13243 | |
| 13244 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 13245 | * {@hide} |
| 13246 | * Look for a child view that matches the specified predicate. |
| 13247 | * If this view matches the predicate, return this view. |
| 13248 | * |
| 13249 | * @param predicate The predicate to evaluate. |
| 13250 | * @return The first view that matches the predicate or null. |
| 13251 | */ |
| 13252 | public final View findViewByPredicate(Predicate<View> predicate) { |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 13253 | return findViewByPredicateTraversal(predicate, null); |
| 13254 | } |
| 13255 | |
| 13256 | /** |
| 13257 | * {@hide} |
| 13258 | * Look for a child view that matches the specified predicate, |
| 13259 | * starting with the specified view and its descendents and then |
| 13260 | * recusively searching the ancestors and siblings of that view |
| 13261 | * until this view is reached. |
| 13262 | * |
| 13263 | * This method is useful in cases where the predicate does not match |
| 13264 | * a single unique view (perhaps multiple views use the same id) |
| 13265 | * and we are trying to find the view that is "closest" in scope to the |
| 13266 | * starting view. |
| 13267 | * |
| 13268 | * @param start The view to start from. |
| 13269 | * @param predicate The predicate to evaluate. |
| 13270 | * @return The first view that matches the predicate or null. |
| 13271 | */ |
| 13272 | public final View findViewByPredicateInsideOut(View start, Predicate<View> predicate) { |
| 13273 | View childToSkip = null; |
| 13274 | for (;;) { |
| 13275 | View view = start.findViewByPredicateTraversal(predicate, childToSkip); |
| 13276 | if (view != null || start == this) { |
| 13277 | return view; |
| 13278 | } |
| 13279 | |
| 13280 | ViewParent parent = start.getParent(); |
| 13281 | if (parent == null || !(parent instanceof View)) { |
| 13282 | return null; |
| 13283 | } |
| 13284 | |
| 13285 | childToSkip = start; |
| 13286 | start = (View) parent; |
| 13287 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 13288 | } |
| 13289 | |
| 13290 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13291 | * Sets the identifier for this view. The identifier does not have to be |
| 13292 | * unique in this view's hierarchy. The identifier should be a positive |
| 13293 | * number. |
| 13294 | * |
| 13295 | * @see #NO_ID |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 13296 | * @see #getId() |
| 13297 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13298 | * |
| 13299 | * @param id a number used to identify the view |
| 13300 | * |
| 13301 | * @attr ref android.R.styleable#View_id |
| 13302 | */ |
| 13303 | public void setId(int id) { |
| 13304 | mID = id; |
| 13305 | } |
| 13306 | |
| 13307 | /** |
| 13308 | * {@hide} |
| 13309 | * |
| 13310 | * @param isRoot true if the view belongs to the root namespace, false |
| 13311 | * otherwise |
| 13312 | */ |
| 13313 | public void setIsRootNamespace(boolean isRoot) { |
| 13314 | if (isRoot) { |
| 13315 | mPrivateFlags |= IS_ROOT_NAMESPACE; |
| 13316 | } else { |
| 13317 | mPrivateFlags &= ~IS_ROOT_NAMESPACE; |
| 13318 | } |
| 13319 | } |
| 13320 | |
| 13321 | /** |
| 13322 | * {@hide} |
| 13323 | * |
| 13324 | * @return true if the view belongs to the root namespace, false otherwise |
| 13325 | */ |
| 13326 | public boolean isRootNamespace() { |
| 13327 | return (mPrivateFlags&IS_ROOT_NAMESPACE) != 0; |
| 13328 | } |
| 13329 | |
| 13330 | /** |
| 13331 | * Returns this view's identifier. |
| 13332 | * |
| 13333 | * @return a positive integer used to identify the view or {@link #NO_ID} |
| 13334 | * if the view has no ID |
| 13335 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 13336 | * @see #setId(int) |
| 13337 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13338 | * @attr ref android.R.styleable#View_id |
| 13339 | */ |
| 13340 | @ViewDebug.CapturedViewProperty |
| 13341 | public int getId() { |
| 13342 | return mID; |
| 13343 | } |
| 13344 | |
| 13345 | /** |
| 13346 | * Returns this view's tag. |
| 13347 | * |
| 13348 | * @return the Object stored in this view as a tag |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13349 | * |
| 13350 | * @see #setTag(Object) |
| 13351 | * @see #getTag(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13352 | */ |
| 13353 | @ViewDebug.ExportedProperty |
| 13354 | public Object getTag() { |
| 13355 | return mTag; |
| 13356 | } |
| 13357 | |
| 13358 | /** |
| 13359 | * Sets the tag associated with this view. A tag can be used to mark |
| 13360 | * a view in its hierarchy and does not have to be unique within the |
| 13361 | * hierarchy. Tags can also be used to store data within a view without |
| 13362 | * resorting to another data structure. |
| 13363 | * |
| 13364 | * @param tag an Object to tag the view with |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13365 | * |
| 13366 | * @see #getTag() |
| 13367 | * @see #setTag(int, Object) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13368 | */ |
| 13369 | public void setTag(final Object tag) { |
| 13370 | mTag = tag; |
| 13371 | } |
| 13372 | |
| 13373 | /** |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13374 | * Returns the tag associated with this view and the specified key. |
| 13375 | * |
| 13376 | * @param key The key identifying the tag |
| 13377 | * |
| 13378 | * @return the Object stored in this view as a tag |
| 13379 | * |
| 13380 | * @see #setTag(int, Object) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13381 | * @see #getTag() |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13382 | */ |
| 13383 | public Object getTag(int key) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 13384 | if (mKeyedTags != null) return mKeyedTags.get(key); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13385 | return null; |
| 13386 | } |
| 13387 | |
| 13388 | /** |
| 13389 | * Sets a tag associated with this view and a key. A tag can be used |
| 13390 | * to mark a view in its hierarchy and does not have to be unique within |
| 13391 | * the hierarchy. Tags can also be used to store data within a view |
| 13392 | * without resorting to another data structure. |
| 13393 | * |
| 13394 | * The specified key should be an id declared in the resources of the |
Scott Main | dfe5c20 | 2010-06-08 15:54:52 -0700 | [diff] [blame] | 13395 | * application to ensure it is unique (see the <a |
| 13396 | * href={@docRoot}guide/topics/resources/more-resources.html#Id">ID resource type</a>). |
| 13397 | * Keys identified as belonging to |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13398 | * the Android framework or not associated with any package will cause |
| 13399 | * an {@link IllegalArgumentException} to be thrown. |
| 13400 | * |
| 13401 | * @param key The key identifying the tag |
| 13402 | * @param tag An Object to tag the view with |
| 13403 | * |
| 13404 | * @throws IllegalArgumentException If they specified key is not valid |
| 13405 | * |
| 13406 | * @see #setTag(Object) |
| 13407 | * @see #getTag(int) |
| 13408 | */ |
| 13409 | public void setTag(int key, final Object tag) { |
| 13410 | // If the package id is 0x00 or 0x01, it's either an undefined package |
| 13411 | // or a framework id |
| 13412 | if ((key >>> 24) < 2) { |
| 13413 | throw new IllegalArgumentException("The key must be an application-specific " |
| 13414 | + "resource id."); |
| 13415 | } |
| 13416 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 13417 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13418 | } |
| 13419 | |
| 13420 | /** |
| 13421 | * Variation of {@link #setTag(int, Object)} that enforces the key to be a |
| 13422 | * framework id. |
| 13423 | * |
| 13424 | * @hide |
| 13425 | */ |
| 13426 | public void setTagInternal(int key, Object tag) { |
| 13427 | if ((key >>> 24) != 0x1) { |
| 13428 | throw new IllegalArgumentException("The key must be a framework-specific " |
| 13429 | + "resource id."); |
| 13430 | } |
| 13431 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 13432 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13433 | } |
| 13434 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 13435 | private void setKeyedTag(int key, Object tag) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 13436 | if (mKeyedTags == null) { |
| 13437 | mKeyedTags = new SparseArray<Object>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13438 | } |
| 13439 | |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 13440 | mKeyedTags.put(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13441 | } |
| 13442 | |
| 13443 | /** |
Romain Guy | 13922e0 | 2009-05-12 17:56:14 -0700 | [diff] [blame] | 13444 | * @param consistency The type of consistency. See ViewDebug for more information. |
| 13445 | * |
| 13446 | * @hide |
| 13447 | */ |
| 13448 | protected boolean dispatchConsistencyCheck(int consistency) { |
| 13449 | return onConsistencyCheck(consistency); |
| 13450 | } |
| 13451 | |
| 13452 | /** |
| 13453 | * Method that subclasses should implement to check their consistency. The type of |
| 13454 | * consistency check is indicated by the bit field passed as a parameter. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13455 | * |
Romain Guy | 13922e0 | 2009-05-12 17:56:14 -0700 | [diff] [blame] | 13456 | * @param consistency The type of consistency. See ViewDebug for more information. |
| 13457 | * |
| 13458 | * @throws IllegalStateException if the view is in an inconsistent state. |
| 13459 | * |
| 13460 | * @hide |
| 13461 | */ |
| 13462 | protected boolean onConsistencyCheck(int consistency) { |
| 13463 | boolean result = true; |
| 13464 | |
| 13465 | final boolean checkLayout = (consistency & ViewDebug.CONSISTENCY_LAYOUT) != 0; |
| 13466 | final boolean checkDrawing = (consistency & ViewDebug.CONSISTENCY_DRAWING) != 0; |
| 13467 | |
| 13468 | if (checkLayout) { |
| 13469 | if (getParent() == null) { |
| 13470 | result = false; |
| 13471 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 13472 | "View " + this + " does not have a parent."); |
| 13473 | } |
| 13474 | |
| 13475 | if (mAttachInfo == null) { |
| 13476 | result = false; |
| 13477 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 13478 | "View " + this + " is not attached to a window."); |
| 13479 | } |
| 13480 | } |
| 13481 | |
| 13482 | if (checkDrawing) { |
| 13483 | // Do not check the DIRTY/DRAWN flags because views can call invalidate() |
| 13484 | // from their draw() method |
| 13485 | |
| 13486 | if ((mPrivateFlags & DRAWN) != DRAWN && |
| 13487 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) { |
| 13488 | result = false; |
| 13489 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 13490 | "View " + this + " was invalidated but its drawing cache is valid."); |
| 13491 | } |
| 13492 | } |
| 13493 | |
| 13494 | return result; |
| 13495 | } |
| 13496 | |
| 13497 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13498 | * Prints information about this view in the log output, with the tag |
| 13499 | * {@link #VIEW_LOG_TAG}. |
| 13500 | * |
| 13501 | * @hide |
| 13502 | */ |
| 13503 | public void debug() { |
| 13504 | debug(0); |
| 13505 | } |
| 13506 | |
| 13507 | /** |
| 13508 | * Prints information about this view in the log output, with the tag |
| 13509 | * {@link #VIEW_LOG_TAG}. Each line in the output is preceded with an |
| 13510 | * indentation defined by the <code>depth</code>. |
| 13511 | * |
| 13512 | * @param depth the indentation level |
| 13513 | * |
| 13514 | * @hide |
| 13515 | */ |
| 13516 | protected void debug(int depth) { |
| 13517 | String output = debugIndent(depth - 1); |
| 13518 | |
| 13519 | output += "+ " + this; |
| 13520 | int id = getId(); |
| 13521 | if (id != -1) { |
| 13522 | output += " (id=" + id + ")"; |
| 13523 | } |
| 13524 | Object tag = getTag(); |
| 13525 | if (tag != null) { |
| 13526 | output += " (tag=" + tag + ")"; |
| 13527 | } |
| 13528 | Log.d(VIEW_LOG_TAG, output); |
| 13529 | |
| 13530 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 13531 | output = debugIndent(depth) + " FOCUSED"; |
| 13532 | Log.d(VIEW_LOG_TAG, output); |
| 13533 | } |
| 13534 | |
| 13535 | output = debugIndent(depth); |
| 13536 | output += "frame={" + mLeft + ", " + mTop + ", " + mRight |
| 13537 | + ", " + mBottom + "} scroll={" + mScrollX + ", " + mScrollY |
| 13538 | + "} "; |
| 13539 | Log.d(VIEW_LOG_TAG, output); |
| 13540 | |
| 13541 | if (mPaddingLeft != 0 || mPaddingTop != 0 || mPaddingRight != 0 |
| 13542 | || mPaddingBottom != 0) { |
| 13543 | output = debugIndent(depth); |
| 13544 | output += "padding={" + mPaddingLeft + ", " + mPaddingTop |
| 13545 | + ", " + mPaddingRight + ", " + mPaddingBottom + "}"; |
| 13546 | Log.d(VIEW_LOG_TAG, output); |
| 13547 | } |
| 13548 | |
| 13549 | output = debugIndent(depth); |
| 13550 | output += "mMeasureWidth=" + mMeasuredWidth + |
| 13551 | " mMeasureHeight=" + mMeasuredHeight; |
| 13552 | Log.d(VIEW_LOG_TAG, output); |
| 13553 | |
| 13554 | output = debugIndent(depth); |
| 13555 | if (mLayoutParams == null) { |
| 13556 | output += "BAD! no layout params"; |
| 13557 | } else { |
| 13558 | output = mLayoutParams.debug(output); |
| 13559 | } |
| 13560 | Log.d(VIEW_LOG_TAG, output); |
| 13561 | |
| 13562 | output = debugIndent(depth); |
| 13563 | output += "flags={"; |
| 13564 | output += View.printFlags(mViewFlags); |
| 13565 | output += "}"; |
| 13566 | Log.d(VIEW_LOG_TAG, output); |
| 13567 | |
| 13568 | output = debugIndent(depth); |
| 13569 | output += "privateFlags={"; |
| 13570 | output += View.printPrivateFlags(mPrivateFlags); |
| 13571 | output += "}"; |
| 13572 | Log.d(VIEW_LOG_TAG, output); |
| 13573 | } |
| 13574 | |
| 13575 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 13576 | * Creates a string of whitespaces used for indentation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13577 | * |
| 13578 | * @param depth the indentation level |
| 13579 | * @return a String containing (depth * 2 + 3) * 2 white spaces |
| 13580 | * |
| 13581 | * @hide |
| 13582 | */ |
| 13583 | protected static String debugIndent(int depth) { |
| 13584 | StringBuilder spaces = new StringBuilder((depth * 2 + 3) * 2); |
| 13585 | for (int i = 0; i < (depth * 2) + 3; i++) { |
| 13586 | spaces.append(' ').append(' '); |
| 13587 | } |
| 13588 | return spaces.toString(); |
| 13589 | } |
| 13590 | |
| 13591 | /** |
| 13592 | * <p>Return the offset of the widget's text baseline from the widget's top |
| 13593 | * boundary. If this widget does not support baseline alignment, this |
| 13594 | * method returns -1. </p> |
| 13595 | * |
| 13596 | * @return the offset of the baseline within the widget's bounds or -1 |
| 13597 | * if baseline alignment is not supported |
| 13598 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 13599 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13600 | public int getBaseline() { |
| 13601 | return -1; |
| 13602 | } |
| 13603 | |
| 13604 | /** |
| 13605 | * Call this when something has changed which has invalidated the |
| 13606 | * layout of this view. This will schedule a layout pass of the view |
| 13607 | * tree. |
| 13608 | */ |
| 13609 | public void requestLayout() { |
| 13610 | if (ViewDebug.TRACE_HIERARCHY) { |
| 13611 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.REQUEST_LAYOUT); |
| 13612 | } |
| 13613 | |
| 13614 | mPrivateFlags |= FORCE_LAYOUT; |
Chet Haase | 5af048c | 2011-01-24 17:00:32 -0800 | [diff] [blame] | 13615 | mPrivateFlags |= INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13616 | |
Fabrice Di Meglio | d794aca | 2011-07-22 18:19:36 -0700 | [diff] [blame] | 13617 | if (mParent != null) { |
| 13618 | if (mLayoutParams != null) { |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 13619 | mLayoutParams.onResolveLayoutDirection(getResolvedLayoutDirection()); |
Fabrice Di Meglio | d794aca | 2011-07-22 18:19:36 -0700 | [diff] [blame] | 13620 | } |
| 13621 | if (!mParent.isLayoutRequested()) { |
| 13622 | mParent.requestLayout(); |
| 13623 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13624 | } |
| 13625 | } |
| 13626 | |
| 13627 | /** |
| 13628 | * Forces this view to be laid out during the next layout pass. |
| 13629 | * This method does not call requestLayout() or forceLayout() |
| 13630 | * on the parent. |
| 13631 | */ |
| 13632 | public void forceLayout() { |
| 13633 | mPrivateFlags |= FORCE_LAYOUT; |
Chet Haase | 5af048c | 2011-01-24 17:00:32 -0800 | [diff] [blame] | 13634 | mPrivateFlags |= INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13635 | } |
| 13636 | |
| 13637 | /** |
| 13638 | * <p> |
| 13639 | * This is called to find out how big a view should be. The parent |
| 13640 | * supplies constraint information in the width and height parameters. |
| 13641 | * </p> |
| 13642 | * |
| 13643 | * <p> |
Romain Guy | 967e2bf | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 13644 | * The actual measurement work of a view is performed in |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13645 | * {@link #onMeasure(int, int)}, called by this method. Therefore, only |
Romain Guy | 967e2bf | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 13646 | * {@link #onMeasure(int, int)} can and must be overridden by subclasses. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13647 | * </p> |
| 13648 | * |
| 13649 | * |
| 13650 | * @param widthMeasureSpec Horizontal space requirements as imposed by the |
| 13651 | * parent |
| 13652 | * @param heightMeasureSpec Vertical space requirements as imposed by the |
| 13653 | * parent |
| 13654 | * |
| 13655 | * @see #onMeasure(int, int) |
| 13656 | */ |
| 13657 | public final void measure(int widthMeasureSpec, int heightMeasureSpec) { |
| 13658 | if ((mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT || |
| 13659 | widthMeasureSpec != mOldWidthMeasureSpec || |
| 13660 | heightMeasureSpec != mOldHeightMeasureSpec) { |
| 13661 | |
| 13662 | // first clears the measured dimension flag |
| 13663 | mPrivateFlags &= ~MEASURED_DIMENSION_SET; |
| 13664 | |
| 13665 | if (ViewDebug.TRACE_HIERARCHY) { |
| 13666 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_MEASURE); |
| 13667 | } |
| 13668 | |
| 13669 | // measure ourselves, this should set the measured dimension flag back |
| 13670 | onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 13671 | |
| 13672 | // flag not set, setMeasuredDimension() was not invoked, we raise |
| 13673 | // an exception to warn the developer |
| 13674 | if ((mPrivateFlags & MEASURED_DIMENSION_SET) != MEASURED_DIMENSION_SET) { |
| 13675 | throw new IllegalStateException("onMeasure() did not set the" |
| 13676 | + " measured dimension by calling" |
| 13677 | + " setMeasuredDimension()"); |
| 13678 | } |
| 13679 | |
| 13680 | mPrivateFlags |= LAYOUT_REQUIRED; |
| 13681 | } |
| 13682 | |
| 13683 | mOldWidthMeasureSpec = widthMeasureSpec; |
| 13684 | mOldHeightMeasureSpec = heightMeasureSpec; |
| 13685 | } |
| 13686 | |
| 13687 | /** |
| 13688 | * <p> |
| 13689 | * Measure the view and its content to determine the measured width and the |
| 13690 | * measured height. This method is invoked by {@link #measure(int, int)} and |
| 13691 | * should be overriden by subclasses to provide accurate and efficient |
| 13692 | * measurement of their contents. |
| 13693 | * </p> |
| 13694 | * |
| 13695 | * <p> |
| 13696 | * <strong>CONTRACT:</strong> When overriding this method, you |
| 13697 | * <em>must</em> call {@link #setMeasuredDimension(int, int)} to store the |
| 13698 | * measured width and height of this view. Failure to do so will trigger an |
| 13699 | * <code>IllegalStateException</code>, thrown by |
| 13700 | * {@link #measure(int, int)}. Calling the superclass' |
| 13701 | * {@link #onMeasure(int, int)} is a valid use. |
| 13702 | * </p> |
| 13703 | * |
| 13704 | * <p> |
| 13705 | * The base class implementation of measure defaults to the background size, |
| 13706 | * unless a larger size is allowed by the MeasureSpec. Subclasses should |
| 13707 | * override {@link #onMeasure(int, int)} to provide better measurements of |
| 13708 | * their content. |
| 13709 | * </p> |
| 13710 | * |
| 13711 | * <p> |
| 13712 | * If this method is overridden, it is the subclass's responsibility to make |
| 13713 | * sure the measured height and width are at least the view's minimum height |
| 13714 | * and width ({@link #getSuggestedMinimumHeight()} and |
| 13715 | * {@link #getSuggestedMinimumWidth()}). |
| 13716 | * </p> |
| 13717 | * |
| 13718 | * @param widthMeasureSpec horizontal space requirements as imposed by the parent. |
| 13719 | * The requirements are encoded with |
| 13720 | * {@link android.view.View.MeasureSpec}. |
| 13721 | * @param heightMeasureSpec vertical space requirements as imposed by the parent. |
| 13722 | * The requirements are encoded with |
| 13723 | * {@link android.view.View.MeasureSpec}. |
| 13724 | * |
| 13725 | * @see #getMeasuredWidth() |
| 13726 | * @see #getMeasuredHeight() |
| 13727 | * @see #setMeasuredDimension(int, int) |
| 13728 | * @see #getSuggestedMinimumHeight() |
| 13729 | * @see #getSuggestedMinimumWidth() |
| 13730 | * @see android.view.View.MeasureSpec#getMode(int) |
| 13731 | * @see android.view.View.MeasureSpec#getSize(int) |
| 13732 | */ |
| 13733 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 13734 | setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), |
| 13735 | getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec)); |
| 13736 | } |
| 13737 | |
| 13738 | /** |
| 13739 | * <p>This mehod must be called by {@link #onMeasure(int, int)} to store the |
| 13740 | * measured width and measured height. Failing to do so will trigger an |
| 13741 | * exception at measurement time.</p> |
| 13742 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 13743 | * @param measuredWidth The measured width of this view. May be a complex |
| 13744 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 13745 | * {@link #MEASURED_STATE_TOO_SMALL}. |
| 13746 | * @param measuredHeight The measured height of this view. May be a complex |
| 13747 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 13748 | * {@link #MEASURED_STATE_TOO_SMALL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13749 | */ |
| 13750 | protected final void setMeasuredDimension(int measuredWidth, int measuredHeight) { |
| 13751 | mMeasuredWidth = measuredWidth; |
| 13752 | mMeasuredHeight = measuredHeight; |
| 13753 | |
| 13754 | mPrivateFlags |= MEASURED_DIMENSION_SET; |
| 13755 | } |
| 13756 | |
| 13757 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 13758 | * Merge two states as returned by {@link #getMeasuredState()}. |
| 13759 | * @param curState The current state as returned from a view or the result |
| 13760 | * of combining multiple views. |
| 13761 | * @param newState The new view state to combine. |
| 13762 | * @return Returns a new integer reflecting the combination of the two |
| 13763 | * states. |
| 13764 | */ |
| 13765 | public static int combineMeasuredStates(int curState, int newState) { |
| 13766 | return curState | newState; |
| 13767 | } |
| 13768 | |
| 13769 | /** |
| 13770 | * Version of {@link #resolveSizeAndState(int, int, int)} |
| 13771 | * returning only the {@link #MEASURED_SIZE_MASK} bits of the result. |
| 13772 | */ |
| 13773 | public static int resolveSize(int size, int measureSpec) { |
| 13774 | return resolveSizeAndState(size, measureSpec, 0) & MEASURED_SIZE_MASK; |
| 13775 | } |
| 13776 | |
| 13777 | /** |
| 13778 | * Utility to reconcile a desired size and state, with constraints imposed |
| 13779 | * by a MeasureSpec. Will take the desired size, unless a different size |
| 13780 | * is imposed by the constraints. The returned value is a compound integer, |
| 13781 | * with the resolved size in the {@link #MEASURED_SIZE_MASK} bits and |
| 13782 | * optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the resulting |
| 13783 | * size is smaller than the size the view wants to be. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13784 | * |
| 13785 | * @param size How big the view wants to be |
| 13786 | * @param measureSpec Constraints imposed by the parent |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 13787 | * @return Size information bit mask as defined by |
| 13788 | * {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13789 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 13790 | public static int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13791 | int result = size; |
| 13792 | int specMode = MeasureSpec.getMode(measureSpec); |
| 13793 | int specSize = MeasureSpec.getSize(measureSpec); |
| 13794 | switch (specMode) { |
| 13795 | case MeasureSpec.UNSPECIFIED: |
| 13796 | result = size; |
| 13797 | break; |
| 13798 | case MeasureSpec.AT_MOST: |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 13799 | if (specSize < size) { |
| 13800 | result = specSize | MEASURED_STATE_TOO_SMALL; |
| 13801 | } else { |
| 13802 | result = size; |
| 13803 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13804 | break; |
| 13805 | case MeasureSpec.EXACTLY: |
| 13806 | result = specSize; |
| 13807 | break; |
| 13808 | } |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 13809 | return result | (childMeasuredState&MEASURED_STATE_MASK); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13810 | } |
| 13811 | |
| 13812 | /** |
| 13813 | * Utility to return a default size. Uses the supplied size if the |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 13814 | * MeasureSpec imposed no constraints. Will get larger if allowed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13815 | * by the MeasureSpec. |
| 13816 | * |
| 13817 | * @param size Default size for this view |
| 13818 | * @param measureSpec Constraints imposed by the parent |
| 13819 | * @return The size this view should be. |
| 13820 | */ |
| 13821 | public static int getDefaultSize(int size, int measureSpec) { |
| 13822 | int result = size; |
| 13823 | int specMode = MeasureSpec.getMode(measureSpec); |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 13824 | int specSize = MeasureSpec.getSize(measureSpec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13825 | |
| 13826 | switch (specMode) { |
| 13827 | case MeasureSpec.UNSPECIFIED: |
| 13828 | result = size; |
| 13829 | break; |
| 13830 | case MeasureSpec.AT_MOST: |
| 13831 | case MeasureSpec.EXACTLY: |
| 13832 | result = specSize; |
| 13833 | break; |
| 13834 | } |
| 13835 | return result; |
| 13836 | } |
| 13837 | |
| 13838 | /** |
| 13839 | * Returns the suggested minimum height that the view should use. This |
| 13840 | * returns the maximum of the view's minimum height |
| 13841 | * and the background's minimum height |
| 13842 | * ({@link android.graphics.drawable.Drawable#getMinimumHeight()}). |
| 13843 | * <p> |
| 13844 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 13845 | * ensure the returned height is within the requirements of the parent. |
| 13846 | * |
| 13847 | * @return The suggested minimum height of the view. |
| 13848 | */ |
| 13849 | protected int getSuggestedMinimumHeight() { |
| 13850 | int suggestedMinHeight = mMinHeight; |
| 13851 | |
| 13852 | if (mBGDrawable != null) { |
| 13853 | final int bgMinHeight = mBGDrawable.getMinimumHeight(); |
| 13854 | if (suggestedMinHeight < bgMinHeight) { |
| 13855 | suggestedMinHeight = bgMinHeight; |
| 13856 | } |
| 13857 | } |
| 13858 | |
| 13859 | return suggestedMinHeight; |
| 13860 | } |
| 13861 | |
| 13862 | /** |
| 13863 | * Returns the suggested minimum width that the view should use. This |
| 13864 | * returns the maximum of the view's minimum width) |
| 13865 | * and the background's minimum width |
| 13866 | * ({@link android.graphics.drawable.Drawable#getMinimumWidth()}). |
| 13867 | * <p> |
| 13868 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 13869 | * ensure the returned width is within the requirements of the parent. |
| 13870 | * |
| 13871 | * @return The suggested minimum width of the view. |
| 13872 | */ |
| 13873 | protected int getSuggestedMinimumWidth() { |
| 13874 | int suggestedMinWidth = mMinWidth; |
| 13875 | |
| 13876 | if (mBGDrawable != null) { |
| 13877 | final int bgMinWidth = mBGDrawable.getMinimumWidth(); |
| 13878 | if (suggestedMinWidth < bgMinWidth) { |
| 13879 | suggestedMinWidth = bgMinWidth; |
| 13880 | } |
| 13881 | } |
| 13882 | |
| 13883 | return suggestedMinWidth; |
| 13884 | } |
| 13885 | |
| 13886 | /** |
| 13887 | * Sets the minimum height of the view. It is not guaranteed the view will |
| 13888 | * be able to achieve this minimum height (for example, if its parent layout |
| 13889 | * constrains it with less available height). |
| 13890 | * |
| 13891 | * @param minHeight The minimum height the view will try to be. |
| 13892 | */ |
| 13893 | public void setMinimumHeight(int minHeight) { |
| 13894 | mMinHeight = minHeight; |
| 13895 | } |
| 13896 | |
| 13897 | /** |
| 13898 | * Sets the minimum width of the view. It is not guaranteed the view will |
| 13899 | * be able to achieve this minimum width (for example, if its parent layout |
| 13900 | * constrains it with less available width). |
| 13901 | * |
| 13902 | * @param minWidth The minimum width the view will try to be. |
| 13903 | */ |
| 13904 | public void setMinimumWidth(int minWidth) { |
| 13905 | mMinWidth = minWidth; |
| 13906 | } |
| 13907 | |
| 13908 | /** |
| 13909 | * Get the animation currently associated with this view. |
| 13910 | * |
| 13911 | * @return The animation that is currently playing or |
| 13912 | * scheduled to play for this view. |
| 13913 | */ |
| 13914 | public Animation getAnimation() { |
| 13915 | return mCurrentAnimation; |
| 13916 | } |
| 13917 | |
| 13918 | /** |
| 13919 | * Start the specified animation now. |
| 13920 | * |
| 13921 | * @param animation the animation to start now |
| 13922 | */ |
| 13923 | public void startAnimation(Animation animation) { |
| 13924 | animation.setStartTime(Animation.START_ON_FIRST_FRAME); |
| 13925 | setAnimation(animation); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 13926 | invalidateParentCaches(); |
| 13927 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13928 | } |
| 13929 | |
| 13930 | /** |
| 13931 | * Cancels any animations for this view. |
| 13932 | */ |
| 13933 | public void clearAnimation() { |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 13934 | if (mCurrentAnimation != null) { |
Romain Guy | b4a107d | 2010-02-09 18:50:08 -0800 | [diff] [blame] | 13935 | mCurrentAnimation.detach(); |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 13936 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13937 | mCurrentAnimation = null; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 13938 | invalidateParentIfNeeded(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13939 | } |
| 13940 | |
| 13941 | /** |
| 13942 | * Sets the next animation to play for this view. |
| 13943 | * If you want the animation to play immediately, use |
| 13944 | * startAnimation. This method provides allows fine-grained |
| 13945 | * control over the start time and invalidation, but you |
| 13946 | * must make sure that 1) the animation has a start time set, and |
| 13947 | * 2) the view will be invalidated when the animation is supposed to |
| 13948 | * start. |
| 13949 | * |
| 13950 | * @param animation The next animation, or null. |
| 13951 | */ |
| 13952 | public void setAnimation(Animation animation) { |
| 13953 | mCurrentAnimation = animation; |
| 13954 | if (animation != null) { |
| 13955 | animation.reset(); |
| 13956 | } |
| 13957 | } |
| 13958 | |
| 13959 | /** |
| 13960 | * Invoked by a parent ViewGroup to notify the start of the animation |
| 13961 | * currently associated with this view. If you override this method, |
| 13962 | * always call super.onAnimationStart(); |
| 13963 | * |
| 13964 | * @see #setAnimation(android.view.animation.Animation) |
| 13965 | * @see #getAnimation() |
| 13966 | */ |
| 13967 | protected void onAnimationStart() { |
| 13968 | mPrivateFlags |= ANIMATION_STARTED; |
| 13969 | } |
| 13970 | |
| 13971 | /** |
| 13972 | * Invoked by a parent ViewGroup to notify the end of the animation |
| 13973 | * currently associated with this view. If you override this method, |
| 13974 | * always call super.onAnimationEnd(); |
| 13975 | * |
| 13976 | * @see #setAnimation(android.view.animation.Animation) |
| 13977 | * @see #getAnimation() |
| 13978 | */ |
| 13979 | protected void onAnimationEnd() { |
| 13980 | mPrivateFlags &= ~ANIMATION_STARTED; |
| 13981 | } |
| 13982 | |
| 13983 | /** |
| 13984 | * Invoked if there is a Transform that involves alpha. Subclass that can |
| 13985 | * draw themselves with the specified alpha should return true, and then |
| 13986 | * respect that alpha when their onDraw() is called. If this returns false |
| 13987 | * then the view may be redirected to draw into an offscreen buffer to |
| 13988 | * fulfill the request, which will look fine, but may be slower than if the |
| 13989 | * subclass handles it internally. The default implementation returns false. |
| 13990 | * |
| 13991 | * @param alpha The alpha (0..255) to apply to the view's drawing |
| 13992 | * @return true if the view can draw with the specified alpha. |
| 13993 | */ |
| 13994 | protected boolean onSetAlpha(int alpha) { |
| 13995 | return false; |
| 13996 | } |
| 13997 | |
| 13998 | /** |
| 13999 | * This is used by the RootView to perform an optimization when |
| 14000 | * the view hierarchy contains one or several SurfaceView. |
| 14001 | * SurfaceView is always considered transparent, but its children are not, |
| 14002 | * therefore all View objects remove themselves from the global transparent |
| 14003 | * region (passed as a parameter to this function). |
| 14004 | * |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 14005 | * @param region The transparent region for this ViewAncestor (window). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14006 | * |
| 14007 | * @return Returns true if the effective visibility of the view at this |
| 14008 | * point is opaque, regardless of the transparent region; returns false |
| 14009 | * if it is possible for underlying windows to be seen behind the view. |
| 14010 | * |
| 14011 | * {@hide} |
| 14012 | */ |
| 14013 | public boolean gatherTransparentRegion(Region region) { |
| 14014 | final AttachInfo attachInfo = mAttachInfo; |
| 14015 | if (region != null && attachInfo != null) { |
| 14016 | final int pflags = mPrivateFlags; |
| 14017 | if ((pflags & SKIP_DRAW) == 0) { |
| 14018 | // The SKIP_DRAW flag IS NOT set, so this view draws. We need to |
| 14019 | // remove it from the transparent region. |
| 14020 | final int[] location = attachInfo.mTransparentLocation; |
| 14021 | getLocationInWindow(location); |
| 14022 | region.op(location[0], location[1], location[0] + mRight - mLeft, |
| 14023 | location[1] + mBottom - mTop, Region.Op.DIFFERENCE); |
| 14024 | } else if ((pflags & ONLY_DRAWS_BACKGROUND) != 0 && mBGDrawable != null) { |
| 14025 | // The ONLY_DRAWS_BACKGROUND flag IS set and the background drawable |
| 14026 | // exists, so we remove the background drawable's non-transparent |
| 14027 | // parts from this transparent region. |
| 14028 | applyDrawableToTransparentRegion(mBGDrawable, region); |
| 14029 | } |
| 14030 | } |
| 14031 | return true; |
| 14032 | } |
| 14033 | |
| 14034 | /** |
| 14035 | * Play a sound effect for this view. |
| 14036 | * |
| 14037 | * <p>The framework will play sound effects for some built in actions, such as |
| 14038 | * clicking, but you may wish to play these effects in your widget, |
| 14039 | * for instance, for internal navigation. |
| 14040 | * |
| 14041 | * <p>The sound effect will only be played if sound effects are enabled by the user, and |
| 14042 | * {@link #isSoundEffectsEnabled()} is true. |
| 14043 | * |
| 14044 | * @param soundConstant One of the constants defined in {@link SoundEffectConstants} |
| 14045 | */ |
| 14046 | public void playSoundEffect(int soundConstant) { |
| 14047 | if (mAttachInfo == null || mAttachInfo.mRootCallbacks == null || !isSoundEffectsEnabled()) { |
| 14048 | return; |
| 14049 | } |
| 14050 | mAttachInfo.mRootCallbacks.playSoundEffect(soundConstant); |
| 14051 | } |
| 14052 | |
| 14053 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 14054 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14055 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 14056 | * <p>Provide haptic feedback to the user for this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14057 | * |
| 14058 | * <p>The framework will provide haptic feedback for some built in actions, |
| 14059 | * such as long presses, but you may wish to provide feedback for your |
| 14060 | * own widget. |
| 14061 | * |
| 14062 | * <p>The feedback will only be performed if |
| 14063 | * {@link #isHapticFeedbackEnabled()} is true. |
| 14064 | * |
| 14065 | * @param feedbackConstant One of the constants defined in |
| 14066 | * {@link HapticFeedbackConstants} |
| 14067 | */ |
| 14068 | public boolean performHapticFeedback(int feedbackConstant) { |
| 14069 | return performHapticFeedback(feedbackConstant, 0); |
| 14070 | } |
| 14071 | |
| 14072 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 14073 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14074 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 14075 | * <p>Like {@link #performHapticFeedback(int)}, with additional options. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14076 | * |
| 14077 | * @param feedbackConstant One of the constants defined in |
| 14078 | * {@link HapticFeedbackConstants} |
| 14079 | * @param flags Additional flags as per {@link HapticFeedbackConstants}. |
| 14080 | */ |
| 14081 | public boolean performHapticFeedback(int feedbackConstant, int flags) { |
| 14082 | if (mAttachInfo == null) { |
| 14083 | return false; |
| 14084 | } |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 14085 | //noinspection SimplifiableIfStatement |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 14086 | if ((flags & HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING) == 0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14087 | && !isHapticFeedbackEnabled()) { |
| 14088 | return false; |
| 14089 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 14090 | return mAttachInfo.mRootCallbacks.performHapticFeedback(feedbackConstant, |
| 14091 | (flags & HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14092 | } |
| 14093 | |
| 14094 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14095 | * Request that the visibility of the status bar be changed. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 14096 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or |
| 14097 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14098 | */ |
| 14099 | public void setSystemUiVisibility(int visibility) { |
Daniel Sandler | 7052406 | 2011-09-21 00:30:47 -0400 | [diff] [blame] | 14100 | if (visibility != mSystemUiVisibility) { |
| 14101 | mSystemUiVisibility = visibility; |
| 14102 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 14103 | mParent.recomputeViewAttributes(this); |
| 14104 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14105 | } |
| 14106 | } |
| 14107 | |
| 14108 | /** |
| 14109 | * Returns the status bar visibility that this view has requested. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 14110 | * @return Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or |
| 14111 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14112 | */ |
Joe Onorato | e595cad | 2011-01-24 09:22:12 -0800 | [diff] [blame] | 14113 | public int getSystemUiVisibility() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14114 | return mSystemUiVisibility; |
| 14115 | } |
| 14116 | |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 14117 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame^] | 14118 | * Returns the current system UI visibility that is currently set for |
| 14119 | * the entire window. This is the combination of the |
| 14120 | * {@link #setSystemUiVisibility(int)} values supplied by all of the |
| 14121 | * views in the window. |
| 14122 | */ |
| 14123 | public int getWindowSystemUiVisibility() { |
| 14124 | return mAttachInfo != null ? mAttachInfo.mSystemUiVisibility : 0; |
| 14125 | } |
| 14126 | |
| 14127 | /** |
| 14128 | * Override to find out when the window's requested system UI visibility |
| 14129 | * has changed, that is the value returned by {@link #getWindowSystemUiVisibility()}. |
| 14130 | * This is different from the callbacks recieved through |
| 14131 | * {@link #setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener)} |
| 14132 | * in that this is only telling you about the local request of the window, |
| 14133 | * not the actual values applied by the system. |
| 14134 | */ |
| 14135 | public void onWindowSystemUiVisibilityChanged(int visible) { |
| 14136 | } |
| 14137 | |
| 14138 | /** |
| 14139 | * Dispatch callbacks to {@link #onWindowSystemUiVisibilityChanged(int)} down |
| 14140 | * the view hierarchy. |
| 14141 | */ |
| 14142 | public void dispatchWindowSystemUiVisiblityChanged(int visible) { |
| 14143 | onWindowSystemUiVisibilityChanged(visible); |
| 14144 | } |
| 14145 | |
| 14146 | /** |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 14147 | * Set a listener to receive callbacks when the visibility of the system bar changes. |
| 14148 | * @param l The {@link OnSystemUiVisibilityChangeListener} to receive callbacks. |
| 14149 | */ |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14150 | public void setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 14151 | getListenerInfo().mOnSystemUiVisibilityChangeListener = l; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14152 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 14153 | mParent.recomputeViewAttributes(this); |
| 14154 | } |
| 14155 | } |
| 14156 | |
| 14157 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 14158 | * Dispatch callbacks to {@link #setOnSystemUiVisibilityChangeListener} down |
| 14159 | * the view hierarchy. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14160 | */ |
| 14161 | public void dispatchSystemUiVisibilityChanged(int visibility) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 14162 | ListenerInfo li = mListenerInfo; |
| 14163 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
| 14164 | li.mOnSystemUiVisibilityChangeListener.onSystemUiVisibilityChange( |
Joe Onorato | 6ab77bd | 2011-01-31 11:21:10 -0800 | [diff] [blame] | 14165 | visibility & PUBLIC_STATUS_BAR_VISIBILITY_MASK); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14166 | } |
| 14167 | } |
| 14168 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 14169 | void updateLocalSystemUiVisibility(int localValue, int localChanges) { |
| 14170 | int val = (mSystemUiVisibility&~localChanges) | (localValue&localChanges); |
| 14171 | if (val != mSystemUiVisibility) { |
| 14172 | setSystemUiVisibility(val); |
| 14173 | } |
| 14174 | } |
| 14175 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14176 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14177 | * Creates an image that the system displays during the drag and drop |
| 14178 | * operation. This is called a "drag shadow". The default implementation |
| 14179 | * for a DragShadowBuilder based on a View returns an image that has exactly the same |
| 14180 | * appearance as the given View. The default also positions the center of the drag shadow |
| 14181 | * directly under the touch point. If no View is provided (the constructor with no parameters |
| 14182 | * is used), and {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} and |
| 14183 | * {@link #onDrawShadow(Canvas) onDrawShadow()} are not overriden, then the |
| 14184 | * default is an invisible drag shadow. |
| 14185 | * <p> |
| 14186 | * You are not required to use the View you provide to the constructor as the basis of the |
| 14187 | * drag shadow. The {@link #onDrawShadow(Canvas) onDrawShadow()} method allows you to draw |
| 14188 | * anything you want as the drag shadow. |
| 14189 | * </p> |
| 14190 | * <p> |
| 14191 | * You pass a DragShadowBuilder object to the system when you start the drag. The system |
| 14192 | * calls {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} to get the |
| 14193 | * size and position of the drag shadow. It uses this data to construct a |
| 14194 | * {@link android.graphics.Canvas} object, then it calls {@link #onDrawShadow(Canvas) onDrawShadow()} |
| 14195 | * so that your application can draw the shadow image in the Canvas. |
| 14196 | * </p> |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 14197 | * |
| 14198 | * <div class="special reference"> |
| 14199 | * <h3>Developer Guides</h3> |
| 14200 | * <p>For a guide to implementing drag and drop features, read the |
| 14201 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 14202 | * </div> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14203 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14204 | public static class DragShadowBuilder { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 14205 | private final WeakReference<View> mView; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14206 | |
| 14207 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14208 | * Constructs a shadow image builder based on a View. By default, the resulting drag |
| 14209 | * shadow will have the same appearance and dimensions as the View, with the touch point |
| 14210 | * over the center of the View. |
| 14211 | * @param view A View. Any View in scope can be used. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14212 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14213 | public DragShadowBuilder(View view) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 14214 | mView = new WeakReference<View>(view); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14215 | } |
| 14216 | |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 14217 | /** |
| 14218 | * Construct a shadow builder object with no associated View. This |
| 14219 | * constructor variant is only useful when the {@link #onProvideShadowMetrics(Point, Point)} |
| 14220 | * and {@link #onDrawShadow(Canvas)} methods are also overridden in order |
| 14221 | * to supply the drag shadow's dimensions and appearance without |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14222 | * reference to any View object. If they are not overridden, then the result is an |
| 14223 | * invisible drag shadow. |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 14224 | */ |
| 14225 | public DragShadowBuilder() { |
| 14226 | mView = new WeakReference<View>(null); |
| 14227 | } |
| 14228 | |
| 14229 | /** |
| 14230 | * Returns the View object that had been passed to the |
| 14231 | * {@link #View.DragShadowBuilder(View)} |
| 14232 | * constructor. If that View parameter was {@code null} or if the |
| 14233 | * {@link #View.DragShadowBuilder()} |
| 14234 | * constructor was used to instantiate the builder object, this method will return |
| 14235 | * null. |
| 14236 | * |
| 14237 | * @return The View object associate with this builder object. |
| 14238 | */ |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 14239 | @SuppressWarnings({"JavadocReference"}) |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 14240 | final public View getView() { |
| 14241 | return mView.get(); |
| 14242 | } |
| 14243 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14244 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14245 | * Provides the metrics for the shadow image. These include the dimensions of |
| 14246 | * the shadow image, and the point within that shadow that should |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14247 | * be centered under the touch location while dragging. |
| 14248 | * <p> |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14249 | * The default implementation sets the dimensions of the shadow to be the |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14250 | * same as the dimensions of the View itself and centers the shadow under |
| 14251 | * the touch point. |
| 14252 | * </p> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14253 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14254 | * @param shadowSize A {@link android.graphics.Point} containing the width and height |
| 14255 | * of the shadow image. Your application must set {@link android.graphics.Point#x} to the |
| 14256 | * desired width and must set {@link android.graphics.Point#y} to the desired height of the |
| 14257 | * image. |
| 14258 | * |
| 14259 | * @param shadowTouchPoint A {@link android.graphics.Point} for the position within the |
| 14260 | * shadow image that should be underneath the touch point during the drag and drop |
| 14261 | * operation. Your application must set {@link android.graphics.Point#x} to the |
| 14262 | * X coordinate and {@link android.graphics.Point#y} to the Y coordinate of this position. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14263 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14264 | public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 14265 | final View view = mView.get(); |
| 14266 | if (view != null) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14267 | shadowSize.set(view.getWidth(), view.getHeight()); |
| 14268 | shadowTouchPoint.set(shadowSize.x / 2, shadowSize.y / 2); |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 14269 | } else { |
| 14270 | Log.e(View.VIEW_LOG_TAG, "Asked for drag thumb metrics but no view"); |
| 14271 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14272 | } |
| 14273 | |
| 14274 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14275 | * Draws the shadow image. The system creates the {@link android.graphics.Canvas} object |
| 14276 | * based on the dimensions it received from the |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14277 | * {@link #onProvideShadowMetrics(Point, Point)} callback. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14278 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14279 | * @param canvas A {@link android.graphics.Canvas} object in which to draw the shadow image. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14280 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14281 | public void onDrawShadow(Canvas canvas) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 14282 | final View view = mView.get(); |
| 14283 | if (view != null) { |
| 14284 | view.draw(canvas); |
| 14285 | } else { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14286 | Log.e(View.VIEW_LOG_TAG, "Asked to draw drag shadow but no view"); |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 14287 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14288 | } |
| 14289 | } |
| 14290 | |
| 14291 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14292 | * Starts a drag and drop operation. When your application calls this method, it passes a |
| 14293 | * {@link android.view.View.DragShadowBuilder} object to the system. The |
| 14294 | * system calls this object's {@link DragShadowBuilder#onProvideShadowMetrics(Point, Point)} |
| 14295 | * to get metrics for the drag shadow, and then calls the object's |
| 14296 | * {@link DragShadowBuilder#onDrawShadow(Canvas)} to draw the drag shadow itself. |
| 14297 | * <p> |
| 14298 | * Once the system has the drag shadow, it begins the drag and drop operation by sending |
| 14299 | * drag events to all the View objects in your application that are currently visible. It does |
| 14300 | * this either by calling the View object's drag listener (an implementation of |
| 14301 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent) onDrag()} or by calling the |
| 14302 | * View object's {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} method. |
| 14303 | * Both are passed a {@link android.view.DragEvent} object that has a |
| 14304 | * {@link android.view.DragEvent#getAction()} value of |
| 14305 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED}. |
| 14306 | * </p> |
| 14307 | * <p> |
| 14308 | * Your application can invoke startDrag() on any attached View object. The View object does not |
| 14309 | * need to be the one used in {@link android.view.View.DragShadowBuilder}, nor does it need to |
| 14310 | * be related to the View the user selected for dragging. |
| 14311 | * </p> |
| 14312 | * @param data A {@link android.content.ClipData} object pointing to the data to be |
| 14313 | * transferred by the drag and drop operation. |
| 14314 | * @param shadowBuilder A {@link android.view.View.DragShadowBuilder} object for building the |
| 14315 | * drag shadow. |
| 14316 | * @param myLocalState An {@link java.lang.Object} containing local data about the drag and |
| 14317 | * drop operation. This Object is put into every DragEvent object sent by the system during the |
| 14318 | * current drag. |
| 14319 | * <p> |
| 14320 | * myLocalState is a lightweight mechanism for the sending information from the dragged View |
| 14321 | * to the target Views. For example, it can contain flags that differentiate between a |
| 14322 | * a copy operation and a move operation. |
| 14323 | * </p> |
| 14324 | * @param flags Flags that control the drag and drop operation. No flags are currently defined, |
| 14325 | * so the parameter should be set to 0. |
| 14326 | * @return {@code true} if the method completes successfully, or |
| 14327 | * {@code false} if it fails anywhere. Returning {@code false} means the system was unable to |
| 14328 | * do a drag, and so no drag operation is in progress. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14329 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14330 | public final boolean startDrag(ClipData data, DragShadowBuilder shadowBuilder, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 14331 | Object myLocalState, int flags) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14332 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 14333 | Log.d(VIEW_LOG_TAG, "startDrag: data=" + data + " flags=" + flags); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14334 | } |
| 14335 | boolean okay = false; |
| 14336 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14337 | Point shadowSize = new Point(); |
| 14338 | Point shadowTouchPoint = new Point(); |
| 14339 | shadowBuilder.onProvideShadowMetrics(shadowSize, shadowTouchPoint); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14340 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14341 | if ((shadowSize.x < 0) || (shadowSize.y < 0) || |
| 14342 | (shadowTouchPoint.x < 0) || (shadowTouchPoint.y < 0)) { |
| 14343 | throw new IllegalStateException("Drag shadow dimensions must not be negative"); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14344 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14345 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 14346 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14347 | Log.d(VIEW_LOG_TAG, "drag shadow: width=" + shadowSize.x + " height=" + shadowSize.y |
| 14348 | + " shadowX=" + shadowTouchPoint.x + " shadowY=" + shadowTouchPoint.y); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 14349 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14350 | Surface surface = new Surface(); |
| 14351 | try { |
| 14352 | IBinder token = mAttachInfo.mSession.prepareDrag(mAttachInfo.mWindow, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 14353 | flags, shadowSize.x, shadowSize.y, surface); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14354 | if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "prepareDrag returned token=" + token |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14355 | + " surface=" + surface); |
| 14356 | if (token != null) { |
| 14357 | Canvas canvas = surface.lockCanvas(null); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 14358 | try { |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 14359 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14360 | shadowBuilder.onDrawShadow(canvas); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 14361 | } finally { |
| 14362 | surface.unlockCanvasAndPost(canvas); |
| 14363 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14364 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 14365 | final ViewRootImpl root = getViewRootImpl(); |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 14366 | |
| 14367 | // Cache the local state object for delivery with DragEvents |
| 14368 | root.setLocalDragState(myLocalState); |
| 14369 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14370 | // repurpose 'shadowSize' for the last touch point |
| 14371 | root.getLastTouchPoint(shadowSize); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14372 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14373 | okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, token, |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14374 | shadowSize.x, shadowSize.y, |
| 14375 | shadowTouchPoint.x, shadowTouchPoint.y, data); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14376 | if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "performDrag returned " + okay); |
Christopher Tate | 8f73b5d | 2011-09-12 15:22:12 -0700 | [diff] [blame] | 14377 | |
| 14378 | // Off and running! Release our local surface instance; the drag |
| 14379 | // shadow surface is now managed by the system process. |
| 14380 | surface.release(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14381 | } |
| 14382 | } catch (Exception e) { |
| 14383 | Log.e(VIEW_LOG_TAG, "Unable to initiate drag", e); |
| 14384 | surface.destroy(); |
| 14385 | } |
| 14386 | |
| 14387 | return okay; |
| 14388 | } |
| 14389 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14390 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14391 | * Handles drag events sent by the system following a call to |
| 14392 | * {@link android.view.View#startDrag(ClipData,DragShadowBuilder,Object,int) startDrag()}. |
| 14393 | *<p> |
| 14394 | * When the system calls this method, it passes a |
| 14395 | * {@link android.view.DragEvent} object. A call to |
| 14396 | * {@link android.view.DragEvent#getAction()} returns one of the action type constants defined |
| 14397 | * in DragEvent. The method uses these to determine what is happening in the drag and drop |
| 14398 | * operation. |
| 14399 | * @param event The {@link android.view.DragEvent} sent by the system. |
| 14400 | * The {@link android.view.DragEvent#getAction()} method returns an action type constant defined |
| 14401 | * in DragEvent, indicating the type of drag event represented by this object. |
| 14402 | * @return {@code true} if the method was successful, otherwise {@code false}. |
| 14403 | * <p> |
| 14404 | * The method should return {@code true} in response to an action type of |
| 14405 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED} to receive drag events for the current |
| 14406 | * operation. |
| 14407 | * </p> |
| 14408 | * <p> |
| 14409 | * The method should also return {@code true} in response to an action type of |
| 14410 | * {@link android.view.DragEvent#ACTION_DROP} if it consumed the drop, or |
| 14411 | * {@code false} if it didn't. |
| 14412 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14413 | */ |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 14414 | public boolean onDragEvent(DragEvent event) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14415 | return false; |
| 14416 | } |
| 14417 | |
| 14418 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14419 | * Detects if this View is enabled and has a drag event listener. |
| 14420 | * If both are true, then it calls the drag event listener with the |
| 14421 | * {@link android.view.DragEvent} it received. If the drag event listener returns |
| 14422 | * {@code true}, then dispatchDragEvent() returns {@code true}. |
| 14423 | * <p> |
| 14424 | * For all other cases, the method calls the |
| 14425 | * {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} drag event handler |
| 14426 | * method and returns its result. |
| 14427 | * </p> |
| 14428 | * <p> |
| 14429 | * This ensures that a drag event is always consumed, even if the View does not have a drag |
| 14430 | * event listener. However, if the View has a listener and the listener returns true, then |
| 14431 | * onDragEvent() is not called. |
| 14432 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14433 | */ |
| 14434 | public boolean dispatchDragEvent(DragEvent event) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 14435 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 14436 | ListenerInfo li = mListenerInfo; |
| 14437 | if (li != null && li.mOnDragListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 14438 | && li.mOnDragListener.onDrag(this, event)) { |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 14439 | return true; |
| 14440 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14441 | return onDragEvent(event); |
| 14442 | } |
| 14443 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 14444 | boolean canAcceptDrag() { |
| 14445 | return (mPrivateFlags2 & DRAG_CAN_ACCEPT) != 0; |
| 14446 | } |
| 14447 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14448 | /** |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 14449 | * This needs to be a better API (NOT ON VIEW) before it is exposed. If |
| 14450 | * it is ever exposed at all. |
Dianne Hackborn | 29e4a3c | 2009-09-30 22:35:40 -0700 | [diff] [blame] | 14451 | * @hide |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 14452 | */ |
| 14453 | public void onCloseSystemDialogs(String reason) { |
| 14454 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14455 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 14456 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14457 | * Given a Drawable whose bounds have been set to draw into this view, |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 14458 | * update a Region being computed for |
| 14459 | * {@link #gatherTransparentRegion(android.graphics.Region)} so |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14460 | * that any non-transparent parts of the Drawable are removed from the |
| 14461 | * given transparent region. |
| 14462 | * |
| 14463 | * @param dr The Drawable whose transparency is to be applied to the region. |
| 14464 | * @param region A Region holding the current transparency information, |
| 14465 | * where any parts of the region that are set are considered to be |
| 14466 | * transparent. On return, this region will be modified to have the |
| 14467 | * transparency information reduced by the corresponding parts of the |
| 14468 | * Drawable that are not transparent. |
| 14469 | * {@hide} |
| 14470 | */ |
| 14471 | public void applyDrawableToTransparentRegion(Drawable dr, Region region) { |
| 14472 | if (DBG) { |
| 14473 | Log.i("View", "Getting transparent region for: " + this); |
| 14474 | } |
| 14475 | final Region r = dr.getTransparentRegion(); |
| 14476 | final Rect db = dr.getBounds(); |
| 14477 | final AttachInfo attachInfo = mAttachInfo; |
| 14478 | if (r != null && attachInfo != null) { |
| 14479 | final int w = getRight()-getLeft(); |
| 14480 | final int h = getBottom()-getTop(); |
| 14481 | if (db.left > 0) { |
| 14482 | //Log.i("VIEW", "Drawable left " + db.left + " > view 0"); |
| 14483 | r.op(0, 0, db.left, h, Region.Op.UNION); |
| 14484 | } |
| 14485 | if (db.right < w) { |
| 14486 | //Log.i("VIEW", "Drawable right " + db.right + " < view " + w); |
| 14487 | r.op(db.right, 0, w, h, Region.Op.UNION); |
| 14488 | } |
| 14489 | if (db.top > 0) { |
| 14490 | //Log.i("VIEW", "Drawable top " + db.top + " > view 0"); |
| 14491 | r.op(0, 0, w, db.top, Region.Op.UNION); |
| 14492 | } |
| 14493 | if (db.bottom < h) { |
| 14494 | //Log.i("VIEW", "Drawable bottom " + db.bottom + " < view " + h); |
| 14495 | r.op(0, db.bottom, w, h, Region.Op.UNION); |
| 14496 | } |
| 14497 | final int[] location = attachInfo.mTransparentLocation; |
| 14498 | getLocationInWindow(location); |
| 14499 | r.translate(location[0], location[1]); |
| 14500 | region.op(r, Region.Op.INTERSECT); |
| 14501 | } else { |
| 14502 | region.op(db, Region.Op.DIFFERENCE); |
| 14503 | } |
| 14504 | } |
| 14505 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 14506 | private void checkForLongClick(int delayOffset) { |
| 14507 | if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) { |
| 14508 | mHasPerformedLongPress = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14509 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 14510 | if (mPendingCheckForLongPress == null) { |
| 14511 | mPendingCheckForLongPress = new CheckForLongPress(); |
| 14512 | } |
| 14513 | mPendingCheckForLongPress.rememberWindowAttachCount(); |
| 14514 | postDelayed(mPendingCheckForLongPress, |
| 14515 | ViewConfiguration.getLongPressTimeout() - delayOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14516 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14517 | } |
| 14518 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14519 | /** |
| 14520 | * Inflate a view from an XML resource. This convenience method wraps the {@link |
| 14521 | * LayoutInflater} class, which provides a full range of options for view inflation. |
| 14522 | * |
| 14523 | * @param context The Context object for your activity or application. |
| 14524 | * @param resource The resource ID to inflate |
| 14525 | * @param root A view group that will be the parent. Used to properly inflate the |
| 14526 | * layout_* parameters. |
| 14527 | * @see LayoutInflater |
| 14528 | */ |
| 14529 | public static View inflate(Context context, int resource, ViewGroup root) { |
| 14530 | LayoutInflater factory = LayoutInflater.from(context); |
| 14531 | return factory.inflate(resource, root); |
| 14532 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 14533 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14534 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 14535 | * Scroll the view with standard behavior for scrolling beyond the normal |
| 14536 | * content boundaries. Views that call this method should override |
| 14537 | * {@link #onOverScrolled(int, int, boolean, boolean)} to respond to the |
| 14538 | * results of an over-scroll operation. |
| 14539 | * |
| 14540 | * Views can use this method to handle any touch or fling-based scrolling. |
| 14541 | * |
| 14542 | * @param deltaX Change in X in pixels |
| 14543 | * @param deltaY Change in Y in pixels |
| 14544 | * @param scrollX Current X scroll value in pixels before applying deltaX |
| 14545 | * @param scrollY Current Y scroll value in pixels before applying deltaY |
| 14546 | * @param scrollRangeX Maximum content scroll range along the X axis |
| 14547 | * @param scrollRangeY Maximum content scroll range along the Y axis |
| 14548 | * @param maxOverScrollX Number of pixels to overscroll by in either direction |
| 14549 | * along the X axis. |
| 14550 | * @param maxOverScrollY Number of pixels to overscroll by in either direction |
| 14551 | * along the Y axis. |
| 14552 | * @param isTouchEvent true if this scroll operation is the result of a touch event. |
| 14553 | * @return true if scrolling was clamped to an over-scroll boundary along either |
| 14554 | * axis, false otherwise. |
| 14555 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 14556 | @SuppressWarnings({"UnusedParameters"}) |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 14557 | protected boolean overScrollBy(int deltaX, int deltaY, |
| 14558 | int scrollX, int scrollY, |
| 14559 | int scrollRangeX, int scrollRangeY, |
| 14560 | int maxOverScrollX, int maxOverScrollY, |
| 14561 | boolean isTouchEvent) { |
| 14562 | final int overScrollMode = mOverScrollMode; |
| 14563 | final boolean canScrollHorizontal = |
| 14564 | computeHorizontalScrollRange() > computeHorizontalScrollExtent(); |
| 14565 | final boolean canScrollVertical = |
| 14566 | computeVerticalScrollRange() > computeVerticalScrollExtent(); |
| 14567 | final boolean overScrollHorizontal = overScrollMode == OVER_SCROLL_ALWAYS || |
| 14568 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollHorizontal); |
| 14569 | final boolean overScrollVertical = overScrollMode == OVER_SCROLL_ALWAYS || |
| 14570 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollVertical); |
| 14571 | |
| 14572 | int newScrollX = scrollX + deltaX; |
| 14573 | if (!overScrollHorizontal) { |
| 14574 | maxOverScrollX = 0; |
| 14575 | } |
| 14576 | |
| 14577 | int newScrollY = scrollY + deltaY; |
| 14578 | if (!overScrollVertical) { |
| 14579 | maxOverScrollY = 0; |
| 14580 | } |
| 14581 | |
| 14582 | // Clamp values if at the limits and record |
| 14583 | final int left = -maxOverScrollX; |
| 14584 | final int right = maxOverScrollX + scrollRangeX; |
| 14585 | final int top = -maxOverScrollY; |
| 14586 | final int bottom = maxOverScrollY + scrollRangeY; |
| 14587 | |
| 14588 | boolean clampedX = false; |
| 14589 | if (newScrollX > right) { |
| 14590 | newScrollX = right; |
| 14591 | clampedX = true; |
| 14592 | } else if (newScrollX < left) { |
| 14593 | newScrollX = left; |
| 14594 | clampedX = true; |
| 14595 | } |
| 14596 | |
| 14597 | boolean clampedY = false; |
| 14598 | if (newScrollY > bottom) { |
| 14599 | newScrollY = bottom; |
| 14600 | clampedY = true; |
| 14601 | } else if (newScrollY < top) { |
| 14602 | newScrollY = top; |
| 14603 | clampedY = true; |
| 14604 | } |
| 14605 | |
| 14606 | onOverScrolled(newScrollX, newScrollY, clampedX, clampedY); |
| 14607 | |
| 14608 | return clampedX || clampedY; |
| 14609 | } |
| 14610 | |
| 14611 | /** |
| 14612 | * Called by {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)} to |
| 14613 | * respond to the results of an over-scroll operation. |
| 14614 | * |
| 14615 | * @param scrollX New X scroll value in pixels |
| 14616 | * @param scrollY New Y scroll value in pixels |
| 14617 | * @param clampedX True if scrollX was clamped to an over-scroll boundary |
| 14618 | * @param clampedY True if scrollY was clamped to an over-scroll boundary |
| 14619 | */ |
| 14620 | protected void onOverScrolled(int scrollX, int scrollY, |
| 14621 | boolean clampedX, boolean clampedY) { |
| 14622 | // Intentionally empty. |
| 14623 | } |
| 14624 | |
| 14625 | /** |
| 14626 | * Returns the over-scroll mode for this view. The result will be |
| 14627 | * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 14628 | * (allow over-scrolling only if the view content is larger than the container), |
| 14629 | * or {@link #OVER_SCROLL_NEVER}. |
| 14630 | * |
| 14631 | * @return This view's over-scroll mode. |
| 14632 | */ |
| 14633 | public int getOverScrollMode() { |
| 14634 | return mOverScrollMode; |
| 14635 | } |
| 14636 | |
| 14637 | /** |
| 14638 | * Set the over-scroll mode for this view. Valid over-scroll modes are |
| 14639 | * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 14640 | * (allow over-scrolling only if the view content is larger than the container), |
| 14641 | * or {@link #OVER_SCROLL_NEVER}. |
| 14642 | * |
| 14643 | * Setting the over-scroll mode of a view will have an effect only if the |
| 14644 | * view is capable of scrolling. |
| 14645 | * |
| 14646 | * @param overScrollMode The new over-scroll mode for this view. |
| 14647 | */ |
| 14648 | public void setOverScrollMode(int overScrollMode) { |
| 14649 | if (overScrollMode != OVER_SCROLL_ALWAYS && |
| 14650 | overScrollMode != OVER_SCROLL_IF_CONTENT_SCROLLS && |
| 14651 | overScrollMode != OVER_SCROLL_NEVER) { |
| 14652 | throw new IllegalArgumentException("Invalid overscroll mode " + overScrollMode); |
| 14653 | } |
| 14654 | mOverScrollMode = overScrollMode; |
| 14655 | } |
| 14656 | |
| 14657 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 14658 | * Gets a scale factor that determines the distance the view should scroll |
| 14659 | * vertically in response to {@link MotionEvent#ACTION_SCROLL}. |
| 14660 | * @return The vertical scroll scale factor. |
| 14661 | * @hide |
| 14662 | */ |
| 14663 | protected float getVerticalScrollFactor() { |
| 14664 | if (mVerticalScrollFactor == 0) { |
| 14665 | TypedValue outValue = new TypedValue(); |
| 14666 | if (!mContext.getTheme().resolveAttribute( |
| 14667 | com.android.internal.R.attr.listPreferredItemHeight, outValue, true)) { |
| 14668 | throw new IllegalStateException( |
| 14669 | "Expected theme to define listPreferredItemHeight."); |
| 14670 | } |
| 14671 | mVerticalScrollFactor = outValue.getDimension( |
| 14672 | mContext.getResources().getDisplayMetrics()); |
| 14673 | } |
| 14674 | return mVerticalScrollFactor; |
| 14675 | } |
| 14676 | |
| 14677 | /** |
| 14678 | * Gets a scale factor that determines the distance the view should scroll |
| 14679 | * horizontally in response to {@link MotionEvent#ACTION_SCROLL}. |
| 14680 | * @return The horizontal scroll scale factor. |
| 14681 | * @hide |
| 14682 | */ |
| 14683 | protected float getHorizontalScrollFactor() { |
| 14684 | // TODO: Should use something else. |
| 14685 | return getVerticalScrollFactor(); |
| 14686 | } |
| 14687 | |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 14688 | /** |
| 14689 | * Return the value specifying the text direction or policy that was set with |
| 14690 | * {@link #setTextDirection(int)}. |
| 14691 | * |
| 14692 | * @return the defined text direction. It can be one of: |
| 14693 | * |
| 14694 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 14695 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 14696 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 14697 | * {@link #TEXT_DIRECTION_LTR}, |
| 14698 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 4c1e00a | 2012-01-05 19:05:55 -0800 | [diff] [blame] | 14699 | * {@link #TEXT_DIRECTION_LOCALE}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 14700 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 14701 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 14702 | @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), |
| 14703 | @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), |
| 14704 | @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), |
| 14705 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), |
| 14706 | @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"), |
| 14707 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE") |
| 14708 | }) |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 14709 | public int getTextDirection() { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 14710 | return (mPrivateFlags2 & TEXT_DIRECTION_MASK) >> TEXT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 14711 | } |
| 14712 | |
| 14713 | /** |
| 14714 | * Set the text direction. |
| 14715 | * |
| 14716 | * @param textDirection the direction to set. Should be one of: |
| 14717 | * |
| 14718 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 14719 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 14720 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 14721 | * {@link #TEXT_DIRECTION_LTR}, |
| 14722 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 4c1e00a | 2012-01-05 19:05:55 -0800 | [diff] [blame] | 14723 | * {@link #TEXT_DIRECTION_LOCALE}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 14724 | */ |
| 14725 | public void setTextDirection(int textDirection) { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 14726 | if (getTextDirection() != textDirection) { |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 14727 | // Reset the current text direction and the resolved one |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 14728 | mPrivateFlags2 &= ~TEXT_DIRECTION_MASK; |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 14729 | resetResolvedTextDirection(); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 14730 | // Set the new text direction |
| 14731 | mPrivateFlags2 |= ((textDirection << TEXT_DIRECTION_MASK_SHIFT) & TEXT_DIRECTION_MASK); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 14732 | requestLayout(); |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 14733 | invalidate(true); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 14734 | } |
| 14735 | } |
| 14736 | |
| 14737 | /** |
| 14738 | * Return the resolved text direction. |
| 14739 | * |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 14740 | * This needs resolution if the value is TEXT_DIRECTION_INHERIT. The resolution matches |
| 14741 | * {@link #getTextDirection()}if it is not TEXT_DIRECTION_INHERIT, otherwise resolution proceeds |
| 14742 | * up the parent chain of the view. if there is no parent, then it will return the default |
| 14743 | * {@link #TEXT_DIRECTION_FIRST_STRONG}. |
| 14744 | * |
| 14745 | * @return the resolved text direction. Returns one of: |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 14746 | * |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 14747 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 14748 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 14749 | * {@link #TEXT_DIRECTION_LTR}, |
| 14750 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 4c1e00a | 2012-01-05 19:05:55 -0800 | [diff] [blame] | 14751 | * {@link #TEXT_DIRECTION_LOCALE}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 14752 | */ |
| 14753 | public int getResolvedTextDirection() { |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 14754 | // The text direction will be resolved only if needed |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 14755 | if ((mPrivateFlags2 & TEXT_DIRECTION_RESOLVED) != TEXT_DIRECTION_RESOLVED) { |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 14756 | resolveTextDirection(); |
| 14757 | } |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 14758 | return (mPrivateFlags2 & TEXT_DIRECTION_RESOLVED_MASK) >> TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 14759 | } |
| 14760 | |
| 14761 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 14762 | * Resolve the text direction. Will call {@link View#onResolvedTextDirectionChanged} when |
| 14763 | * resolution is done. |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 14764 | */ |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 14765 | public void resolveTextDirection() { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 14766 | // Reset any previous text direction resolution |
| 14767 | mPrivateFlags2 &= ~(TEXT_DIRECTION_RESOLVED | TEXT_DIRECTION_RESOLVED_MASK); |
| 14768 | |
| 14769 | // Set resolved text direction flag depending on text direction flag |
| 14770 | final int textDirection = getTextDirection(); |
| 14771 | switch(textDirection) { |
| 14772 | case TEXT_DIRECTION_INHERIT: |
| 14773 | if (canResolveTextDirection()) { |
| 14774 | ViewGroup viewGroup = ((ViewGroup) mParent); |
| 14775 | |
| 14776 | // Set current resolved direction to the same value as the parent's one |
| 14777 | final int parentResolvedDirection = viewGroup.getResolvedTextDirection(); |
| 14778 | switch (parentResolvedDirection) { |
| 14779 | case TEXT_DIRECTION_FIRST_STRONG: |
| 14780 | case TEXT_DIRECTION_ANY_RTL: |
| 14781 | case TEXT_DIRECTION_LTR: |
| 14782 | case TEXT_DIRECTION_RTL: |
| 14783 | case TEXT_DIRECTION_LOCALE: |
| 14784 | mPrivateFlags2 |= |
| 14785 | (parentResolvedDirection << TEXT_DIRECTION_RESOLVED_MASK_SHIFT); |
| 14786 | break; |
| 14787 | default: |
| 14788 | // Default resolved direction is "first strong" heuristic |
| 14789 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT; |
| 14790 | } |
| 14791 | } else { |
| 14792 | // We cannot do the resolution if there is no parent, so use the default one |
| 14793 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT; |
| 14794 | } |
| 14795 | break; |
| 14796 | case TEXT_DIRECTION_FIRST_STRONG: |
| 14797 | case TEXT_DIRECTION_ANY_RTL: |
| 14798 | case TEXT_DIRECTION_LTR: |
| 14799 | case TEXT_DIRECTION_RTL: |
| 14800 | case TEXT_DIRECTION_LOCALE: |
| 14801 | // Resolved direction is the same as text direction |
| 14802 | mPrivateFlags2 |= (textDirection << TEXT_DIRECTION_RESOLVED_MASK_SHIFT); |
| 14803 | break; |
| 14804 | default: |
| 14805 | // Default resolved direction is "first strong" heuristic |
| 14806 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 14807 | } |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 14808 | |
| 14809 | // Set to resolved |
| 14810 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 14811 | onResolvedTextDirectionChanged(); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 14812 | } |
| 14813 | |
| 14814 | /** |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 14815 | * Called when text direction has been resolved. Subclasses that care about text direction |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 14816 | * resolution should override this method. |
| 14817 | * |
| 14818 | * The default implementation does nothing. |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 14819 | */ |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 14820 | public void onResolvedTextDirectionChanged() { |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 14821 | } |
| 14822 | |
| 14823 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 14824 | * Check if text direction resolution can be done. |
| 14825 | * |
| 14826 | * @return true if text direction resolution can be done otherwise return false. |
| 14827 | */ |
| 14828 | public boolean canResolveTextDirection() { |
| 14829 | switch (getTextDirection()) { |
| 14830 | case TEXT_DIRECTION_INHERIT: |
| 14831 | return (mParent != null) && (mParent instanceof ViewGroup); |
| 14832 | default: |
| 14833 | return true; |
| 14834 | } |
| 14835 | } |
| 14836 | |
| 14837 | /** |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 14838 | * Reset resolved text direction. Text direction can be resolved with a call to |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 14839 | * getResolvedTextDirection(). Will call {@link View#onResolvedTextDirectionReset} when |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 14840 | * reset is done. |
| 14841 | */ |
| 14842 | public void resetResolvedTextDirection() { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 14843 | mPrivateFlags2 &= ~(TEXT_DIRECTION_RESOLVED | TEXT_DIRECTION_RESOLVED_MASK); |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 14844 | onResolvedTextDirectionReset(); |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 14845 | } |
| 14846 | |
| 14847 | /** |
| 14848 | * Called when text direction is reset. Subclasses that care about text direction reset should |
| 14849 | * override this method and do a reset of the text direction of their children. The default |
| 14850 | * implementation does nothing. |
| 14851 | */ |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 14852 | public void onResolvedTextDirectionReset() { |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 14853 | } |
| 14854 | |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 14855 | // |
| 14856 | // Properties |
| 14857 | // |
| 14858 | /** |
| 14859 | * A Property wrapper around the <code>alpha</code> functionality handled by the |
| 14860 | * {@link View#setAlpha(float)} and {@link View#getAlpha()} methods. |
| 14861 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 14862 | public static final Property<View, Float> ALPHA = new FloatProperty<View>("alpha") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 14863 | @Override |
| 14864 | public void setValue(View object, float value) { |
| 14865 | object.setAlpha(value); |
| 14866 | } |
| 14867 | |
| 14868 | @Override |
| 14869 | public Float get(View object) { |
| 14870 | return object.getAlpha(); |
| 14871 | } |
| 14872 | }; |
| 14873 | |
| 14874 | /** |
| 14875 | * A Property wrapper around the <code>translationX</code> functionality handled by the |
| 14876 | * {@link View#setTranslationX(float)} and {@link View#getTranslationX()} methods. |
| 14877 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 14878 | public static final Property<View, Float> TRANSLATION_X = new FloatProperty<View>("translationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 14879 | @Override |
| 14880 | public void setValue(View object, float value) { |
| 14881 | object.setTranslationX(value); |
| 14882 | } |
| 14883 | |
| 14884 | @Override |
| 14885 | public Float get(View object) { |
| 14886 | return object.getTranslationX(); |
| 14887 | } |
| 14888 | }; |
| 14889 | |
| 14890 | /** |
| 14891 | * A Property wrapper around the <code>translationY</code> functionality handled by the |
| 14892 | * {@link View#setTranslationY(float)} and {@link View#getTranslationY()} methods. |
| 14893 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 14894 | public static final Property<View, Float> TRANSLATION_Y = new FloatProperty<View>("translationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 14895 | @Override |
| 14896 | public void setValue(View object, float value) { |
| 14897 | object.setTranslationY(value); |
| 14898 | } |
| 14899 | |
| 14900 | @Override |
| 14901 | public Float get(View object) { |
| 14902 | return object.getTranslationY(); |
| 14903 | } |
| 14904 | }; |
| 14905 | |
| 14906 | /** |
| 14907 | * A Property wrapper around the <code>x</code> functionality handled by the |
| 14908 | * {@link View#setX(float)} and {@link View#getX()} methods. |
| 14909 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 14910 | public static final Property<View, Float> X = new FloatProperty<View>("x") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 14911 | @Override |
| 14912 | public void setValue(View object, float value) { |
| 14913 | object.setX(value); |
| 14914 | } |
| 14915 | |
| 14916 | @Override |
| 14917 | public Float get(View object) { |
| 14918 | return object.getX(); |
| 14919 | } |
| 14920 | }; |
| 14921 | |
| 14922 | /** |
| 14923 | * A Property wrapper around the <code>y</code> functionality handled by the |
| 14924 | * {@link View#setY(float)} and {@link View#getY()} methods. |
| 14925 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 14926 | public static final Property<View, Float> Y = new FloatProperty<View>("y") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 14927 | @Override |
| 14928 | public void setValue(View object, float value) { |
| 14929 | object.setY(value); |
| 14930 | } |
| 14931 | |
| 14932 | @Override |
| 14933 | public Float get(View object) { |
| 14934 | return object.getY(); |
| 14935 | } |
| 14936 | }; |
| 14937 | |
| 14938 | /** |
| 14939 | * A Property wrapper around the <code>rotation</code> functionality handled by the |
| 14940 | * {@link View#setRotation(float)} and {@link View#getRotation()} methods. |
| 14941 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 14942 | public static final Property<View, Float> ROTATION = new FloatProperty<View>("rotation") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 14943 | @Override |
| 14944 | public void setValue(View object, float value) { |
| 14945 | object.setRotation(value); |
| 14946 | } |
| 14947 | |
| 14948 | @Override |
| 14949 | public Float get(View object) { |
| 14950 | return object.getRotation(); |
| 14951 | } |
| 14952 | }; |
| 14953 | |
| 14954 | /** |
| 14955 | * A Property wrapper around the <code>rotationX</code> functionality handled by the |
| 14956 | * {@link View#setRotationX(float)} and {@link View#getRotationX()} methods. |
| 14957 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 14958 | public static final Property<View, Float> ROTATION_X = new FloatProperty<View>("rotationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 14959 | @Override |
| 14960 | public void setValue(View object, float value) { |
| 14961 | object.setRotationX(value); |
| 14962 | } |
| 14963 | |
| 14964 | @Override |
| 14965 | public Float get(View object) { |
| 14966 | return object.getRotationX(); |
| 14967 | } |
| 14968 | }; |
| 14969 | |
| 14970 | /** |
| 14971 | * A Property wrapper around the <code>rotationY</code> functionality handled by the |
| 14972 | * {@link View#setRotationY(float)} and {@link View#getRotationY()} methods. |
| 14973 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 14974 | public static final Property<View, Float> ROTATION_Y = new FloatProperty<View>("rotationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 14975 | @Override |
| 14976 | public void setValue(View object, float value) { |
| 14977 | object.setRotationY(value); |
| 14978 | } |
| 14979 | |
| 14980 | @Override |
| 14981 | public Float get(View object) { |
| 14982 | return object.getRotationY(); |
| 14983 | } |
| 14984 | }; |
| 14985 | |
| 14986 | /** |
| 14987 | * A Property wrapper around the <code>scaleX</code> functionality handled by the |
| 14988 | * {@link View#setScaleX(float)} and {@link View#getScaleX()} methods. |
| 14989 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 14990 | public static final Property<View, Float> SCALE_X = new FloatProperty<View>("scaleX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 14991 | @Override |
| 14992 | public void setValue(View object, float value) { |
| 14993 | object.setScaleX(value); |
| 14994 | } |
| 14995 | |
| 14996 | @Override |
| 14997 | public Float get(View object) { |
| 14998 | return object.getScaleX(); |
| 14999 | } |
| 15000 | }; |
| 15001 | |
| 15002 | /** |
| 15003 | * A Property wrapper around the <code>scaleY</code> functionality handled by the |
| 15004 | * {@link View#setScaleY(float)} and {@link View#getScaleY()} methods. |
| 15005 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 15006 | public static final Property<View, Float> SCALE_Y = new FloatProperty<View>("scaleY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 15007 | @Override |
| 15008 | public void setValue(View object, float value) { |
| 15009 | object.setScaleY(value); |
| 15010 | } |
| 15011 | |
| 15012 | @Override |
| 15013 | public Float get(View object) { |
| 15014 | return object.getScaleY(); |
| 15015 | } |
| 15016 | }; |
| 15017 | |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 15018 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15019 | * A MeasureSpec encapsulates the layout requirements passed from parent to child. |
| 15020 | * Each MeasureSpec represents a requirement for either the width or the height. |
| 15021 | * A MeasureSpec is comprised of a size and a mode. There are three possible |
| 15022 | * modes: |
| 15023 | * <dl> |
| 15024 | * <dt>UNSPECIFIED</dt> |
| 15025 | * <dd> |
| 15026 | * The parent has not imposed any constraint on the child. It can be whatever size |
| 15027 | * it wants. |
| 15028 | * </dd> |
| 15029 | * |
| 15030 | * <dt>EXACTLY</dt> |
| 15031 | * <dd> |
| 15032 | * The parent has determined an exact size for the child. The child is going to be |
| 15033 | * given those bounds regardless of how big it wants to be. |
| 15034 | * </dd> |
| 15035 | * |
| 15036 | * <dt>AT_MOST</dt> |
| 15037 | * <dd> |
| 15038 | * The child can be as large as it wants up to the specified size. |
| 15039 | * </dd> |
| 15040 | * </dl> |
| 15041 | * |
| 15042 | * MeasureSpecs are implemented as ints to reduce object allocation. This class |
| 15043 | * is provided to pack and unpack the <size, mode> tuple into the int. |
| 15044 | */ |
| 15045 | public static class MeasureSpec { |
| 15046 | private static final int MODE_SHIFT = 30; |
| 15047 | private static final int MODE_MASK = 0x3 << MODE_SHIFT; |
| 15048 | |
| 15049 | /** |
| 15050 | * Measure specification mode: The parent has not imposed any constraint |
| 15051 | * on the child. It can be whatever size it wants. |
| 15052 | */ |
| 15053 | public static final int UNSPECIFIED = 0 << MODE_SHIFT; |
| 15054 | |
| 15055 | /** |
| 15056 | * Measure specification mode: The parent has determined an exact size |
| 15057 | * for the child. The child is going to be given those bounds regardless |
| 15058 | * of how big it wants to be. |
| 15059 | */ |
| 15060 | public static final int EXACTLY = 1 << MODE_SHIFT; |
| 15061 | |
| 15062 | /** |
| 15063 | * Measure specification mode: The child can be as large as it wants up |
| 15064 | * to the specified size. |
| 15065 | */ |
| 15066 | public static final int AT_MOST = 2 << MODE_SHIFT; |
| 15067 | |
| 15068 | /** |
| 15069 | * Creates a measure specification based on the supplied size and mode. |
| 15070 | * |
| 15071 | * The mode must always be one of the following: |
| 15072 | * <ul> |
| 15073 | * <li>{@link android.view.View.MeasureSpec#UNSPECIFIED}</li> |
| 15074 | * <li>{@link android.view.View.MeasureSpec#EXACTLY}</li> |
| 15075 | * <li>{@link android.view.View.MeasureSpec#AT_MOST}</li> |
| 15076 | * </ul> |
| 15077 | * |
| 15078 | * @param size the size of the measure specification |
| 15079 | * @param mode the mode of the measure specification |
| 15080 | * @return the measure specification based on size and mode |
| 15081 | */ |
| 15082 | public static int makeMeasureSpec(int size, int mode) { |
| 15083 | return size + mode; |
| 15084 | } |
| 15085 | |
| 15086 | /** |
| 15087 | * Extracts the mode from the supplied measure specification. |
| 15088 | * |
| 15089 | * @param measureSpec the measure specification to extract the mode from |
| 15090 | * @return {@link android.view.View.MeasureSpec#UNSPECIFIED}, |
| 15091 | * {@link android.view.View.MeasureSpec#AT_MOST} or |
| 15092 | * {@link android.view.View.MeasureSpec#EXACTLY} |
| 15093 | */ |
| 15094 | public static int getMode(int measureSpec) { |
| 15095 | return (measureSpec & MODE_MASK); |
| 15096 | } |
| 15097 | |
| 15098 | /** |
| 15099 | * Extracts the size from the supplied measure specification. |
| 15100 | * |
| 15101 | * @param measureSpec the measure specification to extract the size from |
| 15102 | * @return the size in pixels defined in the supplied measure specification |
| 15103 | */ |
| 15104 | public static int getSize(int measureSpec) { |
| 15105 | return (measureSpec & ~MODE_MASK); |
| 15106 | } |
| 15107 | |
| 15108 | /** |
| 15109 | * Returns a String representation of the specified measure |
| 15110 | * specification. |
| 15111 | * |
| 15112 | * @param measureSpec the measure specification to convert to a String |
| 15113 | * @return a String with the following format: "MeasureSpec: MODE SIZE" |
| 15114 | */ |
| 15115 | public static String toString(int measureSpec) { |
| 15116 | int mode = getMode(measureSpec); |
| 15117 | int size = getSize(measureSpec); |
| 15118 | |
| 15119 | StringBuilder sb = new StringBuilder("MeasureSpec: "); |
| 15120 | |
| 15121 | if (mode == UNSPECIFIED) |
| 15122 | sb.append("UNSPECIFIED "); |
| 15123 | else if (mode == EXACTLY) |
| 15124 | sb.append("EXACTLY "); |
| 15125 | else if (mode == AT_MOST) |
| 15126 | sb.append("AT_MOST "); |
| 15127 | else |
| 15128 | sb.append(mode).append(" "); |
| 15129 | |
| 15130 | sb.append(size); |
| 15131 | return sb.toString(); |
| 15132 | } |
| 15133 | } |
| 15134 | |
| 15135 | class CheckForLongPress implements Runnable { |
| 15136 | |
| 15137 | private int mOriginalWindowAttachCount; |
| 15138 | |
| 15139 | public void run() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 15140 | if (isPressed() && (mParent != null) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15141 | && mOriginalWindowAttachCount == mWindowAttachCount) { |
| 15142 | if (performLongClick()) { |
| 15143 | mHasPerformedLongPress = true; |
| 15144 | } |
| 15145 | } |
| 15146 | } |
| 15147 | |
| 15148 | public void rememberWindowAttachCount() { |
| 15149 | mOriginalWindowAttachCount = mWindowAttachCount; |
| 15150 | } |
| 15151 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15152 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 15153 | private final class CheckForTap implements Runnable { |
| 15154 | public void run() { |
| 15155 | mPrivateFlags &= ~PREPRESSED; |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 15156 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 15157 | checkForLongClick(ViewConfiguration.getTapTimeout()); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 15158 | } |
| 15159 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15160 | |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 15161 | private final class PerformClick implements Runnable { |
| 15162 | public void run() { |
| 15163 | performClick(); |
| 15164 | } |
| 15165 | } |
| 15166 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 15167 | /** @hide */ |
| 15168 | public void hackTurnOffWindowResizeAnim(boolean off) { |
| 15169 | mAttachInfo.mTurnOffWindowResizeAnim = off; |
| 15170 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15171 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15172 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 15173 | * This method returns a ViewPropertyAnimator object, which can be used to animate |
| 15174 | * specific properties on this View. |
| 15175 | * |
| 15176 | * @return ViewPropertyAnimator The ViewPropertyAnimator associated with this View. |
| 15177 | */ |
| 15178 | public ViewPropertyAnimator animate() { |
| 15179 | if (mAnimator == null) { |
| 15180 | mAnimator = new ViewPropertyAnimator(this); |
| 15181 | } |
| 15182 | return mAnimator; |
| 15183 | } |
| 15184 | |
| 15185 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15186 | * Interface definition for a callback to be invoked when a key event is |
| 15187 | * dispatched to this view. The callback will be invoked before the key |
| 15188 | * event is given to the view. |
| 15189 | */ |
| 15190 | public interface OnKeyListener { |
| 15191 | /** |
| 15192 | * Called when a key is dispatched to a view. This allows listeners to |
| 15193 | * get a chance to respond before the target view. |
| 15194 | * |
| 15195 | * @param v The view the key has been dispatched to. |
| 15196 | * @param keyCode The code for the physical key that was pressed |
| 15197 | * @param event The KeyEvent object containing full information about |
| 15198 | * the event. |
| 15199 | * @return True if the listener has consumed the event, false otherwise. |
| 15200 | */ |
| 15201 | boolean onKey(View v, int keyCode, KeyEvent event); |
| 15202 | } |
| 15203 | |
| 15204 | /** |
| 15205 | * Interface definition for a callback to be invoked when a touch event is |
| 15206 | * dispatched to this view. The callback will be invoked before the touch |
| 15207 | * event is given to the view. |
| 15208 | */ |
| 15209 | public interface OnTouchListener { |
| 15210 | /** |
| 15211 | * Called when a touch event is dispatched to a view. This allows listeners to |
| 15212 | * get a chance to respond before the target view. |
| 15213 | * |
| 15214 | * @param v The view the touch event has been dispatched to. |
| 15215 | * @param event The MotionEvent object containing full information about |
| 15216 | * the event. |
| 15217 | * @return True if the listener has consumed the event, false otherwise. |
| 15218 | */ |
| 15219 | boolean onTouch(View v, MotionEvent event); |
| 15220 | } |
| 15221 | |
| 15222 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 15223 | * Interface definition for a callback to be invoked when a hover event is |
| 15224 | * dispatched to this view. The callback will be invoked before the hover |
| 15225 | * event is given to the view. |
| 15226 | */ |
| 15227 | public interface OnHoverListener { |
| 15228 | /** |
| 15229 | * Called when a hover event is dispatched to a view. This allows listeners to |
| 15230 | * get a chance to respond before the target view. |
| 15231 | * |
| 15232 | * @param v The view the hover event has been dispatched to. |
| 15233 | * @param event The MotionEvent object containing full information about |
| 15234 | * the event. |
| 15235 | * @return True if the listener has consumed the event, false otherwise. |
| 15236 | */ |
| 15237 | boolean onHover(View v, MotionEvent event); |
| 15238 | } |
| 15239 | |
| 15240 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 15241 | * Interface definition for a callback to be invoked when a generic motion event is |
| 15242 | * dispatched to this view. The callback will be invoked before the generic motion |
| 15243 | * event is given to the view. |
| 15244 | */ |
| 15245 | public interface OnGenericMotionListener { |
| 15246 | /** |
| 15247 | * Called when a generic motion event is dispatched to a view. This allows listeners to |
| 15248 | * get a chance to respond before the target view. |
| 15249 | * |
| 15250 | * @param v The view the generic motion event has been dispatched to. |
| 15251 | * @param event The MotionEvent object containing full information about |
| 15252 | * the event. |
| 15253 | * @return True if the listener has consumed the event, false otherwise. |
| 15254 | */ |
| 15255 | boolean onGenericMotion(View v, MotionEvent event); |
| 15256 | } |
| 15257 | |
| 15258 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15259 | * Interface definition for a callback to be invoked when a view has been clicked and held. |
| 15260 | */ |
| 15261 | public interface OnLongClickListener { |
| 15262 | /** |
| 15263 | * Called when a view has been clicked and held. |
| 15264 | * |
| 15265 | * @param v The view that was clicked and held. |
| 15266 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 15267 | * @return true if the callback consumed the long click, false otherwise. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15268 | */ |
| 15269 | boolean onLongClick(View v); |
| 15270 | } |
| 15271 | |
| 15272 | /** |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 15273 | * Interface definition for a callback to be invoked when a drag is being dispatched |
| 15274 | * to this view. The callback will be invoked before the hosting view's own |
| 15275 | * onDrag(event) method. If the listener wants to fall back to the hosting view's |
| 15276 | * onDrag(event) behavior, it should return 'false' from this callback. |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 15277 | * |
| 15278 | * <div class="special reference"> |
| 15279 | * <h3>Developer Guides</h3> |
| 15280 | * <p>For a guide to implementing drag and drop features, read the |
| 15281 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 15282 | * </div> |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 15283 | */ |
| 15284 | public interface OnDragListener { |
| 15285 | /** |
| 15286 | * Called when a drag event is dispatched to a view. This allows listeners |
| 15287 | * to get a chance to override base View behavior. |
| 15288 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15289 | * @param v The View that received the drag event. |
| 15290 | * @param event The {@link android.view.DragEvent} object for the drag event. |
| 15291 | * @return {@code true} if the drag event was handled successfully, or {@code false} |
| 15292 | * if the drag event was not handled. Note that {@code false} will trigger the View |
| 15293 | * to call its {@link #onDragEvent(DragEvent) onDragEvent()} handler. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 15294 | */ |
| 15295 | boolean onDrag(View v, DragEvent event); |
| 15296 | } |
| 15297 | |
| 15298 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15299 | * Interface definition for a callback to be invoked when the focus state of |
| 15300 | * a view changed. |
| 15301 | */ |
| 15302 | public interface OnFocusChangeListener { |
| 15303 | /** |
| 15304 | * Called when the focus state of a view has changed. |
| 15305 | * |
| 15306 | * @param v The view whose state has changed. |
| 15307 | * @param hasFocus The new focus state of v. |
| 15308 | */ |
| 15309 | void onFocusChange(View v, boolean hasFocus); |
| 15310 | } |
| 15311 | |
| 15312 | /** |
| 15313 | * Interface definition for a callback to be invoked when a view is clicked. |
| 15314 | */ |
| 15315 | public interface OnClickListener { |
| 15316 | /** |
| 15317 | * Called when a view has been clicked. |
| 15318 | * |
| 15319 | * @param v The view that was clicked. |
| 15320 | */ |
| 15321 | void onClick(View v); |
| 15322 | } |
| 15323 | |
| 15324 | /** |
| 15325 | * Interface definition for a callback to be invoked when the context menu |
| 15326 | * for this view is being built. |
| 15327 | */ |
| 15328 | public interface OnCreateContextMenuListener { |
| 15329 | /** |
| 15330 | * Called when the context menu for this view is being built. It is not |
| 15331 | * safe to hold onto the menu after this method returns. |
| 15332 | * |
| 15333 | * @param menu The context menu that is being built |
| 15334 | * @param v The view for which the context menu is being built |
| 15335 | * @param menuInfo Extra information about the item for which the |
| 15336 | * context menu should be shown. This information will vary |
| 15337 | * depending on the class of v. |
| 15338 | */ |
| 15339 | void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo); |
| 15340 | } |
| 15341 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15342 | /** |
| 15343 | * Interface definition for a callback to be invoked when the status bar changes |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 15344 | * visibility. This reports <strong>global</strong> changes to the system UI |
| 15345 | * state, not just what the application is requesting. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15346 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 15347 | * @see View#setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15348 | */ |
| 15349 | public interface OnSystemUiVisibilityChangeListener { |
| 15350 | /** |
| 15351 | * Called when the status bar changes visibility because of a call to |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 15352 | * {@link View#setSystemUiVisibility(int)}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15353 | * |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 15354 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 15355 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. This tells you the |
| 15356 | * <strong>global</strong> state of the UI visibility flags, not what your |
| 15357 | * app is currently applying. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15358 | */ |
| 15359 | public void onSystemUiVisibilityChange(int visibility); |
| 15360 | } |
| 15361 | |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 15362 | /** |
| 15363 | * Interface definition for a callback to be invoked when this view is attached |
| 15364 | * or detached from its window. |
| 15365 | */ |
| 15366 | public interface OnAttachStateChangeListener { |
| 15367 | /** |
| 15368 | * Called when the view is attached to a window. |
| 15369 | * @param v The view that was attached |
| 15370 | */ |
| 15371 | public void onViewAttachedToWindow(View v); |
| 15372 | /** |
| 15373 | * Called when the view is detached from a window. |
| 15374 | * @param v The view that was detached |
| 15375 | */ |
| 15376 | public void onViewDetachedFromWindow(View v); |
| 15377 | } |
| 15378 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15379 | private final class UnsetPressedState implements Runnable { |
| 15380 | public void run() { |
| 15381 | setPressed(false); |
| 15382 | } |
| 15383 | } |
| 15384 | |
| 15385 | /** |
| 15386 | * Base class for derived classes that want to save and restore their own |
| 15387 | * state in {@link android.view.View#onSaveInstanceState()}. |
| 15388 | */ |
| 15389 | public static class BaseSavedState extends AbsSavedState { |
| 15390 | /** |
| 15391 | * Constructor used when reading from a parcel. Reads the state of the superclass. |
| 15392 | * |
| 15393 | * @param source |
| 15394 | */ |
| 15395 | public BaseSavedState(Parcel source) { |
| 15396 | super(source); |
| 15397 | } |
| 15398 | |
| 15399 | /** |
| 15400 | * Constructor called by derived classes when creating their SavedState objects |
| 15401 | * |
| 15402 | * @param superState The state of the superclass of this view |
| 15403 | */ |
| 15404 | public BaseSavedState(Parcelable superState) { |
| 15405 | super(superState); |
| 15406 | } |
| 15407 | |
| 15408 | public static final Parcelable.Creator<BaseSavedState> CREATOR = |
| 15409 | new Parcelable.Creator<BaseSavedState>() { |
| 15410 | public BaseSavedState createFromParcel(Parcel in) { |
| 15411 | return new BaseSavedState(in); |
| 15412 | } |
| 15413 | |
| 15414 | public BaseSavedState[] newArray(int size) { |
| 15415 | return new BaseSavedState[size]; |
| 15416 | } |
| 15417 | }; |
| 15418 | } |
| 15419 | |
| 15420 | /** |
| 15421 | * A set of information given to a view when it is attached to its parent |
| 15422 | * window. |
| 15423 | */ |
| 15424 | static class AttachInfo { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15425 | interface Callbacks { |
| 15426 | void playSoundEffect(int effectId); |
| 15427 | boolean performHapticFeedback(int effectId, boolean always); |
| 15428 | } |
| 15429 | |
| 15430 | /** |
| 15431 | * InvalidateInfo is used to post invalidate(int, int, int, int) messages |
| 15432 | * to a Handler. This class contains the target (View) to invalidate and |
| 15433 | * the coordinates of the dirty rectangle. |
| 15434 | * |
| 15435 | * For performance purposes, this class also implements a pool of up to |
| 15436 | * POOL_LIMIT objects that get reused. This reduces memory allocations |
| 15437 | * whenever possible. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15438 | */ |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 15439 | static class InvalidateInfo implements Poolable<InvalidateInfo> { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15440 | private static final int POOL_LIMIT = 10; |
Romain Guy | 2e9bbce | 2009-04-01 10:40:10 -0700 | [diff] [blame] | 15441 | private static final Pool<InvalidateInfo> sPool = Pools.synchronizedPool( |
| 15442 | Pools.finitePool(new PoolableManager<InvalidateInfo>() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 15443 | public InvalidateInfo newInstance() { |
| 15444 | return new InvalidateInfo(); |
| 15445 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15446 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 15447 | public void onAcquired(InvalidateInfo element) { |
| 15448 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15449 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 15450 | public void onReleased(InvalidateInfo element) { |
Romain Guy | 40c18f5 | 2011-09-01 17:01:18 -0700 | [diff] [blame] | 15451 | element.target = null; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 15452 | } |
| 15453 | }, POOL_LIMIT) |
| 15454 | ); |
| 15455 | |
| 15456 | private InvalidateInfo mNext; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 15457 | private boolean mIsPooled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15458 | |
| 15459 | View target; |
| 15460 | |
| 15461 | int left; |
| 15462 | int top; |
| 15463 | int right; |
| 15464 | int bottom; |
| 15465 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 15466 | public void setNextPoolable(InvalidateInfo element) { |
| 15467 | mNext = element; |
| 15468 | } |
| 15469 | |
| 15470 | public InvalidateInfo getNextPoolable() { |
| 15471 | return mNext; |
| 15472 | } |
| 15473 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15474 | static InvalidateInfo acquire() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 15475 | return sPool.acquire(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15476 | } |
| 15477 | |
| 15478 | void release() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 15479 | sPool.release(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15480 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 15481 | |
| 15482 | public boolean isPooled() { |
| 15483 | return mIsPooled; |
| 15484 | } |
| 15485 | |
| 15486 | public void setPooled(boolean isPooled) { |
| 15487 | mIsPooled = isPooled; |
| 15488 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15489 | } |
| 15490 | |
| 15491 | final IWindowSession mSession; |
| 15492 | |
| 15493 | final IWindow mWindow; |
| 15494 | |
| 15495 | final IBinder mWindowToken; |
| 15496 | |
| 15497 | final Callbacks mRootCallbacks; |
| 15498 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 15499 | HardwareCanvas mHardwareCanvas; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 15500 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15501 | /** |
| 15502 | * The top view of the hierarchy. |
| 15503 | */ |
| 15504 | View mRootView; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15505 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15506 | IBinder mPanelParentWindowToken; |
| 15507 | Surface mSurface; |
| 15508 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 15509 | boolean mHardwareAccelerated; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 15510 | boolean mHardwareAccelerationRequested; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 15511 | HardwareRenderer mHardwareRenderer; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15512 | |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 15513 | boolean mScreenOn; |
| 15514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15515 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15516 | * Scale factor used by the compatibility mode |
| 15517 | */ |
| 15518 | float mApplicationScale; |
| 15519 | |
| 15520 | /** |
| 15521 | * Indicates whether the application is in compatibility mode |
| 15522 | */ |
| 15523 | boolean mScalingRequired; |
| 15524 | |
| 15525 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 15526 | * If set, ViewAncestor doesn't use its lame animation for when the window resizes. |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 15527 | */ |
| 15528 | boolean mTurnOffWindowResizeAnim; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15529 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 15530 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15531 | * Left position of this view's window |
| 15532 | */ |
| 15533 | int mWindowLeft; |
| 15534 | |
| 15535 | /** |
| 15536 | * Top position of this view's window |
| 15537 | */ |
| 15538 | int mWindowTop; |
| 15539 | |
| 15540 | /** |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 15541 | * Indicates whether views need to use 32-bit drawing caches |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 15542 | */ |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 15543 | boolean mUse32BitDrawingCache; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 15544 | |
| 15545 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15546 | * For windows that are full-screen but using insets to layout inside |
| 15547 | * of the screen decorations, these are the current insets for the |
| 15548 | * content of the window. |
| 15549 | */ |
| 15550 | final Rect mContentInsets = new Rect(); |
| 15551 | |
| 15552 | /** |
| 15553 | * For windows that are full-screen but using insets to layout inside |
| 15554 | * of the screen decorations, these are the current insets for the |
| 15555 | * actual visible parts of the window. |
| 15556 | */ |
| 15557 | final Rect mVisibleInsets = new Rect(); |
| 15558 | |
| 15559 | /** |
| 15560 | * The internal insets given by this window. This value is |
| 15561 | * supplied by the client (through |
| 15562 | * {@link ViewTreeObserver.OnComputeInternalInsetsListener}) and will |
| 15563 | * be given to the window manager when changed to be used in laying |
| 15564 | * out windows behind it. |
| 15565 | */ |
| 15566 | final ViewTreeObserver.InternalInsetsInfo mGivenInternalInsets |
| 15567 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 15568 | |
| 15569 | /** |
| 15570 | * All views in the window's hierarchy that serve as scroll containers, |
| 15571 | * used to determine if the window can be resized or must be panned |
| 15572 | * to adjust for a soft input area. |
| 15573 | */ |
| 15574 | final ArrayList<View> mScrollContainers = new ArrayList<View>(); |
| 15575 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 15576 | final KeyEvent.DispatcherState mKeyDispatchState |
| 15577 | = new KeyEvent.DispatcherState(); |
| 15578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15579 | /** |
| 15580 | * Indicates whether the view's window currently has the focus. |
| 15581 | */ |
| 15582 | boolean mHasWindowFocus; |
| 15583 | |
| 15584 | /** |
| 15585 | * The current visibility of the window. |
| 15586 | */ |
| 15587 | int mWindowVisibility; |
| 15588 | |
| 15589 | /** |
| 15590 | * Indicates the time at which drawing started to occur. |
| 15591 | */ |
| 15592 | long mDrawingTime; |
| 15593 | |
| 15594 | /** |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 15595 | * Indicates whether or not ignoring the DIRTY_MASK flags. |
| 15596 | */ |
| 15597 | boolean mIgnoreDirtyState; |
| 15598 | |
| 15599 | /** |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 15600 | * This flag tracks when the mIgnoreDirtyState flag is set during draw(), |
| 15601 | * to avoid clearing that flag prematurely. |
| 15602 | */ |
| 15603 | boolean mSetIgnoreDirtyState = false; |
| 15604 | |
| 15605 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15606 | * Indicates whether the view's window is currently in touch mode. |
| 15607 | */ |
| 15608 | boolean mInTouchMode; |
| 15609 | |
| 15610 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 15611 | * Indicates that ViewAncestor should trigger a global layout change |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15612 | * the next time it performs a traversal |
| 15613 | */ |
| 15614 | boolean mRecomputeGlobalAttributes; |
| 15615 | |
| 15616 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 15617 | * Always report new attributes at next traversal. |
| 15618 | */ |
| 15619 | boolean mForceReportNewAttributes; |
| 15620 | |
| 15621 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15622 | * Set during a traveral if any views want to keep the screen on. |
| 15623 | */ |
| 15624 | boolean mKeepScreenOn; |
| 15625 | |
| 15626 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15627 | * Bitwise-or of all of the values that views have passed to setSystemUiVisibility(). |
| 15628 | */ |
| 15629 | int mSystemUiVisibility; |
| 15630 | |
| 15631 | /** |
| 15632 | * True if a view in this hierarchy has an OnSystemUiVisibilityChangeListener |
| 15633 | * attached. |
| 15634 | */ |
| 15635 | boolean mHasSystemUiListeners; |
| 15636 | |
| 15637 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15638 | * Set if the visibility of any views has changed. |
| 15639 | */ |
| 15640 | boolean mViewVisibilityChanged; |
| 15641 | |
| 15642 | /** |
| 15643 | * Set to true if a view has been scrolled. |
| 15644 | */ |
| 15645 | boolean mViewScrollChanged; |
| 15646 | |
| 15647 | /** |
| 15648 | * Global to the view hierarchy used as a temporary for dealing with |
| 15649 | * x/y points in the transparent region computations. |
| 15650 | */ |
| 15651 | final int[] mTransparentLocation = new int[2]; |
| 15652 | |
| 15653 | /** |
| 15654 | * Global to the view hierarchy used as a temporary for dealing with |
| 15655 | * x/y points in the ViewGroup.invalidateChild implementation. |
| 15656 | */ |
| 15657 | final int[] mInvalidateChildLocation = new int[2]; |
| 15658 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 15659 | |
| 15660 | /** |
| 15661 | * Global to the view hierarchy used as a temporary for dealing with |
| 15662 | * x/y location when view is transformed. |
| 15663 | */ |
| 15664 | final float[] mTmpTransformLocation = new float[2]; |
| 15665 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15666 | /** |
| 15667 | * The view tree observer used to dispatch global events like |
| 15668 | * layout, pre-draw, touch mode change, etc. |
| 15669 | */ |
| 15670 | final ViewTreeObserver mTreeObserver = new ViewTreeObserver(); |
| 15671 | |
| 15672 | /** |
| 15673 | * A Canvas used by the view hierarchy to perform bitmap caching. |
| 15674 | */ |
| 15675 | Canvas mCanvas; |
| 15676 | |
| 15677 | /** |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 15678 | * The view root impl. |
| 15679 | */ |
| 15680 | final ViewRootImpl mViewRootImpl; |
| 15681 | |
| 15682 | /** |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 15683 | * A Handler supplied by a view's {@link android.view.ViewRootImpl}. This |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15684 | * handler can be used to pump events in the UI events queue. |
| 15685 | */ |
| 15686 | final Handler mHandler; |
| 15687 | |
| 15688 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15689 | * Temporary for use in computing invalidate rectangles while |
| 15690 | * calling up the hierarchy. |
| 15691 | */ |
| 15692 | final Rect mTmpInvalRect = new Rect(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 15693 | |
| 15694 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 15695 | * Temporary for use in computing hit areas with transformed views |
| 15696 | */ |
| 15697 | final RectF mTmpTransformRect = new RectF(); |
| 15698 | |
| 15699 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 15700 | * Temporary list for use in collecting focusable descendents of a view. |
| 15701 | */ |
| 15702 | final ArrayList<View> mFocusablesTempList = new ArrayList<View>(24); |
| 15703 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15704 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 15705 | * The id of the window for accessibility purposes. |
| 15706 | */ |
| 15707 | int mAccessibilityWindowId = View.NO_ID; |
| 15708 | |
| 15709 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15710 | * Creates a new set of attachment information with the specified |
| 15711 | * events handler and thread. |
| 15712 | * |
| 15713 | * @param handler the events handler the view must use |
| 15714 | */ |
| 15715 | AttachInfo(IWindowSession session, IWindow window, |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 15716 | ViewRootImpl viewRootImpl, Handler handler, Callbacks effectPlayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15717 | mSession = session; |
| 15718 | mWindow = window; |
| 15719 | mWindowToken = window.asBinder(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 15720 | mViewRootImpl = viewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15721 | mHandler = handler; |
| 15722 | mRootCallbacks = effectPlayer; |
| 15723 | } |
| 15724 | } |
| 15725 | |
| 15726 | /** |
| 15727 | * <p>ScrollabilityCache holds various fields used by a View when scrolling |
| 15728 | * is supported. This avoids keeping too many unused fields in most |
| 15729 | * instances of View.</p> |
| 15730 | */ |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 15731 | private static class ScrollabilityCache implements Runnable { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15732 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 15733 | /** |
| 15734 | * Scrollbars are not visible |
| 15735 | */ |
| 15736 | public static final int OFF = 0; |
| 15737 | |
| 15738 | /** |
| 15739 | * Scrollbars are visible |
| 15740 | */ |
| 15741 | public static final int ON = 1; |
| 15742 | |
| 15743 | /** |
| 15744 | * Scrollbars are fading away |
| 15745 | */ |
| 15746 | public static final int FADING = 2; |
| 15747 | |
| 15748 | public boolean fadeScrollBars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15749 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15750 | public int fadingEdgeLength; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 15751 | public int scrollBarDefaultDelayBeforeFade; |
| 15752 | public int scrollBarFadeDuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15753 | |
| 15754 | public int scrollBarSize; |
| 15755 | public ScrollBarDrawable scrollBar; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 15756 | public float[] interpolatorValues; |
| 15757 | public View host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15758 | |
| 15759 | public final Paint paint; |
| 15760 | public final Matrix matrix; |
| 15761 | public Shader shader; |
| 15762 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 15763 | public final Interpolator scrollBarInterpolator = new Interpolator(1, 2); |
| 15764 | |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 15765 | private static final float[] OPAQUE = { 255 }; |
| 15766 | private static final float[] TRANSPARENT = { 0.0f }; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15767 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 15768 | /** |
| 15769 | * When fading should start. This time moves into the future every time |
| 15770 | * a new scroll happens. Measured based on SystemClock.uptimeMillis() |
| 15771 | */ |
| 15772 | public long fadeStartTime; |
| 15773 | |
| 15774 | |
| 15775 | /** |
| 15776 | * The current state of the scrollbars: ON, OFF, or FADING |
| 15777 | */ |
| 15778 | public int state = OFF; |
| 15779 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15780 | private int mLastColor; |
| 15781 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 15782 | public ScrollabilityCache(ViewConfiguration configuration, View host) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15783 | fadingEdgeLength = configuration.getScaledFadingEdgeLength(); |
| 15784 | scrollBarSize = configuration.getScaledScrollBarSize(); |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 15785 | scrollBarDefaultDelayBeforeFade = ViewConfiguration.getScrollDefaultDelay(); |
| 15786 | scrollBarFadeDuration = ViewConfiguration.getScrollBarFadeDuration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15787 | |
| 15788 | paint = new Paint(); |
| 15789 | matrix = new Matrix(); |
| 15790 | // use use a height of 1, and then wack the matrix each time we |
| 15791 | // actually use it. |
| 15792 | shader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15793 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15794 | paint.setShader(shader); |
| 15795 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 15796 | this.host = host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15797 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15798 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15799 | public void setFadeColor(int color) { |
| 15800 | if (color != 0 && color != mLastColor) { |
| 15801 | mLastColor = color; |
| 15802 | color |= 0xFF000000; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15803 | |
Romain Guy | e55e1a7 | 2009-08-27 10:42:26 -0700 | [diff] [blame] | 15804 | shader = new LinearGradient(0, 0, 0, 1, color | 0xFF000000, |
| 15805 | color & 0x00FFFFFF, Shader.TileMode.CLAMP); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15807 | paint.setShader(shader); |
| 15808 | // Restore the default transfer mode (src_over) |
| 15809 | paint.setXfermode(null); |
| 15810 | } |
| 15811 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15812 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 15813 | public void run() { |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 15814 | long now = AnimationUtils.currentAnimationTimeMillis(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 15815 | if (now >= fadeStartTime) { |
| 15816 | |
| 15817 | // the animation fades the scrollbars out by changing |
| 15818 | // the opacity (alpha) from fully opaque to fully |
| 15819 | // transparent |
| 15820 | int nextFrame = (int) now; |
| 15821 | int framesCount = 0; |
| 15822 | |
| 15823 | Interpolator interpolator = scrollBarInterpolator; |
| 15824 | |
| 15825 | // Start opaque |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 15826 | interpolator.setKeyFrame(framesCount++, nextFrame, OPAQUE); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 15827 | |
| 15828 | // End transparent |
| 15829 | nextFrame += scrollBarFadeDuration; |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 15830 | interpolator.setKeyFrame(framesCount, nextFrame, TRANSPARENT); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 15831 | |
| 15832 | state = FADING; |
| 15833 | |
| 15834 | // Kick off the fade animation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 15835 | host.invalidate(true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 15836 | } |
| 15837 | } |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 15838 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 15839 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 15840 | /** |
| 15841 | * Resuable callback for sending |
| 15842 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 15843 | */ |
| 15844 | private class SendViewScrolledAccessibilityEvent implements Runnable { |
| 15845 | public volatile boolean mIsPending; |
| 15846 | |
| 15847 | public void run() { |
| 15848 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED); |
| 15849 | mIsPending = false; |
| 15850 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15851 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 15852 | |
| 15853 | /** |
| 15854 | * <p> |
| 15855 | * This class represents a delegate that can be registered in a {@link View} |
| 15856 | * to enhance accessibility support via composition rather via inheritance. |
| 15857 | * It is specifically targeted to widget developers that extend basic View |
| 15858 | * classes i.e. classes in package android.view, that would like their |
| 15859 | * applications to be backwards compatible. |
| 15860 | * </p> |
| 15861 | * <p> |
| 15862 | * A scenario in which a developer would like to use an accessibility delegate |
| 15863 | * is overriding a method introduced in a later API version then the minimal API |
| 15864 | * version supported by the application. For example, the method |
| 15865 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} is not available |
| 15866 | * in API version 4 when the accessibility APIs were first introduced. If a |
| 15867 | * developer would like his application to run on API version 4 devices (assuming |
| 15868 | * all other APIs used by the application are version 4 or lower) and take advantage |
| 15869 | * of this method, instead of overriding the method which would break the application's |
| 15870 | * backwards compatibility, he can override the corresponding method in this |
| 15871 | * delegate and register the delegate in the target View if the API version of |
| 15872 | * the system is high enough i.e. the API version is same or higher to the API |
| 15873 | * version that introduced |
| 15874 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)}. |
| 15875 | * </p> |
| 15876 | * <p> |
| 15877 | * Here is an example implementation: |
| 15878 | * </p> |
| 15879 | * <code><pre><p> |
| 15880 | * if (Build.VERSION.SDK_INT >= 14) { |
| 15881 | * // If the API version is equal of higher than the version in |
| 15882 | * // which onInitializeAccessibilityNodeInfo was introduced we |
| 15883 | * // register a delegate with a customized implementation. |
| 15884 | * View view = findViewById(R.id.view_id); |
| 15885 | * view.setAccessibilityDelegate(new AccessibilityDelegate() { |
| 15886 | * public void onInitializeAccessibilityNodeInfo(View host, |
| 15887 | * AccessibilityNodeInfo info) { |
| 15888 | * // Let the default implementation populate the info. |
| 15889 | * super.onInitializeAccessibilityNodeInfo(host, info); |
| 15890 | * // Set some other information. |
| 15891 | * info.setEnabled(host.isEnabled()); |
| 15892 | * } |
| 15893 | * }); |
| 15894 | * } |
| 15895 | * </code></pre></p> |
| 15896 | * <p> |
| 15897 | * This delegate contains methods that correspond to the accessibility methods |
| 15898 | * in View. If a delegate has been specified the implementation in View hands |
| 15899 | * off handling to the corresponding method in this delegate. The default |
| 15900 | * implementation the delegate methods behaves exactly as the corresponding |
| 15901 | * method in View for the case of no accessibility delegate been set. Hence, |
| 15902 | * to customize the behavior of a View method, clients can override only the |
| 15903 | * corresponding delegate method without altering the behavior of the rest |
| 15904 | * accessibility related methods of the host view. |
| 15905 | * </p> |
| 15906 | */ |
| 15907 | public static class AccessibilityDelegate { |
| 15908 | |
| 15909 | /** |
| 15910 | * Sends an accessibility event of the given type. If accessibility is not |
| 15911 | * enabled this method has no effect. |
| 15912 | * <p> |
| 15913 | * The default implementation behaves as {@link View#sendAccessibilityEvent(int) |
| 15914 | * View#sendAccessibilityEvent(int)} for the case of no accessibility delegate |
| 15915 | * been set. |
| 15916 | * </p> |
| 15917 | * |
| 15918 | * @param host The View hosting the delegate. |
| 15919 | * @param eventType The type of the event to send. |
| 15920 | * |
| 15921 | * @see View#sendAccessibilityEvent(int) View#sendAccessibilityEvent(int) |
| 15922 | */ |
| 15923 | public void sendAccessibilityEvent(View host, int eventType) { |
| 15924 | host.sendAccessibilityEventInternal(eventType); |
| 15925 | } |
| 15926 | |
| 15927 | /** |
| 15928 | * Sends an accessibility event. This method behaves exactly as |
| 15929 | * {@link #sendAccessibilityEvent(View, int)} but takes as an argument an |
| 15930 | * empty {@link AccessibilityEvent} and does not perform a check whether |
| 15931 | * accessibility is enabled. |
| 15932 | * <p> |
| 15933 | * The default implementation behaves as |
| 15934 | * {@link View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 15935 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent)} for |
| 15936 | * the case of no accessibility delegate been set. |
| 15937 | * </p> |
| 15938 | * |
| 15939 | * @param host The View hosting the delegate. |
| 15940 | * @param event The event to send. |
| 15941 | * |
| 15942 | * @see View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 15943 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 15944 | */ |
| 15945 | public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) { |
| 15946 | host.sendAccessibilityEventUncheckedInternal(event); |
| 15947 | } |
| 15948 | |
| 15949 | /** |
| 15950 | * Dispatches an {@link AccessibilityEvent} to the host {@link View} first and then |
| 15951 | * to its children for adding their text content to the event. |
| 15952 | * <p> |
| 15953 | * The default implementation behaves as |
| 15954 | * {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 15955 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 15956 | * the case of no accessibility delegate been set. |
| 15957 | * </p> |
| 15958 | * |
| 15959 | * @param host The View hosting the delegate. |
| 15960 | * @param event The event. |
| 15961 | * @return True if the event population was completed. |
| 15962 | * |
| 15963 | * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 15964 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 15965 | */ |
| 15966 | public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 15967 | return host.dispatchPopulateAccessibilityEventInternal(event); |
| 15968 | } |
| 15969 | |
| 15970 | /** |
| 15971 | * Gives a chance to the host View to populate the accessibility event with its |
| 15972 | * text content. |
| 15973 | * <p> |
| 15974 | * The default implementation behaves as |
| 15975 | * {@link View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 15976 | * View#onPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 15977 | * the case of no accessibility delegate been set. |
| 15978 | * </p> |
| 15979 | * |
| 15980 | * @param host The View hosting the delegate. |
| 15981 | * @param event The accessibility event which to populate. |
| 15982 | * |
| 15983 | * @see View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 15984 | * View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 15985 | */ |
| 15986 | public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 15987 | host.onPopulateAccessibilityEventInternal(event); |
| 15988 | } |
| 15989 | |
| 15990 | /** |
| 15991 | * Initializes an {@link AccessibilityEvent} with information about the |
| 15992 | * the host View which is the event source. |
| 15993 | * <p> |
| 15994 | * The default implementation behaves as |
| 15995 | * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 15996 | * View#onInitializeAccessibilityEvent(AccessibilityEvent)} for |
| 15997 | * the case of no accessibility delegate been set. |
| 15998 | * </p> |
| 15999 | * |
| 16000 | * @param host The View hosting the delegate. |
| 16001 | * @param event The event to initialize. |
| 16002 | * |
| 16003 | * @see View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 16004 | * View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 16005 | */ |
| 16006 | public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { |
| 16007 | host.onInitializeAccessibilityEventInternal(event); |
| 16008 | } |
| 16009 | |
| 16010 | /** |
| 16011 | * Initializes an {@link AccessibilityNodeInfo} with information about the host view. |
| 16012 | * <p> |
| 16013 | * The default implementation behaves as |
| 16014 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 16015 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} for |
| 16016 | * the case of no accessibility delegate been set. |
| 16017 | * </p> |
| 16018 | * |
| 16019 | * @param host The View hosting the delegate. |
| 16020 | * @param info The instance to initialize. |
| 16021 | * |
| 16022 | * @see View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 16023 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 16024 | */ |
| 16025 | public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 16026 | host.onInitializeAccessibilityNodeInfoInternal(info); |
| 16027 | } |
| 16028 | |
| 16029 | /** |
| 16030 | * Called when a child of the host View has requested sending an |
| 16031 | * {@link AccessibilityEvent} and gives an opportunity to the parent (the host) |
| 16032 | * to augment the event. |
| 16033 | * <p> |
| 16034 | * The default implementation behaves as |
| 16035 | * {@link ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 16036 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent)} for |
| 16037 | * the case of no accessibility delegate been set. |
| 16038 | * </p> |
| 16039 | * |
| 16040 | * @param host The View hosting the delegate. |
| 16041 | * @param child The child which requests sending the event. |
| 16042 | * @param event The event to be sent. |
| 16043 | * @return True if the event should be sent |
| 16044 | * |
| 16045 | * @see ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 16046 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 16047 | */ |
| 16048 | public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, |
| 16049 | AccessibilityEvent event) { |
| 16050 | return host.onRequestSendAccessibilityEventInternal(child, event); |
| 16051 | } |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 16052 | |
| 16053 | /** |
| 16054 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 16055 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 16056 | * that explore the window content. |
| 16057 | * <p> |
| 16058 | * The default implementation behaves as |
| 16059 | * {@link View#getAccessibilityNodeProvider() View#getAccessibilityNodeProvider()} for |
| 16060 | * the case of no accessibility delegate been set. |
| 16061 | * </p> |
| 16062 | * |
| 16063 | * @return The provider. |
| 16064 | * |
| 16065 | * @see AccessibilityNodeProvider |
| 16066 | */ |
| 16067 | public AccessibilityNodeProvider getAccessibilityNodeProvider(View host) { |
| 16068 | return null; |
| 16069 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 16070 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16071 | } |