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.*; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 74 | import static java.lang.Math.max; |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 75 | |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 76 | import com.android.internal.R; |
| 77 | import com.android.internal.util.Predicate; |
| 78 | import com.android.internal.view.menu.MenuBuilder; |
| 79 | |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 80 | import java.lang.ref.WeakReference; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 81 | import java.lang.reflect.InvocationTargetException; |
| 82 | import java.lang.reflect.Method; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import java.util.ArrayList; |
| 84 | import java.util.Arrays; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 85 | import java.util.Locale; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 86 | import java.util.concurrent.CopyOnWriteArrayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * <p> |
| 90 | * This class represents the basic building block for user interface components. A View |
| 91 | * occupies a rectangular area on the screen and is responsible for drawing and |
| 92 | * 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] | 93 | * 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] | 94 | * {@link android.view.ViewGroup} subclass is the base class for <em>layouts</em>, which |
| 95 | * are invisible containers that hold other Views (or other ViewGroups) and define |
| 96 | * their layout properties. |
| 97 | * </p> |
| 98 | * |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 99 | * <div class="special reference"> |
| 100 | * <h3>Developer Guides</h3> |
| 101 | * <p>For information about using this class to develop your application's user interface, |
| 102 | * 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] | 103 | * </div> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 104 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | * <a name="Using"></a> |
| 106 | * <h3>Using Views</h3> |
| 107 | * <p> |
| 108 | * All of the views in a window are arranged in a single tree. You can add views |
| 109 | * either from code or by specifying a tree of views in one or more XML layout |
| 110 | * files. There are many specialized subclasses of views that act as controls or |
| 111 | * are capable of displaying text, images, or other content. |
| 112 | * </p> |
| 113 | * <p> |
| 114 | * Once you have created a tree of views, there are typically a few types of |
| 115 | * common operations you may wish to perform: |
| 116 | * <ul> |
| 117 | * <li><strong>Set properties:</strong> for example setting the text of a |
| 118 | * {@link android.widget.TextView}. The available properties and the methods |
| 119 | * that set them will vary among the different subclasses of views. Note that |
| 120 | * properties that are known at build time can be set in the XML layout |
| 121 | * files.</li> |
| 122 | * <li><strong>Set focus:</strong> The framework will handled moving focus in |
| 123 | * response to user input. To force focus to a specific view, call |
| 124 | * {@link #requestFocus}.</li> |
| 125 | * <li><strong>Set up listeners:</strong> Views allow clients to set listeners |
| 126 | * that will be notified when something interesting happens to the view. For |
| 127 | * example, all views will let you set a listener to be notified when the view |
| 128 | * gains or loses focus. You can register such a listener using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 129 | * {@link #setOnFocusChangeListener(android.view.View.OnFocusChangeListener)}. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 130 | * Other view subclasses offer more specialized listeners. For example, a Button |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 131 | * 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] | 132 | * <li><strong>Set visibility:</strong> You can hide or show views using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 133 | * {@link #setVisibility(int)}.</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | * </ul> |
| 135 | * </p> |
| 136 | * <p><em> |
| 137 | * Note: The Android framework is responsible for measuring, laying out and |
| 138 | * drawing views. You should not call methods that perform these actions on |
| 139 | * views yourself unless you are actually implementing a |
| 140 | * {@link android.view.ViewGroup}. |
| 141 | * </em></p> |
| 142 | * |
| 143 | * <a name="Lifecycle"></a> |
| 144 | * <h3>Implementing a Custom View</h3> |
| 145 | * |
| 146 | * <p> |
| 147 | * To implement a custom view, you will usually begin by providing overrides for |
| 148 | * some of the standard methods that the framework calls on all views. You do |
| 149 | * not need to override all of these methods. In fact, you can start by just |
| 150 | * overriding {@link #onDraw(android.graphics.Canvas)}. |
| 151 | * <table border="2" width="85%" align="center" cellpadding="5"> |
| 152 | * <thead> |
| 153 | * <tr><th>Category</th> <th>Methods</th> <th>Description</th></tr> |
| 154 | * </thead> |
| 155 | * |
| 156 | * <tbody> |
| 157 | * <tr> |
| 158 | * <td rowspan="2">Creation</td> |
| 159 | * <td>Constructors</td> |
| 160 | * <td>There is a form of the constructor that are called when the view |
| 161 | * is created from code and a form that is called when the view is |
| 162 | * inflated from a layout file. The second form should parse and apply |
| 163 | * any attributes defined in the layout file. |
| 164 | * </td> |
| 165 | * </tr> |
| 166 | * <tr> |
| 167 | * <td><code>{@link #onFinishInflate()}</code></td> |
| 168 | * <td>Called after a view and all of its children has been inflated |
| 169 | * from XML.</td> |
| 170 | * </tr> |
| 171 | * |
| 172 | * <tr> |
| 173 | * <td rowspan="3">Layout</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 174 | * <td><code>{@link #onMeasure(int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | * <td>Called to determine the size requirements for this view and all |
| 176 | * of its children. |
| 177 | * </td> |
| 178 | * </tr> |
| 179 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 180 | * <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] | 181 | * <td>Called when this view should assign a size and position to all |
| 182 | * of its children. |
| 183 | * </td> |
| 184 | * </tr> |
| 185 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 186 | * <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] | 187 | * <td>Called when the size of this view has changed. |
| 188 | * </td> |
| 189 | * </tr> |
| 190 | * |
| 191 | * <tr> |
| 192 | * <td>Drawing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 193 | * <td><code>{@link #onDraw(android.graphics.Canvas)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | * <td>Called when the view should render its content. |
| 195 | * </td> |
| 196 | * </tr> |
| 197 | * |
| 198 | * <tr> |
| 199 | * <td rowspan="4">Event processing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 200 | * <td><code>{@link #onKeyDown(int, KeyEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | * <td>Called when a new key event occurs. |
| 202 | * </td> |
| 203 | * </tr> |
| 204 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 205 | * <td><code>{@link #onKeyUp(int, KeyEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | * <td>Called when a key up event occurs. |
| 207 | * </td> |
| 208 | * </tr> |
| 209 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 210 | * <td><code>{@link #onTrackballEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | * <td>Called when a trackball motion event occurs. |
| 212 | * </td> |
| 213 | * </tr> |
| 214 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 215 | * <td><code>{@link #onTouchEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | * <td>Called when a touch screen motion event occurs. |
| 217 | * </td> |
| 218 | * </tr> |
| 219 | * |
| 220 | * <tr> |
| 221 | * <td rowspan="2">Focus</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 222 | * <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] | 223 | * <td>Called when the view gains or loses focus. |
| 224 | * </td> |
| 225 | * </tr> |
| 226 | * |
| 227 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 228 | * <td><code>{@link #onWindowFocusChanged(boolean)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | * <td>Called when the window containing the view gains or loses focus. |
| 230 | * </td> |
| 231 | * </tr> |
| 232 | * |
| 233 | * <tr> |
| 234 | * <td rowspan="3">Attaching</td> |
| 235 | * <td><code>{@link #onAttachedToWindow()}</code></td> |
| 236 | * <td>Called when the view is attached to a window. |
| 237 | * </td> |
| 238 | * </tr> |
| 239 | * |
| 240 | * <tr> |
| 241 | * <td><code>{@link #onDetachedFromWindow}</code></td> |
| 242 | * <td>Called when the view is detached from its window. |
| 243 | * </td> |
| 244 | * </tr> |
| 245 | * |
| 246 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 247 | * <td><code>{@link #onWindowVisibilityChanged(int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | * <td>Called when the visibility of the window containing the view |
| 249 | * has changed. |
| 250 | * </td> |
| 251 | * </tr> |
| 252 | * </tbody> |
| 253 | * |
| 254 | * </table> |
| 255 | * </p> |
| 256 | * |
| 257 | * <a name="IDs"></a> |
| 258 | * <h3>IDs</h3> |
| 259 | * Views may have an integer id associated with them. These ids are typically |
| 260 | * assigned in the layout XML files, and are used to find specific views within |
| 261 | * the view tree. A common pattern is to: |
| 262 | * <ul> |
| 263 | * <li>Define a Button in the layout file and assign it a unique ID. |
| 264 | * <pre> |
Gilles Debunne | 0243caf | 2010-08-24 23:06:35 -0700 | [diff] [blame] | 265 | * <Button |
| 266 | * android:id="@+id/my_button" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | * android:layout_width="wrap_content" |
| 268 | * android:layout_height="wrap_content" |
| 269 | * android:text="@string/my_button_text"/> |
| 270 | * </pre></li> |
| 271 | * <li>From the onCreate method of an Activity, find the Button |
| 272 | * <pre class="prettyprint"> |
| 273 | * Button myButton = (Button) findViewById(R.id.my_button); |
| 274 | * </pre></li> |
| 275 | * </ul> |
| 276 | * <p> |
| 277 | * View IDs need not be unique throughout the tree, but it is good practice to |
| 278 | * ensure that they are at least unique within the part of the tree you are |
| 279 | * searching. |
| 280 | * </p> |
| 281 | * |
| 282 | * <a name="Position"></a> |
| 283 | * <h3>Position</h3> |
| 284 | * <p> |
| 285 | * The geometry of a view is that of a rectangle. A view has a location, |
| 286 | * expressed as a pair of <em>left</em> and <em>top</em> coordinates, and |
| 287 | * two dimensions, expressed as a width and a height. The unit for location |
| 288 | * and dimensions is the pixel. |
| 289 | * </p> |
| 290 | * |
| 291 | * <p> |
| 292 | * It is possible to retrieve the location of a view by invoking the methods |
| 293 | * {@link #getLeft()} and {@link #getTop()}. The former returns the left, or X, |
| 294 | * coordinate of the rectangle representing the view. The latter returns the |
| 295 | * top, or Y, coordinate of the rectangle representing the view. These methods |
| 296 | * both return the location of the view relative to its parent. For instance, |
| 297 | * when getLeft() returns 20, that means the view is located 20 pixels to the |
| 298 | * right of the left edge of its direct parent. |
| 299 | * </p> |
| 300 | * |
| 301 | * <p> |
| 302 | * In addition, several convenience methods are offered to avoid unnecessary |
| 303 | * computations, namely {@link #getRight()} and {@link #getBottom()}. |
| 304 | * These methods return the coordinates of the right and bottom edges of the |
| 305 | * rectangle representing the view. For instance, calling {@link #getRight()} |
| 306 | * is similar to the following computation: <code>getLeft() + getWidth()</code> |
| 307 | * (see <a href="#SizePaddingMargins">Size</a> for more information about the width.) |
| 308 | * </p> |
| 309 | * |
| 310 | * <a name="SizePaddingMargins"></a> |
| 311 | * <h3>Size, padding and margins</h3> |
| 312 | * <p> |
| 313 | * The size of a view is expressed with a width and a height. A view actually |
| 314 | * possess two pairs of width and height values. |
| 315 | * </p> |
| 316 | * |
| 317 | * <p> |
| 318 | * The first pair is known as <em>measured width</em> and |
| 319 | * <em>measured height</em>. These dimensions define how big a view wants to be |
| 320 | * within its parent (see <a href="#Layout">Layout</a> for more details.) The |
| 321 | * measured dimensions can be obtained by calling {@link #getMeasuredWidth()} |
| 322 | * and {@link #getMeasuredHeight()}. |
| 323 | * </p> |
| 324 | * |
| 325 | * <p> |
| 326 | * The second pair is simply known as <em>width</em> and <em>height</em>, or |
| 327 | * sometimes <em>drawing width</em> and <em>drawing height</em>. These |
| 328 | * dimensions define the actual size of the view on screen, at drawing time and |
| 329 | * after layout. These values may, but do not have to, be different from the |
| 330 | * measured width and height. The width and height can be obtained by calling |
| 331 | * {@link #getWidth()} and {@link #getHeight()}. |
| 332 | * </p> |
| 333 | * |
| 334 | * <p> |
| 335 | * To measure its dimensions, a view takes into account its padding. The padding |
| 336 | * is expressed in pixels for the left, top, right and bottom parts of the view. |
| 337 | * Padding can be used to offset the content of the view by a specific amount of |
| 338 | * pixels. For instance, a left padding of 2 will push the view's content by |
| 339 | * 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] | 340 | * {@link #setPadding(int, int, int, int)} or {@link #setPaddingRelative(int, int, int, int)} |
| 341 | * method and queried by calling {@link #getPaddingLeft()}, {@link #getPaddingTop()}, |
| 342 | * {@link #getPaddingRight()}, {@link #getPaddingBottom()}, {@link #getPaddingStart()}, |
| 343 | * {@link #getPaddingEnd()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | * </p> |
| 345 | * |
| 346 | * <p> |
| 347 | * Even though a view can define a padding, it does not provide any support for |
| 348 | * margins. However, view groups provide such a support. Refer to |
| 349 | * {@link android.view.ViewGroup} and |
| 350 | * {@link android.view.ViewGroup.MarginLayoutParams} for further information. |
| 351 | * </p> |
| 352 | * |
| 353 | * <a name="Layout"></a> |
| 354 | * <h3>Layout</h3> |
| 355 | * <p> |
| 356 | * Layout is a two pass process: a measure pass and a layout pass. The measuring |
| 357 | * pass is implemented in {@link #measure(int, int)} and is a top-down traversal |
| 358 | * of the view tree. Each view pushes dimension specifications down the tree |
| 359 | * during the recursion. At the end of the measure pass, every view has stored |
| 360 | * its measurements. The second pass happens in |
| 361 | * {@link #layout(int,int,int,int)} and is also top-down. During |
| 362 | * this pass each parent is responsible for positioning all of its children |
| 363 | * using the sizes computed in the measure pass. |
| 364 | * </p> |
| 365 | * |
| 366 | * <p> |
| 367 | * When a view's measure() method returns, its {@link #getMeasuredWidth()} and |
| 368 | * {@link #getMeasuredHeight()} values must be set, along with those for all of |
| 369 | * that view's descendants. A view's measured width and measured height values |
| 370 | * must respect the constraints imposed by the view's parents. This guarantees |
| 371 | * that at the end of the measure pass, all parents accept all of their |
| 372 | * children's measurements. A parent view may call measure() more than once on |
| 373 | * its children. For example, the parent may measure each child once with |
| 374 | * unspecified dimensions to find out how big they want to be, then call |
| 375 | * measure() on them again with actual numbers if the sum of all the children's |
| 376 | * unconstrained sizes is too big or too small. |
| 377 | * </p> |
| 378 | * |
| 379 | * <p> |
| 380 | * The measure pass uses two classes to communicate dimensions. The |
| 381 | * {@link MeasureSpec} class is used by views to tell their parents how they |
| 382 | * want to be measured and positioned. The base LayoutParams class just |
| 383 | * describes how big the view wants to be for both width and height. For each |
| 384 | * dimension, it can specify one of: |
| 385 | * <ul> |
| 386 | * <li> an exact number |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 387 | * <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] | 388 | * (minus padding) |
| 389 | * <li> WRAP_CONTENT, which means that the view wants to be just big enough to |
| 390 | * enclose its content (plus padding). |
| 391 | * </ul> |
| 392 | * There are subclasses of LayoutParams for different subclasses of ViewGroup. |
| 393 | * For example, AbsoluteLayout has its own subclass of LayoutParams which adds |
| 394 | * an X and Y value. |
| 395 | * </p> |
| 396 | * |
| 397 | * <p> |
| 398 | * MeasureSpecs are used to push requirements down the tree from parent to |
| 399 | * child. A MeasureSpec can be in one of three modes: |
| 400 | * <ul> |
| 401 | * <li>UNSPECIFIED: This is used by a parent to determine the desired dimension |
| 402 | * of a child view. For example, a LinearLayout may call measure() on its child |
| 403 | * with the height set to UNSPECIFIED and a width of EXACTLY 240 to find out how |
| 404 | * tall the child view wants to be given a width of 240 pixels. |
| 405 | * <li>EXACTLY: This is used by the parent to impose an exact size on the |
| 406 | * child. The child must use this size, and guarantee that all of its |
| 407 | * descendants will fit within this size. |
| 408 | * <li>AT_MOST: This is used by the parent to impose a maximum size on the |
| 409 | * child. The child must gurantee that it and all of its descendants will fit |
| 410 | * within this size. |
| 411 | * </ul> |
| 412 | * </p> |
| 413 | * |
| 414 | * <p> |
| 415 | * To intiate a layout, call {@link #requestLayout}. This method is typically |
| 416 | * called by a view on itself when it believes that is can no longer fit within |
| 417 | * its current bounds. |
| 418 | * </p> |
| 419 | * |
| 420 | * <a name="Drawing"></a> |
| 421 | * <h3>Drawing</h3> |
| 422 | * <p> |
| 423 | * Drawing is handled by walking the tree and rendering each view that |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 424 | * 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] | 425 | * this means that parents will draw before (i.e., behind) their children, with |
| 426 | * siblings drawn in the order they appear in the tree. |
| 427 | * If you set a background drawable for a View, then the View will draw it for you |
| 428 | * before calling back to its <code>onDraw()</code> method. |
| 429 | * </p> |
| 430 | * |
| 431 | * <p> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 432 | * 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] | 433 | * </p> |
| 434 | * |
| 435 | * <p> |
| 436 | * To force a view to draw, call {@link #invalidate()}. |
| 437 | * </p> |
| 438 | * |
| 439 | * <a name="EventHandlingThreading"></a> |
| 440 | * <h3>Event Handling and Threading</h3> |
| 441 | * <p> |
| 442 | * The basic cycle of a view is as follows: |
| 443 | * <ol> |
| 444 | * <li>An event comes in and is dispatched to the appropriate view. The view |
| 445 | * handles the event and notifies any listeners.</li> |
| 446 | * <li>If in the course of processing the event, the view's bounds may need |
| 447 | * to be changed, the view will call {@link #requestLayout()}.</li> |
| 448 | * <li>Similarly, if in the course of processing the event the view's appearance |
| 449 | * may need to be changed, the view will call {@link #invalidate()}.</li> |
| 450 | * <li>If either {@link #requestLayout()} or {@link #invalidate()} were called, |
| 451 | * the framework will take care of measuring, laying out, and drawing the tree |
| 452 | * as appropriate.</li> |
| 453 | * </ol> |
| 454 | * </p> |
| 455 | * |
| 456 | * <p><em>Note: The entire view tree is single threaded. You must always be on |
| 457 | * the UI thread when calling any method on any view.</em> |
| 458 | * If you are doing work on other threads and want to update the state of a view |
| 459 | * from that thread, you should use a {@link Handler}. |
| 460 | * </p> |
| 461 | * |
| 462 | * <a name="FocusHandling"></a> |
| 463 | * <h3>Focus Handling</h3> |
| 464 | * <p> |
| 465 | * The framework will handle routine focus movement in response to user input. |
| 466 | * This includes changing the focus as views are removed or hidden, or as new |
| 467 | * views become available. Views indicate their willingness to take focus |
| 468 | * through the {@link #isFocusable} method. To change whether a view can take |
| 469 | * focus, call {@link #setFocusable(boolean)}. When in touch mode (see notes below) |
| 470 | * views indicate whether they still would like focus via {@link #isFocusableInTouchMode} |
| 471 | * and can change this via {@link #setFocusableInTouchMode(boolean)}. |
| 472 | * </p> |
| 473 | * <p> |
| 474 | * Focus movement is based on an algorithm which finds the nearest neighbor in a |
| 475 | * given direction. In rare cases, the default algorithm may not match the |
| 476 | * intended behavior of the developer. In these situations, you can provide |
| 477 | * explicit overrides by using these XML attributes in the layout file: |
| 478 | * <pre> |
| 479 | * nextFocusDown |
| 480 | * nextFocusLeft |
| 481 | * nextFocusRight |
| 482 | * nextFocusUp |
| 483 | * </pre> |
| 484 | * </p> |
| 485 | * |
| 486 | * |
| 487 | * <p> |
| 488 | * To get a particular view to take focus, call {@link #requestFocus()}. |
| 489 | * </p> |
| 490 | * |
| 491 | * <a name="TouchMode"></a> |
| 492 | * <h3>Touch Mode</h3> |
| 493 | * <p> |
| 494 | * When a user is navigating a user interface via directional keys such as a D-pad, it is |
| 495 | * necessary to give focus to actionable items such as buttons so the user can see |
| 496 | * what will take input. If the device has touch capabilities, however, and the user |
| 497 | * begins interacting with the interface by touching it, it is no longer necessary to |
| 498 | * always highlight, or give focus to, a particular view. This motivates a mode |
| 499 | * for interaction named 'touch mode'. |
| 500 | * </p> |
| 501 | * <p> |
| 502 | * For a touch capable device, once the user touches the screen, the device |
| 503 | * will enter touch mode. From this point onward, only views for which |
| 504 | * {@link #isFocusableInTouchMode} is true will be focusable, such as text editing widgets. |
| 505 | * Other views that are touchable, like buttons, will not take focus when touched; they will |
| 506 | * only fire the on click listeners. |
| 507 | * </p> |
| 508 | * <p> |
| 509 | * Any time a user hits a directional key, such as a D-pad direction, the view device will |
| 510 | * exit touch mode, and find a view to take focus, so that the user may resume interacting |
| 511 | * with the user interface without touching the screen again. |
| 512 | * </p> |
| 513 | * <p> |
| 514 | * The touch mode state is maintained across {@link android.app.Activity}s. Call |
| 515 | * {@link #isInTouchMode} to see whether the device is currently in touch mode. |
| 516 | * </p> |
| 517 | * |
| 518 | * <a name="Scrolling"></a> |
| 519 | * <h3>Scrolling</h3> |
| 520 | * <p> |
| 521 | * The framework provides basic support for views that wish to internally |
| 522 | * scroll their content. This includes keeping track of the X and Y scroll |
| 523 | * offset as well as mechanisms for drawing scrollbars. See |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 524 | * {@link #scrollBy(int, int)}, {@link #scrollTo(int, int)}, and |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 525 | * {@link #awakenScrollBars()} for more details. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | * </p> |
| 527 | * |
| 528 | * <a name="Tags"></a> |
| 529 | * <h3>Tags</h3> |
| 530 | * <p> |
| 531 | * Unlike IDs, tags are not used to identify views. Tags are essentially an |
| 532 | * extra piece of information that can be associated with a view. They are most |
| 533 | * often used as a convenience to store data related to views in the views |
| 534 | * themselves rather than by putting them in a separate structure. |
| 535 | * </p> |
| 536 | * |
| 537 | * <a name="Animation"></a> |
| 538 | * <h3>Animation</h3> |
| 539 | * <p> |
| 540 | * You can attach an {@link Animation} object to a view using |
| 541 | * {@link #setAnimation(Animation)} or |
| 542 | * {@link #startAnimation(Animation)}. The animation can alter the scale, |
| 543 | * rotation, translation and alpha of a view over time. If the animation is |
| 544 | * attached to a view that has children, the animation will affect the entire |
| 545 | * subtree rooted by that node. When an animation is started, the framework will |
| 546 | * take care of redrawing the appropriate views until the animation completes. |
| 547 | * </p> |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 548 | * <p> |
| 549 | * Starting with Android 3.0, the preferred way of animating views is to use the |
| 550 | * {@link android.animation} package APIs. |
| 551 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 553 | * <a name="Security"></a> |
| 554 | * <h3>Security</h3> |
| 555 | * <p> |
| 556 | * Sometimes it is essential that an application be able to verify that an action |
| 557 | * is being performed with the full knowledge and consent of the user, such as |
| 558 | * granting a permission request, making a purchase or clicking on an advertisement. |
| 559 | * Unfortunately, a malicious application could try to spoof the user into |
| 560 | * performing these actions, unaware, by concealing the intended purpose of the view. |
| 561 | * As a remedy, the framework offers a touch filtering mechanism that can be used to |
| 562 | * improve the security of views that provide access to sensitive functionality. |
| 563 | * </p><p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 564 | * To enable touch filtering, call {@link #setFilterTouchesWhenObscured(boolean)} or set the |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 565 | * android:filterTouchesWhenObscured layout attribute to true. When enabled, the framework |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 566 | * will discard touches that are received whenever the view's window is obscured by |
| 567 | * another visible window. As a result, the view will not receive touches whenever a |
| 568 | * toast, dialog or other window appears above the view's window. |
| 569 | * </p><p> |
| 570 | * For more fine-grained control over security, consider overriding the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 571 | * {@link #onFilterTouchEventForSecurity(MotionEvent)} method to implement your own |
| 572 | * security policy. See also {@link MotionEvent#FLAG_WINDOW_IS_OBSCURED}. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 573 | * </p> |
| 574 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 575 | * @attr ref android.R.styleable#View_alpha |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 576 | * @attr ref android.R.styleable#View_background |
| 577 | * @attr ref android.R.styleable#View_clickable |
| 578 | * @attr ref android.R.styleable#View_contentDescription |
| 579 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 580 | * @attr ref android.R.styleable#View_duplicateParentState |
| 581 | * @attr ref android.R.styleable#View_id |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 582 | * @attr ref android.R.styleable#View_requiresFadingEdge |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 583 | * @attr ref android.R.styleable#View_fadeScrollbars |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 584 | * @attr ref android.R.styleable#View_fadingEdgeLength |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 585 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 587 | * @attr ref android.R.styleable#View_isScrollContainer |
| 588 | * @attr ref android.R.styleable#View_focusable |
| 589 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 590 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 591 | * @attr ref android.R.styleable#View_keepScreenOn |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 592 | * @attr ref android.R.styleable#View_layerType |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 593 | * @attr ref android.R.styleable#View_longClickable |
| 594 | * @attr ref android.R.styleable#View_minHeight |
| 595 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 596 | * @attr ref android.R.styleable#View_nextFocusDown |
| 597 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 598 | * @attr ref android.R.styleable#View_nextFocusRight |
| 599 | * @attr ref android.R.styleable#View_nextFocusUp |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 600 | * @attr ref android.R.styleable#View_onClick |
| 601 | * @attr ref android.R.styleable#View_padding |
| 602 | * @attr ref android.R.styleable#View_paddingBottom |
| 603 | * @attr ref android.R.styleable#View_paddingLeft |
| 604 | * @attr ref android.R.styleable#View_paddingRight |
| 605 | * @attr ref android.R.styleable#View_paddingTop |
Fabrice Di Meglio | 101d5aa | 2012-02-16 18:36:06 -0800 | [diff] [blame] | 606 | * @attr ref android.R.styleable#View_paddingStart |
| 607 | * @attr ref android.R.styleable#View_paddingEnd |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 608 | * @attr ref android.R.styleable#View_saveEnabled |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 609 | * @attr ref android.R.styleable#View_rotation |
| 610 | * @attr ref android.R.styleable#View_rotationX |
| 611 | * @attr ref android.R.styleable#View_rotationY |
| 612 | * @attr ref android.R.styleable#View_scaleX |
| 613 | * @attr ref android.R.styleable#View_scaleY |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | * @attr ref android.R.styleable#View_scrollX |
| 615 | * @attr ref android.R.styleable#View_scrollY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 616 | * @attr ref android.R.styleable#View_scrollbarSize |
| 617 | * @attr ref android.R.styleable#View_scrollbarStyle |
| 618 | * @attr ref android.R.styleable#View_scrollbars |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 619 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 620 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | * @attr ref android.R.styleable#View_scrollbarTrackHorizontal |
| 622 | * @attr ref android.R.styleable#View_scrollbarThumbHorizontal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 623 | * @attr ref android.R.styleable#View_scrollbarThumbVertical |
| 624 | * @attr ref android.R.styleable#View_scrollbarTrackVertical |
| 625 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawHorizontalTrack |
| 626 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawVerticalTrack |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 627 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 628 | * @attr ref android.R.styleable#View_tag |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 629 | * @attr ref android.R.styleable#View_textAlignment |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 630 | * @attr ref android.R.styleable#View_transformPivotX |
| 631 | * @attr ref android.R.styleable#View_transformPivotY |
| 632 | * @attr ref android.R.styleable#View_translationX |
| 633 | * @attr ref android.R.styleable#View_translationY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 634 | * @attr ref android.R.styleable#View_visibility |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | * |
| 636 | * @see android.view.ViewGroup |
| 637 | */ |
Adam Powell | 8fc54f9 | 2011-09-07 16:40:45 -0700 | [diff] [blame] | 638 | public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Callback, |
| 639 | AccessibilityEventSource { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | private static final boolean DBG = false; |
| 641 | |
| 642 | /** |
| 643 | * The logging tag used by this class with android.util.Log. |
| 644 | */ |
| 645 | protected static final String VIEW_LOG_TAG = "View"; |
| 646 | |
| 647 | /** |
| 648 | * Used to mark a View that has no ID. |
| 649 | */ |
| 650 | public static final int NO_ID = -1; |
| 651 | |
| 652 | /** |
| 653 | * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when |
| 654 | * calling setFlags. |
| 655 | */ |
| 656 | private static final int NOT_FOCUSABLE = 0x00000000; |
| 657 | |
| 658 | /** |
| 659 | * This view wants keystrokes. Use with TAKES_FOCUS_MASK when calling |
| 660 | * setFlags. |
| 661 | */ |
| 662 | private static final int FOCUSABLE = 0x00000001; |
| 663 | |
| 664 | /** |
| 665 | * Mask for use with setFlags indicating bits used for focus. |
| 666 | */ |
| 667 | private static final int FOCUSABLE_MASK = 0x00000001; |
| 668 | |
| 669 | /** |
| 670 | * This view will adjust its padding to fit sytem windows (e.g. status bar) |
| 671 | */ |
| 672 | private static final int FITS_SYSTEM_WINDOWS = 0x00000002; |
| 673 | |
| 674 | /** |
Scott Main | 812634c2 | 2011-07-27 13:22:35 -0700 | [diff] [blame] | 675 | * This view is visible. |
| 676 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 677 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 678 | */ |
| 679 | public static final int VISIBLE = 0x00000000; |
| 680 | |
| 681 | /** |
| 682 | * 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] | 683 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 684 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | */ |
| 686 | public static final int INVISIBLE = 0x00000004; |
| 687 | |
| 688 | /** |
| 689 | * 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] | 690 | * purposes. Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 691 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 692 | */ |
| 693 | public static final int GONE = 0x00000008; |
| 694 | |
| 695 | /** |
| 696 | * Mask for use with setFlags indicating bits used for visibility. |
| 697 | * {@hide} |
| 698 | */ |
| 699 | static final int VISIBILITY_MASK = 0x0000000C; |
| 700 | |
| 701 | private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE}; |
| 702 | |
| 703 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 704 | * This view is enabled. Interpretation varies by subclass. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | * Use with ENABLED_MASK when calling setFlags. |
| 706 | * {@hide} |
| 707 | */ |
| 708 | static final int ENABLED = 0x00000000; |
| 709 | |
| 710 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 711 | * This view is disabled. Interpretation varies by subclass. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 712 | * Use with ENABLED_MASK when calling setFlags. |
| 713 | * {@hide} |
| 714 | */ |
| 715 | static final int DISABLED = 0x00000020; |
| 716 | |
| 717 | /** |
| 718 | * Mask for use with setFlags indicating bits used for indicating whether |
| 719 | * this view is enabled |
| 720 | * {@hide} |
| 721 | */ |
| 722 | static final int ENABLED_MASK = 0x00000020; |
| 723 | |
| 724 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 725 | * This view won't draw. {@link #onDraw(android.graphics.Canvas)} won't be |
| 726 | * called and further optimizations will be performed. It is okay to have |
| 727 | * 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] | 728 | * {@hide} |
| 729 | */ |
| 730 | static final int WILL_NOT_DRAW = 0x00000080; |
| 731 | |
| 732 | /** |
| 733 | * Mask for use with setFlags indicating bits used for indicating whether |
| 734 | * this view is will draw |
| 735 | * {@hide} |
| 736 | */ |
| 737 | static final int DRAW_MASK = 0x00000080; |
| 738 | |
| 739 | /** |
| 740 | * <p>This view doesn't show scrollbars.</p> |
| 741 | * {@hide} |
| 742 | */ |
| 743 | static final int SCROLLBARS_NONE = 0x00000000; |
| 744 | |
| 745 | /** |
| 746 | * <p>This view shows horizontal scrollbars.</p> |
| 747 | * {@hide} |
| 748 | */ |
| 749 | static final int SCROLLBARS_HORIZONTAL = 0x00000100; |
| 750 | |
| 751 | /** |
| 752 | * <p>This view shows vertical scrollbars.</p> |
| 753 | * {@hide} |
| 754 | */ |
| 755 | static final int SCROLLBARS_VERTICAL = 0x00000200; |
| 756 | |
| 757 | /** |
| 758 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 759 | * scrollbars are enabled.</p> |
| 760 | * {@hide} |
| 761 | */ |
| 762 | static final int SCROLLBARS_MASK = 0x00000300; |
| 763 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 764 | /** |
| 765 | * Indicates that the view should filter touches when its window is obscured. |
| 766 | * Refer to the class comments for more information about this security feature. |
| 767 | * {@hide} |
| 768 | */ |
| 769 | static final int FILTER_TOUCHES_WHEN_OBSCURED = 0x00000400; |
| 770 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 771 | /** |
| 772 | * Set for framework elements that use FITS_SYSTEM_WINDOWS, to indicate |
| 773 | * that they are optional and should be skipped if the window has |
| 774 | * requested system UI flags that ignore those insets for layout. |
| 775 | */ |
| 776 | static final int OPTIONAL_FITS_SYSTEM_WINDOWS = 0x00000800; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 777 | |
| 778 | /** |
| 779 | * <p>This view doesn't show fading edges.</p> |
| 780 | * {@hide} |
| 781 | */ |
| 782 | static final int FADING_EDGE_NONE = 0x00000000; |
| 783 | |
| 784 | /** |
| 785 | * <p>This view shows horizontal fading edges.</p> |
| 786 | * {@hide} |
| 787 | */ |
| 788 | static final int FADING_EDGE_HORIZONTAL = 0x00001000; |
| 789 | |
| 790 | /** |
| 791 | * <p>This view shows vertical fading edges.</p> |
| 792 | * {@hide} |
| 793 | */ |
| 794 | static final int FADING_EDGE_VERTICAL = 0x00002000; |
| 795 | |
| 796 | /** |
| 797 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 798 | * fading edges are enabled.</p> |
| 799 | * {@hide} |
| 800 | */ |
| 801 | static final int FADING_EDGE_MASK = 0x00003000; |
| 802 | |
| 803 | /** |
| 804 | * <p>Indicates this view can be clicked. When clickable, a View reacts |
| 805 | * to clicks by notifying the OnClickListener.<p> |
| 806 | * {@hide} |
| 807 | */ |
| 808 | static final int CLICKABLE = 0x00004000; |
| 809 | |
| 810 | /** |
| 811 | * <p>Indicates this view is caching its drawing into a bitmap.</p> |
| 812 | * {@hide} |
| 813 | */ |
| 814 | static final int DRAWING_CACHE_ENABLED = 0x00008000; |
| 815 | |
| 816 | /** |
| 817 | * <p>Indicates that no icicle should be saved for this view.<p> |
| 818 | * {@hide} |
| 819 | */ |
| 820 | static final int SAVE_DISABLED = 0x000010000; |
| 821 | |
| 822 | /** |
| 823 | * <p>Mask for use with setFlags indicating bits used for the saveEnabled |
| 824 | * property.</p> |
| 825 | * {@hide} |
| 826 | */ |
| 827 | static final int SAVE_DISABLED_MASK = 0x000010000; |
| 828 | |
| 829 | /** |
| 830 | * <p>Indicates that no drawing cache should ever be created for this view.<p> |
| 831 | * {@hide} |
| 832 | */ |
| 833 | static final int WILL_NOT_CACHE_DRAWING = 0x000020000; |
| 834 | |
| 835 | /** |
| 836 | * <p>Indicates this view can take / keep focus when int touch mode.</p> |
| 837 | * {@hide} |
| 838 | */ |
| 839 | static final int FOCUSABLE_IN_TOUCH_MODE = 0x00040000; |
| 840 | |
| 841 | /** |
| 842 | * <p>Enables low quality mode for the drawing cache.</p> |
| 843 | */ |
| 844 | public static final int DRAWING_CACHE_QUALITY_LOW = 0x00080000; |
| 845 | |
| 846 | /** |
| 847 | * <p>Enables high quality mode for the drawing cache.</p> |
| 848 | */ |
| 849 | public static final int DRAWING_CACHE_QUALITY_HIGH = 0x00100000; |
| 850 | |
| 851 | /** |
| 852 | * <p>Enables automatic quality mode for the drawing cache.</p> |
| 853 | */ |
| 854 | public static final int DRAWING_CACHE_QUALITY_AUTO = 0x00000000; |
| 855 | |
| 856 | private static final int[] DRAWING_CACHE_QUALITY_FLAGS = { |
| 857 | DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_LOW, DRAWING_CACHE_QUALITY_HIGH |
| 858 | }; |
| 859 | |
| 860 | /** |
| 861 | * <p>Mask for use with setFlags indicating bits used for the cache |
| 862 | * quality property.</p> |
| 863 | * {@hide} |
| 864 | */ |
| 865 | static final int DRAWING_CACHE_QUALITY_MASK = 0x00180000; |
| 866 | |
| 867 | /** |
| 868 | * <p> |
| 869 | * Indicates this view can be long clicked. When long clickable, a View |
| 870 | * reacts to long clicks by notifying the OnLongClickListener or showing a |
| 871 | * context menu. |
| 872 | * </p> |
| 873 | * {@hide} |
| 874 | */ |
| 875 | static final int LONG_CLICKABLE = 0x00200000; |
| 876 | |
| 877 | /** |
| 878 | * <p>Indicates that this view gets its drawable states from its direct parent |
| 879 | * and ignores its original internal states.</p> |
| 880 | * |
| 881 | * @hide |
| 882 | */ |
| 883 | static final int DUPLICATE_PARENT_STATE = 0x00400000; |
| 884 | |
| 885 | /** |
| 886 | * The scrollbar style to display the scrollbars inside the content area, |
| 887 | * without increasing the padding. The scrollbars will be overlaid with |
| 888 | * translucency on the view's content. |
| 889 | */ |
| 890 | public static final int SCROLLBARS_INSIDE_OVERLAY = 0; |
| 891 | |
| 892 | /** |
| 893 | * The scrollbar style to display the scrollbars inside the padded area, |
| 894 | * increasing the padding of the view. The scrollbars will not overlap the |
| 895 | * content area of the view. |
| 896 | */ |
| 897 | public static final int SCROLLBARS_INSIDE_INSET = 0x01000000; |
| 898 | |
| 899 | /** |
| 900 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 901 | * without increasing the padding. The scrollbars will be overlaid with |
| 902 | * translucency. |
| 903 | */ |
| 904 | public static final int SCROLLBARS_OUTSIDE_OVERLAY = 0x02000000; |
| 905 | |
| 906 | /** |
| 907 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 908 | * increasing the padding of the view. The scrollbars will only overlap the |
| 909 | * background, if any. |
| 910 | */ |
| 911 | public static final int SCROLLBARS_OUTSIDE_INSET = 0x03000000; |
| 912 | |
| 913 | /** |
| 914 | * Mask to check if the scrollbar style is overlay or inset. |
| 915 | * {@hide} |
| 916 | */ |
| 917 | static final int SCROLLBARS_INSET_MASK = 0x01000000; |
| 918 | |
| 919 | /** |
| 920 | * Mask to check if the scrollbar style is inside or outside. |
| 921 | * {@hide} |
| 922 | */ |
| 923 | static final int SCROLLBARS_OUTSIDE_MASK = 0x02000000; |
| 924 | |
| 925 | /** |
| 926 | * Mask for scrollbar style. |
| 927 | * {@hide} |
| 928 | */ |
| 929 | static final int SCROLLBARS_STYLE_MASK = 0x03000000; |
| 930 | |
| 931 | /** |
| 932 | * View flag indicating that the screen should remain on while the |
| 933 | * window containing this view is visible to the user. This effectively |
| 934 | * takes care of automatically setting the WindowManager's |
| 935 | * {@link WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON}. |
| 936 | */ |
| 937 | public static final int KEEP_SCREEN_ON = 0x04000000; |
| 938 | |
| 939 | /** |
| 940 | * View flag indicating whether this view should have sound effects enabled |
| 941 | * for events such as clicking and touching. |
| 942 | */ |
| 943 | public static final int SOUND_EFFECTS_ENABLED = 0x08000000; |
| 944 | |
| 945 | /** |
| 946 | * View flag indicating whether this view should have haptic feedback |
| 947 | * enabled for events such as long presses. |
| 948 | */ |
| 949 | public static final int HAPTIC_FEEDBACK_ENABLED = 0x10000000; |
| 950 | |
| 951 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 952 | * <p>Indicates that the view hierarchy should stop saving state when |
| 953 | * it reaches this view. If state saving is initiated immediately at |
| 954 | * the view, it will be allowed. |
| 955 | * {@hide} |
| 956 | */ |
| 957 | static final int PARENT_SAVE_DISABLED = 0x20000000; |
| 958 | |
| 959 | /** |
| 960 | * <p>Mask for use with setFlags indicating bits used for PARENT_SAVE_DISABLED.</p> |
| 961 | * {@hide} |
| 962 | */ |
| 963 | static final int PARENT_SAVE_DISABLED_MASK = 0x20000000; |
| 964 | |
| 965 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 966 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 967 | * should add all focusable Views regardless if they are focusable in touch mode. |
| 968 | */ |
| 969 | public static final int FOCUSABLES_ALL = 0x00000000; |
| 970 | |
| 971 | /** |
| 972 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 973 | * should add only Views focusable in touch mode. |
| 974 | */ |
| 975 | public static final int FOCUSABLES_TOUCH_MODE = 0x00000001; |
| 976 | |
| 977 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 978 | * 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] | 979 | * item. |
| 980 | */ |
| 981 | public static final int FOCUS_BACKWARD = 0x00000001; |
| 982 | |
| 983 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 984 | * 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] | 985 | * item. |
| 986 | */ |
| 987 | public static final int FOCUS_FORWARD = 0x00000002; |
| 988 | |
| 989 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 990 | * 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] | 991 | */ |
| 992 | public static final int FOCUS_LEFT = 0x00000011; |
| 993 | |
| 994 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 995 | * Use with {@link #focusSearch(int)}. Move focus up. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | */ |
| 997 | public static final int FOCUS_UP = 0x00000021; |
| 998 | |
| 999 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1000 | * 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] | 1001 | */ |
| 1002 | public static final int FOCUS_RIGHT = 0x00000042; |
| 1003 | |
| 1004 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1005 | * Use with {@link #focusSearch(int)}. Move focus down. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1006 | */ |
| 1007 | public static final int FOCUS_DOWN = 0x00000082; |
| 1008 | |
| 1009 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1010 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1011 | * {@link #getMeasuredWidthAndState()} that provide the actual measured size. |
| 1012 | */ |
| 1013 | public static final int MEASURED_SIZE_MASK = 0x00ffffff; |
| 1014 | |
| 1015 | /** |
| 1016 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1017 | * {@link #getMeasuredWidthAndState()} that provide the additional state bits. |
| 1018 | */ |
| 1019 | public static final int MEASURED_STATE_MASK = 0xff000000; |
| 1020 | |
| 1021 | /** |
| 1022 | * Bit shift of {@link #MEASURED_STATE_MASK} to get to the height bits |
| 1023 | * for functions that combine both width and height into a single int, |
| 1024 | * such as {@link #getMeasuredState()} and the childState argument of |
| 1025 | * {@link #resolveSizeAndState(int, int, int)}. |
| 1026 | */ |
| 1027 | public static final int MEASURED_HEIGHT_STATE_SHIFT = 16; |
| 1028 | |
| 1029 | /** |
| 1030 | * Bit of {@link #getMeasuredWidthAndState()} and |
| 1031 | * {@link #getMeasuredWidthAndState()} that indicates the measured size |
| 1032 | * is smaller that the space the view would like to have. |
| 1033 | */ |
| 1034 | public static final int MEASURED_STATE_TOO_SMALL = 0x01000000; |
| 1035 | |
| 1036 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1037 | * Base View state sets |
| 1038 | */ |
| 1039 | // Singles |
| 1040 | /** |
| 1041 | * Indicates the view has no states set. States are used with |
| 1042 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1043 | * view depending on its state. |
| 1044 | * |
| 1045 | * @see android.graphics.drawable.Drawable |
| 1046 | * @see #getDrawableState() |
| 1047 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1048 | protected static final int[] EMPTY_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | /** |
| 1050 | * Indicates the view is enabled. States are used with |
| 1051 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1052 | * view depending on its state. |
| 1053 | * |
| 1054 | * @see android.graphics.drawable.Drawable |
| 1055 | * @see #getDrawableState() |
| 1056 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1057 | protected static final int[] ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1058 | /** |
| 1059 | * Indicates the view is focused. States are used with |
| 1060 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1061 | * view depending on its state. |
| 1062 | * |
| 1063 | * @see android.graphics.drawable.Drawable |
| 1064 | * @see #getDrawableState() |
| 1065 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1066 | protected static final int[] FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | /** |
| 1068 | * Indicates the view is selected. States are used with |
| 1069 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1070 | * view depending on its state. |
| 1071 | * |
| 1072 | * @see android.graphics.drawable.Drawable |
| 1073 | * @see #getDrawableState() |
| 1074 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1075 | protected static final int[] SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | /** |
| 1077 | * Indicates the view is pressed. States are used with |
| 1078 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1079 | * view depending on its state. |
| 1080 | * |
| 1081 | * @see android.graphics.drawable.Drawable |
| 1082 | * @see #getDrawableState() |
| 1083 | * @hide |
| 1084 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1085 | protected static final int[] PRESSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1086 | /** |
| 1087 | * Indicates the view's window has focus. States are used with |
| 1088 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1089 | * view depending on its state. |
| 1090 | * |
| 1091 | * @see android.graphics.drawable.Drawable |
| 1092 | * @see #getDrawableState() |
| 1093 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1094 | protected static final int[] WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | // Doubles |
| 1096 | /** |
| 1097 | * Indicates the view is enabled and has the focus. |
| 1098 | * |
| 1099 | * @see #ENABLED_STATE_SET |
| 1100 | * @see #FOCUSED_STATE_SET |
| 1101 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1102 | protected static final int[] ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | /** |
| 1104 | * Indicates the view is enabled and selected. |
| 1105 | * |
| 1106 | * @see #ENABLED_STATE_SET |
| 1107 | * @see #SELECTED_STATE_SET |
| 1108 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1109 | protected static final int[] ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | /** |
| 1111 | * Indicates the view is enabled and that its window has focus. |
| 1112 | * |
| 1113 | * @see #ENABLED_STATE_SET |
| 1114 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1115 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1116 | protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1117 | /** |
| 1118 | * Indicates the view is focused and selected. |
| 1119 | * |
| 1120 | * @see #FOCUSED_STATE_SET |
| 1121 | * @see #SELECTED_STATE_SET |
| 1122 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1123 | protected static final int[] FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1124 | /** |
| 1125 | * Indicates the view has the focus and that its window has the focus. |
| 1126 | * |
| 1127 | * @see #FOCUSED_STATE_SET |
| 1128 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1129 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1130 | protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1131 | /** |
| 1132 | * Indicates the view is selected and that its window has the focus. |
| 1133 | * |
| 1134 | * @see #SELECTED_STATE_SET |
| 1135 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1136 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1137 | protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1138 | // Triples |
| 1139 | /** |
| 1140 | * Indicates the view is enabled, focused and selected. |
| 1141 | * |
| 1142 | * @see #ENABLED_STATE_SET |
| 1143 | * @see #FOCUSED_STATE_SET |
| 1144 | * @see #SELECTED_STATE_SET |
| 1145 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1146 | protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | /** |
| 1148 | * Indicates the view is enabled, focused and its window has the focus. |
| 1149 | * |
| 1150 | * @see #ENABLED_STATE_SET |
| 1151 | * @see #FOCUSED_STATE_SET |
| 1152 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1153 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1154 | 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] | 1155 | /** |
| 1156 | * Indicates the view is enabled, selected and its window has the focus. |
| 1157 | * |
| 1158 | * @see #ENABLED_STATE_SET |
| 1159 | * @see #SELECTED_STATE_SET |
| 1160 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1161 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1162 | 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] | 1163 | /** |
| 1164 | * Indicates the view is focused, selected and its window has the focus. |
| 1165 | * |
| 1166 | * @see #FOCUSED_STATE_SET |
| 1167 | * @see #SELECTED_STATE_SET |
| 1168 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1169 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1170 | 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] | 1171 | /** |
| 1172 | * Indicates the view is enabled, focused, selected and its window |
| 1173 | * has the focus. |
| 1174 | * |
| 1175 | * @see #ENABLED_STATE_SET |
| 1176 | * @see #FOCUSED_STATE_SET |
| 1177 | * @see #SELECTED_STATE_SET |
| 1178 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1179 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1180 | 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] | 1181 | /** |
| 1182 | * Indicates the view is pressed and its window has the focus. |
| 1183 | * |
| 1184 | * @see #PRESSED_STATE_SET |
| 1185 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1186 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1187 | protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1188 | /** |
| 1189 | * Indicates the view is pressed and selected. |
| 1190 | * |
| 1191 | * @see #PRESSED_STATE_SET |
| 1192 | * @see #SELECTED_STATE_SET |
| 1193 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1194 | protected static final int[] PRESSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1195 | /** |
| 1196 | * Indicates the view is pressed, selected and its window has the focus. |
| 1197 | * |
| 1198 | * @see #PRESSED_STATE_SET |
| 1199 | * @see #SELECTED_STATE_SET |
| 1200 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1201 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1202 | 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] | 1203 | /** |
| 1204 | * Indicates the view is pressed and focused. |
| 1205 | * |
| 1206 | * @see #PRESSED_STATE_SET |
| 1207 | * @see #FOCUSED_STATE_SET |
| 1208 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1209 | protected static final int[] PRESSED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1210 | /** |
| 1211 | * Indicates the view is pressed, focused and its window has the focus. |
| 1212 | * |
| 1213 | * @see #PRESSED_STATE_SET |
| 1214 | * @see #FOCUSED_STATE_SET |
| 1215 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1216 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1217 | 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] | 1218 | /** |
| 1219 | * Indicates the view is pressed, focused and selected. |
| 1220 | * |
| 1221 | * @see #PRESSED_STATE_SET |
| 1222 | * @see #SELECTED_STATE_SET |
| 1223 | * @see #FOCUSED_STATE_SET |
| 1224 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1225 | protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1226 | /** |
| 1227 | * Indicates the view is pressed, focused, selected and its window has the focus. |
| 1228 | * |
| 1229 | * @see #PRESSED_STATE_SET |
| 1230 | * @see #FOCUSED_STATE_SET |
| 1231 | * @see #SELECTED_STATE_SET |
| 1232 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1233 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1234 | 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] | 1235 | /** |
| 1236 | * Indicates the view is pressed and enabled. |
| 1237 | * |
| 1238 | * @see #PRESSED_STATE_SET |
| 1239 | * @see #ENABLED_STATE_SET |
| 1240 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1241 | protected static final int[] PRESSED_ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1242 | /** |
| 1243 | * Indicates the view is pressed, enabled and its window has the focus. |
| 1244 | * |
| 1245 | * @see #PRESSED_STATE_SET |
| 1246 | * @see #ENABLED_STATE_SET |
| 1247 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1248 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1249 | 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] | 1250 | /** |
| 1251 | * Indicates the view is pressed, enabled and selected. |
| 1252 | * |
| 1253 | * @see #PRESSED_STATE_SET |
| 1254 | * @see #ENABLED_STATE_SET |
| 1255 | * @see #SELECTED_STATE_SET |
| 1256 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1257 | protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1258 | /** |
| 1259 | * Indicates the view is pressed, enabled, selected and its window has the |
| 1260 | * focus. |
| 1261 | * |
| 1262 | * @see #PRESSED_STATE_SET |
| 1263 | * @see #ENABLED_STATE_SET |
| 1264 | * @see #SELECTED_STATE_SET |
| 1265 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1266 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1267 | 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] | 1268 | /** |
| 1269 | * Indicates the view is pressed, enabled and focused. |
| 1270 | * |
| 1271 | * @see #PRESSED_STATE_SET |
| 1272 | * @see #ENABLED_STATE_SET |
| 1273 | * @see #FOCUSED_STATE_SET |
| 1274 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1275 | protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1276 | /** |
| 1277 | * Indicates the view is pressed, enabled, focused and its window has the |
| 1278 | * focus. |
| 1279 | * |
| 1280 | * @see #PRESSED_STATE_SET |
| 1281 | * @see #ENABLED_STATE_SET |
| 1282 | * @see #FOCUSED_STATE_SET |
| 1283 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1284 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1285 | 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] | 1286 | /** |
| 1287 | * Indicates the view is pressed, enabled, focused and selected. |
| 1288 | * |
| 1289 | * @see #PRESSED_STATE_SET |
| 1290 | * @see #ENABLED_STATE_SET |
| 1291 | * @see #SELECTED_STATE_SET |
| 1292 | * @see #FOCUSED_STATE_SET |
| 1293 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1294 | 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] | 1295 | /** |
| 1296 | * Indicates the view is pressed, enabled, focused, selected and its window |
| 1297 | * has the focus. |
| 1298 | * |
| 1299 | * @see #PRESSED_STATE_SET |
| 1300 | * @see #ENABLED_STATE_SET |
| 1301 | * @see #SELECTED_STATE_SET |
| 1302 | * @see #FOCUSED_STATE_SET |
| 1303 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1304 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1305 | 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] | 1306 | |
| 1307 | /** |
| 1308 | * The order here is very important to {@link #getDrawableState()} |
| 1309 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1310 | private static final int[][] VIEW_STATE_SETS; |
| 1311 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1312 | static final int VIEW_STATE_WINDOW_FOCUSED = 1; |
| 1313 | static final int VIEW_STATE_SELECTED = 1 << 1; |
| 1314 | static final int VIEW_STATE_FOCUSED = 1 << 2; |
| 1315 | static final int VIEW_STATE_ENABLED = 1 << 3; |
| 1316 | static final int VIEW_STATE_PRESSED = 1 << 4; |
| 1317 | static final int VIEW_STATE_ACTIVATED = 1 << 5; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1318 | static final int VIEW_STATE_ACCELERATED = 1 << 6; |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1319 | static final int VIEW_STATE_HOVERED = 1 << 7; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1320 | static final int VIEW_STATE_DRAG_CAN_ACCEPT = 1 << 8; |
| 1321 | static final int VIEW_STATE_DRAG_HOVERED = 1 << 9; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1322 | |
| 1323 | static final int[] VIEW_STATE_IDS = new int[] { |
| 1324 | R.attr.state_window_focused, VIEW_STATE_WINDOW_FOCUSED, |
| 1325 | R.attr.state_selected, VIEW_STATE_SELECTED, |
| 1326 | R.attr.state_focused, VIEW_STATE_FOCUSED, |
| 1327 | R.attr.state_enabled, VIEW_STATE_ENABLED, |
| 1328 | R.attr.state_pressed, VIEW_STATE_PRESSED, |
| 1329 | R.attr.state_activated, VIEW_STATE_ACTIVATED, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1330 | R.attr.state_accelerated, VIEW_STATE_ACCELERATED, |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1331 | R.attr.state_hovered, VIEW_STATE_HOVERED, |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1332 | R.attr.state_drag_can_accept, VIEW_STATE_DRAG_CAN_ACCEPT, |
| 1333 | R.attr.state_drag_hovered, VIEW_STATE_DRAG_HOVERED, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1334 | }; |
| 1335 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1336 | static { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1337 | if ((VIEW_STATE_IDS.length/2) != R.styleable.ViewDrawableStates.length) { |
| 1338 | throw new IllegalStateException( |
| 1339 | "VIEW_STATE_IDs array length does not match ViewDrawableStates style array"); |
| 1340 | } |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1341 | int[] orderedIds = new int[VIEW_STATE_IDS.length]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1342 | for (int i = 0; i < R.styleable.ViewDrawableStates.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1343 | int viewState = R.styleable.ViewDrawableStates[i]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1344 | for (int j = 0; j<VIEW_STATE_IDS.length; j += 2) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1345 | if (VIEW_STATE_IDS[j] == viewState) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1346 | orderedIds[i * 2] = viewState; |
| 1347 | orderedIds[i * 2 + 1] = VIEW_STATE_IDS[j + 1]; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1348 | } |
| 1349 | } |
| 1350 | } |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1351 | final int NUM_BITS = VIEW_STATE_IDS.length / 2; |
| 1352 | VIEW_STATE_SETS = new int[1 << NUM_BITS][]; |
| 1353 | for (int i = 0; i < VIEW_STATE_SETS.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1354 | int numBits = Integer.bitCount(i); |
| 1355 | int[] set = new int[numBits]; |
| 1356 | int pos = 0; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1357 | for (int j = 0; j < orderedIds.length; j += 2) { |
| 1358 | if ((i & orderedIds[j+1]) != 0) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1359 | set[pos++] = orderedIds[j]; |
| 1360 | } |
| 1361 | } |
| 1362 | VIEW_STATE_SETS[i] = set; |
| 1363 | } |
| 1364 | |
| 1365 | EMPTY_STATE_SET = VIEW_STATE_SETS[0]; |
| 1366 | WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_WINDOW_FOCUSED]; |
| 1367 | SELECTED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_SELECTED]; |
| 1368 | SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1369 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED]; |
| 1370 | FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_FOCUSED]; |
| 1371 | FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1372 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED]; |
| 1373 | FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1374 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED]; |
| 1375 | FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1376 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1377 | | VIEW_STATE_FOCUSED]; |
| 1378 | ENABLED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_ENABLED]; |
| 1379 | ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1380 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED]; |
| 1381 | ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1382 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED]; |
| 1383 | ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1384 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1385 | | VIEW_STATE_ENABLED]; |
| 1386 | ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1387 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED]; |
| 1388 | ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1389 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1390 | | VIEW_STATE_ENABLED]; |
| 1391 | ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1392 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1393 | | VIEW_STATE_ENABLED]; |
| 1394 | ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1395 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1396 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED]; |
| 1397 | |
| 1398 | PRESSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_PRESSED]; |
| 1399 | PRESSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1400 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_PRESSED]; |
| 1401 | PRESSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1402 | VIEW_STATE_SELECTED | VIEW_STATE_PRESSED]; |
| 1403 | PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1404 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1405 | | VIEW_STATE_PRESSED]; |
| 1406 | PRESSED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1407 | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1408 | PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1409 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1410 | | VIEW_STATE_PRESSED]; |
| 1411 | PRESSED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1412 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1413 | | VIEW_STATE_PRESSED]; |
| 1414 | PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1415 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1416 | | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1417 | PRESSED_ENABLED_STATE_SET = VIEW_STATE_SETS[ |
| 1418 | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1419 | PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1420 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED |
| 1421 | | VIEW_STATE_PRESSED]; |
| 1422 | PRESSED_ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1423 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED |
| 1424 | | VIEW_STATE_PRESSED]; |
| 1425 | PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1426 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1427 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1428 | PRESSED_ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1429 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED |
| 1430 | | VIEW_STATE_PRESSED]; |
| 1431 | PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1432 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1433 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1434 | PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1435 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1436 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1437 | PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1438 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1439 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED |
| 1440 | | VIEW_STATE_PRESSED]; |
| 1441 | } |
| 1442 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1443 | /** |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1444 | * Accessibility event types that are dispatched for text population. |
| 1445 | */ |
| 1446 | private static final int POPULATING_ACCESSIBILITY_EVENT_TYPES = |
| 1447 | AccessibilityEvent.TYPE_VIEW_CLICKED |
| 1448 | | AccessibilityEvent.TYPE_VIEW_LONG_CLICKED |
| 1449 | | AccessibilityEvent.TYPE_VIEW_SELECTED |
| 1450 | | AccessibilityEvent.TYPE_VIEW_FOCUSED |
| 1451 | | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED |
| 1452 | | AccessibilityEvent.TYPE_VIEW_HOVER_ENTER |
Svetoslav Ganov | 9920f4f | 2011-10-07 18:39:11 -0700 | [diff] [blame] | 1453 | | AccessibilityEvent.TYPE_VIEW_HOVER_EXIT |
Svetoslav Ganov | 84dd52e | 2011-11-18 10:24:00 -0800 | [diff] [blame] | 1454 | | AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED |
| 1455 | | AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED; |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1456 | |
| 1457 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1458 | * Temporary Rect currently for use in setBackground(). This will probably |
| 1459 | * be extended in the future to hold our own class with more than just |
| 1460 | * a Rect. :) |
| 1461 | */ |
| 1462 | static final ThreadLocal<Rect> sThreadLocal = new ThreadLocal<Rect>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1463 | |
| 1464 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 1465 | * Temporary flag, used to enable processing of View properties in the native DisplayList |
| 1466 | * object instead of during draw(). Soon to be enabled by default for hardware-accelerated |
| 1467 | * apps. |
| 1468 | * @hide |
| 1469 | */ |
Chet Haase | 8d56b0e | 2012-04-02 16:34:48 -0700 | [diff] [blame] | 1470 | public static final boolean USE_DISPLAY_LIST_PROPERTIES = true; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 1471 | |
| 1472 | /** |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1473 | * Map used to store views' tags. |
| 1474 | */ |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 1475 | private SparseArray<Object> mKeyedTags; |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1476 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1477 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1478 | * The next available accessiiblity id. |
| 1479 | */ |
| 1480 | private static int sNextAccessibilityViewId; |
| 1481 | |
| 1482 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1483 | * The animation currently associated with this view. |
| 1484 | * @hide |
| 1485 | */ |
| 1486 | protected Animation mCurrentAnimation = null; |
| 1487 | |
| 1488 | /** |
| 1489 | * Width as measured during measure pass. |
| 1490 | * {@hide} |
| 1491 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1492 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1493 | int mMeasuredWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 | |
| 1495 | /** |
| 1496 | * Height as measured during measure pass. |
| 1497 | * {@hide} |
| 1498 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1499 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1500 | int mMeasuredHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1501 | |
| 1502 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1503 | * Flag to indicate that this view was marked INVALIDATED, or had its display list |
| 1504 | * invalidated, prior to the current drawing iteration. If true, the view must re-draw |
| 1505 | * its display list. This flag, used only when hw accelerated, allows us to clear the |
| 1506 | * flag while retaining this information until it's needed (at getDisplayList() time and |
| 1507 | * in drawChild(), when we decide to draw a view's children's display lists into our own). |
| 1508 | * |
| 1509 | * {@hide} |
| 1510 | */ |
| 1511 | boolean mRecreateDisplayList = false; |
| 1512 | |
| 1513 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1514 | * The view's identifier. |
| 1515 | * {@hide} |
| 1516 | * |
| 1517 | * @see #setId(int) |
| 1518 | * @see #getId() |
| 1519 | */ |
| 1520 | @ViewDebug.ExportedProperty(resolveId = true) |
| 1521 | int mID = NO_ID; |
| 1522 | |
| 1523 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 1524 | * The stable ID of this view for accessibility purposes. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1525 | */ |
| 1526 | int mAccessibilityViewId = NO_ID; |
| 1527 | |
| 1528 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1529 | * The view's tag. |
| 1530 | * {@hide} |
| 1531 | * |
| 1532 | * @see #setTag(Object) |
| 1533 | * @see #getTag() |
| 1534 | */ |
| 1535 | protected Object mTag; |
| 1536 | |
| 1537 | // for mPrivateFlags: |
| 1538 | /** {@hide} */ |
| 1539 | static final int WANTS_FOCUS = 0x00000001; |
| 1540 | /** {@hide} */ |
| 1541 | static final int FOCUSED = 0x00000002; |
| 1542 | /** {@hide} */ |
| 1543 | static final int SELECTED = 0x00000004; |
| 1544 | /** {@hide} */ |
| 1545 | static final int IS_ROOT_NAMESPACE = 0x00000008; |
| 1546 | /** {@hide} */ |
| 1547 | static final int HAS_BOUNDS = 0x00000010; |
| 1548 | /** {@hide} */ |
| 1549 | static final int DRAWN = 0x00000020; |
| 1550 | /** |
| 1551 | * When this flag is set, this view is running an animation on behalf of its |
| 1552 | * children and should therefore not cancel invalidate requests, even if they |
| 1553 | * lie outside of this view's bounds. |
| 1554 | * |
| 1555 | * {@hide} |
| 1556 | */ |
| 1557 | static final int DRAW_ANIMATION = 0x00000040; |
| 1558 | /** {@hide} */ |
| 1559 | static final int SKIP_DRAW = 0x00000080; |
| 1560 | /** {@hide} */ |
| 1561 | static final int ONLY_DRAWS_BACKGROUND = 0x00000100; |
| 1562 | /** {@hide} */ |
| 1563 | static final int REQUEST_TRANSPARENT_REGIONS = 0x00000200; |
| 1564 | /** {@hide} */ |
| 1565 | static final int DRAWABLE_STATE_DIRTY = 0x00000400; |
| 1566 | /** {@hide} */ |
| 1567 | static final int MEASURED_DIMENSION_SET = 0x00000800; |
| 1568 | /** {@hide} */ |
| 1569 | static final int FORCE_LAYOUT = 0x00001000; |
Konstantin Lopyrev | c6dc457 | 2010-08-06 15:01:52 -0700 | [diff] [blame] | 1570 | /** {@hide} */ |
| 1571 | static final int LAYOUT_REQUIRED = 0x00002000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1572 | |
| 1573 | private static final int PRESSED = 0x00004000; |
| 1574 | |
| 1575 | /** {@hide} */ |
| 1576 | static final int DRAWING_CACHE_VALID = 0x00008000; |
| 1577 | /** |
| 1578 | * Flag used to indicate that this view should be drawn once more (and only once |
| 1579 | * more) after its animation has completed. |
| 1580 | * {@hide} |
| 1581 | */ |
| 1582 | static final int ANIMATION_STARTED = 0x00010000; |
| 1583 | |
| 1584 | private static final int SAVE_STATE_CALLED = 0x00020000; |
| 1585 | |
| 1586 | /** |
| 1587 | * Indicates that the View returned true when onSetAlpha() was called and that |
| 1588 | * the alpha must be restored. |
| 1589 | * {@hide} |
| 1590 | */ |
| 1591 | static final int ALPHA_SET = 0x00040000; |
| 1592 | |
| 1593 | /** |
| 1594 | * Set by {@link #setScrollContainer(boolean)}. |
| 1595 | */ |
| 1596 | static final int SCROLL_CONTAINER = 0x00080000; |
| 1597 | |
| 1598 | /** |
| 1599 | * Set by {@link #setScrollContainer(boolean)}. |
| 1600 | */ |
| 1601 | static final int SCROLL_CONTAINER_ADDED = 0x00100000; |
| 1602 | |
| 1603 | /** |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1604 | * View flag indicating whether this view was invalidated (fully or partially.) |
| 1605 | * |
| 1606 | * @hide |
| 1607 | */ |
| 1608 | static final int DIRTY = 0x00200000; |
| 1609 | |
| 1610 | /** |
| 1611 | * View flag indicating whether this view was invalidated by an opaque |
| 1612 | * invalidate request. |
| 1613 | * |
| 1614 | * @hide |
| 1615 | */ |
| 1616 | static final int DIRTY_OPAQUE = 0x00400000; |
| 1617 | |
| 1618 | /** |
| 1619 | * Mask for {@link #DIRTY} and {@link #DIRTY_OPAQUE}. |
| 1620 | * |
| 1621 | * @hide |
| 1622 | */ |
| 1623 | static final int DIRTY_MASK = 0x00600000; |
| 1624 | |
| 1625 | /** |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1626 | * Indicates whether the background is opaque. |
| 1627 | * |
| 1628 | * @hide |
| 1629 | */ |
| 1630 | static final int OPAQUE_BACKGROUND = 0x00800000; |
| 1631 | |
| 1632 | /** |
| 1633 | * Indicates whether the scrollbars are opaque. |
| 1634 | * |
| 1635 | * @hide |
| 1636 | */ |
| 1637 | static final int OPAQUE_SCROLLBARS = 0x01000000; |
| 1638 | |
| 1639 | /** |
| 1640 | * Indicates whether the view is opaque. |
| 1641 | * |
| 1642 | * @hide |
| 1643 | */ |
| 1644 | static final int OPAQUE_MASK = 0x01800000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1645 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1646 | /** |
| 1647 | * Indicates a prepressed state; |
| 1648 | * the short time between ACTION_DOWN and recognizing |
| 1649 | * a 'real' press. Prepressed is used to recognize quick taps |
| 1650 | * even when they are shorter than ViewConfiguration.getTapTimeout(). |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1651 | * |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1652 | * @hide |
| 1653 | */ |
| 1654 | private static final int PREPRESSED = 0x02000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1655 | |
Adam Powell | c9fbaab | 2010-02-16 17:16:19 -0800 | [diff] [blame] | 1656 | /** |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 1657 | * Indicates whether the view is temporarily detached. |
| 1658 | * |
| 1659 | * @hide |
| 1660 | */ |
| 1661 | static final int CANCEL_NEXT_UP_EVENT = 0x04000000; |
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 | /** |
| 1664 | * Indicates that we should awaken scroll bars once attached |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1665 | * |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1666 | * @hide |
| 1667 | */ |
| 1668 | private static final int AWAKEN_SCROLL_BARS_ON_ATTACH = 0x08000000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1669 | |
| 1670 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1671 | * Indicates that the view has received HOVER_ENTER. Cleared on HOVER_EXIT. |
| 1672 | * @hide |
| 1673 | */ |
| 1674 | private static final int HOVERED = 0x10000000; |
| 1675 | |
| 1676 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1677 | * Indicates that pivotX or pivotY were explicitly set and we should not assume the center |
| 1678 | * for transform operations |
| 1679 | * |
| 1680 | * @hide |
| 1681 | */ |
Adam Powell | f37df07 | 2010-09-17 16:22:49 -0700 | [diff] [blame] | 1682 | private static final int PIVOT_EXPLICITLY_SET = 0x20000000; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1683 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1684 | /** {@hide} */ |
Adam Powell | f37df07 | 2010-09-17 16:22:49 -0700 | [diff] [blame] | 1685 | static final int ACTIVATED = 0x40000000; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1686 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1687 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1688 | * Indicates that this view was specifically invalidated, not just dirtied because some |
| 1689 | * child view was invalidated. The flag is used to determine when we need to recreate |
| 1690 | * a view's display list (as opposed to just returning a reference to its existing |
| 1691 | * display list). |
| 1692 | * |
| 1693 | * @hide |
| 1694 | */ |
| 1695 | static final int INVALIDATED = 0x80000000; |
| 1696 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1697 | /* Masks for mPrivateFlags2 */ |
| 1698 | |
| 1699 | /** |
| 1700 | * Indicates that this view has reported that it can accept the current drag's content. |
| 1701 | * Cleared when the drag operation concludes. |
| 1702 | * @hide |
| 1703 | */ |
| 1704 | static final int DRAG_CAN_ACCEPT = 0x00000001; |
| 1705 | |
| 1706 | /** |
| 1707 | * Indicates that this view is currently directly under the drag location in a |
| 1708 | * drag-and-drop operation involving content that it can accept. Cleared when |
| 1709 | * the drag exits the view, or when the drag operation concludes. |
| 1710 | * @hide |
| 1711 | */ |
| 1712 | static final int DRAG_HOVERED = 0x00000002; |
| 1713 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1714 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1715 | * Horizontal layout direction of this view is from Left to Right. |
| 1716 | * Use with {@link #setLayoutDirection}. |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1717 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1718 | public static final int LAYOUT_DIRECTION_LTR = 0; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1719 | |
| 1720 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1721 | * Horizontal layout direction of this view is from Right to Left. |
| 1722 | * Use with {@link #setLayoutDirection}. |
| 1723 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1724 | public static final int LAYOUT_DIRECTION_RTL = 1; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1725 | |
| 1726 | /** |
| 1727 | * Horizontal layout direction of this view is inherited from its parent. |
| 1728 | * Use with {@link #setLayoutDirection}. |
| 1729 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1730 | public static final int LAYOUT_DIRECTION_INHERIT = 2; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1731 | |
| 1732 | /** |
| 1733 | * Horizontal layout direction of this view is from deduced from the default language |
| 1734 | * script for the locale. Use with {@link #setLayoutDirection}. |
| 1735 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1736 | public static final int LAYOUT_DIRECTION_LOCALE = 3; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1737 | |
| 1738 | /** |
| 1739 | * 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] | 1740 | * @hide |
| 1741 | */ |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1742 | static final int LAYOUT_DIRECTION_MASK_SHIFT = 2; |
| 1743 | |
| 1744 | /** |
| 1745 | * Mask for use with private flags indicating bits used for horizontal layout direction. |
| 1746 | * @hide |
| 1747 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1748 | static final int LAYOUT_DIRECTION_MASK = 0x00000003 << LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1749 | |
| 1750 | /** |
| 1751 | * Indicates whether the view horizontal layout direction has been resolved and drawn to the |
| 1752 | * right-to-left direction. |
| 1753 | * @hide |
| 1754 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1755 | 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] | 1756 | |
| 1757 | /** |
| 1758 | * Indicates whether the view horizontal layout direction has been resolved. |
| 1759 | * @hide |
| 1760 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1761 | static final int LAYOUT_DIRECTION_RESOLVED = 8 << LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1762 | |
| 1763 | /** |
| 1764 | * Mask for use with private flags indicating bits used for resolved horizontal layout direction. |
| 1765 | * @hide |
| 1766 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1767 | 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] | 1768 | |
| 1769 | /* |
| 1770 | * Array of horizontal layout direction flags for mapping attribute "layoutDirection" to correct |
| 1771 | * flag value. |
| 1772 | * @hide |
| 1773 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1774 | private static final int[] LAYOUT_DIRECTION_FLAGS = { |
| 1775 | LAYOUT_DIRECTION_LTR, |
| 1776 | LAYOUT_DIRECTION_RTL, |
| 1777 | LAYOUT_DIRECTION_INHERIT, |
| 1778 | LAYOUT_DIRECTION_LOCALE |
| 1779 | }; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1780 | |
| 1781 | /** |
| 1782 | * Default horizontal layout direction. |
| 1783 | * @hide |
| 1784 | */ |
| 1785 | private static final int LAYOUT_DIRECTION_DEFAULT = LAYOUT_DIRECTION_INHERIT; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1786 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1787 | |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1788 | /** |
| 1789 | * Indicates that the view is tracking some sort of transient state |
| 1790 | * that the app should not need to be aware of, but that the framework |
| 1791 | * should take special care to preserve. |
| 1792 | * |
| 1793 | * @hide |
| 1794 | */ |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1795 | static final int HAS_TRANSIENT_STATE = 0x00000100; |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1796 | |
| 1797 | |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1798 | /** |
| 1799 | * Text direction is inherited thru {@link ViewGroup} |
| 1800 | */ |
| 1801 | public static final int TEXT_DIRECTION_INHERIT = 0; |
| 1802 | |
| 1803 | /** |
| 1804 | * Text direction is using "first strong algorithm". The first strong directional character |
| 1805 | * determines the paragraph direction. If there is no strong directional character, the |
| 1806 | * paragraph direction is the view's resolved layout direction. |
| 1807 | */ |
| 1808 | public static final int TEXT_DIRECTION_FIRST_STRONG = 1; |
| 1809 | |
| 1810 | /** |
| 1811 | * Text direction is using "any-RTL" algorithm. The paragraph direction is RTL if it contains |
| 1812 | * any strong RTL character, otherwise it is LTR if it contains any strong LTR characters. |
| 1813 | * If there are neither, the paragraph direction is the view's resolved layout direction. |
| 1814 | */ |
| 1815 | public static final int TEXT_DIRECTION_ANY_RTL = 2; |
| 1816 | |
| 1817 | /** |
| 1818 | * Text direction is forced to LTR. |
| 1819 | */ |
| 1820 | public static final int TEXT_DIRECTION_LTR = 3; |
| 1821 | |
| 1822 | /** |
| 1823 | * Text direction is forced to RTL. |
| 1824 | */ |
| 1825 | public static final int TEXT_DIRECTION_RTL = 4; |
| 1826 | |
| 1827 | /** |
| 1828 | * Text direction is coming from the system Locale. |
| 1829 | */ |
| 1830 | public static final int TEXT_DIRECTION_LOCALE = 5; |
| 1831 | |
| 1832 | /** |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1833 | * Default text direction is inherited |
| 1834 | */ |
| 1835 | protected static int TEXT_DIRECTION_DEFAULT = TEXT_DIRECTION_INHERIT; |
| 1836 | |
| 1837 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1838 | * Bit shift to get the horizontal layout direction. (bits after LAYOUT_DIRECTION_RESOLVED) |
| 1839 | * @hide |
| 1840 | */ |
| 1841 | static final int TEXT_DIRECTION_MASK_SHIFT = 6; |
| 1842 | |
| 1843 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1844 | * Mask for use with private flags indicating bits used for text direction. |
| 1845 | * @hide |
| 1846 | */ |
| 1847 | static final int TEXT_DIRECTION_MASK = 0x00000007 << TEXT_DIRECTION_MASK_SHIFT; |
| 1848 | |
| 1849 | /** |
| 1850 | * Array of text direction flags for mapping attribute "textDirection" to correct |
| 1851 | * flag value. |
| 1852 | * @hide |
| 1853 | */ |
| 1854 | private static final int[] TEXT_DIRECTION_FLAGS = { |
| 1855 | TEXT_DIRECTION_INHERIT << TEXT_DIRECTION_MASK_SHIFT, |
| 1856 | TEXT_DIRECTION_FIRST_STRONG << TEXT_DIRECTION_MASK_SHIFT, |
| 1857 | TEXT_DIRECTION_ANY_RTL << TEXT_DIRECTION_MASK_SHIFT, |
| 1858 | TEXT_DIRECTION_LTR << TEXT_DIRECTION_MASK_SHIFT, |
| 1859 | TEXT_DIRECTION_RTL << TEXT_DIRECTION_MASK_SHIFT, |
| 1860 | TEXT_DIRECTION_LOCALE << TEXT_DIRECTION_MASK_SHIFT |
| 1861 | }; |
| 1862 | |
| 1863 | /** |
| 1864 | * Indicates whether the view text direction has been resolved. |
| 1865 | * @hide |
| 1866 | */ |
| 1867 | static final int TEXT_DIRECTION_RESOLVED = 0x00000008 << TEXT_DIRECTION_MASK_SHIFT; |
| 1868 | |
| 1869 | /** |
| 1870 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
| 1871 | * @hide |
| 1872 | */ |
| 1873 | static final int TEXT_DIRECTION_RESOLVED_MASK_SHIFT = 10; |
| 1874 | |
| 1875 | /** |
| 1876 | * Mask for use with private flags indicating bits used for resolved text direction. |
| 1877 | * @hide |
| 1878 | */ |
| 1879 | static final int TEXT_DIRECTION_RESOLVED_MASK = 0x00000007 << TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
| 1880 | |
| 1881 | /** |
| 1882 | * Indicates whether the view text direction has been resolved to the "first strong" heuristic. |
| 1883 | * @hide |
| 1884 | */ |
| 1885 | static final int TEXT_DIRECTION_RESOLVED_DEFAULT = |
| 1886 | TEXT_DIRECTION_FIRST_STRONG << TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
| 1887 | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1888 | /* |
| 1889 | * Default text alignment. The text alignment of this View is inherited from its parent. |
| 1890 | * Use with {@link #setTextAlignment(int)} |
| 1891 | */ |
| 1892 | public static final int TEXT_ALIGNMENT_INHERIT = 0; |
| 1893 | |
| 1894 | /** |
| 1895 | * Default for the root view. The gravity determines the text alignment, ALIGN_NORMAL, |
| 1896 | * ALIGN_CENTER, or ALIGN_OPPOSITE, which are relative to each paragraph’s text direction. |
| 1897 | * |
| 1898 | * Use with {@link #setTextAlignment(int)} |
| 1899 | */ |
| 1900 | public static final int TEXT_ALIGNMENT_GRAVITY = 1; |
| 1901 | |
| 1902 | /** |
| 1903 | * Align to the start of the paragraph, e.g. ALIGN_NORMAL. |
| 1904 | * |
| 1905 | * Use with {@link #setTextAlignment(int)} |
| 1906 | */ |
| 1907 | public static final int TEXT_ALIGNMENT_TEXT_START = 2; |
| 1908 | |
| 1909 | /** |
| 1910 | * Align to the end of the paragraph, e.g. ALIGN_OPPOSITE. |
| 1911 | * |
| 1912 | * Use with {@link #setTextAlignment(int)} |
| 1913 | */ |
| 1914 | public static final int TEXT_ALIGNMENT_TEXT_END = 3; |
| 1915 | |
| 1916 | /** |
| 1917 | * Center the paragraph, e.g. ALIGN_CENTER. |
| 1918 | * |
| 1919 | * Use with {@link #setTextAlignment(int)} |
| 1920 | */ |
| 1921 | public static final int TEXT_ALIGNMENT_CENTER = 4; |
| 1922 | |
| 1923 | /** |
| 1924 | * Align to the start of the view, which is ALIGN_LEFT if the view’s resolved |
| 1925 | * layoutDirection is LTR, and ALIGN_RIGHT otherwise. |
| 1926 | * |
| 1927 | * Use with {@link #setTextAlignment(int)} |
| 1928 | */ |
| 1929 | public static final int TEXT_ALIGNMENT_VIEW_START = 5; |
| 1930 | |
| 1931 | /** |
| 1932 | * Align to the end of the view, which is ALIGN_RIGHT if the view’s resolved |
| 1933 | * layoutDirection is LTR, and ALIGN_LEFT otherwise. |
| 1934 | * |
| 1935 | * Use with {@link #setTextAlignment(int)} |
| 1936 | */ |
| 1937 | public static final int TEXT_ALIGNMENT_VIEW_END = 6; |
| 1938 | |
| 1939 | /** |
| 1940 | * Default text alignment is inherited |
| 1941 | */ |
| 1942 | protected static int TEXT_ALIGNMENT_DEFAULT = TEXT_ALIGNMENT_GRAVITY; |
| 1943 | |
| 1944 | /** |
| 1945 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
| 1946 | * @hide |
| 1947 | */ |
| 1948 | static final int TEXT_ALIGNMENT_MASK_SHIFT = 13; |
| 1949 | |
| 1950 | /** |
| 1951 | * Mask for use with private flags indicating bits used for text alignment. |
| 1952 | * @hide |
| 1953 | */ |
| 1954 | static final int TEXT_ALIGNMENT_MASK = 0x00000007 << TEXT_ALIGNMENT_MASK_SHIFT; |
| 1955 | |
| 1956 | /** |
| 1957 | * Array of text direction flags for mapping attribute "textAlignment" to correct |
| 1958 | * flag value. |
| 1959 | * @hide |
| 1960 | */ |
| 1961 | private static final int[] TEXT_ALIGNMENT_FLAGS = { |
| 1962 | TEXT_ALIGNMENT_INHERIT << TEXT_ALIGNMENT_MASK_SHIFT, |
| 1963 | TEXT_ALIGNMENT_GRAVITY << TEXT_ALIGNMENT_MASK_SHIFT, |
| 1964 | TEXT_ALIGNMENT_TEXT_START << TEXT_ALIGNMENT_MASK_SHIFT, |
| 1965 | TEXT_ALIGNMENT_TEXT_END << TEXT_ALIGNMENT_MASK_SHIFT, |
| 1966 | TEXT_ALIGNMENT_CENTER << TEXT_ALIGNMENT_MASK_SHIFT, |
| 1967 | TEXT_ALIGNMENT_VIEW_START << TEXT_ALIGNMENT_MASK_SHIFT, |
| 1968 | TEXT_ALIGNMENT_VIEW_END << TEXT_ALIGNMENT_MASK_SHIFT |
| 1969 | }; |
| 1970 | |
| 1971 | /** |
| 1972 | * Indicates whether the view text alignment has been resolved. |
| 1973 | * @hide |
| 1974 | */ |
| 1975 | static final int TEXT_ALIGNMENT_RESOLVED = 0x00000008 << TEXT_ALIGNMENT_MASK_SHIFT; |
| 1976 | |
| 1977 | /** |
| 1978 | * Bit shift to get the resolved text alignment. |
| 1979 | * @hide |
| 1980 | */ |
| 1981 | static final int TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT = 17; |
| 1982 | |
| 1983 | /** |
| 1984 | * Mask for use with private flags indicating bits used for text alignment. |
| 1985 | * @hide |
| 1986 | */ |
| 1987 | static final int TEXT_ALIGNMENT_RESOLVED_MASK = 0x00000007 << TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
| 1988 | |
| 1989 | /** |
| 1990 | * Indicates whether if the view text alignment has been resolved to gravity |
| 1991 | */ |
| 1992 | public static final int TEXT_ALIGNMENT_RESOLVED_DEFAULT = |
| 1993 | TEXT_ALIGNMENT_GRAVITY << TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
| 1994 | |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1995 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1996 | /* End of masks for mPrivateFlags2 */ |
| 1997 | |
| 1998 | static final int DRAG_MASK = DRAG_CAN_ACCEPT | DRAG_HOVERED; |
| 1999 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 2000 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2001 | * Always allow a user to over-scroll this view, provided it is a |
| 2002 | * view that can scroll. |
| 2003 | * |
| 2004 | * @see #getOverScrollMode() |
| 2005 | * @see #setOverScrollMode(int) |
| 2006 | */ |
| 2007 | public static final int OVER_SCROLL_ALWAYS = 0; |
| 2008 | |
| 2009 | /** |
| 2010 | * Allow a user to over-scroll this view only if the content is large |
| 2011 | * enough to meaningfully scroll, provided it is a view that can scroll. |
| 2012 | * |
| 2013 | * @see #getOverScrollMode() |
| 2014 | * @see #setOverScrollMode(int) |
| 2015 | */ |
| 2016 | public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1; |
| 2017 | |
| 2018 | /** |
| 2019 | * Never allow a user to over-scroll this view. |
| 2020 | * |
| 2021 | * @see #getOverScrollMode() |
| 2022 | * @see #setOverScrollMode(int) |
| 2023 | */ |
| 2024 | public static final int OVER_SCROLL_NEVER = 2; |
| 2025 | |
| 2026 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2027 | * Special constant for {@link #setSystemUiVisibility(int)}: View has |
| 2028 | * requested the system UI (status bar) to be visible (the default). |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2029 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2030 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2031 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2032 | public static final int SYSTEM_UI_FLAG_VISIBLE = 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2033 | |
| 2034 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2035 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested the |
| 2036 | * system UI to enter an unobtrusive "low profile" mode. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2037 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2038 | * <p>This is for use in games, book readers, video players, or any other |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2039 | * "immersive" application where the usual system chrome is deemed too distracting. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2040 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2041 | * <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] | 2042 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2043 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2044 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2045 | public static final int SYSTEM_UI_FLAG_LOW_PROFILE = 0x00000001; |
| 2046 | |
| 2047 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2048 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested that the |
| 2049 | * system navigation be temporarily hidden. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2050 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2051 | * <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] | 2052 | * {@link #SYSTEM_UI_FLAG_LOW_PROFILE}; on devices that draw essential navigation controls |
| 2053 | * (Home, Back, and the like) on screen, <code>SYSTEM_UI_FLAG_HIDE_NAVIGATION</code> will cause |
| 2054 | * those to disappear. This is useful (in conjunction with the |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2055 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN FLAG_FULLSCREEN} and |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2056 | * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN FLAG_LAYOUT_IN_SCREEN} |
| 2057 | * window flags) for displaying content using every last pixel on the display. |
| 2058 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2059 | * <p>There is a limitation: because navigation controls are so important, the least user |
| 2060 | * interaction will cause them to reappear immediately. When this happens, both |
| 2061 | * this flag and {@link #SYSTEM_UI_FLAG_FULLSCREEN} will be cleared automatically, |
| 2062 | * so that both elements reappear at the same time. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2063 | * |
| 2064 | * @see #setSystemUiVisibility(int) |
| 2065 | */ |
| 2066 | public static final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 0x00000002; |
| 2067 | |
| 2068 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2069 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested to go |
| 2070 | * into the normal fullscreen mode so that its content can take over the screen |
| 2071 | * while still allowing the user to interact with the application. |
| 2072 | * |
| 2073 | * <p>This has the same visual effect as |
| 2074 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN |
| 2075 | * WindowManager.LayoutParams.FLAG_FULLSCREEN}, |
| 2076 | * meaning that non-critical screen decorations (such as the status bar) will be |
| 2077 | * hidden while the user is in the View's window, focusing the experience on |
| 2078 | * that content. Unlike the window flag, if you are using ActionBar in |
| 2079 | * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 2080 | * Window.FEATURE_ACTION_BAR_OVERLAY}, then enabling this flag will also |
| 2081 | * hide the action bar. |
| 2082 | * |
| 2083 | * <p>This approach to going fullscreen is best used over the window flag when |
| 2084 | * it is a transient state -- that is, the application does this at certain |
| 2085 | * points in its user interaction where it wants to allow the user to focus |
| 2086 | * on content, but not as a continuous state. For situations where the application |
| 2087 | * would like to simply stay full screen the entire time (such as a game that |
| 2088 | * wants to take over the screen), the |
| 2089 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN window flag} |
| 2090 | * is usually a better approach. The state set here will be removed by the system |
| 2091 | * in various situations (such as the user moving to another application) like |
| 2092 | * the other system UI states. |
| 2093 | * |
| 2094 | * <p>When using this flag, the application should provide some easy facility |
| 2095 | * for the user to go out of it. A common example would be in an e-book |
| 2096 | * reader, where tapping on the screen brings back whatever screen and UI |
| 2097 | * decorations that had been hidden while the user was immersed in reading |
| 2098 | * the book. |
| 2099 | * |
| 2100 | * @see #setSystemUiVisibility(int) |
| 2101 | */ |
| 2102 | public static final int SYSTEM_UI_FLAG_FULLSCREEN = 0x00000004; |
| 2103 | |
| 2104 | /** |
| 2105 | * Flag for {@link #setSystemUiVisibility(int)}: When using other layout |
| 2106 | * flags, we would like a stable view of the content insets given to |
| 2107 | * {@link #fitSystemWindows(Rect)}. This means that the insets seen there |
| 2108 | * will always represent the worst case that the application can expect |
| 2109 | * as a continue state. In practice this means with any of system bar, |
| 2110 | * nav bar, and status bar shown, but not the space that would be needed |
| 2111 | * for an input method. |
| 2112 | * |
| 2113 | * <p>If you are using ActionBar in |
| 2114 | * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 2115 | * Window.FEATURE_ACTION_BAR_OVERLAY}, this flag will also impact the |
| 2116 | * insets it adds to those given to the application. |
| 2117 | */ |
| 2118 | public static final int SYSTEM_UI_FLAG_LAYOUT_STABLE = 0x00000100; |
| 2119 | |
| 2120 | /** |
| 2121 | * Flag for {@link #setSystemUiVisibility(int)}: View would like its window |
| 2122 | * to be layed out as if it has requested |
| 2123 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, even if it currently hasn't. This |
| 2124 | * allows it to avoid artifacts when switching in and out of that mode, at |
| 2125 | * the expense that some of its user interface may be covered by screen |
| 2126 | * decorations when they are shown. You can perform layout of your inner |
| 2127 | * UI elements to account for the navagation system UI through the |
| 2128 | * {@link #fitSystemWindows(Rect)} method. |
| 2129 | */ |
| 2130 | public static final int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = 0x00000200; |
| 2131 | |
| 2132 | /** |
| 2133 | * Flag for {@link #setSystemUiVisibility(int)}: View would like its window |
| 2134 | * to be layed out as if it has requested |
| 2135 | * {@link #SYSTEM_UI_FLAG_FULLSCREEN}, even if it currently hasn't. This |
| 2136 | * allows it to avoid artifacts when switching in and out of that mode, at |
| 2137 | * the expense that some of its user interface may be covered by screen |
| 2138 | * decorations when they are shown. You can perform layout of your inner |
| 2139 | * UI elements to account for non-fullscreen system UI through the |
| 2140 | * {@link #fitSystemWindows(Rect)} method. |
| 2141 | */ |
| 2142 | public static final int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 0x00000400; |
| 2143 | |
| 2144 | /** |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2145 | * @deprecated Use {@link #SYSTEM_UI_FLAG_LOW_PROFILE} instead. |
| 2146 | */ |
| 2147 | public static final int STATUS_BAR_HIDDEN = SYSTEM_UI_FLAG_LOW_PROFILE; |
| 2148 | |
| 2149 | /** |
| 2150 | * @deprecated Use {@link #SYSTEM_UI_FLAG_VISIBLE} instead. |
| 2151 | */ |
| 2152 | public static final int STATUS_BAR_VISIBLE = SYSTEM_UI_FLAG_VISIBLE; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2153 | |
| 2154 | /** |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2155 | * @hide |
| 2156 | * |
| 2157 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2158 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2159 | * |
| 2160 | * Flag to make the status bar not expandable. Unless you also |
| 2161 | * set {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show. |
| 2162 | */ |
| 2163 | public static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000; |
| 2164 | |
| 2165 | /** |
| 2166 | * @hide |
| 2167 | * |
| 2168 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2169 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2170 | * |
| 2171 | * Flag to hide notification icons and scrolling ticker text. |
| 2172 | */ |
| 2173 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ICONS = 0x00020000; |
| 2174 | |
| 2175 | /** |
| 2176 | * @hide |
| 2177 | * |
| 2178 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2179 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2180 | * |
| 2181 | * Flag to disable incoming notification alerts. This will not block |
| 2182 | * icons, but it will block sound, vibrating and other visual or aural notifications. |
| 2183 | */ |
| 2184 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ALERTS = 0x00040000; |
| 2185 | |
| 2186 | /** |
| 2187 | * @hide |
| 2188 | * |
| 2189 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2190 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2191 | * |
| 2192 | * Flag to hide only the scrolling ticker. Note that |
| 2193 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS} implies |
| 2194 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_TICKER}. |
| 2195 | */ |
| 2196 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_TICKER = 0x00080000; |
| 2197 | |
| 2198 | /** |
| 2199 | * @hide |
| 2200 | * |
| 2201 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2202 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2203 | * |
| 2204 | * Flag to hide the center system info area. |
| 2205 | */ |
| 2206 | public static final int STATUS_BAR_DISABLE_SYSTEM_INFO = 0x00100000; |
| 2207 | |
| 2208 | /** |
| 2209 | * @hide |
| 2210 | * |
| 2211 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2212 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2213 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2214 | * Flag to hide only the home button. Don't use this |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2215 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2216 | */ |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2217 | public static final int STATUS_BAR_DISABLE_HOME = 0x00200000; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2218 | |
| 2219 | /** |
| 2220 | * @hide |
| 2221 | * |
| 2222 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2223 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2224 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2225 | * Flag to hide only the back button. Don't use this |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 2226 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2227 | */ |
| 2228 | public static final int STATUS_BAR_DISABLE_BACK = 0x00400000; |
| 2229 | |
| 2230 | /** |
| 2231 | * @hide |
| 2232 | * |
| 2233 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2234 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2235 | * |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2236 | * Flag to hide only the clock. You might use this if your activity has |
| 2237 | * its own clock making the status bar's clock redundant. |
| 2238 | */ |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 2239 | public static final int STATUS_BAR_DISABLE_CLOCK = 0x00800000; |
| 2240 | |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2241 | /** |
| 2242 | * @hide |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2243 | * |
| 2244 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2245 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2246 | * |
| 2247 | * Flag to hide only the recent apps button. Don't use this |
| 2248 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2249 | */ |
| 2250 | public static final int STATUS_BAR_DISABLE_RECENT = 0x01000000; |
| 2251 | |
| 2252 | /** |
| 2253 | * @hide |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2254 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2255 | public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK = 0x0000FFFF; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2256 | |
| 2257 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2258 | * These are the system UI flags that can be cleared by events outside |
| 2259 | * of an application. Currently this is just the ability to tap on the |
| 2260 | * screen while hiding the navigation bar to have it return. |
| 2261 | * @hide |
| 2262 | */ |
| 2263 | public static final int SYSTEM_UI_CLEARABLE_FLAGS = |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2264 | SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_HIDE_NAVIGATION |
| 2265 | | SYSTEM_UI_FLAG_FULLSCREEN; |
| 2266 | |
| 2267 | /** |
| 2268 | * Flags that can impact the layout in relation to system UI. |
| 2269 | */ |
| 2270 | public static final int SYSTEM_UI_LAYOUT_FLAGS = |
| 2271 | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
| 2272 | | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2273 | |
| 2274 | /** |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 2275 | * Find views that render the specified text. |
| 2276 | * |
| 2277 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2278 | */ |
| 2279 | public static final int FIND_VIEWS_WITH_TEXT = 0x00000001; |
| 2280 | |
| 2281 | /** |
| 2282 | * Find find views that contain the specified content description. |
| 2283 | * |
| 2284 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2285 | */ |
| 2286 | public static final int FIND_VIEWS_WITH_CONTENT_DESCRIPTION = 0x00000002; |
| 2287 | |
| 2288 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 2289 | * Find views that contain {@link AccessibilityNodeProvider}. Such |
| 2290 | * a View is a root of virtual view hierarchy and may contain the searched |
| 2291 | * text. If this flag is set Views with providers are automatically |
| 2292 | * added and it is a responsibility of the client to call the APIs of |
| 2293 | * the provider to determine whether the virtual tree rooted at this View |
| 2294 | * contains the text, i.e. getting the list of {@link AccessibilityNodeInfo}s |
| 2295 | * represeting the virtual views with this text. |
| 2296 | * |
| 2297 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2298 | * |
| 2299 | * @hide |
| 2300 | */ |
| 2301 | public static final int FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS = 0x00000004; |
| 2302 | |
| 2303 | /** |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 2304 | * Indicates that the screen has changed state and is now off. |
| 2305 | * |
| 2306 | * @see #onScreenStateChanged(int) |
| 2307 | */ |
| 2308 | public static final int SCREEN_STATE_OFF = 0x0; |
| 2309 | |
| 2310 | /** |
| 2311 | * Indicates that the screen has changed state and is now on. |
| 2312 | * |
Romain Guy | 1e3d313 | 2012-03-08 15:55:56 -0800 | [diff] [blame] | 2313 | * @see #onScreenStateChanged(int) |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 2314 | */ |
| 2315 | public static final int SCREEN_STATE_ON = 0x1; |
| 2316 | |
| 2317 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2318 | * Controls the over-scroll mode for this view. |
| 2319 | * See {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)}, |
| 2320 | * {@link #OVER_SCROLL_ALWAYS}, {@link #OVER_SCROLL_IF_CONTENT_SCROLLS}, |
| 2321 | * and {@link #OVER_SCROLL_NEVER}. |
| 2322 | */ |
| 2323 | private int mOverScrollMode; |
| 2324 | |
| 2325 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2326 | * The parent this view is attached to. |
| 2327 | * {@hide} |
| 2328 | * |
| 2329 | * @see #getParent() |
| 2330 | */ |
| 2331 | protected ViewParent mParent; |
| 2332 | |
| 2333 | /** |
| 2334 | * {@hide} |
| 2335 | */ |
| 2336 | AttachInfo mAttachInfo; |
| 2337 | |
| 2338 | /** |
| 2339 | * {@hide} |
| 2340 | */ |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2341 | @ViewDebug.ExportedProperty(flagMapping = { |
| 2342 | @ViewDebug.FlagToString(mask = FORCE_LAYOUT, equals = FORCE_LAYOUT, |
| 2343 | name = "FORCE_LAYOUT"), |
| 2344 | @ViewDebug.FlagToString(mask = LAYOUT_REQUIRED, equals = LAYOUT_REQUIRED, |
| 2345 | name = "LAYOUT_REQUIRED"), |
| 2346 | @ViewDebug.FlagToString(mask = DRAWING_CACHE_VALID, equals = DRAWING_CACHE_VALID, |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 2347 | name = "DRAWING_CACHE_INVALID", outputIf = false), |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2348 | @ViewDebug.FlagToString(mask = DRAWN, equals = DRAWN, name = "DRAWN", outputIf = true), |
| 2349 | @ViewDebug.FlagToString(mask = DRAWN, equals = DRAWN, name = "NOT_DRAWN", outputIf = false), |
| 2350 | @ViewDebug.FlagToString(mask = DIRTY_MASK, equals = DIRTY_OPAQUE, name = "DIRTY_OPAQUE"), |
| 2351 | @ViewDebug.FlagToString(mask = DIRTY_MASK, equals = DIRTY, name = "DIRTY") |
| 2352 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2353 | int mPrivateFlags; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2354 | int mPrivateFlags2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2355 | |
| 2356 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2357 | * This view's request for the visibility of the status bar. |
| 2358 | * @hide |
| 2359 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2360 | @ViewDebug.ExportedProperty(flagMapping = { |
| 2361 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2362 | equals = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2363 | name = "SYSTEM_UI_FLAG_LOW_PROFILE", outputIf = true), |
| 2364 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2365 | equals = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2366 | name = "SYSTEM_UI_FLAG_HIDE_NAVIGATION", outputIf = true), |
| 2367 | @ViewDebug.FlagToString(mask = PUBLIC_STATUS_BAR_VISIBILITY_MASK, |
| 2368 | equals = SYSTEM_UI_FLAG_VISIBLE, |
| 2369 | name = "SYSTEM_UI_FLAG_VISIBLE", outputIf = true) |
| 2370 | }) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2371 | int mSystemUiVisibility; |
| 2372 | |
| 2373 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2374 | * Count of how many windows this view has been attached to. |
| 2375 | */ |
| 2376 | int mWindowAttachCount; |
| 2377 | |
| 2378 | /** |
| 2379 | * The layout parameters associated with this view and used by the parent |
| 2380 | * {@link android.view.ViewGroup} to determine how this view should be |
| 2381 | * laid out. |
| 2382 | * {@hide} |
| 2383 | */ |
| 2384 | protected ViewGroup.LayoutParams mLayoutParams; |
| 2385 | |
| 2386 | /** |
| 2387 | * The view flags hold various views states. |
| 2388 | * {@hide} |
| 2389 | */ |
| 2390 | @ViewDebug.ExportedProperty |
| 2391 | int mViewFlags; |
| 2392 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2393 | static class TransformationInfo { |
| 2394 | /** |
| 2395 | * The transform matrix for the View. This transform is calculated internally |
| 2396 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2397 | * is used by default. Do *not* use this variable directly; instead call |
| 2398 | * getMatrix(), which will automatically recalculate the matrix if necessary |
| 2399 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2400 | */ |
| 2401 | private final Matrix mMatrix = new Matrix(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2402 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2403 | /** |
| 2404 | * The transform matrix for the View. This transform is calculated internally |
| 2405 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2406 | * is used by default. Do *not* use this variable directly; instead call |
| 2407 | * getInverseMatrix(), which will automatically recalculate the matrix if necessary |
| 2408 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2409 | */ |
| 2410 | private Matrix mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2411 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2412 | /** |
| 2413 | * An internal variable that tracks whether we need to recalculate the |
| 2414 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2415 | * have changed since the matrix was last calculated. |
| 2416 | */ |
| 2417 | boolean mMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2418 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2419 | /** |
| 2420 | * An internal variable that tracks whether we need to recalculate the |
| 2421 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2422 | * have changed since the matrix was last calculated. |
| 2423 | */ |
| 2424 | private boolean mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2425 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2426 | /** |
| 2427 | * A variable that tracks whether we need to recalculate the |
| 2428 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2429 | * have changed since the matrix was last calculated. This variable |
| 2430 | * is only valid after a call to updateMatrix() or to a function that |
| 2431 | * calls it such as getMatrix(), hasIdentityMatrix() and getInverseMatrix(). |
| 2432 | */ |
| 2433 | private boolean mMatrixIsIdentity = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2434 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2435 | /** |
| 2436 | * The Camera object is used to compute a 3D matrix when rotationX or rotationY are set. |
| 2437 | */ |
| 2438 | private Camera mCamera = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2439 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2440 | /** |
| 2441 | * This matrix is used when computing the matrix for 3D rotations. |
| 2442 | */ |
| 2443 | private Matrix matrix3D = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2444 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2445 | /** |
| 2446 | * These prev values are used to recalculate a centered pivot point when necessary. The |
| 2447 | * pivot point is only used in matrix operations (when rotation, scale, or translation are |
| 2448 | * set), so thes values are only used then as well. |
| 2449 | */ |
| 2450 | private int mPrevWidth = -1; |
| 2451 | private int mPrevHeight = -1; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2452 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2453 | /** |
| 2454 | * The degrees rotation around the vertical axis through the pivot point. |
| 2455 | */ |
| 2456 | @ViewDebug.ExportedProperty |
| 2457 | float mRotationY = 0f; |
| 2458 | |
| 2459 | /** |
| 2460 | * The degrees rotation around the horizontal axis through the pivot point. |
| 2461 | */ |
| 2462 | @ViewDebug.ExportedProperty |
| 2463 | float mRotationX = 0f; |
| 2464 | |
| 2465 | /** |
| 2466 | * The degrees rotation around the pivot point. |
| 2467 | */ |
| 2468 | @ViewDebug.ExportedProperty |
| 2469 | float mRotation = 0f; |
| 2470 | |
| 2471 | /** |
| 2472 | * The amount of translation of the object away from its left property (post-layout). |
| 2473 | */ |
| 2474 | @ViewDebug.ExportedProperty |
| 2475 | float mTranslationX = 0f; |
| 2476 | |
| 2477 | /** |
| 2478 | * The amount of translation of the object away from its top property (post-layout). |
| 2479 | */ |
| 2480 | @ViewDebug.ExportedProperty |
| 2481 | float mTranslationY = 0f; |
| 2482 | |
| 2483 | /** |
| 2484 | * The amount of scale in the x direction around the pivot point. A |
| 2485 | * value of 1 means no scaling is applied. |
| 2486 | */ |
| 2487 | @ViewDebug.ExportedProperty |
| 2488 | float mScaleX = 1f; |
| 2489 | |
| 2490 | /** |
| 2491 | * The amount of scale in the y direction around the pivot point. A |
| 2492 | * value of 1 means no scaling is applied. |
| 2493 | */ |
| 2494 | @ViewDebug.ExportedProperty |
| 2495 | float mScaleY = 1f; |
| 2496 | |
| 2497 | /** |
Chet Haase | a33de55 | 2012-02-03 16:28:24 -0800 | [diff] [blame] | 2498 | * 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] | 2499 | */ |
| 2500 | @ViewDebug.ExportedProperty |
| 2501 | float mPivotX = 0f; |
| 2502 | |
| 2503 | /** |
Chet Haase | a33de55 | 2012-02-03 16:28:24 -0800 | [diff] [blame] | 2504 | * 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] | 2505 | */ |
| 2506 | @ViewDebug.ExportedProperty |
| 2507 | float mPivotY = 0f; |
| 2508 | |
| 2509 | /** |
| 2510 | * The opacity of the View. This is a value from 0 to 1, where 0 means |
| 2511 | * completely transparent and 1 means completely opaque. |
| 2512 | */ |
| 2513 | @ViewDebug.ExportedProperty |
| 2514 | float mAlpha = 1f; |
| 2515 | } |
| 2516 | |
| 2517 | TransformationInfo mTransformationInfo; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2518 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2519 | private boolean mLastIsOpaque; |
| 2520 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2521 | /** |
| 2522 | * Convenience value to check for float values that are close enough to zero to be considered |
| 2523 | * zero. |
| 2524 | */ |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame] | 2525 | private static final float NONZERO_EPSILON = .001f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2526 | |
| 2527 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2528 | * The distance in pixels from the left edge of this view's parent |
| 2529 | * to the left edge of this view. |
| 2530 | * {@hide} |
| 2531 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2532 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2533 | protected int mLeft; |
| 2534 | /** |
| 2535 | * The distance in pixels from the left edge of this view's parent |
| 2536 | * to the right edge of this view. |
| 2537 | * {@hide} |
| 2538 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2539 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2540 | protected int mRight; |
| 2541 | /** |
| 2542 | * The distance in pixels from the top edge of this view's parent |
| 2543 | * to the top edge of this view. |
| 2544 | * {@hide} |
| 2545 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2546 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2547 | protected int mTop; |
| 2548 | /** |
| 2549 | * The distance in pixels from the top edge of this view's parent |
| 2550 | * to the bottom edge of this view. |
| 2551 | * {@hide} |
| 2552 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2553 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2554 | protected int mBottom; |
| 2555 | |
| 2556 | /** |
| 2557 | * The offset, in pixels, by which the content of this view is scrolled |
| 2558 | * horizontally. |
| 2559 | * {@hide} |
| 2560 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2561 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2562 | protected int mScrollX; |
| 2563 | /** |
| 2564 | * The offset, in pixels, by which the content of this view is scrolled |
| 2565 | * vertically. |
| 2566 | * {@hide} |
| 2567 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2568 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2569 | protected int mScrollY; |
| 2570 | |
| 2571 | /** |
| 2572 | * The left padding in pixels, that is the distance in pixels between the |
| 2573 | * left edge of this view and the left edge of its content. |
| 2574 | * {@hide} |
| 2575 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2576 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2577 | protected int mPaddingLeft; |
| 2578 | /** |
| 2579 | * The right padding in pixels, that is the distance in pixels between the |
| 2580 | * right edge of this view and the right edge of its content. |
| 2581 | * {@hide} |
| 2582 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2583 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2584 | protected int mPaddingRight; |
| 2585 | /** |
| 2586 | * The top padding in pixels, that is the distance in pixels between the |
| 2587 | * top edge of this view and the top edge of its content. |
| 2588 | * {@hide} |
| 2589 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2590 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2591 | protected int mPaddingTop; |
| 2592 | /** |
| 2593 | * The bottom padding in pixels, that is the distance in pixels between the |
| 2594 | * bottom edge of this view and the bottom edge of its content. |
| 2595 | * {@hide} |
| 2596 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2597 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2598 | protected int mPaddingBottom; |
| 2599 | |
| 2600 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2601 | * Briefly describes the view and is primarily used for accessibility support. |
| 2602 | */ |
| 2603 | private CharSequence mContentDescription; |
| 2604 | |
| 2605 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2606 | * 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] | 2607 | * |
| 2608 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2609 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2610 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2611 | protected int mUserPaddingRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2612 | |
| 2613 | /** |
| 2614 | * 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] | 2615 | * |
| 2616 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2618 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2619 | protected int mUserPaddingBottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2620 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2621 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2622 | * 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] | 2623 | * |
| 2624 | * @hide |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2625 | */ |
| 2626 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2627 | protected int mUserPaddingLeft; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2628 | |
| 2629 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 2630 | * Cache if the user padding is relative. |
| 2631 | * |
| 2632 | */ |
| 2633 | @ViewDebug.ExportedProperty(category = "padding") |
| 2634 | boolean mUserPaddingRelative; |
| 2635 | |
| 2636 | /** |
| 2637 | * Cache the paddingStart set by the user to append to the scrollbar's size. |
| 2638 | * |
| 2639 | */ |
| 2640 | @ViewDebug.ExportedProperty(category = "padding") |
| 2641 | int mUserPaddingStart; |
| 2642 | |
| 2643 | /** |
| 2644 | * Cache the paddingEnd set by the user to append to the scrollbar's size. |
| 2645 | * |
| 2646 | */ |
| 2647 | @ViewDebug.ExportedProperty(category = "padding") |
| 2648 | int mUserPaddingEnd; |
| 2649 | |
| 2650 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2651 | * @hide |
| 2652 | */ |
| 2653 | int mOldWidthMeasureSpec = Integer.MIN_VALUE; |
| 2654 | /** |
| 2655 | * @hide |
| 2656 | */ |
| 2657 | int mOldHeightMeasureSpec = Integer.MIN_VALUE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2658 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2659 | private Drawable mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2660 | |
| 2661 | private int mBackgroundResource; |
| 2662 | private boolean mBackgroundSizeChanged; |
| 2663 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2664 | static class ListenerInfo { |
| 2665 | /** |
| 2666 | * Listener used to dispatch focus change events. |
| 2667 | * This field should be made private, so it is hidden from the SDK. |
| 2668 | * {@hide} |
| 2669 | */ |
| 2670 | protected OnFocusChangeListener mOnFocusChangeListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2671 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2672 | /** |
| 2673 | * Listeners for layout change events. |
| 2674 | */ |
| 2675 | private ArrayList<OnLayoutChangeListener> mOnLayoutChangeListeners; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 2676 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2677 | /** |
| 2678 | * Listeners for attach events. |
| 2679 | */ |
| 2680 | private CopyOnWriteArrayList<OnAttachStateChangeListener> mOnAttachStateChangeListeners; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 2681 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2682 | /** |
| 2683 | * Listener used to dispatch click events. |
| 2684 | * This field should be made private, so it is hidden from the SDK. |
| 2685 | * {@hide} |
| 2686 | */ |
| 2687 | public OnClickListener mOnClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2688 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2689 | /** |
| 2690 | * Listener used to dispatch long click events. |
| 2691 | * This field should be made private, so it is hidden from the SDK. |
| 2692 | * {@hide} |
| 2693 | */ |
| 2694 | protected OnLongClickListener mOnLongClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2695 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2696 | /** |
| 2697 | * Listener used to build the context menu. |
| 2698 | * This field should be made private, so it is hidden from the SDK. |
| 2699 | * {@hide} |
| 2700 | */ |
| 2701 | protected OnCreateContextMenuListener mOnCreateContextMenuListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2702 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2703 | private OnKeyListener mOnKeyListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2704 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2705 | private OnTouchListener mOnTouchListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2706 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2707 | private OnHoverListener mOnHoverListener; |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2708 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2709 | private OnGenericMotionListener mOnGenericMotionListener; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2710 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2711 | private OnDragListener mOnDragListener; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 2712 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2713 | private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener; |
| 2714 | } |
| 2715 | |
| 2716 | ListenerInfo mListenerInfo; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2717 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2718 | /** |
| 2719 | * The application environment this view lives in. |
| 2720 | * This field should be made private, so it is hidden from the SDK. |
| 2721 | * {@hide} |
| 2722 | */ |
| 2723 | protected Context mContext; |
| 2724 | |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 2725 | private final Resources mResources; |
| 2726 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2727 | private ScrollabilityCache mScrollCache; |
| 2728 | |
| 2729 | private int[] mDrawableState = null; |
| 2730 | |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2731 | /** |
| 2732 | * Set to true when drawing cache is enabled and cannot be created. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2733 | * |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2734 | * @hide |
| 2735 | */ |
| 2736 | public boolean mCachingFailed; |
| 2737 | |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 2738 | private Bitmap mDrawingCache; |
| 2739 | private Bitmap mUnscaledDrawingCache; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 2740 | private HardwareLayer mHardwareLayer; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2741 | DisplayList mDisplayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2742 | |
| 2743 | /** |
| 2744 | * When this view has focus and the next focus is {@link #FOCUS_LEFT}, |
| 2745 | * the user may specify which view to go to next. |
| 2746 | */ |
| 2747 | private int mNextFocusLeftId = View.NO_ID; |
| 2748 | |
| 2749 | /** |
| 2750 | * When this view has focus and the next focus is {@link #FOCUS_RIGHT}, |
| 2751 | * the user may specify which view to go to next. |
| 2752 | */ |
| 2753 | private int mNextFocusRightId = View.NO_ID; |
| 2754 | |
| 2755 | /** |
| 2756 | * When this view has focus and the next focus is {@link #FOCUS_UP}, |
| 2757 | * the user may specify which view to go to next. |
| 2758 | */ |
| 2759 | private int mNextFocusUpId = View.NO_ID; |
| 2760 | |
| 2761 | /** |
| 2762 | * When this view has focus and the next focus is {@link #FOCUS_DOWN}, |
| 2763 | * the user may specify which view to go to next. |
| 2764 | */ |
| 2765 | private int mNextFocusDownId = View.NO_ID; |
| 2766 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 2767 | /** |
| 2768 | * When this view has focus and the next focus is {@link #FOCUS_FORWARD}, |
| 2769 | * the user may specify which view to go to next. |
| 2770 | */ |
| 2771 | int mNextFocusForwardId = View.NO_ID; |
| 2772 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2773 | private CheckForLongPress mPendingCheckForLongPress; |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2774 | private CheckForTap mPendingCheckForTap = null; |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 2775 | private PerformClick mPerformClick; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 2776 | private SendViewScrolledAccessibilityEvent mSendViewScrolledAccessibilityEvent; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2777 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2778 | private UnsetPressedState mUnsetPressedState; |
| 2779 | |
| 2780 | /** |
| 2781 | * Whether the long press's action has been invoked. The tap's action is invoked on the |
| 2782 | * up event while a long press is invoked as soon as the long press duration is reached, so |
| 2783 | * a long press could be performed before the tap is checked, in which case the tap's action |
| 2784 | * should not be invoked. |
| 2785 | */ |
| 2786 | private boolean mHasPerformedLongPress; |
| 2787 | |
| 2788 | /** |
| 2789 | * The minimum height of the view. We'll try our best to have the height |
| 2790 | * of this view to at least this amount. |
| 2791 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2792 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2793 | private int mMinHeight; |
| 2794 | |
| 2795 | /** |
| 2796 | * The minimum width of the view. We'll try our best to have the width |
| 2797 | * of this view to at least this amount. |
| 2798 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2799 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2800 | private int mMinWidth; |
| 2801 | |
| 2802 | /** |
| 2803 | * The delegate to handle touch events that are physically in this view |
| 2804 | * but should be handled by another view. |
| 2805 | */ |
| 2806 | private TouchDelegate mTouchDelegate = null; |
| 2807 | |
| 2808 | /** |
| 2809 | * Solid color to use as a background when creating the drawing cache. Enables |
| 2810 | * the cache to use 16 bit bitmaps instead of 32 bit. |
| 2811 | */ |
| 2812 | private int mDrawingCacheBackgroundColor = 0; |
| 2813 | |
| 2814 | /** |
| 2815 | * Special tree observer used when mAttachInfo is null. |
| 2816 | */ |
| 2817 | private ViewTreeObserver mFloatingTreeObserver; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2818 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2819 | /** |
| 2820 | * Cache the touch slop from the context that created the view. |
| 2821 | */ |
| 2822 | private int mTouchSlop; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2823 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2824 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2825 | * Object that handles automatic animation of view properties. |
| 2826 | */ |
| 2827 | private ViewPropertyAnimator mAnimator = null; |
| 2828 | |
| 2829 | /** |
Christopher Tate | 251602f | 2011-01-28 17:54:12 -0800 | [diff] [blame] | 2830 | * Flag indicating that a drag can cross window boundaries. When |
| 2831 | * {@link #startDrag(ClipData, DragShadowBuilder, Object, int)} is called |
| 2832 | * with this flag set, all visible applications will be able to participate |
| 2833 | * in the drag operation and receive the dragged content. |
Christopher Tate | 7f9ff9d | 2011-02-14 17:31:13 -0800 | [diff] [blame] | 2834 | * |
| 2835 | * @hide |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 2836 | */ |
| 2837 | public static final int DRAG_FLAG_GLOBAL = 1; |
| 2838 | |
| 2839 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2840 | * Vertical scroll factor cached by {@link #getVerticalScrollFactor}. |
| 2841 | */ |
| 2842 | private float mVerticalScrollFactor; |
| 2843 | |
| 2844 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2845 | * Position of the vertical scroll bar. |
| 2846 | */ |
| 2847 | private int mVerticalScrollbarPosition; |
| 2848 | |
| 2849 | /** |
| 2850 | * Position the scroll bar at the default position as determined by the system. |
| 2851 | */ |
| 2852 | public static final int SCROLLBAR_POSITION_DEFAULT = 0; |
| 2853 | |
| 2854 | /** |
| 2855 | * Position the scroll bar along the left edge. |
| 2856 | */ |
| 2857 | public static final int SCROLLBAR_POSITION_LEFT = 1; |
| 2858 | |
| 2859 | /** |
| 2860 | * Position the scroll bar along the right edge. |
| 2861 | */ |
| 2862 | public static final int SCROLLBAR_POSITION_RIGHT = 2; |
| 2863 | |
| 2864 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2865 | * Indicates that the view does not have a layer. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2866 | * |
| 2867 | * @see #getLayerType() |
| 2868 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2869 | * @see #LAYER_TYPE_SOFTWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2870 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2871 | */ |
| 2872 | public static final int LAYER_TYPE_NONE = 0; |
| 2873 | |
| 2874 | /** |
| 2875 | * <p>Indicates that the view has a software layer. A software layer is backed |
| 2876 | * by a bitmap and causes the view to be rendered using Android's software |
| 2877 | * rendering pipeline, even if hardware acceleration is enabled.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2878 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2879 | * <p>Software layers have various usages:</p> |
| 2880 | * <p>When the application is not using hardware acceleration, a software layer |
| 2881 | * is useful to apply a specific color filter and/or blending mode and/or |
| 2882 | * translucency to a view and all its children.</p> |
| 2883 | * <p>When the application is using hardware acceleration, a software layer |
| 2884 | * is useful to render drawing primitives not supported by the hardware |
| 2885 | * accelerated pipeline. It can also be used to cache a complex view tree |
| 2886 | * into a texture and reduce the complexity of drawing operations. For instance, |
| 2887 | * when animating a complex view tree with a translation, a software layer can |
| 2888 | * be used to render the view tree only once.</p> |
| 2889 | * <p>Software layers should be avoided when the affected view tree updates |
| 2890 | * often. Every update will require to re-render the software layer, which can |
| 2891 | * potentially be slow (particularly when hardware acceleration is turned on |
| 2892 | * since the layer will have to be uploaded into a hardware texture after every |
| 2893 | * update.)</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2894 | * |
| 2895 | * @see #getLayerType() |
| 2896 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2897 | * @see #LAYER_TYPE_NONE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2898 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2899 | */ |
| 2900 | public static final int LAYER_TYPE_SOFTWARE = 1; |
| 2901 | |
| 2902 | /** |
| 2903 | * <p>Indicates that the view has a hardware layer. A hardware layer is backed |
| 2904 | * by a hardware specific texture (generally Frame Buffer Objects or FBO on |
| 2905 | * OpenGL hardware) and causes the view to be rendered using Android's hardware |
| 2906 | * rendering pipeline, but only if hardware acceleration is turned on for the |
| 2907 | * view hierarchy. When hardware acceleration is turned off, hardware layers |
| 2908 | * behave exactly as {@link #LAYER_TYPE_SOFTWARE software layers}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2909 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2910 | * <p>A hardware layer is useful to apply a specific color filter and/or |
| 2911 | * 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] | 2912 | * <p>A hardware layer can be used to cache a complex view tree into a |
| 2913 | * texture and reduce the complexity of drawing operations. For instance, |
| 2914 | * when animating a complex view tree with a translation, a hardware layer can |
| 2915 | * be used to render the view tree only once.</p> |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2916 | * <p>A hardware layer can also be used to increase the rendering quality when |
| 2917 | * rotation transformations are applied on a view. It can also be used to |
| 2918 | * prevent potential clipping issues when applying 3D transforms on a view.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2919 | * |
| 2920 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2921 | * @see #setLayerType(int, android.graphics.Paint) |
| 2922 | * @see #LAYER_TYPE_NONE |
| 2923 | * @see #LAYER_TYPE_SOFTWARE |
| 2924 | */ |
| 2925 | public static final int LAYER_TYPE_HARDWARE = 2; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2926 | |
Romain Guy | 3aaff3a | 2011-01-12 14:18:47 -0800 | [diff] [blame] | 2927 | @ViewDebug.ExportedProperty(category = "drawing", mapping = { |
| 2928 | @ViewDebug.IntToString(from = LAYER_TYPE_NONE, to = "NONE"), |
| 2929 | @ViewDebug.IntToString(from = LAYER_TYPE_SOFTWARE, to = "SOFTWARE"), |
| 2930 | @ViewDebug.IntToString(from = LAYER_TYPE_HARDWARE, to = "HARDWARE") |
| 2931 | }) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2932 | int mLayerType = LAYER_TYPE_NONE; |
| 2933 | Paint mLayerPaint; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 2934 | Rect mLocalDirtyRect; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2935 | |
| 2936 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 2937 | * Set to true when the view is sending hover accessibility events because it |
| 2938 | * is the innermost hovered view. |
| 2939 | */ |
| 2940 | private boolean mSendingHoverAccessibilityEvents; |
| 2941 | |
| 2942 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2943 | * Simple constructor to use when creating a view from code. |
| 2944 | * |
| 2945 | * @param context The Context the view is running in, through which it can |
| 2946 | * access the current theme, resources, etc. |
| 2947 | */ |
| 2948 | public View(Context context) { |
| 2949 | mContext = context; |
| 2950 | mResources = context != null ? context.getResources() : null; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 2951 | mViewFlags = SOUND_EFFECTS_ENABLED | HAPTIC_FEEDBACK_ENABLED; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 2952 | // Set layout and text direction defaults |
| 2953 | mPrivateFlags2 = (LAYOUT_DIRECTION_DEFAULT << LAYOUT_DIRECTION_MASK_SHIFT) | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2954 | (TEXT_DIRECTION_DEFAULT << TEXT_DIRECTION_MASK_SHIFT) | |
| 2955 | (TEXT_ALIGNMENT_DEFAULT << TEXT_ALIGNMENT_MASK_SHIFT); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2956 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2957 | setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS); |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 2958 | mUserPaddingStart = -1; |
| 2959 | mUserPaddingEnd = -1; |
| 2960 | mUserPaddingRelative = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | /** |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 2964 | * Delegate for injecting accessiblity functionality. |
| 2965 | */ |
| 2966 | AccessibilityDelegate mAccessibilityDelegate; |
| 2967 | |
| 2968 | /** |
| 2969 | * Consistency verifier for debugging purposes. |
| 2970 | * @hide |
| 2971 | */ |
| 2972 | protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = |
| 2973 | InputEventConsistencyVerifier.isInstrumentationEnabled() ? |
| 2974 | new InputEventConsistencyVerifier(this, 0) : null; |
| 2975 | |
| 2976 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2977 | * Constructor that is called when inflating a view from XML. This is called |
| 2978 | * when a view is being constructed from an XML file, supplying attributes |
| 2979 | * that were specified in the XML file. This version uses a default style of |
| 2980 | * 0, so the only attribute values applied are those in the Context's Theme |
| 2981 | * and the given AttributeSet. |
| 2982 | * |
| 2983 | * <p> |
| 2984 | * The method onFinishInflate() will be called after all children have been |
| 2985 | * added. |
| 2986 | * |
| 2987 | * @param context The Context the view is running in, through which it can |
| 2988 | * access the current theme, resources, etc. |
| 2989 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 2990 | * @see #View(Context, AttributeSet, int) |
| 2991 | */ |
| 2992 | public View(Context context, AttributeSet attrs) { |
| 2993 | this(context, attrs, 0); |
| 2994 | } |
| 2995 | |
| 2996 | /** |
| 2997 | * Perform inflation from XML and apply a class-specific base style. This |
| 2998 | * constructor of View allows subclasses to use their own base style when |
| 2999 | * they are inflating. For example, a Button class's constructor would call |
| 3000 | * this version of the super class constructor and supply |
| 3001 | * <code>R.attr.buttonStyle</code> for <var>defStyle</var>; this allows |
| 3002 | * the theme's button style to modify all of the base view attributes (in |
| 3003 | * particular its background) as well as the Button class's attributes. |
| 3004 | * |
| 3005 | * @param context The Context the view is running in, through which it can |
| 3006 | * access the current theme, resources, etc. |
| 3007 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 3008 | * @param defStyle The default style to apply to this view. If 0, no style |
| 3009 | * will be applied (beyond what is included in the theme). This may |
| 3010 | * either be an attribute resource, whose value will be retrieved |
| 3011 | * from the current theme, or an explicit style resource. |
| 3012 | * @see #View(Context, AttributeSet) |
| 3013 | */ |
| 3014 | public View(Context context, AttributeSet attrs, int defStyle) { |
| 3015 | this(context); |
| 3016 | |
| 3017 | TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View, |
| 3018 | defStyle, 0); |
| 3019 | |
| 3020 | Drawable background = null; |
| 3021 | |
| 3022 | int leftPadding = -1; |
| 3023 | int topPadding = -1; |
| 3024 | int rightPadding = -1; |
| 3025 | int bottomPadding = -1; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3026 | int startPadding = -1; |
| 3027 | int endPadding = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3028 | |
| 3029 | int padding = -1; |
| 3030 | |
| 3031 | int viewFlagValues = 0; |
| 3032 | int viewFlagMasks = 0; |
| 3033 | |
| 3034 | boolean setScrollContainer = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3035 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3036 | int x = 0; |
| 3037 | int y = 0; |
| 3038 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3039 | float tx = 0; |
| 3040 | float ty = 0; |
| 3041 | float rotation = 0; |
| 3042 | float rotationX = 0; |
| 3043 | float rotationY = 0; |
| 3044 | float sx = 1f; |
| 3045 | float sy = 1f; |
| 3046 | boolean transformSet = false; |
| 3047 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3048 | int scrollbarStyle = SCROLLBARS_INSIDE_OVERLAY; |
| 3049 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3050 | int overScrollMode = mOverScrollMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3051 | final int N = a.getIndexCount(); |
| 3052 | for (int i = 0; i < N; i++) { |
| 3053 | int attr = a.getIndex(i); |
| 3054 | switch (attr) { |
| 3055 | case com.android.internal.R.styleable.View_background: |
| 3056 | background = a.getDrawable(attr); |
| 3057 | break; |
| 3058 | case com.android.internal.R.styleable.View_padding: |
| 3059 | padding = a.getDimensionPixelSize(attr, -1); |
| 3060 | break; |
| 3061 | case com.android.internal.R.styleable.View_paddingLeft: |
| 3062 | leftPadding = a.getDimensionPixelSize(attr, -1); |
| 3063 | break; |
| 3064 | case com.android.internal.R.styleable.View_paddingTop: |
| 3065 | topPadding = a.getDimensionPixelSize(attr, -1); |
| 3066 | break; |
| 3067 | case com.android.internal.R.styleable.View_paddingRight: |
| 3068 | rightPadding = a.getDimensionPixelSize(attr, -1); |
| 3069 | break; |
| 3070 | case com.android.internal.R.styleable.View_paddingBottom: |
| 3071 | bottomPadding = a.getDimensionPixelSize(attr, -1); |
| 3072 | break; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3073 | case com.android.internal.R.styleable.View_paddingStart: |
| 3074 | startPadding = a.getDimensionPixelSize(attr, -1); |
| 3075 | break; |
| 3076 | case com.android.internal.R.styleable.View_paddingEnd: |
| 3077 | endPadding = a.getDimensionPixelSize(attr, -1); |
| 3078 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3079 | case com.android.internal.R.styleable.View_scrollX: |
| 3080 | x = a.getDimensionPixelOffset(attr, 0); |
| 3081 | break; |
| 3082 | case com.android.internal.R.styleable.View_scrollY: |
| 3083 | y = a.getDimensionPixelOffset(attr, 0); |
| 3084 | break; |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3085 | case com.android.internal.R.styleable.View_alpha: |
| 3086 | setAlpha(a.getFloat(attr, 1f)); |
| 3087 | break; |
| 3088 | case com.android.internal.R.styleable.View_transformPivotX: |
| 3089 | setPivotX(a.getDimensionPixelOffset(attr, 0)); |
| 3090 | break; |
| 3091 | case com.android.internal.R.styleable.View_transformPivotY: |
| 3092 | setPivotY(a.getDimensionPixelOffset(attr, 0)); |
| 3093 | break; |
| 3094 | case com.android.internal.R.styleable.View_translationX: |
| 3095 | tx = a.getDimensionPixelOffset(attr, 0); |
| 3096 | transformSet = true; |
| 3097 | break; |
| 3098 | case com.android.internal.R.styleable.View_translationY: |
| 3099 | ty = a.getDimensionPixelOffset(attr, 0); |
| 3100 | transformSet = true; |
| 3101 | break; |
| 3102 | case com.android.internal.R.styleable.View_rotation: |
| 3103 | rotation = a.getFloat(attr, 0); |
| 3104 | transformSet = true; |
| 3105 | break; |
| 3106 | case com.android.internal.R.styleable.View_rotationX: |
| 3107 | rotationX = a.getFloat(attr, 0); |
| 3108 | transformSet = true; |
| 3109 | break; |
| 3110 | case com.android.internal.R.styleable.View_rotationY: |
| 3111 | rotationY = a.getFloat(attr, 0); |
| 3112 | transformSet = true; |
| 3113 | break; |
| 3114 | case com.android.internal.R.styleable.View_scaleX: |
| 3115 | sx = a.getFloat(attr, 1f); |
| 3116 | transformSet = true; |
| 3117 | break; |
| 3118 | case com.android.internal.R.styleable.View_scaleY: |
| 3119 | sy = a.getFloat(attr, 1f); |
| 3120 | transformSet = true; |
| 3121 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3122 | case com.android.internal.R.styleable.View_id: |
| 3123 | mID = a.getResourceId(attr, NO_ID); |
| 3124 | break; |
| 3125 | case com.android.internal.R.styleable.View_tag: |
| 3126 | mTag = a.getText(attr); |
| 3127 | break; |
| 3128 | case com.android.internal.R.styleable.View_fitsSystemWindows: |
| 3129 | if (a.getBoolean(attr, false)) { |
| 3130 | viewFlagValues |= FITS_SYSTEM_WINDOWS; |
| 3131 | viewFlagMasks |= FITS_SYSTEM_WINDOWS; |
| 3132 | } |
| 3133 | break; |
| 3134 | case com.android.internal.R.styleable.View_focusable: |
| 3135 | if (a.getBoolean(attr, false)) { |
| 3136 | viewFlagValues |= FOCUSABLE; |
| 3137 | viewFlagMasks |= FOCUSABLE_MASK; |
| 3138 | } |
| 3139 | break; |
| 3140 | case com.android.internal.R.styleable.View_focusableInTouchMode: |
| 3141 | if (a.getBoolean(attr, false)) { |
| 3142 | viewFlagValues |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE; |
| 3143 | viewFlagMasks |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE_MASK; |
| 3144 | } |
| 3145 | break; |
| 3146 | case com.android.internal.R.styleable.View_clickable: |
| 3147 | if (a.getBoolean(attr, false)) { |
| 3148 | viewFlagValues |= CLICKABLE; |
| 3149 | viewFlagMasks |= CLICKABLE; |
| 3150 | } |
| 3151 | break; |
| 3152 | case com.android.internal.R.styleable.View_longClickable: |
| 3153 | if (a.getBoolean(attr, false)) { |
| 3154 | viewFlagValues |= LONG_CLICKABLE; |
| 3155 | viewFlagMasks |= LONG_CLICKABLE; |
| 3156 | } |
| 3157 | break; |
| 3158 | case com.android.internal.R.styleable.View_saveEnabled: |
| 3159 | if (!a.getBoolean(attr, true)) { |
| 3160 | viewFlagValues |= SAVE_DISABLED; |
| 3161 | viewFlagMasks |= SAVE_DISABLED_MASK; |
| 3162 | } |
| 3163 | break; |
| 3164 | case com.android.internal.R.styleable.View_duplicateParentState: |
| 3165 | if (a.getBoolean(attr, false)) { |
| 3166 | viewFlagValues |= DUPLICATE_PARENT_STATE; |
| 3167 | viewFlagMasks |= DUPLICATE_PARENT_STATE; |
| 3168 | } |
| 3169 | break; |
| 3170 | case com.android.internal.R.styleable.View_visibility: |
| 3171 | final int visibility = a.getInt(attr, 0); |
| 3172 | if (visibility != 0) { |
| 3173 | viewFlagValues |= VISIBILITY_FLAGS[visibility]; |
| 3174 | viewFlagMasks |= VISIBILITY_MASK; |
| 3175 | } |
| 3176 | break; |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 3177 | case com.android.internal.R.styleable.View_layoutDirection: |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3178 | // Clear any layout direction flags (included resolved bits) already set |
| 3179 | mPrivateFlags2 &= ~(LAYOUT_DIRECTION_MASK | LAYOUT_DIRECTION_RESOLVED_MASK); |
| 3180 | // 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] | 3181 | final int layoutDirection = a.getInt(attr, -1); |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3182 | final int value = (layoutDirection != -1) ? |
| 3183 | LAYOUT_DIRECTION_FLAGS[layoutDirection] : LAYOUT_DIRECTION_DEFAULT; |
| 3184 | mPrivateFlags2 |= (value << LAYOUT_DIRECTION_MASK_SHIFT); |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 3185 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3186 | case com.android.internal.R.styleable.View_drawingCacheQuality: |
| 3187 | final int cacheQuality = a.getInt(attr, 0); |
| 3188 | if (cacheQuality != 0) { |
| 3189 | viewFlagValues |= DRAWING_CACHE_QUALITY_FLAGS[cacheQuality]; |
| 3190 | viewFlagMasks |= DRAWING_CACHE_QUALITY_MASK; |
| 3191 | } |
| 3192 | break; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3193 | case com.android.internal.R.styleable.View_contentDescription: |
| 3194 | mContentDescription = a.getString(attr); |
| 3195 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3196 | case com.android.internal.R.styleable.View_soundEffectsEnabled: |
| 3197 | if (!a.getBoolean(attr, true)) { |
| 3198 | viewFlagValues &= ~SOUND_EFFECTS_ENABLED; |
| 3199 | viewFlagMasks |= SOUND_EFFECTS_ENABLED; |
| 3200 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 3201 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3202 | case com.android.internal.R.styleable.View_hapticFeedbackEnabled: |
| 3203 | if (!a.getBoolean(attr, true)) { |
| 3204 | viewFlagValues &= ~HAPTIC_FEEDBACK_ENABLED; |
| 3205 | viewFlagMasks |= HAPTIC_FEEDBACK_ENABLED; |
| 3206 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 3207 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3208 | case R.styleable.View_scrollbars: |
| 3209 | final int scrollbars = a.getInt(attr, SCROLLBARS_NONE); |
| 3210 | if (scrollbars != SCROLLBARS_NONE) { |
| 3211 | viewFlagValues |= scrollbars; |
| 3212 | viewFlagMasks |= SCROLLBARS_MASK; |
| 3213 | initializeScrollbars(a); |
| 3214 | } |
| 3215 | break; |
Romain Guy | 2a9fa89 | 2011-09-28 16:50:02 -0700 | [diff] [blame] | 3216 | //noinspection deprecation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3217 | case R.styleable.View_fadingEdge: |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 3218 | if (context.getApplicationInfo().targetSdkVersion >= ICE_CREAM_SANDWICH) { |
| 3219 | // Ignore the attribute starting with ICS |
| 3220 | break; |
| 3221 | } |
| 3222 | // With builds < ICS, fall through and apply fading edges |
| 3223 | case R.styleable.View_requiresFadingEdge: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3224 | final int fadingEdge = a.getInt(attr, FADING_EDGE_NONE); |
| 3225 | if (fadingEdge != FADING_EDGE_NONE) { |
| 3226 | viewFlagValues |= fadingEdge; |
| 3227 | viewFlagMasks |= FADING_EDGE_MASK; |
| 3228 | initializeFadingEdge(a); |
| 3229 | } |
| 3230 | break; |
| 3231 | case R.styleable.View_scrollbarStyle: |
| 3232 | scrollbarStyle = a.getInt(attr, SCROLLBARS_INSIDE_OVERLAY); |
| 3233 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3234 | viewFlagValues |= scrollbarStyle & SCROLLBARS_STYLE_MASK; |
| 3235 | viewFlagMasks |= SCROLLBARS_STYLE_MASK; |
| 3236 | } |
| 3237 | break; |
| 3238 | case R.styleable.View_isScrollContainer: |
| 3239 | setScrollContainer = true; |
| 3240 | if (a.getBoolean(attr, false)) { |
| 3241 | setScrollContainer(true); |
| 3242 | } |
| 3243 | break; |
| 3244 | case com.android.internal.R.styleable.View_keepScreenOn: |
| 3245 | if (a.getBoolean(attr, false)) { |
| 3246 | viewFlagValues |= KEEP_SCREEN_ON; |
| 3247 | viewFlagMasks |= KEEP_SCREEN_ON; |
| 3248 | } |
| 3249 | break; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 3250 | case R.styleable.View_filterTouchesWhenObscured: |
| 3251 | if (a.getBoolean(attr, false)) { |
| 3252 | viewFlagValues |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3253 | viewFlagMasks |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3254 | } |
| 3255 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3256 | case R.styleable.View_nextFocusLeft: |
| 3257 | mNextFocusLeftId = a.getResourceId(attr, View.NO_ID); |
| 3258 | break; |
| 3259 | case R.styleable.View_nextFocusRight: |
| 3260 | mNextFocusRightId = a.getResourceId(attr, View.NO_ID); |
| 3261 | break; |
| 3262 | case R.styleable.View_nextFocusUp: |
| 3263 | mNextFocusUpId = a.getResourceId(attr, View.NO_ID); |
| 3264 | break; |
| 3265 | case R.styleable.View_nextFocusDown: |
| 3266 | mNextFocusDownId = a.getResourceId(attr, View.NO_ID); |
| 3267 | break; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 3268 | case R.styleable.View_nextFocusForward: |
| 3269 | mNextFocusForwardId = a.getResourceId(attr, View.NO_ID); |
| 3270 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3271 | case R.styleable.View_minWidth: |
| 3272 | mMinWidth = a.getDimensionPixelSize(attr, 0); |
| 3273 | break; |
| 3274 | case R.styleable.View_minHeight: |
| 3275 | mMinHeight = a.getDimensionPixelSize(attr, 0); |
| 3276 | break; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3277 | case R.styleable.View_onClick: |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3278 | if (context.isRestricted()) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3279 | throw new IllegalStateException("The android:onClick attribute cannot " |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3280 | + "be used within a restricted context"); |
| 3281 | } |
| 3282 | |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3283 | final String handlerName = a.getString(attr); |
| 3284 | if (handlerName != null) { |
| 3285 | setOnClickListener(new OnClickListener() { |
| 3286 | private Method mHandler; |
| 3287 | |
| 3288 | public void onClick(View v) { |
| 3289 | if (mHandler == null) { |
| 3290 | try { |
| 3291 | mHandler = getContext().getClass().getMethod(handlerName, |
| 3292 | View.class); |
| 3293 | } catch (NoSuchMethodException e) { |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3294 | int id = getId(); |
| 3295 | String idText = id == NO_ID ? "" : " with id '" |
| 3296 | + getContext().getResources().getResourceEntryName( |
| 3297 | id) + "'"; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3298 | throw new IllegalStateException("Could not find a method " + |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3299 | handlerName + "(View) in the activity " |
| 3300 | + getContext().getClass() + " for onClick handler" |
| 3301 | + " on view " + View.this.getClass() + idText, e); |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3302 | } |
| 3303 | } |
| 3304 | |
| 3305 | try { |
| 3306 | mHandler.invoke(getContext(), View.this); |
| 3307 | } catch (IllegalAccessException e) { |
| 3308 | throw new IllegalStateException("Could not execute non " |
| 3309 | + "public method of the activity", e); |
| 3310 | } catch (InvocationTargetException e) { |
| 3311 | throw new IllegalStateException("Could not execute " |
| 3312 | + "method of the activity", e); |
| 3313 | } |
| 3314 | } |
| 3315 | }); |
| 3316 | } |
| 3317 | break; |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3318 | case R.styleable.View_overScrollMode: |
| 3319 | overScrollMode = a.getInt(attr, OVER_SCROLL_IF_CONTENT_SCROLLS); |
| 3320 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3321 | case R.styleable.View_verticalScrollbarPosition: |
| 3322 | mVerticalScrollbarPosition = a.getInt(attr, SCROLLBAR_POSITION_DEFAULT); |
| 3323 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3324 | case R.styleable.View_layerType: |
| 3325 | setLayerType(a.getInt(attr, LAYER_TYPE_NONE), null); |
| 3326 | break; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3327 | case R.styleable.View_textDirection: |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3328 | // Clear any text direction flag already set |
| 3329 | mPrivateFlags2 &= ~TEXT_DIRECTION_MASK; |
| 3330 | // Set the text direction flags depending on the value of the attribute |
| 3331 | final int textDirection = a.getInt(attr, -1); |
| 3332 | if (textDirection != -1) { |
| 3333 | mPrivateFlags2 |= TEXT_DIRECTION_FLAGS[textDirection]; |
| 3334 | } |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3335 | break; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3336 | case R.styleable.View_textAlignment: |
| 3337 | // Clear any text alignment flag already set |
| 3338 | mPrivateFlags2 &= ~TEXT_ALIGNMENT_MASK; |
| 3339 | // Set the text alignment flag depending on the value of the attribute |
| 3340 | final int textAlignment = a.getInt(attr, TEXT_ALIGNMENT_DEFAULT); |
| 3341 | mPrivateFlags2 |= TEXT_ALIGNMENT_FLAGS[textAlignment]; |
| 3342 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | } |
| 3344 | } |
| 3345 | |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 3346 | a.recycle(); |
| 3347 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3348 | setOverScrollMode(overScrollMode); |
| 3349 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3350 | if (background != null) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 3351 | setBackground(background); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3352 | } |
| 3353 | |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 3354 | // Cache user padding as we cannot fully resolve padding here (we dont have yet the resolved |
| 3355 | // layout direction). Those cached values will be used later during padding resolution. |
| 3356 | mUserPaddingStart = startPadding; |
| 3357 | mUserPaddingEnd = endPadding; |
| 3358 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 3359 | updateUserPaddingRelative(); |
| 3360 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3361 | if (padding >= 0) { |
| 3362 | leftPadding = padding; |
| 3363 | topPadding = padding; |
| 3364 | rightPadding = padding; |
| 3365 | bottomPadding = padding; |
| 3366 | } |
| 3367 | |
| 3368 | // If the user specified the padding (either with android:padding or |
| 3369 | // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise |
| 3370 | // use the default padding or the padding from the background drawable |
| 3371 | // (stored at this point in mPadding*) |
| 3372 | setPadding(leftPadding >= 0 ? leftPadding : mPaddingLeft, |
| 3373 | topPadding >= 0 ? topPadding : mPaddingTop, |
| 3374 | rightPadding >= 0 ? rightPadding : mPaddingRight, |
| 3375 | bottomPadding >= 0 ? bottomPadding : mPaddingBottom); |
| 3376 | |
| 3377 | if (viewFlagMasks != 0) { |
| 3378 | setFlags(viewFlagValues, viewFlagMasks); |
| 3379 | } |
| 3380 | |
| 3381 | // Needs to be called after mViewFlags is set |
| 3382 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3383 | recomputePadding(); |
| 3384 | } |
| 3385 | |
| 3386 | if (x != 0 || y != 0) { |
| 3387 | scrollTo(x, y); |
| 3388 | } |
| 3389 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3390 | if (transformSet) { |
| 3391 | setTranslationX(tx); |
| 3392 | setTranslationY(ty); |
| 3393 | setRotation(rotation); |
| 3394 | setRotationX(rotationX); |
| 3395 | setRotationY(rotationY); |
| 3396 | setScaleX(sx); |
| 3397 | setScaleY(sy); |
| 3398 | } |
| 3399 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3400 | if (!setScrollContainer && (viewFlagValues&SCROLLBARS_VERTICAL) != 0) { |
| 3401 | setScrollContainer(true); |
| 3402 | } |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 3403 | |
| 3404 | computeOpaqueFlags(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3405 | } |
| 3406 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 3407 | private void updateUserPaddingRelative() { |
| 3408 | mUserPaddingRelative = (mUserPaddingStart >= 0 || mUserPaddingEnd >= 0); |
| 3409 | } |
| 3410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3411 | /** |
| 3412 | * Non-public constructor for use in testing |
| 3413 | */ |
| 3414 | View() { |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 3415 | mResources = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3416 | } |
| 3417 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3418 | /** |
| 3419 | * <p> |
| 3420 | * Initializes the fading edges from a given set of styled attributes. This |
| 3421 | * method should be called by subclasses that need fading edges and when an |
| 3422 | * instance of these subclasses is created programmatically rather than |
| 3423 | * being inflated from XML. This method is automatically called when the XML |
| 3424 | * is inflated. |
| 3425 | * </p> |
| 3426 | * |
| 3427 | * @param a the styled attributes set to initialize the fading edges from |
| 3428 | */ |
| 3429 | protected void initializeFadingEdge(TypedArray a) { |
| 3430 | initScrollCache(); |
| 3431 | |
| 3432 | mScrollCache.fadingEdgeLength = a.getDimensionPixelSize( |
| 3433 | R.styleable.View_fadingEdgeLength, |
| 3434 | ViewConfiguration.get(mContext).getScaledFadingEdgeLength()); |
| 3435 | } |
| 3436 | |
| 3437 | /** |
| 3438 | * Returns the size of the vertical faded edges used to indicate that more |
| 3439 | * content in this view is visible. |
| 3440 | * |
| 3441 | * @return The size in pixels of the vertical faded edge or 0 if vertical |
| 3442 | * faded edges are not enabled for this view. |
| 3443 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3444 | */ |
| 3445 | public int getVerticalFadingEdgeLength() { |
| 3446 | if (isVerticalFadingEdgeEnabled()) { |
| 3447 | ScrollabilityCache cache = mScrollCache; |
| 3448 | if (cache != null) { |
| 3449 | return cache.fadingEdgeLength; |
| 3450 | } |
| 3451 | } |
| 3452 | return 0; |
| 3453 | } |
| 3454 | |
| 3455 | /** |
| 3456 | * Set the size of the faded edge used to indicate that more content in this |
| 3457 | * 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] | 3458 | * {@link #setVerticalFadingEdgeEnabled(boolean)} or |
| 3459 | * {@link #setHorizontalFadingEdgeEnabled(boolean)} to enable the fading edge |
| 3460 | * for the vertical or horizontal fading edges. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3461 | * |
| 3462 | * @param length The size in pixels of the faded edge used to indicate that more |
| 3463 | * content in this view is visible. |
| 3464 | */ |
| 3465 | public void setFadingEdgeLength(int length) { |
| 3466 | initScrollCache(); |
| 3467 | mScrollCache.fadingEdgeLength = length; |
| 3468 | } |
| 3469 | |
| 3470 | /** |
| 3471 | * Returns the size of the horizontal faded edges used to indicate that more |
| 3472 | * content in this view is visible. |
| 3473 | * |
| 3474 | * @return The size in pixels of the horizontal faded edge or 0 if horizontal |
| 3475 | * faded edges are not enabled for this view. |
| 3476 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3477 | */ |
| 3478 | public int getHorizontalFadingEdgeLength() { |
| 3479 | if (isHorizontalFadingEdgeEnabled()) { |
| 3480 | ScrollabilityCache cache = mScrollCache; |
| 3481 | if (cache != null) { |
| 3482 | return cache.fadingEdgeLength; |
| 3483 | } |
| 3484 | } |
| 3485 | return 0; |
| 3486 | } |
| 3487 | |
| 3488 | /** |
| 3489 | * Returns the width of the vertical scrollbar. |
| 3490 | * |
| 3491 | * @return The width in pixels of the vertical scrollbar or 0 if there |
| 3492 | * is no vertical scrollbar. |
| 3493 | */ |
| 3494 | public int getVerticalScrollbarWidth() { |
| 3495 | ScrollabilityCache cache = mScrollCache; |
| 3496 | if (cache != null) { |
| 3497 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3498 | if (scrollBar != null) { |
| 3499 | int size = scrollBar.getSize(true); |
| 3500 | if (size <= 0) { |
| 3501 | size = cache.scrollBarSize; |
| 3502 | } |
| 3503 | return size; |
| 3504 | } |
| 3505 | return 0; |
| 3506 | } |
| 3507 | return 0; |
| 3508 | } |
| 3509 | |
| 3510 | /** |
| 3511 | * Returns the height of the horizontal scrollbar. |
| 3512 | * |
| 3513 | * @return The height in pixels of the horizontal scrollbar or 0 if |
| 3514 | * there is no horizontal scrollbar. |
| 3515 | */ |
| 3516 | protected int getHorizontalScrollbarHeight() { |
| 3517 | ScrollabilityCache cache = mScrollCache; |
| 3518 | if (cache != null) { |
| 3519 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3520 | if (scrollBar != null) { |
| 3521 | int size = scrollBar.getSize(false); |
| 3522 | if (size <= 0) { |
| 3523 | size = cache.scrollBarSize; |
| 3524 | } |
| 3525 | return size; |
| 3526 | } |
| 3527 | return 0; |
| 3528 | } |
| 3529 | return 0; |
| 3530 | } |
| 3531 | |
| 3532 | /** |
| 3533 | * <p> |
| 3534 | * Initializes the scrollbars from a given set of styled attributes. This |
| 3535 | * method should be called by subclasses that need scrollbars and when an |
| 3536 | * instance of these subclasses is created programmatically rather than |
| 3537 | * being inflated from XML. This method is automatically called when the XML |
| 3538 | * is inflated. |
| 3539 | * </p> |
| 3540 | * |
| 3541 | * @param a the styled attributes set to initialize the scrollbars from |
| 3542 | */ |
| 3543 | protected void initializeScrollbars(TypedArray a) { |
| 3544 | initScrollCache(); |
| 3545 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3546 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3547 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3548 | if (scrollabilityCache.scrollBar == null) { |
| 3549 | scrollabilityCache.scrollBar = new ScrollBarDrawable(); |
| 3550 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3551 | |
Romain Guy | 8bda248 | 2010-03-02 11:42:11 -0800 | [diff] [blame] | 3552 | 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] | 3553 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3554 | if (!fadeScrollbars) { |
| 3555 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 3556 | } |
| 3557 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3558 | |
| 3559 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3560 | scrollabilityCache.scrollBarFadeDuration = a.getInt( |
| 3561 | R.styleable.View_scrollbarFadeDuration, ViewConfiguration |
| 3562 | .getScrollBarFadeDuration()); |
| 3563 | scrollabilityCache.scrollBarDefaultDelayBeforeFade = a.getInt( |
| 3564 | R.styleable.View_scrollbarDefaultDelayBeforeFade, |
| 3565 | ViewConfiguration.getScrollDefaultDelay()); |
| 3566 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3568 | scrollabilityCache.scrollBarSize = a.getDimensionPixelSize( |
| 3569 | com.android.internal.R.styleable.View_scrollbarSize, |
| 3570 | ViewConfiguration.get(mContext).getScaledScrollBarSize()); |
| 3571 | |
| 3572 | Drawable track = a.getDrawable(R.styleable.View_scrollbarTrackHorizontal); |
| 3573 | scrollabilityCache.scrollBar.setHorizontalTrackDrawable(track); |
| 3574 | |
| 3575 | Drawable thumb = a.getDrawable(R.styleable.View_scrollbarThumbHorizontal); |
| 3576 | if (thumb != null) { |
| 3577 | scrollabilityCache.scrollBar.setHorizontalThumbDrawable(thumb); |
| 3578 | } |
| 3579 | |
| 3580 | boolean alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawHorizontalTrack, |
| 3581 | false); |
| 3582 | if (alwaysDraw) { |
| 3583 | scrollabilityCache.scrollBar.setAlwaysDrawHorizontalTrack(true); |
| 3584 | } |
| 3585 | |
| 3586 | track = a.getDrawable(R.styleable.View_scrollbarTrackVertical); |
| 3587 | scrollabilityCache.scrollBar.setVerticalTrackDrawable(track); |
| 3588 | |
| 3589 | thumb = a.getDrawable(R.styleable.View_scrollbarThumbVertical); |
| 3590 | if (thumb != null) { |
| 3591 | scrollabilityCache.scrollBar.setVerticalThumbDrawable(thumb); |
| 3592 | } |
| 3593 | |
| 3594 | alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawVerticalTrack, |
| 3595 | false); |
| 3596 | if (alwaysDraw) { |
| 3597 | scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true); |
| 3598 | } |
| 3599 | |
| 3600 | // Re-apply user/background padding so that scrollbar(s) get added |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3601 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3602 | } |
| 3603 | |
| 3604 | /** |
| 3605 | * <p> |
| 3606 | * Initalizes the scrollability cache if necessary. |
| 3607 | * </p> |
| 3608 | */ |
| 3609 | private void initScrollCache() { |
| 3610 | if (mScrollCache == null) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3611 | mScrollCache = new ScrollabilityCache(ViewConfiguration.get(mContext), this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3612 | } |
| 3613 | } |
| 3614 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 3615 | private ScrollabilityCache getScrollCache() { |
| 3616 | initScrollCache(); |
| 3617 | return mScrollCache; |
| 3618 | } |
| 3619 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3620 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3621 | * Set the position of the vertical scroll bar. Should be one of |
| 3622 | * {@link #SCROLLBAR_POSITION_DEFAULT}, {@link #SCROLLBAR_POSITION_LEFT} or |
| 3623 | * {@link #SCROLLBAR_POSITION_RIGHT}. |
| 3624 | * |
| 3625 | * @param position Where the vertical scroll bar should be positioned. |
| 3626 | */ |
| 3627 | public void setVerticalScrollbarPosition(int position) { |
| 3628 | if (mVerticalScrollbarPosition != position) { |
| 3629 | mVerticalScrollbarPosition = position; |
| 3630 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3631 | resolvePadding(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3632 | } |
| 3633 | } |
| 3634 | |
| 3635 | /** |
| 3636 | * @return The position where the vertical scroll bar will show, if applicable. |
| 3637 | * @see #setVerticalScrollbarPosition(int) |
| 3638 | */ |
| 3639 | public int getVerticalScrollbarPosition() { |
| 3640 | return mVerticalScrollbarPosition; |
| 3641 | } |
| 3642 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3643 | ListenerInfo getListenerInfo() { |
| 3644 | if (mListenerInfo != null) { |
| 3645 | return mListenerInfo; |
| 3646 | } |
| 3647 | mListenerInfo = new ListenerInfo(); |
| 3648 | return mListenerInfo; |
| 3649 | } |
| 3650 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3651 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3652 | * Register a callback to be invoked when focus of this view changed. |
| 3653 | * |
| 3654 | * @param l The callback that will run. |
| 3655 | */ |
| 3656 | public void setOnFocusChangeListener(OnFocusChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3657 | getListenerInfo().mOnFocusChangeListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3661 | * Add a listener that will be called when the bounds of the view change due to |
| 3662 | * layout processing. |
| 3663 | * |
| 3664 | * @param listener The listener that will be called when layout bounds change. |
| 3665 | */ |
| 3666 | public void addOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3667 | ListenerInfo li = getListenerInfo(); |
| 3668 | if (li.mOnLayoutChangeListeners == null) { |
| 3669 | li.mOnLayoutChangeListeners = new ArrayList<OnLayoutChangeListener>(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3670 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3671 | if (!li.mOnLayoutChangeListeners.contains(listener)) { |
| 3672 | li.mOnLayoutChangeListeners.add(listener); |
Chet Haase | 1a76dcd | 2011-10-06 11:16:40 -0700 | [diff] [blame] | 3673 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3674 | } |
| 3675 | |
| 3676 | /** |
| 3677 | * Remove a listener for layout changes. |
| 3678 | * |
| 3679 | * @param listener The listener for layout bounds change. |
| 3680 | */ |
| 3681 | public void removeOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3682 | ListenerInfo li = mListenerInfo; |
| 3683 | if (li == null || li.mOnLayoutChangeListeners == null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3684 | return; |
| 3685 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3686 | li.mOnLayoutChangeListeners.remove(listener); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | /** |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3690 | * Add a listener for attach state changes. |
| 3691 | * |
| 3692 | * This listener will be called whenever this view is attached or detached |
| 3693 | * from a window. Remove the listener using |
| 3694 | * {@link #removeOnAttachStateChangeListener(OnAttachStateChangeListener)}. |
| 3695 | * |
| 3696 | * @param listener Listener to attach |
| 3697 | * @see #removeOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 3698 | */ |
| 3699 | public void addOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3700 | ListenerInfo li = getListenerInfo(); |
| 3701 | if (li.mOnAttachStateChangeListeners == null) { |
| 3702 | li.mOnAttachStateChangeListeners |
| 3703 | = new CopyOnWriteArrayList<OnAttachStateChangeListener>(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3704 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3705 | li.mOnAttachStateChangeListeners.add(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3706 | } |
| 3707 | |
| 3708 | /** |
| 3709 | * Remove a listener for attach state changes. The listener will receive no further |
| 3710 | * notification of window attach/detach events. |
| 3711 | * |
| 3712 | * @param listener Listener to remove |
| 3713 | * @see #addOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 3714 | */ |
| 3715 | public void removeOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3716 | ListenerInfo li = mListenerInfo; |
| 3717 | if (li == null || li.mOnAttachStateChangeListeners == null) { |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3718 | return; |
| 3719 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3720 | li.mOnAttachStateChangeListeners.remove(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3721 | } |
| 3722 | |
| 3723 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3724 | * Returns the focus-change callback registered for this view. |
| 3725 | * |
| 3726 | * @return The callback, or null if one is not registered. |
| 3727 | */ |
| 3728 | public OnFocusChangeListener getOnFocusChangeListener() { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3729 | ListenerInfo li = mListenerInfo; |
| 3730 | return li != null ? li.mOnFocusChangeListener : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3731 | } |
| 3732 | |
| 3733 | /** |
| 3734 | * Register a callback to be invoked when this view is clicked. If this view is not |
| 3735 | * clickable, it becomes clickable. |
| 3736 | * |
| 3737 | * @param l The callback that will run |
| 3738 | * |
| 3739 | * @see #setClickable(boolean) |
| 3740 | */ |
| 3741 | public void setOnClickListener(OnClickListener l) { |
| 3742 | if (!isClickable()) { |
| 3743 | setClickable(true); |
| 3744 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3745 | getListenerInfo().mOnClickListener = l; |
| 3746 | } |
| 3747 | |
| 3748 | /** |
| 3749 | * Return whether this view has an attached OnClickListener. Returns |
| 3750 | * true if there is a listener, false if there is none. |
| 3751 | */ |
| 3752 | public boolean hasOnClickListeners() { |
| 3753 | ListenerInfo li = mListenerInfo; |
| 3754 | return (li != null && li.mOnClickListener != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | /** |
| 3758 | * Register a callback to be invoked when this view is clicked and held. If this view is not |
| 3759 | * long clickable, it becomes long clickable. |
| 3760 | * |
| 3761 | * @param l The callback that will run |
| 3762 | * |
| 3763 | * @see #setLongClickable(boolean) |
| 3764 | */ |
| 3765 | public void setOnLongClickListener(OnLongClickListener l) { |
| 3766 | if (!isLongClickable()) { |
| 3767 | setLongClickable(true); |
| 3768 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3769 | getListenerInfo().mOnLongClickListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3770 | } |
| 3771 | |
| 3772 | /** |
| 3773 | * Register a callback to be invoked when the context menu for this view is |
| 3774 | * being built. If this view is not long clickable, it becomes long clickable. |
| 3775 | * |
| 3776 | * @param l The callback that will run |
| 3777 | * |
| 3778 | */ |
| 3779 | public void setOnCreateContextMenuListener(OnCreateContextMenuListener l) { |
| 3780 | if (!isLongClickable()) { |
| 3781 | setLongClickable(true); |
| 3782 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3783 | getListenerInfo().mOnCreateContextMenuListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3787 | * Call this view's OnClickListener, if it is defined. Performs all normal |
| 3788 | * actions associated with clicking: reporting accessibility event, playing |
| 3789 | * a sound, etc. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3790 | * |
| 3791 | * @return True there was an assigned OnClickListener that was called, false |
| 3792 | * otherwise is returned. |
| 3793 | */ |
| 3794 | public boolean performClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3795 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); |
| 3796 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3797 | ListenerInfo li = mListenerInfo; |
| 3798 | if (li != null && li.mOnClickListener != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3799 | playSoundEffect(SoundEffectConstants.CLICK); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3800 | li.mOnClickListener.onClick(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3801 | return true; |
| 3802 | } |
| 3803 | |
| 3804 | return false; |
| 3805 | } |
| 3806 | |
| 3807 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3808 | * Directly call any attached OnClickListener. Unlike {@link #performClick()}, |
| 3809 | * this only calls the listener, and does not do any associated clicking |
| 3810 | * actions like reporting an accessibility event. |
| 3811 | * |
| 3812 | * @return True there was an assigned OnClickListener that was called, false |
| 3813 | * otherwise is returned. |
| 3814 | */ |
| 3815 | public boolean callOnClick() { |
| 3816 | ListenerInfo li = mListenerInfo; |
| 3817 | if (li != null && li.mOnClickListener != null) { |
| 3818 | li.mOnClickListener.onClick(this); |
| 3819 | return true; |
| 3820 | } |
| 3821 | return false; |
| 3822 | } |
| 3823 | |
| 3824 | /** |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 3825 | * Call this view's OnLongClickListener, if it is defined. Invokes the context menu if the |
| 3826 | * OnLongClickListener did not consume the event. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3827 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 3828 | * @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] | 3829 | */ |
| 3830 | public boolean performLongClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3831 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); |
| 3832 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3833 | boolean handled = false; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3834 | ListenerInfo li = mListenerInfo; |
| 3835 | if (li != null && li.mOnLongClickListener != null) { |
| 3836 | handled = li.mOnLongClickListener.onLongClick(View.this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3837 | } |
| 3838 | if (!handled) { |
| 3839 | handled = showContextMenu(); |
| 3840 | } |
| 3841 | if (handled) { |
| 3842 | performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); |
| 3843 | } |
| 3844 | return handled; |
| 3845 | } |
| 3846 | |
| 3847 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3848 | * Performs button-related actions during a touch down event. |
| 3849 | * |
| 3850 | * @param event The event. |
| 3851 | * @return True if the down was consumed. |
| 3852 | * |
| 3853 | * @hide |
| 3854 | */ |
| 3855 | protected boolean performButtonActionOnTouchDown(MotionEvent event) { |
| 3856 | if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) { |
| 3857 | if (showContextMenu(event.getX(), event.getY(), event.getMetaState())) { |
| 3858 | return true; |
| 3859 | } |
| 3860 | } |
| 3861 | return false; |
| 3862 | } |
| 3863 | |
| 3864 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3865 | * Bring up the context menu for this view. |
| 3866 | * |
| 3867 | * @return Whether a context menu was displayed. |
| 3868 | */ |
| 3869 | public boolean showContextMenu() { |
| 3870 | return getParent().showContextMenuForChild(this); |
| 3871 | } |
| 3872 | |
| 3873 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3874 | * Bring up the context menu for this view, referring to the item under the specified point. |
| 3875 | * |
| 3876 | * @param x The referenced x coordinate. |
| 3877 | * @param y The referenced y coordinate. |
| 3878 | * @param metaState The keyboard modifiers that were pressed. |
| 3879 | * @return Whether a context menu was displayed. |
| 3880 | * |
| 3881 | * @hide |
| 3882 | */ |
| 3883 | public boolean showContextMenu(float x, float y, int metaState) { |
| 3884 | return showContextMenu(); |
| 3885 | } |
| 3886 | |
| 3887 | /** |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 3888 | * Start an action mode. |
| 3889 | * |
| 3890 | * @param callback Callback that will control the lifecycle of the action mode |
| 3891 | * @return The new action mode if it is started, null otherwise |
| 3892 | * |
| 3893 | * @see ActionMode |
| 3894 | */ |
| 3895 | public ActionMode startActionMode(ActionMode.Callback callback) { |
John Reck | 5160e2a | 2012-02-22 09:35:12 -0800 | [diff] [blame] | 3896 | ViewParent parent = getParent(); |
| 3897 | if (parent == null) return null; |
| 3898 | return parent.startActionModeForChild(this, callback); |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 3899 | } |
| 3900 | |
| 3901 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3902 | * Register a callback to be invoked when a key is pressed in this view. |
| 3903 | * @param l the key listener to attach to this view |
| 3904 | */ |
| 3905 | public void setOnKeyListener(OnKeyListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3906 | getListenerInfo().mOnKeyListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3907 | } |
| 3908 | |
| 3909 | /** |
| 3910 | * Register a callback to be invoked when a touch event is sent to this view. |
| 3911 | * @param l the touch listener to attach to this view |
| 3912 | */ |
| 3913 | public void setOnTouchListener(OnTouchListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3914 | getListenerInfo().mOnTouchListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3915 | } |
| 3916 | |
| 3917 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3918 | * Register a callback to be invoked when a generic motion event is sent to this view. |
| 3919 | * @param l the generic motion listener to attach to this view |
| 3920 | */ |
| 3921 | public void setOnGenericMotionListener(OnGenericMotionListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3922 | getListenerInfo().mOnGenericMotionListener = l; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3923 | } |
| 3924 | |
| 3925 | /** |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 3926 | * Register a callback to be invoked when a hover event is sent to this view. |
| 3927 | * @param l the hover listener to attach to this view |
| 3928 | */ |
| 3929 | public void setOnHoverListener(OnHoverListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3930 | getListenerInfo().mOnHoverListener = l; |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 3931 | } |
| 3932 | |
| 3933 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3934 | * Register a drag event listener callback object for this View. The parameter is |
| 3935 | * an implementation of {@link android.view.View.OnDragListener}. To send a drag event to a |
| 3936 | * View, the system calls the |
| 3937 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent)} method. |
| 3938 | * @param l An implementation of {@link android.view.View.OnDragListener}. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 3939 | */ |
| 3940 | public void setOnDragListener(OnDragListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3941 | getListenerInfo().mOnDragListener = l; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 3942 | } |
| 3943 | |
| 3944 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 3945 | * Give this view focus. This will cause |
| 3946 | * {@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] | 3947 | * |
| 3948 | * Note: this does not check whether this {@link View} should get focus, it just |
| 3949 | * gives it focus no matter what. It should only be called internally by framework |
| 3950 | * code that knows what it is doing, namely {@link #requestFocus(int, Rect)}. |
| 3951 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 3952 | * @param direction values are {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN}, |
| 3953 | * {@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] | 3954 | * focus moved when requestFocus() is called. It may not always |
| 3955 | * apply, in which case use the default View.FOCUS_DOWN. |
| 3956 | * @param previouslyFocusedRect The rectangle of the view that had focus |
| 3957 | * prior in this View's coordinate system. |
| 3958 | */ |
| 3959 | void handleFocusGainInternal(int direction, Rect previouslyFocusedRect) { |
| 3960 | if (DBG) { |
| 3961 | System.out.println(this + " requestFocus()"); |
| 3962 | } |
| 3963 | |
| 3964 | if ((mPrivateFlags & FOCUSED) == 0) { |
| 3965 | mPrivateFlags |= FOCUSED; |
| 3966 | |
| 3967 | if (mParent != null) { |
| 3968 | mParent.requestChildFocus(this, this); |
| 3969 | } |
| 3970 | |
| 3971 | onFocusChanged(true, direction, previouslyFocusedRect); |
| 3972 | refreshDrawableState(); |
| 3973 | } |
| 3974 | } |
| 3975 | |
| 3976 | /** |
| 3977 | * Request that a rectangle of this view be visible on the screen, |
| 3978 | * scrolling if necessary just enough. |
| 3979 | * |
| 3980 | * <p>A View should call this if it maintains some notion of which part |
| 3981 | * of its content is interesting. For example, a text editing view |
| 3982 | * should call this when its cursor moves. |
| 3983 | * |
| 3984 | * @param rectangle The rectangle. |
| 3985 | * @return Whether any parent scrolled. |
| 3986 | */ |
| 3987 | public boolean requestRectangleOnScreen(Rect rectangle) { |
| 3988 | return requestRectangleOnScreen(rectangle, false); |
| 3989 | } |
| 3990 | |
| 3991 | /** |
| 3992 | * Request that a rectangle of this view be visible on the screen, |
| 3993 | * scrolling if necessary just enough. |
| 3994 | * |
| 3995 | * <p>A View should call this if it maintains some notion of which part |
| 3996 | * of its content is interesting. For example, a text editing view |
| 3997 | * should call this when its cursor moves. |
| 3998 | * |
| 3999 | * <p>When <code>immediate</code> is set to true, scrolling will not be |
| 4000 | * animated. |
| 4001 | * |
| 4002 | * @param rectangle The rectangle. |
| 4003 | * @param immediate True to forbid animated scrolling, false otherwise |
| 4004 | * @return Whether any parent scrolled. |
| 4005 | */ |
| 4006 | public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) { |
| 4007 | View child = this; |
| 4008 | ViewParent parent = mParent; |
| 4009 | boolean scrolled = false; |
| 4010 | while (parent != null) { |
| 4011 | scrolled |= parent.requestChildRectangleOnScreen(child, |
| 4012 | rectangle, immediate); |
| 4013 | |
| 4014 | // offset rect so next call has the rectangle in the |
| 4015 | // coordinate system of its direct child. |
| 4016 | rectangle.offset(child.getLeft(), child.getTop()); |
| 4017 | rectangle.offset(-child.getScrollX(), -child.getScrollY()); |
| 4018 | |
| 4019 | if (!(parent instanceof View)) { |
| 4020 | break; |
| 4021 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4022 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4023 | child = (View) parent; |
| 4024 | parent = child.getParent(); |
| 4025 | } |
| 4026 | return scrolled; |
| 4027 | } |
| 4028 | |
| 4029 | /** |
Svetoslav Ganov | 13fd561 | 2012-02-01 17:01:12 -0800 | [diff] [blame] | 4030 | * Called when this view wants to give up focus. If focus is cleared |
| 4031 | * {@link #onFocusChanged(boolean, int, android.graphics.Rect)} is called. |
| 4032 | * <p> |
| 4033 | * <strong>Note:</strong> When a View clears focus the framework is trying |
| 4034 | * to give focus to the first focusable View from the top. Hence, if this |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame^] | 4035 | * View is the first from the top that can take focus, then all callbacks |
| 4036 | * related to clearing focus will be invoked after wich the framework will |
| 4037 | * give focus to this view. |
Svetoslav Ganov | 13fd561 | 2012-02-01 17:01:12 -0800 | [diff] [blame] | 4038 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4039 | */ |
| 4040 | public void clearFocus() { |
| 4041 | if (DBG) { |
| 4042 | System.out.println(this + " clearFocus()"); |
| 4043 | } |
| 4044 | |
| 4045 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 4046 | mPrivateFlags &= ~FOCUSED; |
| 4047 | |
| 4048 | if (mParent != null) { |
| 4049 | mParent.clearChildFocus(this); |
| 4050 | } |
| 4051 | |
| 4052 | onFocusChanged(false, 0, null); |
| 4053 | refreshDrawableState(); |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame^] | 4054 | |
| 4055 | ensureInputFocusOnFirstFocusable(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4056 | } |
| 4057 | } |
| 4058 | |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame^] | 4059 | void ensureInputFocusOnFirstFocusable() { |
| 4060 | View root = getRootView(); |
| 4061 | if (root != null) { |
| 4062 | // Find the first focusble from the top. |
| 4063 | View next = root.focusSearch(FOCUS_FORWARD); |
| 4064 | if (next != null) { |
| 4065 | // Giving focus to the found focusable will not |
| 4066 | // perform a search since we found a view that is |
| 4067 | // guaranteed to be able to take focus. |
| 4068 | next.requestFocus(FOCUS_FORWARD); |
| 4069 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4070 | } |
| 4071 | } |
| 4072 | |
| 4073 | /** |
| 4074 | * Called internally by the view system when a new view is getting focus. |
| 4075 | * This is what clears the old focus. |
| 4076 | */ |
| 4077 | void unFocus() { |
| 4078 | if (DBG) { |
| 4079 | System.out.println(this + " unFocus()"); |
| 4080 | } |
| 4081 | |
| 4082 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 4083 | mPrivateFlags &= ~FOCUSED; |
| 4084 | |
| 4085 | onFocusChanged(false, 0, null); |
| 4086 | refreshDrawableState(); |
| 4087 | } |
| 4088 | } |
| 4089 | |
| 4090 | /** |
| 4091 | * Returns true if this view has focus iteself, or is the ancestor of the |
| 4092 | * view that has focus. |
| 4093 | * |
| 4094 | * @return True if this view has or contains focus, false otherwise. |
| 4095 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4096 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4097 | public boolean hasFocus() { |
| 4098 | return (mPrivateFlags & FOCUSED) != 0; |
| 4099 | } |
| 4100 | |
| 4101 | /** |
| 4102 | * Returns true if this view is focusable or if it contains a reachable View |
| 4103 | * for which {@link #hasFocusable()} returns true. A "reachable hasFocusable()" |
| 4104 | * is a View whose parents do not block descendants focus. |
| 4105 | * |
| 4106 | * Only {@link #VISIBLE} views are considered focusable. |
| 4107 | * |
| 4108 | * @return True if the view is focusable or if the view contains a focusable |
| 4109 | * View, false otherwise. |
| 4110 | * |
| 4111 | * @see ViewGroup#FOCUS_BLOCK_DESCENDANTS |
| 4112 | */ |
| 4113 | public boolean hasFocusable() { |
| 4114 | return (mViewFlags & VISIBILITY_MASK) == VISIBLE && isFocusable(); |
| 4115 | } |
| 4116 | |
| 4117 | /** |
| 4118 | * Called by the view system when the focus state of this view changes. |
| 4119 | * When the focus change event is caused by directional navigation, direction |
| 4120 | * and previouslyFocusedRect provide insight into where the focus is coming from. |
| 4121 | * When overriding, be sure to call up through to the super class so that |
| 4122 | * the standard focus handling will occur. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4123 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4124 | * @param gainFocus True if the View has focus; false otherwise. |
| 4125 | * @param direction The direction focus has moved when requestFocus() |
| 4126 | * is called to give this view focus. Values are |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4127 | * {@link #FOCUS_UP}, {@link #FOCUS_DOWN}, {@link #FOCUS_LEFT}, |
| 4128 | * {@link #FOCUS_RIGHT}, {@link #FOCUS_FORWARD}, or {@link #FOCUS_BACKWARD}. |
| 4129 | * 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] | 4130 | * @param previouslyFocusedRect The rectangle, in this view's coordinate |
| 4131 | * system, of the previously focused view. If applicable, this will be |
| 4132 | * passed in as finer grained information about where the focus is coming |
| 4133 | * from (in addition to direction). Will be <code>null</code> otherwise. |
| 4134 | */ |
| 4135 | protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4136 | if (gainFocus) { |
| 4137 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 4138 | } |
| 4139 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4140 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 4141 | if (!gainFocus) { |
| 4142 | if (isPressed()) { |
| 4143 | setPressed(false); |
| 4144 | } |
| 4145 | if (imm != null && mAttachInfo != null |
| 4146 | && mAttachInfo.mHasWindowFocus) { |
| 4147 | imm.focusOut(this); |
| 4148 | } |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4149 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4150 | } else if (imm != null && mAttachInfo != null |
| 4151 | && mAttachInfo.mHasWindowFocus) { |
| 4152 | imm.focusIn(this); |
| 4153 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4154 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 4155 | invalidate(true); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4156 | ListenerInfo li = mListenerInfo; |
| 4157 | if (li != null && li.mOnFocusChangeListener != null) { |
| 4158 | li.mOnFocusChangeListener.onFocusChange(this, gainFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4159 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 4160 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 4161 | if (mAttachInfo != null) { |
| 4162 | mAttachInfo.mKeyDispatchState.reset(this); |
| 4163 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4167 | * Sends an accessibility event of the given type. If accessiiblity is |
| 4168 | * not enabled this method has no effect. The default implementation calls |
| 4169 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)} first |
| 4170 | * to populate information about the event source (this View), then calls |
| 4171 | * {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} to |
| 4172 | * populate the text content of the event source including its descendants, |
| 4173 | * and last calls |
| 4174 | * {@link ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)} |
| 4175 | * on its parent to resuest sending of the event to interested parties. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4176 | * <p> |
| 4177 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4178 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4179 | * {@link AccessibilityDelegate#sendAccessibilityEvent(View, int)} is |
| 4180 | * responsible for handling this call. |
| 4181 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4182 | * |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4183 | * @param eventType The type of the event to send, as defined by several types from |
| 4184 | * {@link android.view.accessibility.AccessibilityEvent}, such as |
| 4185 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_CLICKED} or |
| 4186 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_ENTER}. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4187 | * |
| 4188 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4189 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4190 | * @see ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent) |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4191 | * @see AccessibilityDelegate |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4192 | */ |
| 4193 | public void sendAccessibilityEvent(int eventType) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4194 | if (mAccessibilityDelegate != null) { |
| 4195 | mAccessibilityDelegate.sendAccessibilityEvent(this, eventType); |
| 4196 | } else { |
| 4197 | sendAccessibilityEventInternal(eventType); |
| 4198 | } |
| 4199 | } |
| 4200 | |
| 4201 | /** |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4202 | * Convenience method for sending a {@link AccessibilityEvent#TYPE_ANNOUNCEMENT} |
| 4203 | * {@link AccessibilityEvent} to make an announcement which is related to some |
| 4204 | * sort of a context change for which none of the events representing UI transitions |
| 4205 | * is a good fit. For example, announcing a new page in a book. If accessibility |
| 4206 | * is not enabled this method does nothing. |
| 4207 | * |
| 4208 | * @param text The announcement text. |
| 4209 | */ |
| 4210 | public void announceForAccessibility(CharSequence text) { |
| 4211 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4212 | AccessibilityEvent event = AccessibilityEvent.obtain( |
| 4213 | AccessibilityEvent.TYPE_ANNOUNCEMENT); |
| 4214 | event.getText().add(text); |
| 4215 | sendAccessibilityEventUnchecked(event); |
| 4216 | } |
| 4217 | } |
| 4218 | |
| 4219 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4220 | * @see #sendAccessibilityEvent(int) |
| 4221 | * |
| 4222 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4223 | */ |
| 4224 | void sendAccessibilityEventInternal(int eventType) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4225 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4226 | sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType)); |
| 4227 | } |
| 4228 | } |
| 4229 | |
| 4230 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4231 | * This method behaves exactly as {@link #sendAccessibilityEvent(int)} but |
| 4232 | * takes as an argument an empty {@link AccessibilityEvent} and does not |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4233 | * perform a check whether accessibility is enabled. |
| 4234 | * <p> |
| 4235 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4236 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4237 | * {@link AccessibilityDelegate#sendAccessibilityEventUnchecked(View, AccessibilityEvent)} |
| 4238 | * is responsible for handling this call. |
| 4239 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4240 | * |
| 4241 | * @param event The event to send. |
| 4242 | * |
| 4243 | * @see #sendAccessibilityEvent(int) |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4244 | */ |
| 4245 | public void sendAccessibilityEventUnchecked(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4246 | if (mAccessibilityDelegate != null) { |
| 4247 | mAccessibilityDelegate.sendAccessibilityEventUnchecked(this, event); |
| 4248 | } else { |
| 4249 | sendAccessibilityEventUncheckedInternal(event); |
| 4250 | } |
| 4251 | } |
| 4252 | |
| 4253 | /** |
| 4254 | * @see #sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 4255 | * |
| 4256 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4257 | */ |
| 4258 | void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 9cd1eca | 2011-01-13 14:24:02 -0800 | [diff] [blame] | 4259 | if (!isShown()) { |
| 4260 | return; |
| 4261 | } |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4262 | onInitializeAccessibilityEvent(event); |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4263 | // Only a subset of accessibility events populates text content. |
| 4264 | if ((event.getEventType() & POPULATING_ACCESSIBILITY_EVENT_TYPES) != 0) { |
| 4265 | dispatchPopulateAccessibilityEvent(event); |
| 4266 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4267 | // In the beginning we called #isShown(), so we know that getParent() is not null. |
| 4268 | getParent().requestSendAccessibilityEvent(this, event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4269 | } |
| 4270 | |
| 4271 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4272 | * Dispatches an {@link AccessibilityEvent} to the {@link View} first and then |
| 4273 | * to its children for adding their text content to the event. Note that the |
| 4274 | * event text is populated in a separate dispatch path since we add to the |
| 4275 | * 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] | 4276 | * A typical implementation will call |
| 4277 | * {@link #onPopulateAccessibilityEvent(AccessibilityEvent)} on the this view |
| 4278 | * and then call the {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
| 4279 | * on each child. Override this method if custom population of the event text |
| 4280 | * content is required. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4281 | * <p> |
| 4282 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4283 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4284 | * {@link AccessibilityDelegate#dispatchPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4285 | * is responsible for handling this call. |
| 4286 | * </p> |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4287 | * <p> |
| 4288 | * <em>Note:</em> Accessibility events of certain types are not dispatched for |
| 4289 | * populating the event text via this method. For details refer to {@link AccessibilityEvent}. |
| 4290 | * </p> |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4291 | * |
| 4292 | * @param event The event. |
| 4293 | * |
| 4294 | * @return True if the event population was completed. |
| 4295 | */ |
| 4296 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4297 | if (mAccessibilityDelegate != null) { |
| 4298 | return mAccessibilityDelegate.dispatchPopulateAccessibilityEvent(this, event); |
| 4299 | } else { |
| 4300 | return dispatchPopulateAccessibilityEventInternal(event); |
| 4301 | } |
| 4302 | } |
| 4303 | |
| 4304 | /** |
| 4305 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4306 | * |
| 4307 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4308 | */ |
| 4309 | boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4310 | onPopulateAccessibilityEvent(event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4311 | return false; |
| 4312 | } |
| 4313 | |
| 4314 | /** |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4315 | * Called from {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4316 | * 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] | 4317 | * text content. While this method is free to modify event |
| 4318 | * attributes other than text content, doing so should normally be performed in |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4319 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)}. |
| 4320 | * <p> |
| 4321 | * Example: Adding formatted date string to an accessibility event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4322 | * to the text added by the super implementation: |
| 4323 | * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4324 | * super.onPopulateAccessibilityEvent(event); |
| 4325 | * final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; |
| 4326 | * String selectedDateUtterance = DateUtils.formatDateTime(mContext, |
| 4327 | * mCurrentDate.getTimeInMillis(), flags); |
| 4328 | * event.getText().add(selectedDateUtterance); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4329 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4330 | * <p> |
| 4331 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4332 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4333 | * {@link AccessibilityDelegate#onPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4334 | * is responsible for handling this call. |
| 4335 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4336 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4337 | * information to the event, in case the default implementation has basic information to add. |
| 4338 | * </p> |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4339 | * |
| 4340 | * @param event The accessibility event which to populate. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4341 | * |
| 4342 | * @see #sendAccessibilityEvent(int) |
| 4343 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4344 | */ |
| 4345 | public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4346 | if (mAccessibilityDelegate != null) { |
| 4347 | mAccessibilityDelegate.onPopulateAccessibilityEvent(this, event); |
| 4348 | } else { |
| 4349 | onPopulateAccessibilityEventInternal(event); |
| 4350 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4351 | } |
| 4352 | |
| 4353 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4354 | * @see #onPopulateAccessibilityEvent(AccessibilityEvent) |
| 4355 | * |
| 4356 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4357 | */ |
| 4358 | void onPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
| 4359 | |
| 4360 | } |
| 4361 | |
| 4362 | /** |
| 4363 | * Initializes an {@link AccessibilityEvent} with information about |
| 4364 | * this View which is the event source. In other words, the source of |
| 4365 | * an accessibility event is the view whose state change triggered firing |
| 4366 | * the event. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4367 | * <p> |
| 4368 | * Example: Setting the password property of an event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4369 | * to properties set by the super implementation: |
| 4370 | * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 4371 | * super.onInitializeAccessibilityEvent(event); |
| 4372 | * event.setPassword(true); |
| 4373 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4374 | * <p> |
| 4375 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4376 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4377 | * {@link AccessibilityDelegate#onInitializeAccessibilityEvent(View, AccessibilityEvent)} |
| 4378 | * is responsible for handling this call. |
| 4379 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4380 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4381 | * information to the event, in case the default implementation has basic information to add. |
| 4382 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4383 | * @param event The event to initialize. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4384 | * |
| 4385 | * @see #sendAccessibilityEvent(int) |
| 4386 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4387 | */ |
| 4388 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4389 | if (mAccessibilityDelegate != null) { |
| 4390 | mAccessibilityDelegate.onInitializeAccessibilityEvent(this, event); |
| 4391 | } else { |
| 4392 | onInitializeAccessibilityEventInternal(event); |
| 4393 | } |
| 4394 | } |
| 4395 | |
| 4396 | /** |
| 4397 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4398 | * |
| 4399 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4400 | */ |
| 4401 | void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4402 | event.setSource(this); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 4403 | event.setClassName(View.class.getName()); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4404 | event.setPackageName(getContext().getPackageName()); |
| 4405 | event.setEnabled(isEnabled()); |
| 4406 | event.setContentDescription(mContentDescription); |
| 4407 | |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 4408 | if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && mAttachInfo != null) { |
| 4409 | ArrayList<View> focusablesTempList = mAttachInfo.mFocusablesTempList; |
| 4410 | getRootView().addFocusables(focusablesTempList, View.FOCUS_FORWARD, |
| 4411 | FOCUSABLES_ALL); |
| 4412 | event.setItemCount(focusablesTempList.size()); |
| 4413 | event.setCurrentItemIndex(focusablesTempList.indexOf(this)); |
| 4414 | focusablesTempList.clear(); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4415 | } |
| 4416 | } |
| 4417 | |
| 4418 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4419 | * Returns an {@link AccessibilityNodeInfo} representing this view from the |
| 4420 | * point of view of an {@link android.accessibilityservice.AccessibilityService}. |
| 4421 | * This method is responsible for obtaining an accessibility node info from a |
| 4422 | * pool of reusable instances and calling |
| 4423 | * {@link #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} on this view to |
| 4424 | * initialize the former. |
| 4425 | * <p> |
| 4426 | * Note: The client is responsible for recycling the obtained instance by calling |
| 4427 | * {@link AccessibilityNodeInfo#recycle()} to minimize object creation. |
| 4428 | * </p> |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4429 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4430 | * @return A populated {@link AccessibilityNodeInfo}. |
| 4431 | * |
| 4432 | * @see AccessibilityNodeInfo |
| 4433 | */ |
| 4434 | public AccessibilityNodeInfo createAccessibilityNodeInfo() { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4435 | AccessibilityNodeProvider provider = getAccessibilityNodeProvider(); |
| 4436 | if (provider != null) { |
| 4437 | return provider.createAccessibilityNodeInfo(View.NO_ID); |
| 4438 | } else { |
| 4439 | AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(this); |
| 4440 | onInitializeAccessibilityNodeInfo(info); |
| 4441 | return info; |
| 4442 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4443 | } |
| 4444 | |
| 4445 | /** |
| 4446 | * Initializes an {@link AccessibilityNodeInfo} with information about this view. |
| 4447 | * The base implementation sets: |
| 4448 | * <ul> |
| 4449 | * <li>{@link AccessibilityNodeInfo#setParent(View)},</li> |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4450 | * <li>{@link AccessibilityNodeInfo#setBoundsInParent(Rect)},</li> |
| 4451 | * <li>{@link AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li> |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4452 | * <li>{@link AccessibilityNodeInfo#setPackageName(CharSequence)},</li> |
| 4453 | * <li>{@link AccessibilityNodeInfo#setClassName(CharSequence)},</li> |
| 4454 | * <li>{@link AccessibilityNodeInfo#setContentDescription(CharSequence)},</li> |
| 4455 | * <li>{@link AccessibilityNodeInfo#setEnabled(boolean)},</li> |
| 4456 | * <li>{@link AccessibilityNodeInfo#setClickable(boolean)},</li> |
| 4457 | * <li>{@link AccessibilityNodeInfo#setFocusable(boolean)},</li> |
| 4458 | * <li>{@link AccessibilityNodeInfo#setFocused(boolean)},</li> |
| 4459 | * <li>{@link AccessibilityNodeInfo#setLongClickable(boolean)},</li> |
| 4460 | * <li>{@link AccessibilityNodeInfo#setSelected(boolean)},</li> |
| 4461 | * </ul> |
| 4462 | * <p> |
| 4463 | * Subclasses should override this method, call the super implementation, |
| 4464 | * and set additional attributes. |
| 4465 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4466 | * <p> |
| 4467 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4468 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4469 | * {@link AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)} |
| 4470 | * is responsible for handling this call. |
| 4471 | * </p> |
| 4472 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4473 | * @param info The instance to initialize. |
| 4474 | */ |
| 4475 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4476 | if (mAccessibilityDelegate != null) { |
| 4477 | mAccessibilityDelegate.onInitializeAccessibilityNodeInfo(this, info); |
| 4478 | } else { |
| 4479 | onInitializeAccessibilityNodeInfoInternal(info); |
| 4480 | } |
| 4481 | } |
| 4482 | |
| 4483 | /** |
| 4484 | * @see #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 4485 | * |
| 4486 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4487 | */ |
| 4488 | void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4489 | Rect bounds = mAttachInfo.mTmpInvalRect; |
| 4490 | getDrawingRect(bounds); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4491 | info.setBoundsInParent(bounds); |
| 4492 | |
| 4493 | int[] locationOnScreen = mAttachInfo.mInvalidateChildLocation; |
| 4494 | getLocationOnScreen(locationOnScreen); |
Alan Viverette | 326804f | 2011-07-22 16:20:41 -0700 | [diff] [blame] | 4495 | bounds.offsetTo(0, 0); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4496 | bounds.offset(locationOnScreen[0], locationOnScreen[1]); |
| 4497 | info.setBoundsInScreen(bounds); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4498 | |
Svetoslav Ganov | 57f3b566db | 2011-10-31 17:59:14 -0700 | [diff] [blame] | 4499 | if ((mPrivateFlags & IS_ROOT_NAMESPACE) == 0) { |
| 4500 | ViewParent parent = getParent(); |
| 4501 | if (parent instanceof View) { |
| 4502 | View parentView = (View) parent; |
| 4503 | info.setParent(parentView); |
| 4504 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4505 | } |
| 4506 | |
| 4507 | info.setPackageName(mContext.getPackageName()); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 4508 | info.setClassName(View.class.getName()); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4509 | info.setContentDescription(getContentDescription()); |
| 4510 | |
| 4511 | info.setEnabled(isEnabled()); |
| 4512 | info.setClickable(isClickable()); |
| 4513 | info.setFocusable(isFocusable()); |
| 4514 | info.setFocused(isFocused()); |
| 4515 | info.setSelected(isSelected()); |
| 4516 | info.setLongClickable(isLongClickable()); |
| 4517 | |
| 4518 | // TODO: These make sense only if we are in an AdapterView but all |
| 4519 | // views can be selected. Maybe from accessiiblity perspective |
| 4520 | // we should report as selectable view in an AdapterView. |
| 4521 | info.addAction(AccessibilityNodeInfo.ACTION_SELECT); |
| 4522 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_SELECTION); |
| 4523 | |
| 4524 | if (isFocusable()) { |
| 4525 | if (isFocused()) { |
| 4526 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS); |
| 4527 | } else { |
| 4528 | info.addAction(AccessibilityNodeInfo.ACTION_FOCUS); |
| 4529 | } |
| 4530 | } |
| 4531 | } |
| 4532 | |
| 4533 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4534 | * Sets a delegate for implementing accessibility support via compositon as |
| 4535 | * opposed to inheritance. The delegate's primary use is for implementing |
| 4536 | * backwards compatible widgets. For more details see {@link AccessibilityDelegate}. |
| 4537 | * |
| 4538 | * @param delegate The delegate instance. |
| 4539 | * |
| 4540 | * @see AccessibilityDelegate |
| 4541 | */ |
| 4542 | public void setAccessibilityDelegate(AccessibilityDelegate delegate) { |
| 4543 | mAccessibilityDelegate = delegate; |
| 4544 | } |
| 4545 | |
| 4546 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4547 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 4548 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 4549 | * that explore the window content. |
| 4550 | * <p> |
| 4551 | * If this method returns an instance, this instance is responsible for managing |
| 4552 | * {@link AccessibilityNodeInfo}s describing the virtual sub-tree rooted at this |
| 4553 | * View including the one representing the View itself. Similarly the returned |
| 4554 | * instance is responsible for performing accessibility actions on any virtual |
| 4555 | * view or the root view itself. |
| 4556 | * </p> |
| 4557 | * <p> |
| 4558 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4559 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4560 | * {@link AccessibilityDelegate#getAccessibilityNodeProvider(View)} |
| 4561 | * is responsible for handling this call. |
| 4562 | * </p> |
| 4563 | * |
| 4564 | * @return The provider. |
| 4565 | * |
| 4566 | * @see AccessibilityNodeProvider |
| 4567 | */ |
| 4568 | public AccessibilityNodeProvider getAccessibilityNodeProvider() { |
| 4569 | if (mAccessibilityDelegate != null) { |
| 4570 | return mAccessibilityDelegate.getAccessibilityNodeProvider(this); |
| 4571 | } else { |
| 4572 | return null; |
| 4573 | } |
| 4574 | } |
| 4575 | |
| 4576 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4577 | * Gets the unique identifier of this view on the screen for accessibility purposes. |
| 4578 | * If this {@link View} is not attached to any window, {@value #NO_ID} is returned. |
| 4579 | * |
| 4580 | * @return The view accessibility id. |
| 4581 | * |
| 4582 | * @hide |
| 4583 | */ |
| 4584 | public int getAccessibilityViewId() { |
| 4585 | if (mAccessibilityViewId == NO_ID) { |
| 4586 | mAccessibilityViewId = sNextAccessibilityViewId++; |
| 4587 | } |
| 4588 | return mAccessibilityViewId; |
| 4589 | } |
| 4590 | |
| 4591 | /** |
| 4592 | * Gets the unique identifier of the window in which this View reseides. |
| 4593 | * |
| 4594 | * @return The window accessibility id. |
| 4595 | * |
| 4596 | * @hide |
| 4597 | */ |
| 4598 | public int getAccessibilityWindowId() { |
| 4599 | return mAttachInfo != null ? mAttachInfo.mAccessibilityWindowId : NO_ID; |
| 4600 | } |
| 4601 | |
| 4602 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4603 | * Gets the {@link View} description. It briefly describes the view and is |
| 4604 | * primarily used for accessibility support. Set this property to enable |
| 4605 | * better accessibility support for your application. This is especially |
| 4606 | * true for views that do not have textual representation (For example, |
| 4607 | * ImageButton). |
| 4608 | * |
| 4609 | * @return The content descriptiopn. |
| 4610 | * |
| 4611 | * @attr ref android.R.styleable#View_contentDescription |
| 4612 | */ |
| 4613 | public CharSequence getContentDescription() { |
| 4614 | return mContentDescription; |
| 4615 | } |
| 4616 | |
| 4617 | /** |
| 4618 | * Sets the {@link View} description. It briefly describes the view and is |
| 4619 | * primarily used for accessibility support. Set this property to enable |
| 4620 | * better accessibility support for your application. This is especially |
| 4621 | * true for views that do not have textual representation (For example, |
| 4622 | * ImageButton). |
| 4623 | * |
| 4624 | * @param contentDescription The content description. |
| 4625 | * |
| 4626 | * @attr ref android.R.styleable#View_contentDescription |
| 4627 | */ |
Svetoslav Ganov | e261e28 | 2011-10-18 17:47:04 -0700 | [diff] [blame] | 4628 | @RemotableViewMethod |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4629 | public void setContentDescription(CharSequence contentDescription) { |
| 4630 | mContentDescription = contentDescription; |
| 4631 | } |
| 4632 | |
| 4633 | /** |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4634 | * Invoked whenever this view loses focus, either by losing window focus or by losing |
| 4635 | * focus within its window. This method can be used to clear any state tied to the |
| 4636 | * focus. For instance, if a button is held pressed with the trackball and the window |
| 4637 | * loses focus, this method can be used to cancel the press. |
| 4638 | * |
| 4639 | * Subclasses of View overriding this method should always call super.onFocusLost(). |
| 4640 | * |
| 4641 | * @see #onFocusChanged(boolean, int, android.graphics.Rect) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4642 | * @see #onWindowFocusChanged(boolean) |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4643 | * |
| 4644 | * @hide pending API council approval |
| 4645 | */ |
| 4646 | protected void onFocusLost() { |
| 4647 | resetPressedState(); |
| 4648 | } |
| 4649 | |
| 4650 | private void resetPressedState() { |
| 4651 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 4652 | return; |
| 4653 | } |
| 4654 | |
| 4655 | if (isPressed()) { |
| 4656 | setPressed(false); |
| 4657 | |
| 4658 | if (!mHasPerformedLongPress) { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 4659 | removeLongPressCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4660 | } |
| 4661 | } |
| 4662 | } |
| 4663 | |
| 4664 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4665 | * Returns true if this view has focus |
| 4666 | * |
| 4667 | * @return True if this view has focus, false otherwise. |
| 4668 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4669 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4670 | public boolean isFocused() { |
| 4671 | return (mPrivateFlags & FOCUSED) != 0; |
| 4672 | } |
| 4673 | |
| 4674 | /** |
| 4675 | * Find the view in the hierarchy rooted at this view that currently has |
| 4676 | * focus. |
| 4677 | * |
| 4678 | * @return The view that currently has focus, or null if no focused view can |
| 4679 | * be found. |
| 4680 | */ |
| 4681 | public View findFocus() { |
| 4682 | return (mPrivateFlags & FOCUSED) != 0 ? this : null; |
| 4683 | } |
| 4684 | |
| 4685 | /** |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 4686 | * Indicates whether this view is one of the set of scrollable containers in |
| 4687 | * its window. |
| 4688 | * |
| 4689 | * @return whether this view is one of the set of scrollable containers in |
| 4690 | * its window |
| 4691 | * |
| 4692 | * @attr ref android.R.styleable#View_isScrollContainer |
| 4693 | */ |
| 4694 | public boolean isScrollContainer() { |
| 4695 | return (mPrivateFlags & SCROLL_CONTAINER_ADDED) != 0; |
| 4696 | } |
| 4697 | |
| 4698 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4699 | * Change whether this view is one of the set of scrollable containers in |
| 4700 | * its window. This will be used to determine whether the window can |
| 4701 | * resize or must pan when a soft input area is open -- scrollable |
| 4702 | * containers allow the window to use resize mode since the container |
| 4703 | * will appropriately shrink. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 4704 | * |
| 4705 | * @attr ref android.R.styleable#View_isScrollContainer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4706 | */ |
| 4707 | public void setScrollContainer(boolean isScrollContainer) { |
| 4708 | if (isScrollContainer) { |
| 4709 | if (mAttachInfo != null && (mPrivateFlags&SCROLL_CONTAINER_ADDED) == 0) { |
| 4710 | mAttachInfo.mScrollContainers.add(this); |
| 4711 | mPrivateFlags |= SCROLL_CONTAINER_ADDED; |
| 4712 | } |
| 4713 | mPrivateFlags |= SCROLL_CONTAINER; |
| 4714 | } else { |
| 4715 | if ((mPrivateFlags&SCROLL_CONTAINER_ADDED) != 0) { |
| 4716 | mAttachInfo.mScrollContainers.remove(this); |
| 4717 | } |
| 4718 | mPrivateFlags &= ~(SCROLL_CONTAINER|SCROLL_CONTAINER_ADDED); |
| 4719 | } |
| 4720 | } |
| 4721 | |
| 4722 | /** |
| 4723 | * Returns the quality of the drawing cache. |
| 4724 | * |
| 4725 | * @return One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 4726 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 4727 | * |
| 4728 | * @see #setDrawingCacheQuality(int) |
| 4729 | * @see #setDrawingCacheEnabled(boolean) |
| 4730 | * @see #isDrawingCacheEnabled() |
| 4731 | * |
| 4732 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 4733 | */ |
| 4734 | public int getDrawingCacheQuality() { |
| 4735 | return mViewFlags & DRAWING_CACHE_QUALITY_MASK; |
| 4736 | } |
| 4737 | |
| 4738 | /** |
| 4739 | * Set the drawing cache quality of this view. This value is used only when the |
| 4740 | * drawing cache is enabled |
| 4741 | * |
| 4742 | * @param quality One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 4743 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 4744 | * |
| 4745 | * @see #getDrawingCacheQuality() |
| 4746 | * @see #setDrawingCacheEnabled(boolean) |
| 4747 | * @see #isDrawingCacheEnabled() |
| 4748 | * |
| 4749 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 4750 | */ |
| 4751 | public void setDrawingCacheQuality(int quality) { |
| 4752 | setFlags(quality, DRAWING_CACHE_QUALITY_MASK); |
| 4753 | } |
| 4754 | |
| 4755 | /** |
| 4756 | * Returns whether the screen should remain on, corresponding to the current |
| 4757 | * value of {@link #KEEP_SCREEN_ON}. |
| 4758 | * |
| 4759 | * @return Returns true if {@link #KEEP_SCREEN_ON} is set. |
| 4760 | * |
| 4761 | * @see #setKeepScreenOn(boolean) |
| 4762 | * |
| 4763 | * @attr ref android.R.styleable#View_keepScreenOn |
| 4764 | */ |
| 4765 | public boolean getKeepScreenOn() { |
| 4766 | return (mViewFlags & KEEP_SCREEN_ON) != 0; |
| 4767 | } |
| 4768 | |
| 4769 | /** |
| 4770 | * Controls whether the screen should remain on, modifying the |
| 4771 | * value of {@link #KEEP_SCREEN_ON}. |
| 4772 | * |
| 4773 | * @param keepScreenOn Supply true to set {@link #KEEP_SCREEN_ON}. |
| 4774 | * |
| 4775 | * @see #getKeepScreenOn() |
| 4776 | * |
| 4777 | * @attr ref android.R.styleable#View_keepScreenOn |
| 4778 | */ |
| 4779 | public void setKeepScreenOn(boolean keepScreenOn) { |
| 4780 | setFlags(keepScreenOn ? KEEP_SCREEN_ON : 0, KEEP_SCREEN_ON); |
| 4781 | } |
| 4782 | |
| 4783 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4784 | * Gets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 4785 | * @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] | 4786 | * |
| 4787 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 4788 | */ |
| 4789 | public int getNextFocusLeftId() { |
| 4790 | return mNextFocusLeftId; |
| 4791 | } |
| 4792 | |
| 4793 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4794 | * Sets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 4795 | * @param nextFocusLeftId The next focus ID, or {@link #NO_ID} if the framework should |
| 4796 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4797 | * |
| 4798 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 4799 | */ |
| 4800 | public void setNextFocusLeftId(int nextFocusLeftId) { |
| 4801 | mNextFocusLeftId = nextFocusLeftId; |
| 4802 | } |
| 4803 | |
| 4804 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4805 | * Gets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 4806 | * @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] | 4807 | * |
| 4808 | * @attr ref android.R.styleable#View_nextFocusRight |
| 4809 | */ |
| 4810 | public int getNextFocusRightId() { |
| 4811 | return mNextFocusRightId; |
| 4812 | } |
| 4813 | |
| 4814 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4815 | * Sets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 4816 | * @param nextFocusRightId The next focus ID, or {@link #NO_ID} if the framework should |
| 4817 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4818 | * |
| 4819 | * @attr ref android.R.styleable#View_nextFocusRight |
| 4820 | */ |
| 4821 | public void setNextFocusRightId(int nextFocusRightId) { |
| 4822 | mNextFocusRightId = nextFocusRightId; |
| 4823 | } |
| 4824 | |
| 4825 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4826 | * Gets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 4827 | * @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] | 4828 | * |
| 4829 | * @attr ref android.R.styleable#View_nextFocusUp |
| 4830 | */ |
| 4831 | public int getNextFocusUpId() { |
| 4832 | return mNextFocusUpId; |
| 4833 | } |
| 4834 | |
| 4835 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4836 | * Sets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 4837 | * @param nextFocusUpId The next focus ID, or {@link #NO_ID} if the framework should |
| 4838 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4839 | * |
| 4840 | * @attr ref android.R.styleable#View_nextFocusUp |
| 4841 | */ |
| 4842 | public void setNextFocusUpId(int nextFocusUpId) { |
| 4843 | mNextFocusUpId = nextFocusUpId; |
| 4844 | } |
| 4845 | |
| 4846 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4847 | * Gets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 4848 | * @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] | 4849 | * |
| 4850 | * @attr ref android.R.styleable#View_nextFocusDown |
| 4851 | */ |
| 4852 | public int getNextFocusDownId() { |
| 4853 | return mNextFocusDownId; |
| 4854 | } |
| 4855 | |
| 4856 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4857 | * Sets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 4858 | * @param nextFocusDownId The next focus ID, or {@link #NO_ID} if the framework should |
| 4859 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4860 | * |
| 4861 | * @attr ref android.R.styleable#View_nextFocusDown |
| 4862 | */ |
| 4863 | public void setNextFocusDownId(int nextFocusDownId) { |
| 4864 | mNextFocusDownId = nextFocusDownId; |
| 4865 | } |
| 4866 | |
| 4867 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4868 | * Gets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 4869 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
| 4870 | * |
| 4871 | * @attr ref android.R.styleable#View_nextFocusForward |
| 4872 | */ |
| 4873 | public int getNextFocusForwardId() { |
| 4874 | return mNextFocusForwardId; |
| 4875 | } |
| 4876 | |
| 4877 | /** |
| 4878 | * Sets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 4879 | * @param nextFocusForwardId The next focus ID, or {@link #NO_ID} if the framework should |
| 4880 | * decide automatically. |
| 4881 | * |
| 4882 | * @attr ref android.R.styleable#View_nextFocusForward |
| 4883 | */ |
| 4884 | public void setNextFocusForwardId(int nextFocusForwardId) { |
| 4885 | mNextFocusForwardId = nextFocusForwardId; |
| 4886 | } |
| 4887 | |
| 4888 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4889 | * Returns the visibility of this view and all of its ancestors |
| 4890 | * |
| 4891 | * @return True if this view and all of its ancestors are {@link #VISIBLE} |
| 4892 | */ |
| 4893 | public boolean isShown() { |
| 4894 | View current = this; |
| 4895 | //noinspection ConstantConditions |
| 4896 | do { |
| 4897 | if ((current.mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 4898 | return false; |
| 4899 | } |
| 4900 | ViewParent parent = current.mParent; |
| 4901 | if (parent == null) { |
| 4902 | return false; // We are not attached to the view root |
| 4903 | } |
| 4904 | if (!(parent instanceof View)) { |
| 4905 | return true; |
| 4906 | } |
| 4907 | current = (View) parent; |
| 4908 | } while (current != null); |
| 4909 | |
| 4910 | return false; |
| 4911 | } |
| 4912 | |
| 4913 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4914 | * Called by the view hierarchy when the content insets for a window have |
| 4915 | * changed, to allow it to adjust its content to fit within those windows. |
| 4916 | * The content insets tell you the space that the status bar, input method, |
| 4917 | * 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] | 4918 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4919 | * <p>You do not normally need to deal with this function, since the default |
| 4920 | * window decoration given to applications takes care of applying it to the |
| 4921 | * content of the window. If you use {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} |
| 4922 | * or {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION} this will not be the case, |
| 4923 | * and your content can be placed under those system elements. You can then |
| 4924 | * use this method within your view hierarchy if you have parts of your UI |
| 4925 | * 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] | 4926 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4927 | * <p>The default implementation of this method simply applies the content |
| 4928 | * inset's to the view's padding. This can be enabled through |
| 4929 | * {@link #setFitsSystemWindows(boolean)}. Alternatively, you can override |
| 4930 | * the method and handle the insets however you would like. Note that the |
| 4931 | * insets provided by the framework are always relative to the far edges |
| 4932 | * of the window, not accounting for the location of the called view within |
| 4933 | * that window. (In fact when this method is called you do not yet know |
| 4934 | * where the layout will place the view, as it is done before layout happens.) |
| 4935 | * |
| 4936 | * <p>Note: unlike many View methods, there is no dispatch phase to this |
| 4937 | * call. If you are overriding it in a ViewGroup and want to allow the |
| 4938 | * call to continue to your children, you must be sure to call the super |
| 4939 | * implementation. |
| 4940 | * |
| 4941 | * @param insets Current content insets of the window. Prior to |
| 4942 | * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} you must not modify |
| 4943 | * the insets or else you and Android will be unhappy. |
| 4944 | * |
| 4945 | * @return Return true if this view applied the insets and it should not |
| 4946 | * continue propagating further down the hierarchy, false otherwise. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4947 | */ |
| 4948 | protected boolean fitSystemWindows(Rect insets) { |
| 4949 | if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4950 | mUserPaddingStart = -1; |
| 4951 | mUserPaddingEnd = -1; |
| 4952 | mUserPaddingRelative = false; |
| 4953 | if ((mViewFlags & OPTIONAL_FITS_SYSTEM_WINDOWS) == 0 |
| 4954 | || mAttachInfo == null |
| 4955 | || (mAttachInfo.mSystemUiVisibility & SYSTEM_UI_LAYOUT_FLAGS) == 0) { |
| 4956 | internalSetPadding(insets.left, insets.top, insets.right, insets.bottom); |
| 4957 | return true; |
| 4958 | } else { |
| 4959 | internalSetPadding(0, 0, 0, 0); |
| 4960 | return false; |
| 4961 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4962 | } |
| 4963 | return false; |
| 4964 | } |
| 4965 | |
| 4966 | /** |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 4967 | * Set whether or not this view should account for system screen decorations |
| 4968 | * such as the status bar and inset its content. This allows this view to be |
| 4969 | * positioned in absolute screen coordinates and remain visible to the user. |
| 4970 | * |
| 4971 | * <p>This should only be used by top-level window decor views. |
| 4972 | * |
| 4973 | * @param fitSystemWindows true to inset content for system screen decorations, false for |
| 4974 | * default behavior. |
| 4975 | * |
| 4976 | * @attr ref android.R.styleable#View_fitsSystemWindows |
| 4977 | */ |
| 4978 | public void setFitsSystemWindows(boolean fitSystemWindows) { |
| 4979 | setFlags(fitSystemWindows ? FITS_SYSTEM_WINDOWS : 0, FITS_SYSTEM_WINDOWS); |
| 4980 | } |
| 4981 | |
| 4982 | /** |
| 4983 | * Check for the FITS_SYSTEM_WINDOWS flag. If this method returns true, this view |
| 4984 | * will account for system screen decorations such as the status bar and inset its |
| 4985 | * content. This allows the view to be positioned in absolute screen coordinates |
| 4986 | * and remain visible to the user. |
| 4987 | * |
| 4988 | * @return true if this view will adjust its content bounds for system screen decorations. |
| 4989 | * |
| 4990 | * @attr ref android.R.styleable#View_fitsSystemWindows |
| 4991 | */ |
| 4992 | public boolean fitsSystemWindows() { |
| 4993 | return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS; |
| 4994 | } |
| 4995 | |
| 4996 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 4997 | * Ask that a new dispatch of {@link #fitSystemWindows(Rect)} be performed. |
| 4998 | */ |
| 4999 | public void requestFitSystemWindows() { |
| 5000 | if (mParent != null) { |
| 5001 | mParent.requestFitSystemWindows(); |
| 5002 | } |
| 5003 | } |
| 5004 | |
| 5005 | /** |
| 5006 | * For use by PhoneWindow to make its own system window fitting optional. |
| 5007 | * @hide |
| 5008 | */ |
| 5009 | public void makeOptionalFitsSystemWindows() { |
| 5010 | setFlags(OPTIONAL_FITS_SYSTEM_WINDOWS, OPTIONAL_FITS_SYSTEM_WINDOWS); |
| 5011 | } |
| 5012 | |
| 5013 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5014 | * Returns the visibility status for this view. |
| 5015 | * |
| 5016 | * @return One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 5017 | * @attr ref android.R.styleable#View_visibility |
| 5018 | */ |
| 5019 | @ViewDebug.ExportedProperty(mapping = { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5020 | @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), |
| 5021 | @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), |
| 5022 | @ViewDebug.IntToString(from = GONE, to = "GONE") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5023 | }) |
| 5024 | public int getVisibility() { |
| 5025 | return mViewFlags & VISIBILITY_MASK; |
| 5026 | } |
| 5027 | |
| 5028 | /** |
| 5029 | * Set the enabled state of this view. |
| 5030 | * |
| 5031 | * @param visibility One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 5032 | * @attr ref android.R.styleable#View_visibility |
| 5033 | */ |
| 5034 | @RemotableViewMethod |
| 5035 | public void setVisibility(int visibility) { |
| 5036 | setFlags(visibility, VISIBILITY_MASK); |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5037 | if (mBackground != null) mBackground.setVisible(visibility == VISIBLE, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5038 | } |
| 5039 | |
| 5040 | /** |
| 5041 | * Returns the enabled status for this view. The interpretation of the |
| 5042 | * enabled state varies by subclass. |
| 5043 | * |
| 5044 | * @return True if this view is enabled, false otherwise. |
| 5045 | */ |
| 5046 | @ViewDebug.ExportedProperty |
| 5047 | public boolean isEnabled() { |
| 5048 | return (mViewFlags & ENABLED_MASK) == ENABLED; |
| 5049 | } |
| 5050 | |
| 5051 | /** |
| 5052 | * Set the enabled state of this view. The interpretation of the enabled |
| 5053 | * state varies by subclass. |
| 5054 | * |
| 5055 | * @param enabled True if this view is enabled, false otherwise. |
| 5056 | */ |
Jeff Sharkey | 2b95c24 | 2010-02-08 17:40:30 -0800 | [diff] [blame] | 5057 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5058 | public void setEnabled(boolean enabled) { |
Amith Yamasani | a2ef00b | 2009-07-30 16:14:34 -0700 | [diff] [blame] | 5059 | if (enabled == isEnabled()) return; |
| 5060 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5061 | setFlags(enabled ? ENABLED : DISABLED, ENABLED_MASK); |
| 5062 | |
| 5063 | /* |
| 5064 | * The View most likely has to change its appearance, so refresh |
| 5065 | * the drawable state. |
| 5066 | */ |
| 5067 | refreshDrawableState(); |
| 5068 | |
| 5069 | // Invalidate too, since the default behavior for views is to be |
| 5070 | // be drawn at 50% alpha rather than to change the drawable. |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 5071 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5072 | } |
| 5073 | |
| 5074 | /** |
| 5075 | * Set whether this view can receive the focus. |
| 5076 | * |
| 5077 | * Setting this to false will also ensure that this view is not focusable |
| 5078 | * in touch mode. |
| 5079 | * |
| 5080 | * @param focusable If true, this view can receive the focus. |
| 5081 | * |
| 5082 | * @see #setFocusableInTouchMode(boolean) |
| 5083 | * @attr ref android.R.styleable#View_focusable |
| 5084 | */ |
| 5085 | public void setFocusable(boolean focusable) { |
| 5086 | if (!focusable) { |
| 5087 | setFlags(0, FOCUSABLE_IN_TOUCH_MODE); |
| 5088 | } |
| 5089 | setFlags(focusable ? FOCUSABLE : NOT_FOCUSABLE, FOCUSABLE_MASK); |
| 5090 | } |
| 5091 | |
| 5092 | /** |
| 5093 | * Set whether this view can receive focus while in touch mode. |
| 5094 | * |
| 5095 | * Setting this to true will also ensure that this view is focusable. |
| 5096 | * |
| 5097 | * @param focusableInTouchMode If true, this view can receive the focus while |
| 5098 | * in touch mode. |
| 5099 | * |
| 5100 | * @see #setFocusable(boolean) |
| 5101 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 5102 | */ |
| 5103 | public void setFocusableInTouchMode(boolean focusableInTouchMode) { |
| 5104 | // Focusable in touch mode should always be set before the focusable flag |
| 5105 | // otherwise, setting the focusable flag will trigger a focusableViewAvailable() |
| 5106 | // which, in touch mode, will not successfully request focus on this view |
| 5107 | // because the focusable in touch mode flag is not set |
| 5108 | setFlags(focusableInTouchMode ? FOCUSABLE_IN_TOUCH_MODE : 0, FOCUSABLE_IN_TOUCH_MODE); |
| 5109 | if (focusableInTouchMode) { |
| 5110 | setFlags(FOCUSABLE, FOCUSABLE_MASK); |
| 5111 | } |
| 5112 | } |
| 5113 | |
| 5114 | /** |
| 5115 | * Set whether this view should have sound effects enabled for events such as |
| 5116 | * clicking and touching. |
| 5117 | * |
| 5118 | * <p>You may wish to disable sound effects for a view if you already play sounds, |
| 5119 | * for instance, a dial key that plays dtmf tones. |
| 5120 | * |
| 5121 | * @param soundEffectsEnabled whether sound effects are enabled for this view. |
| 5122 | * @see #isSoundEffectsEnabled() |
| 5123 | * @see #playSoundEffect(int) |
| 5124 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 5125 | */ |
| 5126 | public void setSoundEffectsEnabled(boolean soundEffectsEnabled) { |
| 5127 | setFlags(soundEffectsEnabled ? SOUND_EFFECTS_ENABLED: 0, SOUND_EFFECTS_ENABLED); |
| 5128 | } |
| 5129 | |
| 5130 | /** |
| 5131 | * @return whether this view should have sound effects enabled for events such as |
| 5132 | * clicking and touching. |
| 5133 | * |
| 5134 | * @see #setSoundEffectsEnabled(boolean) |
| 5135 | * @see #playSoundEffect(int) |
| 5136 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 5137 | */ |
| 5138 | @ViewDebug.ExportedProperty |
| 5139 | public boolean isSoundEffectsEnabled() { |
| 5140 | return SOUND_EFFECTS_ENABLED == (mViewFlags & SOUND_EFFECTS_ENABLED); |
| 5141 | } |
| 5142 | |
| 5143 | /** |
| 5144 | * Set whether this view should have haptic feedback for events such as |
| 5145 | * long presses. |
| 5146 | * |
| 5147 | * <p>You may wish to disable haptic feedback if your view already controls |
| 5148 | * its own haptic feedback. |
| 5149 | * |
| 5150 | * @param hapticFeedbackEnabled whether haptic feedback enabled for this view. |
| 5151 | * @see #isHapticFeedbackEnabled() |
| 5152 | * @see #performHapticFeedback(int) |
| 5153 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 5154 | */ |
| 5155 | public void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled) { |
| 5156 | setFlags(hapticFeedbackEnabled ? HAPTIC_FEEDBACK_ENABLED: 0, HAPTIC_FEEDBACK_ENABLED); |
| 5157 | } |
| 5158 | |
| 5159 | /** |
| 5160 | * @return whether this view should have haptic feedback enabled for events |
| 5161 | * long presses. |
| 5162 | * |
| 5163 | * @see #setHapticFeedbackEnabled(boolean) |
| 5164 | * @see #performHapticFeedback(int) |
| 5165 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 5166 | */ |
| 5167 | @ViewDebug.ExportedProperty |
| 5168 | public boolean isHapticFeedbackEnabled() { |
| 5169 | return HAPTIC_FEEDBACK_ENABLED == (mViewFlags & HAPTIC_FEEDBACK_ENABLED); |
| 5170 | } |
| 5171 | |
| 5172 | /** |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5173 | * Returns the layout direction for this view. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5174 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5175 | * @return One of {@link #LAYOUT_DIRECTION_LTR}, |
| 5176 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 5177 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 5178 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
| 5179 | * @attr ref android.R.styleable#View_layoutDirection |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5180 | */ |
Fabrice Di Meglio | bce84d2 | 2011-06-02 15:57:01 -0700 | [diff] [blame] | 5181 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5182 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "LTR"), |
| 5183 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RTL"), |
| 5184 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"), |
| 5185 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE, to = "LOCALE") |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5186 | }) |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5187 | public int getLayoutDirection() { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5188 | return (mPrivateFlags2 & LAYOUT_DIRECTION_MASK) >> LAYOUT_DIRECTION_MASK_SHIFT; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5189 | } |
| 5190 | |
| 5191 | /** |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5192 | * Set the layout direction for this view. This will propagate a reset of layout direction |
| 5193 | * 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] | 5194 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5195 | * @param layoutDirection One of {@link #LAYOUT_DIRECTION_LTR}, |
| 5196 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 5197 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 5198 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5199 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5200 | * @attr ref android.R.styleable#View_layoutDirection |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5201 | */ |
| 5202 | @RemotableViewMethod |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5203 | public void setLayoutDirection(int layoutDirection) { |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5204 | if (getLayoutDirection() != layoutDirection) { |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 5205 | // Reset the current layout direction and the resolved one |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5206 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_MASK; |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 5207 | resetResolvedLayoutDirection(); |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5208 | // Set the new layout direction (filtered) and ask for a layout pass |
| 5209 | mPrivateFlags2 |= |
| 5210 | ((layoutDirection << LAYOUT_DIRECTION_MASK_SHIFT) & LAYOUT_DIRECTION_MASK); |
| 5211 | requestLayout(); |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5212 | } |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5213 | } |
| 5214 | |
| 5215 | /** |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5216 | * Returns the resolved layout direction for this view. |
| 5217 | * |
| 5218 | * @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] | 5219 | * {@link #LAYOUT_DIRECTION_LTR} if the layout direction is not RTL. |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5220 | */ |
| 5221 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5222 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"), |
| 5223 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL") |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5224 | }) |
| 5225 | public int getResolvedLayoutDirection() { |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 5226 | // The layout diretion will be resolved only if needed |
| 5227 | if ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED) != LAYOUT_DIRECTION_RESOLVED) { |
| 5228 | resolveLayoutDirection(); |
| 5229 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 5230 | return ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED_RTL) == LAYOUT_DIRECTION_RESOLVED_RTL) ? |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5231 | LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR; |
| 5232 | } |
| 5233 | |
| 5234 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5235 | * Indicates whether or not this view's layout is right-to-left. This is resolved from |
| 5236 | * layout attribute and/or the inherited value from the parent |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5237 | * |
| 5238 | * @return true if the layout is right-to-left. |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5239 | */ |
| 5240 | @ViewDebug.ExportedProperty(category = "layout") |
| 5241 | public boolean isLayoutRtl() { |
| 5242 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL); |
| 5243 | } |
| 5244 | |
| 5245 | /** |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5246 | * Indicates whether the view is currently tracking transient state that the |
| 5247 | * app should not need to concern itself with saving and restoring, but that |
| 5248 | * the framework should take special note to preserve when possible. |
| 5249 | * |
| 5250 | * @return true if the view has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5251 | */ |
| 5252 | @ViewDebug.ExportedProperty(category = "layout") |
| 5253 | public boolean hasTransientState() { |
| 5254 | return (mPrivateFlags2 & HAS_TRANSIENT_STATE) == HAS_TRANSIENT_STATE; |
| 5255 | } |
| 5256 | |
| 5257 | /** |
| 5258 | * Set whether this view is currently tracking transient state that the |
| 5259 | * framework should attempt to preserve when possible. |
| 5260 | * |
| 5261 | * @param hasTransientState true if this view has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5262 | */ |
| 5263 | public void setHasTransientState(boolean hasTransientState) { |
| 5264 | if (hasTransientState() == hasTransientState) return; |
| 5265 | |
| 5266 | mPrivateFlags2 = (mPrivateFlags2 & ~HAS_TRANSIENT_STATE) | |
| 5267 | (hasTransientState ? HAS_TRANSIENT_STATE : 0); |
| 5268 | if (mParent != null) { |
| 5269 | try { |
| 5270 | mParent.childHasTransientStateChanged(this, hasTransientState); |
| 5271 | } catch (AbstractMethodError e) { |
| 5272 | Log.e(VIEW_LOG_TAG, mParent.getClass().getSimpleName() + |
| 5273 | " does not fully implement ViewParent", e); |
| 5274 | } |
| 5275 | } |
| 5276 | } |
| 5277 | |
| 5278 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5279 | * If this view doesn't do any drawing on its own, set this flag to |
| 5280 | * allow further optimizations. By default, this flag is not set on |
| 5281 | * View, but could be set on some View subclasses such as ViewGroup. |
| 5282 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5283 | * Typically, if you override {@link #onDraw(android.graphics.Canvas)} |
| 5284 | * you should clear this flag. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5285 | * |
| 5286 | * @param willNotDraw whether or not this View draw on its own |
| 5287 | */ |
| 5288 | public void setWillNotDraw(boolean willNotDraw) { |
| 5289 | setFlags(willNotDraw ? WILL_NOT_DRAW : 0, DRAW_MASK); |
| 5290 | } |
| 5291 | |
| 5292 | /** |
| 5293 | * Returns whether or not this View draws on its own. |
| 5294 | * |
| 5295 | * @return true if this view has nothing to draw, false otherwise |
| 5296 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5297 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5298 | public boolean willNotDraw() { |
| 5299 | return (mViewFlags & DRAW_MASK) == WILL_NOT_DRAW; |
| 5300 | } |
| 5301 | |
| 5302 | /** |
| 5303 | * When a View's drawing cache is enabled, drawing is redirected to an |
| 5304 | * offscreen bitmap. Some views, like an ImageView, must be able to |
| 5305 | * bypass this mechanism if they already draw a single bitmap, to avoid |
| 5306 | * unnecessary usage of the memory. |
| 5307 | * |
| 5308 | * @param willNotCacheDrawing true if this view does not cache its |
| 5309 | * drawing, false otherwise |
| 5310 | */ |
| 5311 | public void setWillNotCacheDrawing(boolean willNotCacheDrawing) { |
| 5312 | setFlags(willNotCacheDrawing ? WILL_NOT_CACHE_DRAWING : 0, WILL_NOT_CACHE_DRAWING); |
| 5313 | } |
| 5314 | |
| 5315 | /** |
| 5316 | * Returns whether or not this View can cache its drawing or not. |
| 5317 | * |
| 5318 | * @return true if this view does not cache its drawing, false otherwise |
| 5319 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5320 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5321 | public boolean willNotCacheDrawing() { |
| 5322 | return (mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING; |
| 5323 | } |
| 5324 | |
| 5325 | /** |
| 5326 | * Indicates whether this view reacts to click events or not. |
| 5327 | * |
| 5328 | * @return true if the view is clickable, false otherwise |
| 5329 | * |
| 5330 | * @see #setClickable(boolean) |
| 5331 | * @attr ref android.R.styleable#View_clickable |
| 5332 | */ |
| 5333 | @ViewDebug.ExportedProperty |
| 5334 | public boolean isClickable() { |
| 5335 | return (mViewFlags & CLICKABLE) == CLICKABLE; |
| 5336 | } |
| 5337 | |
| 5338 | /** |
| 5339 | * Enables or disables click events for this view. When a view |
| 5340 | * is clickable it will change its state to "pressed" on every click. |
| 5341 | * Subclasses should set the view clickable to visually react to |
| 5342 | * user's clicks. |
| 5343 | * |
| 5344 | * @param clickable true to make the view clickable, false otherwise |
| 5345 | * |
| 5346 | * @see #isClickable() |
| 5347 | * @attr ref android.R.styleable#View_clickable |
| 5348 | */ |
| 5349 | public void setClickable(boolean clickable) { |
| 5350 | setFlags(clickable ? CLICKABLE : 0, CLICKABLE); |
| 5351 | } |
| 5352 | |
| 5353 | /** |
| 5354 | * Indicates whether this view reacts to long click events or not. |
| 5355 | * |
| 5356 | * @return true if the view is long clickable, false otherwise |
| 5357 | * |
| 5358 | * @see #setLongClickable(boolean) |
| 5359 | * @attr ref android.R.styleable#View_longClickable |
| 5360 | */ |
| 5361 | public boolean isLongClickable() { |
| 5362 | return (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 5363 | } |
| 5364 | |
| 5365 | /** |
| 5366 | * Enables or disables long click events for this view. When a view is long |
| 5367 | * clickable it reacts to the user holding down the button for a longer |
| 5368 | * duration than a tap. This event can either launch the listener or a |
| 5369 | * context menu. |
| 5370 | * |
| 5371 | * @param longClickable true to make the view long clickable, false otherwise |
| 5372 | * @see #isLongClickable() |
| 5373 | * @attr ref android.R.styleable#View_longClickable |
| 5374 | */ |
| 5375 | public void setLongClickable(boolean longClickable) { |
| 5376 | setFlags(longClickable ? LONG_CLICKABLE : 0, LONG_CLICKABLE); |
| 5377 | } |
| 5378 | |
| 5379 | /** |
Chet Haase | 49afa5b | 2010-08-23 11:39:53 -0700 | [diff] [blame] | 5380 | * Sets the pressed state for this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5381 | * |
| 5382 | * @see #isClickable() |
| 5383 | * @see #setClickable(boolean) |
| 5384 | * |
| 5385 | * @param pressed Pass true to set the View's internal state to "pressed", or false to reverts |
| 5386 | * the View's internal state from a previously set "pressed" state. |
| 5387 | */ |
| 5388 | public void setPressed(boolean pressed) { |
Adam Powell | 035a1fc | 2012-02-27 15:23:50 -0800 | [diff] [blame] | 5389 | final boolean needsRefresh = pressed != ((mPrivateFlags & PRESSED) == PRESSED); |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 5390 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5391 | if (pressed) { |
| 5392 | mPrivateFlags |= PRESSED; |
| 5393 | } else { |
| 5394 | mPrivateFlags &= ~PRESSED; |
| 5395 | } |
Adam Powell | 035a1fc | 2012-02-27 15:23:50 -0800 | [diff] [blame] | 5396 | |
| 5397 | if (needsRefresh) { |
| 5398 | refreshDrawableState(); |
| 5399 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5400 | dispatchSetPressed(pressed); |
| 5401 | } |
| 5402 | |
| 5403 | /** |
| 5404 | * Dispatch setPressed to all of this View's children. |
| 5405 | * |
| 5406 | * @see #setPressed(boolean) |
| 5407 | * |
| 5408 | * @param pressed The new pressed state |
| 5409 | */ |
| 5410 | protected void dispatchSetPressed(boolean pressed) { |
| 5411 | } |
| 5412 | |
| 5413 | /** |
| 5414 | * Indicates whether the view is currently in pressed state. Unless |
| 5415 | * {@link #setPressed(boolean)} is explicitly called, only clickable views can enter |
| 5416 | * the pressed state. |
| 5417 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5418 | * @see #setPressed(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5419 | * @see #isClickable() |
| 5420 | * @see #setClickable(boolean) |
| 5421 | * |
| 5422 | * @return true if the view is currently pressed, false otherwise |
| 5423 | */ |
| 5424 | public boolean isPressed() { |
| 5425 | return (mPrivateFlags & PRESSED) == PRESSED; |
| 5426 | } |
| 5427 | |
| 5428 | /** |
| 5429 | * Indicates whether this view will save its state (that is, |
| 5430 | * whether its {@link #onSaveInstanceState} method will be called). |
| 5431 | * |
| 5432 | * @return Returns true if the view state saving is enabled, else false. |
| 5433 | * |
| 5434 | * @see #setSaveEnabled(boolean) |
| 5435 | * @attr ref android.R.styleable#View_saveEnabled |
| 5436 | */ |
| 5437 | public boolean isSaveEnabled() { |
| 5438 | return (mViewFlags & SAVE_DISABLED_MASK) != SAVE_DISABLED; |
| 5439 | } |
| 5440 | |
| 5441 | /** |
| 5442 | * Controls whether the saving of this view's state is |
| 5443 | * enabled (that is, whether its {@link #onSaveInstanceState} method |
| 5444 | * will be called). Note that even if freezing is enabled, the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5445 | * 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] | 5446 | * for its state to be saved. This flag can only disable the |
| 5447 | * saving of this view; any child views may still have their state saved. |
| 5448 | * |
| 5449 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 5450 | * (the default) to allow it. |
| 5451 | * |
| 5452 | * @see #isSaveEnabled() |
| 5453 | * @see #setId(int) |
| 5454 | * @see #onSaveInstanceState() |
| 5455 | * @attr ref android.R.styleable#View_saveEnabled |
| 5456 | */ |
| 5457 | public void setSaveEnabled(boolean enabled) { |
| 5458 | setFlags(enabled ? 0 : SAVE_DISABLED, SAVE_DISABLED_MASK); |
| 5459 | } |
| 5460 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5461 | /** |
| 5462 | * Gets whether the framework should discard touches when the view's |
| 5463 | * window is obscured by another visible window. |
| 5464 | * Refer to the {@link View} security documentation for more details. |
| 5465 | * |
| 5466 | * @return True if touch filtering is enabled. |
| 5467 | * |
| 5468 | * @see #setFilterTouchesWhenObscured(boolean) |
| 5469 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 5470 | */ |
| 5471 | @ViewDebug.ExportedProperty |
| 5472 | public boolean getFilterTouchesWhenObscured() { |
| 5473 | return (mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0; |
| 5474 | } |
| 5475 | |
| 5476 | /** |
| 5477 | * Sets whether the framework should discard touches when the view's |
| 5478 | * window is obscured by another visible window. |
| 5479 | * Refer to the {@link View} security documentation for more details. |
| 5480 | * |
| 5481 | * @param enabled True if touch filtering should be enabled. |
| 5482 | * |
| 5483 | * @see #getFilterTouchesWhenObscured |
| 5484 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 5485 | */ |
| 5486 | public void setFilterTouchesWhenObscured(boolean enabled) { |
| 5487 | setFlags(enabled ? 0 : FILTER_TOUCHES_WHEN_OBSCURED, |
| 5488 | FILTER_TOUCHES_WHEN_OBSCURED); |
| 5489 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5490 | |
| 5491 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 5492 | * Indicates whether the entire hierarchy under this view will save its |
| 5493 | * state when a state saving traversal occurs from its parent. The default |
| 5494 | * is true; if false, these views will not be saved unless |
| 5495 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 5496 | * |
| 5497 | * @return Returns true if the view state saving from parent is enabled, else false. |
| 5498 | * |
| 5499 | * @see #setSaveFromParentEnabled(boolean) |
| 5500 | */ |
| 5501 | public boolean isSaveFromParentEnabled() { |
| 5502 | return (mViewFlags & PARENT_SAVE_DISABLED_MASK) != PARENT_SAVE_DISABLED; |
| 5503 | } |
| 5504 | |
| 5505 | /** |
| 5506 | * Controls whether the entire hierarchy under this view will save its |
| 5507 | * state when a state saving traversal occurs from its parent. The default |
| 5508 | * is true; if false, these views will not be saved unless |
| 5509 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 5510 | * |
| 5511 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 5512 | * (the default) to allow it. |
| 5513 | * |
| 5514 | * @see #isSaveFromParentEnabled() |
| 5515 | * @see #setId(int) |
| 5516 | * @see #onSaveInstanceState() |
| 5517 | */ |
| 5518 | public void setSaveFromParentEnabled(boolean enabled) { |
| 5519 | setFlags(enabled ? 0 : PARENT_SAVE_DISABLED, PARENT_SAVE_DISABLED_MASK); |
| 5520 | } |
| 5521 | |
| 5522 | |
| 5523 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5524 | * Returns whether this View is able to take focus. |
| 5525 | * |
| 5526 | * @return True if this view can take focus, or false otherwise. |
| 5527 | * @attr ref android.R.styleable#View_focusable |
| 5528 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5529 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5530 | public final boolean isFocusable() { |
| 5531 | return FOCUSABLE == (mViewFlags & FOCUSABLE_MASK); |
| 5532 | } |
| 5533 | |
| 5534 | /** |
| 5535 | * When a view is focusable, it may not want to take focus when in touch mode. |
| 5536 | * For example, a button would like focus when the user is navigating via a D-pad |
| 5537 | * so that the user can click on it, but once the user starts touching the screen, |
| 5538 | * the button shouldn't take focus |
| 5539 | * @return Whether the view is focusable in touch mode. |
| 5540 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 5541 | */ |
| 5542 | @ViewDebug.ExportedProperty |
| 5543 | public final boolean isFocusableInTouchMode() { |
| 5544 | return FOCUSABLE_IN_TOUCH_MODE == (mViewFlags & FOCUSABLE_IN_TOUCH_MODE); |
| 5545 | } |
| 5546 | |
| 5547 | /** |
| 5548 | * Find the nearest view in the specified direction that can take focus. |
| 5549 | * This does not actually give focus to that view. |
| 5550 | * |
| 5551 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 5552 | * |
| 5553 | * @return The nearest focusable in the specified direction, or null if none |
| 5554 | * can be found. |
| 5555 | */ |
| 5556 | public View focusSearch(int direction) { |
| 5557 | if (mParent != null) { |
| 5558 | return mParent.focusSearch(this, direction); |
| 5559 | } else { |
| 5560 | return null; |
| 5561 | } |
| 5562 | } |
| 5563 | |
| 5564 | /** |
| 5565 | * This method is the last chance for the focused view and its ancestors to |
| 5566 | * respond to an arrow key. This is called when the focused view did not |
| 5567 | * consume the key internally, nor could the view system find a new view in |
| 5568 | * the requested direction to give focus to. |
| 5569 | * |
| 5570 | * @param focused The currently focused view. |
| 5571 | * @param direction The direction focus wants to move. One of FOCUS_UP, |
| 5572 | * FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT. |
| 5573 | * @return True if the this view consumed this unhandled move. |
| 5574 | */ |
| 5575 | public boolean dispatchUnhandledMove(View focused, int direction) { |
| 5576 | return false; |
| 5577 | } |
| 5578 | |
| 5579 | /** |
| 5580 | * 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] | 5581 | * use the root to look up the view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5582 | * @param root The root view of the hierarchy containing this view. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5583 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, |
| 5584 | * or FOCUS_BACKWARD. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5585 | * @return The user specified next view, or null if there is none. |
| 5586 | */ |
| 5587 | View findUserSetNextFocus(View root, int direction) { |
| 5588 | switch (direction) { |
| 5589 | case FOCUS_LEFT: |
| 5590 | if (mNextFocusLeftId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5591 | return findViewInsideOutShouldExist(root, mNextFocusLeftId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5592 | case FOCUS_RIGHT: |
| 5593 | if (mNextFocusRightId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5594 | return findViewInsideOutShouldExist(root, mNextFocusRightId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5595 | case FOCUS_UP: |
| 5596 | if (mNextFocusUpId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5597 | return findViewInsideOutShouldExist(root, mNextFocusUpId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5598 | case FOCUS_DOWN: |
| 5599 | if (mNextFocusDownId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5600 | return findViewInsideOutShouldExist(root, mNextFocusDownId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5601 | case FOCUS_FORWARD: |
| 5602 | if (mNextFocusForwardId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5603 | return findViewInsideOutShouldExist(root, mNextFocusForwardId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5604 | case FOCUS_BACKWARD: { |
John Reck | 1ecebbb | 2012-03-06 16:08:54 -0800 | [diff] [blame] | 5605 | if (mID == View.NO_ID) return null; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5606 | final int id = mID; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5607 | return root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5608 | @Override |
| 5609 | public boolean apply(View t) { |
| 5610 | return t.mNextFocusForwardId == id; |
| 5611 | } |
| 5612 | }); |
| 5613 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5614 | } |
| 5615 | return null; |
| 5616 | } |
| 5617 | |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5618 | private View findViewInsideOutShouldExist(View root, final int childViewId) { |
| 5619 | View result = root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
| 5620 | @Override |
| 5621 | public boolean apply(View t) { |
| 5622 | return t.mID == childViewId; |
| 5623 | } |
| 5624 | }); |
| 5625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5626 | if (result == null) { |
| 5627 | Log.w(VIEW_LOG_TAG, "couldn't find next focus view specified " |
| 5628 | + "by user for id " + childViewId); |
| 5629 | } |
| 5630 | return result; |
| 5631 | } |
| 5632 | |
| 5633 | /** |
| 5634 | * Find and return all focusable views that are descendants of this view, |
| 5635 | * possibly including this view if it is focusable itself. |
| 5636 | * |
| 5637 | * @param direction The direction of the focus |
| 5638 | * @return A list of focusable views |
| 5639 | */ |
| 5640 | public ArrayList<View> getFocusables(int direction) { |
| 5641 | ArrayList<View> result = new ArrayList<View>(24); |
| 5642 | addFocusables(result, direction); |
| 5643 | return result; |
| 5644 | } |
| 5645 | |
| 5646 | /** |
| 5647 | * Add any focusable views that are descendants of this view (possibly |
| 5648 | * including this view if it is focusable itself) to views. If we are in touch mode, |
| 5649 | * only add views that are also focusable in touch mode. |
| 5650 | * |
| 5651 | * @param views Focusable views found so far |
| 5652 | * @param direction The direction of the focus |
| 5653 | */ |
| 5654 | public void addFocusables(ArrayList<View> views, int direction) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5655 | addFocusables(views, direction, FOCUSABLES_TOUCH_MODE); |
| 5656 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5657 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5658 | /** |
| 5659 | * Adds any focusable views that are descendants of this view (possibly |
| 5660 | * including this view if it is focusable itself) to views. This method |
| 5661 | * adds all focusable views regardless if we are in touch mode or |
| 5662 | * only views focusable in touch mode if we are in touch mode depending on |
| 5663 | * the focusable mode paramater. |
| 5664 | * |
| 5665 | * @param views Focusable views found so far or null if all we are interested is |
| 5666 | * the number of focusables. |
| 5667 | * @param direction The direction of the focus. |
| 5668 | * @param focusableMode The type of focusables to be added. |
| 5669 | * |
| 5670 | * @see #FOCUSABLES_ALL |
| 5671 | * @see #FOCUSABLES_TOUCH_MODE |
| 5672 | */ |
| 5673 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
| 5674 | if (!isFocusable()) { |
| 5675 | return; |
| 5676 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5677 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5678 | if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && |
| 5679 | isInTouchMode() && !isFocusableInTouchMode()) { |
| 5680 | return; |
| 5681 | } |
| 5682 | |
| 5683 | if (views != null) { |
| 5684 | views.add(this); |
| 5685 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5686 | } |
| 5687 | |
| 5688 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5689 | * Finds the Views that contain given text. The containment is case insensitive. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5690 | * The search is performed by either the text that the View renders or the content |
| 5691 | * description that describes the view for accessibility purposes and the view does |
| 5692 | * not render or both. Clients can specify how the search is to be performed via |
| 5693 | * passing the {@link #FIND_VIEWS_WITH_TEXT} and |
| 5694 | * {@link #FIND_VIEWS_WITH_CONTENT_DESCRIPTION} flags. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5695 | * |
| 5696 | * @param outViews The output list of matching Views. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5697 | * @param searched The text to match against. |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 5698 | * |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5699 | * @see #FIND_VIEWS_WITH_TEXT |
| 5700 | * @see #FIND_VIEWS_WITH_CONTENT_DESCRIPTION |
| 5701 | * @see #setContentDescription(CharSequence) |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5702 | */ |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5703 | public void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 5704 | if (getAccessibilityNodeProvider() != null) { |
| 5705 | if ((flags & FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS) != 0) { |
| 5706 | outViews.add(this); |
| 5707 | } |
| 5708 | } else if ((flags & FIND_VIEWS_WITH_CONTENT_DESCRIPTION) != 0 |
| 5709 | && !TextUtils.isEmpty(searched) && !TextUtils.isEmpty(mContentDescription)) { |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5710 | String searchedLowerCase = searched.toString().toLowerCase(); |
| 5711 | String contentDescriptionLowerCase = mContentDescription.toString().toLowerCase(); |
| 5712 | if (contentDescriptionLowerCase.contains(searchedLowerCase)) { |
| 5713 | outViews.add(this); |
| 5714 | } |
| 5715 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5716 | } |
| 5717 | |
| 5718 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5719 | * Find and return all touchable views that are descendants of this view, |
| 5720 | * possibly including this view if it is touchable itself. |
| 5721 | * |
| 5722 | * @return A list of touchable views |
| 5723 | */ |
| 5724 | public ArrayList<View> getTouchables() { |
| 5725 | ArrayList<View> result = new ArrayList<View>(); |
| 5726 | addTouchables(result); |
| 5727 | return result; |
| 5728 | } |
| 5729 | |
| 5730 | /** |
| 5731 | * Add any touchable views that are descendants of this view (possibly |
| 5732 | * including this view if it is touchable itself) to views. |
| 5733 | * |
| 5734 | * @param views Touchable views found so far |
| 5735 | */ |
| 5736 | public void addTouchables(ArrayList<View> views) { |
| 5737 | final int viewFlags = mViewFlags; |
| 5738 | |
| 5739 | if (((viewFlags & CLICKABLE) == CLICKABLE || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) |
| 5740 | && (viewFlags & ENABLED_MASK) == ENABLED) { |
| 5741 | views.add(this); |
| 5742 | } |
| 5743 | } |
| 5744 | |
| 5745 | /** |
| 5746 | * Call this to try to give focus to a specific view or to one of its |
| 5747 | * descendants. |
| 5748 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5749 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 5750 | * false), or if it is focusable and it is not focusable in touch mode |
| 5751 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5752 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5753 | * 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] | 5754 | * have focus, and you want your parent to look for the next one. |
| 5755 | * |
| 5756 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with arguments |
| 5757 | * {@link #FOCUS_DOWN} and <code>null</code>. |
| 5758 | * |
| 5759 | * @return Whether this view or one of its descendants actually took focus. |
| 5760 | */ |
| 5761 | public final boolean requestFocus() { |
| 5762 | return requestFocus(View.FOCUS_DOWN); |
| 5763 | } |
| 5764 | |
| 5765 | |
| 5766 | /** |
| 5767 | * Call this to try to give focus to a specific view or to one of its |
| 5768 | * descendants and give it a hint about what direction focus is heading. |
| 5769 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5770 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 5771 | * false), or if it is focusable and it is not focusable in touch mode |
| 5772 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5773 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5774 | * 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] | 5775 | * have focus, and you want your parent to look for the next one. |
| 5776 | * |
| 5777 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with |
| 5778 | * <code>null</code> set for the previously focused rectangle. |
| 5779 | * |
| 5780 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 5781 | * @return Whether this view or one of its descendants actually took focus. |
| 5782 | */ |
| 5783 | public final boolean requestFocus(int direction) { |
| 5784 | return requestFocus(direction, null); |
| 5785 | } |
| 5786 | |
| 5787 | /** |
| 5788 | * Call this to try to give focus to a specific view or to one of its descendants |
| 5789 | * and give it hints about the direction and a specific rectangle that the focus |
| 5790 | * is coming from. The rectangle can help give larger views a finer grained hint |
| 5791 | * about where focus is coming from, and therefore, where to show selection, or |
| 5792 | * forward focus change internally. |
| 5793 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5794 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 5795 | * false), or if it is focusable and it is not focusable in touch mode |
| 5796 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5797 | * |
| 5798 | * A View will not take focus if it is not visible. |
| 5799 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5800 | * A View will not take focus if one of its parents has |
| 5801 | * {@link android.view.ViewGroup#getDescendantFocusability()} equal to |
| 5802 | * {@link ViewGroup#FOCUS_BLOCK_DESCENDANTS}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5803 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5804 | * 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] | 5805 | * have focus, and you want your parent to look for the next one. |
| 5806 | * |
| 5807 | * You may wish to override this method if your custom {@link View} has an internal |
| 5808 | * {@link View} that it wishes to forward the request to. |
| 5809 | * |
| 5810 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 5811 | * @param previouslyFocusedRect The rectangle (in this View's coordinate system) |
| 5812 | * to give a finer grained hint about where focus is coming from. May be null |
| 5813 | * if there is no hint. |
| 5814 | * @return Whether this view or one of its descendants actually took focus. |
| 5815 | */ |
| 5816 | public boolean requestFocus(int direction, Rect previouslyFocusedRect) { |
| 5817 | // need to be focusable |
| 5818 | if ((mViewFlags & FOCUSABLE_MASK) != FOCUSABLE || |
| 5819 | (mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 5820 | return false; |
| 5821 | } |
| 5822 | |
| 5823 | // need to be focusable in touch mode if in touch mode |
| 5824 | if (isInTouchMode() && |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5825 | (FOCUSABLE_IN_TOUCH_MODE != (mViewFlags & FOCUSABLE_IN_TOUCH_MODE))) { |
| 5826 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5827 | } |
| 5828 | |
| 5829 | // need to not have any parents blocking us |
| 5830 | if (hasAncestorThatBlocksDescendantFocus()) { |
| 5831 | return false; |
| 5832 | } |
| 5833 | |
| 5834 | handleFocusGainInternal(direction, previouslyFocusedRect); |
| 5835 | return true; |
| 5836 | } |
| 5837 | |
| 5838 | /** |
| 5839 | * Call this to try to give focus to a specific view or to one of its descendants. This is a |
| 5840 | * special variant of {@link #requestFocus() } that will allow views that are not focuable in |
| 5841 | * touch mode to request focus when they are touched. |
| 5842 | * |
| 5843 | * @return Whether this view or one of its descendants actually took focus. |
| 5844 | * |
| 5845 | * @see #isInTouchMode() |
| 5846 | * |
| 5847 | */ |
| 5848 | public final boolean requestFocusFromTouch() { |
| 5849 | // Leave touch mode if we need to |
| 5850 | if (isInTouchMode()) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 5851 | ViewRootImpl viewRoot = getViewRootImpl(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5852 | if (viewRoot != null) { |
| 5853 | viewRoot.ensureTouchMode(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5854 | } |
| 5855 | } |
| 5856 | return requestFocus(View.FOCUS_DOWN); |
| 5857 | } |
| 5858 | |
| 5859 | /** |
| 5860 | * @return Whether any ancestor of this view blocks descendant focus. |
| 5861 | */ |
| 5862 | private boolean hasAncestorThatBlocksDescendantFocus() { |
| 5863 | ViewParent ancestor = mParent; |
| 5864 | while (ancestor instanceof ViewGroup) { |
| 5865 | final ViewGroup vgAncestor = (ViewGroup) ancestor; |
| 5866 | if (vgAncestor.getDescendantFocusability() == ViewGroup.FOCUS_BLOCK_DESCENDANTS) { |
| 5867 | return true; |
| 5868 | } else { |
| 5869 | ancestor = vgAncestor.getParent(); |
| 5870 | } |
| 5871 | } |
| 5872 | return false; |
| 5873 | } |
| 5874 | |
| 5875 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5876 | * @hide |
| 5877 | */ |
| 5878 | public void dispatchStartTemporaryDetach() { |
| 5879 | onStartTemporaryDetach(); |
| 5880 | } |
| 5881 | |
| 5882 | /** |
| 5883 | * 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] | 5884 | * {@link ViewGroup#detachViewFromParent(View) ViewGroup.detachViewFromParent}. |
| 5885 | * It will either be followed by {@link #onFinishTemporaryDetach()} or |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5886 | * {@link #onDetachedFromWindow()} when the container is done. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5887 | */ |
| 5888 | public void onStartTemporaryDetach() { |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5889 | removeUnsetPressCallback(); |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 5890 | mPrivateFlags |= CANCEL_NEXT_UP_EVENT; |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5891 | } |
| 5892 | |
| 5893 | /** |
| 5894 | * @hide |
| 5895 | */ |
| 5896 | public void dispatchFinishTemporaryDetach() { |
| 5897 | onFinishTemporaryDetach(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5898 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5899 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5900 | /** |
| 5901 | * Called after {@link #onStartTemporaryDetach} when the container is done |
| 5902 | * changing the view. |
| 5903 | */ |
| 5904 | public void onFinishTemporaryDetach() { |
| 5905 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5906 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5907 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5908 | * Return the global {@link KeyEvent.DispatcherState KeyEvent.DispatcherState} |
| 5909 | * for this view's window. Returns null if the view is not currently attached |
| 5910 | * 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] | 5911 | * just use the standard high-level event callbacks like |
| 5912 | * {@link #onKeyDown(int, KeyEvent)}. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5913 | */ |
| 5914 | public KeyEvent.DispatcherState getKeyDispatcherState() { |
| 5915 | return mAttachInfo != null ? mAttachInfo.mKeyDispatchState : null; |
| 5916 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 5917 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5918 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5919 | * Dispatch a key event before it is processed by any input method |
| 5920 | * associated with the view hierarchy. This can be used to intercept |
| 5921 | * key events in special situations before the IME consumes them; a |
| 5922 | * typical example would be handling the BACK key to update the application's |
| 5923 | * UI instead of allowing the IME to see it and close itself. |
| 5924 | * |
| 5925 | * @param event The key event to be dispatched. |
| 5926 | * @return True if the event was handled, false otherwise. |
| 5927 | */ |
| 5928 | public boolean dispatchKeyEventPreIme(KeyEvent event) { |
| 5929 | return onKeyPreIme(event.getKeyCode(), event); |
| 5930 | } |
| 5931 | |
| 5932 | /** |
| 5933 | * Dispatch a key event to the next view on the focus path. This path runs |
| 5934 | * from the top of the view tree down to the currently focused view. If this |
| 5935 | * view has focus, it will dispatch to itself. Otherwise it will dispatch |
| 5936 | * the next node down the focus path. This method also fires any key |
| 5937 | * listeners. |
| 5938 | * |
| 5939 | * @param event The key event to be dispatched. |
| 5940 | * @return True if the event was handled, false otherwise. |
| 5941 | */ |
| 5942 | public boolean dispatchKeyEvent(KeyEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5943 | if (mInputEventConsistencyVerifier != null) { |
| 5944 | mInputEventConsistencyVerifier.onKeyEvent(event, 0); |
| 5945 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5946 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5947 | // Give any attached key listener a first crack at the event. |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 5948 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 5949 | ListenerInfo li = mListenerInfo; |
| 5950 | if (li != null && li.mOnKeyListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5951 | && li.mOnKeyListener.onKey(this, event.getKeyCode(), event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5952 | return true; |
| 5953 | } |
| 5954 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5955 | if (event.dispatch(this, mAttachInfo != null |
| 5956 | ? mAttachInfo.mKeyDispatchState : null, this)) { |
| 5957 | return true; |
| 5958 | } |
| 5959 | |
| 5960 | if (mInputEventConsistencyVerifier != null) { |
| 5961 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 5962 | } |
| 5963 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5964 | } |
| 5965 | |
| 5966 | /** |
| 5967 | * Dispatches a key shortcut event. |
| 5968 | * |
| 5969 | * @param event The key event to be dispatched. |
| 5970 | * @return True if the event was handled by the view, false otherwise. |
| 5971 | */ |
| 5972 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 5973 | return onKeyShortcut(event.getKeyCode(), event); |
| 5974 | } |
| 5975 | |
| 5976 | /** |
| 5977 | * Pass the touch screen motion event down to the target view, or this |
| 5978 | * view if it is the target. |
| 5979 | * |
| 5980 | * @param event The motion event to be dispatched. |
| 5981 | * @return True if the event was handled by the view, false otherwise. |
| 5982 | */ |
| 5983 | public boolean dispatchTouchEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5984 | if (mInputEventConsistencyVerifier != null) { |
| 5985 | mInputEventConsistencyVerifier.onTouchEvent(event, 0); |
| 5986 | } |
| 5987 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5988 | if (onFilterTouchEventForSecurity(event)) { |
| 5989 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 5990 | ListenerInfo li = mListenerInfo; |
| 5991 | if (li != null && li.mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5992 | && li.mOnTouchListener.onTouch(this, event)) { |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5993 | return true; |
| 5994 | } |
| 5995 | |
| 5996 | if (onTouchEvent(event)) { |
| 5997 | return true; |
| 5998 | } |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5999 | } |
| 6000 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6001 | if (mInputEventConsistencyVerifier != null) { |
| 6002 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6003 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6004 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6005 | } |
| 6006 | |
| 6007 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 6008 | * Filter the touch event to apply security policies. |
| 6009 | * |
| 6010 | * @param event The motion event to be filtered. |
| 6011 | * @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] | 6012 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 6013 | * @see #getFilterTouchesWhenObscured |
| 6014 | */ |
| 6015 | public boolean onFilterTouchEventForSecurity(MotionEvent event) { |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 6016 | //noinspection RedundantIfStatement |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 6017 | if ((mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0 |
| 6018 | && (event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) { |
| 6019 | // Window is obscured, drop this touch. |
| 6020 | return false; |
| 6021 | } |
| 6022 | return true; |
| 6023 | } |
| 6024 | |
| 6025 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6026 | * Pass a trackball motion event down to the focused view. |
| 6027 | * |
| 6028 | * @param event The motion event to be dispatched. |
| 6029 | * @return True if the event was handled by the view, false otherwise. |
| 6030 | */ |
| 6031 | public boolean dispatchTrackballEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 6032 | if (mInputEventConsistencyVerifier != null) { |
| 6033 | mInputEventConsistencyVerifier.onTrackballEvent(event, 0); |
| 6034 | } |
| 6035 | |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 6036 | return onTrackballEvent(event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6037 | } |
| 6038 | |
| 6039 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6040 | * Dispatch a generic motion event. |
| 6041 | * <p> |
| 6042 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 6043 | * 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] | 6044 | * 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] | 6045 | * to {@link #onHoverEvent(MotionEvent)}. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6046 | * </p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6047 | * |
| 6048 | * @param event The motion event to be dispatched. |
| 6049 | * @return True if the event was handled by the view, false otherwise. |
| 6050 | */ |
| 6051 | public boolean dispatchGenericMotionEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 6052 | if (mInputEventConsistencyVerifier != null) { |
| 6053 | mInputEventConsistencyVerifier.onGenericMotionEvent(event, 0); |
| 6054 | } |
| 6055 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6056 | final int source = event.getSource(); |
| 6057 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 6058 | final int action = event.getAction(); |
| 6059 | if (action == MotionEvent.ACTION_HOVER_ENTER |
| 6060 | || action == MotionEvent.ACTION_HOVER_MOVE |
| 6061 | || action == MotionEvent.ACTION_HOVER_EXIT) { |
| 6062 | if (dispatchHoverEvent(event)) { |
| 6063 | return true; |
| 6064 | } |
| 6065 | } else if (dispatchGenericPointerEvent(event)) { |
| 6066 | return true; |
| 6067 | } |
| 6068 | } else if (dispatchGenericFocusedEvent(event)) { |
| 6069 | return true; |
| 6070 | } |
| 6071 | |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6072 | if (dispatchGenericMotionEventInternal(event)) { |
| 6073 | return true; |
| 6074 | } |
| 6075 | |
| 6076 | if (mInputEventConsistencyVerifier != null) { |
| 6077 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 6078 | } |
| 6079 | return false; |
| 6080 | } |
| 6081 | |
| 6082 | private boolean dispatchGenericMotionEventInternal(MotionEvent event) { |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 6083 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6084 | ListenerInfo li = mListenerInfo; |
| 6085 | if (li != null && li.mOnGenericMotionListener != null |
| 6086 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 6087 | && li.mOnGenericMotionListener.onGenericMotion(this, event)) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6088 | return true; |
| 6089 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6090 | |
| 6091 | if (onGenericMotionEvent(event)) { |
| 6092 | return true; |
| 6093 | } |
| 6094 | |
| 6095 | if (mInputEventConsistencyVerifier != null) { |
| 6096 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 6097 | } |
| 6098 | return false; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6099 | } |
| 6100 | |
| 6101 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6102 | * Dispatch a hover event. |
| 6103 | * <p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 6104 | * Do not call this method directly. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6105 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6106 | * </p> |
| 6107 | * |
| 6108 | * @param event The motion event to be dispatched. |
| 6109 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6110 | */ |
| 6111 | protected boolean dispatchHoverEvent(MotionEvent event) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 6112 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6113 | ListenerInfo li = mListenerInfo; |
| 6114 | if (li != null && li.mOnHoverListener != null |
| 6115 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 6116 | && li.mOnHoverListener.onHover(this, event)) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6117 | return true; |
| 6118 | } |
| 6119 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6120 | return onHoverEvent(event); |
| 6121 | } |
| 6122 | |
| 6123 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6124 | * Returns true if the view has a child to which it has recently sent |
| 6125 | * {@link MotionEvent#ACTION_HOVER_ENTER}. If this view is hovered and |
| 6126 | * it does not have a hovered child, then it must be the innermost hovered view. |
| 6127 | * @hide |
| 6128 | */ |
| 6129 | protected boolean hasHoveredChild() { |
| 6130 | return false; |
| 6131 | } |
| 6132 | |
| 6133 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6134 | * Dispatch a generic motion event to the view under the first pointer. |
| 6135 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6136 | * Do not call this method directly. |
| 6137 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6138 | * </p> |
| 6139 | * |
| 6140 | * @param event The motion event to be dispatched. |
| 6141 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6142 | */ |
| 6143 | protected boolean dispatchGenericPointerEvent(MotionEvent event) { |
| 6144 | return false; |
| 6145 | } |
| 6146 | |
| 6147 | /** |
| 6148 | * Dispatch a generic motion event to the currently focused view. |
| 6149 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6150 | * Do not call this method directly. |
| 6151 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6152 | * </p> |
| 6153 | * |
| 6154 | * @param event The motion event to be dispatched. |
| 6155 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6156 | */ |
| 6157 | protected boolean dispatchGenericFocusedEvent(MotionEvent event) { |
| 6158 | return false; |
| 6159 | } |
| 6160 | |
| 6161 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6162 | * Dispatch a pointer event. |
| 6163 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6164 | * Dispatches touch related pointer events to {@link #onTouchEvent(MotionEvent)} and all |
| 6165 | * other events to {@link #onGenericMotionEvent(MotionEvent)}. This separation of concerns |
| 6166 | * reinforces the invariant that {@link #onTouchEvent(MotionEvent)} is really about touches |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6167 | * and should not be expected to handle other pointing device features. |
| 6168 | * </p> |
| 6169 | * |
| 6170 | * @param event The motion event to be dispatched. |
| 6171 | * @return True if the event was handled by the view, false otherwise. |
| 6172 | * @hide |
| 6173 | */ |
| 6174 | public final boolean dispatchPointerEvent(MotionEvent event) { |
| 6175 | if (event.isTouchEvent()) { |
| 6176 | return dispatchTouchEvent(event); |
| 6177 | } else { |
| 6178 | return dispatchGenericMotionEvent(event); |
| 6179 | } |
| 6180 | } |
| 6181 | |
| 6182 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6183 | * Called when the window containing this view gains or loses window focus. |
| 6184 | * ViewGroups should override to route to their children. |
| 6185 | * |
| 6186 | * @param hasFocus True if the window containing this view now has focus, |
| 6187 | * false otherwise. |
| 6188 | */ |
| 6189 | public void dispatchWindowFocusChanged(boolean hasFocus) { |
| 6190 | onWindowFocusChanged(hasFocus); |
| 6191 | } |
| 6192 | |
| 6193 | /** |
| 6194 | * Called when the window containing this view gains or loses focus. Note |
| 6195 | * that this is separate from view focus: to receive key events, both |
| 6196 | * your view and its window must have focus. If a window is displayed |
| 6197 | * on top of yours that takes input focus, then your own window will lose |
| 6198 | * focus but the view focus will remain unchanged. |
| 6199 | * |
| 6200 | * @param hasWindowFocus True if the window containing this view now has |
| 6201 | * focus, false otherwise. |
| 6202 | */ |
| 6203 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 6204 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 6205 | if (!hasWindowFocus) { |
| 6206 | if (isPressed()) { |
| 6207 | setPressed(false); |
| 6208 | } |
| 6209 | if (imm != null && (mPrivateFlags & FOCUSED) != 0) { |
| 6210 | imm.focusOut(this); |
| 6211 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6212 | removeLongPressCallback(); |
Tony Wu | 26edf20 | 2010-09-13 19:54:00 +0800 | [diff] [blame] | 6213 | removeTapCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 6214 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6215 | } else if (imm != null && (mPrivateFlags & FOCUSED) != 0) { |
| 6216 | imm.focusIn(this); |
| 6217 | } |
| 6218 | refreshDrawableState(); |
| 6219 | } |
| 6220 | |
| 6221 | /** |
| 6222 | * Returns true if this view is in a window that currently has window focus. |
| 6223 | * Note that this is not the same as the view itself having focus. |
| 6224 | * |
| 6225 | * @return True if this view is in a window that currently has window focus. |
| 6226 | */ |
| 6227 | public boolean hasWindowFocus() { |
| 6228 | return mAttachInfo != null && mAttachInfo.mHasWindowFocus; |
| 6229 | } |
| 6230 | |
| 6231 | /** |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6232 | * Dispatch a view visibility change down the view hierarchy. |
| 6233 | * ViewGroups should override to route to their children. |
| 6234 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 6235 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6236 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 6237 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6238 | */ |
| 6239 | protected void dispatchVisibilityChanged(View changedView, int visibility) { |
| 6240 | onVisibilityChanged(changedView, visibility); |
| 6241 | } |
| 6242 | |
| 6243 | /** |
| 6244 | * Called when the visibility of the view or an ancestor of the view is changed. |
| 6245 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 6246 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6247 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 6248 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6249 | */ |
| 6250 | protected void onVisibilityChanged(View changedView, int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 6251 | if (visibility == VISIBLE) { |
| 6252 | if (mAttachInfo != null) { |
| 6253 | initialAwakenScrollBars(); |
| 6254 | } else { |
| 6255 | mPrivateFlags |= AWAKEN_SCROLL_BARS_ON_ATTACH; |
| 6256 | } |
| 6257 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6258 | } |
| 6259 | |
| 6260 | /** |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6261 | * Dispatch a hint about whether this view is displayed. For instance, when |
| 6262 | * a View moves out of the screen, it might receives a display hint indicating |
| 6263 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 6264 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6265 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6266 | * @param hint A hint about whether or not this view is displayed: |
| 6267 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 6268 | */ |
| 6269 | public void dispatchDisplayHint(int hint) { |
| 6270 | onDisplayHint(hint); |
| 6271 | } |
| 6272 | |
| 6273 | /** |
| 6274 | * Gives this view a hint about whether is displayed or not. For instance, when |
| 6275 | * a View moves out of the screen, it might receives a display hint indicating |
| 6276 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 6277 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6278 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6279 | * @param hint A hint about whether or not this view is displayed: |
| 6280 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 6281 | */ |
| 6282 | protected void onDisplayHint(int hint) { |
| 6283 | } |
| 6284 | |
| 6285 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6286 | * Dispatch a window visibility change down the view hierarchy. |
| 6287 | * ViewGroups should override to route to their children. |
| 6288 | * |
| 6289 | * @param visibility The new visibility of the window. |
| 6290 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 6291 | * @see #onWindowVisibilityChanged(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6292 | */ |
| 6293 | public void dispatchWindowVisibilityChanged(int visibility) { |
| 6294 | onWindowVisibilityChanged(visibility); |
| 6295 | } |
| 6296 | |
| 6297 | /** |
| 6298 | * Called when the window containing has change its visibility |
| 6299 | * (between {@link #GONE}, {@link #INVISIBLE}, and {@link #VISIBLE}). Note |
| 6300 | * that this tells you whether or not your window is being made visible |
| 6301 | * to the window manager; this does <em>not</em> tell you whether or not |
| 6302 | * your window is obscured by other windows on the screen, even if it |
| 6303 | * is itself visible. |
| 6304 | * |
| 6305 | * @param visibility The new visibility of the window. |
| 6306 | */ |
| 6307 | protected void onWindowVisibilityChanged(int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 6308 | if (visibility == VISIBLE) { |
| 6309 | initialAwakenScrollBars(); |
| 6310 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6311 | } |
| 6312 | |
| 6313 | /** |
| 6314 | * Returns the current visibility of the window this view is attached to |
| 6315 | * (either {@link #GONE}, {@link #INVISIBLE}, or {@link #VISIBLE}). |
| 6316 | * |
| 6317 | * @return Returns the current visibility of the view's window. |
| 6318 | */ |
| 6319 | public int getWindowVisibility() { |
| 6320 | return mAttachInfo != null ? mAttachInfo.mWindowVisibility : GONE; |
| 6321 | } |
| 6322 | |
| 6323 | /** |
| 6324 | * Retrieve the overall visible display size in which the window this view is |
| 6325 | * attached to has been positioned in. This takes into account screen |
| 6326 | * decorations above the window, for both cases where the window itself |
| 6327 | * is being position inside of them or the window is being placed under |
| 6328 | * then and covered insets are used for the window to position its content |
| 6329 | * inside. In effect, this tells you the available area where content can |
| 6330 | * be placed and remain visible to users. |
| 6331 | * |
| 6332 | * <p>This function requires an IPC back to the window manager to retrieve |
| 6333 | * the requested information, so should not be used in performance critical |
| 6334 | * code like drawing. |
| 6335 | * |
| 6336 | * @param outRect Filled in with the visible display frame. If the view |
| 6337 | * is not attached to a window, this is simply the raw display size. |
| 6338 | */ |
| 6339 | public void getWindowVisibleDisplayFrame(Rect outRect) { |
| 6340 | if (mAttachInfo != null) { |
| 6341 | try { |
| 6342 | mAttachInfo.mSession.getDisplayFrame(mAttachInfo.mWindow, outRect); |
| 6343 | } catch (RemoteException e) { |
| 6344 | return; |
| 6345 | } |
| 6346 | // XXX This is really broken, and probably all needs to be done |
| 6347 | // in the window manager, and we need to know more about whether |
| 6348 | // we want the area behind or in front of the IME. |
| 6349 | final Rect insets = mAttachInfo.mVisibleInsets; |
| 6350 | outRect.left += insets.left; |
| 6351 | outRect.top += insets.top; |
| 6352 | outRect.right -= insets.right; |
| 6353 | outRect.bottom -= insets.bottom; |
| 6354 | return; |
| 6355 | } |
| 6356 | Display d = WindowManagerImpl.getDefault().getDefaultDisplay(); |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 6357 | d.getRectSize(outRect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6358 | } |
| 6359 | |
| 6360 | /** |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6361 | * Dispatch a notification about a resource configuration change down |
| 6362 | * the view hierarchy. |
| 6363 | * ViewGroups should override to route to their children. |
| 6364 | * |
| 6365 | * @param newConfig The new resource configuration. |
| 6366 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 6367 | * @see #onConfigurationChanged(android.content.res.Configuration) |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6368 | */ |
| 6369 | public void dispatchConfigurationChanged(Configuration newConfig) { |
| 6370 | onConfigurationChanged(newConfig); |
| 6371 | } |
| 6372 | |
| 6373 | /** |
| 6374 | * Called when the current configuration of the resources being used |
| 6375 | * by the application have changed. You can use this to decide when |
| 6376 | * to reload resources that can changed based on orientation and other |
| 6377 | * configuration characterstics. You only need to use this if you are |
| 6378 | * not relying on the normal {@link android.app.Activity} mechanism of |
| 6379 | * recreating the activity instance upon a configuration change. |
| 6380 | * |
| 6381 | * @param newConfig The new resource configuration. |
| 6382 | */ |
| 6383 | protected void onConfigurationChanged(Configuration newConfig) { |
| 6384 | } |
| 6385 | |
| 6386 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6387 | * Private function to aggregate all per-view attributes in to the view |
| 6388 | * root. |
| 6389 | */ |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6390 | void dispatchCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 6391 | performCollectViewAttributes(attachInfo, visibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6392 | } |
| 6393 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6394 | void performCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 6395 | if ((visibility & VISIBILITY_MASK) == VISIBLE) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6396 | if ((mViewFlags & KEEP_SCREEN_ON) == KEEP_SCREEN_ON) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6397 | attachInfo.mKeepScreenOn = true; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6398 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6399 | attachInfo.mSystemUiVisibility |= mSystemUiVisibility; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6400 | ListenerInfo li = mListenerInfo; |
| 6401 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6402 | attachInfo.mHasSystemUiListeners = true; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6403 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6404 | } |
| 6405 | } |
| 6406 | |
| 6407 | void needGlobalAttributesUpdate(boolean force) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6408 | final AttachInfo ai = mAttachInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6409 | if (ai != null) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6410 | if (force || ai.mKeepScreenOn || (ai.mSystemUiVisibility != 0) |
| 6411 | || ai.mHasSystemUiListeners) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6412 | ai.mRecomputeGlobalAttributes = true; |
| 6413 | } |
| 6414 | } |
| 6415 | } |
| 6416 | |
| 6417 | /** |
| 6418 | * Returns whether the device is currently in touch mode. Touch mode is entered |
| 6419 | * once the user begins interacting with the device by touch, and affects various |
| 6420 | * things like whether focus is always visible to the user. |
| 6421 | * |
| 6422 | * @return Whether the device is in touch mode. |
| 6423 | */ |
| 6424 | @ViewDebug.ExportedProperty |
| 6425 | public boolean isInTouchMode() { |
| 6426 | if (mAttachInfo != null) { |
| 6427 | return mAttachInfo.mInTouchMode; |
| 6428 | } else { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6429 | return ViewRootImpl.isInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6430 | } |
| 6431 | } |
| 6432 | |
| 6433 | /** |
| 6434 | * Returns the context the view is running in, through which it can |
| 6435 | * access the current theme, resources, etc. |
| 6436 | * |
| 6437 | * @return The view's Context. |
| 6438 | */ |
| 6439 | @ViewDebug.CapturedViewProperty |
| 6440 | public final Context getContext() { |
| 6441 | return mContext; |
| 6442 | } |
| 6443 | |
| 6444 | /** |
| 6445 | * Handle a key event before it is processed by any input method |
| 6446 | * associated with the view hierarchy. This can be used to intercept |
| 6447 | * key events in special situations before the IME consumes them; a |
| 6448 | * typical example would be handling the BACK key to update the application's |
| 6449 | * UI instead of allowing the IME to see it and close itself. |
| 6450 | * |
| 6451 | * @param keyCode The value in event.getKeyCode(). |
| 6452 | * @param event Description of the key event. |
| 6453 | * @return If you handled the event, return true. If you want to allow the |
| 6454 | * event to be handled by the next receiver, return false. |
| 6455 | */ |
| 6456 | public boolean onKeyPreIme(int keyCode, KeyEvent event) { |
| 6457 | return false; |
| 6458 | } |
| 6459 | |
| 6460 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 6461 | * Default implementation of {@link KeyEvent.Callback#onKeyDown(int, KeyEvent) |
| 6462 | * KeyEvent.Callback.onKeyDown()}: perform press of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6463 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or {@link KeyEvent#KEYCODE_ENTER} |
| 6464 | * is released, if the view is enabled and clickable. |
| 6465 | * |
| 6466 | * @param keyCode A key code that represents the button pressed, from |
| 6467 | * {@link android.view.KeyEvent}. |
| 6468 | * @param event The KeyEvent object that defines the button action. |
| 6469 | */ |
| 6470 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 6471 | boolean result = false; |
| 6472 | |
| 6473 | switch (keyCode) { |
| 6474 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 6475 | case KeyEvent.KEYCODE_ENTER: { |
| 6476 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 6477 | return true; |
| 6478 | } |
| 6479 | // Long clickable items don't necessarily have to be clickable |
| 6480 | if (((mViewFlags & CLICKABLE) == CLICKABLE || |
| 6481 | (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) && |
| 6482 | (event.getRepeatCount() == 0)) { |
| 6483 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6484 | checkForLongClick(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6485 | return true; |
| 6486 | } |
| 6487 | break; |
| 6488 | } |
| 6489 | } |
| 6490 | return result; |
| 6491 | } |
| 6492 | |
| 6493 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6494 | * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
| 6495 | * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle |
| 6496 | * the event). |
| 6497 | */ |
| 6498 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 6499 | return false; |
| 6500 | } |
| 6501 | |
| 6502 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 6503 | * Default implementation of {@link KeyEvent.Callback#onKeyUp(int, KeyEvent) |
| 6504 | * KeyEvent.Callback.onKeyUp()}: perform clicking of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6505 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or |
| 6506 | * {@link KeyEvent#KEYCODE_ENTER} is released. |
| 6507 | * |
| 6508 | * @param keyCode A key code that represents the button pressed, from |
| 6509 | * {@link android.view.KeyEvent}. |
| 6510 | * @param event The KeyEvent object that defines the button action. |
| 6511 | */ |
| 6512 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 6513 | boolean result = false; |
| 6514 | |
| 6515 | switch (keyCode) { |
| 6516 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 6517 | case KeyEvent.KEYCODE_ENTER: { |
| 6518 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 6519 | return true; |
| 6520 | } |
| 6521 | if ((mViewFlags & CLICKABLE) == CLICKABLE && isPressed()) { |
| 6522 | setPressed(false); |
| 6523 | |
| 6524 | if (!mHasPerformedLongPress) { |
| 6525 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6526 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6527 | |
| 6528 | result = performClick(); |
| 6529 | } |
| 6530 | } |
| 6531 | break; |
| 6532 | } |
| 6533 | } |
| 6534 | return result; |
| 6535 | } |
| 6536 | |
| 6537 | /** |
| 6538 | * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) |
| 6539 | * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle |
| 6540 | * the event). |
| 6541 | * |
| 6542 | * @param keyCode A key code that represents the button pressed, from |
| 6543 | * {@link android.view.KeyEvent}. |
| 6544 | * @param repeatCount The number of times the action was made. |
| 6545 | * @param event The KeyEvent object that defines the button action. |
| 6546 | */ |
| 6547 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 6548 | return false; |
| 6549 | } |
| 6550 | |
| 6551 | /** |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 6552 | * Called on the focused view when a key shortcut event is not handled. |
| 6553 | * Override this method to implement local key shortcuts for the View. |
| 6554 | * Key shortcuts can also be implemented by setting the |
| 6555 | * {@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] | 6556 | * |
| 6557 | * @param keyCode The value in event.getKeyCode(). |
| 6558 | * @param event Description of the key event. |
| 6559 | * @return If you handled the event, return true. If you want to allow the |
| 6560 | * event to be handled by the next receiver, return false. |
| 6561 | */ |
| 6562 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
| 6563 | return false; |
| 6564 | } |
| 6565 | |
| 6566 | /** |
| 6567 | * Check whether the called view is a text editor, in which case it |
| 6568 | * would make sense to automatically display a soft input window for |
| 6569 | * it. Subclasses should override this if they implement |
| 6570 | * {@link #onCreateInputConnection(EditorInfo)} to return true if |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 6571 | * a call on that method would return a non-null InputConnection, and |
| 6572 | * they are really a first-class editor that the user would normally |
| 6573 | * start typing on when the go into a window containing your view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6574 | * |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 6575 | * <p>The default implementation always returns false. This does |
| 6576 | * <em>not</em> mean that its {@link #onCreateInputConnection(EditorInfo)} |
| 6577 | * will not be called or the user can not otherwise perform edits on your |
| 6578 | * view; it is just a hint to the system that this is not the primary |
| 6579 | * purpose of this view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6580 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6581 | * @return Returns true if this view is a text editor, else false. |
| 6582 | */ |
| 6583 | public boolean onCheckIsTextEditor() { |
| 6584 | return false; |
| 6585 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6587 | /** |
| 6588 | * Create a new InputConnection for an InputMethod to interact |
| 6589 | * with the view. The default implementation returns null, since it doesn't |
| 6590 | * support input methods. You can override this to implement such support. |
| 6591 | * This is only needed for views that take focus and text input. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6592 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6593 | * <p>When implementing this, you probably also want to implement |
| 6594 | * {@link #onCheckIsTextEditor()} to indicate you will return a |
| 6595 | * non-null InputConnection. |
| 6596 | * |
| 6597 | * @param outAttrs Fill in with attribute information about the connection. |
| 6598 | */ |
| 6599 | public InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
| 6600 | return null; |
| 6601 | } |
| 6602 | |
| 6603 | /** |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 6604 | * Called by the {@link android.view.inputmethod.InputMethodManager} |
| 6605 | * when a view who is not the current |
| 6606 | * input connection target is trying to make a call on the manager. The |
| 6607 | * default implementation returns false; you can override this to return |
| 6608 | * true for certain views if you are performing InputConnection proxying |
| 6609 | * to them. |
| 6610 | * @param view The View that is making the InputMethodManager call. |
| 6611 | * @return Return true to allow the call, false to reject. |
| 6612 | */ |
| 6613 | public boolean checkInputConnectionProxy(View view) { |
| 6614 | return false; |
| 6615 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6616 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 6617 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6618 | * Show the context menu for this view. It is not safe to hold on to the |
| 6619 | * menu after returning from this method. |
| 6620 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 6621 | * You should normally not overload this method. Overload |
| 6622 | * {@link #onCreateContextMenu(ContextMenu)} or define an |
| 6623 | * {@link OnCreateContextMenuListener} to add items to the context menu. |
| 6624 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6625 | * @param menu The context menu to populate |
| 6626 | */ |
| 6627 | public void createContextMenu(ContextMenu menu) { |
| 6628 | ContextMenuInfo menuInfo = getContextMenuInfo(); |
| 6629 | |
| 6630 | // Sets the current menu info so all items added to menu will have |
| 6631 | // my extra info set. |
| 6632 | ((MenuBuilder)menu).setCurrentMenuInfo(menuInfo); |
| 6633 | |
| 6634 | onCreateContextMenu(menu); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6635 | ListenerInfo li = mListenerInfo; |
| 6636 | if (li != null && li.mOnCreateContextMenuListener != null) { |
| 6637 | li.mOnCreateContextMenuListener.onCreateContextMenu(menu, this, menuInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6638 | } |
| 6639 | |
| 6640 | // Clear the extra information so subsequent items that aren't mine don't |
| 6641 | // have my extra info. |
| 6642 | ((MenuBuilder)menu).setCurrentMenuInfo(null); |
| 6643 | |
| 6644 | if (mParent != null) { |
| 6645 | mParent.createContextMenu(menu); |
| 6646 | } |
| 6647 | } |
| 6648 | |
| 6649 | /** |
| 6650 | * Views should implement this if they have extra information to associate |
| 6651 | * with the context menu. The return result is supplied as a parameter to |
| 6652 | * the {@link OnCreateContextMenuListener#onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} |
| 6653 | * callback. |
| 6654 | * |
| 6655 | * @return Extra information about the item for which the context menu |
| 6656 | * should be shown. This information will vary across different |
| 6657 | * subclasses of View. |
| 6658 | */ |
| 6659 | protected ContextMenuInfo getContextMenuInfo() { |
| 6660 | return null; |
| 6661 | } |
| 6662 | |
| 6663 | /** |
| 6664 | * Views should implement this if the view itself is going to add items to |
| 6665 | * the context menu. |
| 6666 | * |
| 6667 | * @param menu the context menu to populate |
| 6668 | */ |
| 6669 | protected void onCreateContextMenu(ContextMenu menu) { |
| 6670 | } |
| 6671 | |
| 6672 | /** |
| 6673 | * Implement this method to handle trackball motion events. The |
| 6674 | * <em>relative</em> movement of the trackball since the last event |
| 6675 | * can be retrieve with {@link MotionEvent#getX MotionEvent.getX()} and |
| 6676 | * {@link MotionEvent#getY MotionEvent.getY()}. These are normalized so |
| 6677 | * that a movement of 1 corresponds to the user pressing one DPAD key (so |
| 6678 | * they will often be fractional values, representing the more fine-grained |
| 6679 | * movement information available from a trackball). |
| 6680 | * |
| 6681 | * @param event The motion event. |
| 6682 | * @return True if the event was handled, false otherwise. |
| 6683 | */ |
| 6684 | public boolean onTrackballEvent(MotionEvent event) { |
| 6685 | return false; |
| 6686 | } |
| 6687 | |
| 6688 | /** |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6689 | * Implement this method to handle generic motion events. |
| 6690 | * <p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6691 | * Generic motion events describe joystick movements, mouse hovers, track pad |
| 6692 | * touches, scroll wheel movements and other input events. The |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6693 | * {@link MotionEvent#getSource() source} of the motion event specifies |
| 6694 | * the class of input that was received. Implementations of this method |
| 6695 | * must examine the bits in the source before processing the event. |
| 6696 | * The following code example shows how this is done. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6697 | * </p><p> |
| 6698 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 6699 | * are delivered to the view under the pointer. All other generic motion events are |
| 6700 | * delivered to the focused view. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6701 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 6702 | * <pre> public boolean onGenericMotionEvent(MotionEvent event) { |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6703 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6704 | * if (event.getAction() == MotionEvent.ACTION_MOVE) { |
| 6705 | * // process the joystick movement... |
| 6706 | * return true; |
| 6707 | * } |
| 6708 | * } |
| 6709 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 6710 | * switch (event.getAction()) { |
| 6711 | * case MotionEvent.ACTION_HOVER_MOVE: |
| 6712 | * // process the mouse hover movement... |
| 6713 | * return true; |
| 6714 | * case MotionEvent.ACTION_SCROLL: |
| 6715 | * // process the scroll wheel movement... |
| 6716 | * return true; |
| 6717 | * } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6718 | * } |
| 6719 | * return super.onGenericMotionEvent(event); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 6720 | * }</pre> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6721 | * |
| 6722 | * @param event The generic motion event being processed. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6723 | * @return True if the event was handled, false otherwise. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6724 | */ |
| 6725 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 6726 | return false; |
| 6727 | } |
| 6728 | |
| 6729 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6730 | * Implement this method to handle hover events. |
| 6731 | * <p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6732 | * This method is called whenever a pointer is hovering into, over, or out of the |
| 6733 | * bounds of a view and the view is not currently being touched. |
| 6734 | * Hover events are represented as pointer events with action |
| 6735 | * {@link MotionEvent#ACTION_HOVER_ENTER}, {@link MotionEvent#ACTION_HOVER_MOVE}, |
| 6736 | * or {@link MotionEvent#ACTION_HOVER_EXIT}. |
| 6737 | * </p> |
| 6738 | * <ul> |
| 6739 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_ENTER} |
| 6740 | * when the pointer enters the bounds of the view.</li> |
| 6741 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_MOVE} |
| 6742 | * when the pointer has already entered the bounds of the view and has moved.</li> |
| 6743 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_EXIT} |
| 6744 | * when the pointer has exited the bounds of the view or when the pointer is |
| 6745 | * about to go down due to a button click, tap, or similar user action that |
| 6746 | * causes the view to be touched.</li> |
| 6747 | * </ul> |
| 6748 | * <p> |
| 6749 | * The view should implement this method to return true to indicate that it is |
| 6750 | * handling the hover event, such as by changing its drawable state. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6751 | * </p><p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6752 | * The default implementation calls {@link #setHovered} to update the hovered state |
| 6753 | * 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] | 6754 | * is enabled and is clickable. The default implementation also sends hover |
| 6755 | * accessibility events. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6756 | * </p> |
| 6757 | * |
| 6758 | * @param event The motion event that describes the hover. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6759 | * @return True if the view handled the hover event. |
| 6760 | * |
| 6761 | * @see #isHovered |
| 6762 | * @see #setHovered |
| 6763 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6764 | */ |
| 6765 | public boolean onHoverEvent(MotionEvent event) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 6766 | // The root view may receive hover (or touch) events that are outside the bounds of |
| 6767 | // the window. This code ensures that we only send accessibility events for |
| 6768 | // hovers that are actually within the bounds of the root view. |
| 6769 | final int action = event.getAction(); |
| 6770 | if (!mSendingHoverAccessibilityEvents) { |
| 6771 | if ((action == MotionEvent.ACTION_HOVER_ENTER |
| 6772 | || action == MotionEvent.ACTION_HOVER_MOVE) |
| 6773 | && !hasHoveredChild() |
| 6774 | && pointInView(event.getX(), event.getY())) { |
| 6775 | mSendingHoverAccessibilityEvents = true; |
| 6776 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER); |
| 6777 | } |
| 6778 | } else { |
| 6779 | if (action == MotionEvent.ACTION_HOVER_EXIT |
| 6780 | || (action == MotionEvent.ACTION_HOVER_MOVE |
| 6781 | && !pointInView(event.getX(), event.getY()))) { |
| 6782 | mSendingHoverAccessibilityEvents = false; |
| 6783 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT); |
| 6784 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 6785 | } |
| 6786 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6787 | if (isHoverable()) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 6788 | switch (action) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6789 | case MotionEvent.ACTION_HOVER_ENTER: |
| 6790 | setHovered(true); |
| 6791 | break; |
| 6792 | case MotionEvent.ACTION_HOVER_EXIT: |
| 6793 | setHovered(false); |
| 6794 | break; |
| 6795 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 6796 | |
| 6797 | // Dispatch the event to onGenericMotionEvent before returning true. |
| 6798 | // This is to provide compatibility with existing applications that |
| 6799 | // handled HOVER_MOVE events in onGenericMotionEvent and that would |
| 6800 | // break because of the new default handling for hoverable views |
| 6801 | // in onHoverEvent. |
| 6802 | // Note that onGenericMotionEvent will be called by default when |
| 6803 | // onHoverEvent returns false (refer to dispatchGenericMotionEvent). |
| 6804 | dispatchGenericMotionEventInternal(event); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6805 | return true; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6806 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6807 | return false; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6808 | } |
| 6809 | |
| 6810 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6811 | * Returns true if the view should handle {@link #onHoverEvent} |
| 6812 | * by calling {@link #setHovered} to change its hovered state. |
| 6813 | * |
| 6814 | * @return True if the view is hoverable. |
| 6815 | */ |
| 6816 | private boolean isHoverable() { |
| 6817 | final int viewFlags = mViewFlags; |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 6818 | //noinspection SimplifiableIfStatement |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6819 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
| 6820 | return false; |
| 6821 | } |
| 6822 | |
| 6823 | return (viewFlags & CLICKABLE) == CLICKABLE |
| 6824 | || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 6825 | } |
| 6826 | |
| 6827 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6828 | * Returns true if the view is currently hovered. |
| 6829 | * |
| 6830 | * @return True if the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6831 | * |
| 6832 | * @see #setHovered |
| 6833 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6834 | */ |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6835 | @ViewDebug.ExportedProperty |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6836 | public boolean isHovered() { |
| 6837 | return (mPrivateFlags & HOVERED) != 0; |
| 6838 | } |
| 6839 | |
| 6840 | /** |
| 6841 | * Sets whether the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6842 | * <p> |
| 6843 | * Calling this method also changes the drawable state of the view. This |
| 6844 | * enables the view to react to hover by using different drawable resources |
| 6845 | * to change its appearance. |
| 6846 | * </p><p> |
| 6847 | * The {@link #onHoverChanged} method is called when the hovered state changes. |
| 6848 | * </p> |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6849 | * |
| 6850 | * @param hovered True if the view is hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6851 | * |
| 6852 | * @see #isHovered |
| 6853 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6854 | */ |
| 6855 | public void setHovered(boolean hovered) { |
| 6856 | if (hovered) { |
| 6857 | if ((mPrivateFlags & HOVERED) == 0) { |
| 6858 | mPrivateFlags |= HOVERED; |
| 6859 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6860 | onHoverChanged(true); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6861 | } |
| 6862 | } else { |
| 6863 | if ((mPrivateFlags & HOVERED) != 0) { |
| 6864 | mPrivateFlags &= ~HOVERED; |
| 6865 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6866 | onHoverChanged(false); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6867 | } |
| 6868 | } |
| 6869 | } |
| 6870 | |
| 6871 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6872 | * Implement this method to handle hover state changes. |
| 6873 | * <p> |
| 6874 | * This method is called whenever the hover state changes as a result of a |
| 6875 | * call to {@link #setHovered}. |
| 6876 | * </p> |
| 6877 | * |
| 6878 | * @param hovered The current hover state, as returned by {@link #isHovered}. |
| 6879 | * |
| 6880 | * @see #isHovered |
| 6881 | * @see #setHovered |
| 6882 | */ |
| 6883 | public void onHoverChanged(boolean hovered) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6884 | } |
| 6885 | |
| 6886 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6887 | * Implement this method to handle touch screen motion events. |
| 6888 | * |
| 6889 | * @param event The motion event. |
| 6890 | * @return True if the event was handled, false otherwise. |
| 6891 | */ |
| 6892 | public boolean onTouchEvent(MotionEvent event) { |
| 6893 | final int viewFlags = mViewFlags; |
| 6894 | |
| 6895 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
Svetoslav Ganov | 77b80c0 | 2011-03-15 20:52:58 -0700 | [diff] [blame] | 6896 | if (event.getAction() == MotionEvent.ACTION_UP && (mPrivateFlags & PRESSED) != 0) { |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 6897 | setPressed(false); |
Svetoslav Ganov | 77b80c0 | 2011-03-15 20:52:58 -0700 | [diff] [blame] | 6898 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6899 | // A disabled view that is clickable still consumes the touch |
| 6900 | // events, it just doesn't respond to them. |
| 6901 | return (((viewFlags & CLICKABLE) == CLICKABLE || |
| 6902 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)); |
| 6903 | } |
| 6904 | |
| 6905 | if (mTouchDelegate != null) { |
| 6906 | if (mTouchDelegate.onTouchEvent(event)) { |
| 6907 | return true; |
| 6908 | } |
| 6909 | } |
| 6910 | |
| 6911 | if (((viewFlags & CLICKABLE) == CLICKABLE || |
| 6912 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)) { |
| 6913 | switch (event.getAction()) { |
| 6914 | case MotionEvent.ACTION_UP: |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6915 | boolean prepressed = (mPrivateFlags & PREPRESSED) != 0; |
| 6916 | if ((mPrivateFlags & PRESSED) != 0 || prepressed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6917 | // take focus if we don't have it already and we should in |
| 6918 | // touch mode. |
| 6919 | boolean focusTaken = false; |
| 6920 | if (isFocusable() && isFocusableInTouchMode() && !isFocused()) { |
| 6921 | focusTaken = requestFocus(); |
| 6922 | } |
| 6923 | |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 6924 | if (prepressed) { |
| 6925 | // The button is being released before we actually |
| 6926 | // showed it as pressed. Make it show the pressed |
| 6927 | // state now (before scheduling the click) to ensure |
| 6928 | // the user sees it. |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 6929 | setPressed(true); |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 6930 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6931 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6932 | if (!mHasPerformedLongPress) { |
| 6933 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6934 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6935 | |
| 6936 | // Only perform take click actions if we were in the pressed state |
| 6937 | if (!focusTaken) { |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 6938 | // Use a Runnable and post this rather than calling |
| 6939 | // performClick directly. This lets other visual state |
| 6940 | // of the view update before click actions start. |
| 6941 | if (mPerformClick == null) { |
| 6942 | mPerformClick = new PerformClick(); |
| 6943 | } |
| 6944 | if (!post(mPerformClick)) { |
| 6945 | performClick(); |
| 6946 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6947 | } |
| 6948 | } |
| 6949 | |
| 6950 | if (mUnsetPressedState == null) { |
| 6951 | mUnsetPressedState = new UnsetPressedState(); |
| 6952 | } |
| 6953 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6954 | if (prepressed) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6955 | postDelayed(mUnsetPressedState, |
| 6956 | ViewConfiguration.getPressedStateDuration()); |
| 6957 | } else if (!post(mUnsetPressedState)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6958 | // If the post failed, unpress right now |
| 6959 | mUnsetPressedState.run(); |
| 6960 | } |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6961 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6962 | } |
| 6963 | break; |
| 6964 | |
| 6965 | case MotionEvent.ACTION_DOWN: |
Adam Powell | 3b02339 | 2010-03-11 16:30:28 -0800 | [diff] [blame] | 6966 | mHasPerformedLongPress = false; |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6967 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 6968 | if (performButtonActionOnTouchDown(event)) { |
| 6969 | break; |
| 6970 | } |
| 6971 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6972 | // 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] | 6973 | boolean isInScrollingContainer = isInScrollingContainer(); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6974 | |
| 6975 | // For views inside a scrolling container, delay the pressed feedback for |
| 6976 | // a short period in case this is a scroll. |
| 6977 | if (isInScrollingContainer) { |
| 6978 | mPrivateFlags |= PREPRESSED; |
| 6979 | if (mPendingCheckForTap == null) { |
| 6980 | mPendingCheckForTap = new CheckForTap(); |
| 6981 | } |
| 6982 | postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); |
| 6983 | } else { |
| 6984 | // Not inside a scrolling container, so show the feedback right away |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 6985 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6986 | checkForLongClick(0); |
| 6987 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6988 | break; |
| 6989 | |
| 6990 | case MotionEvent.ACTION_CANCEL: |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 6991 | setPressed(false); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6992 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6993 | break; |
| 6994 | |
| 6995 | case MotionEvent.ACTION_MOVE: |
| 6996 | final int x = (int) event.getX(); |
| 6997 | final int y = (int) event.getY(); |
| 6998 | |
| 6999 | // Be lenient about moving outside of buttons |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7000 | if (!pointInView(x, y, mTouchSlop)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7001 | // Outside button |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7002 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7003 | if ((mPrivateFlags & PRESSED) != 0) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7004 | // Remove any future long press/tap checks |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7005 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7006 | |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 7007 | setPressed(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7008 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7009 | } |
| 7010 | break; |
| 7011 | } |
| 7012 | return true; |
| 7013 | } |
| 7014 | |
| 7015 | return false; |
| 7016 | } |
| 7017 | |
| 7018 | /** |
Adam Powell | 1029866 | 2011-08-14 18:26:30 -0700 | [diff] [blame] | 7019 | * @hide |
| 7020 | */ |
| 7021 | public boolean isInScrollingContainer() { |
| 7022 | ViewParent p = getParent(); |
| 7023 | while (p != null && p instanceof ViewGroup) { |
| 7024 | if (((ViewGroup) p).shouldDelayChildPressedState()) { |
| 7025 | return true; |
| 7026 | } |
| 7027 | p = p.getParent(); |
| 7028 | } |
| 7029 | return false; |
| 7030 | } |
| 7031 | |
| 7032 | /** |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7033 | * Remove the longpress detection timer. |
| 7034 | */ |
| 7035 | private void removeLongPressCallback() { |
| 7036 | if (mPendingCheckForLongPress != null) { |
| 7037 | removeCallbacks(mPendingCheckForLongPress); |
| 7038 | } |
| 7039 | } |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 7040 | |
| 7041 | /** |
| 7042 | * Remove the pending click action |
| 7043 | */ |
| 7044 | private void removePerformClickCallback() { |
| 7045 | if (mPerformClick != null) { |
| 7046 | removeCallbacks(mPerformClick); |
| 7047 | } |
| 7048 | } |
| 7049 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7050 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7051 | * Remove the prepress detection timer. |
| 7052 | */ |
| 7053 | private void removeUnsetPressCallback() { |
| 7054 | if ((mPrivateFlags & PRESSED) != 0 && mUnsetPressedState != null) { |
| 7055 | setPressed(false); |
| 7056 | removeCallbacks(mUnsetPressedState); |
| 7057 | } |
| 7058 | } |
| 7059 | |
| 7060 | /** |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7061 | * Remove the tap detection timer. |
| 7062 | */ |
| 7063 | private void removeTapCallback() { |
| 7064 | if (mPendingCheckForTap != null) { |
| 7065 | mPrivateFlags &= ~PREPRESSED; |
| 7066 | removeCallbacks(mPendingCheckForTap); |
| 7067 | } |
| 7068 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7069 | |
| 7070 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7071 | * Cancels a pending long press. Your subclass can use this if you |
| 7072 | * want the context menu to come up if the user presses and holds |
| 7073 | * at the same place, but you don't want it to come up if they press |
| 7074 | * and then move around enough to cause scrolling. |
| 7075 | */ |
| 7076 | public void cancelLongPress() { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7077 | removeLongPressCallback(); |
Adam Powell | 732ebb1 | 2010-02-02 15:28:14 -0800 | [diff] [blame] | 7078 | |
| 7079 | /* |
| 7080 | * The prepressed state handled by the tap callback is a display |
| 7081 | * construct, but the tap callback will post a long press callback |
| 7082 | * less its own timeout. Remove it here. |
| 7083 | */ |
| 7084 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7085 | } |
| 7086 | |
| 7087 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7088 | * Remove the pending callback for sending a |
| 7089 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 7090 | */ |
| 7091 | private void removeSendViewScrolledAccessibilityEventCallback() { |
| 7092 | if (mSendViewScrolledAccessibilityEvent != null) { |
| 7093 | removeCallbacks(mSendViewScrolledAccessibilityEvent); |
| 7094 | } |
| 7095 | } |
| 7096 | |
| 7097 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7098 | * Sets the TouchDelegate for this View. |
| 7099 | */ |
| 7100 | public void setTouchDelegate(TouchDelegate delegate) { |
| 7101 | mTouchDelegate = delegate; |
| 7102 | } |
| 7103 | |
| 7104 | /** |
| 7105 | * Gets the TouchDelegate for this View. |
| 7106 | */ |
| 7107 | public TouchDelegate getTouchDelegate() { |
| 7108 | return mTouchDelegate; |
| 7109 | } |
| 7110 | |
| 7111 | /** |
| 7112 | * Set flags controlling behavior of this view. |
| 7113 | * |
| 7114 | * @param flags Constant indicating the value which should be set |
| 7115 | * @param mask Constant indicating the bit range that should be changed |
| 7116 | */ |
| 7117 | void setFlags(int flags, int mask) { |
| 7118 | int old = mViewFlags; |
| 7119 | mViewFlags = (mViewFlags & ~mask) | (flags & mask); |
| 7120 | |
| 7121 | int changed = mViewFlags ^ old; |
| 7122 | if (changed == 0) { |
| 7123 | return; |
| 7124 | } |
| 7125 | int privateFlags = mPrivateFlags; |
| 7126 | |
| 7127 | /* Check if the FOCUSABLE bit has changed */ |
| 7128 | if (((changed & FOCUSABLE_MASK) != 0) && |
| 7129 | ((privateFlags & HAS_BOUNDS) !=0)) { |
| 7130 | if (((old & FOCUSABLE_MASK) == FOCUSABLE) |
| 7131 | && ((privateFlags & FOCUSED) != 0)) { |
| 7132 | /* Give up focus if we are no longer focusable */ |
| 7133 | clearFocus(); |
| 7134 | } else if (((old & FOCUSABLE_MASK) == NOT_FOCUSABLE) |
| 7135 | && ((privateFlags & FOCUSED) == 0)) { |
| 7136 | /* |
| 7137 | * Tell the view system that we are now available to take focus |
| 7138 | * if no one else already has it. |
| 7139 | */ |
| 7140 | if (mParent != null) mParent.focusableViewAvailable(this); |
| 7141 | } |
| 7142 | } |
| 7143 | |
| 7144 | if ((flags & VISIBILITY_MASK) == VISIBLE) { |
| 7145 | if ((changed & VISIBILITY_MASK) != 0) { |
| 7146 | /* |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 7147 | * 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] | 7148 | * it was not visible. Marking it drawn ensures that the invalidation will |
| 7149 | * go through. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7150 | */ |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 7151 | mPrivateFlags |= DRAWN; |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 7152 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7153 | |
| 7154 | needGlobalAttributesUpdate(true); |
| 7155 | |
| 7156 | // a view becoming visible is worth notifying the parent |
| 7157 | // about in case nothing has focus. even if this specific view |
| 7158 | // isn't focusable, it may contain something that is, so let |
| 7159 | // the root view try to give this focus if nothing else does. |
| 7160 | if ((mParent != null) && (mBottom > mTop) && (mRight > mLeft)) { |
| 7161 | mParent.focusableViewAvailable(this); |
| 7162 | } |
| 7163 | } |
| 7164 | } |
| 7165 | |
| 7166 | /* Check if the GONE bit has changed */ |
| 7167 | if ((changed & GONE) != 0) { |
| 7168 | needGlobalAttributesUpdate(false); |
| 7169 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7170 | |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 7171 | if (((mViewFlags & VISIBILITY_MASK) == GONE)) { |
| 7172 | if (hasFocus()) clearFocus(); |
| 7173 | destroyDrawingCache(); |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 7174 | if (mParent instanceof View) { |
| 7175 | // GONE views noop invalidation, so invalidate the parent |
| 7176 | ((View) mParent).invalidate(true); |
| 7177 | } |
| 7178 | // Mark the view drawn to ensure that it gets invalidated properly the next |
| 7179 | // time it is visible and gets invalidated |
| 7180 | mPrivateFlags |= DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7181 | } |
| 7182 | if (mAttachInfo != null) { |
| 7183 | mAttachInfo.mViewVisibilityChanged = true; |
| 7184 | } |
| 7185 | } |
| 7186 | |
| 7187 | /* Check if the VISIBLE bit has changed */ |
| 7188 | if ((changed & INVISIBLE) != 0) { |
| 7189 | needGlobalAttributesUpdate(false); |
Chet Haase | c8a9a70 | 2011-06-17 12:13:42 -0700 | [diff] [blame] | 7190 | /* |
| 7191 | * If this view is becoming invisible, set the DRAWN flag so that |
| 7192 | * the next invalidate() will not be skipped. |
| 7193 | */ |
| 7194 | mPrivateFlags |= DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7195 | |
| 7196 | if (((mViewFlags & VISIBILITY_MASK) == INVISIBLE) && hasFocus()) { |
| 7197 | // root view becoming invisible shouldn't clear focus |
| 7198 | if (getRootView() != this) { |
| 7199 | clearFocus(); |
| 7200 | } |
| 7201 | } |
| 7202 | if (mAttachInfo != null) { |
| 7203 | mAttachInfo.mViewVisibilityChanged = true; |
| 7204 | } |
| 7205 | } |
| 7206 | |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7207 | if ((changed & VISIBILITY_MASK) != 0) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 7208 | if (mParent instanceof ViewGroup) { |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 7209 | ((ViewGroup) mParent).onChildVisibilityChanged(this, |
| 7210 | (changed & VISIBILITY_MASK), (flags & VISIBILITY_MASK)); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7211 | ((View) mParent).invalidate(true); |
Chet Haase | e4e6e20 | 2011-08-29 14:34:30 -0700 | [diff] [blame] | 7212 | } else if (mParent != null) { |
| 7213 | mParent.invalidateChild(this, null); |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 7214 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7215 | dispatchVisibilityChanged(this, (flags & VISIBILITY_MASK)); |
| 7216 | } |
| 7217 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7218 | if ((changed & WILL_NOT_CACHE_DRAWING) != 0) { |
| 7219 | destroyDrawingCache(); |
| 7220 | } |
| 7221 | |
| 7222 | if ((changed & DRAWING_CACHE_ENABLED) != 0) { |
| 7223 | destroyDrawingCache(); |
| 7224 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7225 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7226 | } |
| 7227 | |
| 7228 | if ((changed & DRAWING_CACHE_QUALITY_MASK) != 0) { |
| 7229 | destroyDrawingCache(); |
| 7230 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 7231 | } |
| 7232 | |
| 7233 | if ((changed & DRAW_MASK) != 0) { |
| 7234 | if ((mViewFlags & WILL_NOT_DRAW) != 0) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7235 | if (mBackground != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7236 | mPrivateFlags &= ~SKIP_DRAW; |
| 7237 | mPrivateFlags |= ONLY_DRAWS_BACKGROUND; |
| 7238 | } else { |
| 7239 | mPrivateFlags |= SKIP_DRAW; |
| 7240 | } |
| 7241 | } else { |
| 7242 | mPrivateFlags &= ~SKIP_DRAW; |
| 7243 | } |
| 7244 | requestLayout(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7245 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7246 | } |
| 7247 | |
| 7248 | if ((changed & KEEP_SCREEN_ON) != 0) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7249 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7250 | mParent.recomputeViewAttributes(this); |
| 7251 | } |
| 7252 | } |
| 7253 | } |
| 7254 | |
| 7255 | /** |
| 7256 | * Change the view's z order in the tree, so it's on top of other sibling |
| 7257 | * views |
| 7258 | */ |
| 7259 | public void bringToFront() { |
| 7260 | if (mParent != null) { |
| 7261 | mParent.bringChildToFront(this); |
| 7262 | } |
| 7263 | } |
| 7264 | |
| 7265 | /** |
| 7266 | * This is called in response to an internal scroll in this view (i.e., the |
| 7267 | * view scrolled its own contents). This is typically as a result of |
| 7268 | * {@link #scrollBy(int, int)} or {@link #scrollTo(int, int)} having been |
| 7269 | * called. |
| 7270 | * |
| 7271 | * @param l Current horizontal scroll origin. |
| 7272 | * @param t Current vertical scroll origin. |
| 7273 | * @param oldl Previous horizontal scroll origin. |
| 7274 | * @param oldt Previous vertical scroll origin. |
| 7275 | */ |
| 7276 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7277 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 7278 | postSendViewScrolledAccessibilityEventCallback(); |
| 7279 | } |
| 7280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7281 | mBackgroundSizeChanged = true; |
| 7282 | |
| 7283 | final AttachInfo ai = mAttachInfo; |
| 7284 | if (ai != null) { |
| 7285 | ai.mViewScrollChanged = true; |
| 7286 | } |
| 7287 | } |
| 7288 | |
| 7289 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7290 | * Interface definition for a callback to be invoked when the layout bounds of a view |
| 7291 | * changes due to layout processing. |
| 7292 | */ |
| 7293 | public interface OnLayoutChangeListener { |
| 7294 | /** |
| 7295 | * Called when the focus state of a view has changed. |
| 7296 | * |
| 7297 | * @param v The view whose state has changed. |
| 7298 | * @param left The new value of the view's left property. |
| 7299 | * @param top The new value of the view's top property. |
| 7300 | * @param right The new value of the view's right property. |
| 7301 | * @param bottom The new value of the view's bottom property. |
| 7302 | * @param oldLeft The previous value of the view's left property. |
| 7303 | * @param oldTop The previous value of the view's top property. |
| 7304 | * @param oldRight The previous value of the view's right property. |
| 7305 | * @param oldBottom The previous value of the view's bottom property. |
| 7306 | */ |
| 7307 | void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 7308 | int oldLeft, int oldTop, int oldRight, int oldBottom); |
| 7309 | } |
| 7310 | |
| 7311 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7312 | * This is called during layout when the size of this view has changed. If |
| 7313 | * you were just added to the view hierarchy, you're called with the old |
| 7314 | * values of 0. |
| 7315 | * |
| 7316 | * @param w Current width of this view. |
| 7317 | * @param h Current height of this view. |
| 7318 | * @param oldw Old width of this view. |
| 7319 | * @param oldh Old height of this view. |
| 7320 | */ |
| 7321 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 7322 | } |
| 7323 | |
| 7324 | /** |
| 7325 | * Called by draw to draw the child views. This may be overridden |
| 7326 | * by derived classes to gain control just before its children are drawn |
| 7327 | * (but after its own view has been drawn). |
| 7328 | * @param canvas the canvas on which to draw the view |
| 7329 | */ |
| 7330 | protected void dispatchDraw(Canvas canvas) { |
| 7331 | } |
| 7332 | |
| 7333 | /** |
| 7334 | * Gets the parent of this view. Note that the parent is a |
| 7335 | * ViewParent and not necessarily a View. |
| 7336 | * |
| 7337 | * @return Parent of this view. |
| 7338 | */ |
| 7339 | public final ViewParent getParent() { |
| 7340 | return mParent; |
| 7341 | } |
| 7342 | |
| 7343 | /** |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 7344 | * Set the horizontal scrolled position of your view. This will cause a call to |
| 7345 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 7346 | * invalidated. |
| 7347 | * @param value the x position to scroll to |
| 7348 | */ |
| 7349 | public void setScrollX(int value) { |
| 7350 | scrollTo(value, mScrollY); |
| 7351 | } |
| 7352 | |
| 7353 | /** |
| 7354 | * Set the vertical scrolled position of your view. This will cause a call to |
| 7355 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 7356 | * invalidated. |
| 7357 | * @param value the y position to scroll to |
| 7358 | */ |
| 7359 | public void setScrollY(int value) { |
| 7360 | scrollTo(mScrollX, value); |
| 7361 | } |
| 7362 | |
| 7363 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7364 | * Return the scrolled left position of this view. This is the left edge of |
| 7365 | * the displayed part of your view. You do not need to draw any pixels |
| 7366 | * farther left, since those are outside of the frame of your view on |
| 7367 | * screen. |
| 7368 | * |
| 7369 | * @return The left edge of the displayed part of your view, in pixels. |
| 7370 | */ |
| 7371 | public final int getScrollX() { |
| 7372 | return mScrollX; |
| 7373 | } |
| 7374 | |
| 7375 | /** |
| 7376 | * Return the scrolled top position of this view. This is the top edge of |
| 7377 | * the displayed part of your view. You do not need to draw any pixels above |
| 7378 | * it, since those are outside of the frame of your view on screen. |
| 7379 | * |
| 7380 | * @return The top edge of the displayed part of your view, in pixels. |
| 7381 | */ |
| 7382 | public final int getScrollY() { |
| 7383 | return mScrollY; |
| 7384 | } |
| 7385 | |
| 7386 | /** |
| 7387 | * Return the width of the your view. |
| 7388 | * |
| 7389 | * @return The width of your view, in pixels. |
| 7390 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 7391 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7392 | public final int getWidth() { |
| 7393 | return mRight - mLeft; |
| 7394 | } |
| 7395 | |
| 7396 | /** |
| 7397 | * Return the height of your view. |
| 7398 | * |
| 7399 | * @return The height of your view, in pixels. |
| 7400 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 7401 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7402 | public final int getHeight() { |
| 7403 | return mBottom - mTop; |
| 7404 | } |
| 7405 | |
| 7406 | /** |
| 7407 | * Return the visible drawing bounds of your view. Fills in the output |
| 7408 | * rectangle with the values from getScrollX(), getScrollY(), |
| 7409 | * getWidth(), and getHeight(). |
| 7410 | * |
| 7411 | * @param outRect The (scrolled) drawing bounds of the view. |
| 7412 | */ |
| 7413 | public void getDrawingRect(Rect outRect) { |
| 7414 | outRect.left = mScrollX; |
| 7415 | outRect.top = mScrollY; |
| 7416 | outRect.right = mScrollX + (mRight - mLeft); |
| 7417 | outRect.bottom = mScrollY + (mBottom - mTop); |
| 7418 | } |
| 7419 | |
| 7420 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7421 | * Like {@link #getMeasuredWidthAndState()}, but only returns the |
| 7422 | * raw width component (that is the result is masked by |
| 7423 | * {@link #MEASURED_SIZE_MASK}). |
| 7424 | * |
| 7425 | * @return The raw measured width of this view. |
| 7426 | */ |
| 7427 | public final int getMeasuredWidth() { |
| 7428 | return mMeasuredWidth & MEASURED_SIZE_MASK; |
| 7429 | } |
| 7430 | |
| 7431 | /** |
| 7432 | * Return the full width measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7433 | * 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] | 7434 | * 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] | 7435 | * This should be used during measurement and layout calculations only. Use |
| 7436 | * {@link #getWidth()} to see how wide a view is after layout. |
| 7437 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7438 | * @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] | 7439 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7440 | public final int getMeasuredWidthAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7441 | return mMeasuredWidth; |
| 7442 | } |
| 7443 | |
| 7444 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7445 | * Like {@link #getMeasuredHeightAndState()}, but only returns the |
| 7446 | * raw width component (that is the result is masked by |
| 7447 | * {@link #MEASURED_SIZE_MASK}). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7448 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7449 | * @return The raw measured height of this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7450 | */ |
| 7451 | public final int getMeasuredHeight() { |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7452 | return mMeasuredHeight & MEASURED_SIZE_MASK; |
| 7453 | } |
| 7454 | |
| 7455 | /** |
| 7456 | * Return the full height measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7457 | * 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] | 7458 | * as defined by {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. |
| 7459 | * This should be used during measurement and layout calculations only. Use |
| 7460 | * {@link #getHeight()} to see how wide a view is after layout. |
| 7461 | * |
| 7462 | * @return The measured width of this view as a bit mask. |
| 7463 | */ |
| 7464 | public final int getMeasuredHeightAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7465 | return mMeasuredHeight; |
| 7466 | } |
| 7467 | |
| 7468 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7469 | * Return only the state bits of {@link #getMeasuredWidthAndState()} |
| 7470 | * and {@link #getMeasuredHeightAndState()}, combined into one integer. |
| 7471 | * The width component is in the regular bits {@link #MEASURED_STATE_MASK} |
| 7472 | * and the height component is at the shifted bits |
| 7473 | * {@link #MEASURED_HEIGHT_STATE_SHIFT}>>{@link #MEASURED_STATE_MASK}. |
| 7474 | */ |
| 7475 | public final int getMeasuredState() { |
| 7476 | return (mMeasuredWidth&MEASURED_STATE_MASK) |
| 7477 | | ((mMeasuredHeight>>MEASURED_HEIGHT_STATE_SHIFT) |
| 7478 | & (MEASURED_STATE_MASK>>MEASURED_HEIGHT_STATE_SHIFT)); |
| 7479 | } |
| 7480 | |
| 7481 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7482 | * The transform matrix of this view, which is calculated based on the current |
| 7483 | * roation, scale, and pivot properties. |
| 7484 | * |
| 7485 | * @see #getRotation() |
| 7486 | * @see #getScaleX() |
| 7487 | * @see #getScaleY() |
| 7488 | * @see #getPivotX() |
| 7489 | * @see #getPivotY() |
| 7490 | * @return The current transform matrix for the view |
| 7491 | */ |
| 7492 | public Matrix getMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7493 | if (mTransformationInfo != null) { |
| 7494 | updateMatrix(); |
| 7495 | return mTransformationInfo.mMatrix; |
| 7496 | } |
| 7497 | return Matrix.IDENTITY_MATRIX; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7498 | } |
| 7499 | |
| 7500 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7501 | * Utility function to determine if the value is far enough away from zero to be |
| 7502 | * considered non-zero. |
| 7503 | * @param value A floating point value to check for zero-ness |
| 7504 | * @return whether the passed-in value is far enough away from zero to be considered non-zero |
| 7505 | */ |
| 7506 | private static boolean nonzero(float value) { |
| 7507 | return (value < -NONZERO_EPSILON || value > NONZERO_EPSILON); |
| 7508 | } |
| 7509 | |
| 7510 | /** |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7511 | * Returns true if the transform matrix is the identity matrix. |
| 7512 | * Recomputes the matrix if necessary. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7513 | * |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7514 | * @return True if the transform matrix is the identity matrix, false otherwise. |
| 7515 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7516 | final boolean hasIdentityMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7517 | if (mTransformationInfo != null) { |
| 7518 | updateMatrix(); |
| 7519 | return mTransformationInfo.mMatrixIsIdentity; |
| 7520 | } |
| 7521 | return true; |
| 7522 | } |
| 7523 | |
| 7524 | void ensureTransformationInfo() { |
| 7525 | if (mTransformationInfo == null) { |
| 7526 | mTransformationInfo = new TransformationInfo(); |
| 7527 | } |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7528 | } |
| 7529 | |
| 7530 | /** |
| 7531 | * Recomputes the transform matrix if necessary. |
| 7532 | */ |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 7533 | private void updateMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7534 | final TransformationInfo info = mTransformationInfo; |
| 7535 | if (info == null) { |
| 7536 | return; |
| 7537 | } |
| 7538 | if (info.mMatrixDirty) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7539 | // transform-related properties have changed since the last time someone |
| 7540 | // asked for the matrix; recalculate it with the current values |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7541 | |
| 7542 | // Figure out if we need to update the pivot point |
| 7543 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7544 | if ((mRight - mLeft) != info.mPrevWidth || (mBottom - mTop) != info.mPrevHeight) { |
| 7545 | info.mPrevWidth = mRight - mLeft; |
| 7546 | info.mPrevHeight = mBottom - mTop; |
| 7547 | info.mPivotX = info.mPrevWidth / 2f; |
| 7548 | info.mPivotY = info.mPrevHeight / 2f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7549 | } |
| 7550 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7551 | info.mMatrix.reset(); |
| 7552 | if (!nonzero(info.mRotationX) && !nonzero(info.mRotationY)) { |
| 7553 | info.mMatrix.setTranslate(info.mTranslationX, info.mTranslationY); |
| 7554 | info.mMatrix.preRotate(info.mRotation, info.mPivotX, info.mPivotY); |
| 7555 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7556 | } else { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7557 | if (info.mCamera == null) { |
| 7558 | info.mCamera = new Camera(); |
| 7559 | info.matrix3D = new Matrix(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7560 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7561 | info.mCamera.save(); |
| 7562 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
| 7563 | info.mCamera.rotate(info.mRotationX, info.mRotationY, -info.mRotation); |
| 7564 | info.mCamera.getMatrix(info.matrix3D); |
| 7565 | info.matrix3D.preTranslate(-info.mPivotX, -info.mPivotY); |
| 7566 | info.matrix3D.postTranslate(info.mPivotX + info.mTranslationX, |
| 7567 | info.mPivotY + info.mTranslationY); |
| 7568 | info.mMatrix.postConcat(info.matrix3D); |
| 7569 | info.mCamera.restore(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7570 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7571 | info.mMatrixDirty = false; |
| 7572 | info.mMatrixIsIdentity = info.mMatrix.isIdentity(); |
| 7573 | info.mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7574 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7575 | } |
| 7576 | |
| 7577 | /** |
| 7578 | * Utility method to retrieve the inverse of the current mMatrix property. |
| 7579 | * We cache the matrix to avoid recalculating it when transform properties |
| 7580 | * have not changed. |
| 7581 | * |
| 7582 | * @return The inverse of the current matrix of this view. |
| 7583 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7584 | final Matrix getInverseMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7585 | final TransformationInfo info = mTransformationInfo; |
| 7586 | if (info != null) { |
| 7587 | updateMatrix(); |
| 7588 | if (info.mInverseMatrixDirty) { |
| 7589 | if (info.mInverseMatrix == null) { |
| 7590 | info.mInverseMatrix = new Matrix(); |
| 7591 | } |
| 7592 | info.mMatrix.invert(info.mInverseMatrix); |
| 7593 | info.mInverseMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7594 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7595 | return info.mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7596 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7597 | return Matrix.IDENTITY_MATRIX; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7598 | } |
| 7599 | |
| 7600 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7601 | * Gets the distance along the Z axis from the camera to this view. |
| 7602 | * |
| 7603 | * @see #setCameraDistance(float) |
| 7604 | * |
| 7605 | * @return The distance along the Z axis. |
| 7606 | */ |
| 7607 | public float getCameraDistance() { |
| 7608 | ensureTransformationInfo(); |
| 7609 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
| 7610 | final TransformationInfo info = mTransformationInfo; |
| 7611 | if (info.mCamera == null) { |
| 7612 | info.mCamera = new Camera(); |
| 7613 | info.matrix3D = new Matrix(); |
| 7614 | } |
| 7615 | return -(info.mCamera.getLocationZ() * dpi); |
| 7616 | } |
| 7617 | |
| 7618 | /** |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7619 | * <p>Sets the distance along the Z axis (orthogonal to the X/Y plane on which |
| 7620 | * views are drawn) from the camera to this view. The camera's distance |
| 7621 | * affects 3D transformations, for instance rotations around the X and Y |
| 7622 | * axis. If the rotationX or rotationY properties are changed and this view is |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7623 | * large (more than half the size of the screen), it is recommended to always |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7624 | * use a camera distance that's greater than the height (X axis rotation) or |
| 7625 | * the width (Y axis rotation) of this view.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7626 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7627 | * <p>The distance of the camera from the view plane can have an affect on the |
| 7628 | * perspective distortion of the view when it is rotated around the x or y axis. |
| 7629 | * For example, a large distance will result in a large viewing angle, and there |
| 7630 | * will not be much perspective distortion of the view as it rotates. A short |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7631 | * distance may cause much more perspective distortion upon rotation, and can |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7632 | * also result in some drawing artifacts if the rotated view ends up partially |
| 7633 | * behind the camera (which is why the recommendation is to use a distance at |
| 7634 | * least as far as the size of the view, if the view is to be rotated.)</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7635 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7636 | * <p>The distance is expressed in "depth pixels." The default distance depends |
| 7637 | * on the screen density. For instance, on a medium density display, the |
| 7638 | * default distance is 1280. On a high density display, the default distance |
| 7639 | * is 1920.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7640 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7641 | * <p>If you want to specify a distance that leads to visually consistent |
| 7642 | * results across various densities, use the following formula:</p> |
| 7643 | * <pre> |
| 7644 | * float scale = context.getResources().getDisplayMetrics().density; |
| 7645 | * view.setCameraDistance(distance * scale); |
| 7646 | * </pre> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7647 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7648 | * <p>The density scale factor of a high density display is 1.5, |
| 7649 | * and 1920 = 1280 * 1.5.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7650 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7651 | * @param distance The distance in "depth pixels", if negative the opposite |
| 7652 | * value is used |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7653 | * |
| 7654 | * @see #setRotationX(float) |
| 7655 | * @see #setRotationY(float) |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7656 | */ |
| 7657 | public void setCameraDistance(float distance) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7658 | invalidateViewProperty(true, false); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7659 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7660 | ensureTransformationInfo(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7661 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7662 | final TransformationInfo info = mTransformationInfo; |
| 7663 | if (info.mCamera == null) { |
| 7664 | info.mCamera = new Camera(); |
| 7665 | info.matrix3D = new Matrix(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7666 | } |
| 7667 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7668 | info.mCamera.setLocation(0.0f, 0.0f, -Math.abs(distance) / dpi); |
| 7669 | info.mMatrixDirty = true; |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7670 | |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7671 | invalidateViewProperty(false, false); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7672 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 7673 | mDisplayList.setCameraDistance(-Math.abs(distance) / dpi); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7674 | } |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7675 | } |
| 7676 | |
| 7677 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7678 | * The degrees that the view is rotated around the pivot point. |
| 7679 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7680 | * @see #setRotation(float) |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7681 | * @see #getPivotX() |
| 7682 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7683 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7684 | * @return The degrees of rotation. |
| 7685 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7686 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7687 | public float getRotation() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7688 | return mTransformationInfo != null ? mTransformationInfo.mRotation : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7689 | } |
| 7690 | |
| 7691 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7692 | * Sets the degrees that the view is rotated around the pivot point. Increasing values |
| 7693 | * result in clockwise rotation. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7694 | * |
| 7695 | * @param rotation The degrees of rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7696 | * |
| 7697 | * @see #getRotation() |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7698 | * @see #getPivotX() |
| 7699 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7700 | * @see #setRotationX(float) |
| 7701 | * @see #setRotationY(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7702 | * |
| 7703 | * @attr ref android.R.styleable#View_rotation |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7704 | */ |
| 7705 | public void setRotation(float rotation) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7706 | ensureTransformationInfo(); |
| 7707 | final TransformationInfo info = mTransformationInfo; |
| 7708 | if (info.mRotation != rotation) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7709 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7710 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7711 | info.mRotation = rotation; |
| 7712 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7713 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7714 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7715 | mDisplayList.setRotation(rotation); |
| 7716 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7717 | } |
| 7718 | } |
| 7719 | |
| 7720 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7721 | * The degrees that the view is rotated around the vertical axis through the pivot point. |
| 7722 | * |
| 7723 | * @see #getPivotX() |
| 7724 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7725 | * @see #setRotationY(float) |
| 7726 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7727 | * @return The degrees of Y rotation. |
| 7728 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7729 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7730 | public float getRotationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7731 | return mTransformationInfo != null ? mTransformationInfo.mRotationY : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7732 | } |
| 7733 | |
| 7734 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7735 | * Sets the degrees that the view is rotated around the vertical axis through the pivot point. |
| 7736 | * Increasing values result in counter-clockwise rotation from the viewpoint of looking |
| 7737 | * down the y axis. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7738 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7739 | * When rotating large views, it is recommended to adjust the camera distance |
| 7740 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7741 | * |
| 7742 | * @param rotationY The degrees of Y rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7743 | * |
| 7744 | * @see #getRotationY() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7745 | * @see #getPivotX() |
| 7746 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7747 | * @see #setRotation(float) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7748 | * @see #setRotationX(float) |
| 7749 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7750 | * |
| 7751 | * @attr ref android.R.styleable#View_rotationY |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7752 | */ |
| 7753 | public void setRotationY(float rotationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7754 | ensureTransformationInfo(); |
| 7755 | final TransformationInfo info = mTransformationInfo; |
| 7756 | if (info.mRotationY != rotationY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7757 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7758 | info.mRotationY = rotationY; |
| 7759 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7760 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7761 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7762 | mDisplayList.setRotationY(rotationY); |
| 7763 | } |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7764 | } |
| 7765 | } |
| 7766 | |
| 7767 | /** |
| 7768 | * The degrees that the view is rotated around the horizontal axis through the pivot point. |
| 7769 | * |
| 7770 | * @see #getPivotX() |
| 7771 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7772 | * @see #setRotationX(float) |
| 7773 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7774 | * @return The degrees of X rotation. |
| 7775 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7776 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7777 | public float getRotationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7778 | return mTransformationInfo != null ? mTransformationInfo.mRotationX : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7779 | } |
| 7780 | |
| 7781 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7782 | * Sets the degrees that the view is rotated around the horizontal axis through the pivot point. |
| 7783 | * Increasing values result in clockwise rotation from the viewpoint of looking down the |
| 7784 | * x axis. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7785 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7786 | * When rotating large views, it is recommended to adjust the camera distance |
| 7787 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7788 | * |
| 7789 | * @param rotationX The degrees of X rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7790 | * |
| 7791 | * @see #getRotationX() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7792 | * @see #getPivotX() |
| 7793 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7794 | * @see #setRotation(float) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7795 | * @see #setRotationY(float) |
| 7796 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7797 | * |
| 7798 | * @attr ref android.R.styleable#View_rotationX |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7799 | */ |
| 7800 | public void setRotationX(float rotationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7801 | ensureTransformationInfo(); |
| 7802 | final TransformationInfo info = mTransformationInfo; |
| 7803 | if (info.mRotationX != rotationX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7804 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7805 | info.mRotationX = rotationX; |
| 7806 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7807 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7808 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7809 | mDisplayList.setRotationX(rotationX); |
| 7810 | } |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7811 | } |
| 7812 | } |
| 7813 | |
| 7814 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7815 | * The amount that the view is scaled in x around the pivot point, as a proportion of |
| 7816 | * the view's unscaled width. A value of 1, the default, means that no scaling is applied. |
| 7817 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 7818 | * <p>By default, this is 1.0f. |
| 7819 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7820 | * @see #getPivotX() |
| 7821 | * @see #getPivotY() |
| 7822 | * @return The scaling factor. |
| 7823 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7824 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7825 | public float getScaleX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7826 | return mTransformationInfo != null ? mTransformationInfo.mScaleX : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7827 | } |
| 7828 | |
| 7829 | /** |
| 7830 | * Sets the amount that the view is scaled in x around the pivot point, as a proportion of |
| 7831 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 7832 | * |
| 7833 | * @param scaleX The scaling factor. |
| 7834 | * @see #getPivotX() |
| 7835 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7836 | * |
| 7837 | * @attr ref android.R.styleable#View_scaleX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7838 | */ |
| 7839 | public void setScaleX(float scaleX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7840 | ensureTransformationInfo(); |
| 7841 | final TransformationInfo info = mTransformationInfo; |
| 7842 | if (info.mScaleX != scaleX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7843 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7844 | info.mScaleX = scaleX; |
| 7845 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7846 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7847 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7848 | mDisplayList.setScaleX(scaleX); |
| 7849 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7850 | } |
| 7851 | } |
| 7852 | |
| 7853 | /** |
| 7854 | * The amount that the view is scaled in y around the pivot point, as a proportion of |
| 7855 | * the view's unscaled height. A value of 1, the default, means that no scaling is applied. |
| 7856 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 7857 | * <p>By default, this is 1.0f. |
| 7858 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7859 | * @see #getPivotX() |
| 7860 | * @see #getPivotY() |
| 7861 | * @return The scaling factor. |
| 7862 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7863 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7864 | public float getScaleY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7865 | return mTransformationInfo != null ? mTransformationInfo.mScaleY : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7866 | } |
| 7867 | |
| 7868 | /** |
| 7869 | * Sets the amount that the view is scaled in Y around the pivot point, as a proportion of |
| 7870 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 7871 | * |
| 7872 | * @param scaleY The scaling factor. |
| 7873 | * @see #getPivotX() |
| 7874 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7875 | * |
| 7876 | * @attr ref android.R.styleable#View_scaleY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7877 | */ |
| 7878 | public void setScaleY(float scaleY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7879 | ensureTransformationInfo(); |
| 7880 | final TransformationInfo info = mTransformationInfo; |
| 7881 | if (info.mScaleY != scaleY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7882 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7883 | info.mScaleY = scaleY; |
| 7884 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7885 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7886 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7887 | mDisplayList.setScaleY(scaleY); |
| 7888 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7889 | } |
| 7890 | } |
| 7891 | |
| 7892 | /** |
| 7893 | * The x location of the point around which the view is {@link #setRotation(float) rotated} |
| 7894 | * and {@link #setScaleX(float) scaled}. |
| 7895 | * |
| 7896 | * @see #getRotation() |
| 7897 | * @see #getScaleX() |
| 7898 | * @see #getScaleY() |
| 7899 | * @see #getPivotY() |
| 7900 | * @return The x location of the pivot point. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7901 | * |
| 7902 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7903 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7904 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7905 | public float getPivotX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7906 | return mTransformationInfo != null ? mTransformationInfo.mPivotX : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7907 | } |
| 7908 | |
| 7909 | /** |
| 7910 | * Sets the x location of the point around which the view is |
| 7911 | * {@link #setRotation(float) rotated} and {@link #setScaleX(float) scaled}. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7912 | * By default, the pivot point is centered on the object. |
| 7913 | * Setting this property disables this behavior and causes the view to use only the |
| 7914 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7915 | * |
| 7916 | * @param pivotX The x location of the pivot point. |
| 7917 | * @see #getRotation() |
| 7918 | * @see #getScaleX() |
| 7919 | * @see #getScaleY() |
| 7920 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7921 | * |
| 7922 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7923 | */ |
| 7924 | public void setPivotX(float pivotX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7925 | ensureTransformationInfo(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7926 | mPrivateFlags |= PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7927 | final TransformationInfo info = mTransformationInfo; |
| 7928 | if (info.mPivotX != pivotX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7929 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7930 | info.mPivotX = pivotX; |
| 7931 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7932 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7933 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7934 | mDisplayList.setPivotX(pivotX); |
| 7935 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7936 | } |
| 7937 | } |
| 7938 | |
| 7939 | /** |
| 7940 | * The y location of the point around which the view is {@link #setRotation(float) rotated} |
| 7941 | * and {@link #setScaleY(float) scaled}. |
| 7942 | * |
| 7943 | * @see #getRotation() |
| 7944 | * @see #getScaleX() |
| 7945 | * @see #getScaleY() |
| 7946 | * @see #getPivotY() |
| 7947 | * @return The y location of the pivot point. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7948 | * |
| 7949 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7950 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7951 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7952 | public float getPivotY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7953 | return mTransformationInfo != null ? mTransformationInfo.mPivotY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7954 | } |
| 7955 | |
| 7956 | /** |
| 7957 | * 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] | 7958 | * and {@link #setScaleY(float) scaled}. By default, the pivot point is centered on the object. |
| 7959 | * Setting this property disables this behavior and causes the view to use only the |
| 7960 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7961 | * |
| 7962 | * @param pivotY The y location of the pivot point. |
| 7963 | * @see #getRotation() |
| 7964 | * @see #getScaleX() |
| 7965 | * @see #getScaleY() |
| 7966 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7967 | * |
| 7968 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7969 | */ |
| 7970 | public void setPivotY(float pivotY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7971 | ensureTransformationInfo(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7972 | mPrivateFlags |= PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7973 | final TransformationInfo info = mTransformationInfo; |
| 7974 | if (info.mPivotY != pivotY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7975 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7976 | info.mPivotY = pivotY; |
| 7977 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 7978 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 7979 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 7980 | mDisplayList.setPivotY(pivotY); |
| 7981 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7982 | } |
| 7983 | } |
| 7984 | |
| 7985 | /** |
| 7986 | * The opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 7987 | * completely transparent and 1 means the view is completely opaque. |
| 7988 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 7989 | * <p>By default this is 1.0f. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7990 | * @return The opacity of the view. |
| 7991 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7992 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7993 | public float getAlpha() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7994 | return mTransformationInfo != null ? mTransformationInfo.mAlpha : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7995 | } |
| 7996 | |
| 7997 | /** |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 7998 | * Returns whether this View has content which overlaps. This function, intended to be |
| 7999 | * overridden by specific View types, is an optimization when alpha is set on a view. If |
| 8000 | * rendering overlaps in a view with alpha < 1, that view is drawn to an offscreen buffer |
| 8001 | * and then composited it into place, which can be expensive. If the view has no overlapping |
| 8002 | * rendering, the view can draw each primitive with the appropriate alpha value directly. |
| 8003 | * An example of overlapping rendering is a TextView with a background image, such as a |
| 8004 | * Button. An example of non-overlapping rendering is a TextView with no background, or |
| 8005 | * an ImageView with only the foreground image. The default implementation returns true; |
| 8006 | * subclasses should override if they have cases which can be optimized. |
| 8007 | * |
| 8008 | * @return true if the content in this view might overlap, false otherwise. |
| 8009 | */ |
| 8010 | public boolean hasOverlappingRendering() { |
| 8011 | return true; |
| 8012 | } |
| 8013 | |
| 8014 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 8015 | * <p>Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 8016 | * completely transparent and 1 means the view is completely opaque.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8017 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 8018 | * <p>If this view overrides {@link #onSetAlpha(int)} to return true, then this view is |
| 8019 | * responsible for applying the opacity itself. Otherwise, calling this method is |
| 8020 | * equivalent to calling {@link #setLayerType(int, android.graphics.Paint)} and |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8021 | * setting a hardware layer.</p> |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8022 | * |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8023 | * <p>Note that setting alpha to a translucent value (0 < alpha < 1) may have |
| 8024 | * performance implications. It is generally best to use the alpha property sparingly and |
| 8025 | * transiently, as in the case of fading animations.</p> |
| 8026 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8027 | * @param alpha The opacity of the view. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8028 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8029 | * @see #setLayerType(int, android.graphics.Paint) |
| 8030 | * |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8031 | * @attr ref android.R.styleable#View_alpha |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8032 | */ |
| 8033 | public void setAlpha(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8034 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8035 | if (mTransformationInfo.mAlpha != alpha) { |
| 8036 | mTransformationInfo.mAlpha = alpha; |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8037 | if (onSetAlpha((int) (alpha * 255))) { |
| 8038 | mPrivateFlags |= ALPHA_SET; |
| 8039 | // subclass is handling alpha - don't optimize rendering cache invalidation |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8040 | invalidateParentCaches(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8041 | invalidate(true); |
| 8042 | } else { |
| 8043 | mPrivateFlags &= ~ALPHA_SET; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8044 | invalidateViewProperty(true, false); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8045 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8046 | mDisplayList.setAlpha(alpha); |
| 8047 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8048 | } |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8049 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8050 | } |
| 8051 | |
| 8052 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 8053 | * Faster version of setAlpha() which performs the same steps except there are |
| 8054 | * no calls to invalidate(). The caller of this function should perform proper invalidation |
| 8055 | * on the parent and this object. The return value indicates whether the subclass handles |
| 8056 | * alpha (the return value for onSetAlpha()). |
| 8057 | * |
| 8058 | * @param alpha The new value for the alpha property |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8059 | * @return true if the View subclass handles alpha (the return value for onSetAlpha()) and |
| 8060 | * 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] | 8061 | */ |
| 8062 | boolean setAlphaNoInvalidation(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8063 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8064 | if (mTransformationInfo.mAlpha != alpha) { |
| 8065 | mTransformationInfo.mAlpha = alpha; |
| 8066 | boolean subclassHandlesAlpha = onSetAlpha((int) (alpha * 255)); |
| 8067 | if (subclassHandlesAlpha) { |
| 8068 | mPrivateFlags |= ALPHA_SET; |
| 8069 | return true; |
| 8070 | } else { |
| 8071 | mPrivateFlags &= ~ALPHA_SET; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8072 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8073 | mDisplayList.setAlpha(alpha); |
| 8074 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8075 | } |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 8076 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8077 | return false; |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 8078 | } |
| 8079 | |
| 8080 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8081 | * Top position of this view relative to its parent. |
| 8082 | * |
| 8083 | * @return The top of this view, in pixels. |
| 8084 | */ |
| 8085 | @ViewDebug.CapturedViewProperty |
| 8086 | public final int getTop() { |
| 8087 | return mTop; |
| 8088 | } |
| 8089 | |
| 8090 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8091 | * Sets the top position of this view relative to its parent. This method is meant to be called |
| 8092 | * by the layout system and should not generally be called otherwise, because the property |
| 8093 | * may be changed at any time by the layout. |
| 8094 | * |
| 8095 | * @param top The top of this view, in pixels. |
| 8096 | */ |
| 8097 | public final void setTop(int top) { |
| 8098 | if (top != mTop) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8099 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8100 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8101 | || mTransformationInfo.mMatrixIsIdentity; |
| 8102 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8103 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8104 | int minTop; |
| 8105 | int yLoc; |
| 8106 | if (top < mTop) { |
| 8107 | minTop = top; |
| 8108 | yLoc = top - mTop; |
| 8109 | } else { |
| 8110 | minTop = mTop; |
| 8111 | yLoc = 0; |
| 8112 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8113 | invalidate(0, yLoc, mRight - mLeft, mBottom - minTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8114 | } |
| 8115 | } else { |
| 8116 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8117 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8118 | } |
| 8119 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8120 | int width = mRight - mLeft; |
| 8121 | int oldHeight = mBottom - mTop; |
| 8122 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8123 | mTop = top; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8124 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8125 | mDisplayList.setTop(mTop); |
| 8126 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8127 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8128 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 8129 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8130 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8131 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 8132 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8133 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8134 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8135 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8136 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8137 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 8138 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8139 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8140 | } |
| 8141 | } |
| 8142 | |
| 8143 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8144 | * Bottom position of this view relative to its parent. |
| 8145 | * |
| 8146 | * @return The bottom of this view, in pixels. |
| 8147 | */ |
| 8148 | @ViewDebug.CapturedViewProperty |
| 8149 | public final int getBottom() { |
| 8150 | return mBottom; |
| 8151 | } |
| 8152 | |
| 8153 | /** |
Michael Jurka | dab559a | 2011-01-04 20:31:51 -0800 | [diff] [blame] | 8154 | * True if this view has changed since the last time being drawn. |
| 8155 | * |
| 8156 | * @return The dirty state of this view. |
| 8157 | */ |
| 8158 | public boolean isDirty() { |
| 8159 | return (mPrivateFlags & DIRTY_MASK) != 0; |
| 8160 | } |
| 8161 | |
| 8162 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8163 | * Sets the bottom position of this view relative to its parent. This method is meant to be |
| 8164 | * called by the layout system and should not generally be called otherwise, because the |
| 8165 | * property may be changed at any time by the layout. |
| 8166 | * |
| 8167 | * @param bottom The bottom of this view, in pixels. |
| 8168 | */ |
| 8169 | public final void setBottom(int bottom) { |
| 8170 | if (bottom != mBottom) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8171 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8172 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8173 | || mTransformationInfo.mMatrixIsIdentity; |
| 8174 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8175 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8176 | int maxBottom; |
| 8177 | if (bottom < mBottom) { |
| 8178 | maxBottom = mBottom; |
| 8179 | } else { |
| 8180 | maxBottom = bottom; |
| 8181 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8182 | invalidate(0, 0, mRight - mLeft, maxBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8183 | } |
| 8184 | } else { |
| 8185 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8186 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8187 | } |
| 8188 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8189 | int width = mRight - mLeft; |
| 8190 | int oldHeight = mBottom - mTop; |
| 8191 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8192 | mBottom = bottom; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8193 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8194 | mDisplayList.setBottom(mBottom); |
| 8195 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8196 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8197 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 8198 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8199 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8200 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 8201 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8202 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8203 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8204 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8205 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8206 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 8207 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8208 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8209 | } |
| 8210 | } |
| 8211 | |
| 8212 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8213 | * Left position of this view relative to its parent. |
| 8214 | * |
| 8215 | * @return The left edge of this view, in pixels. |
| 8216 | */ |
| 8217 | @ViewDebug.CapturedViewProperty |
| 8218 | public final int getLeft() { |
| 8219 | return mLeft; |
| 8220 | } |
| 8221 | |
| 8222 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8223 | * Sets the left position of this view relative to its parent. This method is meant to be called |
| 8224 | * by the layout system and should not generally be called otherwise, because the property |
| 8225 | * may be changed at any time by the layout. |
| 8226 | * |
| 8227 | * @param left The bottom of this view, in pixels. |
| 8228 | */ |
| 8229 | public final void setLeft(int left) { |
| 8230 | if (left != mLeft) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8231 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8232 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8233 | || mTransformationInfo.mMatrixIsIdentity; |
| 8234 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8235 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8236 | int minLeft; |
| 8237 | int xLoc; |
| 8238 | if (left < mLeft) { |
| 8239 | minLeft = left; |
| 8240 | xLoc = left - mLeft; |
| 8241 | } else { |
| 8242 | minLeft = mLeft; |
| 8243 | xLoc = 0; |
| 8244 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8245 | invalidate(xLoc, 0, mRight - minLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8246 | } |
| 8247 | } else { |
| 8248 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8249 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8250 | } |
| 8251 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8252 | int oldWidth = mRight - mLeft; |
| 8253 | int height = mBottom - mTop; |
| 8254 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8255 | mLeft = left; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8256 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8257 | mDisplayList.setLeft(left); |
| 8258 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8259 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8260 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 8261 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8262 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8263 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 8264 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8265 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8266 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8267 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8268 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8269 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 8270 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8271 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8272 | if (USE_DISPLAY_LIST_PROPERTIES) { |
| 8273 | |
| 8274 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8275 | } |
| 8276 | } |
| 8277 | |
| 8278 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8279 | * Right position of this view relative to its parent. |
| 8280 | * |
| 8281 | * @return The right edge of this view, in pixels. |
| 8282 | */ |
| 8283 | @ViewDebug.CapturedViewProperty |
| 8284 | public final int getRight() { |
| 8285 | return mRight; |
| 8286 | } |
| 8287 | |
| 8288 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8289 | * Sets the right position of this view relative to its parent. This method is meant to be called |
| 8290 | * by the layout system and should not generally be called otherwise, because the property |
| 8291 | * may be changed at any time by the layout. |
| 8292 | * |
| 8293 | * @param right The bottom of this view, in pixels. |
| 8294 | */ |
| 8295 | public final void setRight(int right) { |
| 8296 | if (right != mRight) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8297 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8298 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8299 | || mTransformationInfo.mMatrixIsIdentity; |
| 8300 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8301 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8302 | int maxRight; |
| 8303 | if (right < mRight) { |
| 8304 | maxRight = mRight; |
| 8305 | } else { |
| 8306 | maxRight = right; |
| 8307 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8308 | invalidate(0, 0, maxRight - mLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8309 | } |
| 8310 | } else { |
| 8311 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8312 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8313 | } |
| 8314 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8315 | int oldWidth = mRight - mLeft; |
| 8316 | int height = mBottom - mTop; |
| 8317 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8318 | mRight = right; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8319 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8320 | mDisplayList.setRight(mRight); |
| 8321 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8322 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8323 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 8324 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8325 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8326 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 8327 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8328 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8329 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8330 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8331 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8332 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 8333 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8334 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8335 | } |
| 8336 | } |
| 8337 | |
| 8338 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8339 | * The visual x position of this view, in pixels. This is equivalent to the |
| 8340 | * {@link #setTranslationX(float) translationX} property plus the current |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8341 | * {@link #getLeft() left} property. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8342 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8343 | * @return The visual x position of this view, in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8344 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8345 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8346 | public float getX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8347 | return mLeft + (mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8348 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8349 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8350 | /** |
| 8351 | * Sets the visual x position of this view, in pixels. This is equivalent to setting the |
| 8352 | * {@link #setTranslationX(float) translationX} property to be the difference between |
| 8353 | * the x value passed in and the current {@link #getLeft() left} property. |
| 8354 | * |
| 8355 | * @param x The visual x position of this view, in pixels. |
| 8356 | */ |
| 8357 | public void setX(float x) { |
| 8358 | setTranslationX(x - mLeft); |
| 8359 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8360 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8361 | /** |
| 8362 | * The visual y position of this view, in pixels. This is equivalent to the |
| 8363 | * {@link #setTranslationY(float) translationY} property plus the current |
| 8364 | * {@link #getTop() top} property. |
| 8365 | * |
| 8366 | * @return The visual y position of this view, in pixels. |
| 8367 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8368 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8369 | public float getY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8370 | return mTop + (mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8371 | } |
| 8372 | |
| 8373 | /** |
| 8374 | * Sets the visual y position of this view, in pixels. This is equivalent to setting the |
| 8375 | * {@link #setTranslationY(float) translationY} property to be the difference between |
| 8376 | * the y value passed in and the current {@link #getTop() top} property. |
| 8377 | * |
| 8378 | * @param y The visual y position of this view, in pixels. |
| 8379 | */ |
| 8380 | public void setY(float y) { |
| 8381 | setTranslationY(y - mTop); |
| 8382 | } |
| 8383 | |
| 8384 | |
| 8385 | /** |
| 8386 | * The horizontal location of this view relative to its {@link #getLeft() left} position. |
| 8387 | * This position is post-layout, in addition to wherever the object's |
| 8388 | * layout placed it. |
| 8389 | * |
| 8390 | * @return The horizontal position of this view relative to its left position, in pixels. |
| 8391 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8392 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8393 | public float getTranslationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8394 | return mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0; |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8395 | } |
| 8396 | |
| 8397 | /** |
| 8398 | * Sets the horizontal location of this view relative to its {@link #getLeft() left} position. |
| 8399 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 8400 | * layout placed it. |
| 8401 | * |
| 8402 | * @param translationX The horizontal position of this view relative to its left position, |
| 8403 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8404 | * |
| 8405 | * @attr ref android.R.styleable#View_translationX |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8406 | */ |
| 8407 | public void setTranslationX(float translationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8408 | ensureTransformationInfo(); |
| 8409 | final TransformationInfo info = mTransformationInfo; |
| 8410 | if (info.mTranslationX != translationX) { |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8411 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8412 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8413 | info.mTranslationX = translationX; |
| 8414 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8415 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8416 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8417 | mDisplayList.setTranslationX(translationX); |
| 8418 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8419 | } |
| 8420 | } |
| 8421 | |
| 8422 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8423 | * The horizontal location of this view relative to its {@link #getTop() top} position. |
| 8424 | * This position is post-layout, in addition to wherever the object's |
| 8425 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8426 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8427 | * @return The vertical position of this view relative to its top position, |
| 8428 | * in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8429 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8430 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8431 | public float getTranslationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8432 | return mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8433 | } |
| 8434 | |
| 8435 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8436 | * Sets the vertical location of this view relative to its {@link #getTop() top} position. |
| 8437 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 8438 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8439 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8440 | * @param translationY The vertical position of this view relative to its top position, |
| 8441 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8442 | * |
| 8443 | * @attr ref android.R.styleable#View_translationY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8444 | */ |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8445 | public void setTranslationY(float translationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8446 | ensureTransformationInfo(); |
| 8447 | final TransformationInfo info = mTransformationInfo; |
| 8448 | if (info.mTranslationY != translationY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8449 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8450 | info.mTranslationY = translationY; |
| 8451 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8452 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8453 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8454 | mDisplayList.setTranslationY(translationY); |
| 8455 | } |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8456 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8457 | } |
| 8458 | |
| 8459 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8460 | * Hit rectangle in parent's coordinates |
| 8461 | * |
| 8462 | * @param outRect The hit rectangle of the view. |
| 8463 | */ |
| 8464 | public void getHitRect(Rect outRect) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8465 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8466 | final TransformationInfo info = mTransformationInfo; |
| 8467 | if (info == null || info.mMatrixIsIdentity || mAttachInfo == null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8468 | outRect.set(mLeft, mTop, mRight, mBottom); |
| 8469 | } else { |
| 8470 | final RectF tmpRect = mAttachInfo.mTmpTransformRect; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8471 | tmpRect.set(-info.mPivotX, -info.mPivotY, |
| 8472 | getWidth() - info.mPivotX, getHeight() - info.mPivotY); |
| 8473 | info.mMatrix.mapRect(tmpRect); |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8474 | outRect.set((int) tmpRect.left + mLeft, (int) tmpRect.top + mTop, |
| 8475 | (int) tmpRect.right + mLeft, (int) tmpRect.bottom + mTop); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8476 | } |
| 8477 | } |
| 8478 | |
| 8479 | /** |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8480 | * Determines whether the given point, in local coordinates is inside the view. |
| 8481 | */ |
| 8482 | /*package*/ final boolean pointInView(float localX, float localY) { |
| 8483 | return localX >= 0 && localX < (mRight - mLeft) |
| 8484 | && localY >= 0 && localY < (mBottom - mTop); |
| 8485 | } |
| 8486 | |
| 8487 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8488 | * Utility method to determine whether the given point, in local coordinates, |
| 8489 | * is inside the view, where the area of the view is expanded by the slop factor. |
| 8490 | * This method is called while processing touch-move events to determine if the event |
| 8491 | * is still within the view. |
| 8492 | */ |
| 8493 | private boolean pointInView(float localX, float localY, float slop) { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8494 | return localX >= -slop && localY >= -slop && localX < ((mRight - mLeft) + slop) && |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8495 | localY < ((mBottom - mTop) + slop); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8496 | } |
| 8497 | |
| 8498 | /** |
| 8499 | * When a view has focus and the user navigates away from it, the next view is searched for |
| 8500 | * starting from the rectangle filled in by this method. |
| 8501 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8502 | * By default, the rectange is the {@link #getDrawingRect(android.graphics.Rect)}) |
| 8503 | * of the view. However, if your view maintains some idea of internal selection, |
| 8504 | * such as a cursor, or a selected row or column, you should override this method and |
| 8505 | * fill in a more specific rectangle. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8506 | * |
| 8507 | * @param r The rectangle to fill in, in this view's coordinates. |
| 8508 | */ |
| 8509 | public void getFocusedRect(Rect r) { |
| 8510 | getDrawingRect(r); |
| 8511 | } |
| 8512 | |
| 8513 | /** |
| 8514 | * If some part of this view is not clipped by any of its parents, then |
| 8515 | * 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] | 8516 | * coordinates (without taking possible View rotations into account), offset |
| 8517 | * it by -globalOffset (e.g. r.offset(-globalOffset.x, -globalOffset.y)). |
| 8518 | * 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] | 8519 | * |
| 8520 | * @param r If true is returned, r holds the global coordinates of the |
| 8521 | * visible portion of this view. |
| 8522 | * @param globalOffset If true is returned, globalOffset holds the dx,dy |
| 8523 | * between this view and its root. globalOffet may be null. |
| 8524 | * @return true if r is non-empty (i.e. part of the view is visible at the |
| 8525 | * root level. |
| 8526 | */ |
| 8527 | public boolean getGlobalVisibleRect(Rect r, Point globalOffset) { |
| 8528 | int width = mRight - mLeft; |
| 8529 | int height = mBottom - mTop; |
| 8530 | if (width > 0 && height > 0) { |
| 8531 | r.set(0, 0, width, height); |
| 8532 | if (globalOffset != null) { |
| 8533 | globalOffset.set(-mScrollX, -mScrollY); |
| 8534 | } |
| 8535 | return mParent == null || mParent.getChildVisibleRect(this, r, globalOffset); |
| 8536 | } |
| 8537 | return false; |
| 8538 | } |
| 8539 | |
| 8540 | public final boolean getGlobalVisibleRect(Rect r) { |
| 8541 | return getGlobalVisibleRect(r, null); |
| 8542 | } |
| 8543 | |
| 8544 | public final boolean getLocalVisibleRect(Rect r) { |
| 8545 | Point offset = new Point(); |
| 8546 | if (getGlobalVisibleRect(r, offset)) { |
| 8547 | r.offset(-offset.x, -offset.y); // make r local |
| 8548 | return true; |
| 8549 | } |
| 8550 | return false; |
| 8551 | } |
| 8552 | |
| 8553 | /** |
| 8554 | * Offset this view's vertical location by the specified number of pixels. |
| 8555 | * |
| 8556 | * @param offset the number of pixels to offset the view by |
| 8557 | */ |
| 8558 | public void offsetTopAndBottom(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8559 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8560 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8561 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8562 | || mTransformationInfo.mMatrixIsIdentity; |
| 8563 | if (matrixIsIdentity) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8564 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8565 | invalidateViewProperty(false, false); |
| 8566 | } else { |
| 8567 | final ViewParent p = mParent; |
| 8568 | if (p != null && mAttachInfo != null) { |
| 8569 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 8570 | int minTop; |
| 8571 | int maxBottom; |
| 8572 | int yLoc; |
| 8573 | if (offset < 0) { |
| 8574 | minTop = mTop + offset; |
| 8575 | maxBottom = mBottom; |
| 8576 | yLoc = offset; |
| 8577 | } else { |
| 8578 | minTop = mTop; |
| 8579 | maxBottom = mBottom + offset; |
| 8580 | yLoc = 0; |
| 8581 | } |
| 8582 | r.set(0, yLoc, mRight - mLeft, maxBottom - minTop); |
| 8583 | p.invalidateChild(this, r); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 8584 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8585 | } |
| 8586 | } else { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8587 | invalidateViewProperty(false, false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8588 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8589 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8590 | mTop += offset; |
| 8591 | mBottom += offset; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8592 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8593 | mDisplayList.offsetTopBottom(offset); |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8594 | invalidateViewProperty(false, false); |
| 8595 | } else { |
| 8596 | if (!matrixIsIdentity) { |
| 8597 | invalidateViewProperty(false, true); |
| 8598 | } |
| 8599 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8600 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8601 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8602 | } |
| 8603 | |
| 8604 | /** |
| 8605 | * Offset this view's horizontal location by the specified amount of pixels. |
| 8606 | * |
| 8607 | * @param offset the numer of pixels to offset the view by |
| 8608 | */ |
| 8609 | public void offsetLeftAndRight(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8610 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8611 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8612 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8613 | || mTransformationInfo.mMatrixIsIdentity; |
| 8614 | if (matrixIsIdentity) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8615 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8616 | invalidateViewProperty(false, false); |
| 8617 | } else { |
| 8618 | final ViewParent p = mParent; |
| 8619 | if (p != null && mAttachInfo != null) { |
| 8620 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 8621 | int minLeft; |
| 8622 | int maxRight; |
| 8623 | if (offset < 0) { |
| 8624 | minLeft = mLeft + offset; |
| 8625 | maxRight = mRight; |
| 8626 | } else { |
| 8627 | minLeft = mLeft; |
| 8628 | maxRight = mRight + offset; |
| 8629 | } |
| 8630 | r.set(0, 0, maxRight - minLeft, mBottom - mTop); |
| 8631 | p.invalidateChild(this, r); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 8632 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8633 | } |
| 8634 | } else { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8635 | invalidateViewProperty(false, false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8636 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8637 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8638 | mLeft += offset; |
| 8639 | mRight += offset; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8640 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8641 | mDisplayList.offsetLeftRight(offset); |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8642 | invalidateViewProperty(false, false); |
| 8643 | } else { |
| 8644 | if (!matrixIsIdentity) { |
| 8645 | invalidateViewProperty(false, true); |
| 8646 | } |
| 8647 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8648 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8649 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8650 | } |
| 8651 | |
| 8652 | /** |
| 8653 | * Get the LayoutParams associated with this view. All views should have |
| 8654 | * layout parameters. These supply parameters to the <i>parent</i> of this |
| 8655 | * view specifying how it should be arranged. There are many subclasses of |
| 8656 | * ViewGroup.LayoutParams, and these correspond to the different subclasses |
| 8657 | * of ViewGroup that are responsible for arranging their children. |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 8658 | * |
| 8659 | * This method may return null if this View is not attached to a parent |
| 8660 | * ViewGroup or {@link #setLayoutParams(android.view.ViewGroup.LayoutParams)} |
| 8661 | * was not invoked successfully. When a View is attached to a parent |
| 8662 | * ViewGroup, this method must not return null. |
| 8663 | * |
| 8664 | * @return The LayoutParams associated with this view, or null if no |
| 8665 | * parameters have been set yet |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8666 | */ |
Konstantin Lopyrev | 91a7f5f | 2010-08-10 18:54:54 -0700 | [diff] [blame] | 8667 | @ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8668 | public ViewGroup.LayoutParams getLayoutParams() { |
| 8669 | return mLayoutParams; |
| 8670 | } |
| 8671 | |
| 8672 | /** |
| 8673 | * Set the layout parameters associated with this view. These supply |
| 8674 | * parameters to the <i>parent</i> of this view specifying how it should be |
| 8675 | * arranged. There are many subclasses of ViewGroup.LayoutParams, and these |
| 8676 | * correspond to the different subclasses of ViewGroup that are responsible |
| 8677 | * for arranging their children. |
| 8678 | * |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 8679 | * @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] | 8680 | */ |
| 8681 | public void setLayoutParams(ViewGroup.LayoutParams params) { |
| 8682 | if (params == null) { |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 8683 | throw new NullPointerException("Layout parameters cannot be null"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8684 | } |
| 8685 | mLayoutParams = params; |
Philip Milne | d7dd890 | 2012-01-26 16:55:30 -0800 | [diff] [blame] | 8686 | if (mParent instanceof ViewGroup) { |
| 8687 | ((ViewGroup) mParent).onSetLayoutParams(this, params); |
| 8688 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8689 | requestLayout(); |
| 8690 | } |
| 8691 | |
| 8692 | /** |
| 8693 | * Set the scrolled position of your view. This will cause a call to |
| 8694 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8695 | * invalidated. |
| 8696 | * @param x the x position to scroll to |
| 8697 | * @param y the y position to scroll to |
| 8698 | */ |
| 8699 | public void scrollTo(int x, int y) { |
| 8700 | if (mScrollX != x || mScrollY != y) { |
| 8701 | int oldX = mScrollX; |
| 8702 | int oldY = mScrollY; |
| 8703 | mScrollX = x; |
| 8704 | mScrollY = y; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8705 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8706 | onScrollChanged(mScrollX, mScrollY, oldX, oldY); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8707 | if (!awakenScrollBars()) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8708 | invalidate(true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8709 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8710 | } |
| 8711 | } |
| 8712 | |
| 8713 | /** |
| 8714 | * Move the scrolled position of your view. This will cause a call to |
| 8715 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8716 | * invalidated. |
| 8717 | * @param x the amount of pixels to scroll by horizontally |
| 8718 | * @param y the amount of pixels to scroll by vertically |
| 8719 | */ |
| 8720 | public void scrollBy(int x, int y) { |
| 8721 | scrollTo(mScrollX + x, mScrollY + y); |
| 8722 | } |
| 8723 | |
| 8724 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8725 | * <p>Trigger the scrollbars to draw. When invoked this method starts an |
| 8726 | * animation to fade the scrollbars out after a default delay. If a subclass |
| 8727 | * provides animated scrolling, the start delay should equal the duration |
| 8728 | * of the scrolling animation.</p> |
| 8729 | * |
| 8730 | * <p>The animation starts only if at least one of the scrollbars is |
| 8731 | * enabled, as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 8732 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 8733 | * this method returns true, and false otherwise. If the animation is |
| 8734 | * started, this method calls {@link #invalidate()}; in that case the |
| 8735 | * caller should not call {@link #invalidate()}.</p> |
| 8736 | * |
| 8737 | * <p>This method should be invoked every time a subclass directly updates |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 8738 | * the scroll parameters.</p> |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8739 | * |
| 8740 | * <p>This method is automatically invoked by {@link #scrollBy(int, int)} |
| 8741 | * and {@link #scrollTo(int, int)}.</p> |
| 8742 | * |
| 8743 | * @return true if the animation is played, false otherwise |
| 8744 | * |
| 8745 | * @see #awakenScrollBars(int) |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8746 | * @see #scrollBy(int, int) |
| 8747 | * @see #scrollTo(int, int) |
| 8748 | * @see #isHorizontalScrollBarEnabled() |
| 8749 | * @see #isVerticalScrollBarEnabled() |
| 8750 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 8751 | * @see #setVerticalScrollBarEnabled(boolean) |
| 8752 | */ |
| 8753 | protected boolean awakenScrollBars() { |
| 8754 | return mScrollCache != null && |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8755 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade, true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8756 | } |
| 8757 | |
| 8758 | /** |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 8759 | * Trigger the scrollbars to draw. |
| 8760 | * This method differs from awakenScrollBars() only in its default duration. |
| 8761 | * initialAwakenScrollBars() will show the scroll bars for longer than |
| 8762 | * usual to give the user more of a chance to notice them. |
| 8763 | * |
| 8764 | * @return true if the animation is played, false otherwise. |
| 8765 | */ |
| 8766 | private boolean initialAwakenScrollBars() { |
| 8767 | return mScrollCache != null && |
| 8768 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade * 4, true); |
| 8769 | } |
| 8770 | |
| 8771 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8772 | * <p> |
| 8773 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 8774 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 8775 | * provides animated scrolling, the start delay should equal the duration of |
| 8776 | * the scrolling animation. |
| 8777 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8778 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8779 | * <p> |
| 8780 | * The animation starts only if at least one of the scrollbars is enabled, |
| 8781 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 8782 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 8783 | * this method returns true, and false otherwise. If the animation is |
| 8784 | * started, this method calls {@link #invalidate()}; in that case the caller |
| 8785 | * should not call {@link #invalidate()}. |
| 8786 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8787 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8788 | * <p> |
| 8789 | * This method should be invoked everytime a subclass directly updates the |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 8790 | * scroll parameters. |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8791 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8792 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8793 | * @param startDelay the delay, in milliseconds, after which the animation |
| 8794 | * should start; when the delay is 0, the animation starts |
| 8795 | * immediately |
| 8796 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8797 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8798 | * @see #scrollBy(int, int) |
| 8799 | * @see #scrollTo(int, int) |
| 8800 | * @see #isHorizontalScrollBarEnabled() |
| 8801 | * @see #isVerticalScrollBarEnabled() |
| 8802 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 8803 | * @see #setVerticalScrollBarEnabled(boolean) |
| 8804 | */ |
| 8805 | protected boolean awakenScrollBars(int startDelay) { |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8806 | return awakenScrollBars(startDelay, true); |
| 8807 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8808 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8809 | /** |
| 8810 | * <p> |
| 8811 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 8812 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 8813 | * provides animated scrolling, the start delay should equal the duration of |
| 8814 | * the scrolling animation. |
| 8815 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8816 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8817 | * <p> |
| 8818 | * The animation starts only if at least one of the scrollbars is enabled, |
| 8819 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 8820 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 8821 | * this method returns true, and false otherwise. If the animation is |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8822 | * started, this method calls {@link #invalidate()} if the invalidate parameter |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8823 | * is set to true; in that case the caller |
| 8824 | * should not call {@link #invalidate()}. |
| 8825 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8826 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8827 | * <p> |
| 8828 | * This method should be invoked everytime a subclass directly updates the |
| 8829 | * scroll parameters. |
| 8830 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8831 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8832 | * @param startDelay the delay, in milliseconds, after which the animation |
| 8833 | * should start; when the delay is 0, the animation starts |
| 8834 | * immediately |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8835 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8836 | * @param invalidate Wheter this method should call invalidate |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8837 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8838 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8839 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8840 | * @see #scrollBy(int, int) |
| 8841 | * @see #scrollTo(int, int) |
| 8842 | * @see #isHorizontalScrollBarEnabled() |
| 8843 | * @see #isVerticalScrollBarEnabled() |
| 8844 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 8845 | * @see #setVerticalScrollBarEnabled(boolean) |
| 8846 | */ |
| 8847 | protected boolean awakenScrollBars(int startDelay, boolean invalidate) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8848 | final ScrollabilityCache scrollCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8849 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8850 | if (scrollCache == null || !scrollCache.fadeScrollBars) { |
| 8851 | return false; |
| 8852 | } |
| 8853 | |
| 8854 | if (scrollCache.scrollBar == null) { |
| 8855 | scrollCache.scrollBar = new ScrollBarDrawable(); |
| 8856 | } |
| 8857 | |
| 8858 | if (isHorizontalScrollBarEnabled() || isVerticalScrollBarEnabled()) { |
| 8859 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8860 | if (invalidate) { |
| 8861 | // Invalidate to show the scrollbars |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8862 | invalidate(true); |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8863 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8864 | |
| 8865 | if (scrollCache.state == ScrollabilityCache.OFF) { |
| 8866 | // FIXME: this is copied from WindowManagerService. |
| 8867 | // We should get this value from the system when it |
| 8868 | // is possible to do so. |
| 8869 | final int KEY_REPEAT_FIRST_DELAY = 750; |
| 8870 | startDelay = Math.max(KEY_REPEAT_FIRST_DELAY, startDelay); |
| 8871 | } |
| 8872 | |
| 8873 | // Tell mScrollCache when we should start fading. This may |
| 8874 | // extend the fade start time if one was already scheduled |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 8875 | long fadeStartTime = AnimationUtils.currentAnimationTimeMillis() + startDelay; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8876 | scrollCache.fadeStartTime = fadeStartTime; |
| 8877 | scrollCache.state = ScrollabilityCache.ON; |
| 8878 | |
| 8879 | // Schedule our fader to run, unscheduling any old ones first |
| 8880 | if (mAttachInfo != null) { |
| 8881 | mAttachInfo.mHandler.removeCallbacks(scrollCache); |
| 8882 | mAttachInfo.mHandler.postAtTime(scrollCache, fadeStartTime); |
| 8883 | } |
| 8884 | |
| 8885 | return true; |
| 8886 | } |
| 8887 | |
| 8888 | return false; |
| 8889 | } |
| 8890 | |
| 8891 | /** |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8892 | * Do not invalidate views which are not visible and which are not running an animation. They |
| 8893 | * will not get drawn and they should not set dirty flags as if they will be drawn |
| 8894 | */ |
| 8895 | private boolean skipInvalidate() { |
| 8896 | return (mViewFlags & VISIBILITY_MASK) != VISIBLE && mCurrentAnimation == null && |
| 8897 | (!(mParent instanceof ViewGroup) || |
| 8898 | !((ViewGroup) mParent).isViewTransitioning(this)); |
| 8899 | } |
| 8900 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 8901 | * 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] | 8902 | * visible, {@link #onDraw(android.graphics.Canvas)} will be called at some point |
| 8903 | * in the future. This must be called from a UI thread. To call from a non-UI |
| 8904 | * thread, call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8905 | * |
| 8906 | * WARNING: This method is destructive to dirty. |
| 8907 | * @param dirty the rectangle representing the bounds of the dirty region |
| 8908 | */ |
| 8909 | public void invalidate(Rect dirty) { |
| 8910 | if (ViewDebug.TRACE_HIERARCHY) { |
| 8911 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 8912 | } |
| 8913 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8914 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 8915 | return; |
| 8916 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8917 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8918 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || |
| 8919 | (mPrivateFlags & INVALIDATED) != INVALIDATED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8920 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8921 | mPrivateFlags |= INVALIDATED; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 8922 | mPrivateFlags |= DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8923 | final ViewParent p = mParent; |
| 8924 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8925 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 8926 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 8927 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 8928 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 8929 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8930 | p.invalidateChild(this, null); |
| 8931 | return; |
| 8932 | } |
Romain Guy | af636eb | 2010-12-09 17:47:21 -0800 | [diff] [blame] | 8933 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8934 | if (p != null && ai != null) { |
| 8935 | final int scrollX = mScrollX; |
| 8936 | final int scrollY = mScrollY; |
| 8937 | final Rect r = ai.mTmpInvalRect; |
| 8938 | r.set(dirty.left - scrollX, dirty.top - scrollY, |
| 8939 | dirty.right - scrollX, dirty.bottom - scrollY); |
| 8940 | mParent.invalidateChild(this, r); |
| 8941 | } |
| 8942 | } |
| 8943 | } |
| 8944 | |
| 8945 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 8946 | * 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] | 8947 | * The coordinates of the dirty rect are relative to the view. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8948 | * If the view is visible, {@link #onDraw(android.graphics.Canvas)} |
| 8949 | * will be called at some point in the future. This must be called from |
| 8950 | * 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] | 8951 | * @param l the left position of the dirty region |
| 8952 | * @param t the top position of the dirty region |
| 8953 | * @param r the right position of the dirty region |
| 8954 | * @param b the bottom position of the dirty region |
| 8955 | */ |
| 8956 | public void invalidate(int l, int t, int r, int b) { |
| 8957 | if (ViewDebug.TRACE_HIERARCHY) { |
| 8958 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 8959 | } |
| 8960 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8961 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 8962 | return; |
| 8963 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8964 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8965 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || |
| 8966 | (mPrivateFlags & INVALIDATED) != INVALIDATED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8967 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8968 | mPrivateFlags |= INVALIDATED; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 8969 | mPrivateFlags |= DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8970 | final ViewParent p = mParent; |
| 8971 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8972 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 8973 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 8974 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 8975 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 8976 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8977 | p.invalidateChild(this, null); |
| 8978 | return; |
| 8979 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 8980 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8981 | if (p != null && ai != null && l < r && t < b) { |
| 8982 | final int scrollX = mScrollX; |
| 8983 | final int scrollY = mScrollY; |
| 8984 | final Rect tmpr = ai.mTmpInvalRect; |
| 8985 | tmpr.set(l - scrollX, t - scrollY, r - scrollX, b - scrollY); |
| 8986 | p.invalidateChild(this, tmpr); |
| 8987 | } |
| 8988 | } |
| 8989 | } |
| 8990 | |
| 8991 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8992 | * Invalidate the whole view. If the view is visible, |
| 8993 | * {@link #onDraw(android.graphics.Canvas)} will be called at some point in |
| 8994 | * the future. This must be called from a UI thread. To call from a non-UI thread, |
| 8995 | * call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8996 | */ |
| 8997 | public void invalidate() { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8998 | invalidate(true); |
| 8999 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9000 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9001 | /** |
| 9002 | * This is where the invalidate() work actually happens. A full invalidate() |
| 9003 | * causes the drawing cache to be invalidated, but this function can be called with |
| 9004 | * invalidateCache set to false to skip that invalidation step for cases that do not |
| 9005 | * need it (for example, a component that remains at the same dimensions with the same |
| 9006 | * content). |
| 9007 | * |
| 9008 | * @param invalidateCache Whether the drawing cache for this view should be invalidated as |
| 9009 | * well. This is usually true for a full invalidate, but may be set to false if the |
| 9010 | * View's contents or dimensions have not changed. |
| 9011 | */ |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 9012 | void invalidate(boolean invalidateCache) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9013 | if (ViewDebug.TRACE_HIERARCHY) { |
| 9014 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 9015 | } |
| 9016 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 9017 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 9018 | return; |
| 9019 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 9020 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Romain Guy | c5d5586 | 2011-01-21 19:01:46 -0800 | [diff] [blame] | 9021 | (invalidateCache && (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) || |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9022 | (mPrivateFlags & INVALIDATED) != INVALIDATED || isOpaque() != mLastIsOpaque) { |
| 9023 | mLastIsOpaque = isOpaque(); |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9024 | mPrivateFlags &= ~DRAWN; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 9025 | mPrivateFlags |= DIRTY; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9026 | if (invalidateCache) { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9027 | mPrivateFlags |= INVALIDATED; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9028 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 9029 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9030 | final AttachInfo ai = mAttachInfo; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 9031 | final ViewParent p = mParent; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 9032 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 9033 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 9034 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 9035 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 9036 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 9037 | p.invalidateChild(this, null); |
| 9038 | return; |
| 9039 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 9040 | } |
Michael Jurka | ebefea4 | 2010-11-15 16:04:01 -0800 | [diff] [blame] | 9041 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9042 | if (p != null && ai != null) { |
| 9043 | final Rect r = ai.mTmpInvalRect; |
| 9044 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 9045 | // Don't call invalidate -- we don't want to internally scroll |
| 9046 | // our own bounds |
| 9047 | p.invalidateChild(this, r); |
| 9048 | } |
| 9049 | } |
| 9050 | } |
| 9051 | |
| 9052 | /** |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9053 | * Quick invalidation for View property changes (alpha, translationXY, etc.). We don't want to |
| 9054 | * set any flags or handle all of the cases handled by the default invalidation methods. |
| 9055 | * Instead, we just want to schedule a traversal in ViewRootImpl with the appropriate |
| 9056 | * dirty rect. This method calls into fast invalidation methods in ViewGroup that |
| 9057 | * walk up the hierarchy, transforming the dirty rect as necessary. |
| 9058 | * |
| 9059 | * The method also handles normal invalidation logic if display list properties are not |
| 9060 | * being used in this view. The invalidateParent and forceRedraw flags are used by that |
| 9061 | * backup approach, to handle these cases used in the various property-setting methods. |
| 9062 | * |
| 9063 | * @param invalidateParent Force a call to invalidateParentCaches() if display list properties |
| 9064 | * are not being used in this view |
| 9065 | * @param forceRedraw Mark the view as DRAWN to force the invalidation to propagate, if display |
| 9066 | * list properties are not being used in this view |
| 9067 | */ |
| 9068 | void invalidateViewProperty(boolean invalidateParent, boolean forceRedraw) { |
| 9069 | if (!USE_DISPLAY_LIST_PROPERTIES || mDisplayList == null || |
| 9070 | (mPrivateFlags & DRAW_ANIMATION) == DRAW_ANIMATION) { |
| 9071 | if (invalidateParent) { |
| 9072 | invalidateParentCaches(); |
| 9073 | } |
| 9074 | if (forceRedraw) { |
| 9075 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
| 9076 | } |
| 9077 | invalidate(false); |
| 9078 | } else { |
| 9079 | final AttachInfo ai = mAttachInfo; |
| 9080 | final ViewParent p = mParent; |
| 9081 | if (p != null && ai != null) { |
| 9082 | final Rect r = ai.mTmpInvalRect; |
| 9083 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 9084 | if (mParent instanceof ViewGroup) { |
| 9085 | ((ViewGroup) mParent).invalidateChildFast(this, r); |
| 9086 | } else { |
| 9087 | mParent.invalidateChild(this, r); |
| 9088 | } |
| 9089 | } |
| 9090 | } |
| 9091 | } |
| 9092 | |
| 9093 | /** |
| 9094 | * Utility method to transform a given Rect by the current matrix of this view. |
| 9095 | */ |
| 9096 | void transformRect(final Rect rect) { |
| 9097 | if (!getMatrix().isIdentity()) { |
| 9098 | RectF boundingRect = mAttachInfo.mTmpTransformRect; |
| 9099 | boundingRect.set(rect); |
| 9100 | getMatrix().mapRect(boundingRect); |
| 9101 | rect.set((int) (boundingRect.left - 0.5f), |
| 9102 | (int) (boundingRect.top - 0.5f), |
| 9103 | (int) (boundingRect.right + 0.5f), |
| 9104 | (int) (boundingRect.bottom + 0.5f)); |
| 9105 | } |
| 9106 | } |
| 9107 | |
| 9108 | /** |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9109 | * 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] | 9110 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 9111 | * 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] | 9112 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method only |
| 9113 | * clears the parent caches and does not causes an invalidate event. |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9114 | * |
| 9115 | * @hide |
| 9116 | */ |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9117 | protected void invalidateParentCaches() { |
| 9118 | if (mParent instanceof View) { |
| 9119 | ((View) mParent).mPrivateFlags |= INVALIDATED; |
| 9120 | } |
| 9121 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9122 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9123 | /** |
| 9124 | * Used to indicate that the parent of this view should be invalidated. This functionality |
| 9125 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 9126 | * which is necessary when various parent-managed properties of the view change, such as |
| 9127 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method will propagate |
| 9128 | * an invalidation event to the parent. |
| 9129 | * |
| 9130 | * @hide |
| 9131 | */ |
| 9132 | protected void invalidateParentIfNeeded() { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9133 | if (isHardwareAccelerated() && mParent instanceof View) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9134 | ((View) mParent).invalidate(true); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9135 | } |
| 9136 | } |
| 9137 | |
| 9138 | /** |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 9139 | * Indicates whether this View is opaque. An opaque View guarantees that it will |
| 9140 | * draw all the pixels overlapping its bounds using a fully opaque color. |
| 9141 | * |
| 9142 | * Subclasses of View should override this method whenever possible to indicate |
| 9143 | * whether an instance is opaque. Opaque Views are treated in a special way by |
| 9144 | * the View hierarchy, possibly allowing it to perform optimizations during |
| 9145 | * invalidate/draw passes. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 9146 | * |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 9147 | * @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] | 9148 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 9149 | @ViewDebug.ExportedProperty(category = "drawing") |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 9150 | public boolean isOpaque() { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 9151 | return (mPrivateFlags & OPAQUE_MASK) == OPAQUE_MASK && |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9152 | ((mTransformationInfo != null ? mTransformationInfo.mAlpha : 1) |
| 9153 | >= 1.0f - ViewConfiguration.ALPHA_THRESHOLD); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9154 | } |
| 9155 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 9156 | /** |
| 9157 | * @hide |
| 9158 | */ |
| 9159 | protected void computeOpaqueFlags() { |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9160 | // Opaque if: |
| 9161 | // - Has a background |
| 9162 | // - Background is opaque |
| 9163 | // - Doesn't have scrollbars or scrollbars are inside overlay |
| 9164 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9165 | if (mBackground != null && mBackground.getOpacity() == PixelFormat.OPAQUE) { |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9166 | mPrivateFlags |= OPAQUE_BACKGROUND; |
| 9167 | } else { |
| 9168 | mPrivateFlags &= ~OPAQUE_BACKGROUND; |
| 9169 | } |
| 9170 | |
| 9171 | final int flags = mViewFlags; |
| 9172 | if (((flags & SCROLLBARS_VERTICAL) == 0 && (flags & SCROLLBARS_HORIZONTAL) == 0) || |
| 9173 | (flags & SCROLLBARS_STYLE_MASK) == SCROLLBARS_INSIDE_OVERLAY) { |
| 9174 | mPrivateFlags |= OPAQUE_SCROLLBARS; |
| 9175 | } else { |
| 9176 | mPrivateFlags &= ~OPAQUE_SCROLLBARS; |
| 9177 | } |
| 9178 | } |
| 9179 | |
| 9180 | /** |
| 9181 | * @hide |
| 9182 | */ |
| 9183 | protected boolean hasOpaqueScrollbars() { |
| 9184 | return (mPrivateFlags & OPAQUE_SCROLLBARS) == OPAQUE_SCROLLBARS; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 9185 | } |
| 9186 | |
| 9187 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9188 | * @return A handler associated with the thread running the View. This |
| 9189 | * handler can be used to pump events in the UI events queue. |
| 9190 | */ |
| 9191 | public Handler getHandler() { |
| 9192 | if (mAttachInfo != null) { |
| 9193 | return mAttachInfo.mHandler; |
| 9194 | } |
| 9195 | return null; |
| 9196 | } |
| 9197 | |
| 9198 | /** |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9199 | * Gets the view root associated with the View. |
| 9200 | * @return The view root, or null if none. |
| 9201 | * @hide |
| 9202 | */ |
| 9203 | public ViewRootImpl getViewRootImpl() { |
| 9204 | if (mAttachInfo != null) { |
| 9205 | return mAttachInfo.mViewRootImpl; |
| 9206 | } |
| 9207 | return null; |
| 9208 | } |
| 9209 | |
| 9210 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9211 | * <p>Causes the Runnable to be added to the message queue. |
| 9212 | * The runnable will be run on the user interface thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9213 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9214 | * <p>This method can be invoked from outside of the UI thread |
| 9215 | * 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] | 9216 | * |
| 9217 | * @param action The Runnable that will be executed. |
| 9218 | * |
| 9219 | * @return Returns true if the Runnable was successfully placed in to the |
| 9220 | * message queue. Returns false on failure, usually because the |
| 9221 | * looper processing the message queue is exiting. |
| 9222 | */ |
| 9223 | public boolean post(Runnable action) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9224 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 9225 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9226 | return attachInfo.mHandler.post(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9227 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9228 | // Assume that post will succeed later |
| 9229 | ViewRootImpl.getRunQueue().post(action); |
| 9230 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9231 | } |
| 9232 | |
| 9233 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9234 | * <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] | 9235 | * after the specified amount of time elapses. |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9236 | * The runnable will be run on the user interface thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9237 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9238 | * <p>This method can be invoked from outside of the UI thread |
| 9239 | * 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] | 9240 | * |
| 9241 | * @param action The Runnable that will be executed. |
| 9242 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 9243 | * will be executed. |
| 9244 | * |
| 9245 | * @return true if the Runnable was successfully placed in to the |
| 9246 | * message queue. Returns false on failure, usually because the |
| 9247 | * looper processing the message queue is exiting. Note that a |
| 9248 | * result of true does not mean the Runnable will be processed -- |
| 9249 | * if the looper is quit before the delivery time of the message |
| 9250 | * occurs then the message will be dropped. |
| 9251 | */ |
| 9252 | public boolean postDelayed(Runnable action, long delayMillis) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9253 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 9254 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9255 | return attachInfo.mHandler.postDelayed(action, delayMillis); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9256 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9257 | // Assume that post will succeed later |
| 9258 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
| 9259 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9260 | } |
| 9261 | |
| 9262 | /** |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 9263 | * <p>Causes the Runnable to execute on the next animation time step. |
| 9264 | * The runnable will be run on the user interface thread.</p> |
| 9265 | * |
| 9266 | * <p>This method can be invoked from outside of the UI thread |
| 9267 | * only when this View is attached to a window.</p> |
| 9268 | * |
| 9269 | * @param action The Runnable that will be executed. |
| 9270 | * |
| 9271 | * @hide |
| 9272 | */ |
| 9273 | public void postOnAnimation(Runnable action) { |
| 9274 | final AttachInfo attachInfo = mAttachInfo; |
| 9275 | if (attachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 9276 | attachInfo.mViewRootImpl.mChoreographer.postCallback( |
| 9277 | Choreographer.CALLBACK_ANIMATION, action, null); |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 9278 | } else { |
| 9279 | // Assume that post will succeed later |
| 9280 | ViewRootImpl.getRunQueue().post(action); |
| 9281 | } |
| 9282 | } |
| 9283 | |
| 9284 | /** |
| 9285 | * <p>Causes the Runnable to execute on the next animation time step, |
| 9286 | * after the specified amount of time elapses. |
| 9287 | * The runnable will be run on the user interface thread.</p> |
| 9288 | * |
| 9289 | * <p>This method can be invoked from outside of the UI thread |
| 9290 | * only when this View is attached to a window.</p> |
| 9291 | * |
| 9292 | * @param action The Runnable that will be executed. |
| 9293 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 9294 | * will be executed. |
| 9295 | * |
| 9296 | * @hide |
| 9297 | */ |
| 9298 | public void postOnAnimationDelayed(Runnable action, long delayMillis) { |
| 9299 | final AttachInfo attachInfo = mAttachInfo; |
| 9300 | if (attachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 9301 | attachInfo.mViewRootImpl.mChoreographer.postCallbackDelayed( |
| 9302 | Choreographer.CALLBACK_ANIMATION, action, null, delayMillis); |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 9303 | } else { |
| 9304 | // Assume that post will succeed later |
| 9305 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
| 9306 | } |
| 9307 | } |
| 9308 | |
| 9309 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9310 | * <p>Removes the specified Runnable from the message queue.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9311 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9312 | * <p>This method can be invoked from outside of the UI thread |
| 9313 | * 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] | 9314 | * |
| 9315 | * @param action The Runnable to remove from the message handling queue |
| 9316 | * |
| 9317 | * @return true if this view could ask the Handler to remove the Runnable, |
| 9318 | * false otherwise. When the returned value is true, the Runnable |
| 9319 | * may or may not have been actually removed from the message queue |
| 9320 | * (for instance, if the Runnable was not in the queue already.) |
| 9321 | */ |
| 9322 | public boolean removeCallbacks(Runnable action) { |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 9323 | if (action != null) { |
| 9324 | final AttachInfo attachInfo = mAttachInfo; |
| 9325 | if (attachInfo != null) { |
| 9326 | attachInfo.mHandler.removeCallbacks(action); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 9327 | attachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 9328 | Choreographer.CALLBACK_ANIMATION, action, null); |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 9329 | } else { |
| 9330 | // Assume that post will succeed later |
| 9331 | ViewRootImpl.getRunQueue().removeCallbacks(action); |
| 9332 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9333 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9334 | return true; |
| 9335 | } |
| 9336 | |
| 9337 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9338 | * <p>Cause an invalidate to happen on a subsequent cycle through the event loop. |
| 9339 | * 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] | 9340 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9341 | * <p>This method can be invoked from outside of the UI thread |
| 9342 | * only when this View is attached to a window.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9343 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9344 | * @see #invalidate() |
| 9345 | */ |
| 9346 | public void postInvalidate() { |
| 9347 | postInvalidateDelayed(0); |
| 9348 | } |
| 9349 | |
| 9350 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9351 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 9352 | * through the event loop. Use this to invalidate the View from a non-UI thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9353 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9354 | * <p>This method can be invoked from outside of the UI thread |
| 9355 | * 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] | 9356 | * |
| 9357 | * @param left The left coordinate of the rectangle to invalidate. |
| 9358 | * @param top The top coordinate of the rectangle to invalidate. |
| 9359 | * @param right The right coordinate of the rectangle to invalidate. |
| 9360 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 9361 | * |
| 9362 | * @see #invalidate(int, int, int, int) |
| 9363 | * @see #invalidate(Rect) |
| 9364 | */ |
| 9365 | public void postInvalidate(int left, int top, int right, int bottom) { |
| 9366 | postInvalidateDelayed(0, left, top, right, bottom); |
| 9367 | } |
| 9368 | |
| 9369 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9370 | * <p>Cause an invalidate to happen on a subsequent cycle through the event |
| 9371 | * loop. Waits for the specified amount of time.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9372 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9373 | * <p>This method can be invoked from outside of the UI thread |
| 9374 | * 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] | 9375 | * |
| 9376 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 9377 | * invalidation by |
| 9378 | */ |
| 9379 | public void postInvalidateDelayed(long delayMilliseconds) { |
| 9380 | // We try only with the AttachInfo because there's no point in invalidating |
| 9381 | // if we are not attached to our window |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9382 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 9383 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9384 | attachInfo.mViewRootImpl.dispatchInvalidateDelayed(this, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9385 | } |
| 9386 | } |
| 9387 | |
| 9388 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9389 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 9390 | * through the event loop. Waits for the specified amount of time.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9391 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9392 | * <p>This method can be invoked from outside of the UI thread |
| 9393 | * 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] | 9394 | * |
| 9395 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 9396 | * invalidation by |
| 9397 | * @param left The left coordinate of the rectangle to invalidate. |
| 9398 | * @param top The top coordinate of the rectangle to invalidate. |
| 9399 | * @param right The right coordinate of the rectangle to invalidate. |
| 9400 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 9401 | */ |
| 9402 | public void postInvalidateDelayed(long delayMilliseconds, int left, int top, |
| 9403 | int right, int bottom) { |
| 9404 | |
| 9405 | // We try only with the AttachInfo because there's no point in invalidating |
| 9406 | // if we are not attached to our window |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9407 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 9408 | if (attachInfo != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9409 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire(); |
| 9410 | info.target = this; |
| 9411 | info.left = left; |
| 9412 | info.top = top; |
| 9413 | info.right = right; |
| 9414 | info.bottom = bottom; |
| 9415 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9416 | attachInfo.mViewRootImpl.dispatchInvalidateRectDelayed(info, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9417 | } |
| 9418 | } |
| 9419 | |
| 9420 | /** |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 9421 | * <p>Cause an invalidate to happen on the next animation time step, typically the |
| 9422 | * next display frame.</p> |
| 9423 | * |
| 9424 | * <p>This method can be invoked from outside of the UI thread |
| 9425 | * only when this View is attached to a window.</p> |
| 9426 | * |
| 9427 | * @hide |
| 9428 | */ |
| 9429 | public void postInvalidateOnAnimation() { |
| 9430 | // We try only with the AttachInfo because there's no point in invalidating |
| 9431 | // if we are not attached to our window |
| 9432 | final AttachInfo attachInfo = mAttachInfo; |
| 9433 | if (attachInfo != null) { |
| 9434 | attachInfo.mViewRootImpl.dispatchInvalidateOnAnimation(this); |
| 9435 | } |
| 9436 | } |
| 9437 | |
| 9438 | /** |
| 9439 | * <p>Cause an invalidate of the specified area to happen on the next animation |
| 9440 | * time step, typically the next display frame.</p> |
| 9441 | * |
| 9442 | * <p>This method can be invoked from outside of the UI thread |
| 9443 | * only when this View is attached to a window.</p> |
| 9444 | * |
| 9445 | * @param left The left coordinate of the rectangle to invalidate. |
| 9446 | * @param top The top coordinate of the rectangle to invalidate. |
| 9447 | * @param right The right coordinate of the rectangle to invalidate. |
| 9448 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 9449 | * |
| 9450 | * @hide |
| 9451 | */ |
| 9452 | public void postInvalidateOnAnimation(int left, int top, int right, int bottom) { |
| 9453 | // We try only with the AttachInfo because there's no point in invalidating |
| 9454 | // if we are not attached to our window |
| 9455 | final AttachInfo attachInfo = mAttachInfo; |
| 9456 | if (attachInfo != null) { |
| 9457 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire(); |
| 9458 | info.target = this; |
| 9459 | info.left = left; |
| 9460 | info.top = top; |
| 9461 | info.right = right; |
| 9462 | info.bottom = bottom; |
| 9463 | |
| 9464 | attachInfo.mViewRootImpl.dispatchInvalidateRectOnAnimation(info); |
| 9465 | } |
| 9466 | } |
| 9467 | |
| 9468 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 9469 | * Post a callback to send a {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} event. |
| 9470 | * This event is sent at most once every |
| 9471 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
| 9472 | */ |
| 9473 | private void postSendViewScrolledAccessibilityEventCallback() { |
| 9474 | if (mSendViewScrolledAccessibilityEvent == null) { |
| 9475 | mSendViewScrolledAccessibilityEvent = new SendViewScrolledAccessibilityEvent(); |
| 9476 | } |
| 9477 | if (!mSendViewScrolledAccessibilityEvent.mIsPending) { |
| 9478 | mSendViewScrolledAccessibilityEvent.mIsPending = true; |
| 9479 | postDelayed(mSendViewScrolledAccessibilityEvent, |
| 9480 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval()); |
| 9481 | } |
| 9482 | } |
| 9483 | |
| 9484 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9485 | * Called by a parent to request that a child update its values for mScrollX |
| 9486 | * and mScrollY if necessary. This will typically be done if the child is |
| 9487 | * animating a scroll using a {@link android.widget.Scroller Scroller} |
| 9488 | * object. |
| 9489 | */ |
| 9490 | public void computeScroll() { |
| 9491 | } |
| 9492 | |
| 9493 | /** |
| 9494 | * <p>Indicate whether the horizontal edges are faded when the view is |
| 9495 | * scrolled horizontally.</p> |
| 9496 | * |
| 9497 | * @return true if the horizontal edges should are faded on scroll, false |
| 9498 | * otherwise |
| 9499 | * |
| 9500 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9501 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 9502 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9503 | */ |
| 9504 | public boolean isHorizontalFadingEdgeEnabled() { |
| 9505 | return (mViewFlags & FADING_EDGE_HORIZONTAL) == FADING_EDGE_HORIZONTAL; |
| 9506 | } |
| 9507 | |
| 9508 | /** |
| 9509 | * <p>Define whether the horizontal edges should be faded when this view |
| 9510 | * is scrolled horizontally.</p> |
| 9511 | * |
| 9512 | * @param horizontalFadingEdgeEnabled true if the horizontal edges should |
| 9513 | * be faded when the view is scrolled |
| 9514 | * horizontally |
| 9515 | * |
| 9516 | * @see #isHorizontalFadingEdgeEnabled() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9517 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 9518 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9519 | */ |
| 9520 | public void setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled) { |
| 9521 | if (isHorizontalFadingEdgeEnabled() != horizontalFadingEdgeEnabled) { |
| 9522 | if (horizontalFadingEdgeEnabled) { |
| 9523 | initScrollCache(); |
| 9524 | } |
| 9525 | |
| 9526 | mViewFlags ^= FADING_EDGE_HORIZONTAL; |
| 9527 | } |
| 9528 | } |
| 9529 | |
| 9530 | /** |
| 9531 | * <p>Indicate whether the vertical edges are faded when the view is |
| 9532 | * scrolled horizontally.</p> |
| 9533 | * |
| 9534 | * @return true if the vertical edges should are faded on scroll, false |
| 9535 | * otherwise |
| 9536 | * |
| 9537 | * @see #setVerticalFadingEdgeEnabled(boolean) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9538 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 9539 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9540 | */ |
| 9541 | public boolean isVerticalFadingEdgeEnabled() { |
| 9542 | return (mViewFlags & FADING_EDGE_VERTICAL) == FADING_EDGE_VERTICAL; |
| 9543 | } |
| 9544 | |
| 9545 | /** |
| 9546 | * <p>Define whether the vertical edges should be faded when this view |
| 9547 | * is scrolled vertically.</p> |
| 9548 | * |
| 9549 | * @param verticalFadingEdgeEnabled true if the vertical edges should |
| 9550 | * be faded when the view is scrolled |
| 9551 | * vertically |
| 9552 | * |
| 9553 | * @see #isVerticalFadingEdgeEnabled() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9554 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 9555 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9556 | */ |
| 9557 | public void setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled) { |
| 9558 | if (isVerticalFadingEdgeEnabled() != verticalFadingEdgeEnabled) { |
| 9559 | if (verticalFadingEdgeEnabled) { |
| 9560 | initScrollCache(); |
| 9561 | } |
| 9562 | |
| 9563 | mViewFlags ^= FADING_EDGE_VERTICAL; |
| 9564 | } |
| 9565 | } |
| 9566 | |
| 9567 | /** |
| 9568 | * Returns the strength, or intensity, of the top faded edge. The strength is |
| 9569 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 9570 | * returns 0.0 or 1.0 but no value in between. |
| 9571 | * |
| 9572 | * Subclasses should override this method to provide a smoother fade transition |
| 9573 | * when scrolling occurs. |
| 9574 | * |
| 9575 | * @return the intensity of the top fade as a float between 0.0f and 1.0f |
| 9576 | */ |
| 9577 | protected float getTopFadingEdgeStrength() { |
| 9578 | return computeVerticalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 9579 | } |
| 9580 | |
| 9581 | /** |
| 9582 | * Returns the strength, or intensity, of the bottom faded edge. The strength is |
| 9583 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 9584 | * returns 0.0 or 1.0 but no value in between. |
| 9585 | * |
| 9586 | * Subclasses should override this method to provide a smoother fade transition |
| 9587 | * when scrolling occurs. |
| 9588 | * |
| 9589 | * @return the intensity of the bottom fade as a float between 0.0f and 1.0f |
| 9590 | */ |
| 9591 | protected float getBottomFadingEdgeStrength() { |
| 9592 | return computeVerticalScrollOffset() + computeVerticalScrollExtent() < |
| 9593 | computeVerticalScrollRange() ? 1.0f : 0.0f; |
| 9594 | } |
| 9595 | |
| 9596 | /** |
| 9597 | * Returns the strength, or intensity, of the left faded edge. The strength is |
| 9598 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 9599 | * returns 0.0 or 1.0 but no value in between. |
| 9600 | * |
| 9601 | * Subclasses should override this method to provide a smoother fade transition |
| 9602 | * when scrolling occurs. |
| 9603 | * |
| 9604 | * @return the intensity of the left fade as a float between 0.0f and 1.0f |
| 9605 | */ |
| 9606 | protected float getLeftFadingEdgeStrength() { |
| 9607 | return computeHorizontalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 9608 | } |
| 9609 | |
| 9610 | /** |
| 9611 | * Returns the strength, or intensity, of the right faded edge. The strength is |
| 9612 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 9613 | * returns 0.0 or 1.0 but no value in between. |
| 9614 | * |
| 9615 | * Subclasses should override this method to provide a smoother fade transition |
| 9616 | * when scrolling occurs. |
| 9617 | * |
| 9618 | * @return the intensity of the right fade as a float between 0.0f and 1.0f |
| 9619 | */ |
| 9620 | protected float getRightFadingEdgeStrength() { |
| 9621 | return computeHorizontalScrollOffset() + computeHorizontalScrollExtent() < |
| 9622 | computeHorizontalScrollRange() ? 1.0f : 0.0f; |
| 9623 | } |
| 9624 | |
| 9625 | /** |
| 9626 | * <p>Indicate whether the horizontal scrollbar should be drawn or not. The |
| 9627 | * scrollbar is not drawn by default.</p> |
| 9628 | * |
| 9629 | * @return true if the horizontal scrollbar should be painted, false |
| 9630 | * otherwise |
| 9631 | * |
| 9632 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 9633 | */ |
| 9634 | public boolean isHorizontalScrollBarEnabled() { |
| 9635 | return (mViewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 9636 | } |
| 9637 | |
| 9638 | /** |
| 9639 | * <p>Define whether the horizontal scrollbar should be drawn or not. The |
| 9640 | * scrollbar is not drawn by default.</p> |
| 9641 | * |
| 9642 | * @param horizontalScrollBarEnabled true if the horizontal scrollbar should |
| 9643 | * be painted |
| 9644 | * |
| 9645 | * @see #isHorizontalScrollBarEnabled() |
| 9646 | */ |
| 9647 | public void setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled) { |
| 9648 | if (isHorizontalScrollBarEnabled() != horizontalScrollBarEnabled) { |
| 9649 | mViewFlags ^= SCROLLBARS_HORIZONTAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9650 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9651 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9652 | } |
| 9653 | } |
| 9654 | |
| 9655 | /** |
| 9656 | * <p>Indicate whether the vertical scrollbar should be drawn or not. The |
| 9657 | * scrollbar is not drawn by default.</p> |
| 9658 | * |
| 9659 | * @return true if the vertical scrollbar should be painted, false |
| 9660 | * otherwise |
| 9661 | * |
| 9662 | * @see #setVerticalScrollBarEnabled(boolean) |
| 9663 | */ |
| 9664 | public boolean isVerticalScrollBarEnabled() { |
| 9665 | return (mViewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL; |
| 9666 | } |
| 9667 | |
| 9668 | /** |
| 9669 | * <p>Define whether the vertical scrollbar should be drawn or not. The |
| 9670 | * scrollbar is not drawn by default.</p> |
| 9671 | * |
| 9672 | * @param verticalScrollBarEnabled true if the vertical scrollbar should |
| 9673 | * be painted |
| 9674 | * |
| 9675 | * @see #isVerticalScrollBarEnabled() |
| 9676 | */ |
| 9677 | public void setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled) { |
| 9678 | if (isVerticalScrollBarEnabled() != verticalScrollBarEnabled) { |
| 9679 | mViewFlags ^= SCROLLBARS_VERTICAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9680 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9681 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9682 | } |
| 9683 | } |
| 9684 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 9685 | /** |
| 9686 | * @hide |
| 9687 | */ |
| 9688 | protected void recomputePadding() { |
| 9689 | setPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, mUserPaddingBottom); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9690 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9691 | |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9692 | /** |
| 9693 | * Define whether scrollbars will fade when the view is not scrolling. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9694 | * |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9695 | * @param fadeScrollbars wheter to enable fading |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9696 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9697 | * @attr ref android.R.styleable#View_fadeScrollbars |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9698 | */ |
| 9699 | public void setScrollbarFadingEnabled(boolean fadeScrollbars) { |
| 9700 | initScrollCache(); |
| 9701 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
| 9702 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9703 | if (fadeScrollbars) { |
| 9704 | scrollabilityCache.state = ScrollabilityCache.OFF; |
| 9705 | } else { |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9706 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 9707 | } |
| 9708 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9709 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9710 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9711 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9712 | * Returns true if scrollbars will fade when this view is not scrolling |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9713 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9714 | * @return true if scrollbar fading is enabled |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9715 | * |
| 9716 | * @attr ref android.R.styleable#View_fadeScrollbars |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9717 | */ |
| 9718 | public boolean isScrollbarFadingEnabled() { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9719 | return mScrollCache != null && mScrollCache.fadeScrollBars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9720 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9721 | |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9722 | /** |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9723 | * |
| 9724 | * Returns the delay before scrollbars fade. |
| 9725 | * |
| 9726 | * @return the delay before scrollbars fade |
| 9727 | * |
| 9728 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 9729 | */ |
| 9730 | public int getScrollBarDefaultDelayBeforeFade() { |
| 9731 | return mScrollCache == null ? ViewConfiguration.getScrollDefaultDelay() : |
| 9732 | mScrollCache.scrollBarDefaultDelayBeforeFade; |
| 9733 | } |
| 9734 | |
| 9735 | /** |
| 9736 | * Define the delay before scrollbars fade. |
| 9737 | * |
| 9738 | * @param scrollBarDefaultDelayBeforeFade - the delay before scrollbars fade |
| 9739 | * |
| 9740 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 9741 | */ |
| 9742 | public void setScrollBarDefaultDelayBeforeFade(int scrollBarDefaultDelayBeforeFade) { |
| 9743 | getScrollCache().scrollBarDefaultDelayBeforeFade = scrollBarDefaultDelayBeforeFade; |
| 9744 | } |
| 9745 | |
| 9746 | /** |
| 9747 | * |
| 9748 | * Returns the scrollbar fade duration. |
| 9749 | * |
| 9750 | * @return the scrollbar fade duration |
| 9751 | * |
| 9752 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
| 9753 | */ |
| 9754 | public int getScrollBarFadeDuration() { |
| 9755 | return mScrollCache == null ? ViewConfiguration.getScrollBarFadeDuration() : |
| 9756 | mScrollCache.scrollBarFadeDuration; |
| 9757 | } |
| 9758 | |
| 9759 | /** |
| 9760 | * Define the scrollbar fade duration. |
| 9761 | * |
| 9762 | * @param scrollBarFadeDuration - the scrollbar fade duration |
| 9763 | * |
| 9764 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
| 9765 | */ |
| 9766 | public void setScrollBarFadeDuration(int scrollBarFadeDuration) { |
| 9767 | getScrollCache().scrollBarFadeDuration = scrollBarFadeDuration; |
| 9768 | } |
| 9769 | |
| 9770 | /** |
| 9771 | * |
| 9772 | * Returns the scrollbar size. |
| 9773 | * |
| 9774 | * @return the scrollbar size |
| 9775 | * |
| 9776 | * @attr ref android.R.styleable#View_scrollbarSize |
| 9777 | */ |
| 9778 | public int getScrollBarSize() { |
| 9779 | return mScrollCache == null ? ViewConfiguration.getScrollBarSize() : |
| 9780 | mScrollCache.scrollBarSize; |
| 9781 | } |
| 9782 | |
| 9783 | /** |
| 9784 | * Define the scrollbar size. |
| 9785 | * |
| 9786 | * @param scrollBarSize - the scrollbar size |
| 9787 | * |
| 9788 | * @attr ref android.R.styleable#View_scrollbarSize |
| 9789 | */ |
| 9790 | public void setScrollBarSize(int scrollBarSize) { |
| 9791 | getScrollCache().scrollBarSize = scrollBarSize; |
| 9792 | } |
| 9793 | |
| 9794 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9795 | * <p>Specify the style of the scrollbars. The scrollbars can be overlaid or |
| 9796 | * inset. When inset, they add to the padding of the view. And the scrollbars |
| 9797 | * can be drawn inside the padding area or on the edge of the view. For example, |
| 9798 | * if a view has a background drawable and you want to draw the scrollbars |
| 9799 | * inside the padding specified by the drawable, you can use |
| 9800 | * SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to |
| 9801 | * appear at the edge of the view, ignoring the padding, then you can use |
| 9802 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.</p> |
| 9803 | * @param style the style of the scrollbars. Should be one of |
| 9804 | * SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, |
| 9805 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET. |
| 9806 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 9807 | * @see #SCROLLBARS_INSIDE_INSET |
| 9808 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 9809 | * @see #SCROLLBARS_OUTSIDE_INSET |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9810 | * |
| 9811 | * @attr ref android.R.styleable#View_scrollbarStyle |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9812 | */ |
| 9813 | public void setScrollBarStyle(int style) { |
| 9814 | if (style != (mViewFlags & SCROLLBARS_STYLE_MASK)) { |
| 9815 | mViewFlags = (mViewFlags & ~SCROLLBARS_STYLE_MASK) | (style & SCROLLBARS_STYLE_MASK); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9816 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9817 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9818 | } |
| 9819 | } |
| 9820 | |
| 9821 | /** |
| 9822 | * <p>Returns the current scrollbar style.</p> |
| 9823 | * @return the current scrollbar style |
| 9824 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 9825 | * @see #SCROLLBARS_INSIDE_INSET |
| 9826 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 9827 | * @see #SCROLLBARS_OUTSIDE_INSET |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9828 | * |
| 9829 | * @attr ref android.R.styleable#View_scrollbarStyle |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9830 | */ |
Jeff Sharkey | 010d7e5 | 2011-08-08 21:05:02 -0700 | [diff] [blame] | 9831 | @ViewDebug.ExportedProperty(mapping = { |
| 9832 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_OVERLAY, to = "INSIDE_OVERLAY"), |
| 9833 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_INSET, to = "INSIDE_INSET"), |
| 9834 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_OVERLAY, to = "OUTSIDE_OVERLAY"), |
| 9835 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_INSET, to = "OUTSIDE_INSET") |
| 9836 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9837 | public int getScrollBarStyle() { |
| 9838 | return mViewFlags & SCROLLBARS_STYLE_MASK; |
| 9839 | } |
| 9840 | |
| 9841 | /** |
| 9842 | * <p>Compute the horizontal range that the horizontal scrollbar |
| 9843 | * represents.</p> |
| 9844 | * |
| 9845 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9846 | * units used by {@link #computeHorizontalScrollExtent()} and |
| 9847 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 9848 | * |
| 9849 | * <p>The default range is the drawing width of this view.</p> |
| 9850 | * |
| 9851 | * @return the total horizontal range represented by the horizontal |
| 9852 | * scrollbar |
| 9853 | * |
| 9854 | * @see #computeHorizontalScrollExtent() |
| 9855 | * @see #computeHorizontalScrollOffset() |
| 9856 | * @see android.widget.ScrollBarDrawable |
| 9857 | */ |
| 9858 | protected int computeHorizontalScrollRange() { |
| 9859 | return getWidth(); |
| 9860 | } |
| 9861 | |
| 9862 | /** |
| 9863 | * <p>Compute the horizontal offset of the horizontal scrollbar's thumb |
| 9864 | * within the horizontal range. This value is used to compute the position |
| 9865 | * of the thumb within the scrollbar's track.</p> |
| 9866 | * |
| 9867 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9868 | * units used by {@link #computeHorizontalScrollRange()} and |
| 9869 | * {@link #computeHorizontalScrollExtent()}.</p> |
| 9870 | * |
| 9871 | * <p>The default offset is the scroll offset of this view.</p> |
| 9872 | * |
| 9873 | * @return the horizontal offset of the scrollbar's thumb |
| 9874 | * |
| 9875 | * @see #computeHorizontalScrollRange() |
| 9876 | * @see #computeHorizontalScrollExtent() |
| 9877 | * @see android.widget.ScrollBarDrawable |
| 9878 | */ |
| 9879 | protected int computeHorizontalScrollOffset() { |
| 9880 | return mScrollX; |
| 9881 | } |
| 9882 | |
| 9883 | /** |
| 9884 | * <p>Compute the horizontal extent of the horizontal scrollbar's thumb |
| 9885 | * within the horizontal range. This value is used to compute the length |
| 9886 | * of the thumb within the scrollbar's track.</p> |
| 9887 | * |
| 9888 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9889 | * units used by {@link #computeHorizontalScrollRange()} and |
| 9890 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 9891 | * |
| 9892 | * <p>The default extent is the drawing width of this view.</p> |
| 9893 | * |
| 9894 | * @return the horizontal extent of the scrollbar's thumb |
| 9895 | * |
| 9896 | * @see #computeHorizontalScrollRange() |
| 9897 | * @see #computeHorizontalScrollOffset() |
| 9898 | * @see android.widget.ScrollBarDrawable |
| 9899 | */ |
| 9900 | protected int computeHorizontalScrollExtent() { |
| 9901 | return getWidth(); |
| 9902 | } |
| 9903 | |
| 9904 | /** |
| 9905 | * <p>Compute the vertical range that the vertical scrollbar represents.</p> |
| 9906 | * |
| 9907 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9908 | * units used by {@link #computeVerticalScrollExtent()} and |
| 9909 | * {@link #computeVerticalScrollOffset()}.</p> |
| 9910 | * |
| 9911 | * @return the total vertical range represented by the vertical scrollbar |
| 9912 | * |
| 9913 | * <p>The default range is the drawing height of this view.</p> |
| 9914 | * |
| 9915 | * @see #computeVerticalScrollExtent() |
| 9916 | * @see #computeVerticalScrollOffset() |
| 9917 | * @see android.widget.ScrollBarDrawable |
| 9918 | */ |
| 9919 | protected int computeVerticalScrollRange() { |
| 9920 | return getHeight(); |
| 9921 | } |
| 9922 | |
| 9923 | /** |
| 9924 | * <p>Compute the vertical offset of the vertical scrollbar's thumb |
| 9925 | * within the horizontal range. This value is used to compute the position |
| 9926 | * of the thumb within the scrollbar's track.</p> |
| 9927 | * |
| 9928 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9929 | * units used by {@link #computeVerticalScrollRange()} and |
| 9930 | * {@link #computeVerticalScrollExtent()}.</p> |
| 9931 | * |
| 9932 | * <p>The default offset is the scroll offset of this view.</p> |
| 9933 | * |
| 9934 | * @return the vertical offset of the scrollbar's thumb |
| 9935 | * |
| 9936 | * @see #computeVerticalScrollRange() |
| 9937 | * @see #computeVerticalScrollExtent() |
| 9938 | * @see android.widget.ScrollBarDrawable |
| 9939 | */ |
| 9940 | protected int computeVerticalScrollOffset() { |
| 9941 | return mScrollY; |
| 9942 | } |
| 9943 | |
| 9944 | /** |
| 9945 | * <p>Compute the vertical extent of the horizontal scrollbar's thumb |
| 9946 | * within the vertical range. This value is used to compute the length |
| 9947 | * of the thumb within the scrollbar's track.</p> |
| 9948 | * |
| 9949 | * <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] | 9950 | * units used by {@link #computeVerticalScrollRange()} and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9951 | * {@link #computeVerticalScrollOffset()}.</p> |
| 9952 | * |
| 9953 | * <p>The default extent is the drawing height of this view.</p> |
| 9954 | * |
| 9955 | * @return the vertical extent of the scrollbar's thumb |
| 9956 | * |
| 9957 | * @see #computeVerticalScrollRange() |
| 9958 | * @see #computeVerticalScrollOffset() |
| 9959 | * @see android.widget.ScrollBarDrawable |
| 9960 | */ |
| 9961 | protected int computeVerticalScrollExtent() { |
| 9962 | return getHeight(); |
| 9963 | } |
| 9964 | |
| 9965 | /** |
Adam Powell | 6915944 | 2011-06-13 17:53:06 -0700 | [diff] [blame] | 9966 | * Check if this view can be scrolled horizontally in a certain direction. |
| 9967 | * |
| 9968 | * @param direction Negative to check scrolling left, positive to check scrolling right. |
| 9969 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 9970 | */ |
| 9971 | public boolean canScrollHorizontally(int direction) { |
| 9972 | final int offset = computeHorizontalScrollOffset(); |
| 9973 | final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent(); |
| 9974 | if (range == 0) return false; |
| 9975 | if (direction < 0) { |
| 9976 | return offset > 0; |
| 9977 | } else { |
| 9978 | return offset < range - 1; |
| 9979 | } |
| 9980 | } |
| 9981 | |
| 9982 | /** |
| 9983 | * Check if this view can be scrolled vertically in a certain direction. |
| 9984 | * |
| 9985 | * @param direction Negative to check scrolling up, positive to check scrolling down. |
| 9986 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 9987 | */ |
| 9988 | public boolean canScrollVertically(int direction) { |
| 9989 | final int offset = computeVerticalScrollOffset(); |
| 9990 | final int range = computeVerticalScrollRange() - computeVerticalScrollExtent(); |
| 9991 | if (range == 0) return false; |
| 9992 | if (direction < 0) { |
| 9993 | return offset > 0; |
| 9994 | } else { |
| 9995 | return offset < range - 1; |
| 9996 | } |
| 9997 | } |
| 9998 | |
| 9999 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10000 | * <p>Request the drawing of the horizontal and the vertical scrollbar. The |
| 10001 | * scrollbars are painted only if they have been awakened first.</p> |
| 10002 | * |
| 10003 | * @param canvas the canvas on which to draw the scrollbars |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10004 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10005 | * @see #awakenScrollBars(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10006 | */ |
Romain Guy | 1d5b3a6 | 2009-11-05 18:44:12 -0800 | [diff] [blame] | 10007 | protected final void onDrawScrollBars(Canvas canvas) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10008 | // scrollbars are drawn only when the animation is running |
| 10009 | final ScrollabilityCache cache = mScrollCache; |
| 10010 | if (cache != null) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10011 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10012 | int state = cache.state; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10013 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10014 | if (state == ScrollabilityCache.OFF) { |
| 10015 | return; |
| 10016 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10017 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10018 | boolean invalidate = false; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10019 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10020 | if (state == ScrollabilityCache.FADING) { |
| 10021 | // We're fading -- get our fade interpolation |
| 10022 | if (cache.interpolatorValues == null) { |
| 10023 | cache.interpolatorValues = new float[1]; |
| 10024 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10025 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10026 | float[] values = cache.interpolatorValues; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10027 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10028 | // Stops the animation if we're done |
| 10029 | if (cache.scrollBarInterpolator.timeToValues(values) == |
| 10030 | Interpolator.Result.FREEZE_END) { |
| 10031 | cache.state = ScrollabilityCache.OFF; |
| 10032 | } else { |
| 10033 | cache.scrollBar.setAlpha(Math.round(values[0])); |
| 10034 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10035 | |
| 10036 | // This will make the scroll bars inval themselves after |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10037 | // drawing. We only want this when we're fading so that |
| 10038 | // we prevent excessive redraws |
| 10039 | invalidate = true; |
| 10040 | } else { |
| 10041 | // We're just on -- but we may have been fading before so |
| 10042 | // reset alpha |
| 10043 | cache.scrollBar.setAlpha(255); |
| 10044 | } |
| 10045 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10046 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10047 | final int viewFlags = mViewFlags; |
| 10048 | |
| 10049 | final boolean drawHorizontalScrollBar = |
| 10050 | (viewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 10051 | final boolean drawVerticalScrollBar = |
| 10052 | (viewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL |
| 10053 | && !isVerticalScrollBarHidden(); |
| 10054 | |
| 10055 | if (drawVerticalScrollBar || drawHorizontalScrollBar) { |
| 10056 | final int width = mRight - mLeft; |
| 10057 | final int height = mBottom - mTop; |
| 10058 | |
| 10059 | final ScrollBarDrawable scrollBar = cache.scrollBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10060 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10061 | final int scrollX = mScrollX; |
| 10062 | final int scrollY = mScrollY; |
| 10063 | final int inside = (viewFlags & SCROLLBARS_OUTSIDE_MASK) == 0 ? ~0 : 0; |
| 10064 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10065 | int left, top, right, bottom; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10066 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10067 | if (drawHorizontalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 10068 | int size = scrollBar.getSize(false); |
| 10069 | if (size <= 0) { |
| 10070 | size = cache.scrollBarSize; |
| 10071 | } |
| 10072 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10073 | scrollBar.setParameters(computeHorizontalScrollRange(), |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10074 | computeHorizontalScrollOffset(), |
| 10075 | computeHorizontalScrollExtent(), false); |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10076 | final int verticalScrollBarGap = drawVerticalScrollBar ? |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10077 | getVerticalScrollbarWidth() : 0; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10078 | top = scrollY + height - size - (mUserPaddingBottom & inside); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10079 | left = scrollX + (mPaddingLeft & inside); |
| 10080 | right = scrollX + width - (mUserPaddingRight & inside) - verticalScrollBarGap; |
| 10081 | bottom = top + size; |
| 10082 | onDrawHorizontalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 10083 | if (invalidate) { |
| 10084 | invalidate(left, top, right, bottom); |
| 10085 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10086 | } |
| 10087 | |
| 10088 | if (drawVerticalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 10089 | int size = scrollBar.getSize(true); |
| 10090 | if (size <= 0) { |
| 10091 | size = cache.scrollBarSize; |
| 10092 | } |
| 10093 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10094 | scrollBar.setParameters(computeVerticalScrollRange(), |
| 10095 | computeVerticalScrollOffset(), |
| 10096 | computeVerticalScrollExtent(), true); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 10097 | switch (mVerticalScrollbarPosition) { |
| 10098 | default: |
| 10099 | case SCROLLBAR_POSITION_DEFAULT: |
| 10100 | case SCROLLBAR_POSITION_RIGHT: |
| 10101 | left = scrollX + width - size - (mUserPaddingRight & inside); |
| 10102 | break; |
| 10103 | case SCROLLBAR_POSITION_LEFT: |
| 10104 | left = scrollX + (mUserPaddingLeft & inside); |
| 10105 | break; |
| 10106 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10107 | top = scrollY + (mPaddingTop & inside); |
| 10108 | right = left + size; |
| 10109 | bottom = scrollY + height - (mUserPaddingBottom & inside); |
| 10110 | onDrawVerticalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 10111 | if (invalidate) { |
| 10112 | invalidate(left, top, right, bottom); |
| 10113 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10114 | } |
| 10115 | } |
| 10116 | } |
| 10117 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10119 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10120 | * 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] | 10121 | * FastScroller is visible. |
| 10122 | * @return whether to temporarily hide the vertical scrollbar |
| 10123 | * @hide |
| 10124 | */ |
| 10125 | protected boolean isVerticalScrollBarHidden() { |
| 10126 | return false; |
| 10127 | } |
| 10128 | |
| 10129 | /** |
| 10130 | * <p>Draw the horizontal scrollbar if |
| 10131 | * {@link #isHorizontalScrollBarEnabled()} returns true.</p> |
| 10132 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10133 | * @param canvas the canvas on which to draw the scrollbar |
| 10134 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10135 | * |
| 10136 | * @see #isHorizontalScrollBarEnabled() |
| 10137 | * @see #computeHorizontalScrollRange() |
| 10138 | * @see #computeHorizontalScrollExtent() |
| 10139 | * @see #computeHorizontalScrollOffset() |
| 10140 | * @see android.widget.ScrollBarDrawable |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10141 | * @hide |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 10142 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 10143 | protected void onDrawHorizontalScrollBar(Canvas canvas, Drawable scrollBar, |
| 10144 | int l, int t, int r, int b) { |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 10145 | scrollBar.setBounds(l, t, r, b); |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 10146 | scrollBar.draw(canvas); |
| 10147 | } |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10148 | |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 10149 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10150 | * <p>Draw the vertical scrollbar if {@link #isVerticalScrollBarEnabled()} |
| 10151 | * returns true.</p> |
| 10152 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10153 | * @param canvas the canvas on which to draw the scrollbar |
| 10154 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10155 | * |
| 10156 | * @see #isVerticalScrollBarEnabled() |
| 10157 | * @see #computeVerticalScrollRange() |
| 10158 | * @see #computeVerticalScrollExtent() |
| 10159 | * @see #computeVerticalScrollOffset() |
| 10160 | * @see android.widget.ScrollBarDrawable |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10161 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10162 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 10163 | protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, |
| 10164 | int l, int t, int r, int b) { |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10165 | scrollBar.setBounds(l, t, r, b); |
| 10166 | scrollBar.draw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10167 | } |
| 10168 | |
| 10169 | /** |
| 10170 | * Implement this to do your drawing. |
| 10171 | * |
| 10172 | * @param canvas the canvas on which the background will be drawn |
| 10173 | */ |
| 10174 | protected void onDraw(Canvas canvas) { |
| 10175 | } |
| 10176 | |
| 10177 | /* |
| 10178 | * Caller is responsible for calling requestLayout if necessary. |
| 10179 | * (This allows addViewInLayout to not request a new layout.) |
| 10180 | */ |
| 10181 | void assignParent(ViewParent parent) { |
| 10182 | if (mParent == null) { |
| 10183 | mParent = parent; |
| 10184 | } else if (parent == null) { |
| 10185 | mParent = null; |
| 10186 | } else { |
| 10187 | throw new RuntimeException("view " + this + " being added, but" |
| 10188 | + " it already has a parent"); |
| 10189 | } |
| 10190 | } |
| 10191 | |
| 10192 | /** |
| 10193 | * This is called when the view is attached to a window. At this point it |
| 10194 | * has a Surface and will start drawing. Note that this function is |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10195 | * guaranteed to be called before {@link #onDraw(android.graphics.Canvas)}, |
| 10196 | * however it may be called any time before the first onDraw -- including |
| 10197 | * before or after {@link #onMeasure(int, int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10198 | * |
| 10199 | * @see #onDetachedFromWindow() |
| 10200 | */ |
| 10201 | protected void onAttachedToWindow() { |
| 10202 | if ((mPrivateFlags & REQUEST_TRANSPARENT_REGIONS) != 0) { |
| 10203 | mParent.requestTransparentRegion(this); |
| 10204 | } |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 10205 | if ((mPrivateFlags & AWAKEN_SCROLL_BARS_ON_ATTACH) != 0) { |
| 10206 | initialAwakenScrollBars(); |
| 10207 | mPrivateFlags &= ~AWAKEN_SCROLL_BARS_ON_ATTACH; |
| 10208 | } |
Chet Haase | a9b61ac | 2010-12-20 07:40:25 -0800 | [diff] [blame] | 10209 | jumpDrawablesToCurrentState(); |
Fabrice Di Meglio | a646145 | 2011-08-19 15:42:04 -0700 | [diff] [blame] | 10210 | // Order is important here: LayoutDirection MUST be resolved before Padding |
| 10211 | // and TextDirection |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10212 | resolveLayoutDirection(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10213 | resolvePadding(); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 10214 | resolveTextDirection(); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 10215 | resolveTextAlignment(); |
Amith Yamasani | 4503c8d | 2011-06-17 12:36:14 -0700 | [diff] [blame] | 10216 | if (isFocused()) { |
| 10217 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 10218 | imm.focusIn(this); |
| 10219 | } |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 10220 | } |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 10221 | |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 10222 | /** |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 10223 | * @see #onScreenStateChanged(int) |
| 10224 | */ |
| 10225 | void dispatchScreenStateChanged(int screenState) { |
| 10226 | onScreenStateChanged(screenState); |
| 10227 | } |
| 10228 | |
| 10229 | /** |
| 10230 | * This method is called whenever the state of the screen this view is |
| 10231 | * attached to changes. A state change will usually occurs when the screen |
| 10232 | * turns on or off (whether it happens automatically or the user does it |
| 10233 | * manually.) |
| 10234 | * |
| 10235 | * @param screenState The new state of the screen. Can be either |
| 10236 | * {@link #SCREEN_STATE_ON} or {@link #SCREEN_STATE_OFF} |
| 10237 | */ |
| 10238 | public void onScreenStateChanged(int screenState) { |
| 10239 | } |
| 10240 | |
| 10241 | /** |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 10242 | * Return true if the application tag in the AndroidManifest has set "supportRtl" to true |
| 10243 | */ |
| 10244 | private boolean hasRtlSupport() { |
| 10245 | return mContext.getApplicationInfo().hasRtlSupport(); |
| 10246 | } |
| 10247 | |
| 10248 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10249 | * Resolve and cache the layout direction. LTR is set initially. This is implicitly supposing |
| 10250 | * 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] | 10251 | * Will call {@link View#onResolvedLayoutDirectionChanged} when resolution is done. |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 10252 | */ |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10253 | public void resolveLayoutDirection() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10254 | // Clear any previous layout direction resolution |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 10255 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_MASK; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10256 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 10257 | if (hasRtlSupport()) { |
| 10258 | // Set resolved depending on layout direction |
| 10259 | switch (getLayoutDirection()) { |
| 10260 | case LAYOUT_DIRECTION_INHERIT: |
| 10261 | // If this is root view, no need to look at parent's layout dir. |
| 10262 | if (canResolveLayoutDirection()) { |
| 10263 | ViewGroup viewGroup = ((ViewGroup) mParent); |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 10264 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 10265 | if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
| 10266 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
| 10267 | } |
| 10268 | } else { |
| 10269 | // Nothing to do, LTR by default |
| 10270 | } |
| 10271 | break; |
| 10272 | case LAYOUT_DIRECTION_RTL: |
| 10273 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
| 10274 | break; |
| 10275 | case LAYOUT_DIRECTION_LOCALE: |
| 10276 | if(isLayoutDirectionRtl(Locale.getDefault())) { |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 10277 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
| 10278 | } |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 10279 | break; |
| 10280 | default: |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10281 | // Nothing to do, LTR by default |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 10282 | } |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 10283 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10284 | |
| 10285 | // Set to resolved |
| 10286 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10287 | onResolvedLayoutDirectionChanged(); |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 10288 | // Resolve padding |
| 10289 | resolvePadding(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10290 | } |
| 10291 | |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 10292 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10293 | * Called when layout direction has been resolved. |
| 10294 | * |
| 10295 | * The default implementation does nothing. |
| 10296 | */ |
| 10297 | public void onResolvedLayoutDirectionChanged() { |
| 10298 | } |
| 10299 | |
| 10300 | /** |
| 10301 | * Resolve padding depending on layout direction. |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 10302 | */ |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 10303 | public void resolvePadding() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10304 | // If the user specified the absolute padding (either with android:padding or |
| 10305 | // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise |
| 10306 | // use the default padding or the padding from the background drawable |
| 10307 | // (stored at this point in mPadding*) |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 10308 | int resolvedLayoutDirection = getResolvedLayoutDirection(); |
| 10309 | switch (resolvedLayoutDirection) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10310 | case LAYOUT_DIRECTION_RTL: |
| 10311 | // Start user padding override Right user padding. Otherwise, if Right user |
| 10312 | // padding is not defined, use the default Right padding. If Right user padding |
| 10313 | // is defined, just use it. |
| 10314 | if (mUserPaddingStart >= 0) { |
| 10315 | mUserPaddingRight = mUserPaddingStart; |
| 10316 | } else if (mUserPaddingRight < 0) { |
| 10317 | mUserPaddingRight = mPaddingRight; |
| 10318 | } |
| 10319 | if (mUserPaddingEnd >= 0) { |
| 10320 | mUserPaddingLeft = mUserPaddingEnd; |
| 10321 | } else if (mUserPaddingLeft < 0) { |
| 10322 | mUserPaddingLeft = mPaddingLeft; |
| 10323 | } |
| 10324 | break; |
| 10325 | case LAYOUT_DIRECTION_LTR: |
| 10326 | default: |
| 10327 | // Start user padding override Left user padding. Otherwise, if Left user |
| 10328 | // padding is not defined, use the default left padding. If Left user padding |
| 10329 | // is defined, just use it. |
Fabrice Di Meglio | f3e1a93 | 2011-07-15 17:15:39 -0700 | [diff] [blame] | 10330 | if (mUserPaddingStart >= 0) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10331 | mUserPaddingLeft = mUserPaddingStart; |
| 10332 | } else if (mUserPaddingLeft < 0) { |
| 10333 | mUserPaddingLeft = mPaddingLeft; |
| 10334 | } |
Fabrice Di Meglio | f3e1a93 | 2011-07-15 17:15:39 -0700 | [diff] [blame] | 10335 | if (mUserPaddingEnd >= 0) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10336 | mUserPaddingRight = mUserPaddingEnd; |
| 10337 | } else if (mUserPaddingRight < 0) { |
| 10338 | mUserPaddingRight = mPaddingRight; |
| 10339 | } |
| 10340 | } |
| 10341 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10342 | mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom; |
| 10343 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 10344 | if(isPaddingRelative()) { |
| 10345 | setPaddingRelative(mUserPaddingStart, mPaddingTop, mUserPaddingEnd, mUserPaddingBottom); |
| 10346 | } else { |
| 10347 | recomputePadding(); |
| 10348 | } |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10349 | onPaddingChanged(resolvedLayoutDirection); |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 10350 | } |
| 10351 | |
| 10352 | /** |
| 10353 | * Resolve padding depending on the layout direction. Subclasses that care about |
| 10354 | * padding resolution should override this method. The default implementation does |
| 10355 | * nothing. |
| 10356 | * |
| 10357 | * @param layoutDirection the direction of the layout |
| 10358 | * |
Fabrice Di Meglio | e8dc07d | 2012-03-09 17:10:19 -0800 | [diff] [blame] | 10359 | * @see {@link #LAYOUT_DIRECTION_LTR} |
| 10360 | * @see {@link #LAYOUT_DIRECTION_RTL} |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 10361 | */ |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10362 | public void onPaddingChanged(int layoutDirection) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10363 | } |
| 10364 | |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 10365 | /** |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10366 | * Check if layout direction resolution can be done. |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 10367 | * |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10368 | * @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] | 10369 | */ |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10370 | public boolean canResolveLayoutDirection() { |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 10371 | switch (getLayoutDirection()) { |
| 10372 | case LAYOUT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10373 | return (mParent != null) && (mParent instanceof ViewGroup); |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 10374 | default: |
| 10375 | return true; |
| 10376 | } |
| 10377 | } |
| 10378 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10379 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10380 | * Reset the resolved layout direction. Will call {@link View#onResolvedLayoutDirectionReset} |
| 10381 | * when reset is done. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10382 | */ |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10383 | public void resetResolvedLayoutDirection() { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 10384 | // Reset the current resolved bits |
| 10385 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_MASK; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10386 | onResolvedLayoutDirectionReset(); |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 10387 | // Reset also the text direction |
| 10388 | resetResolvedTextDirection(); |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 10389 | } |
| 10390 | |
| 10391 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10392 | * Called during reset of resolved layout direction. |
| 10393 | * |
| 10394 | * Subclasses need to override this method to clear cached information that depends on the |
| 10395 | * resolved layout direction, or to inform child views that inherit their layout direction. |
| 10396 | * |
| 10397 | * The default implementation does nothing. |
| 10398 | */ |
| 10399 | public void onResolvedLayoutDirectionReset() { |
| 10400 | } |
| 10401 | |
| 10402 | /** |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10403 | * Check if a Locale uses an RTL script. |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 10404 | * |
| 10405 | * @param locale Locale to check |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10406 | * @return true if the Locale uses an RTL script. |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 10407 | */ |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 10408 | protected static boolean isLayoutDirectionRtl(Locale locale) { |
Fabrice Di Meglio | 3fb824b | 2012-02-28 17:58:31 -0800 | [diff] [blame] | 10409 | return (LAYOUT_DIRECTION_RTL == LocaleUtil.getLayoutDirectionFromLocale(locale)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10410 | } |
| 10411 | |
| 10412 | /** |
| 10413 | * This is called when the view is detached from a window. At this point it |
| 10414 | * no longer has a surface for drawing. |
| 10415 | * |
| 10416 | * @see #onAttachedToWindow() |
| 10417 | */ |
| 10418 | protected void onDetachedFromWindow() { |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 10419 | mPrivateFlags &= ~CANCEL_NEXT_UP_EVENT; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10420 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 10421 | removeUnsetPressCallback(); |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 10422 | removeLongPressCallback(); |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 10423 | removePerformClickCallback(); |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 10424 | removeSendViewScrolledAccessibilityEventCallback(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10425 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10426 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10427 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 10428 | destroyLayer(false); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 10429 | |
| 10430 | if (mAttachInfo != null) { |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 10431 | if (mDisplayList != null) { |
| 10432 | mAttachInfo.mViewRootImpl.invalidateDisplayList(mDisplayList); |
| 10433 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10434 | mAttachInfo.mViewRootImpl.cancelInvalidate(this); |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 10435 | } else { |
| 10436 | if (mDisplayList != null) { |
| 10437 | // Should never happen |
| 10438 | mDisplayList.invalidate(); |
| 10439 | } |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 10440 | } |
| 10441 | |
Patrick Dubroy | ec84c3a | 2011-01-13 17:55:37 -0800 | [diff] [blame] | 10442 | mCurrentAnimation = null; |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 10443 | |
| 10444 | resetResolvedLayoutDirection(); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 10445 | resetResolvedTextAlignment(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10446 | } |
| 10447 | |
| 10448 | /** |
| 10449 | * @return The number of times this view has been attached to a window |
| 10450 | */ |
| 10451 | protected int getWindowAttachCount() { |
| 10452 | return mWindowAttachCount; |
| 10453 | } |
| 10454 | |
| 10455 | /** |
| 10456 | * Retrieve a unique token identifying the window this view is attached to. |
| 10457 | * @return Return the window's token for use in |
| 10458 | * {@link WindowManager.LayoutParams#token WindowManager.LayoutParams.token}. |
| 10459 | */ |
| 10460 | public IBinder getWindowToken() { |
| 10461 | return mAttachInfo != null ? mAttachInfo.mWindowToken : null; |
| 10462 | } |
| 10463 | |
| 10464 | /** |
| 10465 | * Retrieve a unique token identifying the top-level "real" window of |
| 10466 | * the window that this view is attached to. That is, this is like |
| 10467 | * {@link #getWindowToken}, except if the window this view in is a panel |
| 10468 | * window (attached to another containing window), then the token of |
| 10469 | * the containing window is returned instead. |
| 10470 | * |
| 10471 | * @return Returns the associated window token, either |
| 10472 | * {@link #getWindowToken()} or the containing window's token. |
| 10473 | */ |
| 10474 | public IBinder getApplicationWindowToken() { |
| 10475 | AttachInfo ai = mAttachInfo; |
| 10476 | if (ai != null) { |
| 10477 | IBinder appWindowToken = ai.mPanelParentWindowToken; |
| 10478 | if (appWindowToken == null) { |
| 10479 | appWindowToken = ai.mWindowToken; |
| 10480 | } |
| 10481 | return appWindowToken; |
| 10482 | } |
| 10483 | return null; |
| 10484 | } |
| 10485 | |
| 10486 | /** |
| 10487 | * Retrieve private session object this view hierarchy is using to |
| 10488 | * communicate with the window manager. |
| 10489 | * @return the session object to communicate with the window manager |
| 10490 | */ |
| 10491 | /*package*/ IWindowSession getWindowSession() { |
| 10492 | return mAttachInfo != null ? mAttachInfo.mSession : null; |
| 10493 | } |
| 10494 | |
| 10495 | /** |
| 10496 | * @param info the {@link android.view.View.AttachInfo} to associated with |
| 10497 | * this view |
| 10498 | */ |
| 10499 | void dispatchAttachedToWindow(AttachInfo info, int visibility) { |
| 10500 | //System.out.println("Attached! " + this); |
| 10501 | mAttachInfo = info; |
| 10502 | mWindowAttachCount++; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 10503 | // We will need to evaluate the drawable state at least once. |
| 10504 | mPrivateFlags |= DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10505 | if (mFloatingTreeObserver != null) { |
| 10506 | info.mTreeObserver.merge(mFloatingTreeObserver); |
| 10507 | mFloatingTreeObserver = null; |
| 10508 | } |
| 10509 | if ((mPrivateFlags&SCROLL_CONTAINER) != 0) { |
| 10510 | mAttachInfo.mScrollContainers.add(this); |
| 10511 | mPrivateFlags |= SCROLL_CONTAINER_ADDED; |
| 10512 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 10513 | performCollectViewAttributes(mAttachInfo, visibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10514 | onAttachedToWindow(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 10515 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 10516 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 10517 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 10518 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 10519 | if (listeners != null && listeners.size() > 0) { |
| 10520 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 10521 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 10522 | // could mutate the list by calling the various add/remove methods. This prevents |
| 10523 | // the array from being modified while we iterate it. |
| 10524 | for (OnAttachStateChangeListener listener : listeners) { |
| 10525 | listener.onViewAttachedToWindow(this); |
| 10526 | } |
| 10527 | } |
| 10528 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10529 | int vis = info.mWindowVisibility; |
| 10530 | if (vis != GONE) { |
| 10531 | onWindowVisibilityChanged(vis); |
| 10532 | } |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 10533 | if ((mPrivateFlags&DRAWABLE_STATE_DIRTY) != 0) { |
| 10534 | // If nobody has evaluated the drawable state yet, then do it now. |
| 10535 | refreshDrawableState(); |
| 10536 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10537 | } |
| 10538 | |
| 10539 | void dispatchDetachedFromWindow() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10540 | AttachInfo info = mAttachInfo; |
| 10541 | if (info != null) { |
| 10542 | int vis = info.mWindowVisibility; |
| 10543 | if (vis != GONE) { |
| 10544 | onWindowVisibilityChanged(GONE); |
| 10545 | } |
| 10546 | } |
| 10547 | |
| 10548 | onDetachedFromWindow(); |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 10549 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 10550 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 10551 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 10552 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 10553 | if (listeners != null && listeners.size() > 0) { |
| 10554 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 10555 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 10556 | // could mutate the list by calling the various add/remove methods. This prevents |
| 10557 | // the array from being modified while we iterate it. |
| 10558 | for (OnAttachStateChangeListener listener : listeners) { |
| 10559 | listener.onViewDetachedFromWindow(this); |
| 10560 | } |
| 10561 | } |
| 10562 | |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 10563 | if ((mPrivateFlags & SCROLL_CONTAINER_ADDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10564 | mAttachInfo.mScrollContainers.remove(this); |
| 10565 | mPrivateFlags &= ~SCROLL_CONTAINER_ADDED; |
| 10566 | } |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 10567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10568 | mAttachInfo = null; |
| 10569 | } |
| 10570 | |
| 10571 | /** |
| 10572 | * Store this view hierarchy's frozen state into the given container. |
| 10573 | * |
| 10574 | * @param container The SparseArray in which to save the view's state. |
| 10575 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10576 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 10577 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 10578 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10579 | */ |
| 10580 | public void saveHierarchyState(SparseArray<Parcelable> container) { |
| 10581 | dispatchSaveInstanceState(container); |
| 10582 | } |
| 10583 | |
| 10584 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10585 | * Called by {@link #saveHierarchyState(android.util.SparseArray)} to store the state for |
| 10586 | * this view and its children. May be overridden to modify how freezing happens to a |
| 10587 | * 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] | 10588 | * |
| 10589 | * @param container The SparseArray in which to save the view's state. |
| 10590 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10591 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 10592 | * @see #saveHierarchyState(android.util.SparseArray) |
| 10593 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10594 | */ |
| 10595 | protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { |
| 10596 | if (mID != NO_ID && (mViewFlags & SAVE_DISABLED_MASK) == 0) { |
| 10597 | mPrivateFlags &= ~SAVE_STATE_CALLED; |
| 10598 | Parcelable state = onSaveInstanceState(); |
| 10599 | if ((mPrivateFlags & SAVE_STATE_CALLED) == 0) { |
| 10600 | throw new IllegalStateException( |
| 10601 | "Derived class did not call super.onSaveInstanceState()"); |
| 10602 | } |
| 10603 | if (state != null) { |
| 10604 | // Log.i("View", "Freezing #" + Integer.toHexString(mID) |
| 10605 | // + ": " + state); |
| 10606 | container.put(mID, state); |
| 10607 | } |
| 10608 | } |
| 10609 | } |
| 10610 | |
| 10611 | /** |
| 10612 | * Hook allowing a view to generate a representation of its internal state |
| 10613 | * that can later be used to create a new instance with that same state. |
| 10614 | * This state should only contain information that is not persistent or can |
| 10615 | * not be reconstructed later. For example, you will never store your |
| 10616 | * current position on screen because that will be computed again when a |
| 10617 | * new instance of the view is placed in its view hierarchy. |
| 10618 | * <p> |
| 10619 | * Some examples of things you may store here: the current cursor position |
| 10620 | * in a text view (but usually not the text itself since that is stored in a |
| 10621 | * content provider or other persistent storage), the currently selected |
| 10622 | * item in a list view. |
| 10623 | * |
| 10624 | * @return Returns a Parcelable object containing the view's current dynamic |
| 10625 | * state, or null if there is nothing interesting to save. The |
| 10626 | * default implementation returns null. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10627 | * @see #onRestoreInstanceState(android.os.Parcelable) |
| 10628 | * @see #saveHierarchyState(android.util.SparseArray) |
| 10629 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10630 | * @see #setSaveEnabled(boolean) |
| 10631 | */ |
| 10632 | protected Parcelable onSaveInstanceState() { |
| 10633 | mPrivateFlags |= SAVE_STATE_CALLED; |
| 10634 | return BaseSavedState.EMPTY_STATE; |
| 10635 | } |
| 10636 | |
| 10637 | /** |
| 10638 | * Restore this view hierarchy's frozen state from the given container. |
| 10639 | * |
| 10640 | * @param container The SparseArray which holds previously frozen states. |
| 10641 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10642 | * @see #saveHierarchyState(android.util.SparseArray) |
| 10643 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 10644 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10645 | */ |
| 10646 | public void restoreHierarchyState(SparseArray<Parcelable> container) { |
| 10647 | dispatchRestoreInstanceState(container); |
| 10648 | } |
| 10649 | |
| 10650 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10651 | * Called by {@link #restoreHierarchyState(android.util.SparseArray)} to retrieve the |
| 10652 | * state for this view and its children. May be overridden to modify how restoring |
| 10653 | * happens to a view's children; for example, some views may want to not store state |
| 10654 | * for their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10655 | * |
| 10656 | * @param container The SparseArray which holds previously saved state. |
| 10657 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10658 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 10659 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 10660 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10661 | */ |
| 10662 | protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 10663 | if (mID != NO_ID) { |
| 10664 | Parcelable state = container.get(mID); |
| 10665 | if (state != null) { |
| 10666 | // Log.i("View", "Restoreing #" + Integer.toHexString(mID) |
| 10667 | // + ": " + state); |
| 10668 | mPrivateFlags &= ~SAVE_STATE_CALLED; |
| 10669 | onRestoreInstanceState(state); |
| 10670 | if ((mPrivateFlags & SAVE_STATE_CALLED) == 0) { |
| 10671 | throw new IllegalStateException( |
| 10672 | "Derived class did not call super.onRestoreInstanceState()"); |
| 10673 | } |
| 10674 | } |
| 10675 | } |
| 10676 | } |
| 10677 | |
| 10678 | /** |
| 10679 | * Hook allowing a view to re-apply a representation of its internal state that had previously |
| 10680 | * been generated by {@link #onSaveInstanceState}. This function will never be called with a |
| 10681 | * null state. |
| 10682 | * |
| 10683 | * @param state The frozen state that had previously been returned by |
| 10684 | * {@link #onSaveInstanceState}. |
| 10685 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10686 | * @see #onSaveInstanceState() |
| 10687 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 10688 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10689 | */ |
| 10690 | protected void onRestoreInstanceState(Parcelable state) { |
| 10691 | mPrivateFlags |= SAVE_STATE_CALLED; |
| 10692 | if (state != BaseSavedState.EMPTY_STATE && state != null) { |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 10693 | throw new IllegalArgumentException("Wrong state class, expecting View State but " |
| 10694 | + "received " + state.getClass().toString() + " instead. This usually happens " |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10695 | + "when two views of different type have the same id in the same hierarchy. " |
| 10696 | + "This view's id is " + ViewDebug.resolveId(mContext, getId()) + ". Make sure " |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 10697 | + "other views do not use the same id."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10698 | } |
| 10699 | } |
| 10700 | |
| 10701 | /** |
| 10702 | * <p>Return the time at which the drawing of the view hierarchy started.</p> |
| 10703 | * |
| 10704 | * @return the drawing start time in milliseconds |
| 10705 | */ |
| 10706 | public long getDrawingTime() { |
| 10707 | return mAttachInfo != null ? mAttachInfo.mDrawingTime : 0; |
| 10708 | } |
| 10709 | |
| 10710 | /** |
| 10711 | * <p>Enables or disables the duplication of the parent's state into this view. When |
| 10712 | * duplication is enabled, this view gets its drawable state from its parent rather |
| 10713 | * than from its own internal properties.</p> |
| 10714 | * |
| 10715 | * <p>Note: in the current implementation, setting this property to true after the |
| 10716 | * view was added to a ViewGroup might have no effect at all. This property should |
| 10717 | * always be used from XML or set to true before adding this view to a ViewGroup.</p> |
| 10718 | * |
| 10719 | * <p>Note: if this view's parent addStateFromChildren property is enabled and this |
| 10720 | * property is enabled, an exception will be thrown.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10721 | * |
Gilles Debunne | fb81703 | 2011-01-13 13:52:49 -0800 | [diff] [blame] | 10722 | * <p>Note: if the child view uses and updates additionnal states which are unknown to the |
| 10723 | * 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] | 10724 | * |
| 10725 | * @param enabled True to enable duplication of the parent's drawable state, false |
| 10726 | * to disable it. |
| 10727 | * |
| 10728 | * @see #getDrawableState() |
| 10729 | * @see #isDuplicateParentStateEnabled() |
| 10730 | */ |
| 10731 | public void setDuplicateParentStateEnabled(boolean enabled) { |
| 10732 | setFlags(enabled ? DUPLICATE_PARENT_STATE : 0, DUPLICATE_PARENT_STATE); |
| 10733 | } |
| 10734 | |
| 10735 | /** |
| 10736 | * <p>Indicates whether this duplicates its drawable state from its parent.</p> |
| 10737 | * |
| 10738 | * @return True if this view's drawable state is duplicated from the parent, |
| 10739 | * false otherwise |
| 10740 | * |
| 10741 | * @see #getDrawableState() |
| 10742 | * @see #setDuplicateParentStateEnabled(boolean) |
| 10743 | */ |
| 10744 | public boolean isDuplicateParentStateEnabled() { |
| 10745 | return (mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE; |
| 10746 | } |
| 10747 | |
| 10748 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10749 | * <p>Specifies the type of layer backing this view. The layer can be |
| 10750 | * {@link #LAYER_TYPE_NONE disabled}, {@link #LAYER_TYPE_SOFTWARE software} or |
| 10751 | * {@link #LAYER_TYPE_HARDWARE hardware}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10752 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10753 | * <p>A layer is associated with an optional {@link android.graphics.Paint} |
| 10754 | * instance that controls how the layer is composed on screen. The following |
| 10755 | * properties of the paint are taken into account when composing the layer:</p> |
| 10756 | * <ul> |
| 10757 | * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> |
| 10758 | * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> |
| 10759 | * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> |
| 10760 | * </ul> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10761 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10762 | * <p>If this view has an alpha value set to < 1.0 by calling |
| 10763 | * {@link #setAlpha(float)}, the alpha value of the layer's paint is replaced by |
| 10764 | * this view's alpha value. Calling {@link #setAlpha(float)} is therefore |
| 10765 | * equivalent to setting a hardware layer on this view and providing a paint with |
| 10766 | * the desired alpha value.<p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10767 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10768 | * <p>Refer to the documentation of {@link #LAYER_TYPE_NONE disabled}, |
| 10769 | * {@link #LAYER_TYPE_SOFTWARE software} and {@link #LAYER_TYPE_HARDWARE hardware} |
| 10770 | * for more information on when and how to use layers.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10771 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10772 | * @param layerType The ype of layer to use with this view, must be one of |
| 10773 | * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 10774 | * {@link #LAYER_TYPE_HARDWARE} |
| 10775 | * @param paint The paint used to compose the layer. This argument is optional |
| 10776 | * and can be null. It is ignored when the layer type is |
| 10777 | * {@link #LAYER_TYPE_NONE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10778 | * |
| 10779 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10780 | * @see #LAYER_TYPE_NONE |
| 10781 | * @see #LAYER_TYPE_SOFTWARE |
| 10782 | * @see #LAYER_TYPE_HARDWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10783 | * @see #setAlpha(float) |
| 10784 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10785 | * @attr ref android.R.styleable#View_layerType |
| 10786 | */ |
| 10787 | public void setLayerType(int layerType, Paint paint) { |
| 10788 | if (layerType < LAYER_TYPE_NONE || layerType > LAYER_TYPE_HARDWARE) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10789 | 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] | 10790 | + "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE"); |
| 10791 | } |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10792 | |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 10793 | if (layerType == mLayerType) { |
| 10794 | if (layerType != LAYER_TYPE_NONE && paint != mLayerPaint) { |
| 10795 | mLayerPaint = paint == null ? new Paint() : paint; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10796 | invalidateParentCaches(); |
| 10797 | invalidate(true); |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 10798 | } |
| 10799 | return; |
| 10800 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10801 | |
| 10802 | // Destroy any previous software drawing cache if needed |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10803 | switch (mLayerType) { |
Chet Haase | 6f33e81 | 2011-05-17 12:42:19 -0700 | [diff] [blame] | 10804 | case LAYER_TYPE_HARDWARE: |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 10805 | destroyLayer(false); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 10806 | // fall through - non-accelerated views may use software layer mechanism instead |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10807 | case LAYER_TYPE_SOFTWARE: |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10808 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10809 | break; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10810 | default: |
| 10811 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10812 | } |
| 10813 | |
| 10814 | mLayerType = layerType; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 10815 | final boolean layerDisabled = mLayerType == LAYER_TYPE_NONE; |
| 10816 | mLayerPaint = layerDisabled ? null : (paint == null ? new Paint() : paint); |
| 10817 | mLocalDirtyRect = layerDisabled ? null : new Rect(); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10818 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10819 | invalidateParentCaches(); |
| 10820 | invalidate(true); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10821 | } |
| 10822 | |
| 10823 | /** |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 10824 | * Indicates whether this view has a static layer. A view with layer type |
| 10825 | * {@link #LAYER_TYPE_NONE} is a static layer. Other types of layers are |
| 10826 | * dynamic. |
| 10827 | */ |
| 10828 | boolean hasStaticLayer() { |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 10829 | return true; |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 10830 | } |
| 10831 | |
| 10832 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10833 | * Indicates what type of layer is currently associated with this view. By default |
| 10834 | * a view does not have a layer, and the layer type is {@link #LAYER_TYPE_NONE}. |
| 10835 | * Refer to the documentation of {@link #setLayerType(int, android.graphics.Paint)} |
| 10836 | * for more information on the different types of layers. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10837 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10838 | * @return {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 10839 | * {@link #LAYER_TYPE_HARDWARE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10840 | * |
| 10841 | * @see #setLayerType(int, android.graphics.Paint) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10842 | * @see #buildLayer() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10843 | * @see #LAYER_TYPE_NONE |
| 10844 | * @see #LAYER_TYPE_SOFTWARE |
| 10845 | * @see #LAYER_TYPE_HARDWARE |
| 10846 | */ |
| 10847 | public int getLayerType() { |
| 10848 | return mLayerType; |
| 10849 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10850 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10851 | /** |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10852 | * Forces this view's layer to be created and this view to be rendered |
| 10853 | * into its layer. If this view's layer type is set to {@link #LAYER_TYPE_NONE}, |
| 10854 | * invoking this method will have no effect. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10855 | * |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10856 | * This method can for instance be used to render a view into its layer before |
| 10857 | * starting an animation. If this view is complex, rendering into the layer |
| 10858 | * before starting the animation will avoid skipping frames. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10859 | * |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10860 | * @throws IllegalStateException If this view is not attached to a window |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10861 | * |
| 10862 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10863 | */ |
| 10864 | public void buildLayer() { |
| 10865 | if (mLayerType == LAYER_TYPE_NONE) return; |
| 10866 | |
| 10867 | if (mAttachInfo == null) { |
| 10868 | throw new IllegalStateException("This view must be attached to a window first"); |
| 10869 | } |
| 10870 | |
| 10871 | switch (mLayerType) { |
| 10872 | case LAYER_TYPE_HARDWARE: |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 10873 | if (mAttachInfo.mHardwareRenderer != null && |
| 10874 | mAttachInfo.mHardwareRenderer.isEnabled() && |
| 10875 | mAttachInfo.mHardwareRenderer.validate()) { |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 10876 | getHardwareLayer(); |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 10877 | } |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10878 | break; |
| 10879 | case LAYER_TYPE_SOFTWARE: |
| 10880 | buildDrawingCache(true); |
| 10881 | break; |
| 10882 | } |
| 10883 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10884 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10885 | // Make sure the HardwareRenderer.validate() was invoked before calling this method |
| 10886 | void flushLayer() { |
| 10887 | if (mLayerType == LAYER_TYPE_HARDWARE && mHardwareLayer != null) { |
| 10888 | mHardwareLayer.flush(); |
| 10889 | } |
| 10890 | } |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10891 | |
| 10892 | /** |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10893 | * <p>Returns a hardware layer that can be used to draw this view again |
| 10894 | * without executing its draw method.</p> |
| 10895 | * |
| 10896 | * @return A HardwareLayer ready to render, or null if an error occurred. |
| 10897 | */ |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 10898 | HardwareLayer getHardwareLayer() { |
Romain Guy | ea83503 | 2011-07-28 19:24:37 -0700 | [diff] [blame] | 10899 | if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null || |
| 10900 | !mAttachInfo.mHardwareRenderer.isEnabled()) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10901 | return null; |
| 10902 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10903 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10904 | if (!mAttachInfo.mHardwareRenderer.validate()) return null; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10905 | |
| 10906 | final int width = mRight - mLeft; |
| 10907 | final int height = mBottom - mTop; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10908 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10909 | if (width == 0 || height == 0) { |
| 10910 | return null; |
| 10911 | } |
| 10912 | |
| 10913 | if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || mHardwareLayer == null) { |
| 10914 | if (mHardwareLayer == null) { |
| 10915 | mHardwareLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer( |
| 10916 | width, height, isOpaque()); |
Michael Jurka | 952e02b | 2012-03-13 18:34:35 -0700 | [diff] [blame] | 10917 | mLocalDirtyRect.set(0, 0, width, height); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10918 | } else if (mHardwareLayer.getWidth() != width || mHardwareLayer.getHeight() != height) { |
| 10919 | mHardwareLayer.resize(width, height); |
Michael Jurka | 952e02b | 2012-03-13 18:34:35 -0700 | [diff] [blame] | 10920 | mLocalDirtyRect.set(0, 0, width, height); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10921 | } |
| 10922 | |
Romain Guy | 5cd5c3f | 2011-10-17 17:10:02 -0700 | [diff] [blame] | 10923 | // The layer is not valid if the underlying GPU resources cannot be allocated |
| 10924 | if (!mHardwareLayer.isValid()) { |
| 10925 | return null; |
| 10926 | } |
| 10927 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 10928 | mHardwareLayer.redraw(getHardwareLayerDisplayList(mHardwareLayer), mLocalDirtyRect); |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 10929 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10930 | } |
| 10931 | |
| 10932 | return mHardwareLayer; |
| 10933 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10934 | |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 10935 | /** |
| 10936 | * Destroys this View's hardware layer if possible. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10937 | * |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 10938 | * @return True if the layer was destroyed, false otherwise. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10939 | * |
| 10940 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 10941 | * @see #LAYER_TYPE_HARDWARE |
| 10942 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 10943 | boolean destroyLayer(boolean valid) { |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10944 | if (mHardwareLayer != null) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10945 | AttachInfo info = mAttachInfo; |
| 10946 | if (info != null && info.mHardwareRenderer != null && |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 10947 | info.mHardwareRenderer.isEnabled() && |
| 10948 | (valid || info.mHardwareRenderer.validate())) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10949 | mHardwareLayer.destroy(); |
| 10950 | mHardwareLayer = null; |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 10951 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10952 | invalidate(true); |
| 10953 | invalidateParentCaches(); |
| 10954 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 10955 | return true; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10956 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 10957 | return false; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10958 | } |
| 10959 | |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10960 | /** |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 10961 | * Destroys all hardware rendering resources. This method is invoked |
| 10962 | * when the system needs to reclaim resources. Upon execution of this |
| 10963 | * method, you should free any OpenGL resources created by the view. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10964 | * |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 10965 | * Note: you <strong>must</strong> call |
| 10966 | * <code>super.destroyHardwareResources()</code> when overriding |
| 10967 | * this method. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10968 | * |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 10969 | * @hide |
| 10970 | */ |
| 10971 | protected void destroyHardwareResources() { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 10972 | destroyLayer(true); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 10973 | } |
| 10974 | |
| 10975 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10976 | * <p>Enables or disables the drawing cache. When the drawing cache is enabled, the next call |
| 10977 | * to {@link #getDrawingCache()} or {@link #buildDrawingCache()} will draw the view in a |
| 10978 | * bitmap. Calling {@link #draw(android.graphics.Canvas)} will not draw from the cache when |
| 10979 | * the cache is enabled. To benefit from the cache, you must request the drawing cache by |
| 10980 | * calling {@link #getDrawingCache()} and draw it on screen if the returned bitmap is not |
| 10981 | * null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10982 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10983 | * <p>Enabling the drawing cache is similar to |
| 10984 | * {@link #setLayerType(int, android.graphics.Paint) setting a layer} when hardware |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10985 | * acceleration is turned off. When hardware acceleration is turned on, enabling the |
| 10986 | * drawing cache has no effect on rendering because the system uses a different mechanism |
| 10987 | * for acceleration which ignores the flag. If you want to use a Bitmap for the view, even |
| 10988 | * when hardware acceleration is enabled, see {@link #setLayerType(int, android.graphics.Paint)} |
| 10989 | * for information on how to enable software and hardware layers.</p> |
| 10990 | * |
| 10991 | * <p>This API can be used to manually generate |
| 10992 | * a bitmap copy of this view, by setting the flag to <code>true</code> and calling |
| 10993 | * {@link #getDrawingCache()}.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10994 | * |
| 10995 | * @param enabled true to enable the drawing cache, false otherwise |
| 10996 | * |
| 10997 | * @see #isDrawingCacheEnabled() |
| 10998 | * @see #getDrawingCache() |
| 10999 | * @see #buildDrawingCache() |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11000 | * @see #setLayerType(int, android.graphics.Paint) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11001 | */ |
| 11002 | public void setDrawingCacheEnabled(boolean enabled) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 11003 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11004 | setFlags(enabled ? DRAWING_CACHE_ENABLED : 0, DRAWING_CACHE_ENABLED); |
| 11005 | } |
| 11006 | |
| 11007 | /** |
| 11008 | * <p>Indicates whether the drawing cache is enabled for this view.</p> |
| 11009 | * |
| 11010 | * @return true if the drawing cache is enabled |
| 11011 | * |
| 11012 | * @see #setDrawingCacheEnabled(boolean) |
| 11013 | * @see #getDrawingCache() |
| 11014 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 11015 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11016 | public boolean isDrawingCacheEnabled() { |
| 11017 | return (mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED; |
| 11018 | } |
| 11019 | |
| 11020 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11021 | * Debugging utility which recursively outputs the dirty state of a view and its |
| 11022 | * descendants. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11023 | * |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11024 | * @hide |
| 11025 | */ |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 11026 | @SuppressWarnings({"UnusedDeclaration"}) |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11027 | public void outputDirtyFlags(String indent, boolean clear, int clearMask) { |
| 11028 | Log.d("View", indent + this + " DIRTY(" + (mPrivateFlags & View.DIRTY_MASK) + |
| 11029 | ") DRAWN(" + (mPrivateFlags & DRAWN) + ")" + " CACHE_VALID(" + |
| 11030 | (mPrivateFlags & View.DRAWING_CACHE_VALID) + |
| 11031 | ") INVALIDATED(" + (mPrivateFlags & INVALIDATED) + ")"); |
| 11032 | if (clear) { |
| 11033 | mPrivateFlags &= clearMask; |
| 11034 | } |
| 11035 | if (this instanceof ViewGroup) { |
| 11036 | ViewGroup parent = (ViewGroup) this; |
| 11037 | final int count = parent.getChildCount(); |
| 11038 | for (int i = 0; i < count; i++) { |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 11039 | final View child = parent.getChildAt(i); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11040 | child.outputDirtyFlags(indent + " ", clear, clearMask); |
| 11041 | } |
| 11042 | } |
| 11043 | } |
| 11044 | |
| 11045 | /** |
| 11046 | * This method is used by ViewGroup to cause its children to restore or recreate their |
| 11047 | * display lists. It is called by getDisplayList() when the parent ViewGroup does not need |
| 11048 | * to recreate its own display list, which would happen if it went through the normal |
| 11049 | * draw/dispatchDraw mechanisms. |
| 11050 | * |
| 11051 | * @hide |
| 11052 | */ |
| 11053 | protected void dispatchGetDisplayList() {} |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 11054 | |
| 11055 | /** |
| 11056 | * A view that is not attached or hardware accelerated cannot create a display list. |
| 11057 | * This method checks these conditions and returns the appropriate result. |
| 11058 | * |
| 11059 | * @return true if view has the ability to create a display list, false otherwise. |
| 11060 | * |
| 11061 | * @hide |
| 11062 | */ |
| 11063 | public boolean canHaveDisplayList() { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 11064 | return !(mAttachInfo == null || mAttachInfo.mHardwareRenderer == null); |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 11065 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11066 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11067 | /** |
Gilles Debunne | b35ab7b | 2011-12-05 15:54:00 -0800 | [diff] [blame] | 11068 | * @return The HardwareRenderer associated with that view or null if hardware rendering |
| 11069 | * is not supported or this this has not been attached to a window. |
| 11070 | * |
| 11071 | * @hide |
| 11072 | */ |
| 11073 | public HardwareRenderer getHardwareRenderer() { |
| 11074 | if (mAttachInfo != null) { |
| 11075 | return mAttachInfo.mHardwareRenderer; |
| 11076 | } |
| 11077 | return null; |
| 11078 | } |
| 11079 | |
| 11080 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11081 | * Returns a DisplayList. If the incoming displayList is null, one will be created. |
| 11082 | * Otherwise, the same display list will be returned (after having been rendered into |
| 11083 | * along the way, depending on the invalidation state of the view). |
| 11084 | * |
| 11085 | * @param displayList The previous version of this displayList, could be null. |
| 11086 | * @param isLayer Whether the requester of the display list is a layer. If so, |
| 11087 | * the view will avoid creating a layer inside the resulting display list. |
| 11088 | * @return A new or reused DisplayList object. |
| 11089 | */ |
| 11090 | private DisplayList getDisplayList(DisplayList displayList, boolean isLayer) { |
| 11091 | if (!canHaveDisplayList()) { |
| 11092 | return null; |
| 11093 | } |
| 11094 | |
| 11095 | if (((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || |
| 11096 | displayList == null || !displayList.isValid() || |
| 11097 | (!isLayer && mRecreateDisplayList))) { |
| 11098 | // Don't need to recreate the display list, just need to tell our |
| 11099 | // children to restore/recreate theirs |
| 11100 | if (displayList != null && displayList.isValid() && |
| 11101 | !isLayer && !mRecreateDisplayList) { |
| 11102 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 11103 | mPrivateFlags &= ~DIRTY_MASK; |
| 11104 | dispatchGetDisplayList(); |
| 11105 | |
| 11106 | return displayList; |
| 11107 | } |
| 11108 | |
| 11109 | if (!isLayer) { |
| 11110 | // If we got here, we're recreating it. Mark it as such to ensure that |
| 11111 | // we copy in child display lists into ours in drawChild() |
| 11112 | mRecreateDisplayList = true; |
| 11113 | } |
| 11114 | if (displayList == null) { |
| 11115 | final String name = getClass().getSimpleName(); |
| 11116 | displayList = mAttachInfo.mHardwareRenderer.createDisplayList(name); |
| 11117 | // If we're creating a new display list, make sure our parent gets invalidated |
| 11118 | // since they will need to recreate their display list to account for this |
| 11119 | // new child display list. |
| 11120 | invalidateParentCaches(); |
| 11121 | } |
| 11122 | |
| 11123 | boolean caching = false; |
| 11124 | final HardwareCanvas canvas = displayList.start(); |
| 11125 | int restoreCount = 0; |
| 11126 | int width = mRight - mLeft; |
| 11127 | int height = mBottom - mTop; |
| 11128 | |
| 11129 | try { |
| 11130 | canvas.setViewport(width, height); |
| 11131 | // The dirty rect should always be null for a display list |
| 11132 | canvas.onPreDraw(null); |
| 11133 | int layerType = ( |
| 11134 | !(mParent instanceof ViewGroup) || ((ViewGroup)mParent).mDrawLayers) ? |
| 11135 | getLayerType() : LAYER_TYPE_NONE; |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 11136 | if (!isLayer && layerType != LAYER_TYPE_NONE && USE_DISPLAY_LIST_PROPERTIES) { |
| 11137 | if (layerType == LAYER_TYPE_HARDWARE) { |
| 11138 | final HardwareLayer layer = getHardwareLayer(); |
| 11139 | if (layer != null && layer.isValid()) { |
| 11140 | canvas.drawHardwareLayer(layer, 0, 0, mLayerPaint); |
| 11141 | } else { |
| 11142 | canvas.saveLayer(0, 0, mRight - mLeft, mBottom - mTop, mLayerPaint, |
| 11143 | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | |
| 11144 | Canvas.CLIP_TO_LAYER_SAVE_FLAG); |
| 11145 | } |
| 11146 | caching = true; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11147 | } else { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 11148 | buildDrawingCache(true); |
| 11149 | Bitmap cache = getDrawingCache(true); |
| 11150 | if (cache != null) { |
| 11151 | canvas.drawBitmap(cache, 0, 0, mLayerPaint); |
| 11152 | caching = true; |
| 11153 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11154 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11155 | } else { |
| 11156 | |
| 11157 | computeScroll(); |
| 11158 | |
| 11159 | if (!USE_DISPLAY_LIST_PROPERTIES) { |
| 11160 | restoreCount = canvas.save(); |
| 11161 | } |
| 11162 | canvas.translate(-mScrollX, -mScrollY); |
| 11163 | if (!isLayer) { |
| 11164 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 11165 | mPrivateFlags &= ~DIRTY_MASK; |
| 11166 | } |
| 11167 | |
| 11168 | // Fast path for layouts with no backgrounds |
| 11169 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 11170 | dispatchDraw(canvas); |
| 11171 | } else { |
| 11172 | draw(canvas); |
| 11173 | } |
| 11174 | } |
| 11175 | } finally { |
| 11176 | if (USE_DISPLAY_LIST_PROPERTIES) { |
| 11177 | canvas.restoreToCount(restoreCount); |
| 11178 | } |
| 11179 | canvas.onPostDraw(); |
| 11180 | |
| 11181 | displayList.end(); |
| 11182 | if (USE_DISPLAY_LIST_PROPERTIES) { |
| 11183 | displayList.setCaching(caching); |
| 11184 | } |
| 11185 | if (isLayer && USE_DISPLAY_LIST_PROPERTIES) { |
| 11186 | displayList.setLeftTopRightBottom(0, 0, width, height); |
| 11187 | } else { |
| 11188 | setDisplayListProperties(displayList); |
| 11189 | } |
| 11190 | } |
| 11191 | } else if (!isLayer) { |
| 11192 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 11193 | mPrivateFlags &= ~DIRTY_MASK; |
| 11194 | } |
| 11195 | |
| 11196 | return displayList; |
| 11197 | } |
| 11198 | |
| 11199 | /** |
| 11200 | * Get the DisplayList for the HardwareLayer |
| 11201 | * |
| 11202 | * @param layer The HardwareLayer whose DisplayList we want |
| 11203 | * @return A DisplayList fopr the specified HardwareLayer |
| 11204 | */ |
| 11205 | private DisplayList getHardwareLayerDisplayList(HardwareLayer layer) { |
| 11206 | DisplayList displayList = getDisplayList(layer.getDisplayList(), true); |
| 11207 | layer.setDisplayList(displayList); |
| 11208 | return displayList; |
| 11209 | } |
| 11210 | |
| 11211 | |
| 11212 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 11213 | * <p>Returns a display list that can be used to draw this view again |
| 11214 | * without executing its draw method.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11215 | * |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 11216 | * @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] | 11217 | * |
| 11218 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 11219 | */ |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11220 | public DisplayList getDisplayList() { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11221 | mDisplayList = getDisplayList(mDisplayList, false); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 11222 | return mDisplayList; |
| 11223 | } |
| 11224 | |
| 11225 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11226 | * <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] | 11227 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11228 | * @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] | 11229 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11230 | * @see #getDrawingCache(boolean) |
| 11231 | */ |
| 11232 | public Bitmap getDrawingCache() { |
| 11233 | return getDrawingCache(false); |
| 11234 | } |
| 11235 | |
| 11236 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11237 | * <p>Returns the bitmap in which this view drawing is cached. The returned bitmap |
| 11238 | * is null when caching is disabled. If caching is enabled and the cache is not ready, |
| 11239 | * this method will create it. Calling {@link #draw(android.graphics.Canvas)} will not |
| 11240 | * draw from the cache when the cache is enabled. To benefit from the cache, you must |
| 11241 | * request the drawing cache by calling this method and draw it on screen if the |
| 11242 | * returned bitmap is not null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11243 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11244 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 11245 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 11246 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 11247 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 11248 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 11249 | * size than the view. This implies that your application must be able to handle this |
| 11250 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11251 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11252 | * @param autoScale Indicates whether the generated bitmap should be scaled based on |
| 11253 | * the current density of the screen when the application is in compatibility |
| 11254 | * mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11255 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11256 | * @return A bitmap representing this view or null if cache is disabled. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11257 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11258 | * @see #setDrawingCacheEnabled(boolean) |
| 11259 | * @see #isDrawingCacheEnabled() |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11260 | * @see #buildDrawingCache(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11261 | * @see #destroyDrawingCache() |
| 11262 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11263 | public Bitmap getDrawingCache(boolean autoScale) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11264 | if ((mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING) { |
| 11265 | return null; |
| 11266 | } |
| 11267 | if ((mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11268 | buildDrawingCache(autoScale); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11269 | } |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11270 | return autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11271 | } |
| 11272 | |
| 11273 | /** |
| 11274 | * <p>Frees the resources used by the drawing cache. If you call |
| 11275 | * {@link #buildDrawingCache()} manually without calling |
| 11276 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 11277 | * should cleanup the cache with this method afterwards.</p> |
| 11278 | * |
| 11279 | * @see #setDrawingCacheEnabled(boolean) |
| 11280 | * @see #buildDrawingCache() |
| 11281 | * @see #getDrawingCache() |
| 11282 | */ |
| 11283 | public void destroyDrawingCache() { |
| 11284 | if (mDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11285 | mDrawingCache.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11286 | mDrawingCache = null; |
| 11287 | } |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11288 | if (mUnscaledDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11289 | mUnscaledDrawingCache.recycle(); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11290 | mUnscaledDrawingCache = null; |
| 11291 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11292 | } |
| 11293 | |
| 11294 | /** |
| 11295 | * 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] | 11296 | * 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] | 11297 | * view will always be drawn on top of a solid color. |
| 11298 | * |
| 11299 | * @param color The background color to use for the drawing cache's bitmap |
| 11300 | * |
| 11301 | * @see #setDrawingCacheEnabled(boolean) |
| 11302 | * @see #buildDrawingCache() |
| 11303 | * @see #getDrawingCache() |
| 11304 | */ |
| 11305 | public void setDrawingCacheBackgroundColor(int color) { |
Romain Guy | 52e2ef8 | 2010-01-14 12:11:48 -0800 | [diff] [blame] | 11306 | if (color != mDrawingCacheBackgroundColor) { |
| 11307 | mDrawingCacheBackgroundColor = color; |
| 11308 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 11309 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11310 | } |
| 11311 | |
| 11312 | /** |
| 11313 | * @see #setDrawingCacheBackgroundColor(int) |
| 11314 | * |
| 11315 | * @return The background color to used for the drawing cache's bitmap |
| 11316 | */ |
| 11317 | public int getDrawingCacheBackgroundColor() { |
| 11318 | return mDrawingCacheBackgroundColor; |
| 11319 | } |
| 11320 | |
| 11321 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11322 | * <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] | 11323 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11324 | * @see #buildDrawingCache(boolean) |
| 11325 | */ |
| 11326 | public void buildDrawingCache() { |
| 11327 | buildDrawingCache(false); |
| 11328 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 11329 | |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11330 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11331 | * <p>Forces the drawing cache to be built if the drawing cache is invalid.</p> |
| 11332 | * |
| 11333 | * <p>If you call {@link #buildDrawingCache()} manually without calling |
| 11334 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 11335 | * should cleanup the cache by calling {@link #destroyDrawingCache()} afterwards.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11336 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11337 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 11338 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 11339 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 11340 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 11341 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 11342 | * size than the view. This implies that your application must be able to handle this |
| 11343 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11344 | * |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 11345 | * <p>You should avoid calling this method when hardware acceleration is enabled. If |
| 11346 | * 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] | 11347 | * 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] | 11348 | * performance.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11349 | * |
| 11350 | * @see #getDrawingCache() |
| 11351 | * @see #destroyDrawingCache() |
| 11352 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11353 | public void buildDrawingCache(boolean autoScale) { |
| 11354 | if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || (autoScale ? |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11355 | mDrawingCache == null : mUnscaledDrawingCache == null)) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 11356 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11357 | |
| 11358 | if (ViewDebug.TRACE_HIERARCHY) { |
| 11359 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.BUILD_CACHE); |
| 11360 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11361 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11362 | int width = mRight - mLeft; |
| 11363 | int height = mBottom - mTop; |
| 11364 | |
| 11365 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 11366 | final boolean scalingRequired = attachInfo != null && attachInfo.mScalingRequired; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11367 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 11368 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11369 | width = (int) ((width * attachInfo.mApplicationScale) + 0.5f); |
| 11370 | height = (int) ((height * attachInfo.mApplicationScale) + 0.5f); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11371 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11372 | |
| 11373 | final int drawingCacheBackgroundColor = mDrawingCacheBackgroundColor; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 11374 | final boolean opaque = drawingCacheBackgroundColor != 0 || isOpaque(); |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 11375 | final boolean use32BitCache = attachInfo != null && attachInfo.mUse32BitDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11376 | |
| 11377 | if (width <= 0 || height <= 0 || |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 11378 | // Projected bitmap size in bytes |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 11379 | (width * height * (opaque && !use32BitCache ? 2 : 4) > |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11380 | ViewConfiguration.get(mContext).getScaledMaximumDrawingCacheSize())) { |
| 11381 | destroyDrawingCache(); |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 11382 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11383 | return; |
| 11384 | } |
| 11385 | |
| 11386 | boolean clear = true; |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11387 | Bitmap bitmap = autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11388 | |
| 11389 | if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11390 | Bitmap.Config quality; |
| 11391 | if (!opaque) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 11392 | // Never pick ARGB_4444 because it looks awful |
| 11393 | // 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] | 11394 | switch (mViewFlags & DRAWING_CACHE_QUALITY_MASK) { |
| 11395 | case DRAWING_CACHE_QUALITY_AUTO: |
| 11396 | quality = Bitmap.Config.ARGB_8888; |
| 11397 | break; |
| 11398 | case DRAWING_CACHE_QUALITY_LOW: |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 11399 | quality = Bitmap.Config.ARGB_8888; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11400 | break; |
| 11401 | case DRAWING_CACHE_QUALITY_HIGH: |
| 11402 | quality = Bitmap.Config.ARGB_8888; |
| 11403 | break; |
| 11404 | default: |
| 11405 | quality = Bitmap.Config.ARGB_8888; |
| 11406 | break; |
| 11407 | } |
| 11408 | } else { |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 11409 | // Optimization for translucent windows |
| 11410 | // 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] | 11411 | 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] | 11412 | } |
| 11413 | |
| 11414 | // Try to cleanup memory |
| 11415 | if (bitmap != null) bitmap.recycle(); |
| 11416 | |
| 11417 | try { |
| 11418 | bitmap = Bitmap.createBitmap(width, height, quality); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 11419 | bitmap.setDensity(getResources().getDisplayMetrics().densityDpi); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11420 | if (autoScale) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11421 | mDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11422 | } else { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11423 | mUnscaledDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11424 | } |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 11425 | if (opaque && use32BitCache) bitmap.setHasAlpha(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11426 | } catch (OutOfMemoryError e) { |
| 11427 | // If there is not enough memory to create the bitmap cache, just |
| 11428 | // ignore the issue as bitmap caches are not required to draw the |
| 11429 | // view hierarchy |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11430 | if (autoScale) { |
| 11431 | mDrawingCache = null; |
| 11432 | } else { |
| 11433 | mUnscaledDrawingCache = null; |
| 11434 | } |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 11435 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11436 | return; |
| 11437 | } |
| 11438 | |
| 11439 | clear = drawingCacheBackgroundColor != 0; |
| 11440 | } |
| 11441 | |
| 11442 | Canvas canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11443 | if (attachInfo != null) { |
| 11444 | canvas = attachInfo.mCanvas; |
| 11445 | if (canvas == null) { |
| 11446 | canvas = new Canvas(); |
| 11447 | } |
| 11448 | canvas.setBitmap(bitmap); |
| 11449 | // Temporarily clobber the cached Canvas in case one of our children |
| 11450 | // is also using a drawing cache. Without this, the children would |
| 11451 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 11452 | // thing would happen (invisible views, corrupted drawings, etc.) |
| 11453 | attachInfo.mCanvas = null; |
| 11454 | } else { |
| 11455 | // This case should hopefully never or seldom happen |
| 11456 | canvas = new Canvas(bitmap); |
| 11457 | } |
| 11458 | |
| 11459 | if (clear) { |
| 11460 | bitmap.eraseColor(drawingCacheBackgroundColor); |
| 11461 | } |
| 11462 | |
| 11463 | computeScroll(); |
| 11464 | final int restoreCount = canvas.save(); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11465 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 11466 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11467 | final float scale = attachInfo.mApplicationScale; |
| 11468 | canvas.scale(scale, scale); |
| 11469 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11470 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11471 | canvas.translate(-mScrollX, -mScrollY); |
| 11472 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 11473 | mPrivateFlags |= DRAWN; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11474 | if (mAttachInfo == null || !mAttachInfo.mHardwareAccelerated || |
| 11475 | mLayerType != LAYER_TYPE_NONE) { |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 11476 | mPrivateFlags |= DRAWING_CACHE_VALID; |
| 11477 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11478 | |
| 11479 | // Fast path for layouts with no backgrounds |
| 11480 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 11481 | if (ViewDebug.TRACE_HIERARCHY) { |
| 11482 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW); |
| 11483 | } |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 11484 | mPrivateFlags &= ~DIRTY_MASK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11485 | dispatchDraw(canvas); |
| 11486 | } else { |
| 11487 | draw(canvas); |
| 11488 | } |
| 11489 | |
| 11490 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 11491 | canvas.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11492 | |
| 11493 | if (attachInfo != null) { |
| 11494 | // Restore the cached Canvas for our siblings |
| 11495 | attachInfo.mCanvas = canvas; |
| 11496 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11497 | } |
| 11498 | } |
| 11499 | |
| 11500 | /** |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11501 | * Create a snapshot of the view into a bitmap. We should probably make |
| 11502 | * some form of this public, but should think about the API. |
| 11503 | */ |
Romain Guy | 223ff5c | 2010-03-02 17:07:47 -0800 | [diff] [blame] | 11504 | Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipChildren) { |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 11505 | int width = mRight - mLeft; |
| 11506 | int height = mBottom - mTop; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11507 | |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 11508 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 11509 | final float scale = attachInfo != null ? attachInfo.mApplicationScale : 1.0f; |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 11510 | width = (int) ((width * scale) + 0.5f); |
| 11511 | height = (int) ((height * scale) + 0.5f); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11512 | |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 11513 | 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] | 11514 | if (bitmap == null) { |
| 11515 | throw new OutOfMemoryError(); |
| 11516 | } |
| 11517 | |
Romain Guy | c529d8d | 2011-09-06 15:01:39 -0700 | [diff] [blame] | 11518 | Resources resources = getResources(); |
| 11519 | if (resources != null) { |
| 11520 | bitmap.setDensity(resources.getDisplayMetrics().densityDpi); |
| 11521 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11522 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11523 | Canvas canvas; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11524 | if (attachInfo != null) { |
| 11525 | canvas = attachInfo.mCanvas; |
| 11526 | if (canvas == null) { |
| 11527 | canvas = new Canvas(); |
| 11528 | } |
| 11529 | canvas.setBitmap(bitmap); |
| 11530 | // Temporarily clobber the cached Canvas in case one of our children |
| 11531 | // is also using a drawing cache. Without this, the children would |
| 11532 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 11533 | // things would happen (invisible views, corrupted drawings, etc.) |
| 11534 | attachInfo.mCanvas = null; |
| 11535 | } else { |
| 11536 | // This case should hopefully never or seldom happen |
| 11537 | canvas = new Canvas(bitmap); |
| 11538 | } |
| 11539 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 11540 | if ((backgroundColor & 0xff000000) != 0) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11541 | bitmap.eraseColor(backgroundColor); |
| 11542 | } |
| 11543 | |
| 11544 | computeScroll(); |
| 11545 | final int restoreCount = canvas.save(); |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 11546 | canvas.scale(scale, scale); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11547 | canvas.translate(-mScrollX, -mScrollY); |
| 11548 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 11549 | // Temporarily remove the dirty mask |
| 11550 | int flags = mPrivateFlags; |
| 11551 | mPrivateFlags &= ~DIRTY_MASK; |
| 11552 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11553 | // Fast path for layouts with no backgrounds |
| 11554 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 11555 | dispatchDraw(canvas); |
| 11556 | } else { |
| 11557 | draw(canvas); |
| 11558 | } |
| 11559 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 11560 | mPrivateFlags = flags; |
| 11561 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11562 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 11563 | canvas.setBitmap(null); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11564 | |
| 11565 | if (attachInfo != null) { |
| 11566 | // Restore the cached Canvas for our siblings |
| 11567 | attachInfo.mCanvas = canvas; |
| 11568 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11569 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 11570 | return bitmap; |
| 11571 | } |
| 11572 | |
| 11573 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11574 | * Indicates whether this View is currently in edit mode. A View is usually |
| 11575 | * in edit mode when displayed within a developer tool. For instance, if |
| 11576 | * this View is being drawn by a visual user interface builder, this method |
| 11577 | * should return true. |
| 11578 | * |
| 11579 | * Subclasses should check the return value of this method to provide |
| 11580 | * different behaviors if their normal behavior might interfere with the |
| 11581 | * host environment. For instance: the class spawns a thread in its |
| 11582 | * constructor, the drawing code relies on device-specific features, etc. |
| 11583 | * |
| 11584 | * This method is usually checked in the drawing code of custom widgets. |
| 11585 | * |
| 11586 | * @return True if this View is in edit mode, false otherwise. |
| 11587 | */ |
| 11588 | public boolean isInEditMode() { |
| 11589 | return false; |
| 11590 | } |
| 11591 | |
| 11592 | /** |
| 11593 | * If the View draws content inside its padding and enables fading edges, |
| 11594 | * it needs to support padding offsets. Padding offsets are added to the |
| 11595 | * fading edges to extend the length of the fade so that it covers pixels |
| 11596 | * drawn inside the padding. |
| 11597 | * |
| 11598 | * Subclasses of this class should override this method if they need |
| 11599 | * to draw content inside the padding. |
| 11600 | * |
| 11601 | * @return True if padding offset must be applied, false otherwise. |
| 11602 | * |
| 11603 | * @see #getLeftPaddingOffset() |
| 11604 | * @see #getRightPaddingOffset() |
| 11605 | * @see #getTopPaddingOffset() |
| 11606 | * @see #getBottomPaddingOffset() |
| 11607 | * |
| 11608 | * @since CURRENT |
| 11609 | */ |
| 11610 | protected boolean isPaddingOffsetRequired() { |
| 11611 | return false; |
| 11612 | } |
| 11613 | |
| 11614 | /** |
| 11615 | * Amount by which to extend the left fading region. Called only when |
| 11616 | * {@link #isPaddingOffsetRequired()} returns true. |
| 11617 | * |
| 11618 | * @return The left padding offset in pixels. |
| 11619 | * |
| 11620 | * @see #isPaddingOffsetRequired() |
| 11621 | * |
| 11622 | * @since CURRENT |
| 11623 | */ |
| 11624 | protected int getLeftPaddingOffset() { |
| 11625 | return 0; |
| 11626 | } |
| 11627 | |
| 11628 | /** |
| 11629 | * Amount by which to extend the right fading region. Called only when |
| 11630 | * {@link #isPaddingOffsetRequired()} returns true. |
| 11631 | * |
| 11632 | * @return The right padding offset in pixels. |
| 11633 | * |
| 11634 | * @see #isPaddingOffsetRequired() |
| 11635 | * |
| 11636 | * @since CURRENT |
| 11637 | */ |
| 11638 | protected int getRightPaddingOffset() { |
| 11639 | return 0; |
| 11640 | } |
| 11641 | |
| 11642 | /** |
| 11643 | * Amount by which to extend the top fading region. Called only when |
| 11644 | * {@link #isPaddingOffsetRequired()} returns true. |
| 11645 | * |
| 11646 | * @return The top padding offset in pixels. |
| 11647 | * |
| 11648 | * @see #isPaddingOffsetRequired() |
| 11649 | * |
| 11650 | * @since CURRENT |
| 11651 | */ |
| 11652 | protected int getTopPaddingOffset() { |
| 11653 | return 0; |
| 11654 | } |
| 11655 | |
| 11656 | /** |
| 11657 | * Amount by which to extend the bottom fading region. Called only when |
| 11658 | * {@link #isPaddingOffsetRequired()} returns true. |
| 11659 | * |
| 11660 | * @return The bottom padding offset in pixels. |
| 11661 | * |
| 11662 | * @see #isPaddingOffsetRequired() |
| 11663 | * |
| 11664 | * @since CURRENT |
| 11665 | */ |
| 11666 | protected int getBottomPaddingOffset() { |
| 11667 | return 0; |
| 11668 | } |
| 11669 | |
| 11670 | /** |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 11671 | * @hide |
| 11672 | * @param offsetRequired |
| 11673 | */ |
| 11674 | protected int getFadeTop(boolean offsetRequired) { |
| 11675 | int top = mPaddingTop; |
| 11676 | if (offsetRequired) top += getTopPaddingOffset(); |
| 11677 | return top; |
| 11678 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11679 | |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 11680 | /** |
| 11681 | * @hide |
| 11682 | * @param offsetRequired |
| 11683 | */ |
| 11684 | protected int getFadeHeight(boolean offsetRequired) { |
| 11685 | int padding = mPaddingTop; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11686 | if (offsetRequired) padding += getTopPaddingOffset(); |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 11687 | return mBottom - mTop - mPaddingBottom - padding; |
| 11688 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11689 | |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 11690 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 11691 | * <p>Indicates whether this view is attached to a hardware accelerated |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 11692 | * window or not.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11693 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 11694 | * <p>Even if this method returns true, it does not mean that every call |
| 11695 | * to {@link #draw(android.graphics.Canvas)} will be made with an hardware |
| 11696 | * accelerated {@link android.graphics.Canvas}. For instance, if this view |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 11697 | * is drawn onto an offscreen {@link android.graphics.Bitmap} and its |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 11698 | * window is hardware accelerated, |
| 11699 | * {@link android.graphics.Canvas#isHardwareAccelerated()} will likely |
| 11700 | * return false, and this method will return true.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11701 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 11702 | * @return True if the view is attached to a window and the window is |
| 11703 | * hardware accelerated; false in any other case. |
| 11704 | */ |
| 11705 | public boolean isHardwareAccelerated() { |
| 11706 | return mAttachInfo != null && mAttachInfo.mHardwareAccelerated; |
| 11707 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11708 | |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 11709 | /** |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11710 | * Utility function, called by draw(canvas, parent, drawingTime) to handle the less common |
| 11711 | * case of an active Animation being run on the view. |
| 11712 | */ |
| 11713 | private boolean drawAnimation(ViewGroup parent, long drawingTime, |
| 11714 | Animation a, boolean scalingRequired) { |
| 11715 | Transformation invalidationTransform; |
| 11716 | final int flags = parent.mGroupFlags; |
| 11717 | final boolean initialized = a.isInitialized(); |
| 11718 | if (!initialized) { |
| 11719 | a.initialize(mRight - mLeft, mBottom - mTop, getWidth(), getHeight()); |
| 11720 | a.initializeInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop); |
| 11721 | onAnimationStart(); |
| 11722 | } |
| 11723 | |
| 11724 | boolean more = a.getTransformation(drawingTime, parent.mChildTransformation, 1f); |
| 11725 | if (scalingRequired && mAttachInfo.mApplicationScale != 1f) { |
| 11726 | if (parent.mInvalidationTransformation == null) { |
| 11727 | parent.mInvalidationTransformation = new Transformation(); |
| 11728 | } |
| 11729 | invalidationTransform = parent.mInvalidationTransformation; |
| 11730 | a.getTransformation(drawingTime, invalidationTransform, 1f); |
| 11731 | } else { |
| 11732 | invalidationTransform = parent.mChildTransformation; |
| 11733 | } |
| 11734 | if (more) { |
| 11735 | if (!a.willChangeBounds()) { |
| 11736 | if ((flags & (parent.FLAG_OPTIMIZE_INVALIDATE | parent.FLAG_ANIMATION_DONE)) == |
| 11737 | parent.FLAG_OPTIMIZE_INVALIDATE) { |
| 11738 | parent.mGroupFlags |= parent.FLAG_INVALIDATE_REQUIRED; |
| 11739 | } else if ((flags & parent.FLAG_INVALIDATE_REQUIRED) == 0) { |
| 11740 | // The child need to draw an animation, potentially offscreen, so |
| 11741 | // make sure we do not cancel invalidate requests |
| 11742 | parent.mPrivateFlags |= DRAW_ANIMATION; |
| 11743 | parent.invalidate(mLeft, mTop, mRight, mBottom); |
| 11744 | } |
| 11745 | } else { |
| 11746 | if (parent.mInvalidateRegion == null) { |
| 11747 | parent.mInvalidateRegion = new RectF(); |
| 11748 | } |
| 11749 | final RectF region = parent.mInvalidateRegion; |
| 11750 | a.getInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop, region, |
| 11751 | invalidationTransform); |
| 11752 | |
| 11753 | // The child need to draw an animation, potentially offscreen, so |
| 11754 | // make sure we do not cancel invalidate requests |
| 11755 | parent.mPrivateFlags |= DRAW_ANIMATION; |
| 11756 | |
| 11757 | final int left = mLeft + (int) region.left; |
| 11758 | final int top = mTop + (int) region.top; |
| 11759 | parent.invalidate(left, top, left + (int) (region.width() + .5f), |
| 11760 | top + (int) (region.height() + .5f)); |
| 11761 | } |
| 11762 | } |
| 11763 | return more; |
| 11764 | } |
| 11765 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11766 | void setDisplayListProperties() { |
| 11767 | setDisplayListProperties(mDisplayList); |
| 11768 | } |
| 11769 | |
| 11770 | /** |
| 11771 | * This method is called by getDisplayList() when a display list is created or re-rendered. |
| 11772 | * It sets or resets the current value of all properties on that display list (resetting is |
| 11773 | * necessary when a display list is being re-created, because we need to make sure that |
| 11774 | * previously-set transform values |
| 11775 | */ |
| 11776 | void setDisplayListProperties(DisplayList displayList) { |
| 11777 | if (USE_DISPLAY_LIST_PROPERTIES && displayList != null) { |
| 11778 | displayList.setLeftTopRightBottom(mLeft, mTop, mRight, mBottom); |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 11779 | displayList.setHasOverlappingRendering(hasOverlappingRendering()); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11780 | if (mParent instanceof ViewGroup) { |
| 11781 | displayList.setClipChildren( |
| 11782 | (((ViewGroup)mParent).mGroupFlags & ViewGroup.FLAG_CLIP_CHILDREN) != 0); |
| 11783 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 11784 | float alpha = 1; |
| 11785 | if (mParent instanceof ViewGroup && (((ViewGroup) mParent).mGroupFlags & |
| 11786 | ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
| 11787 | ViewGroup parentVG = (ViewGroup) mParent; |
| 11788 | final boolean hasTransform = |
| 11789 | parentVG.getChildStaticTransformation(this, parentVG.mChildTransformation); |
| 11790 | if (hasTransform) { |
| 11791 | Transformation transform = parentVG.mChildTransformation; |
| 11792 | final int transformType = parentVG.mChildTransformation.getTransformationType(); |
| 11793 | if (transformType != Transformation.TYPE_IDENTITY) { |
| 11794 | if ((transformType & Transformation.TYPE_ALPHA) != 0) { |
| 11795 | alpha = transform.getAlpha(); |
| 11796 | } |
| 11797 | if ((transformType & Transformation.TYPE_MATRIX) != 0) { |
| 11798 | displayList.setStaticMatrix(transform.getMatrix()); |
| 11799 | } |
| 11800 | } |
| 11801 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11802 | } |
| 11803 | if (mTransformationInfo != null) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 11804 | alpha *= mTransformationInfo.mAlpha; |
| 11805 | if (alpha < 1) { |
| 11806 | final int multipliedAlpha = (int) (255 * alpha); |
| 11807 | if (onSetAlpha(multipliedAlpha)) { |
| 11808 | alpha = 1; |
| 11809 | } |
| 11810 | } |
| 11811 | displayList.setTransformationInfo(alpha, |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11812 | mTransformationInfo.mTranslationX, mTransformationInfo.mTranslationY, |
| 11813 | mTransformationInfo.mRotation, mTransformationInfo.mRotationX, |
| 11814 | mTransformationInfo.mRotationY, mTransformationInfo.mScaleX, |
| 11815 | mTransformationInfo.mScaleY); |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 11816 | if (mTransformationInfo.mCamera == null) { |
| 11817 | mTransformationInfo.mCamera = new Camera(); |
| 11818 | mTransformationInfo.matrix3D = new Matrix(); |
| 11819 | } |
| 11820 | displayList.setCameraDistance(mTransformationInfo.mCamera.getLocationZ()); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11821 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == PIVOT_EXPLICITLY_SET) { |
| 11822 | displayList.setPivotX(getPivotX()); |
| 11823 | displayList.setPivotY(getPivotY()); |
| 11824 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 11825 | } else if (alpha < 1) { |
| 11826 | displayList.setAlpha(alpha); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11827 | } |
| 11828 | } |
| 11829 | } |
| 11830 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11831 | /** |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11832 | * This method is called by ViewGroup.drawChild() to have each child view draw itself. |
| 11833 | * This draw() method is an implementation detail and is not intended to be overridden or |
| 11834 | * to be called from anywhere else other than ViewGroup.drawChild(). |
| 11835 | */ |
| 11836 | boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11837 | boolean useDisplayListProperties = USE_DISPLAY_LIST_PROPERTIES && mAttachInfo != null && |
| 11838 | mAttachInfo.mHardwareAccelerated; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11839 | boolean more = false; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11840 | final boolean childHasIdentityMatrix = hasIdentityMatrix(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11841 | final int flags = parent.mGroupFlags; |
| 11842 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11843 | if ((flags & ViewGroup.FLAG_CLEAR_TRANSFORMATION) == ViewGroup.FLAG_CLEAR_TRANSFORMATION) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11844 | parent.mChildTransformation.clear(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11845 | parent.mGroupFlags &= ~ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11846 | } |
| 11847 | |
| 11848 | Transformation transformToApply = null; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11849 | boolean concatMatrix = false; |
| 11850 | |
| 11851 | boolean scalingRequired = false; |
| 11852 | boolean caching; |
| 11853 | int layerType = parent.mDrawLayers ? getLayerType() : LAYER_TYPE_NONE; |
| 11854 | |
| 11855 | final boolean hardwareAccelerated = canvas.isHardwareAccelerated(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11856 | if ((flags & ViewGroup.FLAG_CHILDREN_DRAWN_WITH_CACHE) != 0 || |
| 11857 | (flags & ViewGroup.FLAG_ALWAYS_DRAWN_WITH_CACHE) != 0) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11858 | caching = true; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 11859 | // Auto-scaled apps are not hw-accelerated, no need to set scaling flag on DisplayList |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11860 | if (mAttachInfo != null) scalingRequired = mAttachInfo.mScalingRequired; |
| 11861 | } else { |
| 11862 | caching = (layerType != LAYER_TYPE_NONE) || hardwareAccelerated; |
| 11863 | } |
| 11864 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11865 | final Animation a = getAnimation(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11866 | if (a != null) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11867 | more = drawAnimation(parent, drawingTime, a, scalingRequired); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11868 | concatMatrix = a.willChangeTransformationMatrix(); |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11869 | transformToApply = parent.mChildTransformation; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 11870 | } else if (!useDisplayListProperties && |
| 11871 | (flags & ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11872 | final boolean hasTransform = |
| 11873 | parent.getChildStaticTransformation(this, parent.mChildTransformation); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11874 | if (hasTransform) { |
| 11875 | final int transformType = parent.mChildTransformation.getTransformationType(); |
| 11876 | transformToApply = transformType != Transformation.TYPE_IDENTITY ? |
| 11877 | parent.mChildTransformation : null; |
| 11878 | concatMatrix = (transformType & Transformation.TYPE_MATRIX) != 0; |
| 11879 | } |
| 11880 | } |
| 11881 | |
| 11882 | concatMatrix |= !childHasIdentityMatrix; |
| 11883 | |
| 11884 | // Sets the flag as early as possible to allow draw() implementations |
| 11885 | // to call invalidate() successfully when doing animations |
| 11886 | mPrivateFlags |= DRAWN; |
| 11887 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11888 | if (!concatMatrix && canvas.quickReject(mLeft, mTop, mRight, mBottom, Canvas.EdgeType.BW) && |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11889 | (mPrivateFlags & DRAW_ANIMATION) == 0) { |
| 11890 | return more; |
| 11891 | } |
| 11892 | |
| 11893 | if (hardwareAccelerated) { |
| 11894 | // Clear INVALIDATED flag to allow invalidation to occur during rendering, but |
| 11895 | // retain the flag's value temporarily in the mRecreateDisplayList flag |
| 11896 | mRecreateDisplayList = (mPrivateFlags & INVALIDATED) == INVALIDATED; |
| 11897 | mPrivateFlags &= ~INVALIDATED; |
| 11898 | } |
| 11899 | |
| 11900 | computeScroll(); |
| 11901 | |
| 11902 | final int sx = mScrollX; |
| 11903 | final int sy = mScrollY; |
| 11904 | |
| 11905 | DisplayList displayList = null; |
| 11906 | Bitmap cache = null; |
| 11907 | boolean hasDisplayList = false; |
| 11908 | if (caching) { |
| 11909 | if (!hardwareAccelerated) { |
| 11910 | if (layerType != LAYER_TYPE_NONE) { |
| 11911 | layerType = LAYER_TYPE_SOFTWARE; |
| 11912 | buildDrawingCache(true); |
| 11913 | } |
| 11914 | cache = getDrawingCache(true); |
| 11915 | } else { |
| 11916 | switch (layerType) { |
| 11917 | case LAYER_TYPE_SOFTWARE: |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 11918 | if (useDisplayListProperties) { |
| 11919 | hasDisplayList = canHaveDisplayList(); |
| 11920 | } else { |
| 11921 | buildDrawingCache(true); |
| 11922 | cache = getDrawingCache(true); |
| 11923 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11924 | break; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11925 | case LAYER_TYPE_HARDWARE: |
| 11926 | if (useDisplayListProperties) { |
| 11927 | hasDisplayList = canHaveDisplayList(); |
| 11928 | } |
| 11929 | break; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11930 | case LAYER_TYPE_NONE: |
| 11931 | // Delay getting the display list until animation-driven alpha values are |
| 11932 | // set up and possibly passed on to the view |
| 11933 | hasDisplayList = canHaveDisplayList(); |
| 11934 | break; |
| 11935 | } |
| 11936 | } |
| 11937 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11938 | useDisplayListProperties &= hasDisplayList; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 11939 | if (useDisplayListProperties) { |
| 11940 | displayList = getDisplayList(); |
| 11941 | if (!displayList.isValid()) { |
| 11942 | // Uncommon, but possible. If a view is removed from the hierarchy during the call |
| 11943 | // to getDisplayList(), the display list will be marked invalid and we should not |
| 11944 | // try to use it again. |
| 11945 | displayList = null; |
| 11946 | hasDisplayList = false; |
| 11947 | useDisplayListProperties = false; |
| 11948 | } |
| 11949 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11950 | |
| 11951 | final boolean hasNoCache = cache == null || hasDisplayList; |
| 11952 | final boolean offsetForScroll = cache == null && !hasDisplayList && |
| 11953 | layerType != LAYER_TYPE_HARDWARE; |
| 11954 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11955 | int restoreTo = -1; |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 11956 | if (!useDisplayListProperties || transformToApply != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11957 | restoreTo = canvas.save(); |
| 11958 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11959 | if (offsetForScroll) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 11960 | canvas.translate(mLeft - sx, mTop - sy); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11961 | } else { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11962 | if (!useDisplayListProperties) { |
| 11963 | canvas.translate(mLeft, mTop); |
| 11964 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11965 | if (scalingRequired) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11966 | if (useDisplayListProperties) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 11967 | // TODO: Might not need this if we put everything inside the DL |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11968 | restoreTo = canvas.save(); |
| 11969 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11970 | // mAttachInfo cannot be null, otherwise scalingRequired == false |
| 11971 | final float scale = 1.0f / mAttachInfo.mApplicationScale; |
| 11972 | canvas.scale(scale, scale); |
| 11973 | } |
| 11974 | } |
| 11975 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11976 | float alpha = useDisplayListProperties ? 1 : getAlpha(); |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 11977 | if (transformToApply != null || alpha < 1 || !hasIdentityMatrix()) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11978 | if (transformToApply != null || !childHasIdentityMatrix) { |
| 11979 | int transX = 0; |
| 11980 | int transY = 0; |
| 11981 | |
| 11982 | if (offsetForScroll) { |
| 11983 | transX = -sx; |
| 11984 | transY = -sy; |
| 11985 | } |
| 11986 | |
| 11987 | if (transformToApply != null) { |
| 11988 | if (concatMatrix) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 11989 | if (useDisplayListProperties) { |
| 11990 | displayList.setAnimationMatrix(transformToApply.getMatrix()); |
| 11991 | } else { |
| 11992 | // Undo the scroll translation, apply the transformation matrix, |
| 11993 | // then redo the scroll translate to get the correct result. |
| 11994 | canvas.translate(-transX, -transY); |
| 11995 | canvas.concat(transformToApply.getMatrix()); |
| 11996 | canvas.translate(transX, transY); |
| 11997 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11998 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 11999 | } |
| 12000 | |
| 12001 | float transformAlpha = transformToApply.getAlpha(); |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12002 | if (transformAlpha < 1) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12003 | alpha *= transformToApply.getAlpha(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12004 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12005 | } |
| 12006 | } |
| 12007 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12008 | if (!childHasIdentityMatrix && !useDisplayListProperties) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12009 | canvas.translate(-transX, -transY); |
| 12010 | canvas.concat(getMatrix()); |
| 12011 | canvas.translate(transX, transY); |
| 12012 | } |
| 12013 | } |
| 12014 | |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12015 | if (alpha < 1) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12016 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12017 | if (hasNoCache) { |
| 12018 | final int multipliedAlpha = (int) (255 * alpha); |
| 12019 | if (!onSetAlpha(multipliedAlpha)) { |
| 12020 | int layerFlags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12021 | if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) != 0 || |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12022 | layerType != LAYER_TYPE_NONE) { |
| 12023 | layerFlags |= Canvas.CLIP_TO_LAYER_SAVE_FLAG; |
| 12024 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12025 | if (useDisplayListProperties) { |
| 12026 | displayList.setAlpha(alpha * getAlpha()); |
| 12027 | } else if (layerType == LAYER_TYPE_NONE) { |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 12028 | final int scrollX = hasDisplayList ? 0 : sx; |
| 12029 | final int scrollY = hasDisplayList ? 0 : sy; |
| 12030 | canvas.saveLayerAlpha(scrollX, scrollY, scrollX + mRight - mLeft, |
| 12031 | scrollY + mBottom - mTop, multipliedAlpha, layerFlags); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12032 | } |
| 12033 | } else { |
| 12034 | // Alpha is handled by the child directly, clobber the layer's alpha |
| 12035 | mPrivateFlags |= ALPHA_SET; |
| 12036 | } |
| 12037 | } |
| 12038 | } |
| 12039 | } else if ((mPrivateFlags & ALPHA_SET) == ALPHA_SET) { |
| 12040 | onSetAlpha(255); |
| 12041 | mPrivateFlags &= ~ALPHA_SET; |
| 12042 | } |
| 12043 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12044 | if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) == ViewGroup.FLAG_CLIP_CHILDREN && |
| 12045 | !useDisplayListProperties) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12046 | if (offsetForScroll) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12047 | canvas.clipRect(sx, sy, sx + (mRight - mLeft), sy + (mBottom - mTop)); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12048 | } else { |
| 12049 | if (!scalingRequired || cache == null) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12050 | canvas.clipRect(0, 0, mRight - mLeft, mBottom - mTop); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12051 | } else { |
| 12052 | canvas.clipRect(0, 0, cache.getWidth(), cache.getHeight()); |
| 12053 | } |
| 12054 | } |
| 12055 | } |
| 12056 | |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12057 | if (!useDisplayListProperties && hasDisplayList) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12058 | displayList = getDisplayList(); |
| 12059 | if (!displayList.isValid()) { |
| 12060 | // Uncommon, but possible. If a view is removed from the hierarchy during the call |
| 12061 | // to getDisplayList(), the display list will be marked invalid and we should not |
| 12062 | // try to use it again. |
| 12063 | displayList = null; |
| 12064 | hasDisplayList = false; |
| 12065 | } |
| 12066 | } |
| 12067 | |
| 12068 | if (hasNoCache) { |
| 12069 | boolean layerRendered = false; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12070 | if (layerType == LAYER_TYPE_HARDWARE && !useDisplayListProperties) { |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 12071 | final HardwareLayer layer = getHardwareLayer(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12072 | if (layer != null && layer.isValid()) { |
| 12073 | mLayerPaint.setAlpha((int) (alpha * 255)); |
| 12074 | ((HardwareCanvas) canvas).drawHardwareLayer(layer, 0, 0, mLayerPaint); |
| 12075 | layerRendered = true; |
| 12076 | } else { |
| 12077 | final int scrollX = hasDisplayList ? 0 : sx; |
| 12078 | final int scrollY = hasDisplayList ? 0 : sy; |
| 12079 | canvas.saveLayer(scrollX, scrollY, |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12080 | scrollX + mRight - mLeft, scrollY + mBottom - mTop, mLayerPaint, |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12081 | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); |
| 12082 | } |
| 12083 | } |
| 12084 | |
| 12085 | if (!layerRendered) { |
| 12086 | if (!hasDisplayList) { |
| 12087 | // Fast path for layouts with no backgrounds |
| 12088 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 12089 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12090 | ViewDebug.trace(parent, ViewDebug.HierarchyTraceType.DRAW); |
| 12091 | } |
| 12092 | mPrivateFlags &= ~DIRTY_MASK; |
| 12093 | dispatchDraw(canvas); |
| 12094 | } else { |
| 12095 | draw(canvas); |
| 12096 | } |
| 12097 | } else { |
| 12098 | mPrivateFlags &= ~DIRTY_MASK; |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12099 | ((HardwareCanvas) canvas).drawDisplayList(displayList, |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 12100 | mRight - mLeft, mBottom - mTop, null, flags); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12101 | } |
| 12102 | } |
| 12103 | } else if (cache != null) { |
| 12104 | mPrivateFlags &= ~DIRTY_MASK; |
| 12105 | Paint cachePaint; |
| 12106 | |
| 12107 | if (layerType == LAYER_TYPE_NONE) { |
| 12108 | cachePaint = parent.mCachePaint; |
| 12109 | if (cachePaint == null) { |
| 12110 | cachePaint = new Paint(); |
| 12111 | cachePaint.setDither(false); |
| 12112 | parent.mCachePaint = cachePaint; |
| 12113 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12114 | if (alpha < 1) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12115 | cachePaint.setAlpha((int) (alpha * 255)); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12116 | parent.mGroupFlags |= ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE; |
| 12117 | } else if ((flags & ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE) != 0) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12118 | cachePaint.setAlpha(255); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12119 | parent.mGroupFlags &= ~ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12120 | } |
| 12121 | } else { |
| 12122 | cachePaint = mLayerPaint; |
| 12123 | cachePaint.setAlpha((int) (alpha * 255)); |
| 12124 | } |
| 12125 | canvas.drawBitmap(cache, 0.0f, 0.0f, cachePaint); |
| 12126 | } |
| 12127 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12128 | if (restoreTo >= 0) { |
| 12129 | canvas.restoreToCount(restoreTo); |
| 12130 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12131 | |
| 12132 | if (a != null && !more) { |
| 12133 | if (!hardwareAccelerated && !a.getFillAfter()) { |
| 12134 | onSetAlpha(255); |
| 12135 | } |
| 12136 | parent.finishAnimatingView(this, a); |
| 12137 | } |
| 12138 | |
| 12139 | if (more && hardwareAccelerated) { |
| 12140 | // invalidation is the trigger to recreate display lists, so if we're using |
| 12141 | // display lists to render, force an invalidate to allow the animation to |
| 12142 | // continue drawing another frame |
| 12143 | parent.invalidate(true); |
| 12144 | if (a.hasAlpha() && (mPrivateFlags & ALPHA_SET) == ALPHA_SET) { |
| 12145 | // alpha animations should cause the child to recreate its display list |
| 12146 | invalidate(true); |
| 12147 | } |
| 12148 | } |
| 12149 | |
| 12150 | mRecreateDisplayList = false; |
| 12151 | |
| 12152 | return more; |
| 12153 | } |
| 12154 | |
| 12155 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12156 | * Manually render this view (and all of its children) to the given Canvas. |
| 12157 | * 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] | 12158 | * called. When implementing a view, implement |
| 12159 | * {@link #onDraw(android.graphics.Canvas)} instead of overriding this method. |
| 12160 | * 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] | 12161 | * |
| 12162 | * @param canvas The Canvas to which the View is rendered. |
| 12163 | */ |
| 12164 | public void draw(Canvas canvas) { |
| 12165 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12166 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW); |
| 12167 | } |
| 12168 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12169 | final int privateFlags = mPrivateFlags; |
| 12170 | final boolean dirtyOpaque = (privateFlags & DIRTY_MASK) == DIRTY_OPAQUE && |
| 12171 | (mAttachInfo == null || !mAttachInfo.mIgnoreDirtyState); |
| 12172 | mPrivateFlags = (privateFlags & ~DIRTY_MASK) | DRAWN; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12174 | /* |
| 12175 | * Draw traversal performs several drawing steps which must be executed |
| 12176 | * in the appropriate order: |
| 12177 | * |
| 12178 | * 1. Draw the background |
| 12179 | * 2. If necessary, save the canvas' layers to prepare for fading |
| 12180 | * 3. Draw view's content |
| 12181 | * 4. Draw children |
| 12182 | * 5. If necessary, draw the fading edges and restore layers |
| 12183 | * 6. Draw decorations (scrollbars for instance) |
| 12184 | */ |
| 12185 | |
| 12186 | // Step 1, draw the background, if needed |
| 12187 | int saveCount; |
| 12188 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12189 | if (!dirtyOpaque) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12190 | final Drawable background = mBackground; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12191 | if (background != null) { |
| 12192 | final int scrollX = mScrollX; |
| 12193 | final int scrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12194 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12195 | if (mBackgroundSizeChanged) { |
| 12196 | background.setBounds(0, 0, mRight - mLeft, mBottom - mTop); |
| 12197 | mBackgroundSizeChanged = false; |
| 12198 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12199 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12200 | if ((scrollX | scrollY) == 0) { |
| 12201 | background.draw(canvas); |
| 12202 | } else { |
| 12203 | canvas.translate(scrollX, scrollY); |
| 12204 | background.draw(canvas); |
| 12205 | canvas.translate(-scrollX, -scrollY); |
| 12206 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12207 | } |
| 12208 | } |
| 12209 | |
| 12210 | // skip step 2 & 5 if possible (common case) |
| 12211 | final int viewFlags = mViewFlags; |
| 12212 | boolean horizontalEdges = (viewFlags & FADING_EDGE_HORIZONTAL) != 0; |
| 12213 | boolean verticalEdges = (viewFlags & FADING_EDGE_VERTICAL) != 0; |
| 12214 | if (!verticalEdges && !horizontalEdges) { |
| 12215 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12216 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12217 | |
| 12218 | // Step 4, draw the children |
| 12219 | dispatchDraw(canvas); |
| 12220 | |
| 12221 | // Step 6, draw decorations (scrollbars) |
| 12222 | onDrawScrollBars(canvas); |
| 12223 | |
| 12224 | // we're done... |
| 12225 | return; |
| 12226 | } |
| 12227 | |
| 12228 | /* |
| 12229 | * Here we do the full fledged routine... |
| 12230 | * (this is an uncommon case where speed matters less, |
| 12231 | * this is why we repeat some of the tests that have been |
| 12232 | * done above) |
| 12233 | */ |
| 12234 | |
| 12235 | boolean drawTop = false; |
| 12236 | boolean drawBottom = false; |
| 12237 | boolean drawLeft = false; |
| 12238 | boolean drawRight = false; |
| 12239 | |
| 12240 | float topFadeStrength = 0.0f; |
| 12241 | float bottomFadeStrength = 0.0f; |
| 12242 | float leftFadeStrength = 0.0f; |
| 12243 | float rightFadeStrength = 0.0f; |
| 12244 | |
| 12245 | // Step 2, save the canvas' layers |
| 12246 | int paddingLeft = mPaddingLeft; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12247 | |
| 12248 | final boolean offsetRequired = isPaddingOffsetRequired(); |
| 12249 | if (offsetRequired) { |
| 12250 | paddingLeft += getLeftPaddingOffset(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12251 | } |
| 12252 | |
| 12253 | int left = mScrollX + paddingLeft; |
| 12254 | int right = left + mRight - mLeft - mPaddingRight - paddingLeft; |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 12255 | int top = mScrollY + getFadeTop(offsetRequired); |
| 12256 | int bottom = top + getFadeHeight(offsetRequired); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12257 | |
| 12258 | if (offsetRequired) { |
| 12259 | right += getRightPaddingOffset(); |
| 12260 | bottom += getBottomPaddingOffset(); |
| 12261 | } |
| 12262 | |
| 12263 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12264 | final float fadeHeight = scrollabilityCache.fadingEdgeLength; |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12265 | int length = (int) fadeHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12266 | |
| 12267 | // clip the fade length if top and bottom fades overlap |
| 12268 | // overlapping fades produce odd-looking artifacts |
| 12269 | if (verticalEdges && (top + length > bottom - length)) { |
| 12270 | length = (bottom - top) / 2; |
| 12271 | } |
| 12272 | |
| 12273 | // also clip horizontal fades if necessary |
| 12274 | if (horizontalEdges && (left + length > right - length)) { |
| 12275 | length = (right - left) / 2; |
| 12276 | } |
| 12277 | |
| 12278 | if (verticalEdges) { |
| 12279 | topFadeStrength = Math.max(0.0f, Math.min(1.0f, getTopFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12280 | drawTop = topFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12281 | bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, getBottomFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12282 | drawBottom = bottomFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12283 | } |
| 12284 | |
| 12285 | if (horizontalEdges) { |
| 12286 | leftFadeStrength = Math.max(0.0f, Math.min(1.0f, getLeftFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12287 | drawLeft = leftFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12288 | rightFadeStrength = Math.max(0.0f, Math.min(1.0f, getRightFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12289 | drawRight = rightFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12290 | } |
| 12291 | |
| 12292 | saveCount = canvas.getSaveCount(); |
| 12293 | |
| 12294 | int solidColor = getSolidColor(); |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 12295 | if (solidColor == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12296 | final int flags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
| 12297 | |
| 12298 | if (drawTop) { |
| 12299 | canvas.saveLayer(left, top, right, top + length, null, flags); |
| 12300 | } |
| 12301 | |
| 12302 | if (drawBottom) { |
| 12303 | canvas.saveLayer(left, bottom - length, right, bottom, null, flags); |
| 12304 | } |
| 12305 | |
| 12306 | if (drawLeft) { |
| 12307 | canvas.saveLayer(left, top, left + length, bottom, null, flags); |
| 12308 | } |
| 12309 | |
| 12310 | if (drawRight) { |
| 12311 | canvas.saveLayer(right - length, top, right, bottom, null, flags); |
| 12312 | } |
| 12313 | } else { |
| 12314 | scrollabilityCache.setFadeColor(solidColor); |
| 12315 | } |
| 12316 | |
| 12317 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12318 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12319 | |
| 12320 | // Step 4, draw the children |
| 12321 | dispatchDraw(canvas); |
| 12322 | |
| 12323 | // Step 5, draw the fade effect and restore layers |
| 12324 | final Paint p = scrollabilityCache.paint; |
| 12325 | final Matrix matrix = scrollabilityCache.matrix; |
| 12326 | final Shader fade = scrollabilityCache.shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12327 | |
| 12328 | if (drawTop) { |
| 12329 | matrix.setScale(1, fadeHeight * topFadeStrength); |
| 12330 | matrix.postTranslate(left, top); |
| 12331 | fade.setLocalMatrix(matrix); |
| 12332 | canvas.drawRect(left, top, right, top + length, p); |
| 12333 | } |
| 12334 | |
| 12335 | if (drawBottom) { |
| 12336 | matrix.setScale(1, fadeHeight * bottomFadeStrength); |
| 12337 | matrix.postRotate(180); |
| 12338 | matrix.postTranslate(left, bottom); |
| 12339 | fade.setLocalMatrix(matrix); |
| 12340 | canvas.drawRect(left, bottom - length, right, bottom, p); |
| 12341 | } |
| 12342 | |
| 12343 | if (drawLeft) { |
| 12344 | matrix.setScale(1, fadeHeight * leftFadeStrength); |
| 12345 | matrix.postRotate(-90); |
| 12346 | matrix.postTranslate(left, top); |
| 12347 | fade.setLocalMatrix(matrix); |
| 12348 | canvas.drawRect(left, top, left + length, bottom, p); |
| 12349 | } |
| 12350 | |
| 12351 | if (drawRight) { |
| 12352 | matrix.setScale(1, fadeHeight * rightFadeStrength); |
| 12353 | matrix.postRotate(90); |
| 12354 | matrix.postTranslate(right, top); |
| 12355 | fade.setLocalMatrix(matrix); |
| 12356 | canvas.drawRect(right - length, top, right, bottom, p); |
| 12357 | } |
| 12358 | |
| 12359 | canvas.restoreToCount(saveCount); |
| 12360 | |
| 12361 | // Step 6, draw decorations (scrollbars) |
| 12362 | onDrawScrollBars(canvas); |
| 12363 | } |
| 12364 | |
| 12365 | /** |
| 12366 | * Override this if your view is known to always be drawn on top of a solid color background, |
| 12367 | * and needs to draw fading edges. Returning a non-zero color enables the view system to |
| 12368 | * optimize the drawing of the fading edges. If you do return a non-zero color, the alpha |
| 12369 | * should be set to 0xFF. |
| 12370 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12371 | * @see #setVerticalFadingEdgeEnabled(boolean) |
| 12372 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12373 | * |
| 12374 | * @return The known solid color background for this view, or 0 if the color may vary |
| 12375 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12376 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12377 | public int getSolidColor() { |
| 12378 | return 0; |
| 12379 | } |
| 12380 | |
| 12381 | /** |
| 12382 | * Build a human readable string representation of the specified view flags. |
| 12383 | * |
| 12384 | * @param flags the view flags to convert to a string |
| 12385 | * @return a String representing the supplied flags |
| 12386 | */ |
| 12387 | private static String printFlags(int flags) { |
| 12388 | String output = ""; |
| 12389 | int numFlags = 0; |
| 12390 | if ((flags & FOCUSABLE_MASK) == FOCUSABLE) { |
| 12391 | output += "TAKES_FOCUS"; |
| 12392 | numFlags++; |
| 12393 | } |
| 12394 | |
| 12395 | switch (flags & VISIBILITY_MASK) { |
| 12396 | case INVISIBLE: |
| 12397 | if (numFlags > 0) { |
| 12398 | output += " "; |
| 12399 | } |
| 12400 | output += "INVISIBLE"; |
| 12401 | // USELESS HERE numFlags++; |
| 12402 | break; |
| 12403 | case GONE: |
| 12404 | if (numFlags > 0) { |
| 12405 | output += " "; |
| 12406 | } |
| 12407 | output += "GONE"; |
| 12408 | // USELESS HERE numFlags++; |
| 12409 | break; |
| 12410 | default: |
| 12411 | break; |
| 12412 | } |
| 12413 | return output; |
| 12414 | } |
| 12415 | |
| 12416 | /** |
| 12417 | * Build a human readable string representation of the specified private |
| 12418 | * view flags. |
| 12419 | * |
| 12420 | * @param privateFlags the private view flags to convert to a string |
| 12421 | * @return a String representing the supplied flags |
| 12422 | */ |
| 12423 | private static String printPrivateFlags(int privateFlags) { |
| 12424 | String output = ""; |
| 12425 | int numFlags = 0; |
| 12426 | |
| 12427 | if ((privateFlags & WANTS_FOCUS) == WANTS_FOCUS) { |
| 12428 | output += "WANTS_FOCUS"; |
| 12429 | numFlags++; |
| 12430 | } |
| 12431 | |
| 12432 | if ((privateFlags & FOCUSED) == FOCUSED) { |
| 12433 | if (numFlags > 0) { |
| 12434 | output += " "; |
| 12435 | } |
| 12436 | output += "FOCUSED"; |
| 12437 | numFlags++; |
| 12438 | } |
| 12439 | |
| 12440 | if ((privateFlags & SELECTED) == SELECTED) { |
| 12441 | if (numFlags > 0) { |
| 12442 | output += " "; |
| 12443 | } |
| 12444 | output += "SELECTED"; |
| 12445 | numFlags++; |
| 12446 | } |
| 12447 | |
| 12448 | if ((privateFlags & IS_ROOT_NAMESPACE) == IS_ROOT_NAMESPACE) { |
| 12449 | if (numFlags > 0) { |
| 12450 | output += " "; |
| 12451 | } |
| 12452 | output += "IS_ROOT_NAMESPACE"; |
| 12453 | numFlags++; |
| 12454 | } |
| 12455 | |
| 12456 | if ((privateFlags & HAS_BOUNDS) == HAS_BOUNDS) { |
| 12457 | if (numFlags > 0) { |
| 12458 | output += " "; |
| 12459 | } |
| 12460 | output += "HAS_BOUNDS"; |
| 12461 | numFlags++; |
| 12462 | } |
| 12463 | |
| 12464 | if ((privateFlags & DRAWN) == DRAWN) { |
| 12465 | if (numFlags > 0) { |
| 12466 | output += " "; |
| 12467 | } |
| 12468 | output += "DRAWN"; |
| 12469 | // USELESS HERE numFlags++; |
| 12470 | } |
| 12471 | return output; |
| 12472 | } |
| 12473 | |
| 12474 | /** |
| 12475 | * <p>Indicates whether or not this view's layout will be requested during |
| 12476 | * the next hierarchy layout pass.</p> |
| 12477 | * |
| 12478 | * @return true if the layout will be forced during next layout pass |
| 12479 | */ |
| 12480 | public boolean isLayoutRequested() { |
| 12481 | return (mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT; |
| 12482 | } |
| 12483 | |
| 12484 | /** |
| 12485 | * Assign a size and position to a view and all of its |
| 12486 | * descendants |
| 12487 | * |
| 12488 | * <p>This is the second phase of the layout mechanism. |
| 12489 | * (The first is measuring). In this phase, each parent calls |
| 12490 | * layout on all of its children to position them. |
| 12491 | * This is typically done using the child measurements |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 12492 | * that were stored in the measure pass().</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12493 | * |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 12494 | * <p>Derived classes should not override this method. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12495 | * Derived classes with children should override |
| 12496 | * onLayout. In that method, they should |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 12497 | * call layout on each of their children.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12498 | * |
| 12499 | * @param l Left position, relative to parent |
| 12500 | * @param t Top position, relative to parent |
| 12501 | * @param r Right position, relative to parent |
| 12502 | * @param b Bottom position, relative to parent |
| 12503 | */ |
Romain Guy | 5429e1d | 2010-09-07 12:38:00 -0700 | [diff] [blame] | 12504 | @SuppressWarnings({"unchecked"}) |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 12505 | public void layout(int l, int t, int r, int b) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 12506 | int oldL = mLeft; |
| 12507 | int oldT = mTop; |
| 12508 | int oldB = mBottom; |
| 12509 | int oldR = mRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12510 | boolean changed = setFrame(l, t, r, b); |
| 12511 | if (changed || (mPrivateFlags & LAYOUT_REQUIRED) == LAYOUT_REQUIRED) { |
| 12512 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12513 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_LAYOUT); |
| 12514 | } |
| 12515 | |
| 12516 | onLayout(changed, l, t, r, b); |
| 12517 | mPrivateFlags &= ~LAYOUT_REQUIRED; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 12518 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 12519 | ListenerInfo li = mListenerInfo; |
| 12520 | if (li != null && li.mOnLayoutChangeListeners != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 12521 | ArrayList<OnLayoutChangeListener> listenersCopy = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 12522 | (ArrayList<OnLayoutChangeListener>)li.mOnLayoutChangeListeners.clone(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 12523 | int numListeners = listenersCopy.size(); |
| 12524 | for (int i = 0; i < numListeners; ++i) { |
Chet Haase | 7c608f2 | 2010-10-22 17:54:04 -0700 | [diff] [blame] | 12525 | 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] | 12526 | } |
| 12527 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12528 | } |
| 12529 | mPrivateFlags &= ~FORCE_LAYOUT; |
| 12530 | } |
| 12531 | |
| 12532 | /** |
| 12533 | * Called from layout when this view should |
| 12534 | * assign a size and position to each of its children. |
| 12535 | * |
| 12536 | * Derived classes with children should override |
| 12537 | * this method and call layout on each of |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 12538 | * their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12539 | * @param changed This is a new size or position for this view |
| 12540 | * @param left Left position, relative to parent |
| 12541 | * @param top Top position, relative to parent |
| 12542 | * @param right Right position, relative to parent |
| 12543 | * @param bottom Bottom position, relative to parent |
| 12544 | */ |
| 12545 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 12546 | } |
| 12547 | |
| 12548 | /** |
| 12549 | * Assign a size and position to this view. |
| 12550 | * |
| 12551 | * This is called from layout. |
| 12552 | * |
| 12553 | * @param left Left position, relative to parent |
| 12554 | * @param top Top position, relative to parent |
| 12555 | * @param right Right position, relative to parent |
| 12556 | * @param bottom Bottom position, relative to parent |
| 12557 | * @return true if the new size and position are different than the |
| 12558 | * previous ones |
| 12559 | * {@hide} |
| 12560 | */ |
| 12561 | protected boolean setFrame(int left, int top, int right, int bottom) { |
| 12562 | boolean changed = false; |
| 12563 | |
| 12564 | if (DBG) { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 12565 | Log.d("View", this + " View.setFrame(" + left + "," + top + "," |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12566 | + right + "," + bottom + ")"); |
| 12567 | } |
| 12568 | |
| 12569 | if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) { |
| 12570 | changed = true; |
| 12571 | |
| 12572 | // Remember our drawn bit |
| 12573 | int drawn = mPrivateFlags & DRAWN; |
| 12574 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12575 | int oldWidth = mRight - mLeft; |
| 12576 | int oldHeight = mBottom - mTop; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 12577 | int newWidth = right - left; |
| 12578 | int newHeight = bottom - top; |
| 12579 | boolean sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight); |
| 12580 | |
| 12581 | // Invalidate our old position |
| 12582 | invalidate(sizeChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12583 | |
| 12584 | mLeft = left; |
| 12585 | mTop = top; |
| 12586 | mRight = right; |
| 12587 | mBottom = bottom; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12588 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 12589 | mDisplayList.setLeftTopRightBottom(mLeft, mTop, mRight, mBottom); |
| 12590 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12591 | |
| 12592 | mPrivateFlags |= HAS_BOUNDS; |
| 12593 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12594 | |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 12595 | if (sizeChanged) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 12596 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 12597 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 12598 | if (mTransformationInfo != null) { |
| 12599 | mTransformationInfo.mMatrixDirty = true; |
| 12600 | } |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 12601 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12602 | onSizeChanged(newWidth, newHeight, oldWidth, oldHeight); |
| 12603 | } |
| 12604 | |
| 12605 | if ((mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 12606 | // If we are visible, force the DRAWN bit to on so that |
| 12607 | // this invalidate will go through (at least to our parent). |
| 12608 | // This is because someone may have invalidated this view |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 12609 | // before this call to setFrame came in, thereby clearing |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12610 | // the DRAWN bit. |
| 12611 | mPrivateFlags |= DRAWN; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 12612 | invalidate(sizeChanged); |
Chet Haase | f28595e | 2011-01-31 18:52:12 -0800 | [diff] [blame] | 12613 | // parent display list may need to be recreated based on a change in the bounds |
| 12614 | // of any child |
| 12615 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12616 | } |
| 12617 | |
| 12618 | // Reset drawn bit to original value (invalidate turns it off) |
| 12619 | mPrivateFlags |= drawn; |
| 12620 | |
| 12621 | mBackgroundSizeChanged = true; |
| 12622 | } |
| 12623 | return changed; |
| 12624 | } |
| 12625 | |
| 12626 | /** |
| 12627 | * Finalize inflating a view from XML. This is called as the last phase |
| 12628 | * of inflation, after all child views have been added. |
| 12629 | * |
| 12630 | * <p>Even if the subclass overrides onFinishInflate, they should always be |
| 12631 | * sure to call the super method, so that we get called. |
| 12632 | */ |
| 12633 | protected void onFinishInflate() { |
| 12634 | } |
| 12635 | |
| 12636 | /** |
| 12637 | * Returns the resources associated with this view. |
| 12638 | * |
| 12639 | * @return Resources object. |
| 12640 | */ |
| 12641 | public Resources getResources() { |
| 12642 | return mResources; |
| 12643 | } |
| 12644 | |
| 12645 | /** |
| 12646 | * Invalidates the specified Drawable. |
| 12647 | * |
| 12648 | * @param drawable the drawable to invalidate |
| 12649 | */ |
| 12650 | public void invalidateDrawable(Drawable drawable) { |
| 12651 | if (verifyDrawable(drawable)) { |
| 12652 | final Rect dirty = drawable.getBounds(); |
| 12653 | final int scrollX = mScrollX; |
| 12654 | final int scrollY = mScrollY; |
| 12655 | |
| 12656 | invalidate(dirty.left + scrollX, dirty.top + scrollY, |
| 12657 | dirty.right + scrollX, dirty.bottom + scrollY); |
| 12658 | } |
| 12659 | } |
| 12660 | |
| 12661 | /** |
| 12662 | * Schedules an action on a drawable to occur at a specified time. |
| 12663 | * |
| 12664 | * @param who the recipient of the action |
| 12665 | * @param what the action to run on the drawable |
| 12666 | * @param when the time at which the action must occur. Uses the |
| 12667 | * {@link SystemClock#uptimeMillis} timebase. |
| 12668 | */ |
| 12669 | public void scheduleDrawable(Drawable who, Runnable what, long when) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 12670 | if (verifyDrawable(who) && what != null) { |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 12671 | final long delay = when - SystemClock.uptimeMillis(); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 12672 | if (mAttachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 12673 | mAttachInfo.mViewRootImpl.mChoreographer.postCallbackDelayed( |
| 12674 | Choreographer.CALLBACK_ANIMATION, what, who, |
| 12675 | Choreographer.subtractFrameDelay(delay)); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 12676 | } else { |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 12677 | ViewRootImpl.getRunQueue().postDelayed(what, delay); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 12678 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12679 | } |
| 12680 | } |
| 12681 | |
| 12682 | /** |
| 12683 | * Cancels a scheduled action on a drawable. |
| 12684 | * |
| 12685 | * @param who the recipient of the action |
| 12686 | * @param what the action to cancel |
| 12687 | */ |
| 12688 | public void unscheduleDrawable(Drawable who, Runnable what) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 12689 | if (verifyDrawable(who) && what != null) { |
| 12690 | if (mAttachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 12691 | mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 12692 | Choreographer.CALLBACK_ANIMATION, what, who); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 12693 | } else { |
| 12694 | ViewRootImpl.getRunQueue().removeCallbacks(what); |
| 12695 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12696 | } |
| 12697 | } |
| 12698 | |
| 12699 | /** |
| 12700 | * Unschedule any events associated with the given Drawable. This can be |
| 12701 | * used when selecting a new Drawable into a view, so that the previous |
| 12702 | * one is completely unscheduled. |
| 12703 | * |
| 12704 | * @param who The Drawable to unschedule. |
| 12705 | * |
| 12706 | * @see #drawableStateChanged |
| 12707 | */ |
| 12708 | public void unscheduleDrawable(Drawable who) { |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 12709 | if (mAttachInfo != null && who != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 12710 | mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 12711 | Choreographer.CALLBACK_ANIMATION, null, who); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12712 | } |
| 12713 | } |
| 12714 | |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 12715 | /** |
| 12716 | * Return the layout direction of a given Drawable. |
| 12717 | * |
| 12718 | * @param who the Drawable to query |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 12719 | */ |
| 12720 | public int getResolvedLayoutDirection(Drawable who) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12721 | return (who == mBackground) ? getResolvedLayoutDirection() : LAYOUT_DIRECTION_DEFAULT; |
Fabrice Di Meglio | 6a03640 | 2011-05-23 14:43:23 -0700 | [diff] [blame] | 12722 | } |
| 12723 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12724 | /** |
| 12725 | * If your view subclass is displaying its own Drawable objects, it should |
| 12726 | * override this function and return true for any Drawable it is |
| 12727 | * displaying. This allows animations for those drawables to be |
| 12728 | * scheduled. |
| 12729 | * |
| 12730 | * <p>Be sure to call through to the super class when overriding this |
| 12731 | * function. |
| 12732 | * |
| 12733 | * @param who The Drawable to verify. Return true if it is one you are |
| 12734 | * displaying, else return the result of calling through to the |
| 12735 | * super class. |
| 12736 | * |
| 12737 | * @return boolean If true than the Drawable is being displayed in the |
| 12738 | * view; else false and it is not allowed to animate. |
| 12739 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12740 | * @see #unscheduleDrawable(android.graphics.drawable.Drawable) |
| 12741 | * @see #drawableStateChanged() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12742 | */ |
| 12743 | protected boolean verifyDrawable(Drawable who) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12744 | return who == mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12745 | } |
| 12746 | |
| 12747 | /** |
| 12748 | * This function is called whenever the state of the view changes in such |
| 12749 | * a way that it impacts the state of drawables being shown. |
| 12750 | * |
| 12751 | * <p>Be sure to call through to the superclass when overriding this |
| 12752 | * function. |
| 12753 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12754 | * @see Drawable#setState(int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12755 | */ |
| 12756 | protected void drawableStateChanged() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12757 | Drawable d = mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12758 | if (d != null && d.isStateful()) { |
| 12759 | d.setState(getDrawableState()); |
| 12760 | } |
| 12761 | } |
| 12762 | |
| 12763 | /** |
| 12764 | * Call this to force a view to update its drawable state. This will cause |
| 12765 | * drawableStateChanged to be called on this view. Views that are interested |
| 12766 | * in the new state should call getDrawableState. |
| 12767 | * |
| 12768 | * @see #drawableStateChanged |
| 12769 | * @see #getDrawableState |
| 12770 | */ |
| 12771 | public void refreshDrawableState() { |
| 12772 | mPrivateFlags |= DRAWABLE_STATE_DIRTY; |
| 12773 | drawableStateChanged(); |
| 12774 | |
| 12775 | ViewParent parent = mParent; |
| 12776 | if (parent != null) { |
| 12777 | parent.childDrawableStateChanged(this); |
| 12778 | } |
| 12779 | } |
| 12780 | |
| 12781 | /** |
| 12782 | * Return an array of resource IDs of the drawable states representing the |
| 12783 | * current state of the view. |
| 12784 | * |
| 12785 | * @return The current drawable state |
| 12786 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12787 | * @see Drawable#setState(int[]) |
| 12788 | * @see #drawableStateChanged() |
| 12789 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12790 | */ |
| 12791 | public final int[] getDrawableState() { |
| 12792 | if ((mDrawableState != null) && ((mPrivateFlags & DRAWABLE_STATE_DIRTY) == 0)) { |
| 12793 | return mDrawableState; |
| 12794 | } else { |
| 12795 | mDrawableState = onCreateDrawableState(0); |
| 12796 | mPrivateFlags &= ~DRAWABLE_STATE_DIRTY; |
| 12797 | return mDrawableState; |
| 12798 | } |
| 12799 | } |
| 12800 | |
| 12801 | /** |
| 12802 | * Generate the new {@link android.graphics.drawable.Drawable} state for |
| 12803 | * this view. This is called by the view |
| 12804 | * system when the cached Drawable state is determined to be invalid. To |
| 12805 | * retrieve the current state, you should use {@link #getDrawableState}. |
| 12806 | * |
| 12807 | * @param extraSpace if non-zero, this is the number of extra entries you |
| 12808 | * would like in the returned array in which you can place your own |
| 12809 | * states. |
| 12810 | * |
| 12811 | * @return Returns an array holding the current {@link Drawable} state of |
| 12812 | * the view. |
| 12813 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12814 | * @see #mergeDrawableStates(int[], int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12815 | */ |
| 12816 | protected int[] onCreateDrawableState(int extraSpace) { |
| 12817 | if ((mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE && |
| 12818 | mParent instanceof View) { |
| 12819 | return ((View) mParent).onCreateDrawableState(extraSpace); |
| 12820 | } |
| 12821 | |
| 12822 | int[] drawableState; |
| 12823 | |
| 12824 | int privateFlags = mPrivateFlags; |
| 12825 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 12826 | int viewStateIndex = 0; |
| 12827 | if ((privateFlags & PRESSED) != 0) viewStateIndex |= VIEW_STATE_PRESSED; |
| 12828 | if ((mViewFlags & ENABLED_MASK) == ENABLED) viewStateIndex |= VIEW_STATE_ENABLED; |
| 12829 | if (isFocused()) viewStateIndex |= VIEW_STATE_FOCUSED; |
Neel Parekh | e537858 | 2010-10-06 11:36:50 -0700 | [diff] [blame] | 12830 | if ((privateFlags & SELECTED) != 0) viewStateIndex |= VIEW_STATE_SELECTED; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 12831 | if (hasWindowFocus()) viewStateIndex |= VIEW_STATE_WINDOW_FOCUSED; |
| 12832 | if ((privateFlags & ACTIVATED) != 0) viewStateIndex |= VIEW_STATE_ACTIVATED; |
Adam Powell | 5a7e94e | 2011-04-25 15:30:43 -0700 | [diff] [blame] | 12833 | if (mAttachInfo != null && mAttachInfo.mHardwareAccelerationRequested && |
| 12834 | HardwareRenderer.isAvailable()) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 12835 | // This is set if HW acceleration is requested, even if the current |
| 12836 | // process doesn't allow it. This is just to allow app preview |
| 12837 | // windows to better match their app. |
| 12838 | viewStateIndex |= VIEW_STATE_ACCELERATED; |
| 12839 | } |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 12840 | if ((privateFlags & HOVERED) != 0) viewStateIndex |= VIEW_STATE_HOVERED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12841 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 12842 | final int privateFlags2 = mPrivateFlags2; |
| 12843 | if ((privateFlags2 & DRAG_CAN_ACCEPT) != 0) viewStateIndex |= VIEW_STATE_DRAG_CAN_ACCEPT; |
| 12844 | if ((privateFlags2 & DRAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_DRAG_HOVERED; |
| 12845 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12846 | drawableState = VIEW_STATE_SETS[viewStateIndex]; |
| 12847 | |
| 12848 | //noinspection ConstantIfStatement |
| 12849 | if (false) { |
| 12850 | Log.i("View", "drawableStateIndex=" + viewStateIndex); |
| 12851 | Log.i("View", toString() |
| 12852 | + " pressed=" + ((privateFlags & PRESSED) != 0) |
| 12853 | + " en=" + ((mViewFlags & ENABLED_MASK) == ENABLED) |
| 12854 | + " fo=" + hasFocus() |
| 12855 | + " sl=" + ((privateFlags & SELECTED) != 0) |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 12856 | + " wf=" + hasWindowFocus() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12857 | + ": " + Arrays.toString(drawableState)); |
| 12858 | } |
| 12859 | |
| 12860 | if (extraSpace == 0) { |
| 12861 | return drawableState; |
| 12862 | } |
| 12863 | |
| 12864 | final int[] fullState; |
| 12865 | if (drawableState != null) { |
| 12866 | fullState = new int[drawableState.length + extraSpace]; |
| 12867 | System.arraycopy(drawableState, 0, fullState, 0, drawableState.length); |
| 12868 | } else { |
| 12869 | fullState = new int[extraSpace]; |
| 12870 | } |
| 12871 | |
| 12872 | return fullState; |
| 12873 | } |
| 12874 | |
| 12875 | /** |
| 12876 | * Merge your own state values in <var>additionalState</var> into the base |
| 12877 | * state values <var>baseState</var> that were returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12878 | * {@link #onCreateDrawableState(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12879 | * |
| 12880 | * @param baseState The base state values returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12881 | * {@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] | 12882 | * own additional state values. |
| 12883 | * |
| 12884 | * @param additionalState The additional state values you would like |
| 12885 | * added to <var>baseState</var>; this array is not modified. |
| 12886 | * |
| 12887 | * @return As a convenience, the <var>baseState</var> array you originally |
| 12888 | * passed into the function is returned. |
| 12889 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12890 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12891 | */ |
| 12892 | protected static int[] mergeDrawableStates(int[] baseState, int[] additionalState) { |
| 12893 | final int N = baseState.length; |
| 12894 | int i = N - 1; |
| 12895 | while (i >= 0 && baseState[i] == 0) { |
| 12896 | i--; |
| 12897 | } |
| 12898 | System.arraycopy(additionalState, 0, baseState, i + 1, additionalState.length); |
| 12899 | return baseState; |
| 12900 | } |
| 12901 | |
| 12902 | /** |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 12903 | * Call {@link Drawable#jumpToCurrentState() Drawable.jumpToCurrentState()} |
| 12904 | * on all Drawable objects associated with this view. |
| 12905 | */ |
| 12906 | public void jumpDrawablesToCurrentState() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12907 | if (mBackground != null) { |
| 12908 | mBackground.jumpToCurrentState(); |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 12909 | } |
| 12910 | } |
| 12911 | |
| 12912 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12913 | * Sets the background color for this view. |
| 12914 | * @param color the color of the background |
| 12915 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 12916 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12917 | public void setBackgroundColor(int color) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12918 | if (mBackground instanceof ColorDrawable) { |
| 12919 | ((ColorDrawable) mBackground).setColor(color); |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 12920 | } else { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12921 | setBackground(new ColorDrawable(color)); |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 12922 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12923 | } |
| 12924 | |
| 12925 | /** |
| 12926 | * Set the background to a given resource. The resource should refer to |
Wink Saville | 7cd88e1 | 2009-08-04 14:45:10 -0700 | [diff] [blame] | 12927 | * a Drawable object or 0 to remove the background. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12928 | * @param resid The identifier of the resource. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12929 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12930 | * @attr ref android.R.styleable#View_background |
| 12931 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 12932 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12933 | public void setBackgroundResource(int resid) { |
| 12934 | if (resid != 0 && resid == mBackgroundResource) { |
| 12935 | return; |
| 12936 | } |
| 12937 | |
| 12938 | Drawable d= null; |
| 12939 | if (resid != 0) { |
| 12940 | d = mResources.getDrawable(resid); |
| 12941 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12942 | setBackground(d); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12943 | |
| 12944 | mBackgroundResource = resid; |
| 12945 | } |
| 12946 | |
| 12947 | /** |
| 12948 | * Set the background to a given Drawable, or remove the background. If the |
| 12949 | * background has padding, this View's padding is set to the background's |
| 12950 | * padding. However, when a background is removed, this View's padding isn't |
| 12951 | * touched. If setting the padding is desired, please use |
| 12952 | * {@link #setPadding(int, int, int, int)}. |
| 12953 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12954 | * @param background The Drawable to use as the background, or null to remove the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12955 | * background |
| 12956 | */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12957 | public void setBackground(Drawable background) { |
| 12958 | setBackgroundDrawable(background); |
| 12959 | } |
| 12960 | |
| 12961 | /** |
| 12962 | * @deprecated use {@link #setBackground(Drawable)} instead |
| 12963 | */ |
| 12964 | @Deprecated |
| 12965 | public void setBackgroundDrawable(Drawable background) { |
| 12966 | if (background == mBackground) { |
Adam Powell | 4d36ec1 | 2011-07-17 16:44:16 -0700 | [diff] [blame] | 12967 | return; |
| 12968 | } |
| 12969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12970 | boolean requestLayout = false; |
| 12971 | |
| 12972 | mBackgroundResource = 0; |
| 12973 | |
| 12974 | /* |
| 12975 | * Regardless of whether we're setting a new background or not, we want |
| 12976 | * to clear the previous drawable. |
| 12977 | */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12978 | if (mBackground != null) { |
| 12979 | mBackground.setCallback(null); |
| 12980 | unscheduleDrawable(mBackground); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12981 | } |
| 12982 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12983 | if (background != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12984 | Rect padding = sThreadLocal.get(); |
| 12985 | if (padding == null) { |
| 12986 | padding = new Rect(); |
| 12987 | sThreadLocal.set(padding); |
| 12988 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12989 | if (background.getPadding(padding)) { |
| 12990 | switch (background.getResolvedLayoutDirectionSelf()) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12991 | case LAYOUT_DIRECTION_RTL: |
| 12992 | setPadding(padding.right, padding.top, padding.left, padding.bottom); |
| 12993 | break; |
| 12994 | case LAYOUT_DIRECTION_LTR: |
| 12995 | default: |
| 12996 | setPadding(padding.left, padding.top, padding.right, padding.bottom); |
| 12997 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12998 | } |
| 12999 | |
| 13000 | // Compare the minimum sizes of the old Drawable and the new. If there isn't an old or |
| 13001 | // if it has a different minimum size, we should layout again |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13002 | if (mBackground == null || mBackground.getMinimumHeight() != background.getMinimumHeight() || |
| 13003 | mBackground.getMinimumWidth() != background.getMinimumWidth()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13004 | requestLayout = true; |
| 13005 | } |
| 13006 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13007 | background.setCallback(this); |
| 13008 | if (background.isStateful()) { |
| 13009 | background.setState(getDrawableState()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13010 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13011 | background.setVisible(getVisibility() == VISIBLE, false); |
| 13012 | mBackground = background; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13013 | |
| 13014 | if ((mPrivateFlags & SKIP_DRAW) != 0) { |
| 13015 | mPrivateFlags &= ~SKIP_DRAW; |
| 13016 | mPrivateFlags |= ONLY_DRAWS_BACKGROUND; |
| 13017 | requestLayout = true; |
| 13018 | } |
| 13019 | } else { |
| 13020 | /* Remove the background */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13021 | mBackground = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13022 | |
| 13023 | if ((mPrivateFlags & ONLY_DRAWS_BACKGROUND) != 0) { |
| 13024 | /* |
| 13025 | * This view ONLY drew the background before and we're removing |
| 13026 | * the background, so now it won't draw anything |
| 13027 | * (hence we SKIP_DRAW) |
| 13028 | */ |
| 13029 | mPrivateFlags &= ~ONLY_DRAWS_BACKGROUND; |
| 13030 | mPrivateFlags |= SKIP_DRAW; |
| 13031 | } |
| 13032 | |
| 13033 | /* |
| 13034 | * When the background is set, we try to apply its padding to this |
| 13035 | * View. When the background is removed, we don't touch this View's |
| 13036 | * padding. This is noted in the Javadocs. Hence, we don't need to |
| 13037 | * requestLayout(), the invalidate() below is sufficient. |
| 13038 | */ |
| 13039 | |
| 13040 | // The old background's minimum size could have affected this |
| 13041 | // View's layout, so let's requestLayout |
| 13042 | requestLayout = true; |
| 13043 | } |
| 13044 | |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 13045 | computeOpaqueFlags(); |
| 13046 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13047 | if (requestLayout) { |
| 13048 | requestLayout(); |
| 13049 | } |
| 13050 | |
| 13051 | mBackgroundSizeChanged = true; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 13052 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13053 | } |
| 13054 | |
| 13055 | /** |
| 13056 | * Gets the background drawable |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13057 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13058 | * @return The drawable used as the background for this view, if any. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13059 | * |
| 13060 | * @see #setBackground(Drawable) |
| 13061 | * |
| 13062 | * @attr ref android.R.styleable#View_background |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13063 | */ |
| 13064 | public Drawable getBackground() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13065 | return mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13066 | } |
| 13067 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13068 | /** |
| 13069 | * Sets the padding. The view may add on the space required to display |
| 13070 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 13071 | * So the values returned from {@link #getPaddingLeft}, {@link #getPaddingTop}, |
| 13072 | * {@link #getPaddingRight} and {@link #getPaddingBottom} may be different |
| 13073 | * from the values set in this call. |
| 13074 | * |
| 13075 | * @attr ref android.R.styleable#View_padding |
| 13076 | * @attr ref android.R.styleable#View_paddingBottom |
| 13077 | * @attr ref android.R.styleable#View_paddingLeft |
| 13078 | * @attr ref android.R.styleable#View_paddingRight |
| 13079 | * @attr ref android.R.styleable#View_paddingTop |
| 13080 | * @param left the left padding in pixels |
| 13081 | * @param top the top padding in pixels |
| 13082 | * @param right the right padding in pixels |
| 13083 | * @param bottom the bottom padding in pixels |
| 13084 | */ |
| 13085 | public void setPadding(int left, int top, int right, int bottom) { |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13086 | mUserPaddingStart = -1; |
| 13087 | mUserPaddingEnd = -1; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13088 | mUserPaddingRelative = false; |
| 13089 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13090 | internalSetPadding(left, top, right, bottom); |
| 13091 | } |
| 13092 | |
| 13093 | private void internalSetPadding(int left, int top, int right, int bottom) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 13094 | mUserPaddingLeft = left; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13095 | mUserPaddingRight = right; |
| 13096 | mUserPaddingBottom = bottom; |
| 13097 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13098 | final int viewFlags = mViewFlags; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13099 | boolean changed = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13100 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13101 | // Common case is there are no scroll bars. |
| 13102 | if ((viewFlags & (SCROLLBARS_VERTICAL|SCROLLBARS_HORIZONTAL)) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13103 | if ((viewFlags & SCROLLBARS_VERTICAL) != 0) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 13104 | final int offset = (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13105 | ? 0 : getVerticalScrollbarWidth(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 13106 | switch (mVerticalScrollbarPosition) { |
| 13107 | case SCROLLBAR_POSITION_DEFAULT: |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13108 | if (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
| 13109 | left += offset; |
| 13110 | } else { |
| 13111 | right += offset; |
| 13112 | } |
| 13113 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 13114 | case SCROLLBAR_POSITION_RIGHT: |
| 13115 | right += offset; |
| 13116 | break; |
| 13117 | case SCROLLBAR_POSITION_LEFT: |
| 13118 | left += offset; |
| 13119 | break; |
| 13120 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13121 | } |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 13122 | if ((viewFlags & SCROLLBARS_HORIZONTAL) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13123 | bottom += (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
| 13124 | ? 0 : getHorizontalScrollbarHeight(); |
| 13125 | } |
| 13126 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13127 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13128 | if (mPaddingLeft != left) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13129 | changed = true; |
| 13130 | mPaddingLeft = left; |
| 13131 | } |
| 13132 | if (mPaddingTop != top) { |
| 13133 | changed = true; |
| 13134 | mPaddingTop = top; |
| 13135 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13136 | if (mPaddingRight != right) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13137 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13138 | mPaddingRight = right; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13139 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13140 | if (mPaddingBottom != bottom) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13141 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13142 | mPaddingBottom = bottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13143 | } |
| 13144 | |
| 13145 | if (changed) { |
| 13146 | requestLayout(); |
| 13147 | } |
| 13148 | } |
| 13149 | |
| 13150 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13151 | * Sets the relative padding. The view may add on the space required to display |
| 13152 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 13153 | * So the values returned from {@link #getPaddingStart}, {@link #getPaddingTop}, |
| 13154 | * {@link #getPaddingEnd} and {@link #getPaddingBottom} may be different |
| 13155 | * from the values set in this call. |
| 13156 | * |
| 13157 | * @attr ref android.R.styleable#View_padding |
| 13158 | * @attr ref android.R.styleable#View_paddingBottom |
| 13159 | * @attr ref android.R.styleable#View_paddingStart |
| 13160 | * @attr ref android.R.styleable#View_paddingEnd |
| 13161 | * @attr ref android.R.styleable#View_paddingTop |
| 13162 | * @param start the start padding in pixels |
| 13163 | * @param top the top padding in pixels |
| 13164 | * @param end the end padding in pixels |
| 13165 | * @param bottom the bottom padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13166 | */ |
| 13167 | public void setPaddingRelative(int start, int top, int end, int bottom) { |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 13168 | mUserPaddingStart = start; |
| 13169 | mUserPaddingEnd = end; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13170 | mUserPaddingRelative = true; |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 13171 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13172 | switch(getResolvedLayoutDirection()) { |
| 13173 | case LAYOUT_DIRECTION_RTL: |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13174 | internalSetPadding(end, top, start, bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13175 | break; |
| 13176 | case LAYOUT_DIRECTION_LTR: |
| 13177 | default: |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13178 | internalSetPadding(start, top, end, bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13179 | } |
| 13180 | } |
| 13181 | |
| 13182 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13183 | * Returns the top padding of this view. |
| 13184 | * |
| 13185 | * @return the top padding in pixels |
| 13186 | */ |
| 13187 | public int getPaddingTop() { |
| 13188 | return mPaddingTop; |
| 13189 | } |
| 13190 | |
| 13191 | /** |
| 13192 | * Returns the bottom padding of this view. If there are inset and enabled |
| 13193 | * scrollbars, this value may include the space required to display the |
| 13194 | * scrollbars as well. |
| 13195 | * |
| 13196 | * @return the bottom padding in pixels |
| 13197 | */ |
| 13198 | public int getPaddingBottom() { |
| 13199 | return mPaddingBottom; |
| 13200 | } |
| 13201 | |
| 13202 | /** |
| 13203 | * Returns the left padding of this view. If there are inset and enabled |
| 13204 | * scrollbars, this value may include the space required to display the |
| 13205 | * scrollbars as well. |
| 13206 | * |
| 13207 | * @return the left padding in pixels |
| 13208 | */ |
| 13209 | public int getPaddingLeft() { |
| 13210 | return mPaddingLeft; |
| 13211 | } |
| 13212 | |
| 13213 | /** |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 13214 | * Returns the start padding of this view depending on its resolved layout direction. |
| 13215 | * If there are inset and enabled scrollbars, this value may include the space |
| 13216 | * required to display the scrollbars as well. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13217 | * |
| 13218 | * @return the start padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13219 | */ |
| 13220 | public int getPaddingStart() { |
| 13221 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
| 13222 | mPaddingRight : mPaddingLeft; |
| 13223 | } |
| 13224 | |
| 13225 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13226 | * Returns the right padding of this view. If there are inset and enabled |
| 13227 | * scrollbars, this value may include the space required to display the |
| 13228 | * scrollbars as well. |
| 13229 | * |
| 13230 | * @return the right padding in pixels |
| 13231 | */ |
| 13232 | public int getPaddingRight() { |
| 13233 | return mPaddingRight; |
| 13234 | } |
| 13235 | |
| 13236 | /** |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 13237 | * Returns the end padding of this view depending on its resolved layout direction. |
| 13238 | * If there are inset and enabled scrollbars, this value may include the space |
| 13239 | * required to display the scrollbars as well. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13240 | * |
| 13241 | * @return the end padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13242 | */ |
| 13243 | public int getPaddingEnd() { |
| 13244 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
| 13245 | mPaddingLeft : mPaddingRight; |
| 13246 | } |
| 13247 | |
| 13248 | /** |
| 13249 | * Return if the padding as been set thru relative values |
| 13250 | * {@link #setPaddingRelative(int, int, int, int)} or thru |
| 13251 | * @attr ref android.R.styleable#View_paddingStart or |
| 13252 | * @attr ref android.R.styleable#View_paddingEnd |
| 13253 | * |
| 13254 | * @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] | 13255 | */ |
| 13256 | public boolean isPaddingRelative() { |
| 13257 | return mUserPaddingRelative; |
| 13258 | } |
| 13259 | |
| 13260 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13261 | * Changes the selection state of this view. A view can be selected or not. |
| 13262 | * Note that selection is not the same as focus. Views are typically |
| 13263 | * selected in the context of an AdapterView like ListView or GridView; |
| 13264 | * the selected view is the view that is highlighted. |
| 13265 | * |
| 13266 | * @param selected true if the view must be selected, false otherwise |
| 13267 | */ |
| 13268 | public void setSelected(boolean selected) { |
| 13269 | if (((mPrivateFlags & SELECTED) != 0) != selected) { |
| 13270 | mPrivateFlags = (mPrivateFlags & ~SELECTED) | (selected ? SELECTED : 0); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 13271 | if (!selected) resetPressedState(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 13272 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13273 | refreshDrawableState(); |
| 13274 | dispatchSetSelected(selected); |
| 13275 | } |
| 13276 | } |
| 13277 | |
| 13278 | /** |
| 13279 | * Dispatch setSelected to all of this View's children. |
| 13280 | * |
| 13281 | * @see #setSelected(boolean) |
| 13282 | * |
| 13283 | * @param selected The new selected state |
| 13284 | */ |
| 13285 | protected void dispatchSetSelected(boolean selected) { |
| 13286 | } |
| 13287 | |
| 13288 | /** |
| 13289 | * Indicates the selection state of this view. |
| 13290 | * |
| 13291 | * @return true if the view is selected, false otherwise |
| 13292 | */ |
| 13293 | @ViewDebug.ExportedProperty |
| 13294 | public boolean isSelected() { |
| 13295 | return (mPrivateFlags & SELECTED) != 0; |
| 13296 | } |
| 13297 | |
| 13298 | /** |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 13299 | * Changes the activated state of this view. A view can be activated or not. |
| 13300 | * Note that activation is not the same as selection. Selection is |
| 13301 | * a transient property, representing the view (hierarchy) the user is |
| 13302 | * currently interacting with. Activation is a longer-term state that the |
| 13303 | * user can move views in and out of. For example, in a list view with |
| 13304 | * single or multiple selection enabled, the views in the current selection |
| 13305 | * set are activated. (Um, yeah, we are deeply sorry about the terminology |
| 13306 | * here.) The activated state is propagated down to children of the view it |
| 13307 | * is set on. |
| 13308 | * |
| 13309 | * @param activated true if the view must be activated, false otherwise |
| 13310 | */ |
| 13311 | public void setActivated(boolean activated) { |
| 13312 | if (((mPrivateFlags & ACTIVATED) != 0) != activated) { |
| 13313 | mPrivateFlags = (mPrivateFlags & ~ACTIVATED) | (activated ? ACTIVATED : 0); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 13314 | invalidate(true); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 13315 | refreshDrawableState(); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 13316 | dispatchSetActivated(activated); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 13317 | } |
| 13318 | } |
| 13319 | |
| 13320 | /** |
| 13321 | * Dispatch setActivated to all of this View's children. |
| 13322 | * |
| 13323 | * @see #setActivated(boolean) |
| 13324 | * |
| 13325 | * @param activated The new activated state |
| 13326 | */ |
| 13327 | protected void dispatchSetActivated(boolean activated) { |
| 13328 | } |
| 13329 | |
| 13330 | /** |
| 13331 | * Indicates the activation state of this view. |
| 13332 | * |
| 13333 | * @return true if the view is activated, false otherwise |
| 13334 | */ |
| 13335 | @ViewDebug.ExportedProperty |
| 13336 | public boolean isActivated() { |
| 13337 | return (mPrivateFlags & ACTIVATED) != 0; |
| 13338 | } |
| 13339 | |
| 13340 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13341 | * Returns the ViewTreeObserver for this view's hierarchy. The view tree |
| 13342 | * observer can be used to get notifications when global events, like |
| 13343 | * layout, happen. |
| 13344 | * |
| 13345 | * The returned ViewTreeObserver observer is not guaranteed to remain |
| 13346 | * valid for the lifetime of this View. If the caller of this method keeps |
| 13347 | * a long-lived reference to ViewTreeObserver, it should always check for |
| 13348 | * the return value of {@link ViewTreeObserver#isAlive()}. |
| 13349 | * |
| 13350 | * @return The ViewTreeObserver for this view's hierarchy. |
| 13351 | */ |
| 13352 | public ViewTreeObserver getViewTreeObserver() { |
| 13353 | if (mAttachInfo != null) { |
| 13354 | return mAttachInfo.mTreeObserver; |
| 13355 | } |
| 13356 | if (mFloatingTreeObserver == null) { |
| 13357 | mFloatingTreeObserver = new ViewTreeObserver(); |
| 13358 | } |
| 13359 | return mFloatingTreeObserver; |
| 13360 | } |
| 13361 | |
| 13362 | /** |
| 13363 | * <p>Finds the topmost view in the current view hierarchy.</p> |
| 13364 | * |
| 13365 | * @return the topmost view containing this view |
| 13366 | */ |
| 13367 | public View getRootView() { |
| 13368 | if (mAttachInfo != null) { |
| 13369 | final View v = mAttachInfo.mRootView; |
| 13370 | if (v != null) { |
| 13371 | return v; |
| 13372 | } |
| 13373 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13375 | View parent = this; |
| 13376 | |
| 13377 | while (parent.mParent != null && parent.mParent instanceof View) { |
| 13378 | parent = (View) parent.mParent; |
| 13379 | } |
| 13380 | |
| 13381 | return parent; |
| 13382 | } |
| 13383 | |
| 13384 | /** |
| 13385 | * <p>Computes the coordinates of this view on the screen. The argument |
| 13386 | * must be an array of two integers. After the method returns, the array |
| 13387 | * contains the x and y location in that order.</p> |
| 13388 | * |
| 13389 | * @param location an array of two integers in which to hold the coordinates |
| 13390 | */ |
| 13391 | public void getLocationOnScreen(int[] location) { |
| 13392 | getLocationInWindow(location); |
| 13393 | |
| 13394 | final AttachInfo info = mAttachInfo; |
Romain Guy | 779398e | 2009-06-16 13:17:50 -0700 | [diff] [blame] | 13395 | if (info != null) { |
| 13396 | location[0] += info.mWindowLeft; |
| 13397 | location[1] += info.mWindowTop; |
| 13398 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13399 | } |
| 13400 | |
| 13401 | /** |
| 13402 | * <p>Computes the coordinates of this view in its window. The argument |
| 13403 | * must be an array of two integers. After the method returns, the array |
| 13404 | * contains the x and y location in that order.</p> |
| 13405 | * |
| 13406 | * @param location an array of two integers in which to hold the coordinates |
| 13407 | */ |
| 13408 | public void getLocationInWindow(int[] location) { |
| 13409 | if (location == null || location.length < 2) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 13410 | 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] | 13411 | } |
| 13412 | |
Gilles Debunne | 6583ce5 | 2011-12-06 18:09:02 -0800 | [diff] [blame] | 13413 | if (mAttachInfo == null) { |
| 13414 | // When the view is not attached to a window, this method does not make sense |
| 13415 | location[0] = location[1] = 0; |
| 13416 | return; |
| 13417 | } |
| 13418 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 13419 | float[] position = mAttachInfo.mTmpTransformLocation; |
| 13420 | position[0] = position[1] = 0.0f; |
| 13421 | |
| 13422 | if (!hasIdentityMatrix()) { |
| 13423 | getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 13424 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13425 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 13426 | position[0] += mLeft; |
| 13427 | position[1] += mTop; |
| 13428 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13429 | ViewParent viewParent = mParent; |
| 13430 | while (viewParent instanceof View) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 13431 | final View view = (View) viewParent; |
| 13432 | |
| 13433 | position[0] -= view.mScrollX; |
| 13434 | position[1] -= view.mScrollY; |
| 13435 | |
| 13436 | if (!view.hasIdentityMatrix()) { |
| 13437 | view.getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 13438 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 13439 | |
| 13440 | position[0] += view.mLeft; |
| 13441 | position[1] += view.mTop; |
| 13442 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13443 | viewParent = view.mParent; |
| 13444 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13445 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 13446 | if (viewParent instanceof ViewRootImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13447 | // *cough* |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 13448 | final ViewRootImpl vr = (ViewRootImpl) viewParent; |
| 13449 | position[1] -= vr.mCurScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13450 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 13451 | |
| 13452 | location[0] = (int) (position[0] + 0.5f); |
| 13453 | location[1] = (int) (position[1] + 0.5f); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13454 | } |
| 13455 | |
| 13456 | /** |
| 13457 | * {@hide} |
| 13458 | * @param id the id of the view to be found |
| 13459 | * @return the view of the specified id, null if cannot be found |
| 13460 | */ |
| 13461 | protected View findViewTraversal(int id) { |
| 13462 | if (id == mID) { |
| 13463 | return this; |
| 13464 | } |
| 13465 | return null; |
| 13466 | } |
| 13467 | |
| 13468 | /** |
| 13469 | * {@hide} |
| 13470 | * @param tag the tag of the view to be found |
| 13471 | * @return the view of specified tag, null if cannot be found |
| 13472 | */ |
| 13473 | protected View findViewWithTagTraversal(Object tag) { |
| 13474 | if (tag != null && tag.equals(mTag)) { |
| 13475 | return this; |
| 13476 | } |
| 13477 | return null; |
| 13478 | } |
| 13479 | |
| 13480 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 13481 | * {@hide} |
| 13482 | * @param predicate The predicate to evaluate. |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 13483 | * @param childToSkip If not null, ignores this child during the recursive traversal. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 13484 | * @return The first view that matches the predicate or null. |
| 13485 | */ |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 13486 | protected View findViewByPredicateTraversal(Predicate<View> predicate, View childToSkip) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 13487 | if (predicate.apply(this)) { |
| 13488 | return this; |
| 13489 | } |
| 13490 | return null; |
| 13491 | } |
| 13492 | |
| 13493 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13494 | * Look for a child view with the given id. If this view has the given |
| 13495 | * id, return this view. |
| 13496 | * |
| 13497 | * @param id The id to search for. |
| 13498 | * @return The view that has the given id in the hierarchy or null |
| 13499 | */ |
| 13500 | public final View findViewById(int id) { |
| 13501 | if (id < 0) { |
| 13502 | return null; |
| 13503 | } |
| 13504 | return findViewTraversal(id); |
| 13505 | } |
| 13506 | |
| 13507 | /** |
Svetoslav Ganov | 2cdedff | 2011-10-03 14:18:42 -0700 | [diff] [blame] | 13508 | * Finds a view by its unuque and stable accessibility id. |
| 13509 | * |
| 13510 | * @param accessibilityId The searched accessibility id. |
| 13511 | * @return The found view. |
| 13512 | */ |
| 13513 | final View findViewByAccessibilityId(int accessibilityId) { |
| 13514 | if (accessibilityId < 0) { |
| 13515 | return null; |
| 13516 | } |
| 13517 | return findViewByAccessibilityIdTraversal(accessibilityId); |
| 13518 | } |
| 13519 | |
| 13520 | /** |
| 13521 | * Performs the traversal to find a view by its unuque and stable accessibility id. |
| 13522 | * |
| 13523 | * <strong>Note:</strong>This method does not stop at the root namespace |
| 13524 | * boundary since the user can touch the screen at an arbitrary location |
| 13525 | * potentially crossing the root namespace bounday which will send an |
| 13526 | * accessibility event to accessibility services and they should be able |
| 13527 | * to obtain the event source. Also accessibility ids are guaranteed to be |
| 13528 | * unique in the window. |
| 13529 | * |
| 13530 | * @param accessibilityId The accessibility id. |
| 13531 | * @return The found view. |
| 13532 | */ |
| 13533 | View findViewByAccessibilityIdTraversal(int accessibilityId) { |
| 13534 | if (getAccessibilityViewId() == accessibilityId) { |
| 13535 | return this; |
| 13536 | } |
| 13537 | return null; |
| 13538 | } |
| 13539 | |
| 13540 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13541 | * Look for a child view with the given tag. If this view has the given |
| 13542 | * tag, return this view. |
| 13543 | * |
| 13544 | * @param tag The tag to search for, using "tag.equals(getTag())". |
| 13545 | * @return The View that has the given tag in the hierarchy or null |
| 13546 | */ |
| 13547 | public final View findViewWithTag(Object tag) { |
| 13548 | if (tag == null) { |
| 13549 | return null; |
| 13550 | } |
| 13551 | return findViewWithTagTraversal(tag); |
| 13552 | } |
| 13553 | |
| 13554 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 13555 | * {@hide} |
| 13556 | * Look for a child view that matches the specified predicate. |
| 13557 | * If this view matches the predicate, return this view. |
| 13558 | * |
| 13559 | * @param predicate The predicate to evaluate. |
| 13560 | * @return The first view that matches the predicate or null. |
| 13561 | */ |
| 13562 | public final View findViewByPredicate(Predicate<View> predicate) { |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 13563 | return findViewByPredicateTraversal(predicate, null); |
| 13564 | } |
| 13565 | |
| 13566 | /** |
| 13567 | * {@hide} |
| 13568 | * Look for a child view that matches the specified predicate, |
| 13569 | * starting with the specified view and its descendents and then |
| 13570 | * recusively searching the ancestors and siblings of that view |
| 13571 | * until this view is reached. |
| 13572 | * |
| 13573 | * This method is useful in cases where the predicate does not match |
| 13574 | * a single unique view (perhaps multiple views use the same id) |
| 13575 | * and we are trying to find the view that is "closest" in scope to the |
| 13576 | * starting view. |
| 13577 | * |
| 13578 | * @param start The view to start from. |
| 13579 | * @param predicate The predicate to evaluate. |
| 13580 | * @return The first view that matches the predicate or null. |
| 13581 | */ |
| 13582 | public final View findViewByPredicateInsideOut(View start, Predicate<View> predicate) { |
| 13583 | View childToSkip = null; |
| 13584 | for (;;) { |
| 13585 | View view = start.findViewByPredicateTraversal(predicate, childToSkip); |
| 13586 | if (view != null || start == this) { |
| 13587 | return view; |
| 13588 | } |
| 13589 | |
| 13590 | ViewParent parent = start.getParent(); |
| 13591 | if (parent == null || !(parent instanceof View)) { |
| 13592 | return null; |
| 13593 | } |
| 13594 | |
| 13595 | childToSkip = start; |
| 13596 | start = (View) parent; |
| 13597 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 13598 | } |
| 13599 | |
| 13600 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13601 | * Sets the identifier for this view. The identifier does not have to be |
| 13602 | * unique in this view's hierarchy. The identifier should be a positive |
| 13603 | * number. |
| 13604 | * |
| 13605 | * @see #NO_ID |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13606 | * @see #getId() |
| 13607 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13608 | * |
| 13609 | * @param id a number used to identify the view |
| 13610 | * |
| 13611 | * @attr ref android.R.styleable#View_id |
| 13612 | */ |
| 13613 | public void setId(int id) { |
| 13614 | mID = id; |
| 13615 | } |
| 13616 | |
| 13617 | /** |
| 13618 | * {@hide} |
| 13619 | * |
| 13620 | * @param isRoot true if the view belongs to the root namespace, false |
| 13621 | * otherwise |
| 13622 | */ |
| 13623 | public void setIsRootNamespace(boolean isRoot) { |
| 13624 | if (isRoot) { |
| 13625 | mPrivateFlags |= IS_ROOT_NAMESPACE; |
| 13626 | } else { |
| 13627 | mPrivateFlags &= ~IS_ROOT_NAMESPACE; |
| 13628 | } |
| 13629 | } |
| 13630 | |
| 13631 | /** |
| 13632 | * {@hide} |
| 13633 | * |
| 13634 | * @return true if the view belongs to the root namespace, false otherwise |
| 13635 | */ |
| 13636 | public boolean isRootNamespace() { |
| 13637 | return (mPrivateFlags&IS_ROOT_NAMESPACE) != 0; |
| 13638 | } |
| 13639 | |
| 13640 | /** |
| 13641 | * Returns this view's identifier. |
| 13642 | * |
| 13643 | * @return a positive integer used to identify the view or {@link #NO_ID} |
| 13644 | * if the view has no ID |
| 13645 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13646 | * @see #setId(int) |
| 13647 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13648 | * @attr ref android.R.styleable#View_id |
| 13649 | */ |
| 13650 | @ViewDebug.CapturedViewProperty |
| 13651 | public int getId() { |
| 13652 | return mID; |
| 13653 | } |
| 13654 | |
| 13655 | /** |
| 13656 | * Returns this view's tag. |
| 13657 | * |
| 13658 | * @return the Object stored in this view as a tag |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13659 | * |
| 13660 | * @see #setTag(Object) |
| 13661 | * @see #getTag(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13662 | */ |
| 13663 | @ViewDebug.ExportedProperty |
| 13664 | public Object getTag() { |
| 13665 | return mTag; |
| 13666 | } |
| 13667 | |
| 13668 | /** |
| 13669 | * Sets the tag associated with this view. A tag can be used to mark |
| 13670 | * a view in its hierarchy and does not have to be unique within the |
| 13671 | * hierarchy. Tags can also be used to store data within a view without |
| 13672 | * resorting to another data structure. |
| 13673 | * |
| 13674 | * @param tag an Object to tag the view with |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13675 | * |
| 13676 | * @see #getTag() |
| 13677 | * @see #setTag(int, Object) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13678 | */ |
| 13679 | public void setTag(final Object tag) { |
| 13680 | mTag = tag; |
| 13681 | } |
| 13682 | |
| 13683 | /** |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13684 | * Returns the tag associated with this view and the specified key. |
| 13685 | * |
| 13686 | * @param key The key identifying the tag |
| 13687 | * |
| 13688 | * @return the Object stored in this view as a tag |
| 13689 | * |
| 13690 | * @see #setTag(int, Object) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13691 | * @see #getTag() |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13692 | */ |
| 13693 | public Object getTag(int key) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 13694 | if (mKeyedTags != null) return mKeyedTags.get(key); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13695 | return null; |
| 13696 | } |
| 13697 | |
| 13698 | /** |
| 13699 | * Sets a tag associated with this view and a key. A tag can be used |
| 13700 | * to mark a view in its hierarchy and does not have to be unique within |
| 13701 | * the hierarchy. Tags can also be used to store data within a view |
| 13702 | * without resorting to another data structure. |
| 13703 | * |
| 13704 | * 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] | 13705 | * application to ensure it is unique (see the <a |
| 13706 | * href={@docRoot}guide/topics/resources/more-resources.html#Id">ID resource type</a>). |
| 13707 | * Keys identified as belonging to |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13708 | * the Android framework or not associated with any package will cause |
| 13709 | * an {@link IllegalArgumentException} to be thrown. |
| 13710 | * |
| 13711 | * @param key The key identifying the tag |
| 13712 | * @param tag An Object to tag the view with |
| 13713 | * |
| 13714 | * @throws IllegalArgumentException If they specified key is not valid |
| 13715 | * |
| 13716 | * @see #setTag(Object) |
| 13717 | * @see #getTag(int) |
| 13718 | */ |
| 13719 | public void setTag(int key, final Object tag) { |
| 13720 | // If the package id is 0x00 or 0x01, it's either an undefined package |
| 13721 | // or a framework id |
| 13722 | if ((key >>> 24) < 2) { |
| 13723 | throw new IllegalArgumentException("The key must be an application-specific " |
| 13724 | + "resource id."); |
| 13725 | } |
| 13726 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 13727 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13728 | } |
| 13729 | |
| 13730 | /** |
| 13731 | * Variation of {@link #setTag(int, Object)} that enforces the key to be a |
| 13732 | * framework id. |
| 13733 | * |
| 13734 | * @hide |
| 13735 | */ |
| 13736 | public void setTagInternal(int key, Object tag) { |
| 13737 | if ((key >>> 24) != 0x1) { |
| 13738 | throw new IllegalArgumentException("The key must be a framework-specific " |
| 13739 | + "resource id."); |
| 13740 | } |
| 13741 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 13742 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13743 | } |
| 13744 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 13745 | private void setKeyedTag(int key, Object tag) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 13746 | if (mKeyedTags == null) { |
| 13747 | mKeyedTags = new SparseArray<Object>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13748 | } |
| 13749 | |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 13750 | mKeyedTags.put(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 13751 | } |
| 13752 | |
| 13753 | /** |
Romain Guy | 13922e0 | 2009-05-12 17:56:14 -0700 | [diff] [blame] | 13754 | * @param consistency The type of consistency. See ViewDebug for more information. |
| 13755 | * |
| 13756 | * @hide |
| 13757 | */ |
| 13758 | protected boolean dispatchConsistencyCheck(int consistency) { |
| 13759 | return onConsistencyCheck(consistency); |
| 13760 | } |
| 13761 | |
| 13762 | /** |
| 13763 | * Method that subclasses should implement to check their consistency. The type of |
| 13764 | * consistency check is indicated by the bit field passed as a parameter. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13765 | * |
Romain Guy | 13922e0 | 2009-05-12 17:56:14 -0700 | [diff] [blame] | 13766 | * @param consistency The type of consistency. See ViewDebug for more information. |
| 13767 | * |
| 13768 | * @throws IllegalStateException if the view is in an inconsistent state. |
| 13769 | * |
| 13770 | * @hide |
| 13771 | */ |
| 13772 | protected boolean onConsistencyCheck(int consistency) { |
| 13773 | boolean result = true; |
| 13774 | |
| 13775 | final boolean checkLayout = (consistency & ViewDebug.CONSISTENCY_LAYOUT) != 0; |
| 13776 | final boolean checkDrawing = (consistency & ViewDebug.CONSISTENCY_DRAWING) != 0; |
| 13777 | |
| 13778 | if (checkLayout) { |
| 13779 | if (getParent() == null) { |
| 13780 | result = false; |
| 13781 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 13782 | "View " + this + " does not have a parent."); |
| 13783 | } |
| 13784 | |
| 13785 | if (mAttachInfo == null) { |
| 13786 | result = false; |
| 13787 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 13788 | "View " + this + " is not attached to a window."); |
| 13789 | } |
| 13790 | } |
| 13791 | |
| 13792 | if (checkDrawing) { |
| 13793 | // Do not check the DIRTY/DRAWN flags because views can call invalidate() |
| 13794 | // from their draw() method |
| 13795 | |
| 13796 | if ((mPrivateFlags & DRAWN) != DRAWN && |
| 13797 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) { |
| 13798 | result = false; |
| 13799 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 13800 | "View " + this + " was invalidated but its drawing cache is valid."); |
| 13801 | } |
| 13802 | } |
| 13803 | |
| 13804 | return result; |
| 13805 | } |
| 13806 | |
| 13807 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13808 | * Prints information about this view in the log output, with the tag |
| 13809 | * {@link #VIEW_LOG_TAG}. |
| 13810 | * |
| 13811 | * @hide |
| 13812 | */ |
| 13813 | public void debug() { |
| 13814 | debug(0); |
| 13815 | } |
| 13816 | |
| 13817 | /** |
| 13818 | * Prints information about this view in the log output, with the tag |
| 13819 | * {@link #VIEW_LOG_TAG}. Each line in the output is preceded with an |
| 13820 | * indentation defined by the <code>depth</code>. |
| 13821 | * |
| 13822 | * @param depth the indentation level |
| 13823 | * |
| 13824 | * @hide |
| 13825 | */ |
| 13826 | protected void debug(int depth) { |
| 13827 | String output = debugIndent(depth - 1); |
| 13828 | |
| 13829 | output += "+ " + this; |
| 13830 | int id = getId(); |
| 13831 | if (id != -1) { |
| 13832 | output += " (id=" + id + ")"; |
| 13833 | } |
| 13834 | Object tag = getTag(); |
| 13835 | if (tag != null) { |
| 13836 | output += " (tag=" + tag + ")"; |
| 13837 | } |
| 13838 | Log.d(VIEW_LOG_TAG, output); |
| 13839 | |
| 13840 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 13841 | output = debugIndent(depth) + " FOCUSED"; |
| 13842 | Log.d(VIEW_LOG_TAG, output); |
| 13843 | } |
| 13844 | |
| 13845 | output = debugIndent(depth); |
| 13846 | output += "frame={" + mLeft + ", " + mTop + ", " + mRight |
| 13847 | + ", " + mBottom + "} scroll={" + mScrollX + ", " + mScrollY |
| 13848 | + "} "; |
| 13849 | Log.d(VIEW_LOG_TAG, output); |
| 13850 | |
| 13851 | if (mPaddingLeft != 0 || mPaddingTop != 0 || mPaddingRight != 0 |
| 13852 | || mPaddingBottom != 0) { |
| 13853 | output = debugIndent(depth); |
| 13854 | output += "padding={" + mPaddingLeft + ", " + mPaddingTop |
| 13855 | + ", " + mPaddingRight + ", " + mPaddingBottom + "}"; |
| 13856 | Log.d(VIEW_LOG_TAG, output); |
| 13857 | } |
| 13858 | |
| 13859 | output = debugIndent(depth); |
| 13860 | output += "mMeasureWidth=" + mMeasuredWidth + |
| 13861 | " mMeasureHeight=" + mMeasuredHeight; |
| 13862 | Log.d(VIEW_LOG_TAG, output); |
| 13863 | |
| 13864 | output = debugIndent(depth); |
| 13865 | if (mLayoutParams == null) { |
| 13866 | output += "BAD! no layout params"; |
| 13867 | } else { |
| 13868 | output = mLayoutParams.debug(output); |
| 13869 | } |
| 13870 | Log.d(VIEW_LOG_TAG, output); |
| 13871 | |
| 13872 | output = debugIndent(depth); |
| 13873 | output += "flags={"; |
| 13874 | output += View.printFlags(mViewFlags); |
| 13875 | output += "}"; |
| 13876 | Log.d(VIEW_LOG_TAG, output); |
| 13877 | |
| 13878 | output = debugIndent(depth); |
| 13879 | output += "privateFlags={"; |
| 13880 | output += View.printPrivateFlags(mPrivateFlags); |
| 13881 | output += "}"; |
| 13882 | Log.d(VIEW_LOG_TAG, output); |
| 13883 | } |
| 13884 | |
| 13885 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 13886 | * Creates a string of whitespaces used for indentation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13887 | * |
| 13888 | * @param depth the indentation level |
| 13889 | * @return a String containing (depth * 2 + 3) * 2 white spaces |
| 13890 | * |
| 13891 | * @hide |
| 13892 | */ |
| 13893 | protected static String debugIndent(int depth) { |
| 13894 | StringBuilder spaces = new StringBuilder((depth * 2 + 3) * 2); |
| 13895 | for (int i = 0; i < (depth * 2) + 3; i++) { |
| 13896 | spaces.append(' ').append(' '); |
| 13897 | } |
| 13898 | return spaces.toString(); |
| 13899 | } |
| 13900 | |
| 13901 | /** |
| 13902 | * <p>Return the offset of the widget's text baseline from the widget's top |
| 13903 | * boundary. If this widget does not support baseline alignment, this |
| 13904 | * method returns -1. </p> |
| 13905 | * |
| 13906 | * @return the offset of the baseline within the widget's bounds or -1 |
| 13907 | * if baseline alignment is not supported |
| 13908 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 13909 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13910 | public int getBaseline() { |
| 13911 | return -1; |
| 13912 | } |
| 13913 | |
| 13914 | /** |
| 13915 | * Call this when something has changed which has invalidated the |
| 13916 | * layout of this view. This will schedule a layout pass of the view |
| 13917 | * tree. |
| 13918 | */ |
| 13919 | public void requestLayout() { |
| 13920 | if (ViewDebug.TRACE_HIERARCHY) { |
| 13921 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.REQUEST_LAYOUT); |
| 13922 | } |
| 13923 | |
| 13924 | mPrivateFlags |= FORCE_LAYOUT; |
Chet Haase | 5af048c | 2011-01-24 17:00:32 -0800 | [diff] [blame] | 13925 | mPrivateFlags |= INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13926 | |
Fabrice Di Meglio | 4a526885 | 2012-03-30 15:56:48 -0700 | [diff] [blame] | 13927 | if (mLayoutParams != null) { |
| 13928 | mLayoutParams.onResolveLayoutDirection(getResolvedLayoutDirection()); |
| 13929 | } |
| 13930 | |
| 13931 | if (mParent != null && !mParent.isLayoutRequested()) { |
| 13932 | mParent.requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13933 | } |
| 13934 | } |
| 13935 | |
| 13936 | /** |
| 13937 | * Forces this view to be laid out during the next layout pass. |
| 13938 | * This method does not call requestLayout() or forceLayout() |
| 13939 | * on the parent. |
| 13940 | */ |
| 13941 | public void forceLayout() { |
| 13942 | mPrivateFlags |= FORCE_LAYOUT; |
Chet Haase | 5af048c | 2011-01-24 17:00:32 -0800 | [diff] [blame] | 13943 | mPrivateFlags |= INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13944 | } |
| 13945 | |
| 13946 | /** |
| 13947 | * <p> |
| 13948 | * This is called to find out how big a view should be. The parent |
| 13949 | * supplies constraint information in the width and height parameters. |
| 13950 | * </p> |
| 13951 | * |
| 13952 | * <p> |
Romain Guy | 967e2bf | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 13953 | * 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] | 13954 | * {@link #onMeasure(int, int)}, called by this method. Therefore, only |
Romain Guy | 967e2bf | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 13955 | * {@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] | 13956 | * </p> |
| 13957 | * |
| 13958 | * |
| 13959 | * @param widthMeasureSpec Horizontal space requirements as imposed by the |
| 13960 | * parent |
| 13961 | * @param heightMeasureSpec Vertical space requirements as imposed by the |
| 13962 | * parent |
| 13963 | * |
| 13964 | * @see #onMeasure(int, int) |
| 13965 | */ |
| 13966 | public final void measure(int widthMeasureSpec, int heightMeasureSpec) { |
| 13967 | if ((mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT || |
| 13968 | widthMeasureSpec != mOldWidthMeasureSpec || |
| 13969 | heightMeasureSpec != mOldHeightMeasureSpec) { |
| 13970 | |
| 13971 | // first clears the measured dimension flag |
| 13972 | mPrivateFlags &= ~MEASURED_DIMENSION_SET; |
| 13973 | |
| 13974 | if (ViewDebug.TRACE_HIERARCHY) { |
| 13975 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_MEASURE); |
| 13976 | } |
| 13977 | |
| 13978 | // measure ourselves, this should set the measured dimension flag back |
| 13979 | onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 13980 | |
| 13981 | // flag not set, setMeasuredDimension() was not invoked, we raise |
| 13982 | // an exception to warn the developer |
| 13983 | if ((mPrivateFlags & MEASURED_DIMENSION_SET) != MEASURED_DIMENSION_SET) { |
| 13984 | throw new IllegalStateException("onMeasure() did not set the" |
| 13985 | + " measured dimension by calling" |
| 13986 | + " setMeasuredDimension()"); |
| 13987 | } |
| 13988 | |
| 13989 | mPrivateFlags |= LAYOUT_REQUIRED; |
| 13990 | } |
| 13991 | |
| 13992 | mOldWidthMeasureSpec = widthMeasureSpec; |
| 13993 | mOldHeightMeasureSpec = heightMeasureSpec; |
| 13994 | } |
| 13995 | |
| 13996 | /** |
| 13997 | * <p> |
| 13998 | * Measure the view and its content to determine the measured width and the |
| 13999 | * measured height. This method is invoked by {@link #measure(int, int)} and |
| 14000 | * should be overriden by subclasses to provide accurate and efficient |
| 14001 | * measurement of their contents. |
| 14002 | * </p> |
| 14003 | * |
| 14004 | * <p> |
| 14005 | * <strong>CONTRACT:</strong> When overriding this method, you |
| 14006 | * <em>must</em> call {@link #setMeasuredDimension(int, int)} to store the |
| 14007 | * measured width and height of this view. Failure to do so will trigger an |
| 14008 | * <code>IllegalStateException</code>, thrown by |
| 14009 | * {@link #measure(int, int)}. Calling the superclass' |
| 14010 | * {@link #onMeasure(int, int)} is a valid use. |
| 14011 | * </p> |
| 14012 | * |
| 14013 | * <p> |
| 14014 | * The base class implementation of measure defaults to the background size, |
| 14015 | * unless a larger size is allowed by the MeasureSpec. Subclasses should |
| 14016 | * override {@link #onMeasure(int, int)} to provide better measurements of |
| 14017 | * their content. |
| 14018 | * </p> |
| 14019 | * |
| 14020 | * <p> |
| 14021 | * If this method is overridden, it is the subclass's responsibility to make |
| 14022 | * sure the measured height and width are at least the view's minimum height |
| 14023 | * and width ({@link #getSuggestedMinimumHeight()} and |
| 14024 | * {@link #getSuggestedMinimumWidth()}). |
| 14025 | * </p> |
| 14026 | * |
| 14027 | * @param widthMeasureSpec horizontal space requirements as imposed by the parent. |
| 14028 | * The requirements are encoded with |
| 14029 | * {@link android.view.View.MeasureSpec}. |
| 14030 | * @param heightMeasureSpec vertical space requirements as imposed by the parent. |
| 14031 | * The requirements are encoded with |
| 14032 | * {@link android.view.View.MeasureSpec}. |
| 14033 | * |
| 14034 | * @see #getMeasuredWidth() |
| 14035 | * @see #getMeasuredHeight() |
| 14036 | * @see #setMeasuredDimension(int, int) |
| 14037 | * @see #getSuggestedMinimumHeight() |
| 14038 | * @see #getSuggestedMinimumWidth() |
| 14039 | * @see android.view.View.MeasureSpec#getMode(int) |
| 14040 | * @see android.view.View.MeasureSpec#getSize(int) |
| 14041 | */ |
| 14042 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 14043 | setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), |
| 14044 | getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec)); |
| 14045 | } |
| 14046 | |
| 14047 | /** |
| 14048 | * <p>This mehod must be called by {@link #onMeasure(int, int)} to store the |
| 14049 | * measured width and measured height. Failing to do so will trigger an |
| 14050 | * exception at measurement time.</p> |
| 14051 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14052 | * @param measuredWidth The measured width of this view. May be a complex |
| 14053 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 14054 | * {@link #MEASURED_STATE_TOO_SMALL}. |
| 14055 | * @param measuredHeight The measured height of this view. May be a complex |
| 14056 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 14057 | * {@link #MEASURED_STATE_TOO_SMALL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14058 | */ |
| 14059 | protected final void setMeasuredDimension(int measuredWidth, int measuredHeight) { |
| 14060 | mMeasuredWidth = measuredWidth; |
| 14061 | mMeasuredHeight = measuredHeight; |
| 14062 | |
| 14063 | mPrivateFlags |= MEASURED_DIMENSION_SET; |
| 14064 | } |
| 14065 | |
| 14066 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14067 | * Merge two states as returned by {@link #getMeasuredState()}. |
| 14068 | * @param curState The current state as returned from a view or the result |
| 14069 | * of combining multiple views. |
| 14070 | * @param newState The new view state to combine. |
| 14071 | * @return Returns a new integer reflecting the combination of the two |
| 14072 | * states. |
| 14073 | */ |
| 14074 | public static int combineMeasuredStates(int curState, int newState) { |
| 14075 | return curState | newState; |
| 14076 | } |
| 14077 | |
| 14078 | /** |
| 14079 | * Version of {@link #resolveSizeAndState(int, int, int)} |
| 14080 | * returning only the {@link #MEASURED_SIZE_MASK} bits of the result. |
| 14081 | */ |
| 14082 | public static int resolveSize(int size, int measureSpec) { |
| 14083 | return resolveSizeAndState(size, measureSpec, 0) & MEASURED_SIZE_MASK; |
| 14084 | } |
| 14085 | |
| 14086 | /** |
| 14087 | * Utility to reconcile a desired size and state, with constraints imposed |
| 14088 | * by a MeasureSpec. Will take the desired size, unless a different size |
| 14089 | * is imposed by the constraints. The returned value is a compound integer, |
| 14090 | * with the resolved size in the {@link #MEASURED_SIZE_MASK} bits and |
| 14091 | * optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the resulting |
| 14092 | * 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] | 14093 | * |
| 14094 | * @param size How big the view wants to be |
| 14095 | * @param measureSpec Constraints imposed by the parent |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14096 | * @return Size information bit mask as defined by |
| 14097 | * {@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] | 14098 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14099 | 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] | 14100 | int result = size; |
| 14101 | int specMode = MeasureSpec.getMode(measureSpec); |
| 14102 | int specSize = MeasureSpec.getSize(measureSpec); |
| 14103 | switch (specMode) { |
| 14104 | case MeasureSpec.UNSPECIFIED: |
| 14105 | result = size; |
| 14106 | break; |
| 14107 | case MeasureSpec.AT_MOST: |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14108 | if (specSize < size) { |
| 14109 | result = specSize | MEASURED_STATE_TOO_SMALL; |
| 14110 | } else { |
| 14111 | result = size; |
| 14112 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14113 | break; |
| 14114 | case MeasureSpec.EXACTLY: |
| 14115 | result = specSize; |
| 14116 | break; |
| 14117 | } |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14118 | return result | (childMeasuredState&MEASURED_STATE_MASK); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14119 | } |
| 14120 | |
| 14121 | /** |
| 14122 | * Utility to return a default size. Uses the supplied size if the |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 14123 | * MeasureSpec imposed no constraints. Will get larger if allowed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14124 | * by the MeasureSpec. |
| 14125 | * |
| 14126 | * @param size Default size for this view |
| 14127 | * @param measureSpec Constraints imposed by the parent |
| 14128 | * @return The size this view should be. |
| 14129 | */ |
| 14130 | public static int getDefaultSize(int size, int measureSpec) { |
| 14131 | int result = size; |
| 14132 | int specMode = MeasureSpec.getMode(measureSpec); |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 14133 | int specSize = MeasureSpec.getSize(measureSpec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14134 | |
| 14135 | switch (specMode) { |
| 14136 | case MeasureSpec.UNSPECIFIED: |
| 14137 | result = size; |
| 14138 | break; |
| 14139 | case MeasureSpec.AT_MOST: |
| 14140 | case MeasureSpec.EXACTLY: |
| 14141 | result = specSize; |
| 14142 | break; |
| 14143 | } |
| 14144 | return result; |
| 14145 | } |
| 14146 | |
| 14147 | /** |
| 14148 | * Returns the suggested minimum height that the view should use. This |
| 14149 | * returns the maximum of the view's minimum height |
| 14150 | * and the background's minimum height |
| 14151 | * ({@link android.graphics.drawable.Drawable#getMinimumHeight()}). |
| 14152 | * <p> |
| 14153 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 14154 | * ensure the returned height is within the requirements of the parent. |
| 14155 | * |
| 14156 | * @return The suggested minimum height of the view. |
| 14157 | */ |
| 14158 | protected int getSuggestedMinimumHeight() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14159 | return (mBackground == null) ? mMinHeight : max(mMinHeight, mBackground.getMinimumHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14160 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14161 | } |
| 14162 | |
| 14163 | /** |
| 14164 | * Returns the suggested minimum width that the view should use. This |
| 14165 | * returns the maximum of the view's minimum width) |
| 14166 | * and the background's minimum width |
| 14167 | * ({@link android.graphics.drawable.Drawable#getMinimumWidth()}). |
| 14168 | * <p> |
| 14169 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 14170 | * ensure the returned width is within the requirements of the parent. |
| 14171 | * |
| 14172 | * @return The suggested minimum width of the view. |
| 14173 | */ |
| 14174 | protected int getSuggestedMinimumWidth() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14175 | return (mBackground == null) ? mMinWidth : max(mMinWidth, mBackground.getMinimumWidth()); |
| 14176 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14177 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14178 | /** |
| 14179 | * Returns the minimum height of the view. |
| 14180 | * |
| 14181 | * @return the minimum height the view will try to be. |
| 14182 | * |
| 14183 | * @see #setMinimumHeight(int) |
| 14184 | * |
| 14185 | * @attr ref android.R.styleable#View_minHeight |
| 14186 | */ |
| 14187 | public int getMinimumHeight() { |
| 14188 | return mMinHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14189 | } |
| 14190 | |
| 14191 | /** |
| 14192 | * Sets the minimum height of the view. It is not guaranteed the view will |
| 14193 | * be able to achieve this minimum height (for example, if its parent layout |
| 14194 | * constrains it with less available height). |
| 14195 | * |
| 14196 | * @param minHeight The minimum height the view will try to be. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14197 | * |
| 14198 | * @see #getMinimumHeight() |
| 14199 | * |
| 14200 | * @attr ref android.R.styleable#View_minHeight |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14201 | */ |
| 14202 | public void setMinimumHeight(int minHeight) { |
| 14203 | mMinHeight = minHeight; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14204 | requestLayout(); |
| 14205 | } |
| 14206 | |
| 14207 | /** |
| 14208 | * Returns the minimum width of the view. |
| 14209 | * |
| 14210 | * @return the minimum width the view will try to be. |
| 14211 | * |
| 14212 | * @see #setMinimumWidth(int) |
| 14213 | * |
| 14214 | * @attr ref android.R.styleable#View_minWidth |
| 14215 | */ |
| 14216 | public int getMinimumWidth() { |
| 14217 | return mMinWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14218 | } |
| 14219 | |
| 14220 | /** |
| 14221 | * Sets the minimum width of the view. It is not guaranteed the view will |
| 14222 | * be able to achieve this minimum width (for example, if its parent layout |
| 14223 | * constrains it with less available width). |
| 14224 | * |
| 14225 | * @param minWidth The minimum width the view will try to be. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14226 | * |
| 14227 | * @see #getMinimumWidth() |
| 14228 | * |
| 14229 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14230 | */ |
| 14231 | public void setMinimumWidth(int minWidth) { |
| 14232 | mMinWidth = minWidth; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14233 | requestLayout(); |
| 14234 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14235 | } |
| 14236 | |
| 14237 | /** |
| 14238 | * Get the animation currently associated with this view. |
| 14239 | * |
| 14240 | * @return The animation that is currently playing or |
| 14241 | * scheduled to play for this view. |
| 14242 | */ |
| 14243 | public Animation getAnimation() { |
| 14244 | return mCurrentAnimation; |
| 14245 | } |
| 14246 | |
| 14247 | /** |
| 14248 | * Start the specified animation now. |
| 14249 | * |
| 14250 | * @param animation the animation to start now |
| 14251 | */ |
| 14252 | public void startAnimation(Animation animation) { |
| 14253 | animation.setStartTime(Animation.START_ON_FIRST_FRAME); |
| 14254 | setAnimation(animation); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14255 | invalidateParentCaches(); |
| 14256 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14257 | } |
| 14258 | |
| 14259 | /** |
| 14260 | * Cancels any animations for this view. |
| 14261 | */ |
| 14262 | public void clearAnimation() { |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 14263 | if (mCurrentAnimation != null) { |
Romain Guy | b4a107d | 2010-02-09 18:50:08 -0800 | [diff] [blame] | 14264 | mCurrentAnimation.detach(); |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 14265 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14266 | mCurrentAnimation = null; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14267 | invalidateParentIfNeeded(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14268 | } |
| 14269 | |
| 14270 | /** |
| 14271 | * Sets the next animation to play for this view. |
| 14272 | * If you want the animation to play immediately, use |
| 14273 | * startAnimation. This method provides allows fine-grained |
| 14274 | * control over the start time and invalidation, but you |
| 14275 | * must make sure that 1) the animation has a start time set, and |
| 14276 | * 2) the view will be invalidated when the animation is supposed to |
| 14277 | * start. |
| 14278 | * |
| 14279 | * @param animation The next animation, or null. |
| 14280 | */ |
| 14281 | public void setAnimation(Animation animation) { |
| 14282 | mCurrentAnimation = animation; |
| 14283 | if (animation != null) { |
| 14284 | animation.reset(); |
| 14285 | } |
| 14286 | } |
| 14287 | |
| 14288 | /** |
| 14289 | * Invoked by a parent ViewGroup to notify the start of the animation |
| 14290 | * currently associated with this view. If you override this method, |
| 14291 | * always call super.onAnimationStart(); |
| 14292 | * |
| 14293 | * @see #setAnimation(android.view.animation.Animation) |
| 14294 | * @see #getAnimation() |
| 14295 | */ |
| 14296 | protected void onAnimationStart() { |
| 14297 | mPrivateFlags |= ANIMATION_STARTED; |
| 14298 | } |
| 14299 | |
| 14300 | /** |
| 14301 | * Invoked by a parent ViewGroup to notify the end of the animation |
| 14302 | * currently associated with this view. If you override this method, |
| 14303 | * always call super.onAnimationEnd(); |
| 14304 | * |
| 14305 | * @see #setAnimation(android.view.animation.Animation) |
| 14306 | * @see #getAnimation() |
| 14307 | */ |
| 14308 | protected void onAnimationEnd() { |
| 14309 | mPrivateFlags &= ~ANIMATION_STARTED; |
| 14310 | } |
| 14311 | |
| 14312 | /** |
| 14313 | * Invoked if there is a Transform that involves alpha. Subclass that can |
| 14314 | * draw themselves with the specified alpha should return true, and then |
| 14315 | * respect that alpha when their onDraw() is called. If this returns false |
| 14316 | * then the view may be redirected to draw into an offscreen buffer to |
| 14317 | * fulfill the request, which will look fine, but may be slower than if the |
| 14318 | * subclass handles it internally. The default implementation returns false. |
| 14319 | * |
| 14320 | * @param alpha The alpha (0..255) to apply to the view's drawing |
| 14321 | * @return true if the view can draw with the specified alpha. |
| 14322 | */ |
| 14323 | protected boolean onSetAlpha(int alpha) { |
| 14324 | return false; |
| 14325 | } |
| 14326 | |
| 14327 | /** |
| 14328 | * This is used by the RootView to perform an optimization when |
| 14329 | * the view hierarchy contains one or several SurfaceView. |
| 14330 | * SurfaceView is always considered transparent, but its children are not, |
| 14331 | * therefore all View objects remove themselves from the global transparent |
| 14332 | * region (passed as a parameter to this function). |
| 14333 | * |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 14334 | * @param region The transparent region for this ViewAncestor (window). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14335 | * |
| 14336 | * @return Returns true if the effective visibility of the view at this |
| 14337 | * point is opaque, regardless of the transparent region; returns false |
| 14338 | * if it is possible for underlying windows to be seen behind the view. |
| 14339 | * |
| 14340 | * {@hide} |
| 14341 | */ |
| 14342 | public boolean gatherTransparentRegion(Region region) { |
| 14343 | final AttachInfo attachInfo = mAttachInfo; |
| 14344 | if (region != null && attachInfo != null) { |
| 14345 | final int pflags = mPrivateFlags; |
| 14346 | if ((pflags & SKIP_DRAW) == 0) { |
| 14347 | // The SKIP_DRAW flag IS NOT set, so this view draws. We need to |
| 14348 | // remove it from the transparent region. |
| 14349 | final int[] location = attachInfo.mTransparentLocation; |
| 14350 | getLocationInWindow(location); |
| 14351 | region.op(location[0], location[1], location[0] + mRight - mLeft, |
| 14352 | location[1] + mBottom - mTop, Region.Op.DIFFERENCE); |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14353 | } else if ((pflags & ONLY_DRAWS_BACKGROUND) != 0 && mBackground != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14354 | // The ONLY_DRAWS_BACKGROUND flag IS set and the background drawable |
| 14355 | // exists, so we remove the background drawable's non-transparent |
| 14356 | // parts from this transparent region. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14357 | applyDrawableToTransparentRegion(mBackground, region); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14358 | } |
| 14359 | } |
| 14360 | return true; |
| 14361 | } |
| 14362 | |
| 14363 | /** |
| 14364 | * Play a sound effect for this view. |
| 14365 | * |
| 14366 | * <p>The framework will play sound effects for some built in actions, such as |
| 14367 | * clicking, but you may wish to play these effects in your widget, |
| 14368 | * for instance, for internal navigation. |
| 14369 | * |
| 14370 | * <p>The sound effect will only be played if sound effects are enabled by the user, and |
| 14371 | * {@link #isSoundEffectsEnabled()} is true. |
| 14372 | * |
| 14373 | * @param soundConstant One of the constants defined in {@link SoundEffectConstants} |
| 14374 | */ |
| 14375 | public void playSoundEffect(int soundConstant) { |
| 14376 | if (mAttachInfo == null || mAttachInfo.mRootCallbacks == null || !isSoundEffectsEnabled()) { |
| 14377 | return; |
| 14378 | } |
| 14379 | mAttachInfo.mRootCallbacks.playSoundEffect(soundConstant); |
| 14380 | } |
| 14381 | |
| 14382 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 14383 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14384 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 14385 | * <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] | 14386 | * |
| 14387 | * <p>The framework will provide haptic feedback for some built in actions, |
| 14388 | * such as long presses, but you may wish to provide feedback for your |
| 14389 | * own widget. |
| 14390 | * |
| 14391 | * <p>The feedback will only be performed if |
| 14392 | * {@link #isHapticFeedbackEnabled()} is true. |
| 14393 | * |
| 14394 | * @param feedbackConstant One of the constants defined in |
| 14395 | * {@link HapticFeedbackConstants} |
| 14396 | */ |
| 14397 | public boolean performHapticFeedback(int feedbackConstant) { |
| 14398 | return performHapticFeedback(feedbackConstant, 0); |
| 14399 | } |
| 14400 | |
| 14401 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 14402 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14403 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 14404 | * <p>Like {@link #performHapticFeedback(int)}, with additional options. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14405 | * |
| 14406 | * @param feedbackConstant One of the constants defined in |
| 14407 | * {@link HapticFeedbackConstants} |
| 14408 | * @param flags Additional flags as per {@link HapticFeedbackConstants}. |
| 14409 | */ |
| 14410 | public boolean performHapticFeedback(int feedbackConstant, int flags) { |
| 14411 | if (mAttachInfo == null) { |
| 14412 | return false; |
| 14413 | } |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 14414 | //noinspection SimplifiableIfStatement |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 14415 | if ((flags & HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING) == 0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14416 | && !isHapticFeedbackEnabled()) { |
| 14417 | return false; |
| 14418 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 14419 | return mAttachInfo.mRootCallbacks.performHapticFeedback(feedbackConstant, |
| 14420 | (flags & HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14421 | } |
| 14422 | |
| 14423 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14424 | * Request that the visibility of the status bar be changed. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 14425 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or |
| 14426 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14427 | */ |
| 14428 | public void setSystemUiVisibility(int visibility) { |
Daniel Sandler | 7052406 | 2011-09-21 00:30:47 -0400 | [diff] [blame] | 14429 | if (visibility != mSystemUiVisibility) { |
| 14430 | mSystemUiVisibility = visibility; |
| 14431 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 14432 | mParent.recomputeViewAttributes(this); |
| 14433 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14434 | } |
| 14435 | } |
| 14436 | |
| 14437 | /** |
| 14438 | * Returns the status bar visibility that this view has requested. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 14439 | * @return Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or |
| 14440 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14441 | */ |
Joe Onorato | e595cad | 2011-01-24 09:22:12 -0800 | [diff] [blame] | 14442 | public int getSystemUiVisibility() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14443 | return mSystemUiVisibility; |
| 14444 | } |
| 14445 | |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 14446 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 14447 | * Returns the current system UI visibility that is currently set for |
| 14448 | * the entire window. This is the combination of the |
| 14449 | * {@link #setSystemUiVisibility(int)} values supplied by all of the |
| 14450 | * views in the window. |
| 14451 | */ |
| 14452 | public int getWindowSystemUiVisibility() { |
| 14453 | return mAttachInfo != null ? mAttachInfo.mSystemUiVisibility : 0; |
| 14454 | } |
| 14455 | |
| 14456 | /** |
| 14457 | * Override to find out when the window's requested system UI visibility |
| 14458 | * has changed, that is the value returned by {@link #getWindowSystemUiVisibility()}. |
| 14459 | * This is different from the callbacks recieved through |
| 14460 | * {@link #setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener)} |
| 14461 | * in that this is only telling you about the local request of the window, |
| 14462 | * not the actual values applied by the system. |
| 14463 | */ |
| 14464 | public void onWindowSystemUiVisibilityChanged(int visible) { |
| 14465 | } |
| 14466 | |
| 14467 | /** |
| 14468 | * Dispatch callbacks to {@link #onWindowSystemUiVisibilityChanged(int)} down |
| 14469 | * the view hierarchy. |
| 14470 | */ |
| 14471 | public void dispatchWindowSystemUiVisiblityChanged(int visible) { |
| 14472 | onWindowSystemUiVisibilityChanged(visible); |
| 14473 | } |
| 14474 | |
| 14475 | /** |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 14476 | * Set a listener to receive callbacks when the visibility of the system bar changes. |
| 14477 | * @param l The {@link OnSystemUiVisibilityChangeListener} to receive callbacks. |
| 14478 | */ |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14479 | public void setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 14480 | getListenerInfo().mOnSystemUiVisibilityChangeListener = l; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14481 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 14482 | mParent.recomputeViewAttributes(this); |
| 14483 | } |
| 14484 | } |
| 14485 | |
| 14486 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 14487 | * Dispatch callbacks to {@link #setOnSystemUiVisibilityChangeListener} down |
| 14488 | * the view hierarchy. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14489 | */ |
| 14490 | public void dispatchSystemUiVisibilityChanged(int visibility) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 14491 | ListenerInfo li = mListenerInfo; |
| 14492 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
| 14493 | li.mOnSystemUiVisibilityChangeListener.onSystemUiVisibilityChange( |
Joe Onorato | 6ab77bd | 2011-01-31 11:21:10 -0800 | [diff] [blame] | 14494 | visibility & PUBLIC_STATUS_BAR_VISIBILITY_MASK); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14495 | } |
| 14496 | } |
| 14497 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 14498 | void updateLocalSystemUiVisibility(int localValue, int localChanges) { |
| 14499 | int val = (mSystemUiVisibility&~localChanges) | (localValue&localChanges); |
| 14500 | if (val != mSystemUiVisibility) { |
| 14501 | setSystemUiVisibility(val); |
| 14502 | } |
| 14503 | } |
| 14504 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14505 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14506 | * Creates an image that the system displays during the drag and drop |
| 14507 | * operation. This is called a "drag shadow". The default implementation |
| 14508 | * for a DragShadowBuilder based on a View returns an image that has exactly the same |
| 14509 | * appearance as the given View. The default also positions the center of the drag shadow |
| 14510 | * directly under the touch point. If no View is provided (the constructor with no parameters |
| 14511 | * is used), and {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} and |
| 14512 | * {@link #onDrawShadow(Canvas) onDrawShadow()} are not overriden, then the |
| 14513 | * default is an invisible drag shadow. |
| 14514 | * <p> |
| 14515 | * You are not required to use the View you provide to the constructor as the basis of the |
| 14516 | * drag shadow. The {@link #onDrawShadow(Canvas) onDrawShadow()} method allows you to draw |
| 14517 | * anything you want as the drag shadow. |
| 14518 | * </p> |
| 14519 | * <p> |
| 14520 | * You pass a DragShadowBuilder object to the system when you start the drag. The system |
| 14521 | * calls {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} to get the |
| 14522 | * size and position of the drag shadow. It uses this data to construct a |
| 14523 | * {@link android.graphics.Canvas} object, then it calls {@link #onDrawShadow(Canvas) onDrawShadow()} |
| 14524 | * so that your application can draw the shadow image in the Canvas. |
| 14525 | * </p> |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 14526 | * |
| 14527 | * <div class="special reference"> |
| 14528 | * <h3>Developer Guides</h3> |
| 14529 | * <p>For a guide to implementing drag and drop features, read the |
| 14530 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 14531 | * </div> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14532 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14533 | public static class DragShadowBuilder { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 14534 | private final WeakReference<View> mView; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14535 | |
| 14536 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14537 | * Constructs a shadow image builder based on a View. By default, the resulting drag |
| 14538 | * shadow will have the same appearance and dimensions as the View, with the touch point |
| 14539 | * over the center of the View. |
| 14540 | * @param view A View. Any View in scope can be used. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14541 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14542 | public DragShadowBuilder(View view) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 14543 | mView = new WeakReference<View>(view); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14544 | } |
| 14545 | |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 14546 | /** |
| 14547 | * Construct a shadow builder object with no associated View. This |
| 14548 | * constructor variant is only useful when the {@link #onProvideShadowMetrics(Point, Point)} |
| 14549 | * and {@link #onDrawShadow(Canvas)} methods are also overridden in order |
| 14550 | * to supply the drag shadow's dimensions and appearance without |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14551 | * reference to any View object. If they are not overridden, then the result is an |
| 14552 | * invisible drag shadow. |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 14553 | */ |
| 14554 | public DragShadowBuilder() { |
| 14555 | mView = new WeakReference<View>(null); |
| 14556 | } |
| 14557 | |
| 14558 | /** |
| 14559 | * Returns the View object that had been passed to the |
| 14560 | * {@link #View.DragShadowBuilder(View)} |
| 14561 | * constructor. If that View parameter was {@code null} or if the |
| 14562 | * {@link #View.DragShadowBuilder()} |
| 14563 | * constructor was used to instantiate the builder object, this method will return |
| 14564 | * null. |
| 14565 | * |
| 14566 | * @return The View object associate with this builder object. |
| 14567 | */ |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 14568 | @SuppressWarnings({"JavadocReference"}) |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 14569 | final public View getView() { |
| 14570 | return mView.get(); |
| 14571 | } |
| 14572 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14573 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14574 | * Provides the metrics for the shadow image. These include the dimensions of |
| 14575 | * the shadow image, and the point within that shadow that should |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14576 | * be centered under the touch location while dragging. |
| 14577 | * <p> |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14578 | * The default implementation sets the dimensions of the shadow to be the |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14579 | * same as the dimensions of the View itself and centers the shadow under |
| 14580 | * the touch point. |
| 14581 | * </p> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14582 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14583 | * @param shadowSize A {@link android.graphics.Point} containing the width and height |
| 14584 | * of the shadow image. Your application must set {@link android.graphics.Point#x} to the |
| 14585 | * desired width and must set {@link android.graphics.Point#y} to the desired height of the |
| 14586 | * image. |
| 14587 | * |
| 14588 | * @param shadowTouchPoint A {@link android.graphics.Point} for the position within the |
| 14589 | * shadow image that should be underneath the touch point during the drag and drop |
| 14590 | * operation. Your application must set {@link android.graphics.Point#x} to the |
| 14591 | * 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] | 14592 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14593 | public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 14594 | final View view = mView.get(); |
| 14595 | if (view != null) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14596 | shadowSize.set(view.getWidth(), view.getHeight()); |
| 14597 | shadowTouchPoint.set(shadowSize.x / 2, shadowSize.y / 2); |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 14598 | } else { |
| 14599 | Log.e(View.VIEW_LOG_TAG, "Asked for drag thumb metrics but no view"); |
| 14600 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14601 | } |
| 14602 | |
| 14603 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14604 | * Draws the shadow image. The system creates the {@link android.graphics.Canvas} object |
| 14605 | * based on the dimensions it received from the |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14606 | * {@link #onProvideShadowMetrics(Point, Point)} callback. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14607 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14608 | * @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] | 14609 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14610 | public void onDrawShadow(Canvas canvas) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 14611 | final View view = mView.get(); |
| 14612 | if (view != null) { |
| 14613 | view.draw(canvas); |
| 14614 | } else { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14615 | 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] | 14616 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14617 | } |
| 14618 | } |
| 14619 | |
| 14620 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14621 | * Starts a drag and drop operation. When your application calls this method, it passes a |
| 14622 | * {@link android.view.View.DragShadowBuilder} object to the system. The |
| 14623 | * system calls this object's {@link DragShadowBuilder#onProvideShadowMetrics(Point, Point)} |
| 14624 | * to get metrics for the drag shadow, and then calls the object's |
| 14625 | * {@link DragShadowBuilder#onDrawShadow(Canvas)} to draw the drag shadow itself. |
| 14626 | * <p> |
| 14627 | * Once the system has the drag shadow, it begins the drag and drop operation by sending |
| 14628 | * drag events to all the View objects in your application that are currently visible. It does |
| 14629 | * this either by calling the View object's drag listener (an implementation of |
| 14630 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent) onDrag()} or by calling the |
| 14631 | * View object's {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} method. |
| 14632 | * Both are passed a {@link android.view.DragEvent} object that has a |
| 14633 | * {@link android.view.DragEvent#getAction()} value of |
| 14634 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED}. |
| 14635 | * </p> |
| 14636 | * <p> |
| 14637 | * Your application can invoke startDrag() on any attached View object. The View object does not |
| 14638 | * need to be the one used in {@link android.view.View.DragShadowBuilder}, nor does it need to |
| 14639 | * be related to the View the user selected for dragging. |
| 14640 | * </p> |
| 14641 | * @param data A {@link android.content.ClipData} object pointing to the data to be |
| 14642 | * transferred by the drag and drop operation. |
| 14643 | * @param shadowBuilder A {@link android.view.View.DragShadowBuilder} object for building the |
| 14644 | * drag shadow. |
| 14645 | * @param myLocalState An {@link java.lang.Object} containing local data about the drag and |
| 14646 | * drop operation. This Object is put into every DragEvent object sent by the system during the |
| 14647 | * current drag. |
| 14648 | * <p> |
| 14649 | * myLocalState is a lightweight mechanism for the sending information from the dragged View |
| 14650 | * to the target Views. For example, it can contain flags that differentiate between a |
| 14651 | * a copy operation and a move operation. |
| 14652 | * </p> |
| 14653 | * @param flags Flags that control the drag and drop operation. No flags are currently defined, |
| 14654 | * so the parameter should be set to 0. |
| 14655 | * @return {@code true} if the method completes successfully, or |
| 14656 | * {@code false} if it fails anywhere. Returning {@code false} means the system was unable to |
| 14657 | * do a drag, and so no drag operation is in progress. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14658 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14659 | public final boolean startDrag(ClipData data, DragShadowBuilder shadowBuilder, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 14660 | Object myLocalState, int flags) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14661 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 14662 | Log.d(VIEW_LOG_TAG, "startDrag: data=" + data + " flags=" + flags); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14663 | } |
| 14664 | boolean okay = false; |
| 14665 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14666 | Point shadowSize = new Point(); |
| 14667 | Point shadowTouchPoint = new Point(); |
| 14668 | shadowBuilder.onProvideShadowMetrics(shadowSize, shadowTouchPoint); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14669 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14670 | if ((shadowSize.x < 0) || (shadowSize.y < 0) || |
| 14671 | (shadowTouchPoint.x < 0) || (shadowTouchPoint.y < 0)) { |
| 14672 | throw new IllegalStateException("Drag shadow dimensions must not be negative"); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14673 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14674 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 14675 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14676 | Log.d(VIEW_LOG_TAG, "drag shadow: width=" + shadowSize.x + " height=" + shadowSize.y |
| 14677 | + " shadowX=" + shadowTouchPoint.x + " shadowY=" + shadowTouchPoint.y); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 14678 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14679 | Surface surface = new Surface(); |
| 14680 | try { |
| 14681 | IBinder token = mAttachInfo.mSession.prepareDrag(mAttachInfo.mWindow, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 14682 | flags, shadowSize.x, shadowSize.y, surface); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14683 | 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] | 14684 | + " surface=" + surface); |
| 14685 | if (token != null) { |
| 14686 | Canvas canvas = surface.lockCanvas(null); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 14687 | try { |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 14688 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14689 | shadowBuilder.onDrawShadow(canvas); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 14690 | } finally { |
| 14691 | surface.unlockCanvasAndPost(canvas); |
| 14692 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14693 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 14694 | final ViewRootImpl root = getViewRootImpl(); |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 14695 | |
| 14696 | // Cache the local state object for delivery with DragEvents |
| 14697 | root.setLocalDragState(myLocalState); |
| 14698 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14699 | // repurpose 'shadowSize' for the last touch point |
| 14700 | root.getLastTouchPoint(shadowSize); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14701 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14702 | okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, token, |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 14703 | shadowSize.x, shadowSize.y, |
| 14704 | shadowTouchPoint.x, shadowTouchPoint.y, data); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 14705 | if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "performDrag returned " + okay); |
Christopher Tate | 8f73b5d | 2011-09-12 15:22:12 -0700 | [diff] [blame] | 14706 | |
| 14707 | // Off and running! Release our local surface instance; the drag |
| 14708 | // shadow surface is now managed by the system process. |
| 14709 | surface.release(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14710 | } |
| 14711 | } catch (Exception e) { |
| 14712 | Log.e(VIEW_LOG_TAG, "Unable to initiate drag", e); |
| 14713 | surface.destroy(); |
| 14714 | } |
| 14715 | |
| 14716 | return okay; |
| 14717 | } |
| 14718 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14719 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14720 | * Handles drag events sent by the system following a call to |
| 14721 | * {@link android.view.View#startDrag(ClipData,DragShadowBuilder,Object,int) startDrag()}. |
| 14722 | *<p> |
| 14723 | * When the system calls this method, it passes a |
| 14724 | * {@link android.view.DragEvent} object. A call to |
| 14725 | * {@link android.view.DragEvent#getAction()} returns one of the action type constants defined |
| 14726 | * in DragEvent. The method uses these to determine what is happening in the drag and drop |
| 14727 | * operation. |
| 14728 | * @param event The {@link android.view.DragEvent} sent by the system. |
| 14729 | * The {@link android.view.DragEvent#getAction()} method returns an action type constant defined |
| 14730 | * in DragEvent, indicating the type of drag event represented by this object. |
| 14731 | * @return {@code true} if the method was successful, otherwise {@code false}. |
| 14732 | * <p> |
| 14733 | * The method should return {@code true} in response to an action type of |
| 14734 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED} to receive drag events for the current |
| 14735 | * operation. |
| 14736 | * </p> |
| 14737 | * <p> |
| 14738 | * The method should also return {@code true} in response to an action type of |
| 14739 | * {@link android.view.DragEvent#ACTION_DROP} if it consumed the drop, or |
| 14740 | * {@code false} if it didn't. |
| 14741 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14742 | */ |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 14743 | public boolean onDragEvent(DragEvent event) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14744 | return false; |
| 14745 | } |
| 14746 | |
| 14747 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14748 | * Detects if this View is enabled and has a drag event listener. |
| 14749 | * If both are true, then it calls the drag event listener with the |
| 14750 | * {@link android.view.DragEvent} it received. If the drag event listener returns |
| 14751 | * {@code true}, then dispatchDragEvent() returns {@code true}. |
| 14752 | * <p> |
| 14753 | * For all other cases, the method calls the |
| 14754 | * {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} drag event handler |
| 14755 | * method and returns its result. |
| 14756 | * </p> |
| 14757 | * <p> |
| 14758 | * This ensures that a drag event is always consumed, even if the View does not have a drag |
| 14759 | * event listener. However, if the View has a listener and the listener returns true, then |
| 14760 | * onDragEvent() is not called. |
| 14761 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14762 | */ |
| 14763 | public boolean dispatchDragEvent(DragEvent event) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 14764 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 14765 | ListenerInfo li = mListenerInfo; |
| 14766 | if (li != null && li.mOnDragListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 14767 | && li.mOnDragListener.onDrag(this, event)) { |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 14768 | return true; |
| 14769 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14770 | return onDragEvent(event); |
| 14771 | } |
| 14772 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 14773 | boolean canAcceptDrag() { |
| 14774 | return (mPrivateFlags2 & DRAG_CAN_ACCEPT) != 0; |
| 14775 | } |
| 14776 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 14777 | /** |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 14778 | * This needs to be a better API (NOT ON VIEW) before it is exposed. If |
| 14779 | * it is ever exposed at all. |
Dianne Hackborn | 29e4a3c | 2009-09-30 22:35:40 -0700 | [diff] [blame] | 14780 | * @hide |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 14781 | */ |
| 14782 | public void onCloseSystemDialogs(String reason) { |
| 14783 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14784 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 14785 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14786 | * 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] | 14787 | * update a Region being computed for |
| 14788 | * {@link #gatherTransparentRegion(android.graphics.Region)} so |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14789 | * that any non-transparent parts of the Drawable are removed from the |
| 14790 | * given transparent region. |
| 14791 | * |
| 14792 | * @param dr The Drawable whose transparency is to be applied to the region. |
| 14793 | * @param region A Region holding the current transparency information, |
| 14794 | * where any parts of the region that are set are considered to be |
| 14795 | * transparent. On return, this region will be modified to have the |
| 14796 | * transparency information reduced by the corresponding parts of the |
| 14797 | * Drawable that are not transparent. |
| 14798 | * {@hide} |
| 14799 | */ |
| 14800 | public void applyDrawableToTransparentRegion(Drawable dr, Region region) { |
| 14801 | if (DBG) { |
| 14802 | Log.i("View", "Getting transparent region for: " + this); |
| 14803 | } |
| 14804 | final Region r = dr.getTransparentRegion(); |
| 14805 | final Rect db = dr.getBounds(); |
| 14806 | final AttachInfo attachInfo = mAttachInfo; |
| 14807 | if (r != null && attachInfo != null) { |
| 14808 | final int w = getRight()-getLeft(); |
| 14809 | final int h = getBottom()-getTop(); |
| 14810 | if (db.left > 0) { |
| 14811 | //Log.i("VIEW", "Drawable left " + db.left + " > view 0"); |
| 14812 | r.op(0, 0, db.left, h, Region.Op.UNION); |
| 14813 | } |
| 14814 | if (db.right < w) { |
| 14815 | //Log.i("VIEW", "Drawable right " + db.right + " < view " + w); |
| 14816 | r.op(db.right, 0, w, h, Region.Op.UNION); |
| 14817 | } |
| 14818 | if (db.top > 0) { |
| 14819 | //Log.i("VIEW", "Drawable top " + db.top + " > view 0"); |
| 14820 | r.op(0, 0, w, db.top, Region.Op.UNION); |
| 14821 | } |
| 14822 | if (db.bottom < h) { |
| 14823 | //Log.i("VIEW", "Drawable bottom " + db.bottom + " < view " + h); |
| 14824 | r.op(0, db.bottom, w, h, Region.Op.UNION); |
| 14825 | } |
| 14826 | final int[] location = attachInfo.mTransparentLocation; |
| 14827 | getLocationInWindow(location); |
| 14828 | r.translate(location[0], location[1]); |
| 14829 | region.op(r, Region.Op.INTERSECT); |
| 14830 | } else { |
| 14831 | region.op(db, Region.Op.DIFFERENCE); |
| 14832 | } |
| 14833 | } |
| 14834 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 14835 | private void checkForLongClick(int delayOffset) { |
| 14836 | if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) { |
| 14837 | mHasPerformedLongPress = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14838 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 14839 | if (mPendingCheckForLongPress == null) { |
| 14840 | mPendingCheckForLongPress = new CheckForLongPress(); |
| 14841 | } |
| 14842 | mPendingCheckForLongPress.rememberWindowAttachCount(); |
| 14843 | postDelayed(mPendingCheckForLongPress, |
| 14844 | ViewConfiguration.getLongPressTimeout() - delayOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14845 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14846 | } |
| 14847 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14848 | /** |
| 14849 | * Inflate a view from an XML resource. This convenience method wraps the {@link |
| 14850 | * LayoutInflater} class, which provides a full range of options for view inflation. |
| 14851 | * |
| 14852 | * @param context The Context object for your activity or application. |
| 14853 | * @param resource The resource ID to inflate |
| 14854 | * @param root A view group that will be the parent. Used to properly inflate the |
| 14855 | * layout_* parameters. |
| 14856 | * @see LayoutInflater |
| 14857 | */ |
| 14858 | public static View inflate(Context context, int resource, ViewGroup root) { |
| 14859 | LayoutInflater factory = LayoutInflater.from(context); |
| 14860 | return factory.inflate(resource, root); |
| 14861 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 14862 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14863 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 14864 | * Scroll the view with standard behavior for scrolling beyond the normal |
| 14865 | * content boundaries. Views that call this method should override |
| 14866 | * {@link #onOverScrolled(int, int, boolean, boolean)} to respond to the |
| 14867 | * results of an over-scroll operation. |
| 14868 | * |
| 14869 | * Views can use this method to handle any touch or fling-based scrolling. |
| 14870 | * |
| 14871 | * @param deltaX Change in X in pixels |
| 14872 | * @param deltaY Change in Y in pixels |
| 14873 | * @param scrollX Current X scroll value in pixels before applying deltaX |
| 14874 | * @param scrollY Current Y scroll value in pixels before applying deltaY |
| 14875 | * @param scrollRangeX Maximum content scroll range along the X axis |
| 14876 | * @param scrollRangeY Maximum content scroll range along the Y axis |
| 14877 | * @param maxOverScrollX Number of pixels to overscroll by in either direction |
| 14878 | * along the X axis. |
| 14879 | * @param maxOverScrollY Number of pixels to overscroll by in either direction |
| 14880 | * along the Y axis. |
| 14881 | * @param isTouchEvent true if this scroll operation is the result of a touch event. |
| 14882 | * @return true if scrolling was clamped to an over-scroll boundary along either |
| 14883 | * axis, false otherwise. |
| 14884 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 14885 | @SuppressWarnings({"UnusedParameters"}) |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 14886 | protected boolean overScrollBy(int deltaX, int deltaY, |
| 14887 | int scrollX, int scrollY, |
| 14888 | int scrollRangeX, int scrollRangeY, |
| 14889 | int maxOverScrollX, int maxOverScrollY, |
| 14890 | boolean isTouchEvent) { |
| 14891 | final int overScrollMode = mOverScrollMode; |
| 14892 | final boolean canScrollHorizontal = |
| 14893 | computeHorizontalScrollRange() > computeHorizontalScrollExtent(); |
| 14894 | final boolean canScrollVertical = |
| 14895 | computeVerticalScrollRange() > computeVerticalScrollExtent(); |
| 14896 | final boolean overScrollHorizontal = overScrollMode == OVER_SCROLL_ALWAYS || |
| 14897 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollHorizontal); |
| 14898 | final boolean overScrollVertical = overScrollMode == OVER_SCROLL_ALWAYS || |
| 14899 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollVertical); |
| 14900 | |
| 14901 | int newScrollX = scrollX + deltaX; |
| 14902 | if (!overScrollHorizontal) { |
| 14903 | maxOverScrollX = 0; |
| 14904 | } |
| 14905 | |
| 14906 | int newScrollY = scrollY + deltaY; |
| 14907 | if (!overScrollVertical) { |
| 14908 | maxOverScrollY = 0; |
| 14909 | } |
| 14910 | |
| 14911 | // Clamp values if at the limits and record |
| 14912 | final int left = -maxOverScrollX; |
| 14913 | final int right = maxOverScrollX + scrollRangeX; |
| 14914 | final int top = -maxOverScrollY; |
| 14915 | final int bottom = maxOverScrollY + scrollRangeY; |
| 14916 | |
| 14917 | boolean clampedX = false; |
| 14918 | if (newScrollX > right) { |
| 14919 | newScrollX = right; |
| 14920 | clampedX = true; |
| 14921 | } else if (newScrollX < left) { |
| 14922 | newScrollX = left; |
| 14923 | clampedX = true; |
| 14924 | } |
| 14925 | |
| 14926 | boolean clampedY = false; |
| 14927 | if (newScrollY > bottom) { |
| 14928 | newScrollY = bottom; |
| 14929 | clampedY = true; |
| 14930 | } else if (newScrollY < top) { |
| 14931 | newScrollY = top; |
| 14932 | clampedY = true; |
| 14933 | } |
| 14934 | |
| 14935 | onOverScrolled(newScrollX, newScrollY, clampedX, clampedY); |
| 14936 | |
| 14937 | return clampedX || clampedY; |
| 14938 | } |
| 14939 | |
| 14940 | /** |
| 14941 | * Called by {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)} to |
| 14942 | * respond to the results of an over-scroll operation. |
| 14943 | * |
| 14944 | * @param scrollX New X scroll value in pixels |
| 14945 | * @param scrollY New Y scroll value in pixels |
| 14946 | * @param clampedX True if scrollX was clamped to an over-scroll boundary |
| 14947 | * @param clampedY True if scrollY was clamped to an over-scroll boundary |
| 14948 | */ |
| 14949 | protected void onOverScrolled(int scrollX, int scrollY, |
| 14950 | boolean clampedX, boolean clampedY) { |
| 14951 | // Intentionally empty. |
| 14952 | } |
| 14953 | |
| 14954 | /** |
| 14955 | * Returns the over-scroll mode for this view. The result will be |
| 14956 | * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 14957 | * (allow over-scrolling only if the view content is larger than the container), |
| 14958 | * or {@link #OVER_SCROLL_NEVER}. |
| 14959 | * |
| 14960 | * @return This view's over-scroll mode. |
| 14961 | */ |
| 14962 | public int getOverScrollMode() { |
| 14963 | return mOverScrollMode; |
| 14964 | } |
| 14965 | |
| 14966 | /** |
| 14967 | * Set the over-scroll mode for this view. Valid over-scroll modes are |
| 14968 | * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 14969 | * (allow over-scrolling only if the view content is larger than the container), |
| 14970 | * or {@link #OVER_SCROLL_NEVER}. |
| 14971 | * |
| 14972 | * Setting the over-scroll mode of a view will have an effect only if the |
| 14973 | * view is capable of scrolling. |
| 14974 | * |
| 14975 | * @param overScrollMode The new over-scroll mode for this view. |
| 14976 | */ |
| 14977 | public void setOverScrollMode(int overScrollMode) { |
| 14978 | if (overScrollMode != OVER_SCROLL_ALWAYS && |
| 14979 | overScrollMode != OVER_SCROLL_IF_CONTENT_SCROLLS && |
| 14980 | overScrollMode != OVER_SCROLL_NEVER) { |
| 14981 | throw new IllegalArgumentException("Invalid overscroll mode " + overScrollMode); |
| 14982 | } |
| 14983 | mOverScrollMode = overScrollMode; |
| 14984 | } |
| 14985 | |
| 14986 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 14987 | * Gets a scale factor that determines the distance the view should scroll |
| 14988 | * vertically in response to {@link MotionEvent#ACTION_SCROLL}. |
| 14989 | * @return The vertical scroll scale factor. |
| 14990 | * @hide |
| 14991 | */ |
| 14992 | protected float getVerticalScrollFactor() { |
| 14993 | if (mVerticalScrollFactor == 0) { |
| 14994 | TypedValue outValue = new TypedValue(); |
| 14995 | if (!mContext.getTheme().resolveAttribute( |
| 14996 | com.android.internal.R.attr.listPreferredItemHeight, outValue, true)) { |
| 14997 | throw new IllegalStateException( |
| 14998 | "Expected theme to define listPreferredItemHeight."); |
| 14999 | } |
| 15000 | mVerticalScrollFactor = outValue.getDimension( |
| 15001 | mContext.getResources().getDisplayMetrics()); |
| 15002 | } |
| 15003 | return mVerticalScrollFactor; |
| 15004 | } |
| 15005 | |
| 15006 | /** |
| 15007 | * Gets a scale factor that determines the distance the view should scroll |
| 15008 | * horizontally in response to {@link MotionEvent#ACTION_SCROLL}. |
| 15009 | * @return The horizontal scroll scale factor. |
| 15010 | * @hide |
| 15011 | */ |
| 15012 | protected float getHorizontalScrollFactor() { |
| 15013 | // TODO: Should use something else. |
| 15014 | return getVerticalScrollFactor(); |
| 15015 | } |
| 15016 | |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15017 | /** |
| 15018 | * Return the value specifying the text direction or policy that was set with |
| 15019 | * {@link #setTextDirection(int)}. |
| 15020 | * |
| 15021 | * @return the defined text direction. It can be one of: |
| 15022 | * |
| 15023 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 15024 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 15025 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 15026 | * {@link #TEXT_DIRECTION_LTR}, |
| 15027 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15028 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15029 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15030 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 15031 | @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), |
| 15032 | @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), |
| 15033 | @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), |
| 15034 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), |
| 15035 | @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"), |
| 15036 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE") |
| 15037 | }) |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15038 | public int getTextDirection() { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15039 | return (mPrivateFlags2 & TEXT_DIRECTION_MASK) >> TEXT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15040 | } |
| 15041 | |
| 15042 | /** |
| 15043 | * Set the text direction. |
| 15044 | * |
| 15045 | * @param textDirection the direction to set. Should be one of: |
| 15046 | * |
| 15047 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 15048 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 15049 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 15050 | * {@link #TEXT_DIRECTION_LTR}, |
| 15051 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15052 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15053 | */ |
| 15054 | public void setTextDirection(int textDirection) { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15055 | if (getTextDirection() != textDirection) { |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 15056 | // Reset the current text direction and the resolved one |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15057 | mPrivateFlags2 &= ~TEXT_DIRECTION_MASK; |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 15058 | resetResolvedTextDirection(); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15059 | // Set the new text direction |
| 15060 | mPrivateFlags2 |= ((textDirection << TEXT_DIRECTION_MASK_SHIFT) & TEXT_DIRECTION_MASK); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15061 | // Refresh |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15062 | requestLayout(); |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 15063 | invalidate(true); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15064 | } |
| 15065 | } |
| 15066 | |
| 15067 | /** |
| 15068 | * Return the resolved text direction. |
| 15069 | * |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15070 | * This needs resolution if the value is TEXT_DIRECTION_INHERIT. The resolution matches |
| 15071 | * {@link #getTextDirection()}if it is not TEXT_DIRECTION_INHERIT, otherwise resolution proceeds |
| 15072 | * up the parent chain of the view. if there is no parent, then it will return the default |
| 15073 | * {@link #TEXT_DIRECTION_FIRST_STRONG}. |
| 15074 | * |
| 15075 | * @return the resolved text direction. Returns one of: |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15076 | * |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 15077 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 15078 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15079 | * {@link #TEXT_DIRECTION_LTR}, |
| 15080 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15081 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15082 | */ |
| 15083 | public int getResolvedTextDirection() { |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 15084 | // The text direction will be resolved only if needed |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15085 | if ((mPrivateFlags2 & TEXT_DIRECTION_RESOLVED) != TEXT_DIRECTION_RESOLVED) { |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15086 | resolveTextDirection(); |
| 15087 | } |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15088 | return (mPrivateFlags2 & TEXT_DIRECTION_RESOLVED_MASK) >> TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15089 | } |
| 15090 | |
| 15091 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15092 | * Resolve the text direction. Will call {@link View#onResolvedTextDirectionChanged} when |
| 15093 | * resolution is done. |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15094 | */ |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15095 | public void resolveTextDirection() { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15096 | // Reset any previous text direction resolution |
| 15097 | mPrivateFlags2 &= ~(TEXT_DIRECTION_RESOLVED | TEXT_DIRECTION_RESOLVED_MASK); |
| 15098 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 15099 | if (hasRtlSupport()) { |
| 15100 | // Set resolved text direction flag depending on text direction flag |
| 15101 | final int textDirection = getTextDirection(); |
| 15102 | switch(textDirection) { |
| 15103 | case TEXT_DIRECTION_INHERIT: |
| 15104 | if (canResolveTextDirection()) { |
| 15105 | ViewGroup viewGroup = ((ViewGroup) mParent); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15106 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 15107 | // Set current resolved direction to the same value as the parent's one |
| 15108 | final int parentResolvedDirection = viewGroup.getResolvedTextDirection(); |
| 15109 | switch (parentResolvedDirection) { |
| 15110 | case TEXT_DIRECTION_FIRST_STRONG: |
| 15111 | case TEXT_DIRECTION_ANY_RTL: |
| 15112 | case TEXT_DIRECTION_LTR: |
| 15113 | case TEXT_DIRECTION_RTL: |
| 15114 | case TEXT_DIRECTION_LOCALE: |
| 15115 | mPrivateFlags2 |= |
| 15116 | (parentResolvedDirection << TEXT_DIRECTION_RESOLVED_MASK_SHIFT); |
| 15117 | break; |
| 15118 | default: |
| 15119 | // Default resolved direction is "first strong" heuristic |
| 15120 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT; |
| 15121 | } |
| 15122 | } else { |
| 15123 | // We cannot do the resolution if there is no parent, so use the default one |
| 15124 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15125 | } |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 15126 | break; |
| 15127 | case TEXT_DIRECTION_FIRST_STRONG: |
| 15128 | case TEXT_DIRECTION_ANY_RTL: |
| 15129 | case TEXT_DIRECTION_LTR: |
| 15130 | case TEXT_DIRECTION_RTL: |
| 15131 | case TEXT_DIRECTION_LOCALE: |
| 15132 | // Resolved direction is the same as text direction |
| 15133 | mPrivateFlags2 |= (textDirection << TEXT_DIRECTION_RESOLVED_MASK_SHIFT); |
| 15134 | break; |
| 15135 | default: |
| 15136 | // Default resolved direction is "first strong" heuristic |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15137 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 15138 | } |
| 15139 | } else { |
| 15140 | // Default resolved direction is "first strong" heuristic |
| 15141 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15142 | } |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15143 | |
| 15144 | // Set to resolved |
| 15145 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15146 | onResolvedTextDirectionChanged(); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15147 | } |
| 15148 | |
| 15149 | /** |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15150 | * 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] | 15151 | * resolution should override this method. |
| 15152 | * |
| 15153 | * The default implementation does nothing. |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15154 | */ |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15155 | public void onResolvedTextDirectionChanged() { |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15156 | } |
| 15157 | |
| 15158 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15159 | * Check if text direction resolution can be done. |
| 15160 | * |
| 15161 | * @return true if text direction resolution can be done otherwise return false. |
| 15162 | */ |
| 15163 | public boolean canResolveTextDirection() { |
| 15164 | switch (getTextDirection()) { |
| 15165 | case TEXT_DIRECTION_INHERIT: |
| 15166 | return (mParent != null) && (mParent instanceof ViewGroup); |
| 15167 | default: |
| 15168 | return true; |
| 15169 | } |
| 15170 | } |
| 15171 | |
| 15172 | /** |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15173 | * 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] | 15174 | * getResolvedTextDirection(). Will call {@link View#onResolvedTextDirectionReset} when |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15175 | * reset is done. |
| 15176 | */ |
| 15177 | public void resetResolvedTextDirection() { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15178 | mPrivateFlags2 &= ~(TEXT_DIRECTION_RESOLVED | TEXT_DIRECTION_RESOLVED_MASK); |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15179 | onResolvedTextDirectionReset(); |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15180 | } |
| 15181 | |
| 15182 | /** |
| 15183 | * Called when text direction is reset. Subclasses that care about text direction reset should |
| 15184 | * override this method and do a reset of the text direction of their children. The default |
| 15185 | * implementation does nothing. |
| 15186 | */ |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15187 | public void onResolvedTextDirectionReset() { |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15188 | } |
| 15189 | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15190 | /** |
| 15191 | * Return the value specifying the text alignment or policy that was set with |
| 15192 | * {@link #setTextAlignment(int)}. |
| 15193 | * |
| 15194 | * @return the defined text alignment. It can be one of: |
| 15195 | * |
| 15196 | * {@link #TEXT_ALIGNMENT_INHERIT}, |
| 15197 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 15198 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 15199 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 15200 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 15201 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 15202 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
| 15203 | */ |
| 15204 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 15205 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_INHERIT, to = "INHERIT"), |
| 15206 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_GRAVITY, to = "GRAVITY"), |
| 15207 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_START, to = "TEXT_START"), |
| 15208 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_END, to = "TEXT_END"), |
| 15209 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_CENTER, to = "CENTER"), |
| 15210 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), |
| 15211 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") |
| 15212 | }) |
| 15213 | public int getTextAlignment() { |
| 15214 | return (mPrivateFlags2 & TEXT_ALIGNMENT_MASK) >> TEXT_ALIGNMENT_MASK_SHIFT; |
| 15215 | } |
| 15216 | |
| 15217 | /** |
| 15218 | * Set the text alignment. |
| 15219 | * |
| 15220 | * @param textAlignment The text alignment to set. Should be one of |
| 15221 | * |
| 15222 | * {@link #TEXT_ALIGNMENT_INHERIT}, |
| 15223 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 15224 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 15225 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 15226 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 15227 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 15228 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
| 15229 | * |
| 15230 | * @attr ref android.R.styleable#View_textAlignment |
| 15231 | */ |
| 15232 | public void setTextAlignment(int textAlignment) { |
| 15233 | if (textAlignment != getTextAlignment()) { |
| 15234 | // Reset the current and resolved text alignment |
| 15235 | mPrivateFlags2 &= ~TEXT_ALIGNMENT_MASK; |
| 15236 | resetResolvedTextAlignment(); |
| 15237 | // Set the new text alignment |
| 15238 | mPrivateFlags2 |= ((textAlignment << TEXT_ALIGNMENT_MASK_SHIFT) & TEXT_ALIGNMENT_MASK); |
| 15239 | // Refresh |
| 15240 | requestLayout(); |
| 15241 | invalidate(true); |
| 15242 | } |
| 15243 | } |
| 15244 | |
| 15245 | /** |
| 15246 | * Return the resolved text alignment. |
| 15247 | * |
| 15248 | * The resolved text alignment. This needs resolution if the value is |
| 15249 | * TEXT_ALIGNMENT_INHERIT. The resolution matches {@link #setTextAlignment(int)} if it is |
| 15250 | * not TEXT_ALIGNMENT_INHERIT, otherwise resolution proceeds up the parent chain of the view. |
| 15251 | * |
| 15252 | * @return the resolved text alignment. Returns one of: |
| 15253 | * |
| 15254 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 15255 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 15256 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 15257 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 15258 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 15259 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
| 15260 | */ |
| 15261 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 15262 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_INHERIT, to = "INHERIT"), |
| 15263 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_GRAVITY, to = "GRAVITY"), |
| 15264 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_START, to = "TEXT_START"), |
| 15265 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_END, to = "TEXT_END"), |
| 15266 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_CENTER, to = "CENTER"), |
| 15267 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), |
| 15268 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") |
| 15269 | }) |
| 15270 | public int getResolvedTextAlignment() { |
| 15271 | // If text alignment is not resolved, then resolve it |
| 15272 | if ((mPrivateFlags2 & TEXT_ALIGNMENT_RESOLVED) != TEXT_ALIGNMENT_RESOLVED) { |
| 15273 | resolveTextAlignment(); |
| 15274 | } |
| 15275 | return (mPrivateFlags2 & TEXT_ALIGNMENT_RESOLVED_MASK) >> TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
| 15276 | } |
| 15277 | |
| 15278 | /** |
| 15279 | * Resolve the text alignment. Will call {@link View#onResolvedTextAlignmentChanged} when |
| 15280 | * resolution is done. |
| 15281 | */ |
| 15282 | public void resolveTextAlignment() { |
| 15283 | // Reset any previous text alignment resolution |
| 15284 | mPrivateFlags2 &= ~(TEXT_ALIGNMENT_RESOLVED | TEXT_ALIGNMENT_RESOLVED_MASK); |
| 15285 | |
| 15286 | if (hasRtlSupport()) { |
| 15287 | // Set resolved text alignment flag depending on text alignment flag |
| 15288 | final int textAlignment = getTextAlignment(); |
| 15289 | switch (textAlignment) { |
| 15290 | case TEXT_ALIGNMENT_INHERIT: |
| 15291 | // Check if we can resolve the text alignment |
| 15292 | if (canResolveLayoutDirection() && mParent instanceof View) { |
| 15293 | View view = (View) mParent; |
| 15294 | |
| 15295 | final int parentResolvedTextAlignment = view.getResolvedTextAlignment(); |
| 15296 | switch (parentResolvedTextAlignment) { |
| 15297 | case TEXT_ALIGNMENT_GRAVITY: |
| 15298 | case TEXT_ALIGNMENT_TEXT_START: |
| 15299 | case TEXT_ALIGNMENT_TEXT_END: |
| 15300 | case TEXT_ALIGNMENT_CENTER: |
| 15301 | case TEXT_ALIGNMENT_VIEW_START: |
| 15302 | case TEXT_ALIGNMENT_VIEW_END: |
| 15303 | // Resolved text alignment is the same as the parent resolved |
| 15304 | // text alignment |
| 15305 | mPrivateFlags2 |= |
| 15306 | (parentResolvedTextAlignment << TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT); |
| 15307 | break; |
| 15308 | default: |
| 15309 | // Use default resolved text alignment |
| 15310 | mPrivateFlags2 |= TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 15311 | } |
| 15312 | } |
| 15313 | else { |
| 15314 | // We cannot do the resolution if there is no parent so use the default |
| 15315 | mPrivateFlags2 |= TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 15316 | } |
| 15317 | break; |
| 15318 | case TEXT_ALIGNMENT_GRAVITY: |
| 15319 | case TEXT_ALIGNMENT_TEXT_START: |
| 15320 | case TEXT_ALIGNMENT_TEXT_END: |
| 15321 | case TEXT_ALIGNMENT_CENTER: |
| 15322 | case TEXT_ALIGNMENT_VIEW_START: |
| 15323 | case TEXT_ALIGNMENT_VIEW_END: |
| 15324 | // Resolved text alignment is the same as text alignment |
| 15325 | mPrivateFlags2 |= (textAlignment << TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT); |
| 15326 | break; |
| 15327 | default: |
| 15328 | // Use default resolved text alignment |
| 15329 | mPrivateFlags2 |= TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 15330 | } |
| 15331 | } else { |
| 15332 | // Use default resolved text alignment |
| 15333 | mPrivateFlags2 |= TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 15334 | } |
| 15335 | |
| 15336 | // Set the resolved |
| 15337 | mPrivateFlags2 |= TEXT_ALIGNMENT_RESOLVED; |
| 15338 | onResolvedTextAlignmentChanged(); |
| 15339 | } |
| 15340 | |
| 15341 | /** |
| 15342 | * Check if text alignment resolution can be done. |
| 15343 | * |
| 15344 | * @return true if text alignment resolution can be done otherwise return false. |
| 15345 | */ |
| 15346 | public boolean canResolveTextAlignment() { |
| 15347 | switch (getTextAlignment()) { |
| 15348 | case TEXT_DIRECTION_INHERIT: |
| 15349 | return (mParent != null); |
| 15350 | default: |
| 15351 | return true; |
| 15352 | } |
| 15353 | } |
| 15354 | |
| 15355 | /** |
| 15356 | * Called when text alignment has been resolved. Subclasses that care about text alignment |
| 15357 | * resolution should override this method. |
| 15358 | * |
| 15359 | * The default implementation does nothing. |
| 15360 | */ |
| 15361 | public void onResolvedTextAlignmentChanged() { |
| 15362 | } |
| 15363 | |
| 15364 | /** |
| 15365 | * Reset resolved text alignment. Text alignment can be resolved with a call to |
| 15366 | * getResolvedTextAlignment(). Will call {@link View#onResolvedTextAlignmentReset} when |
| 15367 | * reset is done. |
| 15368 | */ |
| 15369 | public void resetResolvedTextAlignment() { |
| 15370 | // Reset any previous text alignment resolution |
| 15371 | mPrivateFlags2 &= ~(TEXT_ALIGNMENT_RESOLVED | TEXT_ALIGNMENT_RESOLVED_MASK); |
| 15372 | onResolvedTextAlignmentReset(); |
| 15373 | } |
| 15374 | |
| 15375 | /** |
| 15376 | * Called when text alignment is reset. Subclasses that care about text alignment reset should |
| 15377 | * override this method and do a reset of the text alignment of their children. The default |
| 15378 | * implementation does nothing. |
| 15379 | */ |
| 15380 | public void onResolvedTextAlignmentReset() { |
| 15381 | } |
| 15382 | |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 15383 | // |
| 15384 | // Properties |
| 15385 | // |
| 15386 | /** |
| 15387 | * A Property wrapper around the <code>alpha</code> functionality handled by the |
| 15388 | * {@link View#setAlpha(float)} and {@link View#getAlpha()} methods. |
| 15389 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 15390 | public static final Property<View, Float> ALPHA = new FloatProperty<View>("alpha") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 15391 | @Override |
| 15392 | public void setValue(View object, float value) { |
| 15393 | object.setAlpha(value); |
| 15394 | } |
| 15395 | |
| 15396 | @Override |
| 15397 | public Float get(View object) { |
| 15398 | return object.getAlpha(); |
| 15399 | } |
| 15400 | }; |
| 15401 | |
| 15402 | /** |
| 15403 | * A Property wrapper around the <code>translationX</code> functionality handled by the |
| 15404 | * {@link View#setTranslationX(float)} and {@link View#getTranslationX()} methods. |
| 15405 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 15406 | public static final Property<View, Float> TRANSLATION_X = new FloatProperty<View>("translationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 15407 | @Override |
| 15408 | public void setValue(View object, float value) { |
| 15409 | object.setTranslationX(value); |
| 15410 | } |
| 15411 | |
| 15412 | @Override |
| 15413 | public Float get(View object) { |
| 15414 | return object.getTranslationX(); |
| 15415 | } |
| 15416 | }; |
| 15417 | |
| 15418 | /** |
| 15419 | * A Property wrapper around the <code>translationY</code> functionality handled by the |
| 15420 | * {@link View#setTranslationY(float)} and {@link View#getTranslationY()} methods. |
| 15421 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 15422 | public static final Property<View, Float> TRANSLATION_Y = new FloatProperty<View>("translationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 15423 | @Override |
| 15424 | public void setValue(View object, float value) { |
| 15425 | object.setTranslationY(value); |
| 15426 | } |
| 15427 | |
| 15428 | @Override |
| 15429 | public Float get(View object) { |
| 15430 | return object.getTranslationY(); |
| 15431 | } |
| 15432 | }; |
| 15433 | |
| 15434 | /** |
| 15435 | * A Property wrapper around the <code>x</code> functionality handled by the |
| 15436 | * {@link View#setX(float)} and {@link View#getX()} methods. |
| 15437 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 15438 | public static final Property<View, Float> X = new FloatProperty<View>("x") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 15439 | @Override |
| 15440 | public void setValue(View object, float value) { |
| 15441 | object.setX(value); |
| 15442 | } |
| 15443 | |
| 15444 | @Override |
| 15445 | public Float get(View object) { |
| 15446 | return object.getX(); |
| 15447 | } |
| 15448 | }; |
| 15449 | |
| 15450 | /** |
| 15451 | * A Property wrapper around the <code>y</code> functionality handled by the |
| 15452 | * {@link View#setY(float)} and {@link View#getY()} methods. |
| 15453 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 15454 | public static final Property<View, Float> Y = new FloatProperty<View>("y") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 15455 | @Override |
| 15456 | public void setValue(View object, float value) { |
| 15457 | object.setY(value); |
| 15458 | } |
| 15459 | |
| 15460 | @Override |
| 15461 | public Float get(View object) { |
| 15462 | return object.getY(); |
| 15463 | } |
| 15464 | }; |
| 15465 | |
| 15466 | /** |
| 15467 | * A Property wrapper around the <code>rotation</code> functionality handled by the |
| 15468 | * {@link View#setRotation(float)} and {@link View#getRotation()} methods. |
| 15469 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 15470 | public static final Property<View, Float> ROTATION = new FloatProperty<View>("rotation") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 15471 | @Override |
| 15472 | public void setValue(View object, float value) { |
| 15473 | object.setRotation(value); |
| 15474 | } |
| 15475 | |
| 15476 | @Override |
| 15477 | public Float get(View object) { |
| 15478 | return object.getRotation(); |
| 15479 | } |
| 15480 | }; |
| 15481 | |
| 15482 | /** |
| 15483 | * A Property wrapper around the <code>rotationX</code> functionality handled by the |
| 15484 | * {@link View#setRotationX(float)} and {@link View#getRotationX()} methods. |
| 15485 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 15486 | public static final Property<View, Float> ROTATION_X = new FloatProperty<View>("rotationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 15487 | @Override |
| 15488 | public void setValue(View object, float value) { |
| 15489 | object.setRotationX(value); |
| 15490 | } |
| 15491 | |
| 15492 | @Override |
| 15493 | public Float get(View object) { |
| 15494 | return object.getRotationX(); |
| 15495 | } |
| 15496 | }; |
| 15497 | |
| 15498 | /** |
| 15499 | * A Property wrapper around the <code>rotationY</code> functionality handled by the |
| 15500 | * {@link View#setRotationY(float)} and {@link View#getRotationY()} methods. |
| 15501 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 15502 | public static final Property<View, Float> ROTATION_Y = new FloatProperty<View>("rotationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 15503 | @Override |
| 15504 | public void setValue(View object, float value) { |
| 15505 | object.setRotationY(value); |
| 15506 | } |
| 15507 | |
| 15508 | @Override |
| 15509 | public Float get(View object) { |
| 15510 | return object.getRotationY(); |
| 15511 | } |
| 15512 | }; |
| 15513 | |
| 15514 | /** |
| 15515 | * A Property wrapper around the <code>scaleX</code> functionality handled by the |
| 15516 | * {@link View#setScaleX(float)} and {@link View#getScaleX()} methods. |
| 15517 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 15518 | public static final Property<View, Float> SCALE_X = new FloatProperty<View>("scaleX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 15519 | @Override |
| 15520 | public void setValue(View object, float value) { |
| 15521 | object.setScaleX(value); |
| 15522 | } |
| 15523 | |
| 15524 | @Override |
| 15525 | public Float get(View object) { |
| 15526 | return object.getScaleX(); |
| 15527 | } |
| 15528 | }; |
| 15529 | |
| 15530 | /** |
| 15531 | * A Property wrapper around the <code>scaleY</code> functionality handled by the |
| 15532 | * {@link View#setScaleY(float)} and {@link View#getScaleY()} methods. |
| 15533 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 15534 | public static final Property<View, Float> SCALE_Y = new FloatProperty<View>("scaleY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 15535 | @Override |
| 15536 | public void setValue(View object, float value) { |
| 15537 | object.setScaleY(value); |
| 15538 | } |
| 15539 | |
| 15540 | @Override |
| 15541 | public Float get(View object) { |
| 15542 | return object.getScaleY(); |
| 15543 | } |
| 15544 | }; |
| 15545 | |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 15546 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15547 | * A MeasureSpec encapsulates the layout requirements passed from parent to child. |
| 15548 | * Each MeasureSpec represents a requirement for either the width or the height. |
| 15549 | * A MeasureSpec is comprised of a size and a mode. There are three possible |
| 15550 | * modes: |
| 15551 | * <dl> |
| 15552 | * <dt>UNSPECIFIED</dt> |
| 15553 | * <dd> |
| 15554 | * The parent has not imposed any constraint on the child. It can be whatever size |
| 15555 | * it wants. |
| 15556 | * </dd> |
| 15557 | * |
| 15558 | * <dt>EXACTLY</dt> |
| 15559 | * <dd> |
| 15560 | * The parent has determined an exact size for the child. The child is going to be |
| 15561 | * given those bounds regardless of how big it wants to be. |
| 15562 | * </dd> |
| 15563 | * |
| 15564 | * <dt>AT_MOST</dt> |
| 15565 | * <dd> |
| 15566 | * The child can be as large as it wants up to the specified size. |
| 15567 | * </dd> |
| 15568 | * </dl> |
| 15569 | * |
| 15570 | * MeasureSpecs are implemented as ints to reduce object allocation. This class |
| 15571 | * is provided to pack and unpack the <size, mode> tuple into the int. |
| 15572 | */ |
| 15573 | public static class MeasureSpec { |
| 15574 | private static final int MODE_SHIFT = 30; |
| 15575 | private static final int MODE_MASK = 0x3 << MODE_SHIFT; |
| 15576 | |
| 15577 | /** |
| 15578 | * Measure specification mode: The parent has not imposed any constraint |
| 15579 | * on the child. It can be whatever size it wants. |
| 15580 | */ |
| 15581 | public static final int UNSPECIFIED = 0 << MODE_SHIFT; |
| 15582 | |
| 15583 | /** |
| 15584 | * Measure specification mode: The parent has determined an exact size |
| 15585 | * for the child. The child is going to be given those bounds regardless |
| 15586 | * of how big it wants to be. |
| 15587 | */ |
| 15588 | public static final int EXACTLY = 1 << MODE_SHIFT; |
| 15589 | |
| 15590 | /** |
| 15591 | * Measure specification mode: The child can be as large as it wants up |
| 15592 | * to the specified size. |
| 15593 | */ |
| 15594 | public static final int AT_MOST = 2 << MODE_SHIFT; |
| 15595 | |
| 15596 | /** |
| 15597 | * Creates a measure specification based on the supplied size and mode. |
| 15598 | * |
| 15599 | * The mode must always be one of the following: |
| 15600 | * <ul> |
| 15601 | * <li>{@link android.view.View.MeasureSpec#UNSPECIFIED}</li> |
| 15602 | * <li>{@link android.view.View.MeasureSpec#EXACTLY}</li> |
| 15603 | * <li>{@link android.view.View.MeasureSpec#AT_MOST}</li> |
| 15604 | * </ul> |
| 15605 | * |
| 15606 | * @param size the size of the measure specification |
| 15607 | * @param mode the mode of the measure specification |
| 15608 | * @return the measure specification based on size and mode |
| 15609 | */ |
| 15610 | public static int makeMeasureSpec(int size, int mode) { |
| 15611 | return size + mode; |
| 15612 | } |
| 15613 | |
| 15614 | /** |
| 15615 | * Extracts the mode from the supplied measure specification. |
| 15616 | * |
| 15617 | * @param measureSpec the measure specification to extract the mode from |
| 15618 | * @return {@link android.view.View.MeasureSpec#UNSPECIFIED}, |
| 15619 | * {@link android.view.View.MeasureSpec#AT_MOST} or |
| 15620 | * {@link android.view.View.MeasureSpec#EXACTLY} |
| 15621 | */ |
| 15622 | public static int getMode(int measureSpec) { |
| 15623 | return (measureSpec & MODE_MASK); |
| 15624 | } |
| 15625 | |
| 15626 | /** |
| 15627 | * Extracts the size from the supplied measure specification. |
| 15628 | * |
| 15629 | * @param measureSpec the measure specification to extract the size from |
| 15630 | * @return the size in pixels defined in the supplied measure specification |
| 15631 | */ |
| 15632 | public static int getSize(int measureSpec) { |
| 15633 | return (measureSpec & ~MODE_MASK); |
| 15634 | } |
| 15635 | |
| 15636 | /** |
| 15637 | * Returns a String representation of the specified measure |
| 15638 | * specification. |
| 15639 | * |
| 15640 | * @param measureSpec the measure specification to convert to a String |
| 15641 | * @return a String with the following format: "MeasureSpec: MODE SIZE" |
| 15642 | */ |
| 15643 | public static String toString(int measureSpec) { |
| 15644 | int mode = getMode(measureSpec); |
| 15645 | int size = getSize(measureSpec); |
| 15646 | |
| 15647 | StringBuilder sb = new StringBuilder("MeasureSpec: "); |
| 15648 | |
| 15649 | if (mode == UNSPECIFIED) |
| 15650 | sb.append("UNSPECIFIED "); |
| 15651 | else if (mode == EXACTLY) |
| 15652 | sb.append("EXACTLY "); |
| 15653 | else if (mode == AT_MOST) |
| 15654 | sb.append("AT_MOST "); |
| 15655 | else |
| 15656 | sb.append(mode).append(" "); |
| 15657 | |
| 15658 | sb.append(size); |
| 15659 | return sb.toString(); |
| 15660 | } |
| 15661 | } |
| 15662 | |
| 15663 | class CheckForLongPress implements Runnable { |
| 15664 | |
| 15665 | private int mOriginalWindowAttachCount; |
| 15666 | |
| 15667 | public void run() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 15668 | if (isPressed() && (mParent != null) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15669 | && mOriginalWindowAttachCount == mWindowAttachCount) { |
| 15670 | if (performLongClick()) { |
| 15671 | mHasPerformedLongPress = true; |
| 15672 | } |
| 15673 | } |
| 15674 | } |
| 15675 | |
| 15676 | public void rememberWindowAttachCount() { |
| 15677 | mOriginalWindowAttachCount = mWindowAttachCount; |
| 15678 | } |
| 15679 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15680 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 15681 | private final class CheckForTap implements Runnable { |
| 15682 | public void run() { |
| 15683 | mPrivateFlags &= ~PREPRESSED; |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 15684 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 15685 | checkForLongClick(ViewConfiguration.getTapTimeout()); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 15686 | } |
| 15687 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15688 | |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 15689 | private final class PerformClick implements Runnable { |
| 15690 | public void run() { |
| 15691 | performClick(); |
| 15692 | } |
| 15693 | } |
| 15694 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 15695 | /** @hide */ |
| 15696 | public void hackTurnOffWindowResizeAnim(boolean off) { |
| 15697 | mAttachInfo.mTurnOffWindowResizeAnim = off; |
| 15698 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15700 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 15701 | * This method returns a ViewPropertyAnimator object, which can be used to animate |
| 15702 | * specific properties on this View. |
| 15703 | * |
| 15704 | * @return ViewPropertyAnimator The ViewPropertyAnimator associated with this View. |
| 15705 | */ |
| 15706 | public ViewPropertyAnimator animate() { |
| 15707 | if (mAnimator == null) { |
| 15708 | mAnimator = new ViewPropertyAnimator(this); |
| 15709 | } |
| 15710 | return mAnimator; |
| 15711 | } |
| 15712 | |
| 15713 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15714 | * Interface definition for a callback to be invoked when a key event is |
| 15715 | * dispatched to this view. The callback will be invoked before the key |
| 15716 | * event is given to the view. |
| 15717 | */ |
| 15718 | public interface OnKeyListener { |
| 15719 | /** |
| 15720 | * Called when a key is dispatched to a view. This allows listeners to |
| 15721 | * get a chance to respond before the target view. |
| 15722 | * |
| 15723 | * @param v The view the key has been dispatched to. |
| 15724 | * @param keyCode The code for the physical key that was pressed |
| 15725 | * @param event The KeyEvent object containing full information about |
| 15726 | * the event. |
| 15727 | * @return True if the listener has consumed the event, false otherwise. |
| 15728 | */ |
| 15729 | boolean onKey(View v, int keyCode, KeyEvent event); |
| 15730 | } |
| 15731 | |
| 15732 | /** |
| 15733 | * Interface definition for a callback to be invoked when a touch event is |
| 15734 | * dispatched to this view. The callback will be invoked before the touch |
| 15735 | * event is given to the view. |
| 15736 | */ |
| 15737 | public interface OnTouchListener { |
| 15738 | /** |
| 15739 | * Called when a touch event is dispatched to a view. This allows listeners to |
| 15740 | * get a chance to respond before the target view. |
| 15741 | * |
| 15742 | * @param v The view the touch event has been dispatched to. |
| 15743 | * @param event The MotionEvent object containing full information about |
| 15744 | * the event. |
| 15745 | * @return True if the listener has consumed the event, false otherwise. |
| 15746 | */ |
| 15747 | boolean onTouch(View v, MotionEvent event); |
| 15748 | } |
| 15749 | |
| 15750 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 15751 | * Interface definition for a callback to be invoked when a hover event is |
| 15752 | * dispatched to this view. The callback will be invoked before the hover |
| 15753 | * event is given to the view. |
| 15754 | */ |
| 15755 | public interface OnHoverListener { |
| 15756 | /** |
| 15757 | * Called when a hover event is dispatched to a view. This allows listeners to |
| 15758 | * get a chance to respond before the target view. |
| 15759 | * |
| 15760 | * @param v The view the hover event has been dispatched to. |
| 15761 | * @param event The MotionEvent object containing full information about |
| 15762 | * the event. |
| 15763 | * @return True if the listener has consumed the event, false otherwise. |
| 15764 | */ |
| 15765 | boolean onHover(View v, MotionEvent event); |
| 15766 | } |
| 15767 | |
| 15768 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 15769 | * Interface definition for a callback to be invoked when a generic motion event is |
| 15770 | * dispatched to this view. The callback will be invoked before the generic motion |
| 15771 | * event is given to the view. |
| 15772 | */ |
| 15773 | public interface OnGenericMotionListener { |
| 15774 | /** |
| 15775 | * Called when a generic motion event is dispatched to a view. This allows listeners to |
| 15776 | * get a chance to respond before the target view. |
| 15777 | * |
| 15778 | * @param v The view the generic motion event has been dispatched to. |
| 15779 | * @param event The MotionEvent object containing full information about |
| 15780 | * the event. |
| 15781 | * @return True if the listener has consumed the event, false otherwise. |
| 15782 | */ |
| 15783 | boolean onGenericMotion(View v, MotionEvent event); |
| 15784 | } |
| 15785 | |
| 15786 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15787 | * Interface definition for a callback to be invoked when a view has been clicked and held. |
| 15788 | */ |
| 15789 | public interface OnLongClickListener { |
| 15790 | /** |
| 15791 | * Called when a view has been clicked and held. |
| 15792 | * |
| 15793 | * @param v The view that was clicked and held. |
| 15794 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 15795 | * @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] | 15796 | */ |
| 15797 | boolean onLongClick(View v); |
| 15798 | } |
| 15799 | |
| 15800 | /** |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 15801 | * Interface definition for a callback to be invoked when a drag is being dispatched |
| 15802 | * to this view. The callback will be invoked before the hosting view's own |
| 15803 | * onDrag(event) method. If the listener wants to fall back to the hosting view's |
| 15804 | * onDrag(event) behavior, it should return 'false' from this callback. |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 15805 | * |
| 15806 | * <div class="special reference"> |
| 15807 | * <h3>Developer Guides</h3> |
| 15808 | * <p>For a guide to implementing drag and drop features, read the |
| 15809 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 15810 | * </div> |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 15811 | */ |
| 15812 | public interface OnDragListener { |
| 15813 | /** |
| 15814 | * Called when a drag event is dispatched to a view. This allows listeners |
| 15815 | * to get a chance to override base View behavior. |
| 15816 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15817 | * @param v The View that received the drag event. |
| 15818 | * @param event The {@link android.view.DragEvent} object for the drag event. |
| 15819 | * @return {@code true} if the drag event was handled successfully, or {@code false} |
| 15820 | * if the drag event was not handled. Note that {@code false} will trigger the View |
| 15821 | * to call its {@link #onDragEvent(DragEvent) onDragEvent()} handler. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 15822 | */ |
| 15823 | boolean onDrag(View v, DragEvent event); |
| 15824 | } |
| 15825 | |
| 15826 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15827 | * Interface definition for a callback to be invoked when the focus state of |
| 15828 | * a view changed. |
| 15829 | */ |
| 15830 | public interface OnFocusChangeListener { |
| 15831 | /** |
| 15832 | * Called when the focus state of a view has changed. |
| 15833 | * |
| 15834 | * @param v The view whose state has changed. |
| 15835 | * @param hasFocus The new focus state of v. |
| 15836 | */ |
| 15837 | void onFocusChange(View v, boolean hasFocus); |
| 15838 | } |
| 15839 | |
| 15840 | /** |
| 15841 | * Interface definition for a callback to be invoked when a view is clicked. |
| 15842 | */ |
| 15843 | public interface OnClickListener { |
| 15844 | /** |
| 15845 | * Called when a view has been clicked. |
| 15846 | * |
| 15847 | * @param v The view that was clicked. |
| 15848 | */ |
| 15849 | void onClick(View v); |
| 15850 | } |
| 15851 | |
| 15852 | /** |
| 15853 | * Interface definition for a callback to be invoked when the context menu |
| 15854 | * for this view is being built. |
| 15855 | */ |
| 15856 | public interface OnCreateContextMenuListener { |
| 15857 | /** |
| 15858 | * Called when the context menu for this view is being built. It is not |
| 15859 | * safe to hold onto the menu after this method returns. |
| 15860 | * |
| 15861 | * @param menu The context menu that is being built |
| 15862 | * @param v The view for which the context menu is being built |
| 15863 | * @param menuInfo Extra information about the item for which the |
| 15864 | * context menu should be shown. This information will vary |
| 15865 | * depending on the class of v. |
| 15866 | */ |
| 15867 | void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo); |
| 15868 | } |
| 15869 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15870 | /** |
| 15871 | * 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] | 15872 | * visibility. This reports <strong>global</strong> changes to the system UI |
| 15873 | * state, not just what the application is requesting. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15874 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15875 | * @see View#setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15876 | */ |
| 15877 | public interface OnSystemUiVisibilityChangeListener { |
| 15878 | /** |
| 15879 | * Called when the status bar changes visibility because of a call to |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 15880 | * {@link View#setSystemUiVisibility(int)}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15881 | * |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 15882 | * @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] | 15883 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. This tells you the |
| 15884 | * <strong>global</strong> state of the UI visibility flags, not what your |
| 15885 | * app is currently applying. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15886 | */ |
| 15887 | public void onSystemUiVisibilityChange(int visibility); |
| 15888 | } |
| 15889 | |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 15890 | /** |
| 15891 | * Interface definition for a callback to be invoked when this view is attached |
| 15892 | * or detached from its window. |
| 15893 | */ |
| 15894 | public interface OnAttachStateChangeListener { |
| 15895 | /** |
| 15896 | * Called when the view is attached to a window. |
| 15897 | * @param v The view that was attached |
| 15898 | */ |
| 15899 | public void onViewAttachedToWindow(View v); |
| 15900 | /** |
| 15901 | * Called when the view is detached from a window. |
| 15902 | * @param v The view that was detached |
| 15903 | */ |
| 15904 | public void onViewDetachedFromWindow(View v); |
| 15905 | } |
| 15906 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15907 | private final class UnsetPressedState implements Runnable { |
| 15908 | public void run() { |
| 15909 | setPressed(false); |
| 15910 | } |
| 15911 | } |
| 15912 | |
| 15913 | /** |
| 15914 | * Base class for derived classes that want to save and restore their own |
| 15915 | * state in {@link android.view.View#onSaveInstanceState()}. |
| 15916 | */ |
| 15917 | public static class BaseSavedState extends AbsSavedState { |
| 15918 | /** |
| 15919 | * Constructor used when reading from a parcel. Reads the state of the superclass. |
| 15920 | * |
| 15921 | * @param source |
| 15922 | */ |
| 15923 | public BaseSavedState(Parcel source) { |
| 15924 | super(source); |
| 15925 | } |
| 15926 | |
| 15927 | /** |
| 15928 | * Constructor called by derived classes when creating their SavedState objects |
| 15929 | * |
| 15930 | * @param superState The state of the superclass of this view |
| 15931 | */ |
| 15932 | public BaseSavedState(Parcelable superState) { |
| 15933 | super(superState); |
| 15934 | } |
| 15935 | |
| 15936 | public static final Parcelable.Creator<BaseSavedState> CREATOR = |
| 15937 | new Parcelable.Creator<BaseSavedState>() { |
| 15938 | public BaseSavedState createFromParcel(Parcel in) { |
| 15939 | return new BaseSavedState(in); |
| 15940 | } |
| 15941 | |
| 15942 | public BaseSavedState[] newArray(int size) { |
| 15943 | return new BaseSavedState[size]; |
| 15944 | } |
| 15945 | }; |
| 15946 | } |
| 15947 | |
| 15948 | /** |
| 15949 | * A set of information given to a view when it is attached to its parent |
| 15950 | * window. |
| 15951 | */ |
| 15952 | static class AttachInfo { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15953 | interface Callbacks { |
| 15954 | void playSoundEffect(int effectId); |
| 15955 | boolean performHapticFeedback(int effectId, boolean always); |
| 15956 | } |
| 15957 | |
| 15958 | /** |
| 15959 | * InvalidateInfo is used to post invalidate(int, int, int, int) messages |
| 15960 | * to a Handler. This class contains the target (View) to invalidate and |
| 15961 | * the coordinates of the dirty rectangle. |
| 15962 | * |
| 15963 | * For performance purposes, this class also implements a pool of up to |
| 15964 | * POOL_LIMIT objects that get reused. This reduces memory allocations |
| 15965 | * whenever possible. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15966 | */ |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 15967 | static class InvalidateInfo implements Poolable<InvalidateInfo> { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15968 | private static final int POOL_LIMIT = 10; |
Romain Guy | 2e9bbce | 2009-04-01 10:40:10 -0700 | [diff] [blame] | 15969 | private static final Pool<InvalidateInfo> sPool = Pools.synchronizedPool( |
| 15970 | Pools.finitePool(new PoolableManager<InvalidateInfo>() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 15971 | public InvalidateInfo newInstance() { |
| 15972 | return new InvalidateInfo(); |
| 15973 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15974 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 15975 | public void onAcquired(InvalidateInfo element) { |
| 15976 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15977 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 15978 | public void onReleased(InvalidateInfo element) { |
Romain Guy | 40c18f5 | 2011-09-01 17:01:18 -0700 | [diff] [blame] | 15979 | element.target = null; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 15980 | } |
| 15981 | }, POOL_LIMIT) |
| 15982 | ); |
| 15983 | |
| 15984 | private InvalidateInfo mNext; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 15985 | private boolean mIsPooled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15986 | |
| 15987 | View target; |
| 15988 | |
| 15989 | int left; |
| 15990 | int top; |
| 15991 | int right; |
| 15992 | int bottom; |
| 15993 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 15994 | public void setNextPoolable(InvalidateInfo element) { |
| 15995 | mNext = element; |
| 15996 | } |
| 15997 | |
| 15998 | public InvalidateInfo getNextPoolable() { |
| 15999 | return mNext; |
| 16000 | } |
| 16001 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16002 | static InvalidateInfo acquire() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16003 | return sPool.acquire(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16004 | } |
| 16005 | |
| 16006 | void release() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16007 | sPool.release(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16008 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 16009 | |
| 16010 | public boolean isPooled() { |
| 16011 | return mIsPooled; |
| 16012 | } |
| 16013 | |
| 16014 | public void setPooled(boolean isPooled) { |
| 16015 | mIsPooled = isPooled; |
| 16016 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16017 | } |
| 16018 | |
| 16019 | final IWindowSession mSession; |
| 16020 | |
| 16021 | final IWindow mWindow; |
| 16022 | |
| 16023 | final IBinder mWindowToken; |
| 16024 | |
| 16025 | final Callbacks mRootCallbacks; |
| 16026 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 16027 | HardwareCanvas mHardwareCanvas; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 16028 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16029 | /** |
| 16030 | * The top view of the hierarchy. |
| 16031 | */ |
| 16032 | View mRootView; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 16033 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16034 | IBinder mPanelParentWindowToken; |
| 16035 | Surface mSurface; |
| 16036 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 16037 | boolean mHardwareAccelerated; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 16038 | boolean mHardwareAccelerationRequested; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 16039 | HardwareRenderer mHardwareRenderer; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16040 | |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 16041 | boolean mScreenOn; |
| 16042 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16043 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 16044 | * Scale factor used by the compatibility mode |
| 16045 | */ |
| 16046 | float mApplicationScale; |
| 16047 | |
| 16048 | /** |
| 16049 | * Indicates whether the application is in compatibility mode |
| 16050 | */ |
| 16051 | boolean mScalingRequired; |
| 16052 | |
| 16053 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 16054 | * 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] | 16055 | */ |
| 16056 | boolean mTurnOffWindowResizeAnim; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16057 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 16058 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16059 | * Left position of this view's window |
| 16060 | */ |
| 16061 | int mWindowLeft; |
| 16062 | |
| 16063 | /** |
| 16064 | * Top position of this view's window |
| 16065 | */ |
| 16066 | int mWindowTop; |
| 16067 | |
| 16068 | /** |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 16069 | * Indicates whether views need to use 32-bit drawing caches |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 16070 | */ |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 16071 | boolean mUse32BitDrawingCache; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 16072 | |
| 16073 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16074 | * For windows that are full-screen but using insets to layout inside |
| 16075 | * of the screen decorations, these are the current insets for the |
| 16076 | * content of the window. |
| 16077 | */ |
| 16078 | final Rect mContentInsets = new Rect(); |
| 16079 | |
| 16080 | /** |
| 16081 | * For windows that are full-screen but using insets to layout inside |
| 16082 | * of the screen decorations, these are the current insets for the |
| 16083 | * actual visible parts of the window. |
| 16084 | */ |
| 16085 | final Rect mVisibleInsets = new Rect(); |
| 16086 | |
| 16087 | /** |
| 16088 | * The internal insets given by this window. This value is |
| 16089 | * supplied by the client (through |
| 16090 | * {@link ViewTreeObserver.OnComputeInternalInsetsListener}) and will |
| 16091 | * be given to the window manager when changed to be used in laying |
| 16092 | * out windows behind it. |
| 16093 | */ |
| 16094 | final ViewTreeObserver.InternalInsetsInfo mGivenInternalInsets |
| 16095 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 16096 | |
| 16097 | /** |
| 16098 | * All views in the window's hierarchy that serve as scroll containers, |
| 16099 | * used to determine if the window can be resized or must be panned |
| 16100 | * to adjust for a soft input area. |
| 16101 | */ |
| 16102 | final ArrayList<View> mScrollContainers = new ArrayList<View>(); |
| 16103 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 16104 | final KeyEvent.DispatcherState mKeyDispatchState |
| 16105 | = new KeyEvent.DispatcherState(); |
| 16106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16107 | /** |
| 16108 | * Indicates whether the view's window currently has the focus. |
| 16109 | */ |
| 16110 | boolean mHasWindowFocus; |
| 16111 | |
| 16112 | /** |
| 16113 | * The current visibility of the window. |
| 16114 | */ |
| 16115 | int mWindowVisibility; |
| 16116 | |
| 16117 | /** |
| 16118 | * Indicates the time at which drawing started to occur. |
| 16119 | */ |
| 16120 | long mDrawingTime; |
| 16121 | |
| 16122 | /** |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 16123 | * Indicates whether or not ignoring the DIRTY_MASK flags. |
| 16124 | */ |
| 16125 | boolean mIgnoreDirtyState; |
| 16126 | |
| 16127 | /** |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 16128 | * This flag tracks when the mIgnoreDirtyState flag is set during draw(), |
| 16129 | * to avoid clearing that flag prematurely. |
| 16130 | */ |
| 16131 | boolean mSetIgnoreDirtyState = false; |
| 16132 | |
| 16133 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16134 | * Indicates whether the view's window is currently in touch mode. |
| 16135 | */ |
| 16136 | boolean mInTouchMode; |
| 16137 | |
| 16138 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 16139 | * Indicates that ViewAncestor should trigger a global layout change |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16140 | * the next time it performs a traversal |
| 16141 | */ |
| 16142 | boolean mRecomputeGlobalAttributes; |
| 16143 | |
| 16144 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16145 | * Always report new attributes at next traversal. |
| 16146 | */ |
| 16147 | boolean mForceReportNewAttributes; |
| 16148 | |
| 16149 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16150 | * Set during a traveral if any views want to keep the screen on. |
| 16151 | */ |
| 16152 | boolean mKeepScreenOn; |
| 16153 | |
| 16154 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16155 | * Bitwise-or of all of the values that views have passed to setSystemUiVisibility(). |
| 16156 | */ |
| 16157 | int mSystemUiVisibility; |
| 16158 | |
| 16159 | /** |
| 16160 | * True if a view in this hierarchy has an OnSystemUiVisibilityChangeListener |
| 16161 | * attached. |
| 16162 | */ |
| 16163 | boolean mHasSystemUiListeners; |
| 16164 | |
| 16165 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16166 | * Set if the visibility of any views has changed. |
| 16167 | */ |
| 16168 | boolean mViewVisibilityChanged; |
| 16169 | |
| 16170 | /** |
| 16171 | * Set to true if a view has been scrolled. |
| 16172 | */ |
| 16173 | boolean mViewScrollChanged; |
| 16174 | |
| 16175 | /** |
| 16176 | * Global to the view hierarchy used as a temporary for dealing with |
| 16177 | * x/y points in the transparent region computations. |
| 16178 | */ |
| 16179 | final int[] mTransparentLocation = new int[2]; |
| 16180 | |
| 16181 | /** |
| 16182 | * Global to the view hierarchy used as a temporary for dealing with |
| 16183 | * x/y points in the ViewGroup.invalidateChild implementation. |
| 16184 | */ |
| 16185 | final int[] mInvalidateChildLocation = new int[2]; |
| 16186 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 16187 | |
| 16188 | /** |
| 16189 | * Global to the view hierarchy used as a temporary for dealing with |
| 16190 | * x/y location when view is transformed. |
| 16191 | */ |
| 16192 | final float[] mTmpTransformLocation = new float[2]; |
| 16193 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16194 | /** |
| 16195 | * The view tree observer used to dispatch global events like |
| 16196 | * layout, pre-draw, touch mode change, etc. |
| 16197 | */ |
| 16198 | final ViewTreeObserver mTreeObserver = new ViewTreeObserver(); |
| 16199 | |
| 16200 | /** |
| 16201 | * A Canvas used by the view hierarchy to perform bitmap caching. |
| 16202 | */ |
| 16203 | Canvas mCanvas; |
| 16204 | |
| 16205 | /** |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 16206 | * The view root impl. |
| 16207 | */ |
| 16208 | final ViewRootImpl mViewRootImpl; |
| 16209 | |
| 16210 | /** |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 16211 | * 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] | 16212 | * handler can be used to pump events in the UI events queue. |
| 16213 | */ |
| 16214 | final Handler mHandler; |
| 16215 | |
| 16216 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16217 | * Temporary for use in computing invalidate rectangles while |
| 16218 | * calling up the hierarchy. |
| 16219 | */ |
| 16220 | final Rect mTmpInvalRect = new Rect(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 16221 | |
| 16222 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 16223 | * Temporary for use in computing hit areas with transformed views |
| 16224 | */ |
| 16225 | final RectF mTmpTransformRect = new RectF(); |
| 16226 | |
| 16227 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 16228 | * Temporary list for use in collecting focusable descendents of a view. |
| 16229 | */ |
| 16230 | final ArrayList<View> mFocusablesTempList = new ArrayList<View>(24); |
| 16231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16232 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 16233 | * The id of the window for accessibility purposes. |
| 16234 | */ |
| 16235 | int mAccessibilityWindowId = View.NO_ID; |
| 16236 | |
| 16237 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16238 | * Creates a new set of attachment information with the specified |
| 16239 | * events handler and thread. |
| 16240 | * |
| 16241 | * @param handler the events handler the view must use |
| 16242 | */ |
| 16243 | AttachInfo(IWindowSession session, IWindow window, |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 16244 | ViewRootImpl viewRootImpl, Handler handler, Callbacks effectPlayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16245 | mSession = session; |
| 16246 | mWindow = window; |
| 16247 | mWindowToken = window.asBinder(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 16248 | mViewRootImpl = viewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16249 | mHandler = handler; |
| 16250 | mRootCallbacks = effectPlayer; |
| 16251 | } |
| 16252 | } |
| 16253 | |
| 16254 | /** |
| 16255 | * <p>ScrollabilityCache holds various fields used by a View when scrolling |
| 16256 | * is supported. This avoids keeping too many unused fields in most |
| 16257 | * instances of View.</p> |
| 16258 | */ |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16259 | private static class ScrollabilityCache implements Runnable { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16260 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16261 | /** |
| 16262 | * Scrollbars are not visible |
| 16263 | */ |
| 16264 | public static final int OFF = 0; |
| 16265 | |
| 16266 | /** |
| 16267 | * Scrollbars are visible |
| 16268 | */ |
| 16269 | public static final int ON = 1; |
| 16270 | |
| 16271 | /** |
| 16272 | * Scrollbars are fading away |
| 16273 | */ |
| 16274 | public static final int FADING = 2; |
| 16275 | |
| 16276 | public boolean fadeScrollBars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16277 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16278 | public int fadingEdgeLength; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16279 | public int scrollBarDefaultDelayBeforeFade; |
| 16280 | public int scrollBarFadeDuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16281 | |
| 16282 | public int scrollBarSize; |
| 16283 | public ScrollBarDrawable scrollBar; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16284 | public float[] interpolatorValues; |
| 16285 | public View host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16286 | |
| 16287 | public final Paint paint; |
| 16288 | public final Matrix matrix; |
| 16289 | public Shader shader; |
| 16290 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16291 | public final Interpolator scrollBarInterpolator = new Interpolator(1, 2); |
| 16292 | |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 16293 | private static final float[] OPAQUE = { 255 }; |
| 16294 | private static final float[] TRANSPARENT = { 0.0f }; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16295 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16296 | /** |
| 16297 | * When fading should start. This time moves into the future every time |
| 16298 | * a new scroll happens. Measured based on SystemClock.uptimeMillis() |
| 16299 | */ |
| 16300 | public long fadeStartTime; |
| 16301 | |
| 16302 | |
| 16303 | /** |
| 16304 | * The current state of the scrollbars: ON, OFF, or FADING |
| 16305 | */ |
| 16306 | public int state = OFF; |
| 16307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16308 | private int mLastColor; |
| 16309 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16310 | public ScrollabilityCache(ViewConfiguration configuration, View host) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16311 | fadingEdgeLength = configuration.getScaledFadingEdgeLength(); |
| 16312 | scrollBarSize = configuration.getScaledScrollBarSize(); |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 16313 | scrollBarDefaultDelayBeforeFade = ViewConfiguration.getScrollDefaultDelay(); |
| 16314 | scrollBarFadeDuration = ViewConfiguration.getScrollBarFadeDuration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16315 | |
| 16316 | paint = new Paint(); |
| 16317 | matrix = new Matrix(); |
| 16318 | // use use a height of 1, and then wack the matrix each time we |
| 16319 | // actually use it. |
| 16320 | shader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 16321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16322 | paint.setShader(shader); |
| 16323 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16324 | this.host = host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16325 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 16326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16327 | public void setFadeColor(int color) { |
| 16328 | if (color != 0 && color != mLastColor) { |
| 16329 | mLastColor = color; |
| 16330 | color |= 0xFF000000; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 16331 | |
Romain Guy | e55e1a7 | 2009-08-27 10:42:26 -0700 | [diff] [blame] | 16332 | shader = new LinearGradient(0, 0, 0, 1, color | 0xFF000000, |
| 16333 | color & 0x00FFFFFF, Shader.TileMode.CLAMP); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 16334 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16335 | paint.setShader(shader); |
| 16336 | // Restore the default transfer mode (src_over) |
| 16337 | paint.setXfermode(null); |
| 16338 | } |
| 16339 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16340 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16341 | public void run() { |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 16342 | long now = AnimationUtils.currentAnimationTimeMillis(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16343 | if (now >= fadeStartTime) { |
| 16344 | |
| 16345 | // the animation fades the scrollbars out by changing |
| 16346 | // the opacity (alpha) from fully opaque to fully |
| 16347 | // transparent |
| 16348 | int nextFrame = (int) now; |
| 16349 | int framesCount = 0; |
| 16350 | |
| 16351 | Interpolator interpolator = scrollBarInterpolator; |
| 16352 | |
| 16353 | // Start opaque |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 16354 | interpolator.setKeyFrame(framesCount++, nextFrame, OPAQUE); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16355 | |
| 16356 | // End transparent |
| 16357 | nextFrame += scrollBarFadeDuration; |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 16358 | interpolator.setKeyFrame(framesCount, nextFrame, TRANSPARENT); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16359 | |
| 16360 | state = FADING; |
| 16361 | |
| 16362 | // Kick off the fade animation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 16363 | host.invalidate(true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16364 | } |
| 16365 | } |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 16366 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16367 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 16368 | /** |
| 16369 | * Resuable callback for sending |
| 16370 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 16371 | */ |
| 16372 | private class SendViewScrolledAccessibilityEvent implements Runnable { |
| 16373 | public volatile boolean mIsPending; |
| 16374 | |
| 16375 | public void run() { |
| 16376 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED); |
| 16377 | mIsPending = false; |
| 16378 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16379 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 16380 | |
| 16381 | /** |
| 16382 | * <p> |
| 16383 | * This class represents a delegate that can be registered in a {@link View} |
| 16384 | * to enhance accessibility support via composition rather via inheritance. |
| 16385 | * It is specifically targeted to widget developers that extend basic View |
| 16386 | * classes i.e. classes in package android.view, that would like their |
| 16387 | * applications to be backwards compatible. |
| 16388 | * </p> |
Joe Fernandez | e1302ed | 2012-02-06 14:30:15 -0800 | [diff] [blame] | 16389 | * <div class="special reference"> |
| 16390 | * <h3>Developer Guides</h3> |
| 16391 | * <p>For more information about making applications accessible, read the |
| 16392 | * <a href="{@docRoot}guide/topics/ui/accessibility/index.html">Accessibility</a> |
| 16393 | * developer guide.</p> |
| 16394 | * </div> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 16395 | * <p> |
| 16396 | * A scenario in which a developer would like to use an accessibility delegate |
| 16397 | * is overriding a method introduced in a later API version then the minimal API |
| 16398 | * version supported by the application. For example, the method |
| 16399 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} is not available |
| 16400 | * in API version 4 when the accessibility APIs were first introduced. If a |
| 16401 | * developer would like his application to run on API version 4 devices (assuming |
| 16402 | * all other APIs used by the application are version 4 or lower) and take advantage |
| 16403 | * of this method, instead of overriding the method which would break the application's |
| 16404 | * backwards compatibility, he can override the corresponding method in this |
| 16405 | * delegate and register the delegate in the target View if the API version of |
| 16406 | * the system is high enough i.e. the API version is same or higher to the API |
| 16407 | * version that introduced |
| 16408 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)}. |
| 16409 | * </p> |
| 16410 | * <p> |
| 16411 | * Here is an example implementation: |
| 16412 | * </p> |
| 16413 | * <code><pre><p> |
| 16414 | * if (Build.VERSION.SDK_INT >= 14) { |
| 16415 | * // If the API version is equal of higher than the version in |
| 16416 | * // which onInitializeAccessibilityNodeInfo was introduced we |
| 16417 | * // register a delegate with a customized implementation. |
| 16418 | * View view = findViewById(R.id.view_id); |
| 16419 | * view.setAccessibilityDelegate(new AccessibilityDelegate() { |
| 16420 | * public void onInitializeAccessibilityNodeInfo(View host, |
| 16421 | * AccessibilityNodeInfo info) { |
| 16422 | * // Let the default implementation populate the info. |
| 16423 | * super.onInitializeAccessibilityNodeInfo(host, info); |
| 16424 | * // Set some other information. |
| 16425 | * info.setEnabled(host.isEnabled()); |
| 16426 | * } |
| 16427 | * }); |
| 16428 | * } |
| 16429 | * </code></pre></p> |
| 16430 | * <p> |
| 16431 | * This delegate contains methods that correspond to the accessibility methods |
| 16432 | * in View. If a delegate has been specified the implementation in View hands |
| 16433 | * off handling to the corresponding method in this delegate. The default |
| 16434 | * implementation the delegate methods behaves exactly as the corresponding |
| 16435 | * method in View for the case of no accessibility delegate been set. Hence, |
| 16436 | * to customize the behavior of a View method, clients can override only the |
| 16437 | * corresponding delegate method without altering the behavior of the rest |
| 16438 | * accessibility related methods of the host view. |
| 16439 | * </p> |
| 16440 | */ |
| 16441 | public static class AccessibilityDelegate { |
| 16442 | |
| 16443 | /** |
| 16444 | * Sends an accessibility event of the given type. If accessibility is not |
| 16445 | * enabled this method has no effect. |
| 16446 | * <p> |
| 16447 | * The default implementation behaves as {@link View#sendAccessibilityEvent(int) |
| 16448 | * View#sendAccessibilityEvent(int)} for the case of no accessibility delegate |
| 16449 | * been set. |
| 16450 | * </p> |
| 16451 | * |
| 16452 | * @param host The View hosting the delegate. |
| 16453 | * @param eventType The type of the event to send. |
| 16454 | * |
| 16455 | * @see View#sendAccessibilityEvent(int) View#sendAccessibilityEvent(int) |
| 16456 | */ |
| 16457 | public void sendAccessibilityEvent(View host, int eventType) { |
| 16458 | host.sendAccessibilityEventInternal(eventType); |
| 16459 | } |
| 16460 | |
| 16461 | /** |
| 16462 | * Sends an accessibility event. This method behaves exactly as |
| 16463 | * {@link #sendAccessibilityEvent(View, int)} but takes as an argument an |
| 16464 | * empty {@link AccessibilityEvent} and does not perform a check whether |
| 16465 | * accessibility is enabled. |
| 16466 | * <p> |
| 16467 | * The default implementation behaves as |
| 16468 | * {@link View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 16469 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent)} for |
| 16470 | * the case of no accessibility delegate been set. |
| 16471 | * </p> |
| 16472 | * |
| 16473 | * @param host The View hosting the delegate. |
| 16474 | * @param event The event to send. |
| 16475 | * |
| 16476 | * @see View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 16477 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 16478 | */ |
| 16479 | public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) { |
| 16480 | host.sendAccessibilityEventUncheckedInternal(event); |
| 16481 | } |
| 16482 | |
| 16483 | /** |
| 16484 | * Dispatches an {@link AccessibilityEvent} to the host {@link View} first and then |
| 16485 | * to its children for adding their text content to the event. |
| 16486 | * <p> |
| 16487 | * The default implementation behaves as |
| 16488 | * {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 16489 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 16490 | * the case of no accessibility delegate been set. |
| 16491 | * </p> |
| 16492 | * |
| 16493 | * @param host The View hosting the delegate. |
| 16494 | * @param event The event. |
| 16495 | * @return True if the event population was completed. |
| 16496 | * |
| 16497 | * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 16498 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 16499 | */ |
| 16500 | public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 16501 | return host.dispatchPopulateAccessibilityEventInternal(event); |
| 16502 | } |
| 16503 | |
| 16504 | /** |
| 16505 | * Gives a chance to the host View to populate the accessibility event with its |
| 16506 | * text content. |
| 16507 | * <p> |
| 16508 | * The default implementation behaves as |
| 16509 | * {@link View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 16510 | * View#onPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 16511 | * the case of no accessibility delegate been set. |
| 16512 | * </p> |
| 16513 | * |
| 16514 | * @param host The View hosting the delegate. |
| 16515 | * @param event The accessibility event which to populate. |
| 16516 | * |
| 16517 | * @see View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 16518 | * View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 16519 | */ |
| 16520 | public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 16521 | host.onPopulateAccessibilityEventInternal(event); |
| 16522 | } |
| 16523 | |
| 16524 | /** |
| 16525 | * Initializes an {@link AccessibilityEvent} with information about the |
| 16526 | * the host View which is the event source. |
| 16527 | * <p> |
| 16528 | * The default implementation behaves as |
| 16529 | * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 16530 | * View#onInitializeAccessibilityEvent(AccessibilityEvent)} for |
| 16531 | * the case of no accessibility delegate been set. |
| 16532 | * </p> |
| 16533 | * |
| 16534 | * @param host The View hosting the delegate. |
| 16535 | * @param event The event to initialize. |
| 16536 | * |
| 16537 | * @see View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 16538 | * View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 16539 | */ |
| 16540 | public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { |
| 16541 | host.onInitializeAccessibilityEventInternal(event); |
| 16542 | } |
| 16543 | |
| 16544 | /** |
| 16545 | * Initializes an {@link AccessibilityNodeInfo} with information about the host view. |
| 16546 | * <p> |
| 16547 | * The default implementation behaves as |
| 16548 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 16549 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} for |
| 16550 | * the case of no accessibility delegate been set. |
| 16551 | * </p> |
| 16552 | * |
| 16553 | * @param host The View hosting the delegate. |
| 16554 | * @param info The instance to initialize. |
| 16555 | * |
| 16556 | * @see View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 16557 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 16558 | */ |
| 16559 | public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 16560 | host.onInitializeAccessibilityNodeInfoInternal(info); |
| 16561 | } |
| 16562 | |
| 16563 | /** |
| 16564 | * Called when a child of the host View has requested sending an |
| 16565 | * {@link AccessibilityEvent} and gives an opportunity to the parent (the host) |
| 16566 | * to augment the event. |
| 16567 | * <p> |
| 16568 | * The default implementation behaves as |
| 16569 | * {@link ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 16570 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent)} for |
| 16571 | * the case of no accessibility delegate been set. |
| 16572 | * </p> |
| 16573 | * |
| 16574 | * @param host The View hosting the delegate. |
| 16575 | * @param child The child which requests sending the event. |
| 16576 | * @param event The event to be sent. |
| 16577 | * @return True if the event should be sent |
| 16578 | * |
| 16579 | * @see ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 16580 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 16581 | */ |
| 16582 | public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, |
| 16583 | AccessibilityEvent event) { |
| 16584 | return host.onRequestSendAccessibilityEventInternal(child, event); |
| 16585 | } |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 16586 | |
| 16587 | /** |
| 16588 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 16589 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 16590 | * that explore the window content. |
| 16591 | * <p> |
| 16592 | * The default implementation behaves as |
| 16593 | * {@link View#getAccessibilityNodeProvider() View#getAccessibilityNodeProvider()} for |
| 16594 | * the case of no accessibility delegate been set. |
| 16595 | * </p> |
| 16596 | * |
| 16597 | * @return The provider. |
| 16598 | * |
| 16599 | * @see AccessibilityNodeProvider |
| 16600 | */ |
| 16601 | public AccessibilityNodeProvider getAccessibilityNodeProvider(View host) { |
| 16602 | return null; |
| 16603 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 16604 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16605 | } |