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; |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 27 | import android.graphics.Insets; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 28 | import android.graphics.Interpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.graphics.LinearGradient; |
| 30 | import android.graphics.Matrix; |
| 31 | import android.graphics.Paint; |
| 32 | import android.graphics.PixelFormat; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 33 | import android.graphics.Point; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.graphics.PorterDuff; |
| 35 | import android.graphics.PorterDuffXfermode; |
| 36 | import android.graphics.Rect; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 37 | import android.graphics.RectF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.graphics.Region; |
| 39 | import android.graphics.Shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.graphics.drawable.ColorDrawable; |
| 41 | import android.graphics.drawable.Drawable; |
| 42 | import android.os.Handler; |
| 43 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import android.os.Parcel; |
| 45 | import android.os.Parcelable; |
| 46 | import android.os.RemoteException; |
| 47 | import android.os.SystemClock; |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 48 | import android.text.TextUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.util.AttributeSet; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 50 | import android.util.FloatProperty; |
| 51 | import android.util.LocaleUtil; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.util.Log; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 53 | import android.util.Pool; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 54 | import android.util.Poolable; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 55 | import android.util.PoolableManager; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 56 | import android.util.Pools; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 57 | import android.util.Property; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 58 | import android.util.SparseArray; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 59 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.view.ContextMenu.ContextMenuInfo; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 61 | import android.view.accessibility.AccessibilityEvent; |
| 62 | import android.view.accessibility.AccessibilityEventSource; |
| 63 | import android.view.accessibility.AccessibilityManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 64 | import android.view.accessibility.AccessibilityNodeInfo; |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 65 | import android.view.accessibility.AccessibilityNodeProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.view.animation.Animation; |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 67 | import android.view.animation.AnimationUtils; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 68 | import android.view.animation.Transformation; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 69 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | import android.view.inputmethod.InputConnection; |
| 71 | import android.view.inputmethod.InputMethodManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.widget.ScrollBarDrawable; |
| 73 | |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 74 | import static android.os.Build.VERSION_CODES.*; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 75 | import static java.lang.Math.max; |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 76 | |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 77 | import com.android.internal.R; |
| 78 | import com.android.internal.util.Predicate; |
| 79 | import com.android.internal.view.menu.MenuBuilder; |
| 80 | |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 81 | import java.lang.ref.WeakReference; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 82 | import java.lang.reflect.InvocationTargetException; |
| 83 | import java.lang.reflect.Method; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | import java.util.ArrayList; |
| 85 | import java.util.Arrays; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 86 | import java.util.Locale; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 87 | import java.util.concurrent.CopyOnWriteArrayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * <p> |
| 91 | * This class represents the basic building block for user interface components. A View |
| 92 | * occupies a rectangular area on the screen and is responsible for drawing and |
| 93 | * 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] | 94 | * 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] | 95 | * {@link android.view.ViewGroup} subclass is the base class for <em>layouts</em>, which |
| 96 | * are invisible containers that hold other Views (or other ViewGroups) and define |
| 97 | * their layout properties. |
| 98 | * </p> |
| 99 | * |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 100 | * <div class="special reference"> |
| 101 | * <h3>Developer Guides</h3> |
| 102 | * <p>For information about using this class to develop your application's user interface, |
| 103 | * 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] | 104 | * </div> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 105 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | * <a name="Using"></a> |
| 107 | * <h3>Using Views</h3> |
| 108 | * <p> |
| 109 | * All of the views in a window are arranged in a single tree. You can add views |
| 110 | * either from code or by specifying a tree of views in one or more XML layout |
| 111 | * files. There are many specialized subclasses of views that act as controls or |
| 112 | * are capable of displaying text, images, or other content. |
| 113 | * </p> |
| 114 | * <p> |
| 115 | * Once you have created a tree of views, there are typically a few types of |
| 116 | * common operations you may wish to perform: |
| 117 | * <ul> |
| 118 | * <li><strong>Set properties:</strong> for example setting the text of a |
| 119 | * {@link android.widget.TextView}. The available properties and the methods |
| 120 | * that set them will vary among the different subclasses of views. Note that |
| 121 | * properties that are known at build time can be set in the XML layout |
| 122 | * files.</li> |
| 123 | * <li><strong>Set focus:</strong> The framework will handled moving focus in |
| 124 | * response to user input. To force focus to a specific view, call |
| 125 | * {@link #requestFocus}.</li> |
| 126 | * <li><strong>Set up listeners:</strong> Views allow clients to set listeners |
| 127 | * that will be notified when something interesting happens to the view. For |
| 128 | * example, all views will let you set a listener to be notified when the view |
| 129 | * gains or loses focus. You can register such a listener using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 130 | * {@link #setOnFocusChangeListener(android.view.View.OnFocusChangeListener)}. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 131 | * Other view subclasses offer more specialized listeners. For example, a Button |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 132 | * 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] | 133 | * <li><strong>Set visibility:</strong> You can hide or show views using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 134 | * {@link #setVisibility(int)}.</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | * </ul> |
| 136 | * </p> |
| 137 | * <p><em> |
| 138 | * Note: The Android framework is responsible for measuring, laying out and |
| 139 | * drawing views. You should not call methods that perform these actions on |
| 140 | * views yourself unless you are actually implementing a |
| 141 | * {@link android.view.ViewGroup}. |
| 142 | * </em></p> |
| 143 | * |
| 144 | * <a name="Lifecycle"></a> |
| 145 | * <h3>Implementing a Custom View</h3> |
| 146 | * |
| 147 | * <p> |
| 148 | * To implement a custom view, you will usually begin by providing overrides for |
| 149 | * some of the standard methods that the framework calls on all views. You do |
| 150 | * not need to override all of these methods. In fact, you can start by just |
| 151 | * overriding {@link #onDraw(android.graphics.Canvas)}. |
| 152 | * <table border="2" width="85%" align="center" cellpadding="5"> |
| 153 | * <thead> |
| 154 | * <tr><th>Category</th> <th>Methods</th> <th>Description</th></tr> |
| 155 | * </thead> |
| 156 | * |
| 157 | * <tbody> |
| 158 | * <tr> |
| 159 | * <td rowspan="2">Creation</td> |
| 160 | * <td>Constructors</td> |
| 161 | * <td>There is a form of the constructor that are called when the view |
| 162 | * is created from code and a form that is called when the view is |
| 163 | * inflated from a layout file. The second form should parse and apply |
| 164 | * any attributes defined in the layout file. |
| 165 | * </td> |
| 166 | * </tr> |
| 167 | * <tr> |
| 168 | * <td><code>{@link #onFinishInflate()}</code></td> |
| 169 | * <td>Called after a view and all of its children has been inflated |
| 170 | * from XML.</td> |
| 171 | * </tr> |
| 172 | * |
| 173 | * <tr> |
| 174 | * <td rowspan="3">Layout</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 175 | * <td><code>{@link #onMeasure(int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | * <td>Called to determine the size requirements for this view and all |
| 177 | * of its children. |
| 178 | * </td> |
| 179 | * </tr> |
| 180 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 181 | * <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] | 182 | * <td>Called when this view should assign a size and position to all |
| 183 | * of its children. |
| 184 | * </td> |
| 185 | * </tr> |
| 186 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 187 | * <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] | 188 | * <td>Called when the size of this view has changed. |
| 189 | * </td> |
| 190 | * </tr> |
| 191 | * |
| 192 | * <tr> |
| 193 | * <td>Drawing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 194 | * <td><code>{@link #onDraw(android.graphics.Canvas)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | * <td>Called when the view should render its content. |
| 196 | * </td> |
| 197 | * </tr> |
| 198 | * |
| 199 | * <tr> |
| 200 | * <td rowspan="4">Event processing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 201 | * <td><code>{@link #onKeyDown(int, KeyEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | * <td>Called when a new key event occurs. |
| 203 | * </td> |
| 204 | * </tr> |
| 205 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 206 | * <td><code>{@link #onKeyUp(int, KeyEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | * <td>Called when a key up event occurs. |
| 208 | * </td> |
| 209 | * </tr> |
| 210 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 211 | * <td><code>{@link #onTrackballEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | * <td>Called when a trackball motion event occurs. |
| 213 | * </td> |
| 214 | * </tr> |
| 215 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 216 | * <td><code>{@link #onTouchEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | * <td>Called when a touch screen motion event occurs. |
| 218 | * </td> |
| 219 | * </tr> |
| 220 | * |
| 221 | * <tr> |
| 222 | * <td rowspan="2">Focus</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 223 | * <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] | 224 | * <td>Called when the view gains or loses focus. |
| 225 | * </td> |
| 226 | * </tr> |
| 227 | * |
| 228 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 229 | * <td><code>{@link #onWindowFocusChanged(boolean)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | * <td>Called when the window containing the view gains or loses focus. |
| 231 | * </td> |
| 232 | * </tr> |
| 233 | * |
| 234 | * <tr> |
| 235 | * <td rowspan="3">Attaching</td> |
| 236 | * <td><code>{@link #onAttachedToWindow()}</code></td> |
| 237 | * <td>Called when the view is attached to a window. |
| 238 | * </td> |
| 239 | * </tr> |
| 240 | * |
| 241 | * <tr> |
| 242 | * <td><code>{@link #onDetachedFromWindow}</code></td> |
| 243 | * <td>Called when the view is detached from its window. |
| 244 | * </td> |
| 245 | * </tr> |
| 246 | * |
| 247 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 248 | * <td><code>{@link #onWindowVisibilityChanged(int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | * <td>Called when the visibility of the window containing the view |
| 250 | * has changed. |
| 251 | * </td> |
| 252 | * </tr> |
| 253 | * </tbody> |
| 254 | * |
| 255 | * </table> |
| 256 | * </p> |
| 257 | * |
| 258 | * <a name="IDs"></a> |
| 259 | * <h3>IDs</h3> |
| 260 | * Views may have an integer id associated with them. These ids are typically |
| 261 | * assigned in the layout XML files, and are used to find specific views within |
| 262 | * the view tree. A common pattern is to: |
| 263 | * <ul> |
| 264 | * <li>Define a Button in the layout file and assign it a unique ID. |
| 265 | * <pre> |
Gilles Debunne | 0243caf | 2010-08-24 23:06:35 -0700 | [diff] [blame] | 266 | * <Button |
| 267 | * android:id="@+id/my_button" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | * android:layout_width="wrap_content" |
| 269 | * android:layout_height="wrap_content" |
| 270 | * android:text="@string/my_button_text"/> |
| 271 | * </pre></li> |
| 272 | * <li>From the onCreate method of an Activity, find the Button |
| 273 | * <pre class="prettyprint"> |
| 274 | * Button myButton = (Button) findViewById(R.id.my_button); |
| 275 | * </pre></li> |
| 276 | * </ul> |
| 277 | * <p> |
| 278 | * View IDs need not be unique throughout the tree, but it is good practice to |
| 279 | * ensure that they are at least unique within the part of the tree you are |
| 280 | * searching. |
| 281 | * </p> |
| 282 | * |
| 283 | * <a name="Position"></a> |
| 284 | * <h3>Position</h3> |
| 285 | * <p> |
| 286 | * The geometry of a view is that of a rectangle. A view has a location, |
| 287 | * expressed as a pair of <em>left</em> and <em>top</em> coordinates, and |
| 288 | * two dimensions, expressed as a width and a height. The unit for location |
| 289 | * and dimensions is the pixel. |
| 290 | * </p> |
| 291 | * |
| 292 | * <p> |
| 293 | * It is possible to retrieve the location of a view by invoking the methods |
| 294 | * {@link #getLeft()} and {@link #getTop()}. The former returns the left, or X, |
| 295 | * coordinate of the rectangle representing the view. The latter returns the |
| 296 | * top, or Y, coordinate of the rectangle representing the view. These methods |
| 297 | * both return the location of the view relative to its parent. For instance, |
| 298 | * when getLeft() returns 20, that means the view is located 20 pixels to the |
| 299 | * right of the left edge of its direct parent. |
| 300 | * </p> |
| 301 | * |
| 302 | * <p> |
| 303 | * In addition, several convenience methods are offered to avoid unnecessary |
| 304 | * computations, namely {@link #getRight()} and {@link #getBottom()}. |
| 305 | * These methods return the coordinates of the right and bottom edges of the |
| 306 | * rectangle representing the view. For instance, calling {@link #getRight()} |
| 307 | * is similar to the following computation: <code>getLeft() + getWidth()</code> |
| 308 | * (see <a href="#SizePaddingMargins">Size</a> for more information about the width.) |
| 309 | * </p> |
| 310 | * |
| 311 | * <a name="SizePaddingMargins"></a> |
| 312 | * <h3>Size, padding and margins</h3> |
| 313 | * <p> |
| 314 | * The size of a view is expressed with a width and a height. A view actually |
| 315 | * possess two pairs of width and height values. |
| 316 | * </p> |
| 317 | * |
| 318 | * <p> |
| 319 | * The first pair is known as <em>measured width</em> and |
| 320 | * <em>measured height</em>. These dimensions define how big a view wants to be |
| 321 | * within its parent (see <a href="#Layout">Layout</a> for more details.) The |
| 322 | * measured dimensions can be obtained by calling {@link #getMeasuredWidth()} |
| 323 | * and {@link #getMeasuredHeight()}. |
| 324 | * </p> |
| 325 | * |
| 326 | * <p> |
| 327 | * The second pair is simply known as <em>width</em> and <em>height</em>, or |
| 328 | * sometimes <em>drawing width</em> and <em>drawing height</em>. These |
| 329 | * dimensions define the actual size of the view on screen, at drawing time and |
| 330 | * after layout. These values may, but do not have to, be different from the |
| 331 | * measured width and height. The width and height can be obtained by calling |
| 332 | * {@link #getWidth()} and {@link #getHeight()}. |
| 333 | * </p> |
| 334 | * |
| 335 | * <p> |
| 336 | * To measure its dimensions, a view takes into account its padding. The padding |
| 337 | * is expressed in pixels for the left, top, right and bottom parts of the view. |
| 338 | * Padding can be used to offset the content of the view by a specific amount of |
| 339 | * pixels. For instance, a left padding of 2 will push the view's content by |
| 340 | * 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] | 341 | * {@link #setPadding(int, int, int, int)} or {@link #setPaddingRelative(int, int, int, int)} |
| 342 | * method and queried by calling {@link #getPaddingLeft()}, {@link #getPaddingTop()}, |
| 343 | * {@link #getPaddingRight()}, {@link #getPaddingBottom()}, {@link #getPaddingStart()}, |
| 344 | * {@link #getPaddingEnd()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | * </p> |
| 346 | * |
| 347 | * <p> |
| 348 | * Even though a view can define a padding, it does not provide any support for |
| 349 | * margins. However, view groups provide such a support. Refer to |
| 350 | * {@link android.view.ViewGroup} and |
| 351 | * {@link android.view.ViewGroup.MarginLayoutParams} for further information. |
| 352 | * </p> |
| 353 | * |
| 354 | * <a name="Layout"></a> |
| 355 | * <h3>Layout</h3> |
| 356 | * <p> |
| 357 | * Layout is a two pass process: a measure pass and a layout pass. The measuring |
| 358 | * pass is implemented in {@link #measure(int, int)} and is a top-down traversal |
| 359 | * of the view tree. Each view pushes dimension specifications down the tree |
| 360 | * during the recursion. At the end of the measure pass, every view has stored |
| 361 | * its measurements. The second pass happens in |
| 362 | * {@link #layout(int,int,int,int)} and is also top-down. During |
| 363 | * this pass each parent is responsible for positioning all of its children |
| 364 | * using the sizes computed in the measure pass. |
| 365 | * </p> |
| 366 | * |
| 367 | * <p> |
| 368 | * When a view's measure() method returns, its {@link #getMeasuredWidth()} and |
| 369 | * {@link #getMeasuredHeight()} values must be set, along with those for all of |
| 370 | * that view's descendants. A view's measured width and measured height values |
| 371 | * must respect the constraints imposed by the view's parents. This guarantees |
| 372 | * that at the end of the measure pass, all parents accept all of their |
| 373 | * children's measurements. A parent view may call measure() more than once on |
| 374 | * its children. For example, the parent may measure each child once with |
| 375 | * unspecified dimensions to find out how big they want to be, then call |
| 376 | * measure() on them again with actual numbers if the sum of all the children's |
| 377 | * unconstrained sizes is too big or too small. |
| 378 | * </p> |
| 379 | * |
| 380 | * <p> |
| 381 | * The measure pass uses two classes to communicate dimensions. The |
| 382 | * {@link MeasureSpec} class is used by views to tell their parents how they |
| 383 | * want to be measured and positioned. The base LayoutParams class just |
| 384 | * describes how big the view wants to be for both width and height. For each |
| 385 | * dimension, it can specify one of: |
| 386 | * <ul> |
| 387 | * <li> an exact number |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 388 | * <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] | 389 | * (minus padding) |
| 390 | * <li> WRAP_CONTENT, which means that the view wants to be just big enough to |
| 391 | * enclose its content (plus padding). |
| 392 | * </ul> |
| 393 | * There are subclasses of LayoutParams for different subclasses of ViewGroup. |
| 394 | * For example, AbsoluteLayout has its own subclass of LayoutParams which adds |
| 395 | * an X and Y value. |
| 396 | * </p> |
| 397 | * |
| 398 | * <p> |
| 399 | * MeasureSpecs are used to push requirements down the tree from parent to |
| 400 | * child. A MeasureSpec can be in one of three modes: |
| 401 | * <ul> |
| 402 | * <li>UNSPECIFIED: This is used by a parent to determine the desired dimension |
| 403 | * of a child view. For example, a LinearLayout may call measure() on its child |
| 404 | * with the height set to UNSPECIFIED and a width of EXACTLY 240 to find out how |
| 405 | * tall the child view wants to be given a width of 240 pixels. |
| 406 | * <li>EXACTLY: This is used by the parent to impose an exact size on the |
| 407 | * child. The child must use this size, and guarantee that all of its |
| 408 | * descendants will fit within this size. |
| 409 | * <li>AT_MOST: This is used by the parent to impose a maximum size on the |
| 410 | * child. The child must gurantee that it and all of its descendants will fit |
| 411 | * within this size. |
| 412 | * </ul> |
| 413 | * </p> |
| 414 | * |
| 415 | * <p> |
| 416 | * To intiate a layout, call {@link #requestLayout}. This method is typically |
| 417 | * called by a view on itself when it believes that is can no longer fit within |
| 418 | * its current bounds. |
| 419 | * </p> |
| 420 | * |
| 421 | * <a name="Drawing"></a> |
| 422 | * <h3>Drawing</h3> |
| 423 | * <p> |
| 424 | * Drawing is handled by walking the tree and rendering each view that |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 425 | * 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] | 426 | * this means that parents will draw before (i.e., behind) their children, with |
| 427 | * siblings drawn in the order they appear in the tree. |
| 428 | * If you set a background drawable for a View, then the View will draw it for you |
| 429 | * before calling back to its <code>onDraw()</code> method. |
| 430 | * </p> |
| 431 | * |
| 432 | * <p> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 433 | * 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] | 434 | * </p> |
| 435 | * |
| 436 | * <p> |
| 437 | * To force a view to draw, call {@link #invalidate()}. |
| 438 | * </p> |
| 439 | * |
| 440 | * <a name="EventHandlingThreading"></a> |
| 441 | * <h3>Event Handling and Threading</h3> |
| 442 | * <p> |
| 443 | * The basic cycle of a view is as follows: |
| 444 | * <ol> |
| 445 | * <li>An event comes in and is dispatched to the appropriate view. The view |
| 446 | * handles the event and notifies any listeners.</li> |
| 447 | * <li>If in the course of processing the event, the view's bounds may need |
| 448 | * to be changed, the view will call {@link #requestLayout()}.</li> |
| 449 | * <li>Similarly, if in the course of processing the event the view's appearance |
| 450 | * may need to be changed, the view will call {@link #invalidate()}.</li> |
| 451 | * <li>If either {@link #requestLayout()} or {@link #invalidate()} were called, |
| 452 | * the framework will take care of measuring, laying out, and drawing the tree |
| 453 | * as appropriate.</li> |
| 454 | * </ol> |
| 455 | * </p> |
| 456 | * |
| 457 | * <p><em>Note: The entire view tree is single threaded. You must always be on |
| 458 | * the UI thread when calling any method on any view.</em> |
| 459 | * If you are doing work on other threads and want to update the state of a view |
| 460 | * from that thread, you should use a {@link Handler}. |
| 461 | * </p> |
| 462 | * |
| 463 | * <a name="FocusHandling"></a> |
| 464 | * <h3>Focus Handling</h3> |
| 465 | * <p> |
| 466 | * The framework will handle routine focus movement in response to user input. |
| 467 | * This includes changing the focus as views are removed or hidden, or as new |
| 468 | * views become available. Views indicate their willingness to take focus |
| 469 | * through the {@link #isFocusable} method. To change whether a view can take |
| 470 | * focus, call {@link #setFocusable(boolean)}. When in touch mode (see notes below) |
| 471 | * views indicate whether they still would like focus via {@link #isFocusableInTouchMode} |
| 472 | * and can change this via {@link #setFocusableInTouchMode(boolean)}. |
| 473 | * </p> |
| 474 | * <p> |
| 475 | * Focus movement is based on an algorithm which finds the nearest neighbor in a |
| 476 | * given direction. In rare cases, the default algorithm may not match the |
| 477 | * intended behavior of the developer. In these situations, you can provide |
| 478 | * explicit overrides by using these XML attributes in the layout file: |
| 479 | * <pre> |
| 480 | * nextFocusDown |
| 481 | * nextFocusLeft |
| 482 | * nextFocusRight |
| 483 | * nextFocusUp |
| 484 | * </pre> |
| 485 | * </p> |
| 486 | * |
| 487 | * |
| 488 | * <p> |
| 489 | * To get a particular view to take focus, call {@link #requestFocus()}. |
| 490 | * </p> |
| 491 | * |
| 492 | * <a name="TouchMode"></a> |
| 493 | * <h3>Touch Mode</h3> |
| 494 | * <p> |
| 495 | * When a user is navigating a user interface via directional keys such as a D-pad, it is |
| 496 | * necessary to give focus to actionable items such as buttons so the user can see |
| 497 | * what will take input. If the device has touch capabilities, however, and the user |
| 498 | * begins interacting with the interface by touching it, it is no longer necessary to |
| 499 | * always highlight, or give focus to, a particular view. This motivates a mode |
| 500 | * for interaction named 'touch mode'. |
| 501 | * </p> |
| 502 | * <p> |
| 503 | * For a touch capable device, once the user touches the screen, the device |
| 504 | * will enter touch mode. From this point onward, only views for which |
| 505 | * {@link #isFocusableInTouchMode} is true will be focusable, such as text editing widgets. |
| 506 | * Other views that are touchable, like buttons, will not take focus when touched; they will |
| 507 | * only fire the on click listeners. |
| 508 | * </p> |
| 509 | * <p> |
| 510 | * Any time a user hits a directional key, such as a D-pad direction, the view device will |
| 511 | * exit touch mode, and find a view to take focus, so that the user may resume interacting |
| 512 | * with the user interface without touching the screen again. |
| 513 | * </p> |
| 514 | * <p> |
| 515 | * The touch mode state is maintained across {@link android.app.Activity}s. Call |
| 516 | * {@link #isInTouchMode} to see whether the device is currently in touch mode. |
| 517 | * </p> |
| 518 | * |
| 519 | * <a name="Scrolling"></a> |
| 520 | * <h3>Scrolling</h3> |
| 521 | * <p> |
| 522 | * The framework provides basic support for views that wish to internally |
| 523 | * scroll their content. This includes keeping track of the X and Y scroll |
| 524 | * offset as well as mechanisms for drawing scrollbars. See |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 525 | * {@link #scrollBy(int, int)}, {@link #scrollTo(int, int)}, and |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 526 | * {@link #awakenScrollBars()} for more details. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | * </p> |
| 528 | * |
| 529 | * <a name="Tags"></a> |
| 530 | * <h3>Tags</h3> |
| 531 | * <p> |
| 532 | * Unlike IDs, tags are not used to identify views. Tags are essentially an |
| 533 | * extra piece of information that can be associated with a view. They are most |
| 534 | * often used as a convenience to store data related to views in the views |
| 535 | * themselves rather than by putting them in a separate structure. |
| 536 | * </p> |
| 537 | * |
| 538 | * <a name="Animation"></a> |
| 539 | * <h3>Animation</h3> |
| 540 | * <p> |
| 541 | * You can attach an {@link Animation} object to a view using |
| 542 | * {@link #setAnimation(Animation)} or |
| 543 | * {@link #startAnimation(Animation)}. The animation can alter the scale, |
| 544 | * rotation, translation and alpha of a view over time. If the animation is |
| 545 | * attached to a view that has children, the animation will affect the entire |
| 546 | * subtree rooted by that node. When an animation is started, the framework will |
| 547 | * take care of redrawing the appropriate views until the animation completes. |
| 548 | * </p> |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 549 | * <p> |
| 550 | * Starting with Android 3.0, the preferred way of animating views is to use the |
| 551 | * {@link android.animation} package APIs. |
| 552 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 554 | * <a name="Security"></a> |
| 555 | * <h3>Security</h3> |
| 556 | * <p> |
| 557 | * Sometimes it is essential that an application be able to verify that an action |
| 558 | * is being performed with the full knowledge and consent of the user, such as |
| 559 | * granting a permission request, making a purchase or clicking on an advertisement. |
| 560 | * Unfortunately, a malicious application could try to spoof the user into |
| 561 | * performing these actions, unaware, by concealing the intended purpose of the view. |
| 562 | * As a remedy, the framework offers a touch filtering mechanism that can be used to |
| 563 | * improve the security of views that provide access to sensitive functionality. |
| 564 | * </p><p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 565 | * To enable touch filtering, call {@link #setFilterTouchesWhenObscured(boolean)} or set the |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 566 | * android:filterTouchesWhenObscured layout attribute to true. When enabled, the framework |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 567 | * will discard touches that are received whenever the view's window is obscured by |
| 568 | * another visible window. As a result, the view will not receive touches whenever a |
| 569 | * toast, dialog or other window appears above the view's window. |
| 570 | * </p><p> |
| 571 | * For more fine-grained control over security, consider overriding the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 572 | * {@link #onFilterTouchEventForSecurity(MotionEvent)} method to implement your own |
| 573 | * security policy. See also {@link MotionEvent#FLAG_WINDOW_IS_OBSCURED}. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 574 | * </p> |
| 575 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 576 | * @attr ref android.R.styleable#View_alpha |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 577 | * @attr ref android.R.styleable#View_background |
| 578 | * @attr ref android.R.styleable#View_clickable |
| 579 | * @attr ref android.R.styleable#View_contentDescription |
| 580 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 581 | * @attr ref android.R.styleable#View_duplicateParentState |
| 582 | * @attr ref android.R.styleable#View_id |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 583 | * @attr ref android.R.styleable#View_requiresFadingEdge |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 584 | * @attr ref android.R.styleable#View_fadeScrollbars |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 585 | * @attr ref android.R.styleable#View_fadingEdgeLength |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 586 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 588 | * @attr ref android.R.styleable#View_isScrollContainer |
| 589 | * @attr ref android.R.styleable#View_focusable |
| 590 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 591 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 592 | * @attr ref android.R.styleable#View_keepScreenOn |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 593 | * @attr ref android.R.styleable#View_layerType |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 594 | * @attr ref android.R.styleable#View_longClickable |
| 595 | * @attr ref android.R.styleable#View_minHeight |
| 596 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 597 | * @attr ref android.R.styleable#View_nextFocusDown |
| 598 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 599 | * @attr ref android.R.styleable#View_nextFocusRight |
| 600 | * @attr ref android.R.styleable#View_nextFocusUp |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 601 | * @attr ref android.R.styleable#View_onClick |
| 602 | * @attr ref android.R.styleable#View_padding |
| 603 | * @attr ref android.R.styleable#View_paddingBottom |
| 604 | * @attr ref android.R.styleable#View_paddingLeft |
| 605 | * @attr ref android.R.styleable#View_paddingRight |
| 606 | * @attr ref android.R.styleable#View_paddingTop |
Fabrice Di Meglio | 101d5aa | 2012-02-16 18:36:06 -0800 | [diff] [blame] | 607 | * @attr ref android.R.styleable#View_paddingStart |
| 608 | * @attr ref android.R.styleable#View_paddingEnd |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 609 | * @attr ref android.R.styleable#View_saveEnabled |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 610 | * @attr ref android.R.styleable#View_rotation |
| 611 | * @attr ref android.R.styleable#View_rotationX |
| 612 | * @attr ref android.R.styleable#View_rotationY |
| 613 | * @attr ref android.R.styleable#View_scaleX |
| 614 | * @attr ref android.R.styleable#View_scaleY |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 615 | * @attr ref android.R.styleable#View_scrollX |
| 616 | * @attr ref android.R.styleable#View_scrollY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 617 | * @attr ref android.R.styleable#View_scrollbarSize |
| 618 | * @attr ref android.R.styleable#View_scrollbarStyle |
| 619 | * @attr ref android.R.styleable#View_scrollbars |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 620 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 621 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 622 | * @attr ref android.R.styleable#View_scrollbarTrackHorizontal |
| 623 | * @attr ref android.R.styleable#View_scrollbarThumbHorizontal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | * @attr ref android.R.styleable#View_scrollbarThumbVertical |
| 625 | * @attr ref android.R.styleable#View_scrollbarTrackVertical |
| 626 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawHorizontalTrack |
| 627 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawVerticalTrack |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 628 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 629 | * @attr ref android.R.styleable#View_tag |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 630 | * @attr ref android.R.styleable#View_textAlignment |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 631 | * @attr ref android.R.styleable#View_transformPivotX |
| 632 | * @attr ref android.R.styleable#View_transformPivotY |
| 633 | * @attr ref android.R.styleable#View_translationX |
| 634 | * @attr ref android.R.styleable#View_translationY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 635 | * @attr ref android.R.styleable#View_visibility |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 636 | * |
| 637 | * @see android.view.ViewGroup |
| 638 | */ |
Adam Powell | 8fc54f9 | 2011-09-07 16:40:45 -0700 | [diff] [blame] | 639 | public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Callback, |
| 640 | AccessibilityEventSource { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | private static final boolean DBG = false; |
| 642 | |
| 643 | /** |
| 644 | * The logging tag used by this class with android.util.Log. |
| 645 | */ |
| 646 | protected static final String VIEW_LOG_TAG = "View"; |
| 647 | |
| 648 | /** |
| 649 | * Used to mark a View that has no ID. |
| 650 | */ |
| 651 | public static final int NO_ID = -1; |
| 652 | |
| 653 | /** |
| 654 | * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when |
| 655 | * calling setFlags. |
| 656 | */ |
| 657 | private static final int NOT_FOCUSABLE = 0x00000000; |
| 658 | |
| 659 | /** |
| 660 | * This view wants keystrokes. Use with TAKES_FOCUS_MASK when calling |
| 661 | * setFlags. |
| 662 | */ |
| 663 | private static final int FOCUSABLE = 0x00000001; |
| 664 | |
| 665 | /** |
| 666 | * Mask for use with setFlags indicating bits used for focus. |
| 667 | */ |
| 668 | private static final int FOCUSABLE_MASK = 0x00000001; |
| 669 | |
| 670 | /** |
| 671 | * This view will adjust its padding to fit sytem windows (e.g. status bar) |
| 672 | */ |
| 673 | private static final int FITS_SYSTEM_WINDOWS = 0x00000002; |
| 674 | |
| 675 | /** |
Scott Main | 812634c2 | 2011-07-27 13:22:35 -0700 | [diff] [blame] | 676 | * This view is visible. |
| 677 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 678 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 679 | */ |
| 680 | public static final int VISIBLE = 0x00000000; |
| 681 | |
| 682 | /** |
| 683 | * 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] | 684 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 685 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 686 | */ |
| 687 | public static final int INVISIBLE = 0x00000004; |
| 688 | |
| 689 | /** |
| 690 | * 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] | 691 | * purposes. Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 692 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 693 | */ |
| 694 | public static final int GONE = 0x00000008; |
| 695 | |
| 696 | /** |
| 697 | * Mask for use with setFlags indicating bits used for visibility. |
| 698 | * {@hide} |
| 699 | */ |
| 700 | static final int VISIBILITY_MASK = 0x0000000C; |
| 701 | |
| 702 | private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE}; |
| 703 | |
| 704 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 705 | * This view is enabled. Interpretation varies by subclass. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 706 | * Use with ENABLED_MASK when calling setFlags. |
| 707 | * {@hide} |
| 708 | */ |
| 709 | static final int ENABLED = 0x00000000; |
| 710 | |
| 711 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 712 | * This view is disabled. Interpretation varies by subclass. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | * Use with ENABLED_MASK when calling setFlags. |
| 714 | * {@hide} |
| 715 | */ |
| 716 | static final int DISABLED = 0x00000020; |
| 717 | |
| 718 | /** |
| 719 | * Mask for use with setFlags indicating bits used for indicating whether |
| 720 | * this view is enabled |
| 721 | * {@hide} |
| 722 | */ |
| 723 | static final int ENABLED_MASK = 0x00000020; |
| 724 | |
| 725 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 726 | * This view won't draw. {@link #onDraw(android.graphics.Canvas)} won't be |
| 727 | * called and further optimizations will be performed. It is okay to have |
| 728 | * 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] | 729 | * {@hide} |
| 730 | */ |
| 731 | static final int WILL_NOT_DRAW = 0x00000080; |
| 732 | |
| 733 | /** |
| 734 | * Mask for use with setFlags indicating bits used for indicating whether |
| 735 | * this view is will draw |
| 736 | * {@hide} |
| 737 | */ |
| 738 | static final int DRAW_MASK = 0x00000080; |
| 739 | |
| 740 | /** |
| 741 | * <p>This view doesn't show scrollbars.</p> |
| 742 | * {@hide} |
| 743 | */ |
| 744 | static final int SCROLLBARS_NONE = 0x00000000; |
| 745 | |
| 746 | /** |
| 747 | * <p>This view shows horizontal scrollbars.</p> |
| 748 | * {@hide} |
| 749 | */ |
| 750 | static final int SCROLLBARS_HORIZONTAL = 0x00000100; |
| 751 | |
| 752 | /** |
| 753 | * <p>This view shows vertical scrollbars.</p> |
| 754 | * {@hide} |
| 755 | */ |
| 756 | static final int SCROLLBARS_VERTICAL = 0x00000200; |
| 757 | |
| 758 | /** |
| 759 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 760 | * scrollbars are enabled.</p> |
| 761 | * {@hide} |
| 762 | */ |
| 763 | static final int SCROLLBARS_MASK = 0x00000300; |
| 764 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 765 | /** |
| 766 | * Indicates that the view should filter touches when its window is obscured. |
| 767 | * Refer to the class comments for more information about this security feature. |
| 768 | * {@hide} |
| 769 | */ |
| 770 | static final int FILTER_TOUCHES_WHEN_OBSCURED = 0x00000400; |
| 771 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 772 | /** |
| 773 | * Set for framework elements that use FITS_SYSTEM_WINDOWS, to indicate |
| 774 | * that they are optional and should be skipped if the window has |
| 775 | * requested system UI flags that ignore those insets for layout. |
| 776 | */ |
| 777 | static final int OPTIONAL_FITS_SYSTEM_WINDOWS = 0x00000800; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | |
| 779 | /** |
| 780 | * <p>This view doesn't show fading edges.</p> |
| 781 | * {@hide} |
| 782 | */ |
| 783 | static final int FADING_EDGE_NONE = 0x00000000; |
| 784 | |
| 785 | /** |
| 786 | * <p>This view shows horizontal fading edges.</p> |
| 787 | * {@hide} |
| 788 | */ |
| 789 | static final int FADING_EDGE_HORIZONTAL = 0x00001000; |
| 790 | |
| 791 | /** |
| 792 | * <p>This view shows vertical fading edges.</p> |
| 793 | * {@hide} |
| 794 | */ |
| 795 | static final int FADING_EDGE_VERTICAL = 0x00002000; |
| 796 | |
| 797 | /** |
| 798 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 799 | * fading edges are enabled.</p> |
| 800 | * {@hide} |
| 801 | */ |
| 802 | static final int FADING_EDGE_MASK = 0x00003000; |
| 803 | |
| 804 | /** |
| 805 | * <p>Indicates this view can be clicked. When clickable, a View reacts |
| 806 | * to clicks by notifying the OnClickListener.<p> |
| 807 | * {@hide} |
| 808 | */ |
| 809 | static final int CLICKABLE = 0x00004000; |
| 810 | |
| 811 | /** |
| 812 | * <p>Indicates this view is caching its drawing into a bitmap.</p> |
| 813 | * {@hide} |
| 814 | */ |
| 815 | static final int DRAWING_CACHE_ENABLED = 0x00008000; |
| 816 | |
| 817 | /** |
| 818 | * <p>Indicates that no icicle should be saved for this view.<p> |
| 819 | * {@hide} |
| 820 | */ |
| 821 | static final int SAVE_DISABLED = 0x000010000; |
| 822 | |
| 823 | /** |
| 824 | * <p>Mask for use with setFlags indicating bits used for the saveEnabled |
| 825 | * property.</p> |
| 826 | * {@hide} |
| 827 | */ |
| 828 | static final int SAVE_DISABLED_MASK = 0x000010000; |
| 829 | |
| 830 | /** |
| 831 | * <p>Indicates that no drawing cache should ever be created for this view.<p> |
| 832 | * {@hide} |
| 833 | */ |
| 834 | static final int WILL_NOT_CACHE_DRAWING = 0x000020000; |
| 835 | |
| 836 | /** |
| 837 | * <p>Indicates this view can take / keep focus when int touch mode.</p> |
| 838 | * {@hide} |
| 839 | */ |
| 840 | static final int FOCUSABLE_IN_TOUCH_MODE = 0x00040000; |
| 841 | |
| 842 | /** |
| 843 | * <p>Enables low quality mode for the drawing cache.</p> |
| 844 | */ |
| 845 | public static final int DRAWING_CACHE_QUALITY_LOW = 0x00080000; |
| 846 | |
| 847 | /** |
| 848 | * <p>Enables high quality mode for the drawing cache.</p> |
| 849 | */ |
| 850 | public static final int DRAWING_CACHE_QUALITY_HIGH = 0x00100000; |
| 851 | |
| 852 | /** |
| 853 | * <p>Enables automatic quality mode for the drawing cache.</p> |
| 854 | */ |
| 855 | public static final int DRAWING_CACHE_QUALITY_AUTO = 0x00000000; |
| 856 | |
| 857 | private static final int[] DRAWING_CACHE_QUALITY_FLAGS = { |
| 858 | DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_LOW, DRAWING_CACHE_QUALITY_HIGH |
| 859 | }; |
| 860 | |
| 861 | /** |
| 862 | * <p>Mask for use with setFlags indicating bits used for the cache |
| 863 | * quality property.</p> |
| 864 | * {@hide} |
| 865 | */ |
| 866 | static final int DRAWING_CACHE_QUALITY_MASK = 0x00180000; |
| 867 | |
| 868 | /** |
| 869 | * <p> |
| 870 | * Indicates this view can be long clicked. When long clickable, a View |
| 871 | * reacts to long clicks by notifying the OnLongClickListener or showing a |
| 872 | * context menu. |
| 873 | * </p> |
| 874 | * {@hide} |
| 875 | */ |
| 876 | static final int LONG_CLICKABLE = 0x00200000; |
| 877 | |
| 878 | /** |
| 879 | * <p>Indicates that this view gets its drawable states from its direct parent |
| 880 | * and ignores its original internal states.</p> |
| 881 | * |
| 882 | * @hide |
| 883 | */ |
| 884 | static final int DUPLICATE_PARENT_STATE = 0x00400000; |
| 885 | |
| 886 | /** |
| 887 | * The scrollbar style to display the scrollbars inside the content area, |
| 888 | * without increasing the padding. The scrollbars will be overlaid with |
| 889 | * translucency on the view's content. |
| 890 | */ |
| 891 | public static final int SCROLLBARS_INSIDE_OVERLAY = 0; |
| 892 | |
| 893 | /** |
| 894 | * The scrollbar style to display the scrollbars inside the padded area, |
| 895 | * increasing the padding of the view. The scrollbars will not overlap the |
| 896 | * content area of the view. |
| 897 | */ |
| 898 | public static final int SCROLLBARS_INSIDE_INSET = 0x01000000; |
| 899 | |
| 900 | /** |
| 901 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 902 | * without increasing the padding. The scrollbars will be overlaid with |
| 903 | * translucency. |
| 904 | */ |
| 905 | public static final int SCROLLBARS_OUTSIDE_OVERLAY = 0x02000000; |
| 906 | |
| 907 | /** |
| 908 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 909 | * increasing the padding of the view. The scrollbars will only overlap the |
| 910 | * background, if any. |
| 911 | */ |
| 912 | public static final int SCROLLBARS_OUTSIDE_INSET = 0x03000000; |
| 913 | |
| 914 | /** |
| 915 | * Mask to check if the scrollbar style is overlay or inset. |
| 916 | * {@hide} |
| 917 | */ |
| 918 | static final int SCROLLBARS_INSET_MASK = 0x01000000; |
| 919 | |
| 920 | /** |
| 921 | * Mask to check if the scrollbar style is inside or outside. |
| 922 | * {@hide} |
| 923 | */ |
| 924 | static final int SCROLLBARS_OUTSIDE_MASK = 0x02000000; |
| 925 | |
| 926 | /** |
| 927 | * Mask for scrollbar style. |
| 928 | * {@hide} |
| 929 | */ |
| 930 | static final int SCROLLBARS_STYLE_MASK = 0x03000000; |
| 931 | |
| 932 | /** |
| 933 | * View flag indicating that the screen should remain on while the |
| 934 | * window containing this view is visible to the user. This effectively |
| 935 | * takes care of automatically setting the WindowManager's |
| 936 | * {@link WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON}. |
| 937 | */ |
| 938 | public static final int KEEP_SCREEN_ON = 0x04000000; |
| 939 | |
| 940 | /** |
| 941 | * View flag indicating whether this view should have sound effects enabled |
| 942 | * for events such as clicking and touching. |
| 943 | */ |
| 944 | public static final int SOUND_EFFECTS_ENABLED = 0x08000000; |
| 945 | |
| 946 | /** |
| 947 | * View flag indicating whether this view should have haptic feedback |
| 948 | * enabled for events such as long presses. |
| 949 | */ |
| 950 | public static final int HAPTIC_FEEDBACK_ENABLED = 0x10000000; |
| 951 | |
| 952 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 953 | * <p>Indicates that the view hierarchy should stop saving state when |
| 954 | * it reaches this view. If state saving is initiated immediately at |
| 955 | * the view, it will be allowed. |
| 956 | * {@hide} |
| 957 | */ |
| 958 | static final int PARENT_SAVE_DISABLED = 0x20000000; |
| 959 | |
| 960 | /** |
| 961 | * <p>Mask for use with setFlags indicating bits used for PARENT_SAVE_DISABLED.</p> |
| 962 | * {@hide} |
| 963 | */ |
| 964 | static final int PARENT_SAVE_DISABLED_MASK = 0x20000000; |
| 965 | |
| 966 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 967 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 968 | * should add all focusable Views regardless if they are focusable in touch mode. |
| 969 | */ |
| 970 | public static final int FOCUSABLES_ALL = 0x00000000; |
| 971 | |
| 972 | /** |
| 973 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 974 | * should add only Views focusable in touch mode. |
| 975 | */ |
| 976 | public static final int FOCUSABLES_TOUCH_MODE = 0x00000001; |
| 977 | |
| 978 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 979 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 980 | * should add only accessibility focusable Views. |
| 981 | * |
| 982 | * @hide |
| 983 | */ |
| 984 | public static final int FOCUSABLES_ACCESSIBILITY = 0x00000002; |
| 985 | |
| 986 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 987 | * Use with {@link #focusSearch(int)}. Move focus to the previous selectable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 988 | * item. |
| 989 | */ |
| 990 | public static final int FOCUS_BACKWARD = 0x00000001; |
| 991 | |
| 992 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 993 | * 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] | 994 | * item. |
| 995 | */ |
| 996 | public static final int FOCUS_FORWARD = 0x00000002; |
| 997 | |
| 998 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 999 | * 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] | 1000 | */ |
| 1001 | public static final int FOCUS_LEFT = 0x00000011; |
| 1002 | |
| 1003 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1004 | * Use with {@link #focusSearch(int)}. Move focus up. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1005 | */ |
| 1006 | public static final int FOCUS_UP = 0x00000021; |
| 1007 | |
| 1008 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1009 | * 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] | 1010 | */ |
| 1011 | public static final int FOCUS_RIGHT = 0x00000042; |
| 1012 | |
| 1013 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1014 | * Use with {@link #focusSearch(int)}. Move focus down. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | */ |
| 1016 | public static final int FOCUS_DOWN = 0x00000082; |
| 1017 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1018 | // Accessibility focus directions. |
| 1019 | |
| 1020 | /** |
| 1021 | * The accessibility focus which is the current user position when |
| 1022 | * interacting with the accessibility framework. |
| 1023 | */ |
| 1024 | public static final int FOCUS_ACCESSIBILITY = 0x00001000; |
| 1025 | |
| 1026 | /** |
| 1027 | * Use with {@link #focusSearch(int)}. Move acessibility focus left. |
| 1028 | */ |
| 1029 | public static final int ACCESSIBILITY_FOCUS_LEFT = FOCUS_LEFT | FOCUS_ACCESSIBILITY; |
| 1030 | |
| 1031 | /** |
| 1032 | * Use with {@link #focusSearch(int)}. Move acessibility focus up. |
| 1033 | */ |
| 1034 | public static final int ACCESSIBILITY_FOCUS_UP = FOCUS_UP | FOCUS_ACCESSIBILITY; |
| 1035 | |
| 1036 | /** |
| 1037 | * Use with {@link #focusSearch(int)}. Move acessibility focus right. |
| 1038 | */ |
| 1039 | public static final int ACCESSIBILITY_FOCUS_RIGHT = FOCUS_RIGHT | FOCUS_ACCESSIBILITY; |
| 1040 | |
| 1041 | /** |
| 1042 | * Use with {@link #focusSearch(int)}. Move acessibility focus down. |
| 1043 | */ |
| 1044 | public static final int ACCESSIBILITY_FOCUS_DOWN = FOCUS_DOWN | FOCUS_ACCESSIBILITY; |
| 1045 | |
| 1046 | /** |
| 1047 | * Use with {@link #focusSearch(int)}. Move acessibility focus to the next view. |
| 1048 | */ |
| 1049 | public static final int ACCESSIBILITY_FOCUS_FORWARD = FOCUS_FORWARD | FOCUS_ACCESSIBILITY; |
| 1050 | |
| 1051 | /** |
| 1052 | * Use with {@link #focusSearch(int)}. Move acessibility focus to the previous view. |
| 1053 | */ |
| 1054 | public static final int ACCESSIBILITY_FOCUS_BACKWARD = FOCUS_BACKWARD | FOCUS_ACCESSIBILITY; |
| 1055 | |
| 1056 | /** |
| 1057 | * Use with {@link #focusSearch(int)}. Move acessibility focus in a view. |
| 1058 | */ |
| 1059 | public static final int ACCESSIBILITY_FOCUS_IN = 0x00000004 | FOCUS_ACCESSIBILITY; |
| 1060 | |
| 1061 | /** |
| 1062 | * Use with {@link #focusSearch(int)}. Move acessibility focus out of a view. |
| 1063 | */ |
| 1064 | public static final int ACCESSIBILITY_FOCUS_OUT = 0x00000008 | FOCUS_ACCESSIBILITY; |
| 1065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1066 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1067 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1068 | * {@link #getMeasuredWidthAndState()} that provide the actual measured size. |
| 1069 | */ |
| 1070 | public static final int MEASURED_SIZE_MASK = 0x00ffffff; |
| 1071 | |
| 1072 | /** |
| 1073 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1074 | * {@link #getMeasuredWidthAndState()} that provide the additional state bits. |
| 1075 | */ |
| 1076 | public static final int MEASURED_STATE_MASK = 0xff000000; |
| 1077 | |
| 1078 | /** |
| 1079 | * Bit shift of {@link #MEASURED_STATE_MASK} to get to the height bits |
| 1080 | * for functions that combine both width and height into a single int, |
| 1081 | * such as {@link #getMeasuredState()} and the childState argument of |
| 1082 | * {@link #resolveSizeAndState(int, int, int)}. |
| 1083 | */ |
| 1084 | public static final int MEASURED_HEIGHT_STATE_SHIFT = 16; |
| 1085 | |
| 1086 | /** |
| 1087 | * Bit of {@link #getMeasuredWidthAndState()} and |
| 1088 | * {@link #getMeasuredWidthAndState()} that indicates the measured size |
| 1089 | * is smaller that the space the view would like to have. |
| 1090 | */ |
| 1091 | public static final int MEASURED_STATE_TOO_SMALL = 0x01000000; |
| 1092 | |
| 1093 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1094 | * Base View state sets |
| 1095 | */ |
| 1096 | // Singles |
| 1097 | /** |
| 1098 | * Indicates the view has no states set. States are used with |
| 1099 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1100 | * view depending on its state. |
| 1101 | * |
| 1102 | * @see android.graphics.drawable.Drawable |
| 1103 | * @see #getDrawableState() |
| 1104 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1105 | protected static final int[] EMPTY_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | /** |
| 1107 | * Indicates the view is enabled. States are used with |
| 1108 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1109 | * view depending on its state. |
| 1110 | * |
| 1111 | * @see android.graphics.drawable.Drawable |
| 1112 | * @see #getDrawableState() |
| 1113 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1114 | protected static final int[] ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | /** |
| 1116 | * Indicates the view is focused. States are used with |
| 1117 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1118 | * view depending on its state. |
| 1119 | * |
| 1120 | * @see android.graphics.drawable.Drawable |
| 1121 | * @see #getDrawableState() |
| 1122 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1123 | protected static final int[] FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1124 | /** |
| 1125 | * Indicates the view is selected. States are used with |
| 1126 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1127 | * view depending on its state. |
| 1128 | * |
| 1129 | * @see android.graphics.drawable.Drawable |
| 1130 | * @see #getDrawableState() |
| 1131 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1132 | protected static final int[] SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1133 | /** |
| 1134 | * Indicates the view is pressed. States are used with |
| 1135 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1136 | * view depending on its state. |
| 1137 | * |
| 1138 | * @see android.graphics.drawable.Drawable |
| 1139 | * @see #getDrawableState() |
| 1140 | * @hide |
| 1141 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1142 | protected static final int[] PRESSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1143 | /** |
| 1144 | * Indicates the view's window has focus. States are used with |
| 1145 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1146 | * view depending on its state. |
| 1147 | * |
| 1148 | * @see android.graphics.drawable.Drawable |
| 1149 | * @see #getDrawableState() |
| 1150 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1151 | protected static final int[] WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1152 | // Doubles |
| 1153 | /** |
| 1154 | * Indicates the view is enabled and has the focus. |
| 1155 | * |
| 1156 | * @see #ENABLED_STATE_SET |
| 1157 | * @see #FOCUSED_STATE_SET |
| 1158 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1159 | protected static final int[] ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | /** |
| 1161 | * Indicates the view is enabled and selected. |
| 1162 | * |
| 1163 | * @see #ENABLED_STATE_SET |
| 1164 | * @see #SELECTED_STATE_SET |
| 1165 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1166 | protected static final int[] ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1167 | /** |
| 1168 | * Indicates the view is enabled and that its window has focus. |
| 1169 | * |
| 1170 | * @see #ENABLED_STATE_SET |
| 1171 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1172 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1173 | protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1174 | /** |
| 1175 | * Indicates the view is focused and selected. |
| 1176 | * |
| 1177 | * @see #FOCUSED_STATE_SET |
| 1178 | * @see #SELECTED_STATE_SET |
| 1179 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1180 | protected static final int[] FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1181 | /** |
| 1182 | * Indicates the view has the focus and that its window has the focus. |
| 1183 | * |
| 1184 | * @see #FOCUSED_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[] FOCUSED_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 selected and that its window has the focus. |
| 1190 | * |
| 1191 | * @see #SELECTED_STATE_SET |
| 1192 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1193 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1194 | protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1195 | // Triples |
| 1196 | /** |
| 1197 | * Indicates the view is enabled, focused and selected. |
| 1198 | * |
| 1199 | * @see #ENABLED_STATE_SET |
| 1200 | * @see #FOCUSED_STATE_SET |
| 1201 | * @see #SELECTED_STATE_SET |
| 1202 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1203 | protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1204 | /** |
| 1205 | * Indicates the view is enabled, focused and its window has the focus. |
| 1206 | * |
| 1207 | * @see #ENABLED_STATE_SET |
| 1208 | * @see #FOCUSED_STATE_SET |
| 1209 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1210 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1211 | 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] | 1212 | /** |
| 1213 | * Indicates the view is enabled, selected and its window has the focus. |
| 1214 | * |
| 1215 | * @see #ENABLED_STATE_SET |
| 1216 | * @see #SELECTED_STATE_SET |
| 1217 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1218 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1219 | 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] | 1220 | /** |
| 1221 | * Indicates the view is focused, selected and its window has the focus. |
| 1222 | * |
| 1223 | * @see #FOCUSED_STATE_SET |
| 1224 | * @see #SELECTED_STATE_SET |
| 1225 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1226 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1227 | 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] | 1228 | /** |
| 1229 | * Indicates the view is enabled, focused, selected and its window |
| 1230 | * has the focus. |
| 1231 | * |
| 1232 | * @see #ENABLED_STATE_SET |
| 1233 | * @see #FOCUSED_STATE_SET |
| 1234 | * @see #SELECTED_STATE_SET |
| 1235 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1236 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1237 | 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] | 1238 | /** |
| 1239 | * Indicates the view is pressed and its window has the focus. |
| 1240 | * |
| 1241 | * @see #PRESSED_STATE_SET |
| 1242 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1243 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1244 | protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1245 | /** |
| 1246 | * Indicates the view is pressed and selected. |
| 1247 | * |
| 1248 | * @see #PRESSED_STATE_SET |
| 1249 | * @see #SELECTED_STATE_SET |
| 1250 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1251 | protected static final int[] PRESSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1252 | /** |
| 1253 | * Indicates the view is pressed, selected and its window has the focus. |
| 1254 | * |
| 1255 | * @see #PRESSED_STATE_SET |
| 1256 | * @see #SELECTED_STATE_SET |
| 1257 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1258 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1259 | 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] | 1260 | /** |
| 1261 | * Indicates the view is pressed and focused. |
| 1262 | * |
| 1263 | * @see #PRESSED_STATE_SET |
| 1264 | * @see #FOCUSED_STATE_SET |
| 1265 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1266 | protected static final int[] PRESSED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1267 | /** |
| 1268 | * Indicates the view is pressed, focused and its window has the focus. |
| 1269 | * |
| 1270 | * @see #PRESSED_STATE_SET |
| 1271 | * @see #FOCUSED_STATE_SET |
| 1272 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1273 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1274 | 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] | 1275 | /** |
| 1276 | * Indicates the view is pressed, focused and selected. |
| 1277 | * |
| 1278 | * @see #PRESSED_STATE_SET |
| 1279 | * @see #SELECTED_STATE_SET |
| 1280 | * @see #FOCUSED_STATE_SET |
| 1281 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1282 | protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1283 | /** |
| 1284 | * Indicates the view is pressed, focused, selected and its window has the focus. |
| 1285 | * |
| 1286 | * @see #PRESSED_STATE_SET |
| 1287 | * @see #FOCUSED_STATE_SET |
| 1288 | * @see #SELECTED_STATE_SET |
| 1289 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1290 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1291 | 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] | 1292 | /** |
| 1293 | * Indicates the view is pressed and enabled. |
| 1294 | * |
| 1295 | * @see #PRESSED_STATE_SET |
| 1296 | * @see #ENABLED_STATE_SET |
| 1297 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1298 | protected static final int[] PRESSED_ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1299 | /** |
| 1300 | * Indicates the view is pressed, enabled and its window has the focus. |
| 1301 | * |
| 1302 | * @see #PRESSED_STATE_SET |
| 1303 | * @see #ENABLED_STATE_SET |
| 1304 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1305 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1306 | 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] | 1307 | /** |
| 1308 | * Indicates the view is pressed, enabled and selected. |
| 1309 | * |
| 1310 | * @see #PRESSED_STATE_SET |
| 1311 | * @see #ENABLED_STATE_SET |
| 1312 | * @see #SELECTED_STATE_SET |
| 1313 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1314 | protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1315 | /** |
| 1316 | * Indicates the view is pressed, enabled, selected and its window has the |
| 1317 | * focus. |
| 1318 | * |
| 1319 | * @see #PRESSED_STATE_SET |
| 1320 | * @see #ENABLED_STATE_SET |
| 1321 | * @see #SELECTED_STATE_SET |
| 1322 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1323 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1324 | 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] | 1325 | /** |
| 1326 | * Indicates the view is pressed, enabled and focused. |
| 1327 | * |
| 1328 | * @see #PRESSED_STATE_SET |
| 1329 | * @see #ENABLED_STATE_SET |
| 1330 | * @see #FOCUSED_STATE_SET |
| 1331 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1332 | protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1333 | /** |
| 1334 | * Indicates the view is pressed, enabled, focused and its window has the |
| 1335 | * focus. |
| 1336 | * |
| 1337 | * @see #PRESSED_STATE_SET |
| 1338 | * @see #ENABLED_STATE_SET |
| 1339 | * @see #FOCUSED_STATE_SET |
| 1340 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1341 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1342 | 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] | 1343 | /** |
| 1344 | * Indicates the view is pressed, enabled, focused and selected. |
| 1345 | * |
| 1346 | * @see #PRESSED_STATE_SET |
| 1347 | * @see #ENABLED_STATE_SET |
| 1348 | * @see #SELECTED_STATE_SET |
| 1349 | * @see #FOCUSED_STATE_SET |
| 1350 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1351 | 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] | 1352 | /** |
| 1353 | * Indicates the view is pressed, enabled, focused, selected and its window |
| 1354 | * has the focus. |
| 1355 | * |
| 1356 | * @see #PRESSED_STATE_SET |
| 1357 | * @see #ENABLED_STATE_SET |
| 1358 | * @see #SELECTED_STATE_SET |
| 1359 | * @see #FOCUSED_STATE_SET |
| 1360 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1361 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1362 | 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] | 1363 | |
| 1364 | /** |
| 1365 | * The order here is very important to {@link #getDrawableState()} |
| 1366 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1367 | private static final int[][] VIEW_STATE_SETS; |
| 1368 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1369 | static final int VIEW_STATE_WINDOW_FOCUSED = 1; |
| 1370 | static final int VIEW_STATE_SELECTED = 1 << 1; |
| 1371 | static final int VIEW_STATE_FOCUSED = 1 << 2; |
| 1372 | static final int VIEW_STATE_ENABLED = 1 << 3; |
| 1373 | static final int VIEW_STATE_PRESSED = 1 << 4; |
| 1374 | static final int VIEW_STATE_ACTIVATED = 1 << 5; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1375 | static final int VIEW_STATE_ACCELERATED = 1 << 6; |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1376 | static final int VIEW_STATE_HOVERED = 1 << 7; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1377 | static final int VIEW_STATE_DRAG_CAN_ACCEPT = 1 << 8; |
| 1378 | static final int VIEW_STATE_DRAG_HOVERED = 1 << 9; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1379 | |
| 1380 | static final int[] VIEW_STATE_IDS = new int[] { |
| 1381 | R.attr.state_window_focused, VIEW_STATE_WINDOW_FOCUSED, |
| 1382 | R.attr.state_selected, VIEW_STATE_SELECTED, |
| 1383 | R.attr.state_focused, VIEW_STATE_FOCUSED, |
| 1384 | R.attr.state_enabled, VIEW_STATE_ENABLED, |
| 1385 | R.attr.state_pressed, VIEW_STATE_PRESSED, |
| 1386 | R.attr.state_activated, VIEW_STATE_ACTIVATED, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1387 | R.attr.state_accelerated, VIEW_STATE_ACCELERATED, |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1388 | R.attr.state_hovered, VIEW_STATE_HOVERED, |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1389 | R.attr.state_drag_can_accept, VIEW_STATE_DRAG_CAN_ACCEPT, |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1390 | R.attr.state_drag_hovered, VIEW_STATE_DRAG_HOVERED |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1391 | }; |
| 1392 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1393 | static { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1394 | if ((VIEW_STATE_IDS.length/2) != R.styleable.ViewDrawableStates.length) { |
| 1395 | throw new IllegalStateException( |
| 1396 | "VIEW_STATE_IDs array length does not match ViewDrawableStates style array"); |
| 1397 | } |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1398 | int[] orderedIds = new int[VIEW_STATE_IDS.length]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1399 | for (int i = 0; i < R.styleable.ViewDrawableStates.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1400 | int viewState = R.styleable.ViewDrawableStates[i]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1401 | for (int j = 0; j<VIEW_STATE_IDS.length; j += 2) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1402 | if (VIEW_STATE_IDS[j] == viewState) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1403 | orderedIds[i * 2] = viewState; |
| 1404 | orderedIds[i * 2 + 1] = VIEW_STATE_IDS[j + 1]; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1405 | } |
| 1406 | } |
| 1407 | } |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1408 | final int NUM_BITS = VIEW_STATE_IDS.length / 2; |
| 1409 | VIEW_STATE_SETS = new int[1 << NUM_BITS][]; |
| 1410 | for (int i = 0; i < VIEW_STATE_SETS.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1411 | int numBits = Integer.bitCount(i); |
| 1412 | int[] set = new int[numBits]; |
| 1413 | int pos = 0; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1414 | for (int j = 0; j < orderedIds.length; j += 2) { |
| 1415 | if ((i & orderedIds[j+1]) != 0) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1416 | set[pos++] = orderedIds[j]; |
| 1417 | } |
| 1418 | } |
| 1419 | VIEW_STATE_SETS[i] = set; |
| 1420 | } |
| 1421 | |
| 1422 | EMPTY_STATE_SET = VIEW_STATE_SETS[0]; |
| 1423 | WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_WINDOW_FOCUSED]; |
| 1424 | SELECTED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_SELECTED]; |
| 1425 | SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1426 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED]; |
| 1427 | FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_FOCUSED]; |
| 1428 | FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1429 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED]; |
| 1430 | FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1431 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED]; |
| 1432 | FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1433 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1434 | | VIEW_STATE_FOCUSED]; |
| 1435 | ENABLED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_ENABLED]; |
| 1436 | ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1437 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED]; |
| 1438 | ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1439 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED]; |
| 1440 | ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1441 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1442 | | VIEW_STATE_ENABLED]; |
| 1443 | ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1444 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED]; |
| 1445 | ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1446 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1447 | | VIEW_STATE_ENABLED]; |
| 1448 | ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1449 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1450 | | VIEW_STATE_ENABLED]; |
| 1451 | ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1452 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1453 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED]; |
| 1454 | |
| 1455 | PRESSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_PRESSED]; |
| 1456 | PRESSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1457 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_PRESSED]; |
| 1458 | PRESSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1459 | VIEW_STATE_SELECTED | VIEW_STATE_PRESSED]; |
| 1460 | PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1461 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1462 | | VIEW_STATE_PRESSED]; |
| 1463 | PRESSED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1464 | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1465 | PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1466 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1467 | | VIEW_STATE_PRESSED]; |
| 1468 | PRESSED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1469 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1470 | | VIEW_STATE_PRESSED]; |
| 1471 | PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1472 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1473 | | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1474 | PRESSED_ENABLED_STATE_SET = VIEW_STATE_SETS[ |
| 1475 | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1476 | PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1477 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED |
| 1478 | | VIEW_STATE_PRESSED]; |
| 1479 | PRESSED_ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1480 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED |
| 1481 | | VIEW_STATE_PRESSED]; |
| 1482 | PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1483 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1484 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1485 | PRESSED_ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1486 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED |
| 1487 | | VIEW_STATE_PRESSED]; |
| 1488 | PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1489 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1490 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1491 | PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1492 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1493 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1494 | PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1495 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1496 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED |
| 1497 | | VIEW_STATE_PRESSED]; |
| 1498 | } |
| 1499 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1500 | /** |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1501 | * Accessibility event types that are dispatched for text population. |
| 1502 | */ |
| 1503 | private static final int POPULATING_ACCESSIBILITY_EVENT_TYPES = |
| 1504 | AccessibilityEvent.TYPE_VIEW_CLICKED |
| 1505 | | AccessibilityEvent.TYPE_VIEW_LONG_CLICKED |
| 1506 | | AccessibilityEvent.TYPE_VIEW_SELECTED |
| 1507 | | AccessibilityEvent.TYPE_VIEW_FOCUSED |
| 1508 | | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED |
| 1509 | | AccessibilityEvent.TYPE_VIEW_HOVER_ENTER |
Svetoslav Ganov | 9920f4f | 2011-10-07 18:39:11 -0700 | [diff] [blame] | 1510 | | AccessibilityEvent.TYPE_VIEW_HOVER_EXIT |
Svetoslav Ganov | 84dd52e | 2011-11-18 10:24:00 -0800 | [diff] [blame] | 1511 | | AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1512 | | AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED |
| 1513 | | AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED; |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1514 | |
| 1515 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1516 | * Temporary Rect currently for use in setBackground(). This will probably |
| 1517 | * be extended in the future to hold our own class with more than just |
| 1518 | * a Rect. :) |
| 1519 | */ |
| 1520 | static final ThreadLocal<Rect> sThreadLocal = new ThreadLocal<Rect>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1521 | |
| 1522 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 1523 | * Temporary flag, used to enable processing of View properties in the native DisplayList |
| 1524 | * object instead of during draw(). Soon to be enabled by default for hardware-accelerated |
| 1525 | * apps. |
| 1526 | * @hide |
| 1527 | */ |
Chet Haase | 8d56b0e | 2012-04-02 16:34:48 -0700 | [diff] [blame] | 1528 | public static final boolean USE_DISPLAY_LIST_PROPERTIES = true; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 1529 | |
| 1530 | /** |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1531 | * Map used to store views' tags. |
| 1532 | */ |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 1533 | private SparseArray<Object> mKeyedTags; |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1534 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1535 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1536 | * The next available accessiiblity id. |
| 1537 | */ |
| 1538 | private static int sNextAccessibilityViewId; |
| 1539 | |
| 1540 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1541 | * The animation currently associated with this view. |
| 1542 | * @hide |
| 1543 | */ |
| 1544 | protected Animation mCurrentAnimation = null; |
| 1545 | |
| 1546 | /** |
| 1547 | * Width as measured during measure pass. |
| 1548 | * {@hide} |
| 1549 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1550 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1551 | int mMeasuredWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1552 | |
| 1553 | /** |
| 1554 | * Height as measured during measure pass. |
| 1555 | * {@hide} |
| 1556 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1557 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1558 | int mMeasuredHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1559 | |
| 1560 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1561 | * Flag to indicate that this view was marked INVALIDATED, or had its display list |
| 1562 | * invalidated, prior to the current drawing iteration. If true, the view must re-draw |
| 1563 | * its display list. This flag, used only when hw accelerated, allows us to clear the |
| 1564 | * flag while retaining this information until it's needed (at getDisplayList() time and |
| 1565 | * in drawChild(), when we decide to draw a view's children's display lists into our own). |
| 1566 | * |
| 1567 | * {@hide} |
| 1568 | */ |
| 1569 | boolean mRecreateDisplayList = false; |
| 1570 | |
| 1571 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1572 | * The view's identifier. |
| 1573 | * {@hide} |
| 1574 | * |
| 1575 | * @see #setId(int) |
| 1576 | * @see #getId() |
| 1577 | */ |
| 1578 | @ViewDebug.ExportedProperty(resolveId = true) |
| 1579 | int mID = NO_ID; |
| 1580 | |
| 1581 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 1582 | * The stable ID of this view for accessibility purposes. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1583 | */ |
| 1584 | int mAccessibilityViewId = NO_ID; |
| 1585 | |
| 1586 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1587 | * The view's tag. |
| 1588 | * {@hide} |
| 1589 | * |
| 1590 | * @see #setTag(Object) |
| 1591 | * @see #getTag() |
| 1592 | */ |
| 1593 | protected Object mTag; |
| 1594 | |
| 1595 | // for mPrivateFlags: |
| 1596 | /** {@hide} */ |
| 1597 | static final int WANTS_FOCUS = 0x00000001; |
| 1598 | /** {@hide} */ |
| 1599 | static final int FOCUSED = 0x00000002; |
| 1600 | /** {@hide} */ |
| 1601 | static final int SELECTED = 0x00000004; |
| 1602 | /** {@hide} */ |
| 1603 | static final int IS_ROOT_NAMESPACE = 0x00000008; |
| 1604 | /** {@hide} */ |
| 1605 | static final int HAS_BOUNDS = 0x00000010; |
| 1606 | /** {@hide} */ |
| 1607 | static final int DRAWN = 0x00000020; |
| 1608 | /** |
| 1609 | * When this flag is set, this view is running an animation on behalf of its |
| 1610 | * children and should therefore not cancel invalidate requests, even if they |
| 1611 | * lie outside of this view's bounds. |
| 1612 | * |
| 1613 | * {@hide} |
| 1614 | */ |
| 1615 | static final int DRAW_ANIMATION = 0x00000040; |
| 1616 | /** {@hide} */ |
| 1617 | static final int SKIP_DRAW = 0x00000080; |
| 1618 | /** {@hide} */ |
| 1619 | static final int ONLY_DRAWS_BACKGROUND = 0x00000100; |
| 1620 | /** {@hide} */ |
| 1621 | static final int REQUEST_TRANSPARENT_REGIONS = 0x00000200; |
| 1622 | /** {@hide} */ |
| 1623 | static final int DRAWABLE_STATE_DIRTY = 0x00000400; |
| 1624 | /** {@hide} */ |
| 1625 | static final int MEASURED_DIMENSION_SET = 0x00000800; |
| 1626 | /** {@hide} */ |
| 1627 | static final int FORCE_LAYOUT = 0x00001000; |
Konstantin Lopyrev | c6dc457 | 2010-08-06 15:01:52 -0700 | [diff] [blame] | 1628 | /** {@hide} */ |
| 1629 | static final int LAYOUT_REQUIRED = 0x00002000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1630 | |
| 1631 | private static final int PRESSED = 0x00004000; |
| 1632 | |
| 1633 | /** {@hide} */ |
| 1634 | static final int DRAWING_CACHE_VALID = 0x00008000; |
| 1635 | /** |
| 1636 | * Flag used to indicate that this view should be drawn once more (and only once |
| 1637 | * more) after its animation has completed. |
| 1638 | * {@hide} |
| 1639 | */ |
| 1640 | static final int ANIMATION_STARTED = 0x00010000; |
| 1641 | |
| 1642 | private static final int SAVE_STATE_CALLED = 0x00020000; |
| 1643 | |
| 1644 | /** |
| 1645 | * Indicates that the View returned true when onSetAlpha() was called and that |
| 1646 | * the alpha must be restored. |
| 1647 | * {@hide} |
| 1648 | */ |
| 1649 | static final int ALPHA_SET = 0x00040000; |
| 1650 | |
| 1651 | /** |
| 1652 | * Set by {@link #setScrollContainer(boolean)}. |
| 1653 | */ |
| 1654 | static final int SCROLL_CONTAINER = 0x00080000; |
| 1655 | |
| 1656 | /** |
| 1657 | * Set by {@link #setScrollContainer(boolean)}. |
| 1658 | */ |
| 1659 | static final int SCROLL_CONTAINER_ADDED = 0x00100000; |
| 1660 | |
| 1661 | /** |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1662 | * View flag indicating whether this view was invalidated (fully or partially.) |
| 1663 | * |
| 1664 | * @hide |
| 1665 | */ |
| 1666 | static final int DIRTY = 0x00200000; |
| 1667 | |
| 1668 | /** |
| 1669 | * View flag indicating whether this view was invalidated by an opaque |
| 1670 | * invalidate request. |
| 1671 | * |
| 1672 | * @hide |
| 1673 | */ |
| 1674 | static final int DIRTY_OPAQUE = 0x00400000; |
| 1675 | |
| 1676 | /** |
| 1677 | * Mask for {@link #DIRTY} and {@link #DIRTY_OPAQUE}. |
| 1678 | * |
| 1679 | * @hide |
| 1680 | */ |
| 1681 | static final int DIRTY_MASK = 0x00600000; |
| 1682 | |
| 1683 | /** |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1684 | * Indicates whether the background is opaque. |
| 1685 | * |
| 1686 | * @hide |
| 1687 | */ |
| 1688 | static final int OPAQUE_BACKGROUND = 0x00800000; |
| 1689 | |
| 1690 | /** |
| 1691 | * Indicates whether the scrollbars are opaque. |
| 1692 | * |
| 1693 | * @hide |
| 1694 | */ |
| 1695 | static final int OPAQUE_SCROLLBARS = 0x01000000; |
| 1696 | |
| 1697 | /** |
| 1698 | * Indicates whether the view is opaque. |
| 1699 | * |
| 1700 | * @hide |
| 1701 | */ |
| 1702 | static final int OPAQUE_MASK = 0x01800000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1703 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1704 | /** |
| 1705 | * Indicates a prepressed state; |
| 1706 | * the short time between ACTION_DOWN and recognizing |
| 1707 | * a 'real' press. Prepressed is used to recognize quick taps |
| 1708 | * even when they are shorter than ViewConfiguration.getTapTimeout(). |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1709 | * |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1710 | * @hide |
| 1711 | */ |
| 1712 | private static final int PREPRESSED = 0x02000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1713 | |
Adam Powell | c9fbaab | 2010-02-16 17:16:19 -0800 | [diff] [blame] | 1714 | /** |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 1715 | * Indicates whether the view is temporarily detached. |
| 1716 | * |
| 1717 | * @hide |
| 1718 | */ |
| 1719 | static final int CANCEL_NEXT_UP_EVENT = 0x04000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1720 | |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1721 | /** |
| 1722 | * Indicates that we should awaken scroll bars once attached |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1723 | * |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1724 | * @hide |
| 1725 | */ |
| 1726 | private static final int AWAKEN_SCROLL_BARS_ON_ATTACH = 0x08000000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1727 | |
| 1728 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1729 | * Indicates that the view has received HOVER_ENTER. Cleared on HOVER_EXIT. |
| 1730 | * @hide |
| 1731 | */ |
| 1732 | private static final int HOVERED = 0x10000000; |
| 1733 | |
| 1734 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1735 | * Indicates that pivotX or pivotY were explicitly set and we should not assume the center |
| 1736 | * for transform operations |
| 1737 | * |
| 1738 | * @hide |
| 1739 | */ |
Adam Powell | f37df07 | 2010-09-17 16:22:49 -0700 | [diff] [blame] | 1740 | private static final int PIVOT_EXPLICITLY_SET = 0x20000000; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1741 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1742 | /** {@hide} */ |
Adam Powell | f37df07 | 2010-09-17 16:22:49 -0700 | [diff] [blame] | 1743 | static final int ACTIVATED = 0x40000000; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1744 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1745 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1746 | * Indicates that this view was specifically invalidated, not just dirtied because some |
| 1747 | * child view was invalidated. The flag is used to determine when we need to recreate |
| 1748 | * a view's display list (as opposed to just returning a reference to its existing |
| 1749 | * display list). |
| 1750 | * |
| 1751 | * @hide |
| 1752 | */ |
| 1753 | static final int INVALIDATED = 0x80000000; |
| 1754 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1755 | /* Masks for mPrivateFlags2 */ |
| 1756 | |
| 1757 | /** |
| 1758 | * Indicates that this view has reported that it can accept the current drag's content. |
| 1759 | * Cleared when the drag operation concludes. |
| 1760 | * @hide |
| 1761 | */ |
| 1762 | static final int DRAG_CAN_ACCEPT = 0x00000001; |
| 1763 | |
| 1764 | /** |
| 1765 | * Indicates that this view is currently directly under the drag location in a |
| 1766 | * drag-and-drop operation involving content that it can accept. Cleared when |
| 1767 | * the drag exits the view, or when the drag operation concludes. |
| 1768 | * @hide |
| 1769 | */ |
| 1770 | static final int DRAG_HOVERED = 0x00000002; |
| 1771 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1772 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1773 | * Horizontal layout direction of this view is from Left to Right. |
| 1774 | * Use with {@link #setLayoutDirection}. |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1775 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1776 | public static final int LAYOUT_DIRECTION_LTR = 0; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1777 | |
| 1778 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1779 | * Horizontal layout direction of this view is from Right to Left. |
| 1780 | * Use with {@link #setLayoutDirection}. |
| 1781 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1782 | public static final int LAYOUT_DIRECTION_RTL = 1; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1783 | |
| 1784 | /** |
| 1785 | * Horizontal layout direction of this view is inherited from its parent. |
| 1786 | * Use with {@link #setLayoutDirection}. |
| 1787 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1788 | public static final int LAYOUT_DIRECTION_INHERIT = 2; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1789 | |
| 1790 | /** |
| 1791 | * Horizontal layout direction of this view is from deduced from the default language |
| 1792 | * script for the locale. Use with {@link #setLayoutDirection}. |
| 1793 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1794 | public static final int LAYOUT_DIRECTION_LOCALE = 3; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1795 | |
| 1796 | /** |
| 1797 | * 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] | 1798 | * @hide |
| 1799 | */ |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1800 | static final int LAYOUT_DIRECTION_MASK_SHIFT = 2; |
| 1801 | |
| 1802 | /** |
| 1803 | * Mask for use with private flags indicating bits used for horizontal layout direction. |
| 1804 | * @hide |
| 1805 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1806 | static final int LAYOUT_DIRECTION_MASK = 0x00000003 << LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1807 | |
| 1808 | /** |
| 1809 | * Indicates whether the view horizontal layout direction has been resolved and drawn to the |
| 1810 | * right-to-left direction. |
| 1811 | * @hide |
| 1812 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1813 | 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] | 1814 | |
| 1815 | /** |
| 1816 | * Indicates whether the view horizontal layout direction has been resolved. |
| 1817 | * @hide |
| 1818 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1819 | static final int LAYOUT_DIRECTION_RESOLVED = 8 << LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1820 | |
| 1821 | /** |
| 1822 | * Mask for use with private flags indicating bits used for resolved horizontal layout direction. |
| 1823 | * @hide |
| 1824 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1825 | 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] | 1826 | |
| 1827 | /* |
| 1828 | * Array of horizontal layout direction flags for mapping attribute "layoutDirection" to correct |
| 1829 | * flag value. |
| 1830 | * @hide |
| 1831 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1832 | private static final int[] LAYOUT_DIRECTION_FLAGS = { |
| 1833 | LAYOUT_DIRECTION_LTR, |
| 1834 | LAYOUT_DIRECTION_RTL, |
| 1835 | LAYOUT_DIRECTION_INHERIT, |
| 1836 | LAYOUT_DIRECTION_LOCALE |
| 1837 | }; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1838 | |
| 1839 | /** |
| 1840 | * Default horizontal layout direction. |
| 1841 | * @hide |
| 1842 | */ |
| 1843 | private static final int LAYOUT_DIRECTION_DEFAULT = LAYOUT_DIRECTION_INHERIT; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1844 | |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1845 | /** |
| 1846 | * Indicates that the view is tracking some sort of transient state |
| 1847 | * that the app should not need to be aware of, but that the framework |
| 1848 | * should take special care to preserve. |
| 1849 | * |
| 1850 | * @hide |
| 1851 | */ |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1852 | static final int HAS_TRANSIENT_STATE = 0x00000100; |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1853 | |
| 1854 | |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1855 | /** |
| 1856 | * Text direction is inherited thru {@link ViewGroup} |
| 1857 | */ |
| 1858 | public static final int TEXT_DIRECTION_INHERIT = 0; |
| 1859 | |
| 1860 | /** |
| 1861 | * Text direction is using "first strong algorithm". The first strong directional character |
| 1862 | * determines the paragraph direction. If there is no strong directional character, the |
| 1863 | * paragraph direction is the view's resolved layout direction. |
| 1864 | */ |
| 1865 | public static final int TEXT_DIRECTION_FIRST_STRONG = 1; |
| 1866 | |
| 1867 | /** |
| 1868 | * Text direction is using "any-RTL" algorithm. The paragraph direction is RTL if it contains |
| 1869 | * any strong RTL character, otherwise it is LTR if it contains any strong LTR characters. |
| 1870 | * If there are neither, the paragraph direction is the view's resolved layout direction. |
| 1871 | */ |
| 1872 | public static final int TEXT_DIRECTION_ANY_RTL = 2; |
| 1873 | |
| 1874 | /** |
| 1875 | * Text direction is forced to LTR. |
| 1876 | */ |
| 1877 | public static final int TEXT_DIRECTION_LTR = 3; |
| 1878 | |
| 1879 | /** |
| 1880 | * Text direction is forced to RTL. |
| 1881 | */ |
| 1882 | public static final int TEXT_DIRECTION_RTL = 4; |
| 1883 | |
| 1884 | /** |
| 1885 | * Text direction is coming from the system Locale. |
| 1886 | */ |
| 1887 | public static final int TEXT_DIRECTION_LOCALE = 5; |
| 1888 | |
| 1889 | /** |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1890 | * Default text direction is inherited |
| 1891 | */ |
| 1892 | protected static int TEXT_DIRECTION_DEFAULT = TEXT_DIRECTION_INHERIT; |
| 1893 | |
| 1894 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1895 | * Bit shift to get the horizontal layout direction. (bits after LAYOUT_DIRECTION_RESOLVED) |
| 1896 | * @hide |
| 1897 | */ |
| 1898 | static final int TEXT_DIRECTION_MASK_SHIFT = 6; |
| 1899 | |
| 1900 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1901 | * Mask for use with private flags indicating bits used for text direction. |
| 1902 | * @hide |
| 1903 | */ |
| 1904 | static final int TEXT_DIRECTION_MASK = 0x00000007 << TEXT_DIRECTION_MASK_SHIFT; |
| 1905 | |
| 1906 | /** |
| 1907 | * Array of text direction flags for mapping attribute "textDirection" to correct |
| 1908 | * flag value. |
| 1909 | * @hide |
| 1910 | */ |
| 1911 | private static final int[] TEXT_DIRECTION_FLAGS = { |
| 1912 | TEXT_DIRECTION_INHERIT << TEXT_DIRECTION_MASK_SHIFT, |
| 1913 | TEXT_DIRECTION_FIRST_STRONG << TEXT_DIRECTION_MASK_SHIFT, |
| 1914 | TEXT_DIRECTION_ANY_RTL << TEXT_DIRECTION_MASK_SHIFT, |
| 1915 | TEXT_DIRECTION_LTR << TEXT_DIRECTION_MASK_SHIFT, |
| 1916 | TEXT_DIRECTION_RTL << TEXT_DIRECTION_MASK_SHIFT, |
| 1917 | TEXT_DIRECTION_LOCALE << TEXT_DIRECTION_MASK_SHIFT |
| 1918 | }; |
| 1919 | |
| 1920 | /** |
| 1921 | * Indicates whether the view text direction has been resolved. |
| 1922 | * @hide |
| 1923 | */ |
| 1924 | static final int TEXT_DIRECTION_RESOLVED = 0x00000008 << TEXT_DIRECTION_MASK_SHIFT; |
| 1925 | |
| 1926 | /** |
| 1927 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
| 1928 | * @hide |
| 1929 | */ |
| 1930 | static final int TEXT_DIRECTION_RESOLVED_MASK_SHIFT = 10; |
| 1931 | |
| 1932 | /** |
| 1933 | * Mask for use with private flags indicating bits used for resolved text direction. |
| 1934 | * @hide |
| 1935 | */ |
| 1936 | static final int TEXT_DIRECTION_RESOLVED_MASK = 0x00000007 << TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
| 1937 | |
| 1938 | /** |
| 1939 | * Indicates whether the view text direction has been resolved to the "first strong" heuristic. |
| 1940 | * @hide |
| 1941 | */ |
| 1942 | static final int TEXT_DIRECTION_RESOLVED_DEFAULT = |
| 1943 | TEXT_DIRECTION_FIRST_STRONG << TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
| 1944 | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1945 | /* |
| 1946 | * Default text alignment. The text alignment of this View is inherited from its parent. |
| 1947 | * Use with {@link #setTextAlignment(int)} |
| 1948 | */ |
| 1949 | public static final int TEXT_ALIGNMENT_INHERIT = 0; |
| 1950 | |
| 1951 | /** |
| 1952 | * Default for the root view. The gravity determines the text alignment, ALIGN_NORMAL, |
| 1953 | * ALIGN_CENTER, or ALIGN_OPPOSITE, which are relative to each paragraph’s text direction. |
| 1954 | * |
| 1955 | * Use with {@link #setTextAlignment(int)} |
| 1956 | */ |
| 1957 | public static final int TEXT_ALIGNMENT_GRAVITY = 1; |
| 1958 | |
| 1959 | /** |
| 1960 | * Align to the start of the paragraph, e.g. ALIGN_NORMAL. |
| 1961 | * |
| 1962 | * Use with {@link #setTextAlignment(int)} |
| 1963 | */ |
| 1964 | public static final int TEXT_ALIGNMENT_TEXT_START = 2; |
| 1965 | |
| 1966 | /** |
| 1967 | * Align to the end of the paragraph, e.g. ALIGN_OPPOSITE. |
| 1968 | * |
| 1969 | * Use with {@link #setTextAlignment(int)} |
| 1970 | */ |
| 1971 | public static final int TEXT_ALIGNMENT_TEXT_END = 3; |
| 1972 | |
| 1973 | /** |
| 1974 | * Center the paragraph, e.g. ALIGN_CENTER. |
| 1975 | * |
| 1976 | * Use with {@link #setTextAlignment(int)} |
| 1977 | */ |
| 1978 | public static final int TEXT_ALIGNMENT_CENTER = 4; |
| 1979 | |
| 1980 | /** |
| 1981 | * Align to the start of the view, which is ALIGN_LEFT if the view’s resolved |
| 1982 | * layoutDirection is LTR, and ALIGN_RIGHT otherwise. |
| 1983 | * |
| 1984 | * Use with {@link #setTextAlignment(int)} |
| 1985 | */ |
| 1986 | public static final int TEXT_ALIGNMENT_VIEW_START = 5; |
| 1987 | |
| 1988 | /** |
| 1989 | * Align to the end of the view, which is ALIGN_RIGHT if the view’s resolved |
| 1990 | * layoutDirection is LTR, and ALIGN_LEFT otherwise. |
| 1991 | * |
| 1992 | * Use with {@link #setTextAlignment(int)} |
| 1993 | */ |
| 1994 | public static final int TEXT_ALIGNMENT_VIEW_END = 6; |
| 1995 | |
| 1996 | /** |
| 1997 | * Default text alignment is inherited |
| 1998 | */ |
| 1999 | protected static int TEXT_ALIGNMENT_DEFAULT = TEXT_ALIGNMENT_GRAVITY; |
| 2000 | |
| 2001 | /** |
| 2002 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
| 2003 | * @hide |
| 2004 | */ |
| 2005 | static final int TEXT_ALIGNMENT_MASK_SHIFT = 13; |
| 2006 | |
| 2007 | /** |
| 2008 | * Mask for use with private flags indicating bits used for text alignment. |
| 2009 | * @hide |
| 2010 | */ |
| 2011 | static final int TEXT_ALIGNMENT_MASK = 0x00000007 << TEXT_ALIGNMENT_MASK_SHIFT; |
| 2012 | |
| 2013 | /** |
| 2014 | * Array of text direction flags for mapping attribute "textAlignment" to correct |
| 2015 | * flag value. |
| 2016 | * @hide |
| 2017 | */ |
| 2018 | private static final int[] TEXT_ALIGNMENT_FLAGS = { |
| 2019 | TEXT_ALIGNMENT_INHERIT << TEXT_ALIGNMENT_MASK_SHIFT, |
| 2020 | TEXT_ALIGNMENT_GRAVITY << TEXT_ALIGNMENT_MASK_SHIFT, |
| 2021 | TEXT_ALIGNMENT_TEXT_START << TEXT_ALIGNMENT_MASK_SHIFT, |
| 2022 | TEXT_ALIGNMENT_TEXT_END << TEXT_ALIGNMENT_MASK_SHIFT, |
| 2023 | TEXT_ALIGNMENT_CENTER << TEXT_ALIGNMENT_MASK_SHIFT, |
| 2024 | TEXT_ALIGNMENT_VIEW_START << TEXT_ALIGNMENT_MASK_SHIFT, |
| 2025 | TEXT_ALIGNMENT_VIEW_END << TEXT_ALIGNMENT_MASK_SHIFT |
| 2026 | }; |
| 2027 | |
| 2028 | /** |
| 2029 | * Indicates whether the view text alignment has been resolved. |
| 2030 | * @hide |
| 2031 | */ |
| 2032 | static final int TEXT_ALIGNMENT_RESOLVED = 0x00000008 << TEXT_ALIGNMENT_MASK_SHIFT; |
| 2033 | |
| 2034 | /** |
| 2035 | * Bit shift to get the resolved text alignment. |
| 2036 | * @hide |
| 2037 | */ |
| 2038 | static final int TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT = 17; |
| 2039 | |
| 2040 | /** |
| 2041 | * Mask for use with private flags indicating bits used for text alignment. |
| 2042 | * @hide |
| 2043 | */ |
| 2044 | static final int TEXT_ALIGNMENT_RESOLVED_MASK = 0x00000007 << TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
| 2045 | |
| 2046 | /** |
| 2047 | * Indicates whether if the view text alignment has been resolved to gravity |
| 2048 | */ |
| 2049 | public static final int TEXT_ALIGNMENT_RESOLVED_DEFAULT = |
| 2050 | TEXT_ALIGNMENT_GRAVITY << TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
| 2051 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2052 | // Accessiblity constants for mPrivateFlags2 |
| 2053 | |
| 2054 | /** |
| 2055 | * Shift for accessibility related bits in {@link #mPrivateFlags2}. |
| 2056 | */ |
| 2057 | static final int IMPORTANT_FOR_ACCESSIBILITY_SHIFT = 20; |
| 2058 | |
| 2059 | /** |
| 2060 | * Automatically determine whether a view is important for accessibility. |
| 2061 | */ |
| 2062 | public static final int IMPORTANT_FOR_ACCESSIBILITY_AUTO = 0x00000000; |
| 2063 | |
| 2064 | /** |
| 2065 | * The view is important for accessibility. |
| 2066 | */ |
| 2067 | public static final int IMPORTANT_FOR_ACCESSIBILITY_YES = 0x00000001; |
| 2068 | |
| 2069 | /** |
| 2070 | * The view is not important for accessibility. |
| 2071 | */ |
| 2072 | public static final int IMPORTANT_FOR_ACCESSIBILITY_NO = 0x00000002; |
| 2073 | |
| 2074 | /** |
| 2075 | * The default whether the view is important for accessiblity. |
| 2076 | */ |
| 2077 | static final int IMPORTANT_FOR_ACCESSIBILITY_DEFAULT = IMPORTANT_FOR_ACCESSIBILITY_AUTO; |
| 2078 | |
| 2079 | /** |
| 2080 | * Mask for obtainig the bits which specify how to determine |
| 2081 | * whether a view is important for accessibility. |
| 2082 | */ |
| 2083 | static final int IMPORTANT_FOR_ACCESSIBILITY_MASK = (IMPORTANT_FOR_ACCESSIBILITY_AUTO |
| 2084 | | IMPORTANT_FOR_ACCESSIBILITY_YES | IMPORTANT_FOR_ACCESSIBILITY_NO) |
| 2085 | << IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
| 2086 | |
| 2087 | /** |
| 2088 | * Flag indicating whether a view has accessibility focus. |
| 2089 | */ |
| 2090 | static final int ACCESSIBILITY_FOCUSED = 0x00000040 << IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
| 2091 | |
| 2092 | /** |
| 2093 | * Flag indicating whether a view state for accessibility has changed. |
| 2094 | */ |
| 2095 | static final int ACCESSIBILITY_STATE_CHANGED = 0x00000080 << IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 2096 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2097 | /* End of masks for mPrivateFlags2 */ |
| 2098 | |
| 2099 | static final int DRAG_MASK = DRAG_CAN_ACCEPT | DRAG_HOVERED; |
| 2100 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 2101 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2102 | * Always allow a user to over-scroll this view, provided it is a |
| 2103 | * view that can scroll. |
| 2104 | * |
| 2105 | * @see #getOverScrollMode() |
| 2106 | * @see #setOverScrollMode(int) |
| 2107 | */ |
| 2108 | public static final int OVER_SCROLL_ALWAYS = 0; |
| 2109 | |
| 2110 | /** |
| 2111 | * Allow a user to over-scroll this view only if the content is large |
| 2112 | * enough to meaningfully scroll, provided it is a view that can scroll. |
| 2113 | * |
| 2114 | * @see #getOverScrollMode() |
| 2115 | * @see #setOverScrollMode(int) |
| 2116 | */ |
| 2117 | public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1; |
| 2118 | |
| 2119 | /** |
| 2120 | * Never allow a user to over-scroll this view. |
| 2121 | * |
| 2122 | * @see #getOverScrollMode() |
| 2123 | * @see #setOverScrollMode(int) |
| 2124 | */ |
| 2125 | public static final int OVER_SCROLL_NEVER = 2; |
| 2126 | |
| 2127 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2128 | * Special constant for {@link #setSystemUiVisibility(int)}: View has |
| 2129 | * requested the system UI (status bar) to be visible (the default). |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2130 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2131 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2132 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2133 | public static final int SYSTEM_UI_FLAG_VISIBLE = 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2134 | |
| 2135 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2136 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested the |
| 2137 | * system UI to enter an unobtrusive "low profile" mode. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2138 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2139 | * <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] | 2140 | * "immersive" application where the usual system chrome is deemed too distracting. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2141 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2142 | * <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] | 2143 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2144 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2145 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2146 | public static final int SYSTEM_UI_FLAG_LOW_PROFILE = 0x00000001; |
| 2147 | |
| 2148 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2149 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested that the |
| 2150 | * system navigation be temporarily hidden. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2151 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2152 | * <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] | 2153 | * {@link #SYSTEM_UI_FLAG_LOW_PROFILE}; on devices that draw essential navigation controls |
| 2154 | * (Home, Back, and the like) on screen, <code>SYSTEM_UI_FLAG_HIDE_NAVIGATION</code> will cause |
| 2155 | * those to disappear. This is useful (in conjunction with the |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2156 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN FLAG_FULLSCREEN} and |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2157 | * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN FLAG_LAYOUT_IN_SCREEN} |
| 2158 | * window flags) for displaying content using every last pixel on the display. |
| 2159 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2160 | * <p>There is a limitation: because navigation controls are so important, the least user |
| 2161 | * interaction will cause them to reappear immediately. When this happens, both |
| 2162 | * this flag and {@link #SYSTEM_UI_FLAG_FULLSCREEN} will be cleared automatically, |
| 2163 | * so that both elements reappear at the same time. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2164 | * |
| 2165 | * @see #setSystemUiVisibility(int) |
| 2166 | */ |
| 2167 | public static final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 0x00000002; |
| 2168 | |
| 2169 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2170 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested to go |
| 2171 | * into the normal fullscreen mode so that its content can take over the screen |
| 2172 | * while still allowing the user to interact with the application. |
| 2173 | * |
| 2174 | * <p>This has the same visual effect as |
| 2175 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN |
| 2176 | * WindowManager.LayoutParams.FLAG_FULLSCREEN}, |
| 2177 | * meaning that non-critical screen decorations (such as the status bar) will be |
| 2178 | * hidden while the user is in the View's window, focusing the experience on |
| 2179 | * that content. Unlike the window flag, if you are using ActionBar in |
| 2180 | * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 2181 | * Window.FEATURE_ACTION_BAR_OVERLAY}, then enabling this flag will also |
| 2182 | * hide the action bar. |
| 2183 | * |
| 2184 | * <p>This approach to going fullscreen is best used over the window flag when |
| 2185 | * it is a transient state -- that is, the application does this at certain |
| 2186 | * points in its user interaction where it wants to allow the user to focus |
| 2187 | * on content, but not as a continuous state. For situations where the application |
| 2188 | * would like to simply stay full screen the entire time (such as a game that |
| 2189 | * wants to take over the screen), the |
| 2190 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN window flag} |
| 2191 | * is usually a better approach. The state set here will be removed by the system |
| 2192 | * in various situations (such as the user moving to another application) like |
| 2193 | * the other system UI states. |
| 2194 | * |
| 2195 | * <p>When using this flag, the application should provide some easy facility |
| 2196 | * for the user to go out of it. A common example would be in an e-book |
| 2197 | * reader, where tapping on the screen brings back whatever screen and UI |
| 2198 | * decorations that had been hidden while the user was immersed in reading |
| 2199 | * the book. |
| 2200 | * |
| 2201 | * @see #setSystemUiVisibility(int) |
| 2202 | */ |
| 2203 | public static final int SYSTEM_UI_FLAG_FULLSCREEN = 0x00000004; |
| 2204 | |
| 2205 | /** |
| 2206 | * Flag for {@link #setSystemUiVisibility(int)}: When using other layout |
| 2207 | * flags, we would like a stable view of the content insets given to |
| 2208 | * {@link #fitSystemWindows(Rect)}. This means that the insets seen there |
| 2209 | * will always represent the worst case that the application can expect |
| 2210 | * as a continue state. In practice this means with any of system bar, |
| 2211 | * nav bar, and status bar shown, but not the space that would be needed |
| 2212 | * for an input method. |
| 2213 | * |
| 2214 | * <p>If you are using ActionBar in |
| 2215 | * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 2216 | * Window.FEATURE_ACTION_BAR_OVERLAY}, this flag will also impact the |
| 2217 | * insets it adds to those given to the application. |
| 2218 | */ |
| 2219 | public static final int SYSTEM_UI_FLAG_LAYOUT_STABLE = 0x00000100; |
| 2220 | |
| 2221 | /** |
| 2222 | * Flag for {@link #setSystemUiVisibility(int)}: View would like its window |
| 2223 | * to be layed out as if it has requested |
| 2224 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, even if it currently hasn't. This |
| 2225 | * allows it to avoid artifacts when switching in and out of that mode, at |
| 2226 | * the expense that some of its user interface may be covered by screen |
| 2227 | * decorations when they are shown. You can perform layout of your inner |
| 2228 | * UI elements to account for the navagation system UI through the |
| 2229 | * {@link #fitSystemWindows(Rect)} method. |
| 2230 | */ |
| 2231 | public static final int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = 0x00000200; |
| 2232 | |
| 2233 | /** |
| 2234 | * Flag for {@link #setSystemUiVisibility(int)}: View would like its window |
| 2235 | * to be layed out as if it has requested |
| 2236 | * {@link #SYSTEM_UI_FLAG_FULLSCREEN}, even if it currently hasn't. This |
| 2237 | * allows it to avoid artifacts when switching in and out of that mode, at |
| 2238 | * the expense that some of its user interface may be covered by screen |
| 2239 | * decorations when they are shown. You can perform layout of your inner |
| 2240 | * UI elements to account for non-fullscreen system UI through the |
| 2241 | * {@link #fitSystemWindows(Rect)} method. |
| 2242 | */ |
| 2243 | public static final int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 0x00000400; |
| 2244 | |
| 2245 | /** |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2246 | * @deprecated Use {@link #SYSTEM_UI_FLAG_LOW_PROFILE} instead. |
| 2247 | */ |
| 2248 | public static final int STATUS_BAR_HIDDEN = SYSTEM_UI_FLAG_LOW_PROFILE; |
| 2249 | |
| 2250 | /** |
| 2251 | * @deprecated Use {@link #SYSTEM_UI_FLAG_VISIBLE} instead. |
| 2252 | */ |
| 2253 | public static final int STATUS_BAR_VISIBLE = SYSTEM_UI_FLAG_VISIBLE; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2254 | |
| 2255 | /** |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2256 | * @hide |
| 2257 | * |
| 2258 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2259 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2260 | * |
| 2261 | * Flag to make the status bar not expandable. Unless you also |
| 2262 | * set {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show. |
| 2263 | */ |
| 2264 | public static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000; |
| 2265 | |
| 2266 | /** |
| 2267 | * @hide |
| 2268 | * |
| 2269 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2270 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2271 | * |
| 2272 | * Flag to hide notification icons and scrolling ticker text. |
| 2273 | */ |
| 2274 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ICONS = 0x00020000; |
| 2275 | |
| 2276 | /** |
| 2277 | * @hide |
| 2278 | * |
| 2279 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2280 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2281 | * |
| 2282 | * Flag to disable incoming notification alerts. This will not block |
| 2283 | * icons, but it will block sound, vibrating and other visual or aural notifications. |
| 2284 | */ |
| 2285 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ALERTS = 0x00040000; |
| 2286 | |
| 2287 | /** |
| 2288 | * @hide |
| 2289 | * |
| 2290 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2291 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2292 | * |
| 2293 | * Flag to hide only the scrolling ticker. Note that |
| 2294 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS} implies |
| 2295 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_TICKER}. |
| 2296 | */ |
| 2297 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_TICKER = 0x00080000; |
| 2298 | |
| 2299 | /** |
| 2300 | * @hide |
| 2301 | * |
| 2302 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2303 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2304 | * |
| 2305 | * Flag to hide the center system info area. |
| 2306 | */ |
| 2307 | public static final int STATUS_BAR_DISABLE_SYSTEM_INFO = 0x00100000; |
| 2308 | |
| 2309 | /** |
| 2310 | * @hide |
| 2311 | * |
| 2312 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2313 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2314 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2315 | * Flag to hide only the home button. Don't use this |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2316 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2317 | */ |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2318 | public static final int STATUS_BAR_DISABLE_HOME = 0x00200000; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2319 | |
| 2320 | /** |
| 2321 | * @hide |
| 2322 | * |
| 2323 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2324 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2325 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2326 | * Flag to hide only the back button. Don't use this |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 2327 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2328 | */ |
| 2329 | public static final int STATUS_BAR_DISABLE_BACK = 0x00400000; |
| 2330 | |
| 2331 | /** |
| 2332 | * @hide |
| 2333 | * |
| 2334 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2335 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2336 | * |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2337 | * Flag to hide only the clock. You might use this if your activity has |
| 2338 | * its own clock making the status bar's clock redundant. |
| 2339 | */ |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 2340 | public static final int STATUS_BAR_DISABLE_CLOCK = 0x00800000; |
| 2341 | |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2342 | /** |
| 2343 | * @hide |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2344 | * |
| 2345 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2346 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2347 | * |
| 2348 | * Flag to hide only the recent apps button. Don't use this |
| 2349 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2350 | */ |
| 2351 | public static final int STATUS_BAR_DISABLE_RECENT = 0x01000000; |
| 2352 | |
| 2353 | /** |
| 2354 | * @hide |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2355 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2356 | public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK = 0x0000FFFF; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2357 | |
| 2358 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2359 | * These are the system UI flags that can be cleared by events outside |
| 2360 | * of an application. Currently this is just the ability to tap on the |
| 2361 | * screen while hiding the navigation bar to have it return. |
| 2362 | * @hide |
| 2363 | */ |
| 2364 | public static final int SYSTEM_UI_CLEARABLE_FLAGS = |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2365 | SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_HIDE_NAVIGATION |
| 2366 | | SYSTEM_UI_FLAG_FULLSCREEN; |
| 2367 | |
| 2368 | /** |
| 2369 | * Flags that can impact the layout in relation to system UI. |
| 2370 | */ |
| 2371 | public static final int SYSTEM_UI_LAYOUT_FLAGS = |
| 2372 | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
| 2373 | | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2374 | |
| 2375 | /** |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 2376 | * Find views that render the specified text. |
| 2377 | * |
| 2378 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2379 | */ |
| 2380 | public static final int FIND_VIEWS_WITH_TEXT = 0x00000001; |
| 2381 | |
| 2382 | /** |
| 2383 | * Find find views that contain the specified content description. |
| 2384 | * |
| 2385 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2386 | */ |
| 2387 | public static final int FIND_VIEWS_WITH_CONTENT_DESCRIPTION = 0x00000002; |
| 2388 | |
| 2389 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 2390 | * Find views that contain {@link AccessibilityNodeProvider}. Such |
| 2391 | * a View is a root of virtual view hierarchy and may contain the searched |
| 2392 | * text. If this flag is set Views with providers are automatically |
| 2393 | * added and it is a responsibility of the client to call the APIs of |
| 2394 | * the provider to determine whether the virtual tree rooted at this View |
| 2395 | * contains the text, i.e. getting the list of {@link AccessibilityNodeInfo}s |
| 2396 | * represeting the virtual views with this text. |
| 2397 | * |
| 2398 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2399 | * |
| 2400 | * @hide |
| 2401 | */ |
| 2402 | public static final int FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS = 0x00000004; |
| 2403 | |
| 2404 | /** |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 2405 | * Indicates that the screen has changed state and is now off. |
| 2406 | * |
| 2407 | * @see #onScreenStateChanged(int) |
| 2408 | */ |
| 2409 | public static final int SCREEN_STATE_OFF = 0x0; |
| 2410 | |
| 2411 | /** |
| 2412 | * Indicates that the screen has changed state and is now on. |
| 2413 | * |
Romain Guy | 1e3d313 | 2012-03-08 15:55:56 -0800 | [diff] [blame] | 2414 | * @see #onScreenStateChanged(int) |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 2415 | */ |
| 2416 | public static final int SCREEN_STATE_ON = 0x1; |
| 2417 | |
| 2418 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2419 | * Controls the over-scroll mode for this view. |
| 2420 | * See {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)}, |
| 2421 | * {@link #OVER_SCROLL_ALWAYS}, {@link #OVER_SCROLL_IF_CONTENT_SCROLLS}, |
| 2422 | * and {@link #OVER_SCROLL_NEVER}. |
| 2423 | */ |
| 2424 | private int mOverScrollMode; |
| 2425 | |
| 2426 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2427 | * The parent this view is attached to. |
| 2428 | * {@hide} |
| 2429 | * |
| 2430 | * @see #getParent() |
| 2431 | */ |
| 2432 | protected ViewParent mParent; |
| 2433 | |
| 2434 | /** |
| 2435 | * {@hide} |
| 2436 | */ |
| 2437 | AttachInfo mAttachInfo; |
| 2438 | |
| 2439 | /** |
| 2440 | * {@hide} |
| 2441 | */ |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2442 | @ViewDebug.ExportedProperty(flagMapping = { |
| 2443 | @ViewDebug.FlagToString(mask = FORCE_LAYOUT, equals = FORCE_LAYOUT, |
| 2444 | name = "FORCE_LAYOUT"), |
| 2445 | @ViewDebug.FlagToString(mask = LAYOUT_REQUIRED, equals = LAYOUT_REQUIRED, |
| 2446 | name = "LAYOUT_REQUIRED"), |
| 2447 | @ViewDebug.FlagToString(mask = DRAWING_CACHE_VALID, equals = DRAWING_CACHE_VALID, |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 2448 | name = "DRAWING_CACHE_INVALID", outputIf = false), |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2449 | @ViewDebug.FlagToString(mask = DRAWN, equals = DRAWN, name = "DRAWN", outputIf = true), |
| 2450 | @ViewDebug.FlagToString(mask = DRAWN, equals = DRAWN, name = "NOT_DRAWN", outputIf = false), |
| 2451 | @ViewDebug.FlagToString(mask = DIRTY_MASK, equals = DIRTY_OPAQUE, name = "DIRTY_OPAQUE"), |
| 2452 | @ViewDebug.FlagToString(mask = DIRTY_MASK, equals = DIRTY, name = "DIRTY") |
| 2453 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2454 | int mPrivateFlags; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2455 | int mPrivateFlags2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2456 | |
| 2457 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2458 | * This view's request for the visibility of the status bar. |
| 2459 | * @hide |
| 2460 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2461 | @ViewDebug.ExportedProperty(flagMapping = { |
| 2462 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2463 | equals = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2464 | name = "SYSTEM_UI_FLAG_LOW_PROFILE", outputIf = true), |
| 2465 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2466 | equals = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2467 | name = "SYSTEM_UI_FLAG_HIDE_NAVIGATION", outputIf = true), |
| 2468 | @ViewDebug.FlagToString(mask = PUBLIC_STATUS_BAR_VISIBILITY_MASK, |
| 2469 | equals = SYSTEM_UI_FLAG_VISIBLE, |
| 2470 | name = "SYSTEM_UI_FLAG_VISIBLE", outputIf = true) |
| 2471 | }) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2472 | int mSystemUiVisibility; |
| 2473 | |
| 2474 | /** |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame^] | 2475 | * Reference count for transient state. |
| 2476 | * @see #setHasTransientState(boolean) |
| 2477 | */ |
| 2478 | int mTransientStateCount = 0; |
| 2479 | |
| 2480 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2481 | * Count of how many windows this view has been attached to. |
| 2482 | */ |
| 2483 | int mWindowAttachCount; |
| 2484 | |
| 2485 | /** |
| 2486 | * The layout parameters associated with this view and used by the parent |
| 2487 | * {@link android.view.ViewGroup} to determine how this view should be |
| 2488 | * laid out. |
| 2489 | * {@hide} |
| 2490 | */ |
| 2491 | protected ViewGroup.LayoutParams mLayoutParams; |
| 2492 | |
| 2493 | /** |
| 2494 | * The view flags hold various views states. |
| 2495 | * {@hide} |
| 2496 | */ |
| 2497 | @ViewDebug.ExportedProperty |
| 2498 | int mViewFlags; |
| 2499 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2500 | static class TransformationInfo { |
| 2501 | /** |
| 2502 | * The transform matrix for the View. This transform is calculated internally |
| 2503 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2504 | * is used by default. Do *not* use this variable directly; instead call |
| 2505 | * getMatrix(), which will automatically recalculate the matrix if necessary |
| 2506 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2507 | */ |
| 2508 | private final Matrix mMatrix = new Matrix(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2509 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2510 | /** |
| 2511 | * The transform matrix for the View. This transform is calculated internally |
| 2512 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2513 | * is used by default. Do *not* use this variable directly; instead call |
| 2514 | * getInverseMatrix(), which will automatically recalculate the matrix if necessary |
| 2515 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2516 | */ |
| 2517 | private Matrix mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2518 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2519 | /** |
| 2520 | * An internal variable that tracks whether we need to recalculate the |
| 2521 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2522 | * have changed since the matrix was last calculated. |
| 2523 | */ |
| 2524 | boolean mMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2525 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2526 | /** |
| 2527 | * An internal variable that tracks whether we need to recalculate the |
| 2528 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2529 | * have changed since the matrix was last calculated. |
| 2530 | */ |
| 2531 | private boolean mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2532 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2533 | /** |
| 2534 | * A variable that tracks whether we need to recalculate the |
| 2535 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2536 | * have changed since the matrix was last calculated. This variable |
| 2537 | * is only valid after a call to updateMatrix() or to a function that |
| 2538 | * calls it such as getMatrix(), hasIdentityMatrix() and getInverseMatrix(). |
| 2539 | */ |
| 2540 | private boolean mMatrixIsIdentity = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2541 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2542 | /** |
| 2543 | * The Camera object is used to compute a 3D matrix when rotationX or rotationY are set. |
| 2544 | */ |
| 2545 | private Camera mCamera = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2546 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2547 | /** |
| 2548 | * This matrix is used when computing the matrix for 3D rotations. |
| 2549 | */ |
| 2550 | private Matrix matrix3D = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2551 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2552 | /** |
| 2553 | * These prev values are used to recalculate a centered pivot point when necessary. The |
| 2554 | * pivot point is only used in matrix operations (when rotation, scale, or translation are |
| 2555 | * set), so thes values are only used then as well. |
| 2556 | */ |
| 2557 | private int mPrevWidth = -1; |
| 2558 | private int mPrevHeight = -1; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2559 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2560 | /** |
| 2561 | * The degrees rotation around the vertical axis through the pivot point. |
| 2562 | */ |
| 2563 | @ViewDebug.ExportedProperty |
| 2564 | float mRotationY = 0f; |
| 2565 | |
| 2566 | /** |
| 2567 | * The degrees rotation around the horizontal axis through the pivot point. |
| 2568 | */ |
| 2569 | @ViewDebug.ExportedProperty |
| 2570 | float mRotationX = 0f; |
| 2571 | |
| 2572 | /** |
| 2573 | * The degrees rotation around the pivot point. |
| 2574 | */ |
| 2575 | @ViewDebug.ExportedProperty |
| 2576 | float mRotation = 0f; |
| 2577 | |
| 2578 | /** |
| 2579 | * The amount of translation of the object away from its left property (post-layout). |
| 2580 | */ |
| 2581 | @ViewDebug.ExportedProperty |
| 2582 | float mTranslationX = 0f; |
| 2583 | |
| 2584 | /** |
| 2585 | * The amount of translation of the object away from its top property (post-layout). |
| 2586 | */ |
| 2587 | @ViewDebug.ExportedProperty |
| 2588 | float mTranslationY = 0f; |
| 2589 | |
| 2590 | /** |
| 2591 | * The amount of scale in the x direction around the pivot point. A |
| 2592 | * value of 1 means no scaling is applied. |
| 2593 | */ |
| 2594 | @ViewDebug.ExportedProperty |
| 2595 | float mScaleX = 1f; |
| 2596 | |
| 2597 | /** |
| 2598 | * The amount of scale in the y direction around the pivot point. A |
| 2599 | * value of 1 means no scaling is applied. |
| 2600 | */ |
| 2601 | @ViewDebug.ExportedProperty |
| 2602 | float mScaleY = 1f; |
| 2603 | |
| 2604 | /** |
Chet Haase | a33de55 | 2012-02-03 16:28:24 -0800 | [diff] [blame] | 2605 | * 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] | 2606 | */ |
| 2607 | @ViewDebug.ExportedProperty |
| 2608 | float mPivotX = 0f; |
| 2609 | |
| 2610 | /** |
Chet Haase | a33de55 | 2012-02-03 16:28:24 -0800 | [diff] [blame] | 2611 | * 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] | 2612 | */ |
| 2613 | @ViewDebug.ExportedProperty |
| 2614 | float mPivotY = 0f; |
| 2615 | |
| 2616 | /** |
| 2617 | * The opacity of the View. This is a value from 0 to 1, where 0 means |
| 2618 | * completely transparent and 1 means completely opaque. |
| 2619 | */ |
| 2620 | @ViewDebug.ExportedProperty |
| 2621 | float mAlpha = 1f; |
| 2622 | } |
| 2623 | |
| 2624 | TransformationInfo mTransformationInfo; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2625 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2626 | private boolean mLastIsOpaque; |
| 2627 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2628 | /** |
| 2629 | * Convenience value to check for float values that are close enough to zero to be considered |
| 2630 | * zero. |
| 2631 | */ |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame] | 2632 | private static final float NONZERO_EPSILON = .001f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2633 | |
| 2634 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2635 | * The distance in pixels from the left edge of this view's parent |
| 2636 | * to the left edge of this view. |
| 2637 | * {@hide} |
| 2638 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2639 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2640 | protected int mLeft; |
| 2641 | /** |
| 2642 | * The distance in pixels from the left edge of this view's parent |
| 2643 | * to the right edge of this view. |
| 2644 | * {@hide} |
| 2645 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2646 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2647 | protected int mRight; |
| 2648 | /** |
| 2649 | * The distance in pixels from the top edge of this view's parent |
| 2650 | * to the top edge of this view. |
| 2651 | * {@hide} |
| 2652 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2653 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2654 | protected int mTop; |
| 2655 | /** |
| 2656 | * The distance in pixels from the top edge of this view's parent |
| 2657 | * to the bottom edge of this view. |
| 2658 | * {@hide} |
| 2659 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2660 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | protected int mBottom; |
| 2662 | |
| 2663 | /** |
| 2664 | * The offset, in pixels, by which the content of this view is scrolled |
| 2665 | * horizontally. |
| 2666 | * {@hide} |
| 2667 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2668 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2669 | protected int mScrollX; |
| 2670 | /** |
| 2671 | * The offset, in pixels, by which the content of this view is scrolled |
| 2672 | * vertically. |
| 2673 | * {@hide} |
| 2674 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2675 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2676 | protected int mScrollY; |
| 2677 | |
| 2678 | /** |
| 2679 | * The left padding in pixels, that is the distance in pixels between the |
| 2680 | * left edge of this view and the left edge of its content. |
| 2681 | * {@hide} |
| 2682 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2683 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2684 | protected int mPaddingLeft; |
| 2685 | /** |
| 2686 | * The right padding in pixels, that is the distance in pixels between the |
| 2687 | * right edge of this view and the right edge of its content. |
| 2688 | * {@hide} |
| 2689 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2690 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2691 | protected int mPaddingRight; |
| 2692 | /** |
| 2693 | * The top padding in pixels, that is the distance in pixels between the |
| 2694 | * top edge of this view and the top edge of its content. |
| 2695 | * {@hide} |
| 2696 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2697 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2698 | protected int mPaddingTop; |
| 2699 | /** |
| 2700 | * The bottom padding in pixels, that is the distance in pixels between the |
| 2701 | * bottom edge of this view and the bottom edge of its content. |
| 2702 | * {@hide} |
| 2703 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2704 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2705 | protected int mPaddingBottom; |
| 2706 | |
| 2707 | /** |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 2708 | * The layout insets in pixels, that is the distance in pixels between the |
| 2709 | * visible edges of this view its bounds. |
| 2710 | */ |
| 2711 | private Insets mLayoutInsets; |
| 2712 | |
| 2713 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2714 | * Briefly describes the view and is primarily used for accessibility support. |
| 2715 | */ |
| 2716 | private CharSequence mContentDescription; |
| 2717 | |
| 2718 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2719 | * 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] | 2720 | * |
| 2721 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2722 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2723 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2724 | protected int mUserPaddingRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2725 | |
| 2726 | /** |
| 2727 | * 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] | 2728 | * |
| 2729 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2730 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2731 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2732 | protected int mUserPaddingBottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2733 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2734 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2735 | * 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] | 2736 | * |
| 2737 | * @hide |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2738 | */ |
| 2739 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2740 | protected int mUserPaddingLeft; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2741 | |
| 2742 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 2743 | * Cache if the user padding is relative. |
| 2744 | * |
| 2745 | */ |
| 2746 | @ViewDebug.ExportedProperty(category = "padding") |
| 2747 | boolean mUserPaddingRelative; |
| 2748 | |
| 2749 | /** |
| 2750 | * Cache the paddingStart set by the user to append to the scrollbar's size. |
| 2751 | * |
| 2752 | */ |
| 2753 | @ViewDebug.ExportedProperty(category = "padding") |
| 2754 | int mUserPaddingStart; |
| 2755 | |
| 2756 | /** |
| 2757 | * Cache the paddingEnd set by the user to append to the scrollbar's size. |
| 2758 | * |
| 2759 | */ |
| 2760 | @ViewDebug.ExportedProperty(category = "padding") |
| 2761 | int mUserPaddingEnd; |
| 2762 | |
| 2763 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2764 | * @hide |
| 2765 | */ |
| 2766 | int mOldWidthMeasureSpec = Integer.MIN_VALUE; |
| 2767 | /** |
| 2768 | * @hide |
| 2769 | */ |
| 2770 | int mOldHeightMeasureSpec = Integer.MIN_VALUE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2771 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2772 | private Drawable mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2773 | |
| 2774 | private int mBackgroundResource; |
| 2775 | private boolean mBackgroundSizeChanged; |
| 2776 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2777 | static class ListenerInfo { |
| 2778 | /** |
| 2779 | * Listener used to dispatch focus change events. |
| 2780 | * This field should be made private, so it is hidden from the SDK. |
| 2781 | * {@hide} |
| 2782 | */ |
| 2783 | protected OnFocusChangeListener mOnFocusChangeListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2784 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2785 | /** |
| 2786 | * Listeners for layout change events. |
| 2787 | */ |
| 2788 | private ArrayList<OnLayoutChangeListener> mOnLayoutChangeListeners; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 2789 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2790 | /** |
| 2791 | * Listeners for attach events. |
| 2792 | */ |
| 2793 | private CopyOnWriteArrayList<OnAttachStateChangeListener> mOnAttachStateChangeListeners; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 2794 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2795 | /** |
| 2796 | * Listener used to dispatch click events. |
| 2797 | * This field should be made private, so it is hidden from the SDK. |
| 2798 | * {@hide} |
| 2799 | */ |
| 2800 | public OnClickListener mOnClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2801 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2802 | /** |
| 2803 | * Listener used to dispatch long click events. |
| 2804 | * This field should be made private, so it is hidden from the SDK. |
| 2805 | * {@hide} |
| 2806 | */ |
| 2807 | protected OnLongClickListener mOnLongClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2808 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2809 | /** |
| 2810 | * Listener used to build the context menu. |
| 2811 | * This field should be made private, so it is hidden from the SDK. |
| 2812 | * {@hide} |
| 2813 | */ |
| 2814 | protected OnCreateContextMenuListener mOnCreateContextMenuListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2815 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2816 | private OnKeyListener mOnKeyListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2817 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2818 | private OnTouchListener mOnTouchListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2819 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2820 | private OnHoverListener mOnHoverListener; |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2821 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2822 | private OnGenericMotionListener mOnGenericMotionListener; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2823 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2824 | private OnDragListener mOnDragListener; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 2825 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2826 | private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener; |
| 2827 | } |
| 2828 | |
| 2829 | ListenerInfo mListenerInfo; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2830 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2831 | /** |
| 2832 | * The application environment this view lives in. |
| 2833 | * This field should be made private, so it is hidden from the SDK. |
| 2834 | * {@hide} |
| 2835 | */ |
| 2836 | protected Context mContext; |
| 2837 | |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 2838 | private final Resources mResources; |
| 2839 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2840 | private ScrollabilityCache mScrollCache; |
| 2841 | |
| 2842 | private int[] mDrawableState = null; |
| 2843 | |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2844 | /** |
| 2845 | * Set to true when drawing cache is enabled and cannot be created. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2846 | * |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2847 | * @hide |
| 2848 | */ |
| 2849 | public boolean mCachingFailed; |
| 2850 | |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 2851 | private Bitmap mDrawingCache; |
| 2852 | private Bitmap mUnscaledDrawingCache; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 2853 | private HardwareLayer mHardwareLayer; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2854 | DisplayList mDisplayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2855 | |
| 2856 | /** |
| 2857 | * When this view has focus and the next focus is {@link #FOCUS_LEFT}, |
| 2858 | * the user may specify which view to go to next. |
| 2859 | */ |
| 2860 | private int mNextFocusLeftId = View.NO_ID; |
| 2861 | |
| 2862 | /** |
| 2863 | * When this view has focus and the next focus is {@link #FOCUS_RIGHT}, |
| 2864 | * the user may specify which view to go to next. |
| 2865 | */ |
| 2866 | private int mNextFocusRightId = View.NO_ID; |
| 2867 | |
| 2868 | /** |
| 2869 | * When this view has focus and the next focus is {@link #FOCUS_UP}, |
| 2870 | * the user may specify which view to go to next. |
| 2871 | */ |
| 2872 | private int mNextFocusUpId = View.NO_ID; |
| 2873 | |
| 2874 | /** |
| 2875 | * When this view has focus and the next focus is {@link #FOCUS_DOWN}, |
| 2876 | * the user may specify which view to go to next. |
| 2877 | */ |
| 2878 | private int mNextFocusDownId = View.NO_ID; |
| 2879 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 2880 | /** |
| 2881 | * When this view has focus and the next focus is {@link #FOCUS_FORWARD}, |
| 2882 | * the user may specify which view to go to next. |
| 2883 | */ |
| 2884 | int mNextFocusForwardId = View.NO_ID; |
| 2885 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2886 | private CheckForLongPress mPendingCheckForLongPress; |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2887 | private CheckForTap mPendingCheckForTap = null; |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 2888 | private PerformClick mPerformClick; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 2889 | private SendViewScrolledAccessibilityEvent mSendViewScrolledAccessibilityEvent; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2890 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2891 | private UnsetPressedState mUnsetPressedState; |
| 2892 | |
| 2893 | /** |
| 2894 | * Whether the long press's action has been invoked. The tap's action is invoked on the |
| 2895 | * up event while a long press is invoked as soon as the long press duration is reached, so |
| 2896 | * a long press could be performed before the tap is checked, in which case the tap's action |
| 2897 | * should not be invoked. |
| 2898 | */ |
| 2899 | private boolean mHasPerformedLongPress; |
| 2900 | |
| 2901 | /** |
| 2902 | * The minimum height of the view. We'll try our best to have the height |
| 2903 | * of this view to at least this amount. |
| 2904 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2905 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2906 | private int mMinHeight; |
| 2907 | |
| 2908 | /** |
| 2909 | * The minimum width of the view. We'll try our best to have the width |
| 2910 | * of this view to at least this amount. |
| 2911 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2912 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2913 | private int mMinWidth; |
| 2914 | |
| 2915 | /** |
| 2916 | * The delegate to handle touch events that are physically in this view |
| 2917 | * but should be handled by another view. |
| 2918 | */ |
| 2919 | private TouchDelegate mTouchDelegate = null; |
| 2920 | |
| 2921 | /** |
| 2922 | * Solid color to use as a background when creating the drawing cache. Enables |
| 2923 | * the cache to use 16 bit bitmaps instead of 32 bit. |
| 2924 | */ |
| 2925 | private int mDrawingCacheBackgroundColor = 0; |
| 2926 | |
| 2927 | /** |
| 2928 | * Special tree observer used when mAttachInfo is null. |
| 2929 | */ |
| 2930 | private ViewTreeObserver mFloatingTreeObserver; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2931 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2932 | /** |
| 2933 | * Cache the touch slop from the context that created the view. |
| 2934 | */ |
| 2935 | private int mTouchSlop; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2936 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2937 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2938 | * Object that handles automatic animation of view properties. |
| 2939 | */ |
| 2940 | private ViewPropertyAnimator mAnimator = null; |
| 2941 | |
| 2942 | /** |
Christopher Tate | 251602f | 2011-01-28 17:54:12 -0800 | [diff] [blame] | 2943 | * Flag indicating that a drag can cross window boundaries. When |
| 2944 | * {@link #startDrag(ClipData, DragShadowBuilder, Object, int)} is called |
| 2945 | * with this flag set, all visible applications will be able to participate |
| 2946 | * in the drag operation and receive the dragged content. |
Christopher Tate | 7f9ff9d | 2011-02-14 17:31:13 -0800 | [diff] [blame] | 2947 | * |
| 2948 | * @hide |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 2949 | */ |
| 2950 | public static final int DRAG_FLAG_GLOBAL = 1; |
| 2951 | |
| 2952 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2953 | * Vertical scroll factor cached by {@link #getVerticalScrollFactor}. |
| 2954 | */ |
| 2955 | private float mVerticalScrollFactor; |
| 2956 | |
| 2957 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2958 | * Position of the vertical scroll bar. |
| 2959 | */ |
| 2960 | private int mVerticalScrollbarPosition; |
| 2961 | |
| 2962 | /** |
| 2963 | * Position the scroll bar at the default position as determined by the system. |
| 2964 | */ |
| 2965 | public static final int SCROLLBAR_POSITION_DEFAULT = 0; |
| 2966 | |
| 2967 | /** |
| 2968 | * Position the scroll bar along the left edge. |
| 2969 | */ |
| 2970 | public static final int SCROLLBAR_POSITION_LEFT = 1; |
| 2971 | |
| 2972 | /** |
| 2973 | * Position the scroll bar along the right edge. |
| 2974 | */ |
| 2975 | public static final int SCROLLBAR_POSITION_RIGHT = 2; |
| 2976 | |
| 2977 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2978 | * Indicates that the view does not have a layer. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2979 | * |
| 2980 | * @see #getLayerType() |
| 2981 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2982 | * @see #LAYER_TYPE_SOFTWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2983 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2984 | */ |
| 2985 | public static final int LAYER_TYPE_NONE = 0; |
| 2986 | |
| 2987 | /** |
| 2988 | * <p>Indicates that the view has a software layer. A software layer is backed |
| 2989 | * by a bitmap and causes the view to be rendered using Android's software |
| 2990 | * rendering pipeline, even if hardware acceleration is enabled.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2991 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2992 | * <p>Software layers have various usages:</p> |
| 2993 | * <p>When the application is not using hardware acceleration, a software layer |
| 2994 | * is useful to apply a specific color filter and/or blending mode and/or |
| 2995 | * translucency to a view and all its children.</p> |
| 2996 | * <p>When the application is using hardware acceleration, a software layer |
| 2997 | * is useful to render drawing primitives not supported by the hardware |
| 2998 | * accelerated pipeline. It can also be used to cache a complex view tree |
| 2999 | * into a texture and reduce the complexity of drawing operations. For instance, |
| 3000 | * when animating a complex view tree with a translation, a software layer can |
| 3001 | * be used to render the view tree only once.</p> |
| 3002 | * <p>Software layers should be avoided when the affected view tree updates |
| 3003 | * often. Every update will require to re-render the software layer, which can |
| 3004 | * potentially be slow (particularly when hardware acceleration is turned on |
| 3005 | * since the layer will have to be uploaded into a hardware texture after every |
| 3006 | * update.)</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3007 | * |
| 3008 | * @see #getLayerType() |
| 3009 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3010 | * @see #LAYER_TYPE_NONE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3011 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3012 | */ |
| 3013 | public static final int LAYER_TYPE_SOFTWARE = 1; |
| 3014 | |
| 3015 | /** |
| 3016 | * <p>Indicates that the view has a hardware layer. A hardware layer is backed |
| 3017 | * by a hardware specific texture (generally Frame Buffer Objects or FBO on |
| 3018 | * OpenGL hardware) and causes the view to be rendered using Android's hardware |
| 3019 | * rendering pipeline, but only if hardware acceleration is turned on for the |
| 3020 | * view hierarchy. When hardware acceleration is turned off, hardware layers |
| 3021 | * behave exactly as {@link #LAYER_TYPE_SOFTWARE software layers}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3022 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3023 | * <p>A hardware layer is useful to apply a specific color filter and/or |
| 3024 | * 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] | 3025 | * <p>A hardware layer can be used to cache a complex view tree into a |
| 3026 | * texture and reduce the complexity of drawing operations. For instance, |
| 3027 | * when animating a complex view tree with a translation, a hardware layer can |
| 3028 | * be used to render the view tree only once.</p> |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3029 | * <p>A hardware layer can also be used to increase the rendering quality when |
| 3030 | * rotation transformations are applied on a view. It can also be used to |
| 3031 | * prevent potential clipping issues when applying 3D transforms on a view.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3032 | * |
| 3033 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3034 | * @see #setLayerType(int, android.graphics.Paint) |
| 3035 | * @see #LAYER_TYPE_NONE |
| 3036 | * @see #LAYER_TYPE_SOFTWARE |
| 3037 | */ |
| 3038 | public static final int LAYER_TYPE_HARDWARE = 2; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3039 | |
Romain Guy | 3aaff3a | 2011-01-12 14:18:47 -0800 | [diff] [blame] | 3040 | @ViewDebug.ExportedProperty(category = "drawing", mapping = { |
| 3041 | @ViewDebug.IntToString(from = LAYER_TYPE_NONE, to = "NONE"), |
| 3042 | @ViewDebug.IntToString(from = LAYER_TYPE_SOFTWARE, to = "SOFTWARE"), |
| 3043 | @ViewDebug.IntToString(from = LAYER_TYPE_HARDWARE, to = "HARDWARE") |
| 3044 | }) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3045 | int mLayerType = LAYER_TYPE_NONE; |
| 3046 | Paint mLayerPaint; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 3047 | Rect mLocalDirtyRect; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3048 | |
| 3049 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 3050 | * Set to true when the view is sending hover accessibility events because it |
| 3051 | * is the innermost hovered view. |
| 3052 | */ |
| 3053 | private boolean mSendingHoverAccessibilityEvents; |
| 3054 | |
| 3055 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3056 | * Simple constructor to use when creating a view from code. |
| 3057 | * |
| 3058 | * @param context The Context the view is running in, through which it can |
| 3059 | * access the current theme, resources, etc. |
| 3060 | */ |
| 3061 | public View(Context context) { |
| 3062 | mContext = context; |
| 3063 | mResources = context != null ? context.getResources() : null; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3064 | mViewFlags = SOUND_EFFECTS_ENABLED | HAPTIC_FEEDBACK_ENABLED; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3065 | // Set layout and text direction defaults |
| 3066 | mPrivateFlags2 = (LAYOUT_DIRECTION_DEFAULT << LAYOUT_DIRECTION_MASK_SHIFT) | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3067 | (TEXT_DIRECTION_DEFAULT << TEXT_DIRECTION_MASK_SHIFT) | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3068 | (TEXT_ALIGNMENT_DEFAULT << TEXT_ALIGNMENT_MASK_SHIFT) | |
| 3069 | (IMPORTANT_FOR_ACCESSIBILITY_DEFAULT << IMPORTANT_FOR_ACCESSIBILITY_SHIFT); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 3070 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3071 | setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS); |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 3072 | mUserPaddingStart = -1; |
| 3073 | mUserPaddingEnd = -1; |
| 3074 | mUserPaddingRelative = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3075 | } |
| 3076 | |
| 3077 | /** |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 3078 | * Delegate for injecting accessiblity functionality. |
| 3079 | */ |
| 3080 | AccessibilityDelegate mAccessibilityDelegate; |
| 3081 | |
| 3082 | /** |
| 3083 | * Consistency verifier for debugging purposes. |
| 3084 | * @hide |
| 3085 | */ |
| 3086 | protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = |
| 3087 | InputEventConsistencyVerifier.isInstrumentationEnabled() ? |
| 3088 | new InputEventConsistencyVerifier(this, 0) : null; |
| 3089 | |
| 3090 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3091 | * Constructor that is called when inflating a view from XML. This is called |
| 3092 | * when a view is being constructed from an XML file, supplying attributes |
| 3093 | * that were specified in the XML file. This version uses a default style of |
| 3094 | * 0, so the only attribute values applied are those in the Context's Theme |
| 3095 | * and the given AttributeSet. |
| 3096 | * |
| 3097 | * <p> |
| 3098 | * The method onFinishInflate() will be called after all children have been |
| 3099 | * added. |
| 3100 | * |
| 3101 | * @param context The Context the view is running in, through which it can |
| 3102 | * access the current theme, resources, etc. |
| 3103 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 3104 | * @see #View(Context, AttributeSet, int) |
| 3105 | */ |
| 3106 | public View(Context context, AttributeSet attrs) { |
| 3107 | this(context, attrs, 0); |
| 3108 | } |
| 3109 | |
| 3110 | /** |
| 3111 | * Perform inflation from XML and apply a class-specific base style. This |
| 3112 | * constructor of View allows subclasses to use their own base style when |
| 3113 | * they are inflating. For example, a Button class's constructor would call |
| 3114 | * this version of the super class constructor and supply |
| 3115 | * <code>R.attr.buttonStyle</code> for <var>defStyle</var>; this allows |
| 3116 | * the theme's button style to modify all of the base view attributes (in |
| 3117 | * particular its background) as well as the Button class's attributes. |
| 3118 | * |
| 3119 | * @param context The Context the view is running in, through which it can |
| 3120 | * access the current theme, resources, etc. |
| 3121 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 3122 | * @param defStyle The default style to apply to this view. If 0, no style |
| 3123 | * will be applied (beyond what is included in the theme). This may |
| 3124 | * either be an attribute resource, whose value will be retrieved |
| 3125 | * from the current theme, or an explicit style resource. |
| 3126 | * @see #View(Context, AttributeSet) |
| 3127 | */ |
| 3128 | public View(Context context, AttributeSet attrs, int defStyle) { |
| 3129 | this(context); |
| 3130 | |
| 3131 | TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View, |
| 3132 | defStyle, 0); |
| 3133 | |
| 3134 | Drawable background = null; |
| 3135 | |
| 3136 | int leftPadding = -1; |
| 3137 | int topPadding = -1; |
| 3138 | int rightPadding = -1; |
| 3139 | int bottomPadding = -1; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3140 | int startPadding = -1; |
| 3141 | int endPadding = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3142 | |
| 3143 | int padding = -1; |
| 3144 | |
| 3145 | int viewFlagValues = 0; |
| 3146 | int viewFlagMasks = 0; |
| 3147 | |
| 3148 | boolean setScrollContainer = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3150 | int x = 0; |
| 3151 | int y = 0; |
| 3152 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3153 | float tx = 0; |
| 3154 | float ty = 0; |
| 3155 | float rotation = 0; |
| 3156 | float rotationX = 0; |
| 3157 | float rotationY = 0; |
| 3158 | float sx = 1f; |
| 3159 | float sy = 1f; |
| 3160 | boolean transformSet = false; |
| 3161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3162 | int scrollbarStyle = SCROLLBARS_INSIDE_OVERLAY; |
| 3163 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3164 | int overScrollMode = mOverScrollMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3165 | final int N = a.getIndexCount(); |
| 3166 | for (int i = 0; i < N; i++) { |
| 3167 | int attr = a.getIndex(i); |
| 3168 | switch (attr) { |
| 3169 | case com.android.internal.R.styleable.View_background: |
| 3170 | background = a.getDrawable(attr); |
| 3171 | break; |
| 3172 | case com.android.internal.R.styleable.View_padding: |
| 3173 | padding = a.getDimensionPixelSize(attr, -1); |
| 3174 | break; |
| 3175 | case com.android.internal.R.styleable.View_paddingLeft: |
| 3176 | leftPadding = a.getDimensionPixelSize(attr, -1); |
| 3177 | break; |
| 3178 | case com.android.internal.R.styleable.View_paddingTop: |
| 3179 | topPadding = a.getDimensionPixelSize(attr, -1); |
| 3180 | break; |
| 3181 | case com.android.internal.R.styleable.View_paddingRight: |
| 3182 | rightPadding = a.getDimensionPixelSize(attr, -1); |
| 3183 | break; |
| 3184 | case com.android.internal.R.styleable.View_paddingBottom: |
| 3185 | bottomPadding = a.getDimensionPixelSize(attr, -1); |
| 3186 | break; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3187 | case com.android.internal.R.styleable.View_paddingStart: |
| 3188 | startPadding = a.getDimensionPixelSize(attr, -1); |
| 3189 | break; |
| 3190 | case com.android.internal.R.styleable.View_paddingEnd: |
| 3191 | endPadding = a.getDimensionPixelSize(attr, -1); |
| 3192 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3193 | case com.android.internal.R.styleable.View_scrollX: |
| 3194 | x = a.getDimensionPixelOffset(attr, 0); |
| 3195 | break; |
| 3196 | case com.android.internal.R.styleable.View_scrollY: |
| 3197 | y = a.getDimensionPixelOffset(attr, 0); |
| 3198 | break; |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3199 | case com.android.internal.R.styleable.View_alpha: |
| 3200 | setAlpha(a.getFloat(attr, 1f)); |
| 3201 | break; |
| 3202 | case com.android.internal.R.styleable.View_transformPivotX: |
| 3203 | setPivotX(a.getDimensionPixelOffset(attr, 0)); |
| 3204 | break; |
| 3205 | case com.android.internal.R.styleable.View_transformPivotY: |
| 3206 | setPivotY(a.getDimensionPixelOffset(attr, 0)); |
| 3207 | break; |
| 3208 | case com.android.internal.R.styleable.View_translationX: |
| 3209 | tx = a.getDimensionPixelOffset(attr, 0); |
| 3210 | transformSet = true; |
| 3211 | break; |
| 3212 | case com.android.internal.R.styleable.View_translationY: |
| 3213 | ty = a.getDimensionPixelOffset(attr, 0); |
| 3214 | transformSet = true; |
| 3215 | break; |
| 3216 | case com.android.internal.R.styleable.View_rotation: |
| 3217 | rotation = a.getFloat(attr, 0); |
| 3218 | transformSet = true; |
| 3219 | break; |
| 3220 | case com.android.internal.R.styleable.View_rotationX: |
| 3221 | rotationX = a.getFloat(attr, 0); |
| 3222 | transformSet = true; |
| 3223 | break; |
| 3224 | case com.android.internal.R.styleable.View_rotationY: |
| 3225 | rotationY = a.getFloat(attr, 0); |
| 3226 | transformSet = true; |
| 3227 | break; |
| 3228 | case com.android.internal.R.styleable.View_scaleX: |
| 3229 | sx = a.getFloat(attr, 1f); |
| 3230 | transformSet = true; |
| 3231 | break; |
| 3232 | case com.android.internal.R.styleable.View_scaleY: |
| 3233 | sy = a.getFloat(attr, 1f); |
| 3234 | transformSet = true; |
| 3235 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | case com.android.internal.R.styleable.View_id: |
| 3237 | mID = a.getResourceId(attr, NO_ID); |
| 3238 | break; |
| 3239 | case com.android.internal.R.styleable.View_tag: |
| 3240 | mTag = a.getText(attr); |
| 3241 | break; |
| 3242 | case com.android.internal.R.styleable.View_fitsSystemWindows: |
| 3243 | if (a.getBoolean(attr, false)) { |
| 3244 | viewFlagValues |= FITS_SYSTEM_WINDOWS; |
| 3245 | viewFlagMasks |= FITS_SYSTEM_WINDOWS; |
| 3246 | } |
| 3247 | break; |
| 3248 | case com.android.internal.R.styleable.View_focusable: |
| 3249 | if (a.getBoolean(attr, false)) { |
| 3250 | viewFlagValues |= FOCUSABLE; |
| 3251 | viewFlagMasks |= FOCUSABLE_MASK; |
| 3252 | } |
| 3253 | break; |
| 3254 | case com.android.internal.R.styleable.View_focusableInTouchMode: |
| 3255 | if (a.getBoolean(attr, false)) { |
| 3256 | viewFlagValues |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE; |
| 3257 | viewFlagMasks |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE_MASK; |
| 3258 | } |
| 3259 | break; |
| 3260 | case com.android.internal.R.styleable.View_clickable: |
| 3261 | if (a.getBoolean(attr, false)) { |
| 3262 | viewFlagValues |= CLICKABLE; |
| 3263 | viewFlagMasks |= CLICKABLE; |
| 3264 | } |
| 3265 | break; |
| 3266 | case com.android.internal.R.styleable.View_longClickable: |
| 3267 | if (a.getBoolean(attr, false)) { |
| 3268 | viewFlagValues |= LONG_CLICKABLE; |
| 3269 | viewFlagMasks |= LONG_CLICKABLE; |
| 3270 | } |
| 3271 | break; |
| 3272 | case com.android.internal.R.styleable.View_saveEnabled: |
| 3273 | if (!a.getBoolean(attr, true)) { |
| 3274 | viewFlagValues |= SAVE_DISABLED; |
| 3275 | viewFlagMasks |= SAVE_DISABLED_MASK; |
| 3276 | } |
| 3277 | break; |
| 3278 | case com.android.internal.R.styleable.View_duplicateParentState: |
| 3279 | if (a.getBoolean(attr, false)) { |
| 3280 | viewFlagValues |= DUPLICATE_PARENT_STATE; |
| 3281 | viewFlagMasks |= DUPLICATE_PARENT_STATE; |
| 3282 | } |
| 3283 | break; |
| 3284 | case com.android.internal.R.styleable.View_visibility: |
| 3285 | final int visibility = a.getInt(attr, 0); |
| 3286 | if (visibility != 0) { |
| 3287 | viewFlagValues |= VISIBILITY_FLAGS[visibility]; |
| 3288 | viewFlagMasks |= VISIBILITY_MASK; |
| 3289 | } |
| 3290 | break; |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 3291 | case com.android.internal.R.styleable.View_layoutDirection: |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3292 | // Clear any layout direction flags (included resolved bits) already set |
| 3293 | mPrivateFlags2 &= ~(LAYOUT_DIRECTION_MASK | LAYOUT_DIRECTION_RESOLVED_MASK); |
| 3294 | // 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] | 3295 | final int layoutDirection = a.getInt(attr, -1); |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3296 | final int value = (layoutDirection != -1) ? |
| 3297 | LAYOUT_DIRECTION_FLAGS[layoutDirection] : LAYOUT_DIRECTION_DEFAULT; |
| 3298 | mPrivateFlags2 |= (value << LAYOUT_DIRECTION_MASK_SHIFT); |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 3299 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3300 | case com.android.internal.R.styleable.View_drawingCacheQuality: |
| 3301 | final int cacheQuality = a.getInt(attr, 0); |
| 3302 | if (cacheQuality != 0) { |
| 3303 | viewFlagValues |= DRAWING_CACHE_QUALITY_FLAGS[cacheQuality]; |
| 3304 | viewFlagMasks |= DRAWING_CACHE_QUALITY_MASK; |
| 3305 | } |
| 3306 | break; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3307 | case com.android.internal.R.styleable.View_contentDescription: |
| 3308 | mContentDescription = a.getString(attr); |
| 3309 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3310 | case com.android.internal.R.styleable.View_soundEffectsEnabled: |
| 3311 | if (!a.getBoolean(attr, true)) { |
| 3312 | viewFlagValues &= ~SOUND_EFFECTS_ENABLED; |
| 3313 | viewFlagMasks |= SOUND_EFFECTS_ENABLED; |
| 3314 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 3315 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3316 | case com.android.internal.R.styleable.View_hapticFeedbackEnabled: |
| 3317 | if (!a.getBoolean(attr, true)) { |
| 3318 | viewFlagValues &= ~HAPTIC_FEEDBACK_ENABLED; |
| 3319 | viewFlagMasks |= HAPTIC_FEEDBACK_ENABLED; |
| 3320 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 3321 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3322 | case R.styleable.View_scrollbars: |
| 3323 | final int scrollbars = a.getInt(attr, SCROLLBARS_NONE); |
| 3324 | if (scrollbars != SCROLLBARS_NONE) { |
| 3325 | viewFlagValues |= scrollbars; |
| 3326 | viewFlagMasks |= SCROLLBARS_MASK; |
| 3327 | initializeScrollbars(a); |
| 3328 | } |
| 3329 | break; |
Romain Guy | 2a9fa89 | 2011-09-28 16:50:02 -0700 | [diff] [blame] | 3330 | //noinspection deprecation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3331 | case R.styleable.View_fadingEdge: |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 3332 | if (context.getApplicationInfo().targetSdkVersion >= ICE_CREAM_SANDWICH) { |
| 3333 | // Ignore the attribute starting with ICS |
| 3334 | break; |
| 3335 | } |
| 3336 | // With builds < ICS, fall through and apply fading edges |
| 3337 | case R.styleable.View_requiresFadingEdge: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3338 | final int fadingEdge = a.getInt(attr, FADING_EDGE_NONE); |
| 3339 | if (fadingEdge != FADING_EDGE_NONE) { |
| 3340 | viewFlagValues |= fadingEdge; |
| 3341 | viewFlagMasks |= FADING_EDGE_MASK; |
| 3342 | initializeFadingEdge(a); |
| 3343 | } |
| 3344 | break; |
| 3345 | case R.styleable.View_scrollbarStyle: |
| 3346 | scrollbarStyle = a.getInt(attr, SCROLLBARS_INSIDE_OVERLAY); |
| 3347 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3348 | viewFlagValues |= scrollbarStyle & SCROLLBARS_STYLE_MASK; |
| 3349 | viewFlagMasks |= SCROLLBARS_STYLE_MASK; |
| 3350 | } |
| 3351 | break; |
| 3352 | case R.styleable.View_isScrollContainer: |
| 3353 | setScrollContainer = true; |
| 3354 | if (a.getBoolean(attr, false)) { |
| 3355 | setScrollContainer(true); |
| 3356 | } |
| 3357 | break; |
| 3358 | case com.android.internal.R.styleable.View_keepScreenOn: |
| 3359 | if (a.getBoolean(attr, false)) { |
| 3360 | viewFlagValues |= KEEP_SCREEN_ON; |
| 3361 | viewFlagMasks |= KEEP_SCREEN_ON; |
| 3362 | } |
| 3363 | break; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 3364 | case R.styleable.View_filterTouchesWhenObscured: |
| 3365 | if (a.getBoolean(attr, false)) { |
| 3366 | viewFlagValues |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3367 | viewFlagMasks |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3368 | } |
| 3369 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3370 | case R.styleable.View_nextFocusLeft: |
| 3371 | mNextFocusLeftId = a.getResourceId(attr, View.NO_ID); |
| 3372 | break; |
| 3373 | case R.styleable.View_nextFocusRight: |
| 3374 | mNextFocusRightId = a.getResourceId(attr, View.NO_ID); |
| 3375 | break; |
| 3376 | case R.styleable.View_nextFocusUp: |
| 3377 | mNextFocusUpId = a.getResourceId(attr, View.NO_ID); |
| 3378 | break; |
| 3379 | case R.styleable.View_nextFocusDown: |
| 3380 | mNextFocusDownId = a.getResourceId(attr, View.NO_ID); |
| 3381 | break; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 3382 | case R.styleable.View_nextFocusForward: |
| 3383 | mNextFocusForwardId = a.getResourceId(attr, View.NO_ID); |
| 3384 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3385 | case R.styleable.View_minWidth: |
| 3386 | mMinWidth = a.getDimensionPixelSize(attr, 0); |
| 3387 | break; |
| 3388 | case R.styleable.View_minHeight: |
| 3389 | mMinHeight = a.getDimensionPixelSize(attr, 0); |
| 3390 | break; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3391 | case R.styleable.View_onClick: |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3392 | if (context.isRestricted()) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3393 | throw new IllegalStateException("The android:onClick attribute cannot " |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3394 | + "be used within a restricted context"); |
| 3395 | } |
| 3396 | |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3397 | final String handlerName = a.getString(attr); |
| 3398 | if (handlerName != null) { |
| 3399 | setOnClickListener(new OnClickListener() { |
| 3400 | private Method mHandler; |
| 3401 | |
| 3402 | public void onClick(View v) { |
| 3403 | if (mHandler == null) { |
| 3404 | try { |
| 3405 | mHandler = getContext().getClass().getMethod(handlerName, |
| 3406 | View.class); |
| 3407 | } catch (NoSuchMethodException e) { |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3408 | int id = getId(); |
| 3409 | String idText = id == NO_ID ? "" : " with id '" |
| 3410 | + getContext().getResources().getResourceEntryName( |
| 3411 | id) + "'"; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3412 | throw new IllegalStateException("Could not find a method " + |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3413 | handlerName + "(View) in the activity " |
| 3414 | + getContext().getClass() + " for onClick handler" |
| 3415 | + " on view " + View.this.getClass() + idText, e); |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3416 | } |
| 3417 | } |
| 3418 | |
| 3419 | try { |
| 3420 | mHandler.invoke(getContext(), View.this); |
| 3421 | } catch (IllegalAccessException e) { |
| 3422 | throw new IllegalStateException("Could not execute non " |
| 3423 | + "public method of the activity", e); |
| 3424 | } catch (InvocationTargetException e) { |
| 3425 | throw new IllegalStateException("Could not execute " |
| 3426 | + "method of the activity", e); |
| 3427 | } |
| 3428 | } |
| 3429 | }); |
| 3430 | } |
| 3431 | break; |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3432 | case R.styleable.View_overScrollMode: |
| 3433 | overScrollMode = a.getInt(attr, OVER_SCROLL_IF_CONTENT_SCROLLS); |
| 3434 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3435 | case R.styleable.View_verticalScrollbarPosition: |
| 3436 | mVerticalScrollbarPosition = a.getInt(attr, SCROLLBAR_POSITION_DEFAULT); |
| 3437 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3438 | case R.styleable.View_layerType: |
| 3439 | setLayerType(a.getInt(attr, LAYER_TYPE_NONE), null); |
| 3440 | break; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3441 | case R.styleable.View_textDirection: |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3442 | // Clear any text direction flag already set |
| 3443 | mPrivateFlags2 &= ~TEXT_DIRECTION_MASK; |
| 3444 | // Set the text direction flags depending on the value of the attribute |
| 3445 | final int textDirection = a.getInt(attr, -1); |
| 3446 | if (textDirection != -1) { |
| 3447 | mPrivateFlags2 |= TEXT_DIRECTION_FLAGS[textDirection]; |
| 3448 | } |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3449 | break; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3450 | case R.styleable.View_textAlignment: |
| 3451 | // Clear any text alignment flag already set |
| 3452 | mPrivateFlags2 &= ~TEXT_ALIGNMENT_MASK; |
| 3453 | // Set the text alignment flag depending on the value of the attribute |
| 3454 | final int textAlignment = a.getInt(attr, TEXT_ALIGNMENT_DEFAULT); |
| 3455 | mPrivateFlags2 |= TEXT_ALIGNMENT_FLAGS[textAlignment]; |
| 3456 | break; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3457 | case R.styleable.View_importantForAccessibility: |
| 3458 | setImportantForAccessibility(a.getInt(attr, |
| 3459 | IMPORTANT_FOR_ACCESSIBILITY_DEFAULT)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3460 | } |
| 3461 | } |
| 3462 | |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 3463 | a.recycle(); |
| 3464 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3465 | setOverScrollMode(overScrollMode); |
| 3466 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3467 | if (background != null) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 3468 | setBackground(background); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3469 | } |
| 3470 | |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 3471 | // Cache user padding as we cannot fully resolve padding here (we dont have yet the resolved |
| 3472 | // layout direction). Those cached values will be used later during padding resolution. |
| 3473 | mUserPaddingStart = startPadding; |
| 3474 | mUserPaddingEnd = endPadding; |
| 3475 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 3476 | updateUserPaddingRelative(); |
| 3477 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3478 | if (padding >= 0) { |
| 3479 | leftPadding = padding; |
| 3480 | topPadding = padding; |
| 3481 | rightPadding = padding; |
| 3482 | bottomPadding = padding; |
| 3483 | } |
| 3484 | |
| 3485 | // If the user specified the padding (either with android:padding or |
| 3486 | // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise |
| 3487 | // use the default padding or the padding from the background drawable |
| 3488 | // (stored at this point in mPadding*) |
| 3489 | setPadding(leftPadding >= 0 ? leftPadding : mPaddingLeft, |
| 3490 | topPadding >= 0 ? topPadding : mPaddingTop, |
| 3491 | rightPadding >= 0 ? rightPadding : mPaddingRight, |
| 3492 | bottomPadding >= 0 ? bottomPadding : mPaddingBottom); |
| 3493 | |
| 3494 | if (viewFlagMasks != 0) { |
| 3495 | setFlags(viewFlagValues, viewFlagMasks); |
| 3496 | } |
| 3497 | |
| 3498 | // Needs to be called after mViewFlags is set |
| 3499 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3500 | recomputePadding(); |
| 3501 | } |
| 3502 | |
| 3503 | if (x != 0 || y != 0) { |
| 3504 | scrollTo(x, y); |
| 3505 | } |
| 3506 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3507 | if (transformSet) { |
| 3508 | setTranslationX(tx); |
| 3509 | setTranslationY(ty); |
| 3510 | setRotation(rotation); |
| 3511 | setRotationX(rotationX); |
| 3512 | setRotationY(rotationY); |
| 3513 | setScaleX(sx); |
| 3514 | setScaleY(sy); |
| 3515 | } |
| 3516 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3517 | if (!setScrollContainer && (viewFlagValues&SCROLLBARS_VERTICAL) != 0) { |
| 3518 | setScrollContainer(true); |
| 3519 | } |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 3520 | |
| 3521 | computeOpaqueFlags(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3522 | } |
| 3523 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 3524 | private void updateUserPaddingRelative() { |
| 3525 | mUserPaddingRelative = (mUserPaddingStart >= 0 || mUserPaddingEnd >= 0); |
| 3526 | } |
| 3527 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3528 | /** |
| 3529 | * Non-public constructor for use in testing |
| 3530 | */ |
| 3531 | View() { |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 3532 | mResources = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3533 | } |
| 3534 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3535 | /** |
| 3536 | * <p> |
| 3537 | * Initializes the fading edges from a given set of styled attributes. This |
| 3538 | * method should be called by subclasses that need fading edges and when an |
| 3539 | * instance of these subclasses is created programmatically rather than |
| 3540 | * being inflated from XML. This method is automatically called when the XML |
| 3541 | * is inflated. |
| 3542 | * </p> |
| 3543 | * |
| 3544 | * @param a the styled attributes set to initialize the fading edges from |
| 3545 | */ |
| 3546 | protected void initializeFadingEdge(TypedArray a) { |
| 3547 | initScrollCache(); |
| 3548 | |
| 3549 | mScrollCache.fadingEdgeLength = a.getDimensionPixelSize( |
| 3550 | R.styleable.View_fadingEdgeLength, |
| 3551 | ViewConfiguration.get(mContext).getScaledFadingEdgeLength()); |
| 3552 | } |
| 3553 | |
| 3554 | /** |
| 3555 | * Returns the size of the vertical faded edges used to indicate that more |
| 3556 | * content in this view is visible. |
| 3557 | * |
| 3558 | * @return The size in pixels of the vertical faded edge or 0 if vertical |
| 3559 | * faded edges are not enabled for this view. |
| 3560 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3561 | */ |
| 3562 | public int getVerticalFadingEdgeLength() { |
| 3563 | if (isVerticalFadingEdgeEnabled()) { |
| 3564 | ScrollabilityCache cache = mScrollCache; |
| 3565 | if (cache != null) { |
| 3566 | return cache.fadingEdgeLength; |
| 3567 | } |
| 3568 | } |
| 3569 | return 0; |
| 3570 | } |
| 3571 | |
| 3572 | /** |
| 3573 | * Set the size of the faded edge used to indicate that more content in this |
| 3574 | * 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] | 3575 | * {@link #setVerticalFadingEdgeEnabled(boolean)} or |
| 3576 | * {@link #setHorizontalFadingEdgeEnabled(boolean)} to enable the fading edge |
| 3577 | * for the vertical or horizontal fading edges. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3578 | * |
| 3579 | * @param length The size in pixels of the faded edge used to indicate that more |
| 3580 | * content in this view is visible. |
| 3581 | */ |
| 3582 | public void setFadingEdgeLength(int length) { |
| 3583 | initScrollCache(); |
| 3584 | mScrollCache.fadingEdgeLength = length; |
| 3585 | } |
| 3586 | |
| 3587 | /** |
| 3588 | * Returns the size of the horizontal faded edges used to indicate that more |
| 3589 | * content in this view is visible. |
| 3590 | * |
| 3591 | * @return The size in pixels of the horizontal faded edge or 0 if horizontal |
| 3592 | * faded edges are not enabled for this view. |
| 3593 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3594 | */ |
| 3595 | public int getHorizontalFadingEdgeLength() { |
| 3596 | if (isHorizontalFadingEdgeEnabled()) { |
| 3597 | ScrollabilityCache cache = mScrollCache; |
| 3598 | if (cache != null) { |
| 3599 | return cache.fadingEdgeLength; |
| 3600 | } |
| 3601 | } |
| 3602 | return 0; |
| 3603 | } |
| 3604 | |
| 3605 | /** |
| 3606 | * Returns the width of the vertical scrollbar. |
| 3607 | * |
| 3608 | * @return The width in pixels of the vertical scrollbar or 0 if there |
| 3609 | * is no vertical scrollbar. |
| 3610 | */ |
| 3611 | public int getVerticalScrollbarWidth() { |
| 3612 | ScrollabilityCache cache = mScrollCache; |
| 3613 | if (cache != null) { |
| 3614 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3615 | if (scrollBar != null) { |
| 3616 | int size = scrollBar.getSize(true); |
| 3617 | if (size <= 0) { |
| 3618 | size = cache.scrollBarSize; |
| 3619 | } |
| 3620 | return size; |
| 3621 | } |
| 3622 | return 0; |
| 3623 | } |
| 3624 | return 0; |
| 3625 | } |
| 3626 | |
| 3627 | /** |
| 3628 | * Returns the height of the horizontal scrollbar. |
| 3629 | * |
| 3630 | * @return The height in pixels of the horizontal scrollbar or 0 if |
| 3631 | * there is no horizontal scrollbar. |
| 3632 | */ |
| 3633 | protected int getHorizontalScrollbarHeight() { |
| 3634 | ScrollabilityCache cache = mScrollCache; |
| 3635 | if (cache != null) { |
| 3636 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3637 | if (scrollBar != null) { |
| 3638 | int size = scrollBar.getSize(false); |
| 3639 | if (size <= 0) { |
| 3640 | size = cache.scrollBarSize; |
| 3641 | } |
| 3642 | return size; |
| 3643 | } |
| 3644 | return 0; |
| 3645 | } |
| 3646 | return 0; |
| 3647 | } |
| 3648 | |
| 3649 | /** |
| 3650 | * <p> |
| 3651 | * Initializes the scrollbars from a given set of styled attributes. This |
| 3652 | * method should be called by subclasses that need scrollbars and when an |
| 3653 | * instance of these subclasses is created programmatically rather than |
| 3654 | * being inflated from XML. This method is automatically called when the XML |
| 3655 | * is inflated. |
| 3656 | * </p> |
| 3657 | * |
| 3658 | * @param a the styled attributes set to initialize the scrollbars from |
| 3659 | */ |
| 3660 | protected void initializeScrollbars(TypedArray a) { |
| 3661 | initScrollCache(); |
| 3662 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3663 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3664 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3665 | if (scrollabilityCache.scrollBar == null) { |
| 3666 | scrollabilityCache.scrollBar = new ScrollBarDrawable(); |
| 3667 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3668 | |
Romain Guy | 8bda248 | 2010-03-02 11:42:11 -0800 | [diff] [blame] | 3669 | 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] | 3670 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3671 | if (!fadeScrollbars) { |
| 3672 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 3673 | } |
| 3674 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3675 | |
| 3676 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3677 | scrollabilityCache.scrollBarFadeDuration = a.getInt( |
| 3678 | R.styleable.View_scrollbarFadeDuration, ViewConfiguration |
| 3679 | .getScrollBarFadeDuration()); |
| 3680 | scrollabilityCache.scrollBarDefaultDelayBeforeFade = a.getInt( |
| 3681 | R.styleable.View_scrollbarDefaultDelayBeforeFade, |
| 3682 | ViewConfiguration.getScrollDefaultDelay()); |
| 3683 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3684 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3685 | scrollabilityCache.scrollBarSize = a.getDimensionPixelSize( |
| 3686 | com.android.internal.R.styleable.View_scrollbarSize, |
| 3687 | ViewConfiguration.get(mContext).getScaledScrollBarSize()); |
| 3688 | |
| 3689 | Drawable track = a.getDrawable(R.styleable.View_scrollbarTrackHorizontal); |
| 3690 | scrollabilityCache.scrollBar.setHorizontalTrackDrawable(track); |
| 3691 | |
| 3692 | Drawable thumb = a.getDrawable(R.styleable.View_scrollbarThumbHorizontal); |
| 3693 | if (thumb != null) { |
| 3694 | scrollabilityCache.scrollBar.setHorizontalThumbDrawable(thumb); |
| 3695 | } |
| 3696 | |
| 3697 | boolean alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawHorizontalTrack, |
| 3698 | false); |
| 3699 | if (alwaysDraw) { |
| 3700 | scrollabilityCache.scrollBar.setAlwaysDrawHorizontalTrack(true); |
| 3701 | } |
| 3702 | |
| 3703 | track = a.getDrawable(R.styleable.View_scrollbarTrackVertical); |
| 3704 | scrollabilityCache.scrollBar.setVerticalTrackDrawable(track); |
| 3705 | |
| 3706 | thumb = a.getDrawable(R.styleable.View_scrollbarThumbVertical); |
| 3707 | if (thumb != null) { |
| 3708 | scrollabilityCache.scrollBar.setVerticalThumbDrawable(thumb); |
| 3709 | } |
| 3710 | |
| 3711 | alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawVerticalTrack, |
| 3712 | false); |
| 3713 | if (alwaysDraw) { |
| 3714 | scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true); |
| 3715 | } |
| 3716 | |
| 3717 | // Re-apply user/background padding so that scrollbar(s) get added |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3718 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | /** |
| 3722 | * <p> |
| 3723 | * Initalizes the scrollability cache if necessary. |
| 3724 | * </p> |
| 3725 | */ |
| 3726 | private void initScrollCache() { |
| 3727 | if (mScrollCache == null) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3728 | mScrollCache = new ScrollabilityCache(ViewConfiguration.get(mContext), this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3729 | } |
| 3730 | } |
| 3731 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 3732 | private ScrollabilityCache getScrollCache() { |
| 3733 | initScrollCache(); |
| 3734 | return mScrollCache; |
| 3735 | } |
| 3736 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3737 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3738 | * Set the position of the vertical scroll bar. Should be one of |
| 3739 | * {@link #SCROLLBAR_POSITION_DEFAULT}, {@link #SCROLLBAR_POSITION_LEFT} or |
| 3740 | * {@link #SCROLLBAR_POSITION_RIGHT}. |
| 3741 | * |
| 3742 | * @param position Where the vertical scroll bar should be positioned. |
| 3743 | */ |
| 3744 | public void setVerticalScrollbarPosition(int position) { |
| 3745 | if (mVerticalScrollbarPosition != position) { |
| 3746 | mVerticalScrollbarPosition = position; |
| 3747 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3748 | resolvePadding(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3749 | } |
| 3750 | } |
| 3751 | |
| 3752 | /** |
| 3753 | * @return The position where the vertical scroll bar will show, if applicable. |
| 3754 | * @see #setVerticalScrollbarPosition(int) |
| 3755 | */ |
| 3756 | public int getVerticalScrollbarPosition() { |
| 3757 | return mVerticalScrollbarPosition; |
| 3758 | } |
| 3759 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3760 | ListenerInfo getListenerInfo() { |
| 3761 | if (mListenerInfo != null) { |
| 3762 | return mListenerInfo; |
| 3763 | } |
| 3764 | mListenerInfo = new ListenerInfo(); |
| 3765 | return mListenerInfo; |
| 3766 | } |
| 3767 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3768 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3769 | * Register a callback to be invoked when focus of this view changed. |
| 3770 | * |
| 3771 | * @param l The callback that will run. |
| 3772 | */ |
| 3773 | public void setOnFocusChangeListener(OnFocusChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3774 | getListenerInfo().mOnFocusChangeListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3775 | } |
| 3776 | |
| 3777 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3778 | * Add a listener that will be called when the bounds of the view change due to |
| 3779 | * layout processing. |
| 3780 | * |
| 3781 | * @param listener The listener that will be called when layout bounds change. |
| 3782 | */ |
| 3783 | public void addOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3784 | ListenerInfo li = getListenerInfo(); |
| 3785 | if (li.mOnLayoutChangeListeners == null) { |
| 3786 | li.mOnLayoutChangeListeners = new ArrayList<OnLayoutChangeListener>(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3787 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3788 | if (!li.mOnLayoutChangeListeners.contains(listener)) { |
| 3789 | li.mOnLayoutChangeListeners.add(listener); |
Chet Haase | 1a76dcd | 2011-10-06 11:16:40 -0700 | [diff] [blame] | 3790 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3791 | } |
| 3792 | |
| 3793 | /** |
| 3794 | * Remove a listener for layout changes. |
| 3795 | * |
| 3796 | * @param listener The listener for layout bounds change. |
| 3797 | */ |
| 3798 | public void removeOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3799 | ListenerInfo li = mListenerInfo; |
| 3800 | if (li == null || li.mOnLayoutChangeListeners == null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3801 | return; |
| 3802 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3803 | li.mOnLayoutChangeListeners.remove(listener); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3804 | } |
| 3805 | |
| 3806 | /** |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3807 | * Add a listener for attach state changes. |
| 3808 | * |
| 3809 | * This listener will be called whenever this view is attached or detached |
| 3810 | * from a window. Remove the listener using |
| 3811 | * {@link #removeOnAttachStateChangeListener(OnAttachStateChangeListener)}. |
| 3812 | * |
| 3813 | * @param listener Listener to attach |
| 3814 | * @see #removeOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 3815 | */ |
| 3816 | public void addOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3817 | ListenerInfo li = getListenerInfo(); |
| 3818 | if (li.mOnAttachStateChangeListeners == null) { |
| 3819 | li.mOnAttachStateChangeListeners |
| 3820 | = new CopyOnWriteArrayList<OnAttachStateChangeListener>(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3821 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3822 | li.mOnAttachStateChangeListeners.add(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3823 | } |
| 3824 | |
| 3825 | /** |
| 3826 | * Remove a listener for attach state changes. The listener will receive no further |
| 3827 | * notification of window attach/detach events. |
| 3828 | * |
| 3829 | * @param listener Listener to remove |
| 3830 | * @see #addOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 3831 | */ |
| 3832 | public void removeOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3833 | ListenerInfo li = mListenerInfo; |
| 3834 | if (li == null || li.mOnAttachStateChangeListeners == null) { |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3835 | return; |
| 3836 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3837 | li.mOnAttachStateChangeListeners.remove(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3838 | } |
| 3839 | |
| 3840 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3841 | * Returns the focus-change callback registered for this view. |
| 3842 | * |
| 3843 | * @return The callback, or null if one is not registered. |
| 3844 | */ |
| 3845 | public OnFocusChangeListener getOnFocusChangeListener() { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3846 | ListenerInfo li = mListenerInfo; |
| 3847 | return li != null ? li.mOnFocusChangeListener : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3848 | } |
| 3849 | |
| 3850 | /** |
| 3851 | * Register a callback to be invoked when this view is clicked. If this view is not |
| 3852 | * clickable, it becomes clickable. |
| 3853 | * |
| 3854 | * @param l The callback that will run |
| 3855 | * |
| 3856 | * @see #setClickable(boolean) |
| 3857 | */ |
| 3858 | public void setOnClickListener(OnClickListener l) { |
| 3859 | if (!isClickable()) { |
| 3860 | setClickable(true); |
| 3861 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3862 | getListenerInfo().mOnClickListener = l; |
| 3863 | } |
| 3864 | |
| 3865 | /** |
| 3866 | * Return whether this view has an attached OnClickListener. Returns |
| 3867 | * true if there is a listener, false if there is none. |
| 3868 | */ |
| 3869 | public boolean hasOnClickListeners() { |
| 3870 | ListenerInfo li = mListenerInfo; |
| 3871 | return (li != null && li.mOnClickListener != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | /** |
| 3875 | * Register a callback to be invoked when this view is clicked and held. If this view is not |
| 3876 | * long clickable, it becomes long clickable. |
| 3877 | * |
| 3878 | * @param l The callback that will run |
| 3879 | * |
| 3880 | * @see #setLongClickable(boolean) |
| 3881 | */ |
| 3882 | public void setOnLongClickListener(OnLongClickListener l) { |
| 3883 | if (!isLongClickable()) { |
| 3884 | setLongClickable(true); |
| 3885 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3886 | getListenerInfo().mOnLongClickListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3887 | } |
| 3888 | |
| 3889 | /** |
| 3890 | * Register a callback to be invoked when the context menu for this view is |
| 3891 | * being built. If this view is not long clickable, it becomes long clickable. |
| 3892 | * |
| 3893 | * @param l The callback that will run |
| 3894 | * |
| 3895 | */ |
| 3896 | public void setOnCreateContextMenuListener(OnCreateContextMenuListener l) { |
| 3897 | if (!isLongClickable()) { |
| 3898 | setLongClickable(true); |
| 3899 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3900 | getListenerInfo().mOnCreateContextMenuListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3901 | } |
| 3902 | |
| 3903 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3904 | * Call this view's OnClickListener, if it is defined. Performs all normal |
| 3905 | * actions associated with clicking: reporting accessibility event, playing |
| 3906 | * a sound, etc. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3907 | * |
| 3908 | * @return True there was an assigned OnClickListener that was called, false |
| 3909 | * otherwise is returned. |
| 3910 | */ |
| 3911 | public boolean performClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3912 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); |
| 3913 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3914 | ListenerInfo li = mListenerInfo; |
| 3915 | if (li != null && li.mOnClickListener != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3916 | playSoundEffect(SoundEffectConstants.CLICK); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3917 | li.mOnClickListener.onClick(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3918 | return true; |
| 3919 | } |
| 3920 | |
| 3921 | return false; |
| 3922 | } |
| 3923 | |
| 3924 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3925 | * Directly call any attached OnClickListener. Unlike {@link #performClick()}, |
| 3926 | * this only calls the listener, and does not do any associated clicking |
| 3927 | * actions like reporting an accessibility event. |
| 3928 | * |
| 3929 | * @return True there was an assigned OnClickListener that was called, false |
| 3930 | * otherwise is returned. |
| 3931 | */ |
| 3932 | public boolean callOnClick() { |
| 3933 | ListenerInfo li = mListenerInfo; |
| 3934 | if (li != null && li.mOnClickListener != null) { |
| 3935 | li.mOnClickListener.onClick(this); |
| 3936 | return true; |
| 3937 | } |
| 3938 | return false; |
| 3939 | } |
| 3940 | |
| 3941 | /** |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 3942 | * Call this view's OnLongClickListener, if it is defined. Invokes the context menu if the |
| 3943 | * OnLongClickListener did not consume the event. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3944 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 3945 | * @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] | 3946 | */ |
| 3947 | public boolean performLongClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3948 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); |
| 3949 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3950 | boolean handled = false; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3951 | ListenerInfo li = mListenerInfo; |
| 3952 | if (li != null && li.mOnLongClickListener != null) { |
| 3953 | handled = li.mOnLongClickListener.onLongClick(View.this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3954 | } |
| 3955 | if (!handled) { |
| 3956 | handled = showContextMenu(); |
| 3957 | } |
| 3958 | if (handled) { |
| 3959 | performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); |
| 3960 | } |
| 3961 | return handled; |
| 3962 | } |
| 3963 | |
| 3964 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3965 | * Performs button-related actions during a touch down event. |
| 3966 | * |
| 3967 | * @param event The event. |
| 3968 | * @return True if the down was consumed. |
| 3969 | * |
| 3970 | * @hide |
| 3971 | */ |
| 3972 | protected boolean performButtonActionOnTouchDown(MotionEvent event) { |
| 3973 | if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) { |
| 3974 | if (showContextMenu(event.getX(), event.getY(), event.getMetaState())) { |
| 3975 | return true; |
| 3976 | } |
| 3977 | } |
| 3978 | return false; |
| 3979 | } |
| 3980 | |
| 3981 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3982 | * Bring up the context menu for this view. |
| 3983 | * |
| 3984 | * @return Whether a context menu was displayed. |
| 3985 | */ |
| 3986 | public boolean showContextMenu() { |
| 3987 | return getParent().showContextMenuForChild(this); |
| 3988 | } |
| 3989 | |
| 3990 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3991 | * Bring up the context menu for this view, referring to the item under the specified point. |
| 3992 | * |
| 3993 | * @param x The referenced x coordinate. |
| 3994 | * @param y The referenced y coordinate. |
| 3995 | * @param metaState The keyboard modifiers that were pressed. |
| 3996 | * @return Whether a context menu was displayed. |
| 3997 | * |
| 3998 | * @hide |
| 3999 | */ |
| 4000 | public boolean showContextMenu(float x, float y, int metaState) { |
| 4001 | return showContextMenu(); |
| 4002 | } |
| 4003 | |
| 4004 | /** |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 4005 | * Start an action mode. |
| 4006 | * |
| 4007 | * @param callback Callback that will control the lifecycle of the action mode |
| 4008 | * @return The new action mode if it is started, null otherwise |
| 4009 | * |
| 4010 | * @see ActionMode |
| 4011 | */ |
| 4012 | public ActionMode startActionMode(ActionMode.Callback callback) { |
John Reck | 5160e2a | 2012-02-22 09:35:12 -0800 | [diff] [blame] | 4013 | ViewParent parent = getParent(); |
| 4014 | if (parent == null) return null; |
| 4015 | return parent.startActionModeForChild(this, callback); |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 4016 | } |
| 4017 | |
| 4018 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4019 | * Register a callback to be invoked when a key is pressed in this view. |
| 4020 | * @param l the key listener to attach to this view |
| 4021 | */ |
| 4022 | public void setOnKeyListener(OnKeyListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4023 | getListenerInfo().mOnKeyListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4024 | } |
| 4025 | |
| 4026 | /** |
| 4027 | * Register a callback to be invoked when a touch event is sent to this view. |
| 4028 | * @param l the touch listener to attach to this view |
| 4029 | */ |
| 4030 | public void setOnTouchListener(OnTouchListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4031 | getListenerInfo().mOnTouchListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 4035 | * Register a callback to be invoked when a generic motion event is sent to this view. |
| 4036 | * @param l the generic motion listener to attach to this view |
| 4037 | */ |
| 4038 | public void setOnGenericMotionListener(OnGenericMotionListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4039 | getListenerInfo().mOnGenericMotionListener = l; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 4040 | } |
| 4041 | |
| 4042 | /** |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 4043 | * Register a callback to be invoked when a hover event is sent to this view. |
| 4044 | * @param l the hover listener to attach to this view |
| 4045 | */ |
| 4046 | public void setOnHoverListener(OnHoverListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4047 | getListenerInfo().mOnHoverListener = l; |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 4048 | } |
| 4049 | |
| 4050 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 4051 | * Register a drag event listener callback object for this View. The parameter is |
| 4052 | * an implementation of {@link android.view.View.OnDragListener}. To send a drag event to a |
| 4053 | * View, the system calls the |
| 4054 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent)} method. |
| 4055 | * @param l An implementation of {@link android.view.View.OnDragListener}. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 4056 | */ |
| 4057 | public void setOnDragListener(OnDragListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4058 | getListenerInfo().mOnDragListener = l; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 4062 | * Give this view focus. This will cause |
| 4063 | * {@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] | 4064 | * |
| 4065 | * Note: this does not check whether this {@link View} should get focus, it just |
| 4066 | * gives it focus no matter what. It should only be called internally by framework |
| 4067 | * code that knows what it is doing, namely {@link #requestFocus(int, Rect)}. |
| 4068 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 4069 | * @param direction values are {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN}, |
| 4070 | * {@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] | 4071 | * focus moved when requestFocus() is called. It may not always |
| 4072 | * apply, in which case use the default View.FOCUS_DOWN. |
| 4073 | * @param previouslyFocusedRect The rectangle of the view that had focus |
| 4074 | * prior in this View's coordinate system. |
| 4075 | */ |
| 4076 | void handleFocusGainInternal(int direction, Rect previouslyFocusedRect) { |
| 4077 | if (DBG) { |
| 4078 | System.out.println(this + " requestFocus()"); |
| 4079 | } |
| 4080 | |
| 4081 | if ((mPrivateFlags & FOCUSED) == 0) { |
| 4082 | mPrivateFlags |= FOCUSED; |
| 4083 | |
| 4084 | if (mParent != null) { |
| 4085 | mParent.requestChildFocus(this, this); |
| 4086 | } |
| 4087 | |
| 4088 | onFocusChanged(true, direction, previouslyFocusedRect); |
| 4089 | refreshDrawableState(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4090 | |
| 4091 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4092 | notifyAccessibilityStateChanged(); |
| 4093 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4094 | } |
| 4095 | } |
| 4096 | |
| 4097 | /** |
| 4098 | * Request that a rectangle of this view be visible on the screen, |
| 4099 | * scrolling if necessary just enough. |
| 4100 | * |
| 4101 | * <p>A View should call this if it maintains some notion of which part |
| 4102 | * of its content is interesting. For example, a text editing view |
| 4103 | * should call this when its cursor moves. |
| 4104 | * |
| 4105 | * @param rectangle The rectangle. |
| 4106 | * @return Whether any parent scrolled. |
| 4107 | */ |
| 4108 | public boolean requestRectangleOnScreen(Rect rectangle) { |
| 4109 | return requestRectangleOnScreen(rectangle, false); |
| 4110 | } |
| 4111 | |
| 4112 | /** |
| 4113 | * Request that a rectangle of this view be visible on the screen, |
| 4114 | * scrolling if necessary just enough. |
| 4115 | * |
| 4116 | * <p>A View should call this if it maintains some notion of which part |
| 4117 | * of its content is interesting. For example, a text editing view |
| 4118 | * should call this when its cursor moves. |
| 4119 | * |
| 4120 | * <p>When <code>immediate</code> is set to true, scrolling will not be |
| 4121 | * animated. |
| 4122 | * |
| 4123 | * @param rectangle The rectangle. |
| 4124 | * @param immediate True to forbid animated scrolling, false otherwise |
| 4125 | * @return Whether any parent scrolled. |
| 4126 | */ |
| 4127 | public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) { |
| 4128 | View child = this; |
| 4129 | ViewParent parent = mParent; |
| 4130 | boolean scrolled = false; |
| 4131 | while (parent != null) { |
| 4132 | scrolled |= parent.requestChildRectangleOnScreen(child, |
| 4133 | rectangle, immediate); |
| 4134 | |
| 4135 | // offset rect so next call has the rectangle in the |
| 4136 | // coordinate system of its direct child. |
| 4137 | rectangle.offset(child.getLeft(), child.getTop()); |
| 4138 | rectangle.offset(-child.getScrollX(), -child.getScrollY()); |
| 4139 | |
| 4140 | if (!(parent instanceof View)) { |
| 4141 | break; |
| 4142 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4144 | child = (View) parent; |
| 4145 | parent = child.getParent(); |
| 4146 | } |
| 4147 | return scrolled; |
| 4148 | } |
| 4149 | |
| 4150 | /** |
Svetoslav Ganov | 13fd561 | 2012-02-01 17:01:12 -0800 | [diff] [blame] | 4151 | * Called when this view wants to give up focus. If focus is cleared |
| 4152 | * {@link #onFocusChanged(boolean, int, android.graphics.Rect)} is called. |
| 4153 | * <p> |
| 4154 | * <strong>Note:</strong> When a View clears focus the framework is trying |
| 4155 | * 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] | 4156 | * View is the first from the top that can take focus, then all callbacks |
| 4157 | * related to clearing focus will be invoked after wich the framework will |
| 4158 | * give focus to this view. |
Svetoslav Ganov | 13fd561 | 2012-02-01 17:01:12 -0800 | [diff] [blame] | 4159 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4160 | */ |
| 4161 | public void clearFocus() { |
| 4162 | if (DBG) { |
| 4163 | System.out.println(this + " clearFocus()"); |
| 4164 | } |
| 4165 | |
| 4166 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 4167 | mPrivateFlags &= ~FOCUSED; |
| 4168 | |
| 4169 | if (mParent != null) { |
| 4170 | mParent.clearChildFocus(this); |
| 4171 | } |
| 4172 | |
| 4173 | onFocusChanged(false, 0, null); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4175 | refreshDrawableState(); |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame] | 4176 | |
| 4177 | ensureInputFocusOnFirstFocusable(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4178 | |
| 4179 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4180 | notifyAccessibilityStateChanged(); |
| 4181 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4182 | } |
| 4183 | } |
| 4184 | |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame] | 4185 | void ensureInputFocusOnFirstFocusable() { |
| 4186 | View root = getRootView(); |
| 4187 | if (root != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4188 | root.requestFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4189 | } |
| 4190 | } |
| 4191 | |
| 4192 | /** |
| 4193 | * Called internally by the view system when a new view is getting focus. |
| 4194 | * This is what clears the old focus. |
| 4195 | */ |
| 4196 | void unFocus() { |
| 4197 | if (DBG) { |
| 4198 | System.out.println(this + " unFocus()"); |
| 4199 | } |
| 4200 | |
| 4201 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 4202 | mPrivateFlags &= ~FOCUSED; |
| 4203 | |
| 4204 | onFocusChanged(false, 0, null); |
| 4205 | refreshDrawableState(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4206 | |
| 4207 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4208 | notifyAccessibilityStateChanged(); |
| 4209 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4210 | } |
| 4211 | } |
| 4212 | |
| 4213 | /** |
| 4214 | * Returns true if this view has focus iteself, or is the ancestor of the |
| 4215 | * view that has focus. |
| 4216 | * |
| 4217 | * @return True if this view has or contains focus, false otherwise. |
| 4218 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4219 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4220 | public boolean hasFocus() { |
| 4221 | return (mPrivateFlags & FOCUSED) != 0; |
| 4222 | } |
| 4223 | |
| 4224 | /** |
| 4225 | * Returns true if this view is focusable or if it contains a reachable View |
| 4226 | * for which {@link #hasFocusable()} returns true. A "reachable hasFocusable()" |
| 4227 | * is a View whose parents do not block descendants focus. |
| 4228 | * |
| 4229 | * Only {@link #VISIBLE} views are considered focusable. |
| 4230 | * |
| 4231 | * @return True if the view is focusable or if the view contains a focusable |
| 4232 | * View, false otherwise. |
| 4233 | * |
| 4234 | * @see ViewGroup#FOCUS_BLOCK_DESCENDANTS |
| 4235 | */ |
| 4236 | public boolean hasFocusable() { |
| 4237 | return (mViewFlags & VISIBILITY_MASK) == VISIBLE && isFocusable(); |
| 4238 | } |
| 4239 | |
| 4240 | /** |
| 4241 | * Called by the view system when the focus state of this view changes. |
| 4242 | * When the focus change event is caused by directional navigation, direction |
| 4243 | * and previouslyFocusedRect provide insight into where the focus is coming from. |
| 4244 | * When overriding, be sure to call up through to the super class so that |
| 4245 | * the standard focus handling will occur. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4246 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4247 | * @param gainFocus True if the View has focus; false otherwise. |
| 4248 | * @param direction The direction focus has moved when requestFocus() |
| 4249 | * is called to give this view focus. Values are |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4250 | * {@link #FOCUS_UP}, {@link #FOCUS_DOWN}, {@link #FOCUS_LEFT}, |
| 4251 | * {@link #FOCUS_RIGHT}, {@link #FOCUS_FORWARD}, or {@link #FOCUS_BACKWARD}. |
| 4252 | * 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] | 4253 | * @param previouslyFocusedRect The rectangle, in this view's coordinate |
| 4254 | * system, of the previously focused view. If applicable, this will be |
| 4255 | * passed in as finer grained information about where the focus is coming |
| 4256 | * from (in addition to direction). Will be <code>null</code> otherwise. |
| 4257 | */ |
| 4258 | protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4259 | if (gainFocus) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4260 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4261 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 4262 | requestAccessibilityFocus(); |
| 4263 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4264 | } |
| 4265 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4266 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 4267 | if (!gainFocus) { |
| 4268 | if (isPressed()) { |
| 4269 | setPressed(false); |
| 4270 | } |
| 4271 | if (imm != null && mAttachInfo != null |
| 4272 | && mAttachInfo.mHasWindowFocus) { |
| 4273 | imm.focusOut(this); |
| 4274 | } |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4275 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4276 | } else if (imm != null && mAttachInfo != null |
| 4277 | && mAttachInfo.mHasWindowFocus) { |
| 4278 | imm.focusIn(this); |
| 4279 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4280 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 4281 | invalidate(true); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4282 | ListenerInfo li = mListenerInfo; |
| 4283 | if (li != null && li.mOnFocusChangeListener != null) { |
| 4284 | li.mOnFocusChangeListener.onFocusChange(this, gainFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4285 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 4286 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 4287 | if (mAttachInfo != null) { |
| 4288 | mAttachInfo.mKeyDispatchState.reset(this); |
| 4289 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4290 | } |
| 4291 | |
| 4292 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4293 | * Sends an accessibility event of the given type. If accessiiblity is |
| 4294 | * not enabled this method has no effect. The default implementation calls |
| 4295 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)} first |
| 4296 | * to populate information about the event source (this View), then calls |
| 4297 | * {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} to |
| 4298 | * populate the text content of the event source including its descendants, |
| 4299 | * and last calls |
| 4300 | * {@link ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)} |
| 4301 | * on its parent to resuest sending of the event to interested parties. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4302 | * <p> |
| 4303 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4304 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4305 | * {@link AccessibilityDelegate#sendAccessibilityEvent(View, int)} is |
| 4306 | * responsible for handling this call. |
| 4307 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4308 | * |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4309 | * @param eventType The type of the event to send, as defined by several types from |
| 4310 | * {@link android.view.accessibility.AccessibilityEvent}, such as |
| 4311 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_CLICKED} or |
| 4312 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_ENTER}. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4313 | * |
| 4314 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4315 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4316 | * @see ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent) |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4317 | * @see AccessibilityDelegate |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4318 | */ |
| 4319 | public void sendAccessibilityEvent(int eventType) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4320 | if (mAccessibilityDelegate != null) { |
| 4321 | mAccessibilityDelegate.sendAccessibilityEvent(this, eventType); |
| 4322 | } else { |
| 4323 | sendAccessibilityEventInternal(eventType); |
| 4324 | } |
| 4325 | } |
| 4326 | |
| 4327 | /** |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4328 | * Convenience method for sending a {@link AccessibilityEvent#TYPE_ANNOUNCEMENT} |
| 4329 | * {@link AccessibilityEvent} to make an announcement which is related to some |
| 4330 | * sort of a context change for which none of the events representing UI transitions |
| 4331 | * is a good fit. For example, announcing a new page in a book. If accessibility |
| 4332 | * is not enabled this method does nothing. |
| 4333 | * |
| 4334 | * @param text The announcement text. |
| 4335 | */ |
| 4336 | public void announceForAccessibility(CharSequence text) { |
| 4337 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4338 | AccessibilityEvent event = AccessibilityEvent.obtain( |
| 4339 | AccessibilityEvent.TYPE_ANNOUNCEMENT); |
| 4340 | event.getText().add(text); |
| 4341 | sendAccessibilityEventUnchecked(event); |
| 4342 | } |
| 4343 | } |
| 4344 | |
| 4345 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4346 | * @see #sendAccessibilityEvent(int) |
| 4347 | * |
| 4348 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4349 | */ |
| 4350 | void sendAccessibilityEventInternal(int eventType) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4351 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4352 | sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType)); |
| 4353 | } |
| 4354 | } |
| 4355 | |
| 4356 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4357 | * This method behaves exactly as {@link #sendAccessibilityEvent(int)} but |
| 4358 | * takes as an argument an empty {@link AccessibilityEvent} and does not |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4359 | * perform a check whether accessibility is enabled. |
| 4360 | * <p> |
| 4361 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4362 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4363 | * {@link AccessibilityDelegate#sendAccessibilityEventUnchecked(View, AccessibilityEvent)} |
| 4364 | * is responsible for handling this call. |
| 4365 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4366 | * |
| 4367 | * @param event The event to send. |
| 4368 | * |
| 4369 | * @see #sendAccessibilityEvent(int) |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4370 | */ |
| 4371 | public void sendAccessibilityEventUnchecked(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4372 | if (mAccessibilityDelegate != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4373 | mAccessibilityDelegate.sendAccessibilityEventUnchecked(this, event); |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4374 | } else { |
| 4375 | sendAccessibilityEventUncheckedInternal(event); |
| 4376 | } |
| 4377 | } |
| 4378 | |
| 4379 | /** |
| 4380 | * @see #sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 4381 | * |
| 4382 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4383 | */ |
| 4384 | void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 9cd1eca | 2011-01-13 14:24:02 -0800 | [diff] [blame] | 4385 | if (!isShown()) { |
| 4386 | return; |
| 4387 | } |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4388 | onInitializeAccessibilityEvent(event); |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4389 | // Only a subset of accessibility events populates text content. |
| 4390 | if ((event.getEventType() & POPULATING_ACCESSIBILITY_EVENT_TYPES) != 0) { |
| 4391 | dispatchPopulateAccessibilityEvent(event); |
| 4392 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4393 | // Intercept accessibility focus events fired by virtual nodes to keep |
| 4394 | // track of accessibility focus position in such nodes. |
| 4395 | final int eventType = event.getEventType(); |
| 4396 | switch (eventType) { |
| 4397 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: { |
| 4398 | final long virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 4399 | event.getSourceNodeId()); |
| 4400 | if (virtualNodeId != AccessibilityNodeInfo.UNDEFINED) { |
| 4401 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 4402 | if (viewRootImpl != null) { |
| 4403 | viewRootImpl.setAccessibilityFocusedHost(this); |
| 4404 | } |
| 4405 | } |
| 4406 | } break; |
| 4407 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: { |
| 4408 | final long virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 4409 | event.getSourceNodeId()); |
| 4410 | if (virtualNodeId != AccessibilityNodeInfo.UNDEFINED) { |
| 4411 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 4412 | if (viewRootImpl != null) { |
| 4413 | viewRootImpl.setAccessibilityFocusedHost(null); |
| 4414 | } |
| 4415 | } |
| 4416 | } break; |
| 4417 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4418 | // In the beginning we called #isShown(), so we know that getParent() is not null. |
| 4419 | getParent().requestSendAccessibilityEvent(this, event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4420 | } |
| 4421 | |
| 4422 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4423 | * Dispatches an {@link AccessibilityEvent} to the {@link View} first and then |
| 4424 | * to its children for adding their text content to the event. Note that the |
| 4425 | * event text is populated in a separate dispatch path since we add to the |
| 4426 | * 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] | 4427 | * A typical implementation will call |
| 4428 | * {@link #onPopulateAccessibilityEvent(AccessibilityEvent)} on the this view |
| 4429 | * and then call the {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
| 4430 | * on each child. Override this method if custom population of the event text |
| 4431 | * content is required. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4432 | * <p> |
| 4433 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4434 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4435 | * {@link AccessibilityDelegate#dispatchPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4436 | * is responsible for handling this call. |
| 4437 | * </p> |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4438 | * <p> |
| 4439 | * <em>Note:</em> Accessibility events of certain types are not dispatched for |
| 4440 | * populating the event text via this method. For details refer to {@link AccessibilityEvent}. |
| 4441 | * </p> |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4442 | * |
| 4443 | * @param event The event. |
| 4444 | * |
| 4445 | * @return True if the event population was completed. |
| 4446 | */ |
| 4447 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4448 | if (mAccessibilityDelegate != null) { |
| 4449 | return mAccessibilityDelegate.dispatchPopulateAccessibilityEvent(this, event); |
| 4450 | } else { |
| 4451 | return dispatchPopulateAccessibilityEventInternal(event); |
| 4452 | } |
| 4453 | } |
| 4454 | |
| 4455 | /** |
| 4456 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4457 | * |
| 4458 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4459 | */ |
| 4460 | boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4461 | onPopulateAccessibilityEvent(event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4462 | return false; |
| 4463 | } |
| 4464 | |
| 4465 | /** |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4466 | * Called from {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4467 | * 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] | 4468 | * text content. While this method is free to modify event |
| 4469 | * attributes other than text content, doing so should normally be performed in |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4470 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)}. |
| 4471 | * <p> |
| 4472 | * Example: Adding formatted date string to an accessibility event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4473 | * to the text added by the super implementation: |
| 4474 | * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4475 | * super.onPopulateAccessibilityEvent(event); |
| 4476 | * final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; |
| 4477 | * String selectedDateUtterance = DateUtils.formatDateTime(mContext, |
| 4478 | * mCurrentDate.getTimeInMillis(), flags); |
| 4479 | * event.getText().add(selectedDateUtterance); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4480 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4481 | * <p> |
| 4482 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4483 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4484 | * {@link AccessibilityDelegate#onPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4485 | * is responsible for handling this call. |
| 4486 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4487 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4488 | * information to the event, in case the default implementation has basic information to add. |
| 4489 | * </p> |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4490 | * |
| 4491 | * @param event The accessibility event which to populate. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4492 | * |
| 4493 | * @see #sendAccessibilityEvent(int) |
| 4494 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4495 | */ |
| 4496 | public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4497 | if (mAccessibilityDelegate != null) { |
| 4498 | mAccessibilityDelegate.onPopulateAccessibilityEvent(this, event); |
| 4499 | } else { |
| 4500 | onPopulateAccessibilityEventInternal(event); |
| 4501 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4502 | } |
| 4503 | |
| 4504 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4505 | * @see #onPopulateAccessibilityEvent(AccessibilityEvent) |
| 4506 | * |
| 4507 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4508 | */ |
| 4509 | void onPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
| 4510 | |
| 4511 | } |
| 4512 | |
| 4513 | /** |
| 4514 | * Initializes an {@link AccessibilityEvent} with information about |
| 4515 | * this View which is the event source. In other words, the source of |
| 4516 | * an accessibility event is the view whose state change triggered firing |
| 4517 | * the event. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4518 | * <p> |
| 4519 | * Example: Setting the password property of an event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4520 | * to properties set by the super implementation: |
| 4521 | * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 4522 | * super.onInitializeAccessibilityEvent(event); |
| 4523 | * event.setPassword(true); |
| 4524 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4525 | * <p> |
| 4526 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4527 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4528 | * {@link AccessibilityDelegate#onInitializeAccessibilityEvent(View, AccessibilityEvent)} |
| 4529 | * is responsible for handling this call. |
| 4530 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4531 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4532 | * information to the event, in case the default implementation has basic information to add. |
| 4533 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4534 | * @param event The event to initialize. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4535 | * |
| 4536 | * @see #sendAccessibilityEvent(int) |
| 4537 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4538 | */ |
| 4539 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4540 | if (mAccessibilityDelegate != null) { |
| 4541 | mAccessibilityDelegate.onInitializeAccessibilityEvent(this, event); |
| 4542 | } else { |
| 4543 | onInitializeAccessibilityEventInternal(event); |
| 4544 | } |
| 4545 | } |
| 4546 | |
| 4547 | /** |
| 4548 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4549 | * |
| 4550 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4551 | */ |
| 4552 | void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4553 | event.setSource(this); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 4554 | event.setClassName(View.class.getName()); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4555 | event.setPackageName(getContext().getPackageName()); |
| 4556 | event.setEnabled(isEnabled()); |
| 4557 | event.setContentDescription(mContentDescription); |
| 4558 | |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 4559 | if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && mAttachInfo != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4560 | ArrayList<View> focusablesTempList = mAttachInfo.mTempArrayList; |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 4561 | getRootView().addFocusables(focusablesTempList, View.FOCUS_FORWARD, |
| 4562 | FOCUSABLES_ALL); |
| 4563 | event.setItemCount(focusablesTempList.size()); |
| 4564 | event.setCurrentItemIndex(focusablesTempList.indexOf(this)); |
| 4565 | focusablesTempList.clear(); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4566 | } |
| 4567 | } |
| 4568 | |
| 4569 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4570 | * Returns an {@link AccessibilityNodeInfo} representing this view from the |
| 4571 | * point of view of an {@link android.accessibilityservice.AccessibilityService}. |
| 4572 | * This method is responsible for obtaining an accessibility node info from a |
| 4573 | * pool of reusable instances and calling |
| 4574 | * {@link #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} on this view to |
| 4575 | * initialize the former. |
| 4576 | * <p> |
| 4577 | * Note: The client is responsible for recycling the obtained instance by calling |
| 4578 | * {@link AccessibilityNodeInfo#recycle()} to minimize object creation. |
| 4579 | * </p> |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4580 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4581 | * @return A populated {@link AccessibilityNodeInfo}. |
| 4582 | * |
| 4583 | * @see AccessibilityNodeInfo |
| 4584 | */ |
| 4585 | public AccessibilityNodeInfo createAccessibilityNodeInfo() { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4586 | AccessibilityNodeProvider provider = getAccessibilityNodeProvider(); |
| 4587 | if (provider != null) { |
| 4588 | return provider.createAccessibilityNodeInfo(View.NO_ID); |
| 4589 | } else { |
| 4590 | AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(this); |
| 4591 | onInitializeAccessibilityNodeInfo(info); |
| 4592 | return info; |
| 4593 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4594 | } |
| 4595 | |
| 4596 | /** |
| 4597 | * Initializes an {@link AccessibilityNodeInfo} with information about this view. |
| 4598 | * The base implementation sets: |
| 4599 | * <ul> |
| 4600 | * <li>{@link AccessibilityNodeInfo#setParent(View)},</li> |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4601 | * <li>{@link AccessibilityNodeInfo#setBoundsInParent(Rect)},</li> |
| 4602 | * <li>{@link AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li> |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4603 | * <li>{@link AccessibilityNodeInfo#setPackageName(CharSequence)},</li> |
| 4604 | * <li>{@link AccessibilityNodeInfo#setClassName(CharSequence)},</li> |
| 4605 | * <li>{@link AccessibilityNodeInfo#setContentDescription(CharSequence)},</li> |
| 4606 | * <li>{@link AccessibilityNodeInfo#setEnabled(boolean)},</li> |
| 4607 | * <li>{@link AccessibilityNodeInfo#setClickable(boolean)},</li> |
| 4608 | * <li>{@link AccessibilityNodeInfo#setFocusable(boolean)},</li> |
| 4609 | * <li>{@link AccessibilityNodeInfo#setFocused(boolean)},</li> |
| 4610 | * <li>{@link AccessibilityNodeInfo#setLongClickable(boolean)},</li> |
| 4611 | * <li>{@link AccessibilityNodeInfo#setSelected(boolean)},</li> |
| 4612 | * </ul> |
| 4613 | * <p> |
| 4614 | * Subclasses should override this method, call the super implementation, |
| 4615 | * and set additional attributes. |
| 4616 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4617 | * <p> |
| 4618 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4619 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4620 | * {@link AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)} |
| 4621 | * is responsible for handling this call. |
| 4622 | * </p> |
| 4623 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4624 | * @param info The instance to initialize. |
| 4625 | */ |
| 4626 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4627 | if (mAccessibilityDelegate != null) { |
| 4628 | mAccessibilityDelegate.onInitializeAccessibilityNodeInfo(this, info); |
| 4629 | } else { |
| 4630 | onInitializeAccessibilityNodeInfoInternal(info); |
| 4631 | } |
| 4632 | } |
| 4633 | |
| 4634 | /** |
| 4635 | * @see #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 4636 | * |
| 4637 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4638 | */ |
| 4639 | void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4640 | Rect bounds = mAttachInfo.mTmpInvalRect; |
| 4641 | getDrawingRect(bounds); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4642 | info.setBoundsInParent(bounds); |
| 4643 | |
Svetoslav Ganov | aa6f3de | 2012-04-09 17:39:00 -0700 | [diff] [blame] | 4644 | getGlobalVisibleRect(bounds); |
| 4645 | bounds.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4646 | info.setBoundsInScreen(bounds); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4647 | |
Svetoslav Ganov | 57f3b566db | 2011-10-31 17:59:14 -0700 | [diff] [blame] | 4648 | if ((mPrivateFlags & IS_ROOT_NAMESPACE) == 0) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4649 | ViewParent parent = getParentForAccessibility(); |
Svetoslav Ganov | 57f3b566db | 2011-10-31 17:59:14 -0700 | [diff] [blame] | 4650 | if (parent instanceof View) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4651 | info.setParent((View) parent); |
Svetoslav Ganov | 57f3b566db | 2011-10-31 17:59:14 -0700 | [diff] [blame] | 4652 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4653 | } |
| 4654 | |
| 4655 | info.setPackageName(mContext.getPackageName()); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 4656 | info.setClassName(View.class.getName()); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4657 | info.setContentDescription(getContentDescription()); |
| 4658 | |
| 4659 | info.setEnabled(isEnabled()); |
| 4660 | info.setClickable(isClickable()); |
| 4661 | info.setFocusable(isFocusable()); |
| 4662 | info.setFocused(isFocused()); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4663 | info.setAccessibilityFocused(isAccessibilityFocused()); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4664 | info.setSelected(isSelected()); |
| 4665 | info.setLongClickable(isLongClickable()); |
| 4666 | |
| 4667 | // TODO: These make sense only if we are in an AdapterView but all |
| 4668 | // views can be selected. Maybe from accessiiblity perspective |
| 4669 | // we should report as selectable view in an AdapterView. |
| 4670 | info.addAction(AccessibilityNodeInfo.ACTION_SELECT); |
| 4671 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_SELECTION); |
| 4672 | |
| 4673 | if (isFocusable()) { |
| 4674 | if (isFocused()) { |
| 4675 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS); |
| 4676 | } else { |
| 4677 | info.addAction(AccessibilityNodeInfo.ACTION_FOCUS); |
| 4678 | } |
| 4679 | } |
| 4680 | } |
| 4681 | |
| 4682 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4683 | * Sets a delegate for implementing accessibility support via compositon as |
| 4684 | * opposed to inheritance. The delegate's primary use is for implementing |
| 4685 | * backwards compatible widgets. For more details see {@link AccessibilityDelegate}. |
| 4686 | * |
| 4687 | * @param delegate The delegate instance. |
| 4688 | * |
| 4689 | * @see AccessibilityDelegate |
| 4690 | */ |
| 4691 | public void setAccessibilityDelegate(AccessibilityDelegate delegate) { |
| 4692 | mAccessibilityDelegate = delegate; |
| 4693 | } |
| 4694 | |
| 4695 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4696 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 4697 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 4698 | * that explore the window content. |
| 4699 | * <p> |
| 4700 | * If this method returns an instance, this instance is responsible for managing |
| 4701 | * {@link AccessibilityNodeInfo}s describing the virtual sub-tree rooted at this |
| 4702 | * View including the one representing the View itself. Similarly the returned |
| 4703 | * instance is responsible for performing accessibility actions on any virtual |
| 4704 | * view or the root view itself. |
| 4705 | * </p> |
| 4706 | * <p> |
| 4707 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4708 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4709 | * {@link AccessibilityDelegate#getAccessibilityNodeProvider(View)} |
| 4710 | * is responsible for handling this call. |
| 4711 | * </p> |
| 4712 | * |
| 4713 | * @return The provider. |
| 4714 | * |
| 4715 | * @see AccessibilityNodeProvider |
| 4716 | */ |
| 4717 | public AccessibilityNodeProvider getAccessibilityNodeProvider() { |
| 4718 | if (mAccessibilityDelegate != null) { |
| 4719 | return mAccessibilityDelegate.getAccessibilityNodeProvider(this); |
| 4720 | } else { |
| 4721 | return null; |
| 4722 | } |
| 4723 | } |
| 4724 | |
| 4725 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4726 | * Gets the unique identifier of this view on the screen for accessibility purposes. |
| 4727 | * If this {@link View} is not attached to any window, {@value #NO_ID} is returned. |
| 4728 | * |
| 4729 | * @return The view accessibility id. |
| 4730 | * |
| 4731 | * @hide |
| 4732 | */ |
| 4733 | public int getAccessibilityViewId() { |
| 4734 | if (mAccessibilityViewId == NO_ID) { |
| 4735 | mAccessibilityViewId = sNextAccessibilityViewId++; |
| 4736 | } |
| 4737 | return mAccessibilityViewId; |
| 4738 | } |
| 4739 | |
| 4740 | /** |
| 4741 | * Gets the unique identifier of the window in which this View reseides. |
| 4742 | * |
| 4743 | * @return The window accessibility id. |
| 4744 | * |
| 4745 | * @hide |
| 4746 | */ |
| 4747 | public int getAccessibilityWindowId() { |
| 4748 | return mAttachInfo != null ? mAttachInfo.mAccessibilityWindowId : NO_ID; |
| 4749 | } |
| 4750 | |
| 4751 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4752 | * Gets the {@link View} description. It briefly describes the view and is |
| 4753 | * primarily used for accessibility support. Set this property to enable |
| 4754 | * better accessibility support for your application. This is especially |
| 4755 | * true for views that do not have textual representation (For example, |
| 4756 | * ImageButton). |
| 4757 | * |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4758 | * @return The content description. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4759 | * |
| 4760 | * @attr ref android.R.styleable#View_contentDescription |
| 4761 | */ |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4762 | @ViewDebug.ExportedProperty(category = "accessibility") |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4763 | public CharSequence getContentDescription() { |
| 4764 | return mContentDescription; |
| 4765 | } |
| 4766 | |
| 4767 | /** |
| 4768 | * Sets the {@link View} description. It briefly describes the view and is |
| 4769 | * primarily used for accessibility support. Set this property to enable |
| 4770 | * better accessibility support for your application. This is especially |
| 4771 | * true for views that do not have textual representation (For example, |
| 4772 | * ImageButton). |
| 4773 | * |
| 4774 | * @param contentDescription The content description. |
| 4775 | * |
| 4776 | * @attr ref android.R.styleable#View_contentDescription |
| 4777 | */ |
Svetoslav Ganov | e261e28 | 2011-10-18 17:47:04 -0700 | [diff] [blame] | 4778 | @RemotableViewMethod |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4779 | public void setContentDescription(CharSequence contentDescription) { |
| 4780 | mContentDescription = contentDescription; |
| 4781 | } |
| 4782 | |
| 4783 | /** |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4784 | * Invoked whenever this view loses focus, either by losing window focus or by losing |
| 4785 | * focus within its window. This method can be used to clear any state tied to the |
| 4786 | * focus. For instance, if a button is held pressed with the trackball and the window |
| 4787 | * loses focus, this method can be used to cancel the press. |
| 4788 | * |
| 4789 | * Subclasses of View overriding this method should always call super.onFocusLost(). |
| 4790 | * |
| 4791 | * @see #onFocusChanged(boolean, int, android.graphics.Rect) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4792 | * @see #onWindowFocusChanged(boolean) |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4793 | * |
| 4794 | * @hide pending API council approval |
| 4795 | */ |
| 4796 | protected void onFocusLost() { |
| 4797 | resetPressedState(); |
| 4798 | } |
| 4799 | |
| 4800 | private void resetPressedState() { |
| 4801 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 4802 | return; |
| 4803 | } |
| 4804 | |
| 4805 | if (isPressed()) { |
| 4806 | setPressed(false); |
| 4807 | |
| 4808 | if (!mHasPerformedLongPress) { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 4809 | removeLongPressCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4810 | } |
| 4811 | } |
| 4812 | } |
| 4813 | |
| 4814 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4815 | * Returns true if this view has focus |
| 4816 | * |
| 4817 | * @return True if this view has focus, false otherwise. |
| 4818 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4819 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4820 | public boolean isFocused() { |
| 4821 | return (mPrivateFlags & FOCUSED) != 0; |
| 4822 | } |
| 4823 | |
| 4824 | /** |
| 4825 | * Find the view in the hierarchy rooted at this view that currently has |
| 4826 | * focus. |
| 4827 | * |
| 4828 | * @return The view that currently has focus, or null if no focused view can |
| 4829 | * be found. |
| 4830 | */ |
| 4831 | public View findFocus() { |
| 4832 | return (mPrivateFlags & FOCUSED) != 0 ? this : null; |
| 4833 | } |
| 4834 | |
| 4835 | /** |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 4836 | * Indicates whether this view is one of the set of scrollable containers in |
| 4837 | * its window. |
| 4838 | * |
| 4839 | * @return whether this view is one of the set of scrollable containers in |
| 4840 | * its window |
| 4841 | * |
| 4842 | * @attr ref android.R.styleable#View_isScrollContainer |
| 4843 | */ |
| 4844 | public boolean isScrollContainer() { |
| 4845 | return (mPrivateFlags & SCROLL_CONTAINER_ADDED) != 0; |
| 4846 | } |
| 4847 | |
| 4848 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4849 | * Change whether this view is one of the set of scrollable containers in |
| 4850 | * its window. This will be used to determine whether the window can |
| 4851 | * resize or must pan when a soft input area is open -- scrollable |
| 4852 | * containers allow the window to use resize mode since the container |
| 4853 | * will appropriately shrink. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 4854 | * |
| 4855 | * @attr ref android.R.styleable#View_isScrollContainer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4856 | */ |
| 4857 | public void setScrollContainer(boolean isScrollContainer) { |
| 4858 | if (isScrollContainer) { |
| 4859 | if (mAttachInfo != null && (mPrivateFlags&SCROLL_CONTAINER_ADDED) == 0) { |
| 4860 | mAttachInfo.mScrollContainers.add(this); |
| 4861 | mPrivateFlags |= SCROLL_CONTAINER_ADDED; |
| 4862 | } |
| 4863 | mPrivateFlags |= SCROLL_CONTAINER; |
| 4864 | } else { |
| 4865 | if ((mPrivateFlags&SCROLL_CONTAINER_ADDED) != 0) { |
| 4866 | mAttachInfo.mScrollContainers.remove(this); |
| 4867 | } |
| 4868 | mPrivateFlags &= ~(SCROLL_CONTAINER|SCROLL_CONTAINER_ADDED); |
| 4869 | } |
| 4870 | } |
| 4871 | |
| 4872 | /** |
| 4873 | * Returns the quality of the drawing cache. |
| 4874 | * |
| 4875 | * @return One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 4876 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 4877 | * |
| 4878 | * @see #setDrawingCacheQuality(int) |
| 4879 | * @see #setDrawingCacheEnabled(boolean) |
| 4880 | * @see #isDrawingCacheEnabled() |
| 4881 | * |
| 4882 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 4883 | */ |
| 4884 | public int getDrawingCacheQuality() { |
| 4885 | return mViewFlags & DRAWING_CACHE_QUALITY_MASK; |
| 4886 | } |
| 4887 | |
| 4888 | /** |
| 4889 | * Set the drawing cache quality of this view. This value is used only when the |
| 4890 | * drawing cache is enabled |
| 4891 | * |
| 4892 | * @param quality One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 4893 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 4894 | * |
| 4895 | * @see #getDrawingCacheQuality() |
| 4896 | * @see #setDrawingCacheEnabled(boolean) |
| 4897 | * @see #isDrawingCacheEnabled() |
| 4898 | * |
| 4899 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 4900 | */ |
| 4901 | public void setDrawingCacheQuality(int quality) { |
| 4902 | setFlags(quality, DRAWING_CACHE_QUALITY_MASK); |
| 4903 | } |
| 4904 | |
| 4905 | /** |
| 4906 | * Returns whether the screen should remain on, corresponding to the current |
| 4907 | * value of {@link #KEEP_SCREEN_ON}. |
| 4908 | * |
| 4909 | * @return Returns true if {@link #KEEP_SCREEN_ON} is set. |
| 4910 | * |
| 4911 | * @see #setKeepScreenOn(boolean) |
| 4912 | * |
| 4913 | * @attr ref android.R.styleable#View_keepScreenOn |
| 4914 | */ |
| 4915 | public boolean getKeepScreenOn() { |
| 4916 | return (mViewFlags & KEEP_SCREEN_ON) != 0; |
| 4917 | } |
| 4918 | |
| 4919 | /** |
| 4920 | * Controls whether the screen should remain on, modifying the |
| 4921 | * value of {@link #KEEP_SCREEN_ON}. |
| 4922 | * |
| 4923 | * @param keepScreenOn Supply true to set {@link #KEEP_SCREEN_ON}. |
| 4924 | * |
| 4925 | * @see #getKeepScreenOn() |
| 4926 | * |
| 4927 | * @attr ref android.R.styleable#View_keepScreenOn |
| 4928 | */ |
| 4929 | public void setKeepScreenOn(boolean keepScreenOn) { |
| 4930 | setFlags(keepScreenOn ? KEEP_SCREEN_ON : 0, KEEP_SCREEN_ON); |
| 4931 | } |
| 4932 | |
| 4933 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4934 | * Gets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 4935 | * @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] | 4936 | * |
| 4937 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 4938 | */ |
| 4939 | public int getNextFocusLeftId() { |
| 4940 | return mNextFocusLeftId; |
| 4941 | } |
| 4942 | |
| 4943 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4944 | * Sets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 4945 | * @param nextFocusLeftId The next focus ID, or {@link #NO_ID} if the framework should |
| 4946 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4947 | * |
| 4948 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 4949 | */ |
| 4950 | public void setNextFocusLeftId(int nextFocusLeftId) { |
| 4951 | mNextFocusLeftId = nextFocusLeftId; |
| 4952 | } |
| 4953 | |
| 4954 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4955 | * Gets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 4956 | * @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] | 4957 | * |
| 4958 | * @attr ref android.R.styleable#View_nextFocusRight |
| 4959 | */ |
| 4960 | public int getNextFocusRightId() { |
| 4961 | return mNextFocusRightId; |
| 4962 | } |
| 4963 | |
| 4964 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4965 | * Sets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 4966 | * @param nextFocusRightId The next focus ID, or {@link #NO_ID} if the framework should |
| 4967 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4968 | * |
| 4969 | * @attr ref android.R.styleable#View_nextFocusRight |
| 4970 | */ |
| 4971 | public void setNextFocusRightId(int nextFocusRightId) { |
| 4972 | mNextFocusRightId = nextFocusRightId; |
| 4973 | } |
| 4974 | |
| 4975 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4976 | * Gets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 4977 | * @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] | 4978 | * |
| 4979 | * @attr ref android.R.styleable#View_nextFocusUp |
| 4980 | */ |
| 4981 | public int getNextFocusUpId() { |
| 4982 | return mNextFocusUpId; |
| 4983 | } |
| 4984 | |
| 4985 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4986 | * Sets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 4987 | * @param nextFocusUpId The next focus ID, or {@link #NO_ID} if the framework should |
| 4988 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4989 | * |
| 4990 | * @attr ref android.R.styleable#View_nextFocusUp |
| 4991 | */ |
| 4992 | public void setNextFocusUpId(int nextFocusUpId) { |
| 4993 | mNextFocusUpId = nextFocusUpId; |
| 4994 | } |
| 4995 | |
| 4996 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4997 | * Gets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 4998 | * @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] | 4999 | * |
| 5000 | * @attr ref android.R.styleable#View_nextFocusDown |
| 5001 | */ |
| 5002 | public int getNextFocusDownId() { |
| 5003 | return mNextFocusDownId; |
| 5004 | } |
| 5005 | |
| 5006 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5007 | * Sets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 5008 | * @param nextFocusDownId The next focus ID, or {@link #NO_ID} if the framework should |
| 5009 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5010 | * |
| 5011 | * @attr ref android.R.styleable#View_nextFocusDown |
| 5012 | */ |
| 5013 | public void setNextFocusDownId(int nextFocusDownId) { |
| 5014 | mNextFocusDownId = nextFocusDownId; |
| 5015 | } |
| 5016 | |
| 5017 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5018 | * Gets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 5019 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
| 5020 | * |
| 5021 | * @attr ref android.R.styleable#View_nextFocusForward |
| 5022 | */ |
| 5023 | public int getNextFocusForwardId() { |
| 5024 | return mNextFocusForwardId; |
| 5025 | } |
| 5026 | |
| 5027 | /** |
| 5028 | * Sets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 5029 | * @param nextFocusForwardId The next focus ID, or {@link #NO_ID} if the framework should |
| 5030 | * decide automatically. |
| 5031 | * |
| 5032 | * @attr ref android.R.styleable#View_nextFocusForward |
| 5033 | */ |
| 5034 | public void setNextFocusForwardId(int nextFocusForwardId) { |
| 5035 | mNextFocusForwardId = nextFocusForwardId; |
| 5036 | } |
| 5037 | |
| 5038 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5039 | * Returns the visibility of this view and all of its ancestors |
| 5040 | * |
| 5041 | * @return True if this view and all of its ancestors are {@link #VISIBLE} |
| 5042 | */ |
| 5043 | public boolean isShown() { |
| 5044 | View current = this; |
| 5045 | //noinspection ConstantConditions |
| 5046 | do { |
| 5047 | if ((current.mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 5048 | return false; |
| 5049 | } |
| 5050 | ViewParent parent = current.mParent; |
| 5051 | if (parent == null) { |
| 5052 | return false; // We are not attached to the view root |
| 5053 | } |
| 5054 | if (!(parent instanceof View)) { |
| 5055 | return true; |
| 5056 | } |
| 5057 | current = (View) parent; |
| 5058 | } while (current != null); |
| 5059 | |
| 5060 | return false; |
| 5061 | } |
| 5062 | |
| 5063 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5064 | * Called by the view hierarchy when the content insets for a window have |
| 5065 | * changed, to allow it to adjust its content to fit within those windows. |
| 5066 | * The content insets tell you the space that the status bar, input method, |
| 5067 | * 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] | 5068 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5069 | * <p>You do not normally need to deal with this function, since the default |
| 5070 | * window decoration given to applications takes care of applying it to the |
| 5071 | * content of the window. If you use {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} |
| 5072 | * or {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION} this will not be the case, |
| 5073 | * and your content can be placed under those system elements. You can then |
| 5074 | * use this method within your view hierarchy if you have parts of your UI |
| 5075 | * 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] | 5076 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5077 | * <p>The default implementation of this method simply applies the content |
| 5078 | * inset's to the view's padding. This can be enabled through |
| 5079 | * {@link #setFitsSystemWindows(boolean)}. Alternatively, you can override |
| 5080 | * the method and handle the insets however you would like. Note that the |
| 5081 | * insets provided by the framework are always relative to the far edges |
| 5082 | * of the window, not accounting for the location of the called view within |
| 5083 | * that window. (In fact when this method is called you do not yet know |
| 5084 | * where the layout will place the view, as it is done before layout happens.) |
| 5085 | * |
| 5086 | * <p>Note: unlike many View methods, there is no dispatch phase to this |
| 5087 | * call. If you are overriding it in a ViewGroup and want to allow the |
| 5088 | * call to continue to your children, you must be sure to call the super |
| 5089 | * implementation. |
| 5090 | * |
| 5091 | * @param insets Current content insets of the window. Prior to |
| 5092 | * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} you must not modify |
| 5093 | * the insets or else you and Android will be unhappy. |
| 5094 | * |
| 5095 | * @return Return true if this view applied the insets and it should not |
| 5096 | * continue propagating further down the hierarchy, false otherwise. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5097 | */ |
| 5098 | protected boolean fitSystemWindows(Rect insets) { |
| 5099 | if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5100 | mUserPaddingStart = -1; |
| 5101 | mUserPaddingEnd = -1; |
| 5102 | mUserPaddingRelative = false; |
| 5103 | if ((mViewFlags & OPTIONAL_FITS_SYSTEM_WINDOWS) == 0 |
| 5104 | || mAttachInfo == null |
| 5105 | || (mAttachInfo.mSystemUiVisibility & SYSTEM_UI_LAYOUT_FLAGS) == 0) { |
| 5106 | internalSetPadding(insets.left, insets.top, insets.right, insets.bottom); |
| 5107 | return true; |
| 5108 | } else { |
| 5109 | internalSetPadding(0, 0, 0, 0); |
| 5110 | return false; |
| 5111 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5112 | } |
| 5113 | return false; |
| 5114 | } |
| 5115 | |
| 5116 | /** |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5117 | * Set whether or not this view should account for system screen decorations |
| 5118 | * such as the status bar and inset its content. This allows this view to be |
| 5119 | * positioned in absolute screen coordinates and remain visible to the user. |
| 5120 | * |
| 5121 | * <p>This should only be used by top-level window decor views. |
| 5122 | * |
| 5123 | * @param fitSystemWindows true to inset content for system screen decorations, false for |
| 5124 | * default behavior. |
| 5125 | * |
| 5126 | * @attr ref android.R.styleable#View_fitsSystemWindows |
| 5127 | */ |
| 5128 | public void setFitsSystemWindows(boolean fitSystemWindows) { |
| 5129 | setFlags(fitSystemWindows ? FITS_SYSTEM_WINDOWS : 0, FITS_SYSTEM_WINDOWS); |
| 5130 | } |
| 5131 | |
| 5132 | /** |
| 5133 | * Check for the FITS_SYSTEM_WINDOWS flag. If this method returns true, this view |
| 5134 | * will account for system screen decorations such as the status bar and inset its |
| 5135 | * content. This allows the view to be positioned in absolute screen coordinates |
| 5136 | * and remain visible to the user. |
| 5137 | * |
| 5138 | * @return true if this view will adjust its content bounds for system screen decorations. |
| 5139 | * |
| 5140 | * @attr ref android.R.styleable#View_fitsSystemWindows |
| 5141 | */ |
| 5142 | public boolean fitsSystemWindows() { |
| 5143 | return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS; |
| 5144 | } |
| 5145 | |
| 5146 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5147 | * Ask that a new dispatch of {@link #fitSystemWindows(Rect)} be performed. |
| 5148 | */ |
| 5149 | public void requestFitSystemWindows() { |
| 5150 | if (mParent != null) { |
| 5151 | mParent.requestFitSystemWindows(); |
| 5152 | } |
| 5153 | } |
| 5154 | |
| 5155 | /** |
| 5156 | * For use by PhoneWindow to make its own system window fitting optional. |
| 5157 | * @hide |
| 5158 | */ |
| 5159 | public void makeOptionalFitsSystemWindows() { |
| 5160 | setFlags(OPTIONAL_FITS_SYSTEM_WINDOWS, OPTIONAL_FITS_SYSTEM_WINDOWS); |
| 5161 | } |
| 5162 | |
| 5163 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5164 | * Returns the visibility status for this view. |
| 5165 | * |
| 5166 | * @return One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 5167 | * @attr ref android.R.styleable#View_visibility |
| 5168 | */ |
| 5169 | @ViewDebug.ExportedProperty(mapping = { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5170 | @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), |
| 5171 | @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), |
| 5172 | @ViewDebug.IntToString(from = GONE, to = "GONE") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5173 | }) |
| 5174 | public int getVisibility() { |
| 5175 | return mViewFlags & VISIBILITY_MASK; |
| 5176 | } |
| 5177 | |
| 5178 | /** |
| 5179 | * Set the enabled state of this view. |
| 5180 | * |
| 5181 | * @param visibility One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 5182 | * @attr ref android.R.styleable#View_visibility |
| 5183 | */ |
| 5184 | @RemotableViewMethod |
| 5185 | public void setVisibility(int visibility) { |
| 5186 | setFlags(visibility, VISIBILITY_MASK); |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5187 | if (mBackground != null) mBackground.setVisible(visibility == VISIBLE, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5188 | } |
| 5189 | |
| 5190 | /** |
| 5191 | * Returns the enabled status for this view. The interpretation of the |
| 5192 | * enabled state varies by subclass. |
| 5193 | * |
| 5194 | * @return True if this view is enabled, false otherwise. |
| 5195 | */ |
| 5196 | @ViewDebug.ExportedProperty |
| 5197 | public boolean isEnabled() { |
| 5198 | return (mViewFlags & ENABLED_MASK) == ENABLED; |
| 5199 | } |
| 5200 | |
| 5201 | /** |
| 5202 | * Set the enabled state of this view. The interpretation of the enabled |
| 5203 | * state varies by subclass. |
| 5204 | * |
| 5205 | * @param enabled True if this view is enabled, false otherwise. |
| 5206 | */ |
Jeff Sharkey | 2b95c24 | 2010-02-08 17:40:30 -0800 | [diff] [blame] | 5207 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5208 | public void setEnabled(boolean enabled) { |
Amith Yamasani | a2ef00b | 2009-07-30 16:14:34 -0700 | [diff] [blame] | 5209 | if (enabled == isEnabled()) return; |
| 5210 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5211 | setFlags(enabled ? ENABLED : DISABLED, ENABLED_MASK); |
| 5212 | |
| 5213 | /* |
| 5214 | * The View most likely has to change its appearance, so refresh |
| 5215 | * the drawable state. |
| 5216 | */ |
| 5217 | refreshDrawableState(); |
| 5218 | |
| 5219 | // Invalidate too, since the default behavior for views is to be |
| 5220 | // be drawn at 50% alpha rather than to change the drawable. |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 5221 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5222 | } |
| 5223 | |
| 5224 | /** |
| 5225 | * Set whether this view can receive the focus. |
| 5226 | * |
| 5227 | * Setting this to false will also ensure that this view is not focusable |
| 5228 | * in touch mode. |
| 5229 | * |
| 5230 | * @param focusable If true, this view can receive the focus. |
| 5231 | * |
| 5232 | * @see #setFocusableInTouchMode(boolean) |
| 5233 | * @attr ref android.R.styleable#View_focusable |
| 5234 | */ |
| 5235 | public void setFocusable(boolean focusable) { |
| 5236 | if (!focusable) { |
| 5237 | setFlags(0, FOCUSABLE_IN_TOUCH_MODE); |
| 5238 | } |
| 5239 | setFlags(focusable ? FOCUSABLE : NOT_FOCUSABLE, FOCUSABLE_MASK); |
| 5240 | } |
| 5241 | |
| 5242 | /** |
| 5243 | * Set whether this view can receive focus while in touch mode. |
| 5244 | * |
| 5245 | * Setting this to true will also ensure that this view is focusable. |
| 5246 | * |
| 5247 | * @param focusableInTouchMode If true, this view can receive the focus while |
| 5248 | * in touch mode. |
| 5249 | * |
| 5250 | * @see #setFocusable(boolean) |
| 5251 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 5252 | */ |
| 5253 | public void setFocusableInTouchMode(boolean focusableInTouchMode) { |
| 5254 | // Focusable in touch mode should always be set before the focusable flag |
| 5255 | // otherwise, setting the focusable flag will trigger a focusableViewAvailable() |
| 5256 | // which, in touch mode, will not successfully request focus on this view |
| 5257 | // because the focusable in touch mode flag is not set |
| 5258 | setFlags(focusableInTouchMode ? FOCUSABLE_IN_TOUCH_MODE : 0, FOCUSABLE_IN_TOUCH_MODE); |
| 5259 | if (focusableInTouchMode) { |
| 5260 | setFlags(FOCUSABLE, FOCUSABLE_MASK); |
| 5261 | } |
| 5262 | } |
| 5263 | |
| 5264 | /** |
| 5265 | * Set whether this view should have sound effects enabled for events such as |
| 5266 | * clicking and touching. |
| 5267 | * |
| 5268 | * <p>You may wish to disable sound effects for a view if you already play sounds, |
| 5269 | * for instance, a dial key that plays dtmf tones. |
| 5270 | * |
| 5271 | * @param soundEffectsEnabled whether sound effects are enabled for this view. |
| 5272 | * @see #isSoundEffectsEnabled() |
| 5273 | * @see #playSoundEffect(int) |
| 5274 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 5275 | */ |
| 5276 | public void setSoundEffectsEnabled(boolean soundEffectsEnabled) { |
| 5277 | setFlags(soundEffectsEnabled ? SOUND_EFFECTS_ENABLED: 0, SOUND_EFFECTS_ENABLED); |
| 5278 | } |
| 5279 | |
| 5280 | /** |
| 5281 | * @return whether this view should have sound effects enabled for events such as |
| 5282 | * clicking and touching. |
| 5283 | * |
| 5284 | * @see #setSoundEffectsEnabled(boolean) |
| 5285 | * @see #playSoundEffect(int) |
| 5286 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 5287 | */ |
| 5288 | @ViewDebug.ExportedProperty |
| 5289 | public boolean isSoundEffectsEnabled() { |
| 5290 | return SOUND_EFFECTS_ENABLED == (mViewFlags & SOUND_EFFECTS_ENABLED); |
| 5291 | } |
| 5292 | |
| 5293 | /** |
| 5294 | * Set whether this view should have haptic feedback for events such as |
| 5295 | * long presses. |
| 5296 | * |
| 5297 | * <p>You may wish to disable haptic feedback if your view already controls |
| 5298 | * its own haptic feedback. |
| 5299 | * |
| 5300 | * @param hapticFeedbackEnabled whether haptic feedback enabled for this view. |
| 5301 | * @see #isHapticFeedbackEnabled() |
| 5302 | * @see #performHapticFeedback(int) |
| 5303 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 5304 | */ |
| 5305 | public void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled) { |
| 5306 | setFlags(hapticFeedbackEnabled ? HAPTIC_FEEDBACK_ENABLED: 0, HAPTIC_FEEDBACK_ENABLED); |
| 5307 | } |
| 5308 | |
| 5309 | /** |
| 5310 | * @return whether this view should have haptic feedback enabled for events |
| 5311 | * long presses. |
| 5312 | * |
| 5313 | * @see #setHapticFeedbackEnabled(boolean) |
| 5314 | * @see #performHapticFeedback(int) |
| 5315 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 5316 | */ |
| 5317 | @ViewDebug.ExportedProperty |
| 5318 | public boolean isHapticFeedbackEnabled() { |
| 5319 | return HAPTIC_FEEDBACK_ENABLED == (mViewFlags & HAPTIC_FEEDBACK_ENABLED); |
| 5320 | } |
| 5321 | |
| 5322 | /** |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5323 | * Returns the layout direction for this view. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5324 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5325 | * @return One of {@link #LAYOUT_DIRECTION_LTR}, |
| 5326 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 5327 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 5328 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
| 5329 | * @attr ref android.R.styleable#View_layoutDirection |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5330 | */ |
Fabrice Di Meglio | bce84d2 | 2011-06-02 15:57:01 -0700 | [diff] [blame] | 5331 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5332 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "LTR"), |
| 5333 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RTL"), |
| 5334 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"), |
| 5335 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE, to = "LOCALE") |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5336 | }) |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5337 | public int getLayoutDirection() { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5338 | return (mPrivateFlags2 & LAYOUT_DIRECTION_MASK) >> LAYOUT_DIRECTION_MASK_SHIFT; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5339 | } |
| 5340 | |
| 5341 | /** |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5342 | * Set the layout direction for this view. This will propagate a reset of layout direction |
| 5343 | * 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] | 5344 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5345 | * @param layoutDirection One of {@link #LAYOUT_DIRECTION_LTR}, |
| 5346 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 5347 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 5348 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5349 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5350 | * @attr ref android.R.styleable#View_layoutDirection |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5351 | */ |
| 5352 | @RemotableViewMethod |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5353 | public void setLayoutDirection(int layoutDirection) { |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5354 | if (getLayoutDirection() != layoutDirection) { |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 5355 | // Reset the current layout direction and the resolved one |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5356 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_MASK; |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 5357 | resetResolvedLayoutDirection(); |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5358 | // Set the new layout direction (filtered) and ask for a layout pass |
| 5359 | mPrivateFlags2 |= |
| 5360 | ((layoutDirection << LAYOUT_DIRECTION_MASK_SHIFT) & LAYOUT_DIRECTION_MASK); |
| 5361 | requestLayout(); |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5362 | } |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5363 | } |
| 5364 | |
| 5365 | /** |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5366 | * Returns the resolved layout direction for this view. |
| 5367 | * |
| 5368 | * @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] | 5369 | * {@link #LAYOUT_DIRECTION_LTR} if the layout direction is not RTL. |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5370 | */ |
| 5371 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5372 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"), |
| 5373 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL") |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5374 | }) |
| 5375 | public int getResolvedLayoutDirection() { |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 5376 | // The layout diretion will be resolved only if needed |
| 5377 | if ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED) != LAYOUT_DIRECTION_RESOLVED) { |
| 5378 | resolveLayoutDirection(); |
| 5379 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 5380 | return ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED_RTL) == LAYOUT_DIRECTION_RESOLVED_RTL) ? |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5381 | LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR; |
| 5382 | } |
| 5383 | |
| 5384 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5385 | * Indicates whether or not this view's layout is right-to-left. This is resolved from |
| 5386 | * layout attribute and/or the inherited value from the parent |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5387 | * |
| 5388 | * @return true if the layout is right-to-left. |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5389 | */ |
| 5390 | @ViewDebug.ExportedProperty(category = "layout") |
| 5391 | public boolean isLayoutRtl() { |
| 5392 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL); |
| 5393 | } |
| 5394 | |
| 5395 | /** |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5396 | * Indicates whether the view is currently tracking transient state that the |
| 5397 | * app should not need to concern itself with saving and restoring, but that |
| 5398 | * the framework should take special note to preserve when possible. |
| 5399 | * |
| 5400 | * @return true if the view has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5401 | */ |
| 5402 | @ViewDebug.ExportedProperty(category = "layout") |
| 5403 | public boolean hasTransientState() { |
| 5404 | return (mPrivateFlags2 & HAS_TRANSIENT_STATE) == HAS_TRANSIENT_STATE; |
| 5405 | } |
| 5406 | |
| 5407 | /** |
| 5408 | * Set whether this view is currently tracking transient state that the |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame^] | 5409 | * framework should attempt to preserve when possible. This flag is reference counted, |
| 5410 | * so every call to setHasTransientState(true) should be paired with a later call |
| 5411 | * to setHasTransientState(false). |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5412 | * |
| 5413 | * @param hasTransientState true if this view has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5414 | */ |
| 5415 | public void setHasTransientState(boolean hasTransientState) { |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame^] | 5416 | mTransientStateCount = hasTransientState ? mTransientStateCount + 1 : |
| 5417 | mTransientStateCount - 1; |
| 5418 | if (mTransientStateCount < 0) { |
| 5419 | mTransientStateCount = 0; |
| 5420 | Log.e(VIEW_LOG_TAG, "hasTransientState decremented below 0: " + |
| 5421 | "unmatched pair of setHasTransientState calls"); |
| 5422 | } |
| 5423 | if ((hasTransientState && mTransientStateCount == 1) || |
| 5424 | (hasTransientState && mTransientStateCount == 0)) { |
| 5425 | // update flag if we've just incremented up from 0 or decremented down to 0 |
| 5426 | mPrivateFlags2 = (mPrivateFlags2 & ~HAS_TRANSIENT_STATE) | |
| 5427 | (hasTransientState ? HAS_TRANSIENT_STATE : 0); |
| 5428 | if (mParent != null) { |
| 5429 | try { |
| 5430 | mParent.childHasTransientStateChanged(this, hasTransientState); |
| 5431 | } catch (AbstractMethodError e) { |
| 5432 | Log.e(VIEW_LOG_TAG, mParent.getClass().getSimpleName() + |
| 5433 | " does not fully implement ViewParent", e); |
| 5434 | } |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5435 | } |
| 5436 | } |
| 5437 | } |
| 5438 | |
| 5439 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5440 | * If this view doesn't do any drawing on its own, set this flag to |
| 5441 | * allow further optimizations. By default, this flag is not set on |
| 5442 | * View, but could be set on some View subclasses such as ViewGroup. |
| 5443 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5444 | * Typically, if you override {@link #onDraw(android.graphics.Canvas)} |
| 5445 | * you should clear this flag. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5446 | * |
| 5447 | * @param willNotDraw whether or not this View draw on its own |
| 5448 | */ |
| 5449 | public void setWillNotDraw(boolean willNotDraw) { |
| 5450 | setFlags(willNotDraw ? WILL_NOT_DRAW : 0, DRAW_MASK); |
| 5451 | } |
| 5452 | |
| 5453 | /** |
| 5454 | * Returns whether or not this View draws on its own. |
| 5455 | * |
| 5456 | * @return true if this view has nothing to draw, false otherwise |
| 5457 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5458 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5459 | public boolean willNotDraw() { |
| 5460 | return (mViewFlags & DRAW_MASK) == WILL_NOT_DRAW; |
| 5461 | } |
| 5462 | |
| 5463 | /** |
| 5464 | * When a View's drawing cache is enabled, drawing is redirected to an |
| 5465 | * offscreen bitmap. Some views, like an ImageView, must be able to |
| 5466 | * bypass this mechanism if they already draw a single bitmap, to avoid |
| 5467 | * unnecessary usage of the memory. |
| 5468 | * |
| 5469 | * @param willNotCacheDrawing true if this view does not cache its |
| 5470 | * drawing, false otherwise |
| 5471 | */ |
| 5472 | public void setWillNotCacheDrawing(boolean willNotCacheDrawing) { |
| 5473 | setFlags(willNotCacheDrawing ? WILL_NOT_CACHE_DRAWING : 0, WILL_NOT_CACHE_DRAWING); |
| 5474 | } |
| 5475 | |
| 5476 | /** |
| 5477 | * Returns whether or not this View can cache its drawing or not. |
| 5478 | * |
| 5479 | * @return true if this view does not cache its drawing, false otherwise |
| 5480 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5481 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5482 | public boolean willNotCacheDrawing() { |
| 5483 | return (mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING; |
| 5484 | } |
| 5485 | |
| 5486 | /** |
| 5487 | * Indicates whether this view reacts to click events or not. |
| 5488 | * |
| 5489 | * @return true if the view is clickable, false otherwise |
| 5490 | * |
| 5491 | * @see #setClickable(boolean) |
| 5492 | * @attr ref android.R.styleable#View_clickable |
| 5493 | */ |
| 5494 | @ViewDebug.ExportedProperty |
| 5495 | public boolean isClickable() { |
| 5496 | return (mViewFlags & CLICKABLE) == CLICKABLE; |
| 5497 | } |
| 5498 | |
| 5499 | /** |
| 5500 | * Enables or disables click events for this view. When a view |
| 5501 | * is clickable it will change its state to "pressed" on every click. |
| 5502 | * Subclasses should set the view clickable to visually react to |
| 5503 | * user's clicks. |
| 5504 | * |
| 5505 | * @param clickable true to make the view clickable, false otherwise |
| 5506 | * |
| 5507 | * @see #isClickable() |
| 5508 | * @attr ref android.R.styleable#View_clickable |
| 5509 | */ |
| 5510 | public void setClickable(boolean clickable) { |
| 5511 | setFlags(clickable ? CLICKABLE : 0, CLICKABLE); |
| 5512 | } |
| 5513 | |
| 5514 | /** |
| 5515 | * Indicates whether this view reacts to long click events or not. |
| 5516 | * |
| 5517 | * @return true if the view is long clickable, false otherwise |
| 5518 | * |
| 5519 | * @see #setLongClickable(boolean) |
| 5520 | * @attr ref android.R.styleable#View_longClickable |
| 5521 | */ |
| 5522 | public boolean isLongClickable() { |
| 5523 | return (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 5524 | } |
| 5525 | |
| 5526 | /** |
| 5527 | * Enables or disables long click events for this view. When a view is long |
| 5528 | * clickable it reacts to the user holding down the button for a longer |
| 5529 | * duration than a tap. This event can either launch the listener or a |
| 5530 | * context menu. |
| 5531 | * |
| 5532 | * @param longClickable true to make the view long clickable, false otherwise |
| 5533 | * @see #isLongClickable() |
| 5534 | * @attr ref android.R.styleable#View_longClickable |
| 5535 | */ |
| 5536 | public void setLongClickable(boolean longClickable) { |
| 5537 | setFlags(longClickable ? LONG_CLICKABLE : 0, LONG_CLICKABLE); |
| 5538 | } |
| 5539 | |
| 5540 | /** |
Chet Haase | 49afa5b | 2010-08-23 11:39:53 -0700 | [diff] [blame] | 5541 | * Sets the pressed state for this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5542 | * |
| 5543 | * @see #isClickable() |
| 5544 | * @see #setClickable(boolean) |
| 5545 | * |
| 5546 | * @param pressed Pass true to set the View's internal state to "pressed", or false to reverts |
| 5547 | * the View's internal state from a previously set "pressed" state. |
| 5548 | */ |
| 5549 | public void setPressed(boolean pressed) { |
Adam Powell | 035a1fc | 2012-02-27 15:23:50 -0800 | [diff] [blame] | 5550 | final boolean needsRefresh = pressed != ((mPrivateFlags & PRESSED) == PRESSED); |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 5551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5552 | if (pressed) { |
| 5553 | mPrivateFlags |= PRESSED; |
| 5554 | } else { |
| 5555 | mPrivateFlags &= ~PRESSED; |
| 5556 | } |
Adam Powell | 035a1fc | 2012-02-27 15:23:50 -0800 | [diff] [blame] | 5557 | |
| 5558 | if (needsRefresh) { |
| 5559 | refreshDrawableState(); |
| 5560 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5561 | dispatchSetPressed(pressed); |
| 5562 | } |
| 5563 | |
| 5564 | /** |
| 5565 | * Dispatch setPressed to all of this View's children. |
| 5566 | * |
| 5567 | * @see #setPressed(boolean) |
| 5568 | * |
| 5569 | * @param pressed The new pressed state |
| 5570 | */ |
| 5571 | protected void dispatchSetPressed(boolean pressed) { |
| 5572 | } |
| 5573 | |
| 5574 | /** |
| 5575 | * Indicates whether the view is currently in pressed state. Unless |
| 5576 | * {@link #setPressed(boolean)} is explicitly called, only clickable views can enter |
| 5577 | * the pressed state. |
| 5578 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5579 | * @see #setPressed(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5580 | * @see #isClickable() |
| 5581 | * @see #setClickable(boolean) |
| 5582 | * |
| 5583 | * @return true if the view is currently pressed, false otherwise |
| 5584 | */ |
| 5585 | public boolean isPressed() { |
| 5586 | return (mPrivateFlags & PRESSED) == PRESSED; |
| 5587 | } |
| 5588 | |
| 5589 | /** |
| 5590 | * Indicates whether this view will save its state (that is, |
| 5591 | * whether its {@link #onSaveInstanceState} method will be called). |
| 5592 | * |
| 5593 | * @return Returns true if the view state saving is enabled, else false. |
| 5594 | * |
| 5595 | * @see #setSaveEnabled(boolean) |
| 5596 | * @attr ref android.R.styleable#View_saveEnabled |
| 5597 | */ |
| 5598 | public boolean isSaveEnabled() { |
| 5599 | return (mViewFlags & SAVE_DISABLED_MASK) != SAVE_DISABLED; |
| 5600 | } |
| 5601 | |
| 5602 | /** |
| 5603 | * Controls whether the saving of this view's state is |
| 5604 | * enabled (that is, whether its {@link #onSaveInstanceState} method |
| 5605 | * will be called). Note that even if freezing is enabled, the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5606 | * 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] | 5607 | * for its state to be saved. This flag can only disable the |
| 5608 | * saving of this view; any child views may still have their state saved. |
| 5609 | * |
| 5610 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 5611 | * (the default) to allow it. |
| 5612 | * |
| 5613 | * @see #isSaveEnabled() |
| 5614 | * @see #setId(int) |
| 5615 | * @see #onSaveInstanceState() |
| 5616 | * @attr ref android.R.styleable#View_saveEnabled |
| 5617 | */ |
| 5618 | public void setSaveEnabled(boolean enabled) { |
| 5619 | setFlags(enabled ? 0 : SAVE_DISABLED, SAVE_DISABLED_MASK); |
| 5620 | } |
| 5621 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5622 | /** |
| 5623 | * Gets whether the framework should discard touches when the view's |
| 5624 | * window is obscured by another visible window. |
| 5625 | * Refer to the {@link View} security documentation for more details. |
| 5626 | * |
| 5627 | * @return True if touch filtering is enabled. |
| 5628 | * |
| 5629 | * @see #setFilterTouchesWhenObscured(boolean) |
| 5630 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 5631 | */ |
| 5632 | @ViewDebug.ExportedProperty |
| 5633 | public boolean getFilterTouchesWhenObscured() { |
| 5634 | return (mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0; |
| 5635 | } |
| 5636 | |
| 5637 | /** |
| 5638 | * Sets whether the framework should discard touches when the view's |
| 5639 | * window is obscured by another visible window. |
| 5640 | * Refer to the {@link View} security documentation for more details. |
| 5641 | * |
| 5642 | * @param enabled True if touch filtering should be enabled. |
| 5643 | * |
| 5644 | * @see #getFilterTouchesWhenObscured |
| 5645 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 5646 | */ |
| 5647 | public void setFilterTouchesWhenObscured(boolean enabled) { |
| 5648 | setFlags(enabled ? 0 : FILTER_TOUCHES_WHEN_OBSCURED, |
| 5649 | FILTER_TOUCHES_WHEN_OBSCURED); |
| 5650 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5651 | |
| 5652 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 5653 | * Indicates whether the entire hierarchy under this view will save its |
| 5654 | * state when a state saving traversal occurs from its parent. The default |
| 5655 | * is true; if false, these views will not be saved unless |
| 5656 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 5657 | * |
| 5658 | * @return Returns true if the view state saving from parent is enabled, else false. |
| 5659 | * |
| 5660 | * @see #setSaveFromParentEnabled(boolean) |
| 5661 | */ |
| 5662 | public boolean isSaveFromParentEnabled() { |
| 5663 | return (mViewFlags & PARENT_SAVE_DISABLED_MASK) != PARENT_SAVE_DISABLED; |
| 5664 | } |
| 5665 | |
| 5666 | /** |
| 5667 | * Controls whether the entire hierarchy under this view will save its |
| 5668 | * state when a state saving traversal occurs from its parent. The default |
| 5669 | * is true; if false, these views will not be saved unless |
| 5670 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 5671 | * |
| 5672 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 5673 | * (the default) to allow it. |
| 5674 | * |
| 5675 | * @see #isSaveFromParentEnabled() |
| 5676 | * @see #setId(int) |
| 5677 | * @see #onSaveInstanceState() |
| 5678 | */ |
| 5679 | public void setSaveFromParentEnabled(boolean enabled) { |
| 5680 | setFlags(enabled ? 0 : PARENT_SAVE_DISABLED, PARENT_SAVE_DISABLED_MASK); |
| 5681 | } |
| 5682 | |
| 5683 | |
| 5684 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5685 | * Returns whether this View is able to take focus. |
| 5686 | * |
| 5687 | * @return True if this view can take focus, or false otherwise. |
| 5688 | * @attr ref android.R.styleable#View_focusable |
| 5689 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5690 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5691 | public final boolean isFocusable() { |
| 5692 | return FOCUSABLE == (mViewFlags & FOCUSABLE_MASK); |
| 5693 | } |
| 5694 | |
| 5695 | /** |
| 5696 | * When a view is focusable, it may not want to take focus when in touch mode. |
| 5697 | * For example, a button would like focus when the user is navigating via a D-pad |
| 5698 | * so that the user can click on it, but once the user starts touching the screen, |
| 5699 | * the button shouldn't take focus |
| 5700 | * @return Whether the view is focusable in touch mode. |
| 5701 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 5702 | */ |
| 5703 | @ViewDebug.ExportedProperty |
| 5704 | public final boolean isFocusableInTouchMode() { |
| 5705 | return FOCUSABLE_IN_TOUCH_MODE == (mViewFlags & FOCUSABLE_IN_TOUCH_MODE); |
| 5706 | } |
| 5707 | |
| 5708 | /** |
| 5709 | * Find the nearest view in the specified direction that can take focus. |
| 5710 | * This does not actually give focus to that view. |
| 5711 | * |
| 5712 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 5713 | * |
| 5714 | * @return The nearest focusable in the specified direction, or null if none |
| 5715 | * can be found. |
| 5716 | */ |
| 5717 | public View focusSearch(int direction) { |
| 5718 | if (mParent != null) { |
| 5719 | return mParent.focusSearch(this, direction); |
| 5720 | } else { |
| 5721 | return null; |
| 5722 | } |
| 5723 | } |
| 5724 | |
| 5725 | /** |
| 5726 | * This method is the last chance for the focused view and its ancestors to |
| 5727 | * respond to an arrow key. This is called when the focused view did not |
| 5728 | * consume the key internally, nor could the view system find a new view in |
| 5729 | * the requested direction to give focus to. |
| 5730 | * |
| 5731 | * @param focused The currently focused view. |
| 5732 | * @param direction The direction focus wants to move. One of FOCUS_UP, |
| 5733 | * FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT. |
| 5734 | * @return True if the this view consumed this unhandled move. |
| 5735 | */ |
| 5736 | public boolean dispatchUnhandledMove(View focused, int direction) { |
| 5737 | return false; |
| 5738 | } |
| 5739 | |
| 5740 | /** |
| 5741 | * 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] | 5742 | * use the root to look up the view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5743 | * @param root The root view of the hierarchy containing this view. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5744 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, |
| 5745 | * or FOCUS_BACKWARD. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5746 | * @return The user specified next view, or null if there is none. |
| 5747 | */ |
| 5748 | View findUserSetNextFocus(View root, int direction) { |
| 5749 | switch (direction) { |
| 5750 | case FOCUS_LEFT: |
| 5751 | if (mNextFocusLeftId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5752 | return findViewInsideOutShouldExist(root, mNextFocusLeftId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5753 | case FOCUS_RIGHT: |
| 5754 | if (mNextFocusRightId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5755 | return findViewInsideOutShouldExist(root, mNextFocusRightId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5756 | case FOCUS_UP: |
| 5757 | if (mNextFocusUpId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5758 | return findViewInsideOutShouldExist(root, mNextFocusUpId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5759 | case FOCUS_DOWN: |
| 5760 | if (mNextFocusDownId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5761 | return findViewInsideOutShouldExist(root, mNextFocusDownId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5762 | case FOCUS_FORWARD: |
| 5763 | if (mNextFocusForwardId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5764 | return findViewInsideOutShouldExist(root, mNextFocusForwardId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5765 | case FOCUS_BACKWARD: { |
John Reck | 1ecebbb | 2012-03-06 16:08:54 -0800 | [diff] [blame] | 5766 | if (mID == View.NO_ID) return null; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5767 | final int id = mID; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5768 | return root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5769 | @Override |
| 5770 | public boolean apply(View t) { |
| 5771 | return t.mNextFocusForwardId == id; |
| 5772 | } |
| 5773 | }); |
| 5774 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5775 | } |
| 5776 | return null; |
| 5777 | } |
| 5778 | |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5779 | private View findViewInsideOutShouldExist(View root, final int childViewId) { |
| 5780 | View result = root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
| 5781 | @Override |
| 5782 | public boolean apply(View t) { |
| 5783 | return t.mID == childViewId; |
| 5784 | } |
| 5785 | }); |
| 5786 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5787 | if (result == null) { |
| 5788 | Log.w(VIEW_LOG_TAG, "couldn't find next focus view specified " |
| 5789 | + "by user for id " + childViewId); |
| 5790 | } |
| 5791 | return result; |
| 5792 | } |
| 5793 | |
| 5794 | /** |
| 5795 | * Find and return all focusable views that are descendants of this view, |
| 5796 | * possibly including this view if it is focusable itself. |
| 5797 | * |
| 5798 | * @param direction The direction of the focus |
| 5799 | * @return A list of focusable views |
| 5800 | */ |
| 5801 | public ArrayList<View> getFocusables(int direction) { |
| 5802 | ArrayList<View> result = new ArrayList<View>(24); |
| 5803 | addFocusables(result, direction); |
| 5804 | return result; |
| 5805 | } |
| 5806 | |
| 5807 | /** |
| 5808 | * Add any focusable views that are descendants of this view (possibly |
| 5809 | * including this view if it is focusable itself) to views. If we are in touch mode, |
| 5810 | * only add views that are also focusable in touch mode. |
| 5811 | * |
| 5812 | * @param views Focusable views found so far |
| 5813 | * @param direction The direction of the focus |
| 5814 | */ |
| 5815 | public void addFocusables(ArrayList<View> views, int direction) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5816 | addFocusables(views, direction, FOCUSABLES_TOUCH_MODE); |
| 5817 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5818 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5819 | /** |
| 5820 | * Adds any focusable views that are descendants of this view (possibly |
| 5821 | * including this view if it is focusable itself) to views. This method |
| 5822 | * adds all focusable views regardless if we are in touch mode or |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5823 | * only views focusable in touch mode if we are in touch mode or |
| 5824 | * only views that can take accessibility focus if accessibility is enabeld |
| 5825 | * depending on the focusable mode paramater. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5826 | * |
| 5827 | * @param views Focusable views found so far or null if all we are interested is |
| 5828 | * the number of focusables. |
| 5829 | * @param direction The direction of the focus. |
| 5830 | * @param focusableMode The type of focusables to be added. |
| 5831 | * |
| 5832 | * @see #FOCUSABLES_ALL |
| 5833 | * @see #FOCUSABLES_TOUCH_MODE |
| 5834 | */ |
| 5835 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5836 | if (views == null) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5837 | return; |
| 5838 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5839 | if ((focusableMode & FOCUSABLES_ACCESSIBILITY) == FOCUSABLES_ACCESSIBILITY) { |
| 5840 | if (AccessibilityManager.getInstance(mContext).isEnabled() |
| 5841 | && includeForAccessibility()) { |
| 5842 | views.add(this); |
| 5843 | return; |
| 5844 | } |
| 5845 | } |
Svetoslav Ganov | 3cb889c | 2012-04-16 19:10:30 -0700 | [diff] [blame] | 5846 | if (!isFocusable()) { |
| 5847 | return; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5848 | } |
Svetoslav Ganov | 3cb889c | 2012-04-16 19:10:30 -0700 | [diff] [blame] | 5849 | if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE |
| 5850 | && isInTouchMode() && !isFocusableInTouchMode()) { |
| 5851 | return; |
| 5852 | } |
| 5853 | views.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5854 | } |
| 5855 | |
| 5856 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5857 | * Finds the Views that contain given text. The containment is case insensitive. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5858 | * The search is performed by either the text that the View renders or the content |
| 5859 | * description that describes the view for accessibility purposes and the view does |
| 5860 | * not render or both. Clients can specify how the search is to be performed via |
| 5861 | * passing the {@link #FIND_VIEWS_WITH_TEXT} and |
| 5862 | * {@link #FIND_VIEWS_WITH_CONTENT_DESCRIPTION} flags. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5863 | * |
| 5864 | * @param outViews The output list of matching Views. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5865 | * @param searched The text to match against. |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 5866 | * |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5867 | * @see #FIND_VIEWS_WITH_TEXT |
| 5868 | * @see #FIND_VIEWS_WITH_CONTENT_DESCRIPTION |
| 5869 | * @see #setContentDescription(CharSequence) |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5870 | */ |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5871 | public void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 5872 | if (getAccessibilityNodeProvider() != null) { |
| 5873 | if ((flags & FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS) != 0) { |
| 5874 | outViews.add(this); |
| 5875 | } |
| 5876 | } else if ((flags & FIND_VIEWS_WITH_CONTENT_DESCRIPTION) != 0 |
| 5877 | && !TextUtils.isEmpty(searched) && !TextUtils.isEmpty(mContentDescription)) { |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5878 | String searchedLowerCase = searched.toString().toLowerCase(); |
| 5879 | String contentDescriptionLowerCase = mContentDescription.toString().toLowerCase(); |
| 5880 | if (contentDescriptionLowerCase.contains(searchedLowerCase)) { |
| 5881 | outViews.add(this); |
| 5882 | } |
| 5883 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5884 | } |
| 5885 | |
| 5886 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5887 | * Find and return all touchable views that are descendants of this view, |
| 5888 | * possibly including this view if it is touchable itself. |
| 5889 | * |
| 5890 | * @return A list of touchable views |
| 5891 | */ |
| 5892 | public ArrayList<View> getTouchables() { |
| 5893 | ArrayList<View> result = new ArrayList<View>(); |
| 5894 | addTouchables(result); |
| 5895 | return result; |
| 5896 | } |
| 5897 | |
| 5898 | /** |
| 5899 | * Add any touchable views that are descendants of this view (possibly |
| 5900 | * including this view if it is touchable itself) to views. |
| 5901 | * |
| 5902 | * @param views Touchable views found so far |
| 5903 | */ |
| 5904 | public void addTouchables(ArrayList<View> views) { |
| 5905 | final int viewFlags = mViewFlags; |
| 5906 | |
| 5907 | if (((viewFlags & CLICKABLE) == CLICKABLE || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) |
| 5908 | && (viewFlags & ENABLED_MASK) == ENABLED) { |
| 5909 | views.add(this); |
| 5910 | } |
| 5911 | } |
| 5912 | |
| 5913 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5914 | * Returns whether this View is accessibility focused. |
| 5915 | * |
| 5916 | * @return True if this View is accessibility focused. |
| 5917 | */ |
| 5918 | boolean isAccessibilityFocused() { |
| 5919 | return (mPrivateFlags2 & ACCESSIBILITY_FOCUSED) != 0; |
| 5920 | } |
| 5921 | |
| 5922 | /** |
| 5923 | * Call this to try to give accessibility focus to this view. |
| 5924 | * |
| 5925 | * A view will not actually take focus if {@link AccessibilityManager#isEnabled()} |
| 5926 | * returns false or the view is no visible or the view already has accessibility |
| 5927 | * focus. |
| 5928 | * |
| 5929 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
| 5930 | * have focus, and you want your parent to look for the next one. |
| 5931 | * |
| 5932 | * @return Whether this view actually took accessibility focus. |
| 5933 | * |
| 5934 | * @hide |
| 5935 | */ |
| 5936 | public boolean requestAccessibilityFocus() { |
| 5937 | if (!AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 5938 | return false; |
| 5939 | } |
| 5940 | if ((mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 5941 | return false; |
| 5942 | } |
| 5943 | if ((mPrivateFlags2 & ACCESSIBILITY_FOCUSED) == 0) { |
| 5944 | mPrivateFlags2 |= ACCESSIBILITY_FOCUSED; |
| 5945 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 5946 | if (viewRootImpl != null) { |
| 5947 | viewRootImpl.setAccessibilityFocusedHost(this); |
| 5948 | } |
| 5949 | invalidate(); |
| 5950 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED); |
| 5951 | notifyAccessibilityStateChanged(); |
| 5952 | // Try to give input focus to this view - not a descendant. |
| 5953 | requestFocusNoSearch(View.FOCUS_DOWN, null); |
| 5954 | return true; |
| 5955 | } |
| 5956 | return false; |
| 5957 | } |
| 5958 | |
| 5959 | /** |
| 5960 | * Call this to try to clear accessibility focus of this view. |
| 5961 | * |
| 5962 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
| 5963 | * have focus, and you want your parent to look for the next one. |
| 5964 | * |
| 5965 | * @hide |
| 5966 | */ |
| 5967 | public void clearAccessibilityFocus() { |
| 5968 | if ((mPrivateFlags2 & ACCESSIBILITY_FOCUSED) != 0) { |
| 5969 | mPrivateFlags2 &= ~ACCESSIBILITY_FOCUSED; |
| 5970 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 5971 | if (viewRootImpl != null) { |
| 5972 | viewRootImpl.setAccessibilityFocusedHost(null); |
| 5973 | } |
| 5974 | invalidate(); |
| 5975 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED); |
| 5976 | notifyAccessibilityStateChanged(); |
| 5977 | // Try to move accessibility focus to the input focus. |
| 5978 | View rootView = getRootView(); |
| 5979 | if (rootView != null) { |
| 5980 | View inputFocus = rootView.findFocus(); |
| 5981 | if (inputFocus != null) { |
| 5982 | inputFocus.requestAccessibilityFocus(); |
| 5983 | } |
| 5984 | } |
| 5985 | } |
| 5986 | } |
| 5987 | |
| 5988 | /** |
| 5989 | * Find the best view to take accessibility focus from a hover. |
| 5990 | * This function finds the deepest actionable view and if that |
| 5991 | * fails ask the parent to take accessibility focus from hover. |
| 5992 | * |
| 5993 | * @param x The X hovered location in this view coorditantes. |
| 5994 | * @param y The Y hovered location in this view coorditantes. |
| 5995 | * @return Whether the request was handled. |
| 5996 | * |
| 5997 | * @hide |
| 5998 | */ |
| 5999 | public boolean requestAccessibilityFocusFromHover(float x, float y) { |
| 6000 | if (onRequestAccessibilityFocusFromHover(x, y)) { |
| 6001 | return true; |
| 6002 | } |
| 6003 | ViewParent parent = mParent; |
| 6004 | if (parent instanceof View) { |
| 6005 | View parentView = (View) parent; |
| 6006 | |
| 6007 | float[] position = mAttachInfo.mTmpTransformLocation; |
| 6008 | position[0] = x; |
| 6009 | position[1] = y; |
| 6010 | |
| 6011 | // Compensate for the transformation of the current matrix. |
| 6012 | if (!hasIdentityMatrix()) { |
| 6013 | getMatrix().mapPoints(position); |
| 6014 | } |
| 6015 | |
| 6016 | // Compensate for the parent scroll and the offset |
| 6017 | // of this view stop from the parent top. |
| 6018 | position[0] += mLeft - parentView.mScrollX; |
| 6019 | position[1] += mTop - parentView.mScrollY; |
| 6020 | |
| 6021 | return parentView.requestAccessibilityFocusFromHover(position[0], position[1]); |
| 6022 | } |
| 6023 | return false; |
| 6024 | } |
| 6025 | |
| 6026 | /** |
| 6027 | * Requests to give this View focus from hover. |
| 6028 | * |
| 6029 | * @param x The X hovered location in this view coorditantes. |
| 6030 | * @param y The Y hovered location in this view coorditantes. |
| 6031 | * @return Whether the request was handled. |
| 6032 | * |
| 6033 | * @hide |
| 6034 | */ |
| 6035 | public boolean onRequestAccessibilityFocusFromHover(float x, float y) { |
| 6036 | if (includeForAccessibility() |
| 6037 | && (isActionableForAccessibility() || hasListenersForAccessibility())) { |
| 6038 | return requestAccessibilityFocus(); |
| 6039 | } |
| 6040 | return false; |
| 6041 | } |
| 6042 | |
| 6043 | /** |
| 6044 | * Clears accessibility focus without calling any callback methods |
| 6045 | * normally invoked in {@link #clearAccessibilityFocus()}. This method |
| 6046 | * is used for clearing accessibility focus when giving this focus to |
| 6047 | * another view. |
| 6048 | */ |
| 6049 | void clearAccessibilityFocusNoCallbacks() { |
| 6050 | if ((mPrivateFlags2 & ACCESSIBILITY_FOCUSED) != 0) { |
| 6051 | mPrivateFlags2 &= ~ACCESSIBILITY_FOCUSED; |
| 6052 | invalidate(); |
| 6053 | } |
| 6054 | } |
| 6055 | |
| 6056 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6057 | * Call this to try to give focus to a specific view or to one of its |
| 6058 | * descendants. |
| 6059 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6060 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6061 | * false), or if it is focusable and it is not focusable in touch mode |
| 6062 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6063 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6064 | * 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] | 6065 | * have focus, and you want your parent to look for the next one. |
| 6066 | * |
| 6067 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with arguments |
| 6068 | * {@link #FOCUS_DOWN} and <code>null</code>. |
| 6069 | * |
| 6070 | * @return Whether this view or one of its descendants actually took focus. |
| 6071 | */ |
| 6072 | public final boolean requestFocus() { |
| 6073 | return requestFocus(View.FOCUS_DOWN); |
| 6074 | } |
| 6075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6076 | /** |
| 6077 | * Call this to try to give focus to a specific view or to one of its |
| 6078 | * descendants and give it a hint about what direction focus is heading. |
| 6079 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6080 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6081 | * false), or if it is focusable and it is not focusable in touch mode |
| 6082 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6083 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6084 | * 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] | 6085 | * have focus, and you want your parent to look for the next one. |
| 6086 | * |
| 6087 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with |
| 6088 | * <code>null</code> set for the previously focused rectangle. |
| 6089 | * |
| 6090 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 6091 | * @return Whether this view or one of its descendants actually took focus. |
| 6092 | */ |
| 6093 | public final boolean requestFocus(int direction) { |
| 6094 | return requestFocus(direction, null); |
| 6095 | } |
| 6096 | |
| 6097 | /** |
| 6098 | * Call this to try to give focus to a specific view or to one of its descendants |
| 6099 | * and give it hints about the direction and a specific rectangle that the focus |
| 6100 | * is coming from. The rectangle can help give larger views a finer grained hint |
| 6101 | * about where focus is coming from, and therefore, where to show selection, or |
| 6102 | * forward focus change internally. |
| 6103 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6104 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6105 | * false), or if it is focusable and it is not focusable in touch mode |
| 6106 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6107 | * |
| 6108 | * A View will not take focus if it is not visible. |
| 6109 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6110 | * A View will not take focus if one of its parents has |
| 6111 | * {@link android.view.ViewGroup#getDescendantFocusability()} equal to |
| 6112 | * {@link ViewGroup#FOCUS_BLOCK_DESCENDANTS}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6113 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6114 | * 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] | 6115 | * have focus, and you want your parent to look for the next one. |
| 6116 | * |
| 6117 | * You may wish to override this method if your custom {@link View} has an internal |
| 6118 | * {@link View} that it wishes to forward the request to. |
| 6119 | * |
| 6120 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 6121 | * @param previouslyFocusedRect The rectangle (in this View's coordinate system) |
| 6122 | * to give a finer grained hint about where focus is coming from. May be null |
| 6123 | * if there is no hint. |
| 6124 | * @return Whether this view or one of its descendants actually took focus. |
| 6125 | */ |
| 6126 | public boolean requestFocus(int direction, Rect previouslyFocusedRect) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6127 | return requestFocusNoSearch(direction, previouslyFocusedRect); |
| 6128 | } |
| 6129 | |
| 6130 | private boolean requestFocusNoSearch(int direction, Rect previouslyFocusedRect) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6131 | // need to be focusable |
| 6132 | if ((mViewFlags & FOCUSABLE_MASK) != FOCUSABLE || |
| 6133 | (mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 6134 | return false; |
| 6135 | } |
| 6136 | |
| 6137 | // need to be focusable in touch mode if in touch mode |
| 6138 | if (isInTouchMode() && |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6139 | (FOCUSABLE_IN_TOUCH_MODE != (mViewFlags & FOCUSABLE_IN_TOUCH_MODE))) { |
| 6140 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6141 | } |
| 6142 | |
| 6143 | // need to not have any parents blocking us |
| 6144 | if (hasAncestorThatBlocksDescendantFocus()) { |
| 6145 | return false; |
| 6146 | } |
| 6147 | |
| 6148 | handleFocusGainInternal(direction, previouslyFocusedRect); |
| 6149 | return true; |
| 6150 | } |
| 6151 | |
| 6152 | /** |
| 6153 | * Call this to try to give focus to a specific view or to one of its descendants. This is a |
| 6154 | * special variant of {@link #requestFocus() } that will allow views that are not focuable in |
| 6155 | * touch mode to request focus when they are touched. |
| 6156 | * |
| 6157 | * @return Whether this view or one of its descendants actually took focus. |
| 6158 | * |
| 6159 | * @see #isInTouchMode() |
| 6160 | * |
| 6161 | */ |
| 6162 | public final boolean requestFocusFromTouch() { |
| 6163 | // Leave touch mode if we need to |
| 6164 | if (isInTouchMode()) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6165 | ViewRootImpl viewRoot = getViewRootImpl(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6166 | if (viewRoot != null) { |
| 6167 | viewRoot.ensureTouchMode(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6168 | } |
| 6169 | } |
| 6170 | return requestFocus(View.FOCUS_DOWN); |
| 6171 | } |
| 6172 | |
| 6173 | /** |
| 6174 | * @return Whether any ancestor of this view blocks descendant focus. |
| 6175 | */ |
| 6176 | private boolean hasAncestorThatBlocksDescendantFocus() { |
| 6177 | ViewParent ancestor = mParent; |
| 6178 | while (ancestor instanceof ViewGroup) { |
| 6179 | final ViewGroup vgAncestor = (ViewGroup) ancestor; |
| 6180 | if (vgAncestor.getDescendantFocusability() == ViewGroup.FOCUS_BLOCK_DESCENDANTS) { |
| 6181 | return true; |
| 6182 | } else { |
| 6183 | ancestor = vgAncestor.getParent(); |
| 6184 | } |
| 6185 | } |
| 6186 | return false; |
| 6187 | } |
| 6188 | |
| 6189 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6190 | * Gets the mode for determining whether this View is important for accessibility |
| 6191 | * which is if it fires accessibility events and if it is reported to |
| 6192 | * accessibility services that query the screen. |
| 6193 | * |
| 6194 | * @return The mode for determining whether a View is important for accessibility. |
| 6195 | * |
| 6196 | * @attr ref android.R.styleable#View_importantForAccessibility |
| 6197 | * |
| 6198 | * @see #IMPORTANT_FOR_ACCESSIBILITY_YES |
| 6199 | * @see #IMPORTANT_FOR_ACCESSIBILITY_NO |
| 6200 | * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO |
| 6201 | */ |
| 6202 | @ViewDebug.ExportedProperty(category = "accessibility", mapping = { |
| 6203 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_AUTO, |
| 6204 | to = "IMPORTANT_FOR_ACCESSIBILITY_AUTO"), |
| 6205 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_YES, |
| 6206 | to = "IMPORTANT_FOR_ACCESSIBILITY_YES"), |
| 6207 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_NO, |
| 6208 | to = "IMPORTANT_FOR_ACCESSIBILITY_NO") |
| 6209 | }) |
| 6210 | public int getImportantForAccessibility() { |
| 6211 | return (mPrivateFlags2 & IMPORTANT_FOR_ACCESSIBILITY_MASK) |
| 6212 | >> IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
| 6213 | } |
| 6214 | |
| 6215 | /** |
| 6216 | * Sets how to determine whether this view is important for accessibility |
| 6217 | * which is if it fires accessibility events and if it is reported to |
| 6218 | * accessibility services that query the screen. |
| 6219 | * |
| 6220 | * @param mode How to determine whether this view is important for accessibility. |
| 6221 | * |
| 6222 | * @attr ref android.R.styleable#View_importantForAccessibility |
| 6223 | * |
| 6224 | * @see #IMPORTANT_FOR_ACCESSIBILITY_YES |
| 6225 | * @see #IMPORTANT_FOR_ACCESSIBILITY_NO |
| 6226 | * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO |
| 6227 | */ |
| 6228 | public void setImportantForAccessibility(int mode) { |
| 6229 | if (mode != getImportantForAccessibility()) { |
| 6230 | mPrivateFlags2 &= ~IMPORTANT_FOR_ACCESSIBILITY_MASK; |
| 6231 | mPrivateFlags2 |= (mode << IMPORTANT_FOR_ACCESSIBILITY_SHIFT) |
| 6232 | & IMPORTANT_FOR_ACCESSIBILITY_MASK; |
| 6233 | notifyAccessibilityStateChanged(); |
| 6234 | } |
| 6235 | } |
| 6236 | |
| 6237 | /** |
| 6238 | * Gets whether this view should be exposed for accessibility. |
| 6239 | * |
| 6240 | * @return Whether the view is exposed for accessibility. |
| 6241 | * |
| 6242 | * @hide |
| 6243 | */ |
| 6244 | public boolean isImportantForAccessibility() { |
| 6245 | final int mode = (mPrivateFlags2 & IMPORTANT_FOR_ACCESSIBILITY_MASK) |
| 6246 | >> IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
| 6247 | switch (mode) { |
| 6248 | case IMPORTANT_FOR_ACCESSIBILITY_YES: |
| 6249 | return true; |
| 6250 | case IMPORTANT_FOR_ACCESSIBILITY_NO: |
| 6251 | return false; |
| 6252 | case IMPORTANT_FOR_ACCESSIBILITY_AUTO: |
| 6253 | return isActionableForAccessibility() || hasListenersForAccessibility(); |
| 6254 | default: |
| 6255 | throw new IllegalArgumentException("Unknow important for accessibility mode: " |
| 6256 | + mode); |
| 6257 | } |
| 6258 | } |
| 6259 | |
| 6260 | /** |
| 6261 | * Gets the parent for accessibility purposes. Note that the parent for |
| 6262 | * accessibility is not necessary the immediate parent. It is the first |
| 6263 | * predecessor that is important for accessibility. |
| 6264 | * |
| 6265 | * @return The parent for accessibility purposes. |
| 6266 | */ |
| 6267 | public ViewParent getParentForAccessibility() { |
| 6268 | if (mParent instanceof View) { |
| 6269 | View parentView = (View) mParent; |
| 6270 | if (parentView.includeForAccessibility()) { |
| 6271 | return mParent; |
| 6272 | } else { |
| 6273 | return mParent.getParentForAccessibility(); |
| 6274 | } |
| 6275 | } |
| 6276 | return null; |
| 6277 | } |
| 6278 | |
| 6279 | /** |
| 6280 | * Adds the children of a given View for accessibility. Since some Views are |
| 6281 | * not important for accessibility the children for accessibility are not |
| 6282 | * necessarily direct children of the riew, rather they are the first level of |
| 6283 | * descendants important for accessibility. |
| 6284 | * |
| 6285 | * @param children The list of children for accessibility. |
| 6286 | */ |
| 6287 | public void addChildrenForAccessibility(ArrayList<View> children) { |
| 6288 | if (includeForAccessibility()) { |
| 6289 | children.add(this); |
| 6290 | } |
| 6291 | } |
| 6292 | |
| 6293 | /** |
| 6294 | * Whether to regard this view for accessibility. A view is regarded for |
| 6295 | * accessibility if it is important for accessibility or the querying |
| 6296 | * accessibility service has explicitly requested that view not |
| 6297 | * important for accessibility are regarded. |
| 6298 | * |
| 6299 | * @return Whether to regard the view for accessibility. |
| 6300 | */ |
| 6301 | boolean includeForAccessibility() { |
| 6302 | if (mAttachInfo != null) { |
| 6303 | if (!mAttachInfo.mIncludeNotImportantViews) { |
| 6304 | return isImportantForAccessibility(); |
| 6305 | } else { |
| 6306 | return true; |
| 6307 | } |
| 6308 | } |
| 6309 | return false; |
| 6310 | } |
| 6311 | |
| 6312 | /** |
| 6313 | * Returns whether the View is considered actionable from |
| 6314 | * accessibility perspective. Such view are important for |
| 6315 | * accessiiblity. |
| 6316 | * |
| 6317 | * @return True if the view is actionable for accessibility. |
| 6318 | */ |
| 6319 | private boolean isActionableForAccessibility() { |
| 6320 | return (isClickable() || isLongClickable() || isFocusable()); |
| 6321 | } |
| 6322 | |
| 6323 | /** |
| 6324 | * Returns whether the View has registered callbacks wich makes it |
| 6325 | * important for accessiiblity. |
| 6326 | * |
| 6327 | * @return True if the view is actionable for accessibility. |
| 6328 | */ |
| 6329 | private boolean hasListenersForAccessibility() { |
| 6330 | ListenerInfo info = getListenerInfo(); |
| 6331 | return mTouchDelegate != null || info.mOnKeyListener != null |
| 6332 | || info.mOnTouchListener != null || info.mOnGenericMotionListener != null |
| 6333 | || info.mOnHoverListener != null || info.mOnDragListener != null; |
| 6334 | } |
| 6335 | |
| 6336 | /** |
| 6337 | * Notifies accessibility services that some view's important for |
| 6338 | * accessibility state has changed. Note that such notifications |
| 6339 | * are made at most once every |
| 6340 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()} |
| 6341 | * to avoid unnecessary load to the system. Also once a view has |
| 6342 | * made a notifucation this method is a NOP until the notification has |
| 6343 | * been sent to clients. |
| 6344 | * |
| 6345 | * @hide |
| 6346 | * |
| 6347 | * TODO: Makse sure this method is called for any view state change |
| 6348 | * that is interesting for accessilility purposes. |
| 6349 | */ |
| 6350 | public void notifyAccessibilityStateChanged() { |
| 6351 | if ((mPrivateFlags2 & ACCESSIBILITY_STATE_CHANGED) == 0) { |
| 6352 | mPrivateFlags2 |= ACCESSIBILITY_STATE_CHANGED; |
| 6353 | if (mParent != null) { |
| 6354 | mParent.childAccessibilityStateChanged(this); |
| 6355 | } |
| 6356 | } |
| 6357 | } |
| 6358 | |
| 6359 | /** |
| 6360 | * Reset the state indicating the this view has requested clients |
| 6361 | * interested in its accessiblity state to be notified. |
| 6362 | * |
| 6363 | * @hide |
| 6364 | */ |
| 6365 | public void resetAccessibilityStateChanged() { |
| 6366 | mPrivateFlags2 &= ~ACCESSIBILITY_STATE_CHANGED; |
| 6367 | } |
| 6368 | |
| 6369 | /** |
| 6370 | * Performs the specified accessibility action on the view. For |
| 6371 | * possible accessibility actions look at {@link AccessibilityNodeInfo}. |
| 6372 | * |
| 6373 | * @param action The action to perform. |
| 6374 | * @return Whether the action was performed. |
| 6375 | */ |
| 6376 | public boolean performAccessibilityAction(int action) { |
| 6377 | switch (action) { |
| 6378 | case AccessibilityNodeInfo.ACTION_CLICK: { |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 6379 | if (isClickable()) { |
| 6380 | performClick(); |
| 6381 | } |
| 6382 | } break; |
| 6383 | case AccessibilityNodeInfo.ACTION_LONG_CLICK: { |
| 6384 | if (isLongClickable()) { |
| 6385 | performLongClick(); |
| 6386 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6387 | } break; |
| 6388 | case AccessibilityNodeInfo.ACTION_FOCUS: { |
| 6389 | if (!hasFocus()) { |
| 6390 | // Get out of touch mode since accessibility |
| 6391 | // wants to move focus around. |
| 6392 | getViewRootImpl().ensureTouchMode(false); |
| 6393 | return requestFocus(); |
| 6394 | } |
| 6395 | } break; |
| 6396 | case AccessibilityNodeInfo.ACTION_CLEAR_FOCUS: { |
| 6397 | if (hasFocus()) { |
| 6398 | clearFocus(); |
| 6399 | return !isFocused(); |
| 6400 | } |
| 6401 | } break; |
| 6402 | case AccessibilityNodeInfo.ACTION_SELECT: { |
| 6403 | if (!isSelected()) { |
| 6404 | setSelected(true); |
| 6405 | return isSelected(); |
| 6406 | } |
| 6407 | } break; |
| 6408 | case AccessibilityNodeInfo.ACTION_CLEAR_SELECTION: { |
| 6409 | if (isSelected()) { |
| 6410 | setSelected(false); |
| 6411 | return !isSelected(); |
| 6412 | } |
| 6413 | } break; |
| 6414 | case AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS: { |
| 6415 | if (!isAccessibilityFocused()) { |
| 6416 | return requestAccessibilityFocus(); |
| 6417 | } |
| 6418 | } break; |
| 6419 | case AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS: { |
| 6420 | if (isAccessibilityFocused()) { |
| 6421 | clearAccessibilityFocus(); |
| 6422 | return true; |
| 6423 | } |
| 6424 | } break; |
| 6425 | } |
| 6426 | return false; |
| 6427 | } |
| 6428 | |
| 6429 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6430 | * @hide |
| 6431 | */ |
| 6432 | public void dispatchStartTemporaryDetach() { |
| 6433 | onStartTemporaryDetach(); |
| 6434 | } |
| 6435 | |
| 6436 | /** |
| 6437 | * 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] | 6438 | * {@link ViewGroup#detachViewFromParent(View) ViewGroup.detachViewFromParent}. |
| 6439 | * It will either be followed by {@link #onFinishTemporaryDetach()} or |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6440 | * {@link #onDetachedFromWindow()} when the container is done. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6441 | */ |
| 6442 | public void onStartTemporaryDetach() { |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6443 | removeUnsetPressCallback(); |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 6444 | mPrivateFlags |= CANCEL_NEXT_UP_EVENT; |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6445 | } |
| 6446 | |
| 6447 | /** |
| 6448 | * @hide |
| 6449 | */ |
| 6450 | public void dispatchFinishTemporaryDetach() { |
| 6451 | onFinishTemporaryDetach(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6452 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6453 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6454 | /** |
| 6455 | * Called after {@link #onStartTemporaryDetach} when the container is done |
| 6456 | * changing the view. |
| 6457 | */ |
| 6458 | public void onFinishTemporaryDetach() { |
| 6459 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6461 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6462 | * Return the global {@link KeyEvent.DispatcherState KeyEvent.DispatcherState} |
| 6463 | * for this view's window. Returns null if the view is not currently attached |
| 6464 | * 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] | 6465 | * just use the standard high-level event callbacks like |
| 6466 | * {@link #onKeyDown(int, KeyEvent)}. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6467 | */ |
| 6468 | public KeyEvent.DispatcherState getKeyDispatcherState() { |
| 6469 | return mAttachInfo != null ? mAttachInfo.mKeyDispatchState : null; |
| 6470 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6471 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6472 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6473 | * Dispatch a key event before it is processed by any input method |
| 6474 | * associated with the view hierarchy. This can be used to intercept |
| 6475 | * key events in special situations before the IME consumes them; a |
| 6476 | * typical example would be handling the BACK key to update the application's |
| 6477 | * UI instead of allowing the IME to see it and close itself. |
| 6478 | * |
| 6479 | * @param event The key event to be dispatched. |
| 6480 | * @return True if the event was handled, false otherwise. |
| 6481 | */ |
| 6482 | public boolean dispatchKeyEventPreIme(KeyEvent event) { |
| 6483 | return onKeyPreIme(event.getKeyCode(), event); |
| 6484 | } |
| 6485 | |
| 6486 | /** |
| 6487 | * Dispatch a key event to the next view on the focus path. This path runs |
| 6488 | * from the top of the view tree down to the currently focused view. If this |
| 6489 | * view has focus, it will dispatch to itself. Otherwise it will dispatch |
| 6490 | * the next node down the focus path. This method also fires any key |
| 6491 | * listeners. |
| 6492 | * |
| 6493 | * @param event The key event to be dispatched. |
| 6494 | * @return True if the event was handled, false otherwise. |
| 6495 | */ |
| 6496 | public boolean dispatchKeyEvent(KeyEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 6497 | if (mInputEventConsistencyVerifier != null) { |
| 6498 | mInputEventConsistencyVerifier.onKeyEvent(event, 0); |
| 6499 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6500 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 6501 | // Give any attached key listener a first crack at the event. |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 6502 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6503 | ListenerInfo li = mListenerInfo; |
| 6504 | if (li != null && li.mOnKeyListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 6505 | && li.mOnKeyListener.onKey(this, event.getKeyCode(), event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6506 | return true; |
| 6507 | } |
| 6508 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6509 | if (event.dispatch(this, mAttachInfo != null |
| 6510 | ? mAttachInfo.mKeyDispatchState : null, this)) { |
| 6511 | return true; |
| 6512 | } |
| 6513 | |
| 6514 | if (mInputEventConsistencyVerifier != null) { |
| 6515 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 6516 | } |
| 6517 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6518 | } |
| 6519 | |
| 6520 | /** |
| 6521 | * Dispatches a key shortcut event. |
| 6522 | * |
| 6523 | * @param event The key event to be dispatched. |
| 6524 | * @return True if the event was handled by the view, false otherwise. |
| 6525 | */ |
| 6526 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 6527 | return onKeyShortcut(event.getKeyCode(), event); |
| 6528 | } |
| 6529 | |
| 6530 | /** |
| 6531 | * Pass the touch screen motion event down to the target view, or this |
| 6532 | * view if it is the target. |
| 6533 | * |
| 6534 | * @param event The motion event to be dispatched. |
| 6535 | * @return True if the event was handled by the view, false otherwise. |
| 6536 | */ |
| 6537 | public boolean dispatchTouchEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 6538 | if (mInputEventConsistencyVerifier != null) { |
| 6539 | mInputEventConsistencyVerifier.onTouchEvent(event, 0); |
| 6540 | } |
| 6541 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6542 | if (onFilterTouchEventForSecurity(event)) { |
| 6543 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6544 | ListenerInfo li = mListenerInfo; |
| 6545 | if (li != null && li.mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 6546 | && li.mOnTouchListener.onTouch(this, event)) { |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6547 | return true; |
| 6548 | } |
| 6549 | |
| 6550 | if (onTouchEvent(event)) { |
| 6551 | return true; |
| 6552 | } |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 6553 | } |
| 6554 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6555 | if (mInputEventConsistencyVerifier != null) { |
| 6556 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6557 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6558 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6559 | } |
| 6560 | |
| 6561 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 6562 | * Filter the touch event to apply security policies. |
| 6563 | * |
| 6564 | * @param event The motion event to be filtered. |
| 6565 | * @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] | 6566 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 6567 | * @see #getFilterTouchesWhenObscured |
| 6568 | */ |
| 6569 | public boolean onFilterTouchEventForSecurity(MotionEvent event) { |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 6570 | //noinspection RedundantIfStatement |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 6571 | if ((mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0 |
| 6572 | && (event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) { |
| 6573 | // Window is obscured, drop this touch. |
| 6574 | return false; |
| 6575 | } |
| 6576 | return true; |
| 6577 | } |
| 6578 | |
| 6579 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6580 | * Pass a trackball motion event down to the focused view. |
| 6581 | * |
| 6582 | * @param event The motion event to be dispatched. |
| 6583 | * @return True if the event was handled by the view, false otherwise. |
| 6584 | */ |
| 6585 | public boolean dispatchTrackballEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 6586 | if (mInputEventConsistencyVerifier != null) { |
| 6587 | mInputEventConsistencyVerifier.onTrackballEvent(event, 0); |
| 6588 | } |
| 6589 | |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 6590 | return onTrackballEvent(event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6591 | } |
| 6592 | |
| 6593 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6594 | * Dispatch a generic motion event. |
| 6595 | * <p> |
| 6596 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 6597 | * 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] | 6598 | * 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] | 6599 | * to {@link #onHoverEvent(MotionEvent)}. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6600 | * </p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6601 | * |
| 6602 | * @param event The motion event to be dispatched. |
| 6603 | * @return True if the event was handled by the view, false otherwise. |
| 6604 | */ |
| 6605 | public boolean dispatchGenericMotionEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 6606 | if (mInputEventConsistencyVerifier != null) { |
| 6607 | mInputEventConsistencyVerifier.onGenericMotionEvent(event, 0); |
| 6608 | } |
| 6609 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6610 | final int source = event.getSource(); |
| 6611 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 6612 | final int action = event.getAction(); |
| 6613 | if (action == MotionEvent.ACTION_HOVER_ENTER |
| 6614 | || action == MotionEvent.ACTION_HOVER_MOVE |
| 6615 | || action == MotionEvent.ACTION_HOVER_EXIT) { |
| 6616 | if (dispatchHoverEvent(event)) { |
| 6617 | return true; |
| 6618 | } |
| 6619 | } else if (dispatchGenericPointerEvent(event)) { |
| 6620 | return true; |
| 6621 | } |
| 6622 | } else if (dispatchGenericFocusedEvent(event)) { |
| 6623 | return true; |
| 6624 | } |
| 6625 | |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6626 | if (dispatchGenericMotionEventInternal(event)) { |
| 6627 | return true; |
| 6628 | } |
| 6629 | |
| 6630 | if (mInputEventConsistencyVerifier != null) { |
| 6631 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 6632 | } |
| 6633 | return false; |
| 6634 | } |
| 6635 | |
| 6636 | private boolean dispatchGenericMotionEventInternal(MotionEvent event) { |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 6637 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6638 | ListenerInfo li = mListenerInfo; |
| 6639 | if (li != null && li.mOnGenericMotionListener != null |
| 6640 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 6641 | && li.mOnGenericMotionListener.onGenericMotion(this, event)) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6642 | return true; |
| 6643 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6644 | |
| 6645 | if (onGenericMotionEvent(event)) { |
| 6646 | return true; |
| 6647 | } |
| 6648 | |
| 6649 | if (mInputEventConsistencyVerifier != null) { |
| 6650 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 6651 | } |
| 6652 | return false; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6653 | } |
| 6654 | |
| 6655 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6656 | * Dispatch a hover event. |
| 6657 | * <p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 6658 | * Do not call this method directly. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6659 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6660 | * </p> |
| 6661 | * |
| 6662 | * @param event The motion event to be dispatched. |
| 6663 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6664 | */ |
| 6665 | protected boolean dispatchHoverEvent(MotionEvent event) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 6666 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6667 | ListenerInfo li = mListenerInfo; |
| 6668 | if (li != null && li.mOnHoverListener != null |
| 6669 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 6670 | && li.mOnHoverListener.onHover(this, event)) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6671 | return true; |
| 6672 | } |
| 6673 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6674 | return onHoverEvent(event); |
| 6675 | } |
| 6676 | |
| 6677 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6678 | * Returns true if the view has a child to which it has recently sent |
| 6679 | * {@link MotionEvent#ACTION_HOVER_ENTER}. If this view is hovered and |
| 6680 | * it does not have a hovered child, then it must be the innermost hovered view. |
| 6681 | * @hide |
| 6682 | */ |
| 6683 | protected boolean hasHoveredChild() { |
| 6684 | return false; |
| 6685 | } |
| 6686 | |
| 6687 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6688 | * Dispatch a generic motion event to the view under the first pointer. |
| 6689 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6690 | * Do not call this method directly. |
| 6691 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6692 | * </p> |
| 6693 | * |
| 6694 | * @param event The motion event to be dispatched. |
| 6695 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6696 | */ |
| 6697 | protected boolean dispatchGenericPointerEvent(MotionEvent event) { |
| 6698 | return false; |
| 6699 | } |
| 6700 | |
| 6701 | /** |
| 6702 | * Dispatch a generic motion event to the currently focused view. |
| 6703 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6704 | * Do not call this method directly. |
| 6705 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6706 | * </p> |
| 6707 | * |
| 6708 | * @param event The motion event to be dispatched. |
| 6709 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6710 | */ |
| 6711 | protected boolean dispatchGenericFocusedEvent(MotionEvent event) { |
| 6712 | return false; |
| 6713 | } |
| 6714 | |
| 6715 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6716 | * Dispatch a pointer event. |
| 6717 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6718 | * Dispatches touch related pointer events to {@link #onTouchEvent(MotionEvent)} and all |
| 6719 | * other events to {@link #onGenericMotionEvent(MotionEvent)}. This separation of concerns |
| 6720 | * reinforces the invariant that {@link #onTouchEvent(MotionEvent)} is really about touches |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6721 | * and should not be expected to handle other pointing device features. |
| 6722 | * </p> |
| 6723 | * |
| 6724 | * @param event The motion event to be dispatched. |
| 6725 | * @return True if the event was handled by the view, false otherwise. |
| 6726 | * @hide |
| 6727 | */ |
| 6728 | public final boolean dispatchPointerEvent(MotionEvent event) { |
| 6729 | if (event.isTouchEvent()) { |
| 6730 | return dispatchTouchEvent(event); |
| 6731 | } else { |
| 6732 | return dispatchGenericMotionEvent(event); |
| 6733 | } |
| 6734 | } |
| 6735 | |
| 6736 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6737 | * Called when the window containing this view gains or loses window focus. |
| 6738 | * ViewGroups should override to route to their children. |
| 6739 | * |
| 6740 | * @param hasFocus True if the window containing this view now has focus, |
| 6741 | * false otherwise. |
| 6742 | */ |
| 6743 | public void dispatchWindowFocusChanged(boolean hasFocus) { |
| 6744 | onWindowFocusChanged(hasFocus); |
| 6745 | } |
| 6746 | |
| 6747 | /** |
| 6748 | * Called when the window containing this view gains or loses focus. Note |
| 6749 | * that this is separate from view focus: to receive key events, both |
| 6750 | * your view and its window must have focus. If a window is displayed |
| 6751 | * on top of yours that takes input focus, then your own window will lose |
| 6752 | * focus but the view focus will remain unchanged. |
| 6753 | * |
| 6754 | * @param hasWindowFocus True if the window containing this view now has |
| 6755 | * focus, false otherwise. |
| 6756 | */ |
| 6757 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 6758 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 6759 | if (!hasWindowFocus) { |
| 6760 | if (isPressed()) { |
| 6761 | setPressed(false); |
| 6762 | } |
| 6763 | if (imm != null && (mPrivateFlags & FOCUSED) != 0) { |
| 6764 | imm.focusOut(this); |
| 6765 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6766 | removeLongPressCallback(); |
Tony Wu | 26edf20 | 2010-09-13 19:54:00 +0800 | [diff] [blame] | 6767 | removeTapCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 6768 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6769 | } else if (imm != null && (mPrivateFlags & FOCUSED) != 0) { |
| 6770 | imm.focusIn(this); |
| 6771 | } |
| 6772 | refreshDrawableState(); |
| 6773 | } |
| 6774 | |
| 6775 | /** |
| 6776 | * Returns true if this view is in a window that currently has window focus. |
| 6777 | * Note that this is not the same as the view itself having focus. |
| 6778 | * |
| 6779 | * @return True if this view is in a window that currently has window focus. |
| 6780 | */ |
| 6781 | public boolean hasWindowFocus() { |
| 6782 | return mAttachInfo != null && mAttachInfo.mHasWindowFocus; |
| 6783 | } |
| 6784 | |
| 6785 | /** |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6786 | * Dispatch a view visibility change down the view hierarchy. |
| 6787 | * ViewGroups should override to route to their children. |
| 6788 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 6789 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6790 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 6791 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6792 | */ |
| 6793 | protected void dispatchVisibilityChanged(View changedView, int visibility) { |
| 6794 | onVisibilityChanged(changedView, visibility); |
| 6795 | } |
| 6796 | |
| 6797 | /** |
| 6798 | * Called when the visibility of the view or an ancestor of the view is changed. |
| 6799 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 6800 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6801 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 6802 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6803 | */ |
| 6804 | protected void onVisibilityChanged(View changedView, int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 6805 | if (visibility == VISIBLE) { |
| 6806 | if (mAttachInfo != null) { |
| 6807 | initialAwakenScrollBars(); |
| 6808 | } else { |
| 6809 | mPrivateFlags |= AWAKEN_SCROLL_BARS_ON_ATTACH; |
| 6810 | } |
| 6811 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6812 | } |
| 6813 | |
| 6814 | /** |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6815 | * Dispatch a hint about whether this view is displayed. For instance, when |
| 6816 | * a View moves out of the screen, it might receives a display hint indicating |
| 6817 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 6818 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6819 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6820 | * @param hint A hint about whether or not this view is displayed: |
| 6821 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 6822 | */ |
| 6823 | public void dispatchDisplayHint(int hint) { |
| 6824 | onDisplayHint(hint); |
| 6825 | } |
| 6826 | |
| 6827 | /** |
| 6828 | * Gives this view a hint about whether is displayed or not. For instance, when |
| 6829 | * a View moves out of the screen, it might receives a display hint indicating |
| 6830 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 6831 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6832 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6833 | * @param hint A hint about whether or not this view is displayed: |
| 6834 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 6835 | */ |
| 6836 | protected void onDisplayHint(int hint) { |
| 6837 | } |
| 6838 | |
| 6839 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6840 | * Dispatch a window visibility change down the view hierarchy. |
| 6841 | * ViewGroups should override to route to their children. |
| 6842 | * |
| 6843 | * @param visibility The new visibility of the window. |
| 6844 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 6845 | * @see #onWindowVisibilityChanged(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6846 | */ |
| 6847 | public void dispatchWindowVisibilityChanged(int visibility) { |
| 6848 | onWindowVisibilityChanged(visibility); |
| 6849 | } |
| 6850 | |
| 6851 | /** |
| 6852 | * Called when the window containing has change its visibility |
| 6853 | * (between {@link #GONE}, {@link #INVISIBLE}, and {@link #VISIBLE}). Note |
| 6854 | * that this tells you whether or not your window is being made visible |
| 6855 | * to the window manager; this does <em>not</em> tell you whether or not |
| 6856 | * your window is obscured by other windows on the screen, even if it |
| 6857 | * is itself visible. |
| 6858 | * |
| 6859 | * @param visibility The new visibility of the window. |
| 6860 | */ |
| 6861 | protected void onWindowVisibilityChanged(int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 6862 | if (visibility == VISIBLE) { |
| 6863 | initialAwakenScrollBars(); |
| 6864 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6865 | } |
| 6866 | |
| 6867 | /** |
| 6868 | * Returns the current visibility of the window this view is attached to |
| 6869 | * (either {@link #GONE}, {@link #INVISIBLE}, or {@link #VISIBLE}). |
| 6870 | * |
| 6871 | * @return Returns the current visibility of the view's window. |
| 6872 | */ |
| 6873 | public int getWindowVisibility() { |
| 6874 | return mAttachInfo != null ? mAttachInfo.mWindowVisibility : GONE; |
| 6875 | } |
| 6876 | |
| 6877 | /** |
| 6878 | * Retrieve the overall visible display size in which the window this view is |
| 6879 | * attached to has been positioned in. This takes into account screen |
| 6880 | * decorations above the window, for both cases where the window itself |
| 6881 | * is being position inside of them or the window is being placed under |
| 6882 | * then and covered insets are used for the window to position its content |
| 6883 | * inside. In effect, this tells you the available area where content can |
| 6884 | * be placed and remain visible to users. |
| 6885 | * |
| 6886 | * <p>This function requires an IPC back to the window manager to retrieve |
| 6887 | * the requested information, so should not be used in performance critical |
| 6888 | * code like drawing. |
| 6889 | * |
| 6890 | * @param outRect Filled in with the visible display frame. If the view |
| 6891 | * is not attached to a window, this is simply the raw display size. |
| 6892 | */ |
| 6893 | public void getWindowVisibleDisplayFrame(Rect outRect) { |
| 6894 | if (mAttachInfo != null) { |
| 6895 | try { |
| 6896 | mAttachInfo.mSession.getDisplayFrame(mAttachInfo.mWindow, outRect); |
| 6897 | } catch (RemoteException e) { |
| 6898 | return; |
| 6899 | } |
| 6900 | // XXX This is really broken, and probably all needs to be done |
| 6901 | // in the window manager, and we need to know more about whether |
| 6902 | // we want the area behind or in front of the IME. |
| 6903 | final Rect insets = mAttachInfo.mVisibleInsets; |
| 6904 | outRect.left += insets.left; |
| 6905 | outRect.top += insets.top; |
| 6906 | outRect.right -= insets.right; |
| 6907 | outRect.bottom -= insets.bottom; |
| 6908 | return; |
| 6909 | } |
| 6910 | Display d = WindowManagerImpl.getDefault().getDefaultDisplay(); |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 6911 | d.getRectSize(outRect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6912 | } |
| 6913 | |
| 6914 | /** |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6915 | * Dispatch a notification about a resource configuration change down |
| 6916 | * the view hierarchy. |
| 6917 | * ViewGroups should override to route to their children. |
| 6918 | * |
| 6919 | * @param newConfig The new resource configuration. |
| 6920 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 6921 | * @see #onConfigurationChanged(android.content.res.Configuration) |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6922 | */ |
| 6923 | public void dispatchConfigurationChanged(Configuration newConfig) { |
| 6924 | onConfigurationChanged(newConfig); |
| 6925 | } |
| 6926 | |
| 6927 | /** |
| 6928 | * Called when the current configuration of the resources being used |
| 6929 | * by the application have changed. You can use this to decide when |
| 6930 | * to reload resources that can changed based on orientation and other |
| 6931 | * configuration characterstics. You only need to use this if you are |
| 6932 | * not relying on the normal {@link android.app.Activity} mechanism of |
| 6933 | * recreating the activity instance upon a configuration change. |
| 6934 | * |
| 6935 | * @param newConfig The new resource configuration. |
| 6936 | */ |
| 6937 | protected void onConfigurationChanged(Configuration newConfig) { |
| 6938 | } |
| 6939 | |
| 6940 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6941 | * Private function to aggregate all per-view attributes in to the view |
| 6942 | * root. |
| 6943 | */ |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6944 | void dispatchCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 6945 | performCollectViewAttributes(attachInfo, visibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6946 | } |
| 6947 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6948 | void performCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 6949 | if ((visibility & VISIBILITY_MASK) == VISIBLE) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6950 | if ((mViewFlags & KEEP_SCREEN_ON) == KEEP_SCREEN_ON) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6951 | attachInfo.mKeepScreenOn = true; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6952 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6953 | attachInfo.mSystemUiVisibility |= mSystemUiVisibility; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6954 | ListenerInfo li = mListenerInfo; |
| 6955 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 6956 | attachInfo.mHasSystemUiListeners = true; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6957 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6958 | } |
| 6959 | } |
| 6960 | |
| 6961 | void needGlobalAttributesUpdate(boolean force) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6962 | final AttachInfo ai = mAttachInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6963 | if (ai != null) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6964 | if (force || ai.mKeepScreenOn || (ai.mSystemUiVisibility != 0) |
| 6965 | || ai.mHasSystemUiListeners) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6966 | ai.mRecomputeGlobalAttributes = true; |
| 6967 | } |
| 6968 | } |
| 6969 | } |
| 6970 | |
| 6971 | /** |
| 6972 | * Returns whether the device is currently in touch mode. Touch mode is entered |
| 6973 | * once the user begins interacting with the device by touch, and affects various |
| 6974 | * things like whether focus is always visible to the user. |
| 6975 | * |
| 6976 | * @return Whether the device is in touch mode. |
| 6977 | */ |
| 6978 | @ViewDebug.ExportedProperty |
| 6979 | public boolean isInTouchMode() { |
| 6980 | if (mAttachInfo != null) { |
| 6981 | return mAttachInfo.mInTouchMode; |
| 6982 | } else { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6983 | return ViewRootImpl.isInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6984 | } |
| 6985 | } |
| 6986 | |
| 6987 | /** |
| 6988 | * Returns the context the view is running in, through which it can |
| 6989 | * access the current theme, resources, etc. |
| 6990 | * |
| 6991 | * @return The view's Context. |
| 6992 | */ |
| 6993 | @ViewDebug.CapturedViewProperty |
| 6994 | public final Context getContext() { |
| 6995 | return mContext; |
| 6996 | } |
| 6997 | |
| 6998 | /** |
| 6999 | * Handle a key event before it is processed by any input method |
| 7000 | * associated with the view hierarchy. This can be used to intercept |
| 7001 | * key events in special situations before the IME consumes them; a |
| 7002 | * typical example would be handling the BACK key to update the application's |
| 7003 | * UI instead of allowing the IME to see it and close itself. |
| 7004 | * |
| 7005 | * @param keyCode The value in event.getKeyCode(). |
| 7006 | * @param event Description of the key event. |
| 7007 | * @return If you handled the event, return true. If you want to allow the |
| 7008 | * event to be handled by the next receiver, return false. |
| 7009 | */ |
| 7010 | public boolean onKeyPreIme(int keyCode, KeyEvent event) { |
| 7011 | return false; |
| 7012 | } |
| 7013 | |
| 7014 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 7015 | * Default implementation of {@link KeyEvent.Callback#onKeyDown(int, KeyEvent) |
| 7016 | * KeyEvent.Callback.onKeyDown()}: perform press of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7017 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or {@link KeyEvent#KEYCODE_ENTER} |
| 7018 | * is released, if the view is enabled and clickable. |
| 7019 | * |
| 7020 | * @param keyCode A key code that represents the button pressed, from |
| 7021 | * {@link android.view.KeyEvent}. |
| 7022 | * @param event The KeyEvent object that defines the button action. |
| 7023 | */ |
| 7024 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 7025 | boolean result = false; |
| 7026 | |
| 7027 | switch (keyCode) { |
| 7028 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 7029 | case KeyEvent.KEYCODE_ENTER: { |
| 7030 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 7031 | return true; |
| 7032 | } |
| 7033 | // Long clickable items don't necessarily have to be clickable |
| 7034 | if (((mViewFlags & CLICKABLE) == CLICKABLE || |
| 7035 | (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) && |
| 7036 | (event.getRepeatCount() == 0)) { |
| 7037 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7038 | checkForLongClick(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7039 | return true; |
| 7040 | } |
| 7041 | break; |
| 7042 | } |
| 7043 | } |
| 7044 | return result; |
| 7045 | } |
| 7046 | |
| 7047 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7048 | * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
| 7049 | * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle |
| 7050 | * the event). |
| 7051 | */ |
| 7052 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 7053 | return false; |
| 7054 | } |
| 7055 | |
| 7056 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 7057 | * Default implementation of {@link KeyEvent.Callback#onKeyUp(int, KeyEvent) |
| 7058 | * KeyEvent.Callback.onKeyUp()}: perform clicking of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7059 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or |
| 7060 | * {@link KeyEvent#KEYCODE_ENTER} is released. |
| 7061 | * |
| 7062 | * @param keyCode A key code that represents the button pressed, from |
| 7063 | * {@link android.view.KeyEvent}. |
| 7064 | * @param event The KeyEvent object that defines the button action. |
| 7065 | */ |
| 7066 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 7067 | boolean result = false; |
| 7068 | |
| 7069 | switch (keyCode) { |
| 7070 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 7071 | case KeyEvent.KEYCODE_ENTER: { |
| 7072 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 7073 | return true; |
| 7074 | } |
| 7075 | if ((mViewFlags & CLICKABLE) == CLICKABLE && isPressed()) { |
| 7076 | setPressed(false); |
| 7077 | |
| 7078 | if (!mHasPerformedLongPress) { |
| 7079 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7080 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7081 | |
| 7082 | result = performClick(); |
| 7083 | } |
| 7084 | } |
| 7085 | break; |
| 7086 | } |
| 7087 | } |
| 7088 | return result; |
| 7089 | } |
| 7090 | |
| 7091 | /** |
| 7092 | * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) |
| 7093 | * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle |
| 7094 | * the event). |
| 7095 | * |
| 7096 | * @param keyCode A key code that represents the button pressed, from |
| 7097 | * {@link android.view.KeyEvent}. |
| 7098 | * @param repeatCount The number of times the action was made. |
| 7099 | * @param event The KeyEvent object that defines the button action. |
| 7100 | */ |
| 7101 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 7102 | return false; |
| 7103 | } |
| 7104 | |
| 7105 | /** |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 7106 | * Called on the focused view when a key shortcut event is not handled. |
| 7107 | * Override this method to implement local key shortcuts for the View. |
| 7108 | * Key shortcuts can also be implemented by setting the |
| 7109 | * {@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] | 7110 | * |
| 7111 | * @param keyCode The value in event.getKeyCode(). |
| 7112 | * @param event Description of the key event. |
| 7113 | * @return If you handled the event, return true. If you want to allow the |
| 7114 | * event to be handled by the next receiver, return false. |
| 7115 | */ |
| 7116 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
| 7117 | return false; |
| 7118 | } |
| 7119 | |
| 7120 | /** |
| 7121 | * Check whether the called view is a text editor, in which case it |
| 7122 | * would make sense to automatically display a soft input window for |
| 7123 | * it. Subclasses should override this if they implement |
| 7124 | * {@link #onCreateInputConnection(EditorInfo)} to return true if |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7125 | * a call on that method would return a non-null InputConnection, and |
| 7126 | * they are really a first-class editor that the user would normally |
| 7127 | * start typing on when the go into a window containing your view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7128 | * |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7129 | * <p>The default implementation always returns false. This does |
| 7130 | * <em>not</em> mean that its {@link #onCreateInputConnection(EditorInfo)} |
| 7131 | * will not be called or the user can not otherwise perform edits on your |
| 7132 | * view; it is just a hint to the system that this is not the primary |
| 7133 | * purpose of this view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7134 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7135 | * @return Returns true if this view is a text editor, else false. |
| 7136 | */ |
| 7137 | public boolean onCheckIsTextEditor() { |
| 7138 | return false; |
| 7139 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7141 | /** |
| 7142 | * Create a new InputConnection for an InputMethod to interact |
| 7143 | * with the view. The default implementation returns null, since it doesn't |
| 7144 | * support input methods. You can override this to implement such support. |
| 7145 | * This is only needed for views that take focus and text input. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7146 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7147 | * <p>When implementing this, you probably also want to implement |
| 7148 | * {@link #onCheckIsTextEditor()} to indicate you will return a |
| 7149 | * non-null InputConnection. |
| 7150 | * |
| 7151 | * @param outAttrs Fill in with attribute information about the connection. |
| 7152 | */ |
| 7153 | public InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
| 7154 | return null; |
| 7155 | } |
| 7156 | |
| 7157 | /** |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7158 | * Called by the {@link android.view.inputmethod.InputMethodManager} |
| 7159 | * when a view who is not the current |
| 7160 | * input connection target is trying to make a call on the manager. The |
| 7161 | * default implementation returns false; you can override this to return |
| 7162 | * true for certain views if you are performing InputConnection proxying |
| 7163 | * to them. |
| 7164 | * @param view The View that is making the InputMethodManager call. |
| 7165 | * @return Return true to allow the call, false to reject. |
| 7166 | */ |
| 7167 | public boolean checkInputConnectionProxy(View view) { |
| 7168 | return false; |
| 7169 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7170 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7171 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7172 | * Show the context menu for this view. It is not safe to hold on to the |
| 7173 | * menu after returning from this method. |
| 7174 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 7175 | * You should normally not overload this method. Overload |
| 7176 | * {@link #onCreateContextMenu(ContextMenu)} or define an |
| 7177 | * {@link OnCreateContextMenuListener} to add items to the context menu. |
| 7178 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7179 | * @param menu The context menu to populate |
| 7180 | */ |
| 7181 | public void createContextMenu(ContextMenu menu) { |
| 7182 | ContextMenuInfo menuInfo = getContextMenuInfo(); |
| 7183 | |
| 7184 | // Sets the current menu info so all items added to menu will have |
| 7185 | // my extra info set. |
| 7186 | ((MenuBuilder)menu).setCurrentMenuInfo(menuInfo); |
| 7187 | |
| 7188 | onCreateContextMenu(menu); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7189 | ListenerInfo li = mListenerInfo; |
| 7190 | if (li != null && li.mOnCreateContextMenuListener != null) { |
| 7191 | li.mOnCreateContextMenuListener.onCreateContextMenu(menu, this, menuInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7192 | } |
| 7193 | |
| 7194 | // Clear the extra information so subsequent items that aren't mine don't |
| 7195 | // have my extra info. |
| 7196 | ((MenuBuilder)menu).setCurrentMenuInfo(null); |
| 7197 | |
| 7198 | if (mParent != null) { |
| 7199 | mParent.createContextMenu(menu); |
| 7200 | } |
| 7201 | } |
| 7202 | |
| 7203 | /** |
| 7204 | * Views should implement this if they have extra information to associate |
| 7205 | * with the context menu. The return result is supplied as a parameter to |
| 7206 | * the {@link OnCreateContextMenuListener#onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} |
| 7207 | * callback. |
| 7208 | * |
| 7209 | * @return Extra information about the item for which the context menu |
| 7210 | * should be shown. This information will vary across different |
| 7211 | * subclasses of View. |
| 7212 | */ |
| 7213 | protected ContextMenuInfo getContextMenuInfo() { |
| 7214 | return null; |
| 7215 | } |
| 7216 | |
| 7217 | /** |
| 7218 | * Views should implement this if the view itself is going to add items to |
| 7219 | * the context menu. |
| 7220 | * |
| 7221 | * @param menu the context menu to populate |
| 7222 | */ |
| 7223 | protected void onCreateContextMenu(ContextMenu menu) { |
| 7224 | } |
| 7225 | |
| 7226 | /** |
| 7227 | * Implement this method to handle trackball motion events. The |
| 7228 | * <em>relative</em> movement of the trackball since the last event |
| 7229 | * can be retrieve with {@link MotionEvent#getX MotionEvent.getX()} and |
| 7230 | * {@link MotionEvent#getY MotionEvent.getY()}. These are normalized so |
| 7231 | * that a movement of 1 corresponds to the user pressing one DPAD key (so |
| 7232 | * they will often be fractional values, representing the more fine-grained |
| 7233 | * movement information available from a trackball). |
| 7234 | * |
| 7235 | * @param event The motion event. |
| 7236 | * @return True if the event was handled, false otherwise. |
| 7237 | */ |
| 7238 | public boolean onTrackballEvent(MotionEvent event) { |
| 7239 | return false; |
| 7240 | } |
| 7241 | |
| 7242 | /** |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7243 | * Implement this method to handle generic motion events. |
| 7244 | * <p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7245 | * Generic motion events describe joystick movements, mouse hovers, track pad |
| 7246 | * touches, scroll wheel movements and other input events. The |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7247 | * {@link MotionEvent#getSource() source} of the motion event specifies |
| 7248 | * the class of input that was received. Implementations of this method |
| 7249 | * must examine the bits in the source before processing the event. |
| 7250 | * The following code example shows how this is done. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7251 | * </p><p> |
| 7252 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 7253 | * are delivered to the view under the pointer. All other generic motion events are |
| 7254 | * delivered to the focused view. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7255 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 7256 | * <pre> public boolean onGenericMotionEvent(MotionEvent event) { |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7257 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7258 | * if (event.getAction() == MotionEvent.ACTION_MOVE) { |
| 7259 | * // process the joystick movement... |
| 7260 | * return true; |
| 7261 | * } |
| 7262 | * } |
| 7263 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 7264 | * switch (event.getAction()) { |
| 7265 | * case MotionEvent.ACTION_HOVER_MOVE: |
| 7266 | * // process the mouse hover movement... |
| 7267 | * return true; |
| 7268 | * case MotionEvent.ACTION_SCROLL: |
| 7269 | * // process the scroll wheel movement... |
| 7270 | * return true; |
| 7271 | * } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7272 | * } |
| 7273 | * return super.onGenericMotionEvent(event); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 7274 | * }</pre> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7275 | * |
| 7276 | * @param event The generic motion event being processed. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7277 | * @return True if the event was handled, false otherwise. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7278 | */ |
| 7279 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 7280 | return false; |
| 7281 | } |
| 7282 | |
| 7283 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7284 | * Implement this method to handle hover events. |
| 7285 | * <p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7286 | * This method is called whenever a pointer is hovering into, over, or out of the |
| 7287 | * bounds of a view and the view is not currently being touched. |
| 7288 | * Hover events are represented as pointer events with action |
| 7289 | * {@link MotionEvent#ACTION_HOVER_ENTER}, {@link MotionEvent#ACTION_HOVER_MOVE}, |
| 7290 | * or {@link MotionEvent#ACTION_HOVER_EXIT}. |
| 7291 | * </p> |
| 7292 | * <ul> |
| 7293 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_ENTER} |
| 7294 | * when the pointer enters the bounds of the view.</li> |
| 7295 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_MOVE} |
| 7296 | * when the pointer has already entered the bounds of the view and has moved.</li> |
| 7297 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_EXIT} |
| 7298 | * when the pointer has exited the bounds of the view or when the pointer is |
| 7299 | * about to go down due to a button click, tap, or similar user action that |
| 7300 | * causes the view to be touched.</li> |
| 7301 | * </ul> |
| 7302 | * <p> |
| 7303 | * The view should implement this method to return true to indicate that it is |
| 7304 | * handling the hover event, such as by changing its drawable state. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7305 | * </p><p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7306 | * The default implementation calls {@link #setHovered} to update the hovered state |
| 7307 | * 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] | 7308 | * is enabled and is clickable. The default implementation also sends hover |
| 7309 | * accessibility events. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7310 | * </p> |
| 7311 | * |
| 7312 | * @param event The motion event that describes the hover. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7313 | * @return True if the view handled the hover event. |
| 7314 | * |
| 7315 | * @see #isHovered |
| 7316 | * @see #setHovered |
| 7317 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7318 | */ |
| 7319 | public boolean onHoverEvent(MotionEvent event) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7320 | // The root view may receive hover (or touch) events that are outside the bounds of |
| 7321 | // the window. This code ensures that we only send accessibility events for |
| 7322 | // hovers that are actually within the bounds of the root view. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7323 | final int action = event.getActionMasked(); |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7324 | if (!mSendingHoverAccessibilityEvents) { |
| 7325 | if ((action == MotionEvent.ACTION_HOVER_ENTER |
| 7326 | || action == MotionEvent.ACTION_HOVER_MOVE) |
| 7327 | && !hasHoveredChild() |
| 7328 | && pointInView(event.getX(), event.getY())) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7329 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7330 | mSendingHoverAccessibilityEvents = true; |
| 7331 | requestAccessibilityFocusFromHover((int) event.getX(), (int) event.getY()); |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7332 | } |
| 7333 | } else { |
| 7334 | if (action == MotionEvent.ACTION_HOVER_EXIT |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7335 | || (action == MotionEvent.ACTION_MOVE |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7336 | && !pointInView(event.getX(), event.getY()))) { |
| 7337 | mSendingHoverAccessibilityEvents = false; |
| 7338 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7339 | // If the window does not have input focus we take away accessibility |
| 7340 | // focus as soon as the user stop hovering over the view. |
| 7341 | if (!mAttachInfo.mHasWindowFocus) { |
| 7342 | getViewRootImpl().setAccessibilityFocusedHost(null); |
| 7343 | } |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7344 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 7345 | } |
| 7346 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 7347 | if (isHoverable()) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7348 | switch (action) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7349 | case MotionEvent.ACTION_HOVER_ENTER: |
| 7350 | setHovered(true); |
| 7351 | break; |
| 7352 | case MotionEvent.ACTION_HOVER_EXIT: |
| 7353 | setHovered(false); |
| 7354 | break; |
| 7355 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 7356 | |
| 7357 | // Dispatch the event to onGenericMotionEvent before returning true. |
| 7358 | // This is to provide compatibility with existing applications that |
| 7359 | // handled HOVER_MOVE events in onGenericMotionEvent and that would |
| 7360 | // break because of the new default handling for hoverable views |
| 7361 | // in onHoverEvent. |
| 7362 | // Note that onGenericMotionEvent will be called by default when |
| 7363 | // onHoverEvent returns false (refer to dispatchGenericMotionEvent). |
| 7364 | dispatchGenericMotionEventInternal(event); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7365 | return true; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7366 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7367 | |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 7368 | return false; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7369 | } |
| 7370 | |
| 7371 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 7372 | * Returns true if the view should handle {@link #onHoverEvent} |
| 7373 | * by calling {@link #setHovered} to change its hovered state. |
| 7374 | * |
| 7375 | * @return True if the view is hoverable. |
| 7376 | */ |
| 7377 | private boolean isHoverable() { |
| 7378 | final int viewFlags = mViewFlags; |
| 7379 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
| 7380 | return false; |
| 7381 | } |
| 7382 | |
| 7383 | return (viewFlags & CLICKABLE) == CLICKABLE |
| 7384 | || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 7385 | } |
| 7386 | |
| 7387 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7388 | * Returns true if the view is currently hovered. |
| 7389 | * |
| 7390 | * @return True if the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7391 | * |
| 7392 | * @see #setHovered |
| 7393 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7394 | */ |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7395 | @ViewDebug.ExportedProperty |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7396 | public boolean isHovered() { |
| 7397 | return (mPrivateFlags & HOVERED) != 0; |
| 7398 | } |
| 7399 | |
| 7400 | /** |
| 7401 | * Sets whether the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7402 | * <p> |
| 7403 | * Calling this method also changes the drawable state of the view. This |
| 7404 | * enables the view to react to hover by using different drawable resources |
| 7405 | * to change its appearance. |
| 7406 | * </p><p> |
| 7407 | * The {@link #onHoverChanged} method is called when the hovered state changes. |
| 7408 | * </p> |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7409 | * |
| 7410 | * @param hovered True if the view is hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7411 | * |
| 7412 | * @see #isHovered |
| 7413 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7414 | */ |
| 7415 | public void setHovered(boolean hovered) { |
| 7416 | if (hovered) { |
| 7417 | if ((mPrivateFlags & HOVERED) == 0) { |
| 7418 | mPrivateFlags |= HOVERED; |
| 7419 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7420 | onHoverChanged(true); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7421 | } |
| 7422 | } else { |
| 7423 | if ((mPrivateFlags & HOVERED) != 0) { |
| 7424 | mPrivateFlags &= ~HOVERED; |
| 7425 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7426 | onHoverChanged(false); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7427 | } |
| 7428 | } |
| 7429 | } |
| 7430 | |
| 7431 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7432 | * Implement this method to handle hover state changes. |
| 7433 | * <p> |
| 7434 | * This method is called whenever the hover state changes as a result of a |
| 7435 | * call to {@link #setHovered}. |
| 7436 | * </p> |
| 7437 | * |
| 7438 | * @param hovered The current hover state, as returned by {@link #isHovered}. |
| 7439 | * |
| 7440 | * @see #isHovered |
| 7441 | * @see #setHovered |
| 7442 | */ |
| 7443 | public void onHoverChanged(boolean hovered) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7444 | } |
| 7445 | |
| 7446 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7447 | * Implement this method to handle touch screen motion events. |
| 7448 | * |
| 7449 | * @param event The motion event. |
| 7450 | * @return True if the event was handled, false otherwise. |
| 7451 | */ |
| 7452 | public boolean onTouchEvent(MotionEvent event) { |
| 7453 | final int viewFlags = mViewFlags; |
| 7454 | |
| 7455 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
Svetoslav Ganov | 77b80c0 | 2011-03-15 20:52:58 -0700 | [diff] [blame] | 7456 | if (event.getAction() == MotionEvent.ACTION_UP && (mPrivateFlags & PRESSED) != 0) { |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 7457 | setPressed(false); |
Svetoslav Ganov | 77b80c0 | 2011-03-15 20:52:58 -0700 | [diff] [blame] | 7458 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7459 | // A disabled view that is clickable still consumes the touch |
| 7460 | // events, it just doesn't respond to them. |
| 7461 | return (((viewFlags & CLICKABLE) == CLICKABLE || |
| 7462 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)); |
| 7463 | } |
| 7464 | |
| 7465 | if (mTouchDelegate != null) { |
| 7466 | if (mTouchDelegate.onTouchEvent(event)) { |
| 7467 | return true; |
| 7468 | } |
| 7469 | } |
| 7470 | |
| 7471 | if (((viewFlags & CLICKABLE) == CLICKABLE || |
| 7472 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)) { |
| 7473 | switch (event.getAction()) { |
| 7474 | case MotionEvent.ACTION_UP: |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7475 | boolean prepressed = (mPrivateFlags & PREPRESSED) != 0; |
| 7476 | if ((mPrivateFlags & PRESSED) != 0 || prepressed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7477 | // take focus if we don't have it already and we should in |
| 7478 | // touch mode. |
| 7479 | boolean focusTaken = false; |
| 7480 | if (isFocusable() && isFocusableInTouchMode() && !isFocused()) { |
| 7481 | focusTaken = requestFocus(); |
| 7482 | } |
| 7483 | |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 7484 | if (prepressed) { |
| 7485 | // The button is being released before we actually |
| 7486 | // showed it as pressed. Make it show the pressed |
| 7487 | // state now (before scheduling the click) to ensure |
| 7488 | // the user sees it. |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 7489 | setPressed(true); |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 7490 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7492 | if (!mHasPerformedLongPress) { |
| 7493 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7494 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7495 | |
| 7496 | // Only perform take click actions if we were in the pressed state |
| 7497 | if (!focusTaken) { |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 7498 | // Use a Runnable and post this rather than calling |
| 7499 | // performClick directly. This lets other visual state |
| 7500 | // of the view update before click actions start. |
| 7501 | if (mPerformClick == null) { |
| 7502 | mPerformClick = new PerformClick(); |
| 7503 | } |
| 7504 | if (!post(mPerformClick)) { |
| 7505 | performClick(); |
| 7506 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7507 | } |
| 7508 | } |
| 7509 | |
| 7510 | if (mUnsetPressedState == null) { |
| 7511 | mUnsetPressedState = new UnsetPressedState(); |
| 7512 | } |
| 7513 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7514 | if (prepressed) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7515 | postDelayed(mUnsetPressedState, |
| 7516 | ViewConfiguration.getPressedStateDuration()); |
| 7517 | } else if (!post(mUnsetPressedState)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7518 | // If the post failed, unpress right now |
| 7519 | mUnsetPressedState.run(); |
| 7520 | } |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7521 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7522 | } |
| 7523 | break; |
| 7524 | |
| 7525 | case MotionEvent.ACTION_DOWN: |
Adam Powell | 3b02339 | 2010-03-11 16:30:28 -0800 | [diff] [blame] | 7526 | mHasPerformedLongPress = false; |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7527 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 7528 | if (performButtonActionOnTouchDown(event)) { |
| 7529 | break; |
| 7530 | } |
| 7531 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7532 | // 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] | 7533 | boolean isInScrollingContainer = isInScrollingContainer(); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7534 | |
| 7535 | // For views inside a scrolling container, delay the pressed feedback for |
| 7536 | // a short period in case this is a scroll. |
| 7537 | if (isInScrollingContainer) { |
| 7538 | mPrivateFlags |= PREPRESSED; |
| 7539 | if (mPendingCheckForTap == null) { |
| 7540 | mPendingCheckForTap = new CheckForTap(); |
| 7541 | } |
| 7542 | postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); |
| 7543 | } else { |
| 7544 | // Not inside a scrolling container, so show the feedback right away |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 7545 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7546 | checkForLongClick(0); |
| 7547 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7548 | break; |
| 7549 | |
| 7550 | case MotionEvent.ACTION_CANCEL: |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 7551 | setPressed(false); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7552 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7553 | break; |
| 7554 | |
| 7555 | case MotionEvent.ACTION_MOVE: |
| 7556 | final int x = (int) event.getX(); |
| 7557 | final int y = (int) event.getY(); |
| 7558 | |
| 7559 | // Be lenient about moving outside of buttons |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7560 | if (!pointInView(x, y, mTouchSlop)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7561 | // Outside button |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7562 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7563 | if ((mPrivateFlags & PRESSED) != 0) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7564 | // Remove any future long press/tap checks |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7565 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7566 | |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 7567 | setPressed(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7568 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7569 | } |
| 7570 | break; |
| 7571 | } |
| 7572 | return true; |
| 7573 | } |
| 7574 | |
| 7575 | return false; |
| 7576 | } |
| 7577 | |
| 7578 | /** |
Adam Powell | 1029866 | 2011-08-14 18:26:30 -0700 | [diff] [blame] | 7579 | * @hide |
| 7580 | */ |
| 7581 | public boolean isInScrollingContainer() { |
| 7582 | ViewParent p = getParent(); |
| 7583 | while (p != null && p instanceof ViewGroup) { |
| 7584 | if (((ViewGroup) p).shouldDelayChildPressedState()) { |
| 7585 | return true; |
| 7586 | } |
| 7587 | p = p.getParent(); |
| 7588 | } |
| 7589 | return false; |
| 7590 | } |
| 7591 | |
| 7592 | /** |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7593 | * Remove the longpress detection timer. |
| 7594 | */ |
| 7595 | private void removeLongPressCallback() { |
| 7596 | if (mPendingCheckForLongPress != null) { |
| 7597 | removeCallbacks(mPendingCheckForLongPress); |
| 7598 | } |
| 7599 | } |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 7600 | |
| 7601 | /** |
| 7602 | * Remove the pending click action |
| 7603 | */ |
| 7604 | private void removePerformClickCallback() { |
| 7605 | if (mPerformClick != null) { |
| 7606 | removeCallbacks(mPerformClick); |
| 7607 | } |
| 7608 | } |
| 7609 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7610 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7611 | * Remove the prepress detection timer. |
| 7612 | */ |
| 7613 | private void removeUnsetPressCallback() { |
| 7614 | if ((mPrivateFlags & PRESSED) != 0 && mUnsetPressedState != null) { |
| 7615 | setPressed(false); |
| 7616 | removeCallbacks(mUnsetPressedState); |
| 7617 | } |
| 7618 | } |
| 7619 | |
| 7620 | /** |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7621 | * Remove the tap detection timer. |
| 7622 | */ |
| 7623 | private void removeTapCallback() { |
| 7624 | if (mPendingCheckForTap != null) { |
| 7625 | mPrivateFlags &= ~PREPRESSED; |
| 7626 | removeCallbacks(mPendingCheckForTap); |
| 7627 | } |
| 7628 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7629 | |
| 7630 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7631 | * Cancels a pending long press. Your subclass can use this if you |
| 7632 | * want the context menu to come up if the user presses and holds |
| 7633 | * at the same place, but you don't want it to come up if they press |
| 7634 | * and then move around enough to cause scrolling. |
| 7635 | */ |
| 7636 | public void cancelLongPress() { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7637 | removeLongPressCallback(); |
Adam Powell | 732ebb1 | 2010-02-02 15:28:14 -0800 | [diff] [blame] | 7638 | |
| 7639 | /* |
| 7640 | * The prepressed state handled by the tap callback is a display |
| 7641 | * construct, but the tap callback will post a long press callback |
| 7642 | * less its own timeout. Remove it here. |
| 7643 | */ |
| 7644 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7645 | } |
| 7646 | |
| 7647 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7648 | * Remove the pending callback for sending a |
| 7649 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 7650 | */ |
| 7651 | private void removeSendViewScrolledAccessibilityEventCallback() { |
| 7652 | if (mSendViewScrolledAccessibilityEvent != null) { |
| 7653 | removeCallbacks(mSendViewScrolledAccessibilityEvent); |
| 7654 | } |
| 7655 | } |
| 7656 | |
| 7657 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7658 | * Sets the TouchDelegate for this View. |
| 7659 | */ |
| 7660 | public void setTouchDelegate(TouchDelegate delegate) { |
| 7661 | mTouchDelegate = delegate; |
| 7662 | } |
| 7663 | |
| 7664 | /** |
| 7665 | * Gets the TouchDelegate for this View. |
| 7666 | */ |
| 7667 | public TouchDelegate getTouchDelegate() { |
| 7668 | return mTouchDelegate; |
| 7669 | } |
| 7670 | |
| 7671 | /** |
| 7672 | * Set flags controlling behavior of this view. |
| 7673 | * |
| 7674 | * @param flags Constant indicating the value which should be set |
| 7675 | * @param mask Constant indicating the bit range that should be changed |
| 7676 | */ |
| 7677 | void setFlags(int flags, int mask) { |
| 7678 | int old = mViewFlags; |
| 7679 | mViewFlags = (mViewFlags & ~mask) | (flags & mask); |
| 7680 | |
| 7681 | int changed = mViewFlags ^ old; |
| 7682 | if (changed == 0) { |
| 7683 | return; |
| 7684 | } |
| 7685 | int privateFlags = mPrivateFlags; |
| 7686 | |
| 7687 | /* Check if the FOCUSABLE bit has changed */ |
| 7688 | if (((changed & FOCUSABLE_MASK) != 0) && |
| 7689 | ((privateFlags & HAS_BOUNDS) !=0)) { |
| 7690 | if (((old & FOCUSABLE_MASK) == FOCUSABLE) |
| 7691 | && ((privateFlags & FOCUSED) != 0)) { |
| 7692 | /* Give up focus if we are no longer focusable */ |
| 7693 | clearFocus(); |
| 7694 | } else if (((old & FOCUSABLE_MASK) == NOT_FOCUSABLE) |
| 7695 | && ((privateFlags & FOCUSED) == 0)) { |
| 7696 | /* |
| 7697 | * Tell the view system that we are now available to take focus |
| 7698 | * if no one else already has it. |
| 7699 | */ |
| 7700 | if (mParent != null) mParent.focusableViewAvailable(this); |
| 7701 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7702 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 7703 | notifyAccessibilityStateChanged(); |
| 7704 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7705 | } |
| 7706 | |
| 7707 | if ((flags & VISIBILITY_MASK) == VISIBLE) { |
| 7708 | if ((changed & VISIBILITY_MASK) != 0) { |
| 7709 | /* |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 7710 | * 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] | 7711 | * it was not visible. Marking it drawn ensures that the invalidation will |
| 7712 | * go through. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7713 | */ |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 7714 | mPrivateFlags |= DRAWN; |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 7715 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7716 | |
| 7717 | needGlobalAttributesUpdate(true); |
| 7718 | |
| 7719 | // a view becoming visible is worth notifying the parent |
| 7720 | // about in case nothing has focus. even if this specific view |
| 7721 | // isn't focusable, it may contain something that is, so let |
| 7722 | // the root view try to give this focus if nothing else does. |
| 7723 | if ((mParent != null) && (mBottom > mTop) && (mRight > mLeft)) { |
| 7724 | mParent.focusableViewAvailable(this); |
| 7725 | } |
| 7726 | } |
| 7727 | } |
| 7728 | |
| 7729 | /* Check if the GONE bit has changed */ |
| 7730 | if ((changed & GONE) != 0) { |
| 7731 | needGlobalAttributesUpdate(false); |
| 7732 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7733 | |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 7734 | if (((mViewFlags & VISIBILITY_MASK) == GONE)) { |
| 7735 | if (hasFocus()) clearFocus(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7736 | clearAccessibilityFocus(); |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 7737 | destroyDrawingCache(); |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 7738 | if (mParent instanceof View) { |
| 7739 | // GONE views noop invalidation, so invalidate the parent |
| 7740 | ((View) mParent).invalidate(true); |
| 7741 | } |
| 7742 | // Mark the view drawn to ensure that it gets invalidated properly the next |
| 7743 | // time it is visible and gets invalidated |
| 7744 | mPrivateFlags |= DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7745 | } |
| 7746 | if (mAttachInfo != null) { |
| 7747 | mAttachInfo.mViewVisibilityChanged = true; |
| 7748 | } |
| 7749 | } |
| 7750 | |
| 7751 | /* Check if the VISIBLE bit has changed */ |
| 7752 | if ((changed & INVISIBLE) != 0) { |
| 7753 | needGlobalAttributesUpdate(false); |
Chet Haase | c8a9a70 | 2011-06-17 12:13:42 -0700 | [diff] [blame] | 7754 | /* |
| 7755 | * If this view is becoming invisible, set the DRAWN flag so that |
| 7756 | * the next invalidate() will not be skipped. |
| 7757 | */ |
| 7758 | mPrivateFlags |= DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7759 | |
| 7760 | if (((mViewFlags & VISIBILITY_MASK) == INVISIBLE) && hasFocus()) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7761 | // root view becoming invisible shouldn't clear focus and accessibility focus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7762 | if (getRootView() != this) { |
| 7763 | clearFocus(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7764 | clearAccessibilityFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7765 | } |
| 7766 | } |
| 7767 | if (mAttachInfo != null) { |
| 7768 | mAttachInfo.mViewVisibilityChanged = true; |
| 7769 | } |
| 7770 | } |
| 7771 | |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7772 | if ((changed & VISIBILITY_MASK) != 0) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 7773 | if (mParent instanceof ViewGroup) { |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 7774 | ((ViewGroup) mParent).onChildVisibilityChanged(this, |
| 7775 | (changed & VISIBILITY_MASK), (flags & VISIBILITY_MASK)); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7776 | ((View) mParent).invalidate(true); |
Chet Haase | e4e6e20 | 2011-08-29 14:34:30 -0700 | [diff] [blame] | 7777 | } else if (mParent != null) { |
| 7778 | mParent.invalidateChild(this, null); |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 7779 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7780 | dispatchVisibilityChanged(this, (flags & VISIBILITY_MASK)); |
| 7781 | } |
| 7782 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7783 | if ((changed & WILL_NOT_CACHE_DRAWING) != 0) { |
| 7784 | destroyDrawingCache(); |
| 7785 | } |
| 7786 | |
| 7787 | if ((changed & DRAWING_CACHE_ENABLED) != 0) { |
| 7788 | destroyDrawingCache(); |
| 7789 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7790 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7791 | } |
| 7792 | |
| 7793 | if ((changed & DRAWING_CACHE_QUALITY_MASK) != 0) { |
| 7794 | destroyDrawingCache(); |
| 7795 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 7796 | } |
| 7797 | |
| 7798 | if ((changed & DRAW_MASK) != 0) { |
| 7799 | if ((mViewFlags & WILL_NOT_DRAW) != 0) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7800 | if (mBackground != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7801 | mPrivateFlags &= ~SKIP_DRAW; |
| 7802 | mPrivateFlags |= ONLY_DRAWS_BACKGROUND; |
| 7803 | } else { |
| 7804 | mPrivateFlags |= SKIP_DRAW; |
| 7805 | } |
| 7806 | } else { |
| 7807 | mPrivateFlags &= ~SKIP_DRAW; |
| 7808 | } |
| 7809 | requestLayout(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7810 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7811 | } |
| 7812 | |
| 7813 | if ((changed & KEEP_SCREEN_ON) != 0) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7814 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7815 | mParent.recomputeViewAttributes(this); |
| 7816 | } |
| 7817 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7818 | |
| 7819 | if (AccessibilityManager.getInstance(mContext).isEnabled() |
| 7820 | && ((changed & FOCUSABLE) != 0 || (changed & CLICKABLE) != 0 |
| 7821 | || (changed & LONG_CLICKABLE) != 0 || (changed & ENABLED) != 0)) { |
| 7822 | notifyAccessibilityStateChanged(); |
| 7823 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7824 | } |
| 7825 | |
| 7826 | /** |
| 7827 | * Change the view's z order in the tree, so it's on top of other sibling |
| 7828 | * views |
| 7829 | */ |
| 7830 | public void bringToFront() { |
| 7831 | if (mParent != null) { |
| 7832 | mParent.bringChildToFront(this); |
| 7833 | } |
| 7834 | } |
| 7835 | |
| 7836 | /** |
| 7837 | * This is called in response to an internal scroll in this view (i.e., the |
| 7838 | * view scrolled its own contents). This is typically as a result of |
| 7839 | * {@link #scrollBy(int, int)} or {@link #scrollTo(int, int)} having been |
| 7840 | * called. |
| 7841 | * |
| 7842 | * @param l Current horizontal scroll origin. |
| 7843 | * @param t Current vertical scroll origin. |
| 7844 | * @param oldl Previous horizontal scroll origin. |
| 7845 | * @param oldt Previous vertical scroll origin. |
| 7846 | */ |
| 7847 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7848 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 7849 | postSendViewScrolledAccessibilityEventCallback(); |
| 7850 | } |
| 7851 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7852 | mBackgroundSizeChanged = true; |
| 7853 | |
| 7854 | final AttachInfo ai = mAttachInfo; |
| 7855 | if (ai != null) { |
| 7856 | ai.mViewScrollChanged = true; |
| 7857 | } |
| 7858 | } |
| 7859 | |
| 7860 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7861 | * Interface definition for a callback to be invoked when the layout bounds of a view |
| 7862 | * changes due to layout processing. |
| 7863 | */ |
| 7864 | public interface OnLayoutChangeListener { |
| 7865 | /** |
| 7866 | * Called when the focus state of a view has changed. |
| 7867 | * |
| 7868 | * @param v The view whose state has changed. |
| 7869 | * @param left The new value of the view's left property. |
| 7870 | * @param top The new value of the view's top property. |
| 7871 | * @param right The new value of the view's right property. |
| 7872 | * @param bottom The new value of the view's bottom property. |
| 7873 | * @param oldLeft The previous value of the view's left property. |
| 7874 | * @param oldTop The previous value of the view's top property. |
| 7875 | * @param oldRight The previous value of the view's right property. |
| 7876 | * @param oldBottom The previous value of the view's bottom property. |
| 7877 | */ |
| 7878 | void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 7879 | int oldLeft, int oldTop, int oldRight, int oldBottom); |
| 7880 | } |
| 7881 | |
| 7882 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7883 | * This is called during layout when the size of this view has changed. If |
| 7884 | * you were just added to the view hierarchy, you're called with the old |
| 7885 | * values of 0. |
| 7886 | * |
| 7887 | * @param w Current width of this view. |
| 7888 | * @param h Current height of this view. |
| 7889 | * @param oldw Old width of this view. |
| 7890 | * @param oldh Old height of this view. |
| 7891 | */ |
| 7892 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 7893 | } |
| 7894 | |
| 7895 | /** |
| 7896 | * Called by draw to draw the child views. This may be overridden |
| 7897 | * by derived classes to gain control just before its children are drawn |
| 7898 | * (but after its own view has been drawn). |
| 7899 | * @param canvas the canvas on which to draw the view |
| 7900 | */ |
| 7901 | protected void dispatchDraw(Canvas canvas) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7903 | } |
| 7904 | |
| 7905 | /** |
| 7906 | * Gets the parent of this view. Note that the parent is a |
| 7907 | * ViewParent and not necessarily a View. |
| 7908 | * |
| 7909 | * @return Parent of this view. |
| 7910 | */ |
| 7911 | public final ViewParent getParent() { |
| 7912 | return mParent; |
| 7913 | } |
| 7914 | |
| 7915 | /** |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 7916 | * Set the horizontal scrolled position of your view. This will cause a call to |
| 7917 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 7918 | * invalidated. |
| 7919 | * @param value the x position to scroll to |
| 7920 | */ |
| 7921 | public void setScrollX(int value) { |
| 7922 | scrollTo(value, mScrollY); |
| 7923 | } |
| 7924 | |
| 7925 | /** |
| 7926 | * Set the vertical scrolled position of your view. This will cause a call to |
| 7927 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 7928 | * invalidated. |
| 7929 | * @param value the y position to scroll to |
| 7930 | */ |
| 7931 | public void setScrollY(int value) { |
| 7932 | scrollTo(mScrollX, value); |
| 7933 | } |
| 7934 | |
| 7935 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7936 | * Return the scrolled left position of this view. This is the left edge of |
| 7937 | * the displayed part of your view. You do not need to draw any pixels |
| 7938 | * farther left, since those are outside of the frame of your view on |
| 7939 | * screen. |
| 7940 | * |
| 7941 | * @return The left edge of the displayed part of your view, in pixels. |
| 7942 | */ |
| 7943 | public final int getScrollX() { |
| 7944 | return mScrollX; |
| 7945 | } |
| 7946 | |
| 7947 | /** |
| 7948 | * Return the scrolled top position of this view. This is the top edge of |
| 7949 | * the displayed part of your view. You do not need to draw any pixels above |
| 7950 | * it, since those are outside of the frame of your view on screen. |
| 7951 | * |
| 7952 | * @return The top edge of the displayed part of your view, in pixels. |
| 7953 | */ |
| 7954 | public final int getScrollY() { |
| 7955 | return mScrollY; |
| 7956 | } |
| 7957 | |
| 7958 | /** |
| 7959 | * Return the width of the your view. |
| 7960 | * |
| 7961 | * @return The width of your view, in pixels. |
| 7962 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 7963 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7964 | public final int getWidth() { |
| 7965 | return mRight - mLeft; |
| 7966 | } |
| 7967 | |
| 7968 | /** |
| 7969 | * Return the height of your view. |
| 7970 | * |
| 7971 | * @return The height of your view, in pixels. |
| 7972 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 7973 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7974 | public final int getHeight() { |
| 7975 | return mBottom - mTop; |
| 7976 | } |
| 7977 | |
| 7978 | /** |
| 7979 | * Return the visible drawing bounds of your view. Fills in the output |
| 7980 | * rectangle with the values from getScrollX(), getScrollY(), |
| 7981 | * getWidth(), and getHeight(). |
| 7982 | * |
| 7983 | * @param outRect The (scrolled) drawing bounds of the view. |
| 7984 | */ |
| 7985 | public void getDrawingRect(Rect outRect) { |
| 7986 | outRect.left = mScrollX; |
| 7987 | outRect.top = mScrollY; |
| 7988 | outRect.right = mScrollX + (mRight - mLeft); |
| 7989 | outRect.bottom = mScrollY + (mBottom - mTop); |
| 7990 | } |
| 7991 | |
| 7992 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7993 | * Like {@link #getMeasuredWidthAndState()}, but only returns the |
| 7994 | * raw width component (that is the result is masked by |
| 7995 | * {@link #MEASURED_SIZE_MASK}). |
| 7996 | * |
| 7997 | * @return The raw measured width of this view. |
| 7998 | */ |
| 7999 | public final int getMeasuredWidth() { |
| 8000 | return mMeasuredWidth & MEASURED_SIZE_MASK; |
| 8001 | } |
| 8002 | |
| 8003 | /** |
| 8004 | * Return the full width measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8005 | * 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] | 8006 | * 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] | 8007 | * This should be used during measurement and layout calculations only. Use |
| 8008 | * {@link #getWidth()} to see how wide a view is after layout. |
| 8009 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8010 | * @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] | 8011 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8012 | public final int getMeasuredWidthAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8013 | return mMeasuredWidth; |
| 8014 | } |
| 8015 | |
| 8016 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8017 | * Like {@link #getMeasuredHeightAndState()}, but only returns the |
| 8018 | * raw width component (that is the result is masked by |
| 8019 | * {@link #MEASURED_SIZE_MASK}). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8020 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8021 | * @return The raw measured height of this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8022 | */ |
| 8023 | public final int getMeasuredHeight() { |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8024 | return mMeasuredHeight & MEASURED_SIZE_MASK; |
| 8025 | } |
| 8026 | |
| 8027 | /** |
| 8028 | * Return the full height measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8029 | * 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] | 8030 | * as defined by {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. |
| 8031 | * This should be used during measurement and layout calculations only. Use |
| 8032 | * {@link #getHeight()} to see how wide a view is after layout. |
| 8033 | * |
| 8034 | * @return The measured width of this view as a bit mask. |
| 8035 | */ |
| 8036 | public final int getMeasuredHeightAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8037 | return mMeasuredHeight; |
| 8038 | } |
| 8039 | |
| 8040 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8041 | * Return only the state bits of {@link #getMeasuredWidthAndState()} |
| 8042 | * and {@link #getMeasuredHeightAndState()}, combined into one integer. |
| 8043 | * The width component is in the regular bits {@link #MEASURED_STATE_MASK} |
| 8044 | * and the height component is at the shifted bits |
| 8045 | * {@link #MEASURED_HEIGHT_STATE_SHIFT}>>{@link #MEASURED_STATE_MASK}. |
| 8046 | */ |
| 8047 | public final int getMeasuredState() { |
| 8048 | return (mMeasuredWidth&MEASURED_STATE_MASK) |
| 8049 | | ((mMeasuredHeight>>MEASURED_HEIGHT_STATE_SHIFT) |
| 8050 | & (MEASURED_STATE_MASK>>MEASURED_HEIGHT_STATE_SHIFT)); |
| 8051 | } |
| 8052 | |
| 8053 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8054 | * The transform matrix of this view, which is calculated based on the current |
| 8055 | * roation, scale, and pivot properties. |
| 8056 | * |
| 8057 | * @see #getRotation() |
| 8058 | * @see #getScaleX() |
| 8059 | * @see #getScaleY() |
| 8060 | * @see #getPivotX() |
| 8061 | * @see #getPivotY() |
| 8062 | * @return The current transform matrix for the view |
| 8063 | */ |
| 8064 | public Matrix getMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8065 | if (mTransformationInfo != null) { |
| 8066 | updateMatrix(); |
| 8067 | return mTransformationInfo.mMatrix; |
| 8068 | } |
| 8069 | return Matrix.IDENTITY_MATRIX; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8070 | } |
| 8071 | |
| 8072 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8073 | * Utility function to determine if the value is far enough away from zero to be |
| 8074 | * considered non-zero. |
| 8075 | * @param value A floating point value to check for zero-ness |
| 8076 | * @return whether the passed-in value is far enough away from zero to be considered non-zero |
| 8077 | */ |
| 8078 | private static boolean nonzero(float value) { |
| 8079 | return (value < -NONZERO_EPSILON || value > NONZERO_EPSILON); |
| 8080 | } |
| 8081 | |
| 8082 | /** |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8083 | * Returns true if the transform matrix is the identity matrix. |
| 8084 | * Recomputes the matrix if necessary. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8085 | * |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8086 | * @return True if the transform matrix is the identity matrix, false otherwise. |
| 8087 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8088 | final boolean hasIdentityMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8089 | if (mTransformationInfo != null) { |
| 8090 | updateMatrix(); |
| 8091 | return mTransformationInfo.mMatrixIsIdentity; |
| 8092 | } |
| 8093 | return true; |
| 8094 | } |
| 8095 | |
| 8096 | void ensureTransformationInfo() { |
| 8097 | if (mTransformationInfo == null) { |
| 8098 | mTransformationInfo = new TransformationInfo(); |
| 8099 | } |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8100 | } |
| 8101 | |
| 8102 | /** |
| 8103 | * Recomputes the transform matrix if necessary. |
| 8104 | */ |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8105 | private void updateMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8106 | final TransformationInfo info = mTransformationInfo; |
| 8107 | if (info == null) { |
| 8108 | return; |
| 8109 | } |
| 8110 | if (info.mMatrixDirty) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8111 | // transform-related properties have changed since the last time someone |
| 8112 | // asked for the matrix; recalculate it with the current values |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8113 | |
| 8114 | // Figure out if we need to update the pivot point |
| 8115 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8116 | if ((mRight - mLeft) != info.mPrevWidth || (mBottom - mTop) != info.mPrevHeight) { |
| 8117 | info.mPrevWidth = mRight - mLeft; |
| 8118 | info.mPrevHeight = mBottom - mTop; |
| 8119 | info.mPivotX = info.mPrevWidth / 2f; |
| 8120 | info.mPivotY = info.mPrevHeight / 2f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8121 | } |
| 8122 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8123 | info.mMatrix.reset(); |
| 8124 | if (!nonzero(info.mRotationX) && !nonzero(info.mRotationY)) { |
| 8125 | info.mMatrix.setTranslate(info.mTranslationX, info.mTranslationY); |
| 8126 | info.mMatrix.preRotate(info.mRotation, info.mPivotX, info.mPivotY); |
| 8127 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8128 | } else { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8129 | if (info.mCamera == null) { |
| 8130 | info.mCamera = new Camera(); |
| 8131 | info.matrix3D = new Matrix(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8132 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8133 | info.mCamera.save(); |
| 8134 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
| 8135 | info.mCamera.rotate(info.mRotationX, info.mRotationY, -info.mRotation); |
| 8136 | info.mCamera.getMatrix(info.matrix3D); |
| 8137 | info.matrix3D.preTranslate(-info.mPivotX, -info.mPivotY); |
| 8138 | info.matrix3D.postTranslate(info.mPivotX + info.mTranslationX, |
| 8139 | info.mPivotY + info.mTranslationY); |
| 8140 | info.mMatrix.postConcat(info.matrix3D); |
| 8141 | info.mCamera.restore(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8142 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8143 | info.mMatrixDirty = false; |
| 8144 | info.mMatrixIsIdentity = info.mMatrix.isIdentity(); |
| 8145 | info.mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8146 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8147 | } |
| 8148 | |
| 8149 | /** |
| 8150 | * Utility method to retrieve the inverse of the current mMatrix property. |
| 8151 | * We cache the matrix to avoid recalculating it when transform properties |
| 8152 | * have not changed. |
| 8153 | * |
| 8154 | * @return The inverse of the current matrix of this view. |
| 8155 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8156 | final Matrix getInverseMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8157 | final TransformationInfo info = mTransformationInfo; |
| 8158 | if (info != null) { |
| 8159 | updateMatrix(); |
| 8160 | if (info.mInverseMatrixDirty) { |
| 8161 | if (info.mInverseMatrix == null) { |
| 8162 | info.mInverseMatrix = new Matrix(); |
| 8163 | } |
| 8164 | info.mMatrix.invert(info.mInverseMatrix); |
| 8165 | info.mInverseMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8166 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8167 | return info.mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8168 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8169 | return Matrix.IDENTITY_MATRIX; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8170 | } |
| 8171 | |
| 8172 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8173 | * Gets the distance along the Z axis from the camera to this view. |
| 8174 | * |
| 8175 | * @see #setCameraDistance(float) |
| 8176 | * |
| 8177 | * @return The distance along the Z axis. |
| 8178 | */ |
| 8179 | public float getCameraDistance() { |
| 8180 | ensureTransformationInfo(); |
| 8181 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
| 8182 | final TransformationInfo info = mTransformationInfo; |
| 8183 | if (info.mCamera == null) { |
| 8184 | info.mCamera = new Camera(); |
| 8185 | info.matrix3D = new Matrix(); |
| 8186 | } |
| 8187 | return -(info.mCamera.getLocationZ() * dpi); |
| 8188 | } |
| 8189 | |
| 8190 | /** |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8191 | * <p>Sets the distance along the Z axis (orthogonal to the X/Y plane on which |
| 8192 | * views are drawn) from the camera to this view. The camera's distance |
| 8193 | * affects 3D transformations, for instance rotations around the X and Y |
| 8194 | * 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] | 8195 | * 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] | 8196 | * use a camera distance that's greater than the height (X axis rotation) or |
| 8197 | * the width (Y axis rotation) of this view.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8198 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8199 | * <p>The distance of the camera from the view plane can have an affect on the |
| 8200 | * perspective distortion of the view when it is rotated around the x or y axis. |
| 8201 | * For example, a large distance will result in a large viewing angle, and there |
| 8202 | * 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] | 8203 | * distance may cause much more perspective distortion upon rotation, and can |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8204 | * also result in some drawing artifacts if the rotated view ends up partially |
| 8205 | * behind the camera (which is why the recommendation is to use a distance at |
| 8206 | * 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] | 8207 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8208 | * <p>The distance is expressed in "depth pixels." The default distance depends |
| 8209 | * on the screen density. For instance, on a medium density display, the |
| 8210 | * default distance is 1280. On a high density display, the default distance |
| 8211 | * is 1920.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8212 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8213 | * <p>If you want to specify a distance that leads to visually consistent |
| 8214 | * results across various densities, use the following formula:</p> |
| 8215 | * <pre> |
| 8216 | * float scale = context.getResources().getDisplayMetrics().density; |
| 8217 | * view.setCameraDistance(distance * scale); |
| 8218 | * </pre> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8219 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8220 | * <p>The density scale factor of a high density display is 1.5, |
| 8221 | * and 1920 = 1280 * 1.5.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8222 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8223 | * @param distance The distance in "depth pixels", if negative the opposite |
| 8224 | * value is used |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8225 | * |
| 8226 | * @see #setRotationX(float) |
| 8227 | * @see #setRotationY(float) |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8228 | */ |
| 8229 | public void setCameraDistance(float distance) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8230 | invalidateViewProperty(true, false); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8231 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8232 | ensureTransformationInfo(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8233 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8234 | final TransformationInfo info = mTransformationInfo; |
| 8235 | if (info.mCamera == null) { |
| 8236 | info.mCamera = new Camera(); |
| 8237 | info.matrix3D = new Matrix(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8238 | } |
| 8239 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8240 | info.mCamera.setLocation(0.0f, 0.0f, -Math.abs(distance) / dpi); |
| 8241 | info.mMatrixDirty = true; |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8242 | |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8243 | invalidateViewProperty(false, false); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8244 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 8245 | mDisplayList.setCameraDistance(-Math.abs(distance) / dpi); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8246 | } |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8247 | } |
| 8248 | |
| 8249 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8250 | * The degrees that the view is rotated around the pivot point. |
| 8251 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8252 | * @see #setRotation(float) |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8253 | * @see #getPivotX() |
| 8254 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8255 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8256 | * @return The degrees of rotation. |
| 8257 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8258 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8259 | public float getRotation() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8260 | return mTransformationInfo != null ? mTransformationInfo.mRotation : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8261 | } |
| 8262 | |
| 8263 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8264 | * Sets the degrees that the view is rotated around the pivot point. Increasing values |
| 8265 | * result in clockwise rotation. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8266 | * |
| 8267 | * @param rotation The degrees of rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8268 | * |
| 8269 | * @see #getRotation() |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8270 | * @see #getPivotX() |
| 8271 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8272 | * @see #setRotationX(float) |
| 8273 | * @see #setRotationY(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8274 | * |
| 8275 | * @attr ref android.R.styleable#View_rotation |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8276 | */ |
| 8277 | public void setRotation(float rotation) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8278 | ensureTransformationInfo(); |
| 8279 | final TransformationInfo info = mTransformationInfo; |
| 8280 | if (info.mRotation != rotation) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8281 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8282 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8283 | info.mRotation = rotation; |
| 8284 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8285 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8286 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8287 | mDisplayList.setRotation(rotation); |
| 8288 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8289 | } |
| 8290 | } |
| 8291 | |
| 8292 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8293 | * The degrees that the view is rotated around the vertical axis through the pivot point. |
| 8294 | * |
| 8295 | * @see #getPivotX() |
| 8296 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8297 | * @see #setRotationY(float) |
| 8298 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8299 | * @return The degrees of Y rotation. |
| 8300 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8301 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8302 | public float getRotationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8303 | return mTransformationInfo != null ? mTransformationInfo.mRotationY : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8304 | } |
| 8305 | |
| 8306 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8307 | * Sets the degrees that the view is rotated around the vertical axis through the pivot point. |
| 8308 | * Increasing values result in counter-clockwise rotation from the viewpoint of looking |
| 8309 | * down the y axis. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8310 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8311 | * When rotating large views, it is recommended to adjust the camera distance |
| 8312 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8313 | * |
| 8314 | * @param rotationY The degrees of Y rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8315 | * |
| 8316 | * @see #getRotationY() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8317 | * @see #getPivotX() |
| 8318 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8319 | * @see #setRotation(float) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8320 | * @see #setRotationX(float) |
| 8321 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8322 | * |
| 8323 | * @attr ref android.R.styleable#View_rotationY |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8324 | */ |
| 8325 | public void setRotationY(float rotationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8326 | ensureTransformationInfo(); |
| 8327 | final TransformationInfo info = mTransformationInfo; |
| 8328 | if (info.mRotationY != rotationY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8329 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8330 | info.mRotationY = rotationY; |
| 8331 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8332 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8333 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8334 | mDisplayList.setRotationY(rotationY); |
| 8335 | } |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8336 | } |
| 8337 | } |
| 8338 | |
| 8339 | /** |
| 8340 | * The degrees that the view is rotated around the horizontal axis through the pivot point. |
| 8341 | * |
| 8342 | * @see #getPivotX() |
| 8343 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8344 | * @see #setRotationX(float) |
| 8345 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8346 | * @return The degrees of X rotation. |
| 8347 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8348 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8349 | public float getRotationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8350 | return mTransformationInfo != null ? mTransformationInfo.mRotationX : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8351 | } |
| 8352 | |
| 8353 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8354 | * Sets the degrees that the view is rotated around the horizontal axis through the pivot point. |
| 8355 | * Increasing values result in clockwise rotation from the viewpoint of looking down the |
| 8356 | * x axis. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8357 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8358 | * When rotating large views, it is recommended to adjust the camera distance |
| 8359 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8360 | * |
| 8361 | * @param rotationX The degrees of X rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8362 | * |
| 8363 | * @see #getRotationX() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8364 | * @see #getPivotX() |
| 8365 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8366 | * @see #setRotation(float) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8367 | * @see #setRotationY(float) |
| 8368 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8369 | * |
| 8370 | * @attr ref android.R.styleable#View_rotationX |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8371 | */ |
| 8372 | public void setRotationX(float rotationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8373 | ensureTransformationInfo(); |
| 8374 | final TransformationInfo info = mTransformationInfo; |
| 8375 | if (info.mRotationX != rotationX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8376 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8377 | info.mRotationX = rotationX; |
| 8378 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8379 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8380 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8381 | mDisplayList.setRotationX(rotationX); |
| 8382 | } |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8383 | } |
| 8384 | } |
| 8385 | |
| 8386 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8387 | * The amount that the view is scaled in x around the pivot point, as a proportion of |
| 8388 | * the view's unscaled width. A value of 1, the default, means that no scaling is applied. |
| 8389 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 8390 | * <p>By default, this is 1.0f. |
| 8391 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8392 | * @see #getPivotX() |
| 8393 | * @see #getPivotY() |
| 8394 | * @return The scaling factor. |
| 8395 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8396 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8397 | public float getScaleX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8398 | return mTransformationInfo != null ? mTransformationInfo.mScaleX : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8399 | } |
| 8400 | |
| 8401 | /** |
| 8402 | * Sets the amount that the view is scaled in x around the pivot point, as a proportion of |
| 8403 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 8404 | * |
| 8405 | * @param scaleX The scaling factor. |
| 8406 | * @see #getPivotX() |
| 8407 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8408 | * |
| 8409 | * @attr ref android.R.styleable#View_scaleX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8410 | */ |
| 8411 | public void setScaleX(float scaleX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8412 | ensureTransformationInfo(); |
| 8413 | final TransformationInfo info = mTransformationInfo; |
| 8414 | if (info.mScaleX != scaleX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8415 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8416 | info.mScaleX = scaleX; |
| 8417 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8418 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8419 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8420 | mDisplayList.setScaleX(scaleX); |
| 8421 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8422 | } |
| 8423 | } |
| 8424 | |
| 8425 | /** |
| 8426 | * The amount that the view is scaled in y around the pivot point, as a proportion of |
| 8427 | * the view's unscaled height. A value of 1, the default, means that no scaling is applied. |
| 8428 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 8429 | * <p>By default, this is 1.0f. |
| 8430 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8431 | * @see #getPivotX() |
| 8432 | * @see #getPivotY() |
| 8433 | * @return The scaling factor. |
| 8434 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8435 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8436 | public float getScaleY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8437 | return mTransformationInfo != null ? mTransformationInfo.mScaleY : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8438 | } |
| 8439 | |
| 8440 | /** |
| 8441 | * Sets the amount that the view is scaled in Y around the pivot point, as a proportion of |
| 8442 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 8443 | * |
| 8444 | * @param scaleY The scaling factor. |
| 8445 | * @see #getPivotX() |
| 8446 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8447 | * |
| 8448 | * @attr ref android.R.styleable#View_scaleY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8449 | */ |
| 8450 | public void setScaleY(float scaleY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8451 | ensureTransformationInfo(); |
| 8452 | final TransformationInfo info = mTransformationInfo; |
| 8453 | if (info.mScaleY != scaleY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8454 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8455 | info.mScaleY = scaleY; |
| 8456 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8457 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8458 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8459 | mDisplayList.setScaleY(scaleY); |
| 8460 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8461 | } |
| 8462 | } |
| 8463 | |
| 8464 | /** |
| 8465 | * The x location of the point around which the view is {@link #setRotation(float) rotated} |
| 8466 | * and {@link #setScaleX(float) scaled}. |
| 8467 | * |
| 8468 | * @see #getRotation() |
| 8469 | * @see #getScaleX() |
| 8470 | * @see #getScaleY() |
| 8471 | * @see #getPivotY() |
| 8472 | * @return The x location of the pivot point. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8473 | * |
| 8474 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8475 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8476 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8477 | public float getPivotX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8478 | return mTransformationInfo != null ? mTransformationInfo.mPivotX : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8479 | } |
| 8480 | |
| 8481 | /** |
| 8482 | * Sets the x location of the point around which the view is |
| 8483 | * {@link #setRotation(float) rotated} and {@link #setScaleX(float) scaled}. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8484 | * By default, the pivot point is centered on the object. |
| 8485 | * Setting this property disables this behavior and causes the view to use only the |
| 8486 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8487 | * |
| 8488 | * @param pivotX The x location of the pivot point. |
| 8489 | * @see #getRotation() |
| 8490 | * @see #getScaleX() |
| 8491 | * @see #getScaleY() |
| 8492 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8493 | * |
| 8494 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8495 | */ |
| 8496 | public void setPivotX(float pivotX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8497 | ensureTransformationInfo(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8498 | mPrivateFlags |= PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8499 | final TransformationInfo info = mTransformationInfo; |
| 8500 | if (info.mPivotX != pivotX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8501 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8502 | info.mPivotX = pivotX; |
| 8503 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8504 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8505 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8506 | mDisplayList.setPivotX(pivotX); |
| 8507 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8508 | } |
| 8509 | } |
| 8510 | |
| 8511 | /** |
| 8512 | * The y location of the point around which the view is {@link #setRotation(float) rotated} |
| 8513 | * and {@link #setScaleY(float) scaled}. |
| 8514 | * |
| 8515 | * @see #getRotation() |
| 8516 | * @see #getScaleX() |
| 8517 | * @see #getScaleY() |
| 8518 | * @see #getPivotY() |
| 8519 | * @return The y location of the pivot point. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8520 | * |
| 8521 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8522 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8523 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8524 | public float getPivotY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8525 | return mTransformationInfo != null ? mTransformationInfo.mPivotY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8526 | } |
| 8527 | |
| 8528 | /** |
| 8529 | * 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] | 8530 | * and {@link #setScaleY(float) scaled}. By default, the pivot point is centered on the object. |
| 8531 | * Setting this property disables this behavior and causes the view to use only the |
| 8532 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8533 | * |
| 8534 | * @param pivotY The y location of the pivot point. |
| 8535 | * @see #getRotation() |
| 8536 | * @see #getScaleX() |
| 8537 | * @see #getScaleY() |
| 8538 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8539 | * |
| 8540 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8541 | */ |
| 8542 | public void setPivotY(float pivotY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8543 | ensureTransformationInfo(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8544 | mPrivateFlags |= PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8545 | final TransformationInfo info = mTransformationInfo; |
| 8546 | if (info.mPivotY != pivotY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8547 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8548 | info.mPivotY = pivotY; |
| 8549 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8550 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8551 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8552 | mDisplayList.setPivotY(pivotY); |
| 8553 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8554 | } |
| 8555 | } |
| 8556 | |
| 8557 | /** |
| 8558 | * The opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 8559 | * completely transparent and 1 means the view is completely opaque. |
| 8560 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 8561 | * <p>By default this is 1.0f. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8562 | * @return The opacity of the view. |
| 8563 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8564 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8565 | public float getAlpha() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8566 | return mTransformationInfo != null ? mTransformationInfo.mAlpha : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8567 | } |
| 8568 | |
| 8569 | /** |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 8570 | * Returns whether this View has content which overlaps. This function, intended to be |
| 8571 | * overridden by specific View types, is an optimization when alpha is set on a view. If |
| 8572 | * rendering overlaps in a view with alpha < 1, that view is drawn to an offscreen buffer |
| 8573 | * and then composited it into place, which can be expensive. If the view has no overlapping |
| 8574 | * rendering, the view can draw each primitive with the appropriate alpha value directly. |
| 8575 | * An example of overlapping rendering is a TextView with a background image, such as a |
| 8576 | * Button. An example of non-overlapping rendering is a TextView with no background, or |
| 8577 | * an ImageView with only the foreground image. The default implementation returns true; |
| 8578 | * subclasses should override if they have cases which can be optimized. |
| 8579 | * |
| 8580 | * @return true if the content in this view might overlap, false otherwise. |
| 8581 | */ |
| 8582 | public boolean hasOverlappingRendering() { |
| 8583 | return true; |
| 8584 | } |
| 8585 | |
| 8586 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 8587 | * <p>Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 8588 | * completely transparent and 1 means the view is completely opaque.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8589 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 8590 | * <p>If this view overrides {@link #onSetAlpha(int)} to return true, then this view is |
| 8591 | * responsible for applying the opacity itself. Otherwise, calling this method is |
| 8592 | * equivalent to calling {@link #setLayerType(int, android.graphics.Paint)} and |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8593 | * setting a hardware layer.</p> |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8594 | * |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8595 | * <p>Note that setting alpha to a translucent value (0 < alpha < 1) may have |
| 8596 | * performance implications. It is generally best to use the alpha property sparingly and |
| 8597 | * transiently, as in the case of fading animations.</p> |
| 8598 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8599 | * @param alpha The opacity of the view. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8600 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8601 | * @see #setLayerType(int, android.graphics.Paint) |
| 8602 | * |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8603 | * @attr ref android.R.styleable#View_alpha |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8604 | */ |
| 8605 | public void setAlpha(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8606 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8607 | if (mTransformationInfo.mAlpha != alpha) { |
| 8608 | mTransformationInfo.mAlpha = alpha; |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8609 | if (onSetAlpha((int) (alpha * 255))) { |
| 8610 | mPrivateFlags |= ALPHA_SET; |
| 8611 | // subclass is handling alpha - don't optimize rendering cache invalidation |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8612 | invalidateParentCaches(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8613 | invalidate(true); |
| 8614 | } else { |
| 8615 | mPrivateFlags &= ~ALPHA_SET; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8616 | invalidateViewProperty(true, false); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8617 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8618 | mDisplayList.setAlpha(alpha); |
| 8619 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8620 | } |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8621 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8622 | } |
| 8623 | |
| 8624 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 8625 | * Faster version of setAlpha() which performs the same steps except there are |
| 8626 | * no calls to invalidate(). The caller of this function should perform proper invalidation |
| 8627 | * on the parent and this object. The return value indicates whether the subclass handles |
| 8628 | * alpha (the return value for onSetAlpha()). |
| 8629 | * |
| 8630 | * @param alpha The new value for the alpha property |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8631 | * @return true if the View subclass handles alpha (the return value for onSetAlpha()) and |
| 8632 | * 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] | 8633 | */ |
| 8634 | boolean setAlphaNoInvalidation(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8635 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8636 | if (mTransformationInfo.mAlpha != alpha) { |
| 8637 | mTransformationInfo.mAlpha = alpha; |
| 8638 | boolean subclassHandlesAlpha = onSetAlpha((int) (alpha * 255)); |
| 8639 | if (subclassHandlesAlpha) { |
| 8640 | mPrivateFlags |= ALPHA_SET; |
| 8641 | return true; |
| 8642 | } else { |
| 8643 | mPrivateFlags &= ~ALPHA_SET; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8644 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8645 | mDisplayList.setAlpha(alpha); |
| 8646 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8647 | } |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 8648 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8649 | return false; |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 8650 | } |
| 8651 | |
| 8652 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8653 | * Top position of this view relative to its parent. |
| 8654 | * |
| 8655 | * @return The top of this view, in pixels. |
| 8656 | */ |
| 8657 | @ViewDebug.CapturedViewProperty |
| 8658 | public final int getTop() { |
| 8659 | return mTop; |
| 8660 | } |
| 8661 | |
| 8662 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8663 | * Sets the top position of this view relative to its parent. This method is meant to be called |
| 8664 | * by the layout system and should not generally be called otherwise, because the property |
| 8665 | * may be changed at any time by the layout. |
| 8666 | * |
| 8667 | * @param top The top of this view, in pixels. |
| 8668 | */ |
| 8669 | public final void setTop(int top) { |
| 8670 | if (top != mTop) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8671 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8672 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8673 | || mTransformationInfo.mMatrixIsIdentity; |
| 8674 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8675 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8676 | int minTop; |
| 8677 | int yLoc; |
| 8678 | if (top < mTop) { |
| 8679 | minTop = top; |
| 8680 | yLoc = top - mTop; |
| 8681 | } else { |
| 8682 | minTop = mTop; |
| 8683 | yLoc = 0; |
| 8684 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8685 | invalidate(0, yLoc, mRight - mLeft, mBottom - minTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8686 | } |
| 8687 | } else { |
| 8688 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8689 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8690 | } |
| 8691 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8692 | int width = mRight - mLeft; |
| 8693 | int oldHeight = mBottom - mTop; |
| 8694 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8695 | mTop = top; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8696 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8697 | mDisplayList.setTop(mTop); |
| 8698 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8699 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8700 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 8701 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8702 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8703 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 8704 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8705 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8706 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8707 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8708 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8709 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 8710 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8711 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8712 | } |
| 8713 | } |
| 8714 | |
| 8715 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8716 | * Bottom position of this view relative to its parent. |
| 8717 | * |
| 8718 | * @return The bottom of this view, in pixels. |
| 8719 | */ |
| 8720 | @ViewDebug.CapturedViewProperty |
| 8721 | public final int getBottom() { |
| 8722 | return mBottom; |
| 8723 | } |
| 8724 | |
| 8725 | /** |
Michael Jurka | dab559a | 2011-01-04 20:31:51 -0800 | [diff] [blame] | 8726 | * True if this view has changed since the last time being drawn. |
| 8727 | * |
| 8728 | * @return The dirty state of this view. |
| 8729 | */ |
| 8730 | public boolean isDirty() { |
| 8731 | return (mPrivateFlags & DIRTY_MASK) != 0; |
| 8732 | } |
| 8733 | |
| 8734 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8735 | * Sets the bottom position of this view relative to its parent. This method is meant to be |
| 8736 | * called by the layout system and should not generally be called otherwise, because the |
| 8737 | * property may be changed at any time by the layout. |
| 8738 | * |
| 8739 | * @param bottom The bottom of this view, in pixels. |
| 8740 | */ |
| 8741 | public final void setBottom(int bottom) { |
| 8742 | if (bottom != mBottom) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8743 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8744 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8745 | || mTransformationInfo.mMatrixIsIdentity; |
| 8746 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8747 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8748 | int maxBottom; |
| 8749 | if (bottom < mBottom) { |
| 8750 | maxBottom = mBottom; |
| 8751 | } else { |
| 8752 | maxBottom = bottom; |
| 8753 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8754 | invalidate(0, 0, mRight - mLeft, maxBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8755 | } |
| 8756 | } else { |
| 8757 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8758 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8759 | } |
| 8760 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8761 | int width = mRight - mLeft; |
| 8762 | int oldHeight = mBottom - mTop; |
| 8763 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8764 | mBottom = bottom; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8765 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8766 | mDisplayList.setBottom(mBottom); |
| 8767 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8768 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8769 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 8770 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8771 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8772 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 8773 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8774 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8775 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8776 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8777 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8778 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 8779 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8780 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8781 | } |
| 8782 | } |
| 8783 | |
| 8784 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8785 | * Left position of this view relative to its parent. |
| 8786 | * |
| 8787 | * @return The left edge of this view, in pixels. |
| 8788 | */ |
| 8789 | @ViewDebug.CapturedViewProperty |
| 8790 | public final int getLeft() { |
| 8791 | return mLeft; |
| 8792 | } |
| 8793 | |
| 8794 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8795 | * Sets the left position of this view relative to its parent. This method is meant to be called |
| 8796 | * by the layout system and should not generally be called otherwise, because the property |
| 8797 | * may be changed at any time by the layout. |
| 8798 | * |
| 8799 | * @param left The bottom of this view, in pixels. |
| 8800 | */ |
| 8801 | public final void setLeft(int left) { |
| 8802 | if (left != mLeft) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8803 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8804 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8805 | || mTransformationInfo.mMatrixIsIdentity; |
| 8806 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8807 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8808 | int minLeft; |
| 8809 | int xLoc; |
| 8810 | if (left < mLeft) { |
| 8811 | minLeft = left; |
| 8812 | xLoc = left - mLeft; |
| 8813 | } else { |
| 8814 | minLeft = mLeft; |
| 8815 | xLoc = 0; |
| 8816 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8817 | invalidate(xLoc, 0, mRight - minLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8818 | } |
| 8819 | } else { |
| 8820 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8821 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8822 | } |
| 8823 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8824 | int oldWidth = mRight - mLeft; |
| 8825 | int height = mBottom - mTop; |
| 8826 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8827 | mLeft = left; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8828 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8829 | mDisplayList.setLeft(left); |
| 8830 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8831 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8832 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 8833 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8834 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8835 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 8836 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8837 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8838 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8839 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8840 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8841 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 8842 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8843 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8844 | if (USE_DISPLAY_LIST_PROPERTIES) { |
| 8845 | |
| 8846 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8847 | } |
| 8848 | } |
| 8849 | |
| 8850 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8851 | * Right position of this view relative to its parent. |
| 8852 | * |
| 8853 | * @return The right edge of this view, in pixels. |
| 8854 | */ |
| 8855 | @ViewDebug.CapturedViewProperty |
| 8856 | public final int getRight() { |
| 8857 | return mRight; |
| 8858 | } |
| 8859 | |
| 8860 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8861 | * Sets the right position of this view relative to its parent. This method is meant to be called |
| 8862 | * by the layout system and should not generally be called otherwise, because the property |
| 8863 | * may be changed at any time by the layout. |
| 8864 | * |
| 8865 | * @param right The bottom of this view, in pixels. |
| 8866 | */ |
| 8867 | public final void setRight(int right) { |
| 8868 | if (right != mRight) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8869 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8870 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8871 | || mTransformationInfo.mMatrixIsIdentity; |
| 8872 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8873 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8874 | int maxRight; |
| 8875 | if (right < mRight) { |
| 8876 | maxRight = mRight; |
| 8877 | } else { |
| 8878 | maxRight = right; |
| 8879 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8880 | invalidate(0, 0, maxRight - mLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8881 | } |
| 8882 | } else { |
| 8883 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8884 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8885 | } |
| 8886 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8887 | int oldWidth = mRight - mLeft; |
| 8888 | int height = mBottom - mTop; |
| 8889 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8890 | mRight = right; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8891 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8892 | mDisplayList.setRight(mRight); |
| 8893 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8894 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8895 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 8896 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8897 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8898 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 8899 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8900 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8901 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8902 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8903 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8904 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 8905 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8906 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8907 | } |
| 8908 | } |
| 8909 | |
| 8910 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8911 | * The visual x position of this view, in pixels. This is equivalent to the |
| 8912 | * {@link #setTranslationX(float) translationX} property plus the current |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8913 | * {@link #getLeft() left} property. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8914 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8915 | * @return The visual x position of this view, in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8916 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8917 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8918 | public float getX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8919 | return mLeft + (mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8920 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8921 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8922 | /** |
| 8923 | * Sets the visual x position of this view, in pixels. This is equivalent to setting the |
| 8924 | * {@link #setTranslationX(float) translationX} property to be the difference between |
| 8925 | * the x value passed in and the current {@link #getLeft() left} property. |
| 8926 | * |
| 8927 | * @param x The visual x position of this view, in pixels. |
| 8928 | */ |
| 8929 | public void setX(float x) { |
| 8930 | setTranslationX(x - mLeft); |
| 8931 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8932 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8933 | /** |
| 8934 | * The visual y position of this view, in pixels. This is equivalent to the |
| 8935 | * {@link #setTranslationY(float) translationY} property plus the current |
| 8936 | * {@link #getTop() top} property. |
| 8937 | * |
| 8938 | * @return The visual y position of this view, in pixels. |
| 8939 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8940 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8941 | public float getY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8942 | return mTop + (mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8943 | } |
| 8944 | |
| 8945 | /** |
| 8946 | * Sets the visual y position of this view, in pixels. This is equivalent to setting the |
| 8947 | * {@link #setTranslationY(float) translationY} property to be the difference between |
| 8948 | * the y value passed in and the current {@link #getTop() top} property. |
| 8949 | * |
| 8950 | * @param y The visual y position of this view, in pixels. |
| 8951 | */ |
| 8952 | public void setY(float y) { |
| 8953 | setTranslationY(y - mTop); |
| 8954 | } |
| 8955 | |
| 8956 | |
| 8957 | /** |
| 8958 | * The horizontal location of this view relative to its {@link #getLeft() left} position. |
| 8959 | * This position is post-layout, in addition to wherever the object's |
| 8960 | * layout placed it. |
| 8961 | * |
| 8962 | * @return The horizontal position of this view relative to its left position, in pixels. |
| 8963 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8964 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8965 | public float getTranslationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8966 | return mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0; |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8967 | } |
| 8968 | |
| 8969 | /** |
| 8970 | * Sets the horizontal location of this view relative to its {@link #getLeft() left} position. |
| 8971 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 8972 | * layout placed it. |
| 8973 | * |
| 8974 | * @param translationX The horizontal position of this view relative to its left position, |
| 8975 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8976 | * |
| 8977 | * @attr ref android.R.styleable#View_translationX |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8978 | */ |
| 8979 | public void setTranslationX(float translationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8980 | ensureTransformationInfo(); |
| 8981 | final TransformationInfo info = mTransformationInfo; |
| 8982 | if (info.mTranslationX != translationX) { |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8983 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8984 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8985 | info.mTranslationX = translationX; |
| 8986 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8987 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8988 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 8989 | mDisplayList.setTranslationX(translationX); |
| 8990 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8991 | } |
| 8992 | } |
| 8993 | |
| 8994 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8995 | * The horizontal location of this view relative to its {@link #getTop() top} position. |
| 8996 | * This position is post-layout, in addition to wherever the object's |
| 8997 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8998 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8999 | * @return The vertical position of this view relative to its top position, |
| 9000 | * in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9001 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9002 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9003 | public float getTranslationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9004 | return mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9005 | } |
| 9006 | |
| 9007 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9008 | * Sets the vertical location of this view relative to its {@link #getTop() top} position. |
| 9009 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 9010 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9011 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9012 | * @param translationY The vertical position of this view relative to its top position, |
| 9013 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9014 | * |
| 9015 | * @attr ref android.R.styleable#View_translationY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9016 | */ |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9017 | public void setTranslationY(float translationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9018 | ensureTransformationInfo(); |
| 9019 | final TransformationInfo info = mTransformationInfo; |
| 9020 | if (info.mTranslationY != translationY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9021 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9022 | info.mTranslationY = translationY; |
| 9023 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9024 | invalidateViewProperty(false, true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9025 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 9026 | mDisplayList.setTranslationY(translationY); |
| 9027 | } |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9028 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9029 | } |
| 9030 | |
| 9031 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9032 | * Hit rectangle in parent's coordinates |
| 9033 | * |
| 9034 | * @param outRect The hit rectangle of the view. |
| 9035 | */ |
| 9036 | public void getHitRect(Rect outRect) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9037 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9038 | final TransformationInfo info = mTransformationInfo; |
| 9039 | if (info == null || info.mMatrixIsIdentity || mAttachInfo == null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9040 | outRect.set(mLeft, mTop, mRight, mBottom); |
| 9041 | } else { |
| 9042 | final RectF tmpRect = mAttachInfo.mTmpTransformRect; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9043 | tmpRect.set(-info.mPivotX, -info.mPivotY, |
| 9044 | getWidth() - info.mPivotX, getHeight() - info.mPivotY); |
| 9045 | info.mMatrix.mapRect(tmpRect); |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9046 | outRect.set((int) tmpRect.left + mLeft, (int) tmpRect.top + mTop, |
| 9047 | (int) tmpRect.right + mLeft, (int) tmpRect.bottom + mTop); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9048 | } |
| 9049 | } |
| 9050 | |
| 9051 | /** |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 9052 | * Determines whether the given point, in local coordinates is inside the view. |
| 9053 | */ |
| 9054 | /*package*/ final boolean pointInView(float localX, float localY) { |
| 9055 | return localX >= 0 && localX < (mRight - mLeft) |
| 9056 | && localY >= 0 && localY < (mBottom - mTop); |
| 9057 | } |
| 9058 | |
| 9059 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9060 | * Utility method to determine whether the given point, in local coordinates, |
| 9061 | * is inside the view, where the area of the view is expanded by the slop factor. |
| 9062 | * This method is called while processing touch-move events to determine if the event |
| 9063 | * is still within the view. |
| 9064 | */ |
| 9065 | private boolean pointInView(float localX, float localY, float slop) { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 9066 | return localX >= -slop && localY >= -slop && localX < ((mRight - mLeft) + slop) && |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9067 | localY < ((mBottom - mTop) + slop); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9068 | } |
| 9069 | |
| 9070 | /** |
| 9071 | * When a view has focus and the user navigates away from it, the next view is searched for |
| 9072 | * starting from the rectangle filled in by this method. |
| 9073 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9074 | * By default, the rectange is the {@link #getDrawingRect(android.graphics.Rect)}) |
| 9075 | * of the view. However, if your view maintains some idea of internal selection, |
| 9076 | * such as a cursor, or a selected row or column, you should override this method and |
| 9077 | * fill in a more specific rectangle. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9078 | * |
| 9079 | * @param r The rectangle to fill in, in this view's coordinates. |
| 9080 | */ |
| 9081 | public void getFocusedRect(Rect r) { |
| 9082 | getDrawingRect(r); |
| 9083 | } |
| 9084 | |
| 9085 | /** |
| 9086 | * If some part of this view is not clipped by any of its parents, then |
| 9087 | * 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] | 9088 | * coordinates (without taking possible View rotations into account), offset |
| 9089 | * it by -globalOffset (e.g. r.offset(-globalOffset.x, -globalOffset.y)). |
| 9090 | * 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] | 9091 | * |
| 9092 | * @param r If true is returned, r holds the global coordinates of the |
| 9093 | * visible portion of this view. |
| 9094 | * @param globalOffset If true is returned, globalOffset holds the dx,dy |
| 9095 | * between this view and its root. globalOffet may be null. |
| 9096 | * @return true if r is non-empty (i.e. part of the view is visible at the |
| 9097 | * root level. |
| 9098 | */ |
| 9099 | public boolean getGlobalVisibleRect(Rect r, Point globalOffset) { |
| 9100 | int width = mRight - mLeft; |
| 9101 | int height = mBottom - mTop; |
| 9102 | if (width > 0 && height > 0) { |
| 9103 | r.set(0, 0, width, height); |
| 9104 | if (globalOffset != null) { |
| 9105 | globalOffset.set(-mScrollX, -mScrollY); |
| 9106 | } |
| 9107 | return mParent == null || mParent.getChildVisibleRect(this, r, globalOffset); |
| 9108 | } |
| 9109 | return false; |
| 9110 | } |
| 9111 | |
| 9112 | public final boolean getGlobalVisibleRect(Rect r) { |
| 9113 | return getGlobalVisibleRect(r, null); |
| 9114 | } |
| 9115 | |
| 9116 | public final boolean getLocalVisibleRect(Rect r) { |
| 9117 | Point offset = new Point(); |
| 9118 | if (getGlobalVisibleRect(r, offset)) { |
| 9119 | r.offset(-offset.x, -offset.y); // make r local |
| 9120 | return true; |
| 9121 | } |
| 9122 | return false; |
| 9123 | } |
| 9124 | |
| 9125 | /** |
| 9126 | * Offset this view's vertical location by the specified number of pixels. |
| 9127 | * |
| 9128 | * @param offset the number of pixels to offset the view by |
| 9129 | */ |
| 9130 | public void offsetTopAndBottom(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9131 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9132 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9133 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9134 | || mTransformationInfo.mMatrixIsIdentity; |
| 9135 | if (matrixIsIdentity) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9136 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 9137 | invalidateViewProperty(false, false); |
| 9138 | } else { |
| 9139 | final ViewParent p = mParent; |
| 9140 | if (p != null && mAttachInfo != null) { |
| 9141 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 9142 | int minTop; |
| 9143 | int maxBottom; |
| 9144 | int yLoc; |
| 9145 | if (offset < 0) { |
| 9146 | minTop = mTop + offset; |
| 9147 | maxBottom = mBottom; |
| 9148 | yLoc = offset; |
| 9149 | } else { |
| 9150 | minTop = mTop; |
| 9151 | maxBottom = mBottom + offset; |
| 9152 | yLoc = 0; |
| 9153 | } |
| 9154 | r.set(0, yLoc, mRight - mLeft, maxBottom - minTop); |
| 9155 | p.invalidateChild(this, r); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 9156 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9157 | } |
| 9158 | } else { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9159 | invalidateViewProperty(false, false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9160 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9161 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9162 | mTop += offset; |
| 9163 | mBottom += offset; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9164 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 9165 | mDisplayList.offsetTopBottom(offset); |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9166 | invalidateViewProperty(false, false); |
| 9167 | } else { |
| 9168 | if (!matrixIsIdentity) { |
| 9169 | invalidateViewProperty(false, true); |
| 9170 | } |
| 9171 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9172 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9173 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9174 | } |
| 9175 | |
| 9176 | /** |
| 9177 | * Offset this view's horizontal location by the specified amount of pixels. |
| 9178 | * |
| 9179 | * @param offset the numer of pixels to offset the view by |
| 9180 | */ |
| 9181 | public void offsetLeftAndRight(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9182 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9183 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9184 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9185 | || mTransformationInfo.mMatrixIsIdentity; |
| 9186 | if (matrixIsIdentity) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9187 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 9188 | invalidateViewProperty(false, false); |
| 9189 | } else { |
| 9190 | final ViewParent p = mParent; |
| 9191 | if (p != null && mAttachInfo != null) { |
| 9192 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 9193 | int minLeft; |
| 9194 | int maxRight; |
| 9195 | if (offset < 0) { |
| 9196 | minLeft = mLeft + offset; |
| 9197 | maxRight = mRight; |
| 9198 | } else { |
| 9199 | minLeft = mLeft; |
| 9200 | maxRight = mRight + offset; |
| 9201 | } |
| 9202 | r.set(0, 0, maxRight - minLeft, mBottom - mTop); |
| 9203 | p.invalidateChild(this, r); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 9204 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9205 | } |
| 9206 | } else { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9207 | invalidateViewProperty(false, false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9208 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9209 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9210 | mLeft += offset; |
| 9211 | mRight += offset; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9212 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 9213 | mDisplayList.offsetLeftRight(offset); |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9214 | invalidateViewProperty(false, false); |
| 9215 | } else { |
| 9216 | if (!matrixIsIdentity) { |
| 9217 | invalidateViewProperty(false, true); |
| 9218 | } |
| 9219 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9220 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9221 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9222 | } |
| 9223 | |
| 9224 | /** |
| 9225 | * Get the LayoutParams associated with this view. All views should have |
| 9226 | * layout parameters. These supply parameters to the <i>parent</i> of this |
| 9227 | * view specifying how it should be arranged. There are many subclasses of |
| 9228 | * ViewGroup.LayoutParams, and these correspond to the different subclasses |
| 9229 | * of ViewGroup that are responsible for arranging their children. |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 9230 | * |
| 9231 | * This method may return null if this View is not attached to a parent |
| 9232 | * ViewGroup or {@link #setLayoutParams(android.view.ViewGroup.LayoutParams)} |
| 9233 | * was not invoked successfully. When a View is attached to a parent |
| 9234 | * ViewGroup, this method must not return null. |
| 9235 | * |
| 9236 | * @return The LayoutParams associated with this view, or null if no |
| 9237 | * parameters have been set yet |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9238 | */ |
Konstantin Lopyrev | 91a7f5f | 2010-08-10 18:54:54 -0700 | [diff] [blame] | 9239 | @ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9240 | public ViewGroup.LayoutParams getLayoutParams() { |
| 9241 | return mLayoutParams; |
| 9242 | } |
| 9243 | |
| 9244 | /** |
| 9245 | * Set the layout parameters associated with this view. These supply |
| 9246 | * parameters to the <i>parent</i> of this view specifying how it should be |
| 9247 | * arranged. There are many subclasses of ViewGroup.LayoutParams, and these |
| 9248 | * correspond to the different subclasses of ViewGroup that are responsible |
| 9249 | * for arranging their children. |
| 9250 | * |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 9251 | * @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] | 9252 | */ |
| 9253 | public void setLayoutParams(ViewGroup.LayoutParams params) { |
| 9254 | if (params == null) { |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 9255 | throw new NullPointerException("Layout parameters cannot be null"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9256 | } |
| 9257 | mLayoutParams = params; |
Philip Milne | d7dd890 | 2012-01-26 16:55:30 -0800 | [diff] [blame] | 9258 | if (mParent instanceof ViewGroup) { |
| 9259 | ((ViewGroup) mParent).onSetLayoutParams(this, params); |
| 9260 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9261 | requestLayout(); |
| 9262 | } |
| 9263 | |
| 9264 | /** |
| 9265 | * Set the scrolled position of your view. This will cause a call to |
| 9266 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 9267 | * invalidated. |
| 9268 | * @param x the x position to scroll to |
| 9269 | * @param y the y position to scroll to |
| 9270 | */ |
| 9271 | public void scrollTo(int x, int y) { |
| 9272 | if (mScrollX != x || mScrollY != y) { |
| 9273 | int oldX = mScrollX; |
| 9274 | int oldY = mScrollY; |
| 9275 | mScrollX = x; |
| 9276 | mScrollY = y; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9277 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9278 | onScrollChanged(mScrollX, mScrollY, oldX, oldY); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9279 | if (!awakenScrollBars()) { |
Adam Powell | df3ae4f | 2012-04-10 18:55:22 -0700 | [diff] [blame] | 9280 | postInvalidateOnAnimation(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9281 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9282 | } |
| 9283 | } |
| 9284 | |
| 9285 | /** |
| 9286 | * Move the scrolled position of your view. This will cause a call to |
| 9287 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 9288 | * invalidated. |
| 9289 | * @param x the amount of pixels to scroll by horizontally |
| 9290 | * @param y the amount of pixels to scroll by vertically |
| 9291 | */ |
| 9292 | public void scrollBy(int x, int y) { |
| 9293 | scrollTo(mScrollX + x, mScrollY + y); |
| 9294 | } |
| 9295 | |
| 9296 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9297 | * <p>Trigger the scrollbars to draw. When invoked this method starts an |
| 9298 | * animation to fade the scrollbars out after a default delay. If a subclass |
| 9299 | * provides animated scrolling, the start delay should equal the duration |
| 9300 | * of the scrolling animation.</p> |
| 9301 | * |
| 9302 | * <p>The animation starts only if at least one of the scrollbars is |
| 9303 | * enabled, as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 9304 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 9305 | * this method returns true, and false otherwise. If the animation is |
| 9306 | * started, this method calls {@link #invalidate()}; in that case the |
| 9307 | * caller should not call {@link #invalidate()}.</p> |
| 9308 | * |
| 9309 | * <p>This method should be invoked every time a subclass directly updates |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9310 | * the scroll parameters.</p> |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9311 | * |
| 9312 | * <p>This method is automatically invoked by {@link #scrollBy(int, int)} |
| 9313 | * and {@link #scrollTo(int, int)}.</p> |
| 9314 | * |
| 9315 | * @return true if the animation is played, false otherwise |
| 9316 | * |
| 9317 | * @see #awakenScrollBars(int) |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9318 | * @see #scrollBy(int, int) |
| 9319 | * @see #scrollTo(int, int) |
| 9320 | * @see #isHorizontalScrollBarEnabled() |
| 9321 | * @see #isVerticalScrollBarEnabled() |
| 9322 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 9323 | * @see #setVerticalScrollBarEnabled(boolean) |
| 9324 | */ |
| 9325 | protected boolean awakenScrollBars() { |
| 9326 | return mScrollCache != null && |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9327 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade, true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9328 | } |
| 9329 | |
| 9330 | /** |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 9331 | * Trigger the scrollbars to draw. |
| 9332 | * This method differs from awakenScrollBars() only in its default duration. |
| 9333 | * initialAwakenScrollBars() will show the scroll bars for longer than |
| 9334 | * usual to give the user more of a chance to notice them. |
| 9335 | * |
| 9336 | * @return true if the animation is played, false otherwise. |
| 9337 | */ |
| 9338 | private boolean initialAwakenScrollBars() { |
| 9339 | return mScrollCache != null && |
| 9340 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade * 4, true); |
| 9341 | } |
| 9342 | |
| 9343 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9344 | * <p> |
| 9345 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 9346 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 9347 | * provides animated scrolling, the start delay should equal the duration of |
| 9348 | * the scrolling animation. |
| 9349 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9350 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9351 | * <p> |
| 9352 | * The animation starts only if at least one of the scrollbars is enabled, |
| 9353 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 9354 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 9355 | * this method returns true, and false otherwise. If the animation is |
| 9356 | * started, this method calls {@link #invalidate()}; in that case the caller |
| 9357 | * should not call {@link #invalidate()}. |
| 9358 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9359 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9360 | * <p> |
| 9361 | * This method should be invoked everytime a subclass directly updates the |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9362 | * scroll parameters. |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9363 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9364 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9365 | * @param startDelay the delay, in milliseconds, after which the animation |
| 9366 | * should start; when the delay is 0, the animation starts |
| 9367 | * immediately |
| 9368 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9369 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9370 | * @see #scrollBy(int, int) |
| 9371 | * @see #scrollTo(int, int) |
| 9372 | * @see #isHorizontalScrollBarEnabled() |
| 9373 | * @see #isVerticalScrollBarEnabled() |
| 9374 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 9375 | * @see #setVerticalScrollBarEnabled(boolean) |
| 9376 | */ |
| 9377 | protected boolean awakenScrollBars(int startDelay) { |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9378 | return awakenScrollBars(startDelay, true); |
| 9379 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9380 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9381 | /** |
| 9382 | * <p> |
| 9383 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 9384 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 9385 | * provides animated scrolling, the start delay should equal the duration of |
| 9386 | * the scrolling animation. |
| 9387 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9388 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9389 | * <p> |
| 9390 | * The animation starts only if at least one of the scrollbars is enabled, |
| 9391 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 9392 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 9393 | * this method returns true, and false otherwise. If the animation is |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9394 | * started, this method calls {@link #invalidate()} if the invalidate parameter |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9395 | * is set to true; in that case the caller |
| 9396 | * should not call {@link #invalidate()}. |
| 9397 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9398 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9399 | * <p> |
| 9400 | * This method should be invoked everytime a subclass directly updates the |
| 9401 | * scroll parameters. |
| 9402 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9403 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9404 | * @param startDelay the delay, in milliseconds, after which the animation |
| 9405 | * should start; when the delay is 0, the animation starts |
| 9406 | * immediately |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9407 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9408 | * @param invalidate Wheter this method should call invalidate |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9409 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9410 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9411 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9412 | * @see #scrollBy(int, int) |
| 9413 | * @see #scrollTo(int, int) |
| 9414 | * @see #isHorizontalScrollBarEnabled() |
| 9415 | * @see #isVerticalScrollBarEnabled() |
| 9416 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 9417 | * @see #setVerticalScrollBarEnabled(boolean) |
| 9418 | */ |
| 9419 | protected boolean awakenScrollBars(int startDelay, boolean invalidate) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9420 | final ScrollabilityCache scrollCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9421 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9422 | if (scrollCache == null || !scrollCache.fadeScrollBars) { |
| 9423 | return false; |
| 9424 | } |
| 9425 | |
| 9426 | if (scrollCache.scrollBar == null) { |
| 9427 | scrollCache.scrollBar = new ScrollBarDrawable(); |
| 9428 | } |
| 9429 | |
| 9430 | if (isHorizontalScrollBarEnabled() || isVerticalScrollBarEnabled()) { |
| 9431 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9432 | if (invalidate) { |
| 9433 | // Invalidate to show the scrollbars |
Adam Powell | df3ae4f | 2012-04-10 18:55:22 -0700 | [diff] [blame] | 9434 | postInvalidateOnAnimation(); |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9435 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9436 | |
| 9437 | if (scrollCache.state == ScrollabilityCache.OFF) { |
| 9438 | // FIXME: this is copied from WindowManagerService. |
| 9439 | // We should get this value from the system when it |
| 9440 | // is possible to do so. |
| 9441 | final int KEY_REPEAT_FIRST_DELAY = 750; |
| 9442 | startDelay = Math.max(KEY_REPEAT_FIRST_DELAY, startDelay); |
| 9443 | } |
| 9444 | |
| 9445 | // Tell mScrollCache when we should start fading. This may |
| 9446 | // extend the fade start time if one was already scheduled |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 9447 | long fadeStartTime = AnimationUtils.currentAnimationTimeMillis() + startDelay; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9448 | scrollCache.fadeStartTime = fadeStartTime; |
| 9449 | scrollCache.state = ScrollabilityCache.ON; |
| 9450 | |
| 9451 | // Schedule our fader to run, unscheduling any old ones first |
| 9452 | if (mAttachInfo != null) { |
| 9453 | mAttachInfo.mHandler.removeCallbacks(scrollCache); |
| 9454 | mAttachInfo.mHandler.postAtTime(scrollCache, fadeStartTime); |
| 9455 | } |
| 9456 | |
| 9457 | return true; |
| 9458 | } |
| 9459 | |
| 9460 | return false; |
| 9461 | } |
| 9462 | |
| 9463 | /** |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 9464 | * Do not invalidate views which are not visible and which are not running an animation. They |
| 9465 | * will not get drawn and they should not set dirty flags as if they will be drawn |
| 9466 | */ |
| 9467 | private boolean skipInvalidate() { |
| 9468 | return (mViewFlags & VISIBILITY_MASK) != VISIBLE && mCurrentAnimation == null && |
| 9469 | (!(mParent instanceof ViewGroup) || |
| 9470 | !((ViewGroup) mParent).isViewTransitioning(this)); |
| 9471 | } |
| 9472 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 9473 | * 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] | 9474 | * visible, {@link #onDraw(android.graphics.Canvas)} will be called at some point |
| 9475 | * in the future. This must be called from a UI thread. To call from a non-UI |
| 9476 | * thread, call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9477 | * |
| 9478 | * WARNING: This method is destructive to dirty. |
| 9479 | * @param dirty the rectangle representing the bounds of the dirty region |
| 9480 | */ |
| 9481 | public void invalidate(Rect dirty) { |
| 9482 | if (ViewDebug.TRACE_HIERARCHY) { |
| 9483 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 9484 | } |
| 9485 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 9486 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 9487 | return; |
| 9488 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 9489 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9490 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || |
| 9491 | (mPrivateFlags & INVALIDATED) != INVALIDATED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9492 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9493 | mPrivateFlags |= INVALIDATED; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 9494 | mPrivateFlags |= DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9495 | final ViewParent p = mParent; |
| 9496 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 9497 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 9498 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 9499 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 9500 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 9501 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 9502 | p.invalidateChild(this, null); |
| 9503 | return; |
| 9504 | } |
Romain Guy | af636eb | 2010-12-09 17:47:21 -0800 | [diff] [blame] | 9505 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9506 | if (p != null && ai != null) { |
| 9507 | final int scrollX = mScrollX; |
| 9508 | final int scrollY = mScrollY; |
| 9509 | final Rect r = ai.mTmpInvalRect; |
| 9510 | r.set(dirty.left - scrollX, dirty.top - scrollY, |
| 9511 | dirty.right - scrollX, dirty.bottom - scrollY); |
| 9512 | mParent.invalidateChild(this, r); |
| 9513 | } |
| 9514 | } |
| 9515 | } |
| 9516 | |
| 9517 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 9518 | * 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] | 9519 | * The coordinates of the dirty rect are relative to the view. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9520 | * If the view is visible, {@link #onDraw(android.graphics.Canvas)} |
| 9521 | * will be called at some point in the future. This must be called from |
| 9522 | * 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] | 9523 | * @param l the left position of the dirty region |
| 9524 | * @param t the top position of the dirty region |
| 9525 | * @param r the right position of the dirty region |
| 9526 | * @param b the bottom position of the dirty region |
| 9527 | */ |
| 9528 | public void invalidate(int l, int t, int r, int b) { |
| 9529 | if (ViewDebug.TRACE_HIERARCHY) { |
| 9530 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 9531 | } |
| 9532 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 9533 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 9534 | return; |
| 9535 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 9536 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9537 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || |
| 9538 | (mPrivateFlags & INVALIDATED) != INVALIDATED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9539 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9540 | mPrivateFlags |= INVALIDATED; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 9541 | mPrivateFlags |= DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9542 | final ViewParent p = mParent; |
| 9543 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 9544 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 9545 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 9546 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 9547 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 9548 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 9549 | p.invalidateChild(this, null); |
| 9550 | return; |
| 9551 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 9552 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9553 | if (p != null && ai != null && l < r && t < b) { |
| 9554 | final int scrollX = mScrollX; |
| 9555 | final int scrollY = mScrollY; |
| 9556 | final Rect tmpr = ai.mTmpInvalRect; |
| 9557 | tmpr.set(l - scrollX, t - scrollY, r - scrollX, b - scrollY); |
| 9558 | p.invalidateChild(this, tmpr); |
| 9559 | } |
| 9560 | } |
| 9561 | } |
| 9562 | |
| 9563 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9564 | * Invalidate the whole view. If the view is visible, |
| 9565 | * {@link #onDraw(android.graphics.Canvas)} will be called at some point in |
| 9566 | * the future. This must be called from a UI thread. To call from a non-UI thread, |
| 9567 | * call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9568 | */ |
| 9569 | public void invalidate() { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9570 | invalidate(true); |
| 9571 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9572 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9573 | /** |
| 9574 | * This is where the invalidate() work actually happens. A full invalidate() |
| 9575 | * causes the drawing cache to be invalidated, but this function can be called with |
| 9576 | * invalidateCache set to false to skip that invalidation step for cases that do not |
| 9577 | * need it (for example, a component that remains at the same dimensions with the same |
| 9578 | * content). |
| 9579 | * |
| 9580 | * @param invalidateCache Whether the drawing cache for this view should be invalidated as |
| 9581 | * well. This is usually true for a full invalidate, but may be set to false if the |
| 9582 | * View's contents or dimensions have not changed. |
| 9583 | */ |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 9584 | void invalidate(boolean invalidateCache) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9585 | if (ViewDebug.TRACE_HIERARCHY) { |
| 9586 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 9587 | } |
| 9588 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 9589 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 9590 | return; |
| 9591 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 9592 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Romain Guy | c5d5586 | 2011-01-21 19:01:46 -0800 | [diff] [blame] | 9593 | (invalidateCache && (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) || |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9594 | (mPrivateFlags & INVALIDATED) != INVALIDATED || isOpaque() != mLastIsOpaque) { |
| 9595 | mLastIsOpaque = isOpaque(); |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9596 | mPrivateFlags &= ~DRAWN; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 9597 | mPrivateFlags |= DIRTY; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9598 | if (invalidateCache) { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9599 | mPrivateFlags |= INVALIDATED; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9600 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 9601 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9602 | final AttachInfo ai = mAttachInfo; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 9603 | final ViewParent p = mParent; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 9604 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 9605 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 9606 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 9607 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 9608 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 9609 | p.invalidateChild(this, null); |
| 9610 | return; |
| 9611 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 9612 | } |
Michael Jurka | ebefea4 | 2010-11-15 16:04:01 -0800 | [diff] [blame] | 9613 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9614 | if (p != null && ai != null) { |
| 9615 | final Rect r = ai.mTmpInvalRect; |
| 9616 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 9617 | // Don't call invalidate -- we don't want to internally scroll |
| 9618 | // our own bounds |
| 9619 | p.invalidateChild(this, r); |
| 9620 | } |
| 9621 | } |
| 9622 | } |
| 9623 | |
| 9624 | /** |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9625 | * Quick invalidation for View property changes (alpha, translationXY, etc.). We don't want to |
| 9626 | * set any flags or handle all of the cases handled by the default invalidation methods. |
| 9627 | * Instead, we just want to schedule a traversal in ViewRootImpl with the appropriate |
| 9628 | * dirty rect. This method calls into fast invalidation methods in ViewGroup that |
| 9629 | * walk up the hierarchy, transforming the dirty rect as necessary. |
| 9630 | * |
| 9631 | * The method also handles normal invalidation logic if display list properties are not |
| 9632 | * being used in this view. The invalidateParent and forceRedraw flags are used by that |
| 9633 | * backup approach, to handle these cases used in the various property-setting methods. |
| 9634 | * |
| 9635 | * @param invalidateParent Force a call to invalidateParentCaches() if display list properties |
| 9636 | * are not being used in this view |
| 9637 | * @param forceRedraw Mark the view as DRAWN to force the invalidation to propagate, if display |
| 9638 | * list properties are not being used in this view |
| 9639 | */ |
| 9640 | void invalidateViewProperty(boolean invalidateParent, boolean forceRedraw) { |
| 9641 | if (!USE_DISPLAY_LIST_PROPERTIES || mDisplayList == null || |
| 9642 | (mPrivateFlags & DRAW_ANIMATION) == DRAW_ANIMATION) { |
| 9643 | if (invalidateParent) { |
| 9644 | invalidateParentCaches(); |
| 9645 | } |
| 9646 | if (forceRedraw) { |
| 9647 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
| 9648 | } |
| 9649 | invalidate(false); |
| 9650 | } else { |
| 9651 | final AttachInfo ai = mAttachInfo; |
| 9652 | final ViewParent p = mParent; |
| 9653 | if (p != null && ai != null) { |
| 9654 | final Rect r = ai.mTmpInvalRect; |
| 9655 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 9656 | if (mParent instanceof ViewGroup) { |
| 9657 | ((ViewGroup) mParent).invalidateChildFast(this, r); |
| 9658 | } else { |
| 9659 | mParent.invalidateChild(this, r); |
| 9660 | } |
| 9661 | } |
| 9662 | } |
| 9663 | } |
| 9664 | |
| 9665 | /** |
| 9666 | * Utility method to transform a given Rect by the current matrix of this view. |
| 9667 | */ |
| 9668 | void transformRect(final Rect rect) { |
| 9669 | if (!getMatrix().isIdentity()) { |
| 9670 | RectF boundingRect = mAttachInfo.mTmpTransformRect; |
| 9671 | boundingRect.set(rect); |
| 9672 | getMatrix().mapRect(boundingRect); |
| 9673 | rect.set((int) (boundingRect.left - 0.5f), |
| 9674 | (int) (boundingRect.top - 0.5f), |
| 9675 | (int) (boundingRect.right + 0.5f), |
| 9676 | (int) (boundingRect.bottom + 0.5f)); |
| 9677 | } |
| 9678 | } |
| 9679 | |
| 9680 | /** |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9681 | * 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] | 9682 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 9683 | * 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] | 9684 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method only |
| 9685 | * clears the parent caches and does not causes an invalidate event. |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9686 | * |
| 9687 | * @hide |
| 9688 | */ |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9689 | protected void invalidateParentCaches() { |
| 9690 | if (mParent instanceof View) { |
| 9691 | ((View) mParent).mPrivateFlags |= INVALIDATED; |
| 9692 | } |
| 9693 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9694 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9695 | /** |
| 9696 | * Used to indicate that the parent of this view should be invalidated. This functionality |
| 9697 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 9698 | * which is necessary when various parent-managed properties of the view change, such as |
| 9699 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method will propagate |
| 9700 | * an invalidation event to the parent. |
| 9701 | * |
| 9702 | * @hide |
| 9703 | */ |
| 9704 | protected void invalidateParentIfNeeded() { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9705 | if (isHardwareAccelerated() && mParent instanceof View) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9706 | ((View) mParent).invalidate(true); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9707 | } |
| 9708 | } |
| 9709 | |
| 9710 | /** |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 9711 | * Indicates whether this View is opaque. An opaque View guarantees that it will |
| 9712 | * draw all the pixels overlapping its bounds using a fully opaque color. |
| 9713 | * |
| 9714 | * Subclasses of View should override this method whenever possible to indicate |
| 9715 | * whether an instance is opaque. Opaque Views are treated in a special way by |
| 9716 | * the View hierarchy, possibly allowing it to perform optimizations during |
| 9717 | * invalidate/draw passes. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 9718 | * |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 9719 | * @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] | 9720 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 9721 | @ViewDebug.ExportedProperty(category = "drawing") |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 9722 | public boolean isOpaque() { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 9723 | return (mPrivateFlags & OPAQUE_MASK) == OPAQUE_MASK && |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9724 | ((mTransformationInfo != null ? mTransformationInfo.mAlpha : 1) |
| 9725 | >= 1.0f - ViewConfiguration.ALPHA_THRESHOLD); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9726 | } |
| 9727 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 9728 | /** |
| 9729 | * @hide |
| 9730 | */ |
| 9731 | protected void computeOpaqueFlags() { |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9732 | // Opaque if: |
| 9733 | // - Has a background |
| 9734 | // - Background is opaque |
| 9735 | // - Doesn't have scrollbars or scrollbars are inside overlay |
| 9736 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9737 | if (mBackground != null && mBackground.getOpacity() == PixelFormat.OPAQUE) { |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9738 | mPrivateFlags |= OPAQUE_BACKGROUND; |
| 9739 | } else { |
| 9740 | mPrivateFlags &= ~OPAQUE_BACKGROUND; |
| 9741 | } |
| 9742 | |
| 9743 | final int flags = mViewFlags; |
| 9744 | if (((flags & SCROLLBARS_VERTICAL) == 0 && (flags & SCROLLBARS_HORIZONTAL) == 0) || |
| 9745 | (flags & SCROLLBARS_STYLE_MASK) == SCROLLBARS_INSIDE_OVERLAY) { |
| 9746 | mPrivateFlags |= OPAQUE_SCROLLBARS; |
| 9747 | } else { |
| 9748 | mPrivateFlags &= ~OPAQUE_SCROLLBARS; |
| 9749 | } |
| 9750 | } |
| 9751 | |
| 9752 | /** |
| 9753 | * @hide |
| 9754 | */ |
| 9755 | protected boolean hasOpaqueScrollbars() { |
| 9756 | return (mPrivateFlags & OPAQUE_SCROLLBARS) == OPAQUE_SCROLLBARS; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 9757 | } |
| 9758 | |
| 9759 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9760 | * @return A handler associated with the thread running the View. This |
| 9761 | * handler can be used to pump events in the UI events queue. |
| 9762 | */ |
| 9763 | public Handler getHandler() { |
| 9764 | if (mAttachInfo != null) { |
| 9765 | return mAttachInfo.mHandler; |
| 9766 | } |
| 9767 | return null; |
| 9768 | } |
| 9769 | |
| 9770 | /** |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9771 | * Gets the view root associated with the View. |
| 9772 | * @return The view root, or null if none. |
| 9773 | * @hide |
| 9774 | */ |
| 9775 | public ViewRootImpl getViewRootImpl() { |
| 9776 | if (mAttachInfo != null) { |
| 9777 | return mAttachInfo.mViewRootImpl; |
| 9778 | } |
| 9779 | return null; |
| 9780 | } |
| 9781 | |
| 9782 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9783 | * <p>Causes the Runnable to be added to the message queue. |
| 9784 | * The runnable will be run on the user interface thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9785 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9786 | * <p>This method can be invoked from outside of the UI thread |
| 9787 | * 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] | 9788 | * |
| 9789 | * @param action The Runnable that will be executed. |
| 9790 | * |
| 9791 | * @return Returns true if the Runnable was successfully placed in to the |
| 9792 | * message queue. Returns false on failure, usually because the |
| 9793 | * looper processing the message queue is exiting. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 9794 | * |
| 9795 | * @see #postDelayed |
| 9796 | * @see #removeCallbacks |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9797 | */ |
| 9798 | public boolean post(Runnable action) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9799 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 9800 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9801 | return attachInfo.mHandler.post(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9802 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9803 | // Assume that post will succeed later |
| 9804 | ViewRootImpl.getRunQueue().post(action); |
| 9805 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9806 | } |
| 9807 | |
| 9808 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9809 | * <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] | 9810 | * after the specified amount of time elapses. |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9811 | * The runnable will be run on the user interface thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9812 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9813 | * <p>This method can be invoked from outside of the UI thread |
| 9814 | * 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] | 9815 | * |
| 9816 | * @param action The Runnable that will be executed. |
| 9817 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 9818 | * will be executed. |
| 9819 | * |
| 9820 | * @return true if the Runnable was successfully placed in to the |
| 9821 | * message queue. Returns false on failure, usually because the |
| 9822 | * looper processing the message queue is exiting. Note that a |
| 9823 | * result of true does not mean the Runnable will be processed -- |
| 9824 | * if the looper is quit before the delivery time of the message |
| 9825 | * occurs then the message will be dropped. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 9826 | * |
| 9827 | * @see #post |
| 9828 | * @see #removeCallbacks |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9829 | */ |
| 9830 | public boolean postDelayed(Runnable action, long delayMillis) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9831 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 9832 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9833 | return attachInfo.mHandler.postDelayed(action, delayMillis); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9834 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9835 | // Assume that post will succeed later |
| 9836 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
| 9837 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9838 | } |
| 9839 | |
| 9840 | /** |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 9841 | * <p>Causes the Runnable to execute on the next animation time step. |
| 9842 | * The runnable will be run on the user interface thread.</p> |
| 9843 | * |
| 9844 | * <p>This method can be invoked from outside of the UI thread |
| 9845 | * only when this View is attached to a window.</p> |
| 9846 | * |
| 9847 | * @param action The Runnable that will be executed. |
| 9848 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 9849 | * @see #postOnAnimationDelayed |
| 9850 | * @see #removeCallbacks |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 9851 | */ |
| 9852 | public void postOnAnimation(Runnable action) { |
| 9853 | final AttachInfo attachInfo = mAttachInfo; |
| 9854 | if (attachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 9855 | attachInfo.mViewRootImpl.mChoreographer.postCallback( |
| 9856 | Choreographer.CALLBACK_ANIMATION, action, null); |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 9857 | } else { |
| 9858 | // Assume that post will succeed later |
| 9859 | ViewRootImpl.getRunQueue().post(action); |
| 9860 | } |
| 9861 | } |
| 9862 | |
| 9863 | /** |
| 9864 | * <p>Causes the Runnable to execute on the next animation time step, |
| 9865 | * after the specified amount of time elapses. |
| 9866 | * The runnable will be run on the user interface thread.</p> |
| 9867 | * |
| 9868 | * <p>This method can be invoked from outside of the UI thread |
| 9869 | * only when this View is attached to a window.</p> |
| 9870 | * |
| 9871 | * @param action The Runnable that will be executed. |
| 9872 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 9873 | * will be executed. |
| 9874 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 9875 | * @see #postOnAnimation |
| 9876 | * @see #removeCallbacks |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 9877 | */ |
| 9878 | public void postOnAnimationDelayed(Runnable action, long delayMillis) { |
| 9879 | final AttachInfo attachInfo = mAttachInfo; |
| 9880 | if (attachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 9881 | attachInfo.mViewRootImpl.mChoreographer.postCallbackDelayed( |
| 9882 | Choreographer.CALLBACK_ANIMATION, action, null, delayMillis); |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 9883 | } else { |
| 9884 | // Assume that post will succeed later |
| 9885 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
| 9886 | } |
| 9887 | } |
| 9888 | |
| 9889 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9890 | * <p>Removes the specified Runnable from the message queue.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9891 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9892 | * <p>This method can be invoked from outside of the UI thread |
| 9893 | * 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] | 9894 | * |
| 9895 | * @param action The Runnable to remove from the message handling queue |
| 9896 | * |
| 9897 | * @return true if this view could ask the Handler to remove the Runnable, |
| 9898 | * false otherwise. When the returned value is true, the Runnable |
| 9899 | * may or may not have been actually removed from the message queue |
| 9900 | * (for instance, if the Runnable was not in the queue already.) |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 9901 | * |
| 9902 | * @see #post |
| 9903 | * @see #postDelayed |
| 9904 | * @see #postOnAnimation |
| 9905 | * @see #postOnAnimationDelayed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9906 | */ |
| 9907 | public boolean removeCallbacks(Runnable action) { |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 9908 | if (action != null) { |
| 9909 | final AttachInfo attachInfo = mAttachInfo; |
| 9910 | if (attachInfo != null) { |
| 9911 | attachInfo.mHandler.removeCallbacks(action); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 9912 | attachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 9913 | Choreographer.CALLBACK_ANIMATION, action, null); |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 9914 | } else { |
| 9915 | // Assume that post will succeed later |
| 9916 | ViewRootImpl.getRunQueue().removeCallbacks(action); |
| 9917 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9918 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9919 | return true; |
| 9920 | } |
| 9921 | |
| 9922 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9923 | * <p>Cause an invalidate to happen on a subsequent cycle through the event loop. |
| 9924 | * 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] | 9925 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9926 | * <p>This method can be invoked from outside of the UI thread |
| 9927 | * only when this View is attached to a window.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9928 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9929 | * @see #invalidate() |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 9930 | * @see #postInvalidateDelayed(long) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9931 | */ |
| 9932 | public void postInvalidate() { |
| 9933 | postInvalidateDelayed(0); |
| 9934 | } |
| 9935 | |
| 9936 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9937 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 9938 | * 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] | 9939 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9940 | * <p>This method can be invoked from outside of the UI thread |
| 9941 | * 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] | 9942 | * |
| 9943 | * @param left The left coordinate of the rectangle to invalidate. |
| 9944 | * @param top The top coordinate of the rectangle to invalidate. |
| 9945 | * @param right The right coordinate of the rectangle to invalidate. |
| 9946 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 9947 | * |
| 9948 | * @see #invalidate(int, int, int, int) |
| 9949 | * @see #invalidate(Rect) |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 9950 | * @see #postInvalidateDelayed(long, int, int, int, int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9951 | */ |
| 9952 | public void postInvalidate(int left, int top, int right, int bottom) { |
| 9953 | postInvalidateDelayed(0, left, top, right, bottom); |
| 9954 | } |
| 9955 | |
| 9956 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9957 | * <p>Cause an invalidate to happen on a subsequent cycle through the event |
| 9958 | * loop. Waits for the specified amount of time.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9959 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9960 | * <p>This method can be invoked from outside of the UI thread |
| 9961 | * 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] | 9962 | * |
| 9963 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 9964 | * invalidation by |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 9965 | * |
| 9966 | * @see #invalidate() |
| 9967 | * @see #postInvalidate() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9968 | */ |
| 9969 | public void postInvalidateDelayed(long delayMilliseconds) { |
| 9970 | // We try only with the AttachInfo because there's no point in invalidating |
| 9971 | // if we are not attached to our window |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9972 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 9973 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9974 | attachInfo.mViewRootImpl.dispatchInvalidateDelayed(this, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9975 | } |
| 9976 | } |
| 9977 | |
| 9978 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9979 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 9980 | * through the event loop. Waits for the specified amount of time.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9981 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9982 | * <p>This method can be invoked from outside of the UI thread |
| 9983 | * 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] | 9984 | * |
| 9985 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 9986 | * invalidation by |
| 9987 | * @param left The left coordinate of the rectangle to invalidate. |
| 9988 | * @param top The top coordinate of the rectangle to invalidate. |
| 9989 | * @param right The right coordinate of the rectangle to invalidate. |
| 9990 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 9991 | * |
| 9992 | * @see #invalidate(int, int, int, int) |
| 9993 | * @see #invalidate(Rect) |
| 9994 | * @see #postInvalidate(int, int, int, int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9995 | */ |
| 9996 | public void postInvalidateDelayed(long delayMilliseconds, int left, int top, |
| 9997 | int right, int bottom) { |
| 9998 | |
| 9999 | // We try only with the AttachInfo because there's no point in invalidating |
| 10000 | // if we are not attached to our window |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10001 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10002 | if (attachInfo != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10003 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire(); |
| 10004 | info.target = this; |
| 10005 | info.left = left; |
| 10006 | info.top = top; |
| 10007 | info.right = right; |
| 10008 | info.bottom = bottom; |
| 10009 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10010 | attachInfo.mViewRootImpl.dispatchInvalidateRectDelayed(info, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10011 | } |
| 10012 | } |
| 10013 | |
| 10014 | /** |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10015 | * <p>Cause an invalidate to happen on the next animation time step, typically the |
| 10016 | * next display frame.</p> |
| 10017 | * |
| 10018 | * <p>This method can be invoked from outside of the UI thread |
| 10019 | * only when this View is attached to a window.</p> |
| 10020 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10021 | * @see #invalidate() |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10022 | */ |
| 10023 | public void postInvalidateOnAnimation() { |
| 10024 | // We try only with the AttachInfo because there's no point in invalidating |
| 10025 | // if we are not attached to our window |
| 10026 | final AttachInfo attachInfo = mAttachInfo; |
| 10027 | if (attachInfo != null) { |
| 10028 | attachInfo.mViewRootImpl.dispatchInvalidateOnAnimation(this); |
| 10029 | } |
| 10030 | } |
| 10031 | |
| 10032 | /** |
| 10033 | * <p>Cause an invalidate of the specified area to happen on the next animation |
| 10034 | * time step, typically the next display frame.</p> |
| 10035 | * |
| 10036 | * <p>This method can be invoked from outside of the UI thread |
| 10037 | * only when this View is attached to a window.</p> |
| 10038 | * |
| 10039 | * @param left The left coordinate of the rectangle to invalidate. |
| 10040 | * @param top The top coordinate of the rectangle to invalidate. |
| 10041 | * @param right The right coordinate of the rectangle to invalidate. |
| 10042 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 10043 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10044 | * @see #invalidate(int, int, int, int) |
| 10045 | * @see #invalidate(Rect) |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10046 | */ |
| 10047 | public void postInvalidateOnAnimation(int left, int top, int right, int bottom) { |
| 10048 | // We try only with the AttachInfo because there's no point in invalidating |
| 10049 | // if we are not attached to our window |
| 10050 | final AttachInfo attachInfo = mAttachInfo; |
| 10051 | if (attachInfo != null) { |
| 10052 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire(); |
| 10053 | info.target = this; |
| 10054 | info.left = left; |
| 10055 | info.top = top; |
| 10056 | info.right = right; |
| 10057 | info.bottom = bottom; |
| 10058 | |
| 10059 | attachInfo.mViewRootImpl.dispatchInvalidateRectOnAnimation(info); |
| 10060 | } |
| 10061 | } |
| 10062 | |
| 10063 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 10064 | * Post a callback to send a {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} event. |
| 10065 | * This event is sent at most once every |
| 10066 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
| 10067 | */ |
| 10068 | private void postSendViewScrolledAccessibilityEventCallback() { |
| 10069 | if (mSendViewScrolledAccessibilityEvent == null) { |
| 10070 | mSendViewScrolledAccessibilityEvent = new SendViewScrolledAccessibilityEvent(); |
| 10071 | } |
| 10072 | if (!mSendViewScrolledAccessibilityEvent.mIsPending) { |
| 10073 | mSendViewScrolledAccessibilityEvent.mIsPending = true; |
| 10074 | postDelayed(mSendViewScrolledAccessibilityEvent, |
| 10075 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval()); |
| 10076 | } |
| 10077 | } |
| 10078 | |
| 10079 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10080 | * Called by a parent to request that a child update its values for mScrollX |
| 10081 | * and mScrollY if necessary. This will typically be done if the child is |
| 10082 | * animating a scroll using a {@link android.widget.Scroller Scroller} |
| 10083 | * object. |
| 10084 | */ |
| 10085 | public void computeScroll() { |
| 10086 | } |
| 10087 | |
| 10088 | /** |
| 10089 | * <p>Indicate whether the horizontal edges are faded when the view is |
| 10090 | * scrolled horizontally.</p> |
| 10091 | * |
| 10092 | * @return true if the horizontal edges should are faded on scroll, false |
| 10093 | * otherwise |
| 10094 | * |
| 10095 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10096 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10097 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10098 | */ |
| 10099 | public boolean isHorizontalFadingEdgeEnabled() { |
| 10100 | return (mViewFlags & FADING_EDGE_HORIZONTAL) == FADING_EDGE_HORIZONTAL; |
| 10101 | } |
| 10102 | |
| 10103 | /** |
| 10104 | * <p>Define whether the horizontal edges should be faded when this view |
| 10105 | * is scrolled horizontally.</p> |
| 10106 | * |
| 10107 | * @param horizontalFadingEdgeEnabled true if the horizontal edges should |
| 10108 | * be faded when the view is scrolled |
| 10109 | * horizontally |
| 10110 | * |
| 10111 | * @see #isHorizontalFadingEdgeEnabled() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10112 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10113 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10114 | */ |
| 10115 | public void setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled) { |
| 10116 | if (isHorizontalFadingEdgeEnabled() != horizontalFadingEdgeEnabled) { |
| 10117 | if (horizontalFadingEdgeEnabled) { |
| 10118 | initScrollCache(); |
| 10119 | } |
| 10120 | |
| 10121 | mViewFlags ^= FADING_EDGE_HORIZONTAL; |
| 10122 | } |
| 10123 | } |
| 10124 | |
| 10125 | /** |
| 10126 | * <p>Indicate whether the vertical edges are faded when the view is |
| 10127 | * scrolled horizontally.</p> |
| 10128 | * |
| 10129 | * @return true if the vertical edges should are faded on scroll, false |
| 10130 | * otherwise |
| 10131 | * |
| 10132 | * @see #setVerticalFadingEdgeEnabled(boolean) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10133 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10134 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10135 | */ |
| 10136 | public boolean isVerticalFadingEdgeEnabled() { |
| 10137 | return (mViewFlags & FADING_EDGE_VERTICAL) == FADING_EDGE_VERTICAL; |
| 10138 | } |
| 10139 | |
| 10140 | /** |
| 10141 | * <p>Define whether the vertical edges should be faded when this view |
| 10142 | * is scrolled vertically.</p> |
| 10143 | * |
| 10144 | * @param verticalFadingEdgeEnabled true if the vertical edges should |
| 10145 | * be faded when the view is scrolled |
| 10146 | * vertically |
| 10147 | * |
| 10148 | * @see #isVerticalFadingEdgeEnabled() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10149 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10150 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10151 | */ |
| 10152 | public void setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled) { |
| 10153 | if (isVerticalFadingEdgeEnabled() != verticalFadingEdgeEnabled) { |
| 10154 | if (verticalFadingEdgeEnabled) { |
| 10155 | initScrollCache(); |
| 10156 | } |
| 10157 | |
| 10158 | mViewFlags ^= FADING_EDGE_VERTICAL; |
| 10159 | } |
| 10160 | } |
| 10161 | |
| 10162 | /** |
| 10163 | * Returns the strength, or intensity, of the top faded edge. The strength is |
| 10164 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10165 | * returns 0.0 or 1.0 but no value in between. |
| 10166 | * |
| 10167 | * Subclasses should override this method to provide a smoother fade transition |
| 10168 | * when scrolling occurs. |
| 10169 | * |
| 10170 | * @return the intensity of the top fade as a float between 0.0f and 1.0f |
| 10171 | */ |
| 10172 | protected float getTopFadingEdgeStrength() { |
| 10173 | return computeVerticalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 10174 | } |
| 10175 | |
| 10176 | /** |
| 10177 | * Returns the strength, or intensity, of the bottom faded edge. The strength is |
| 10178 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10179 | * returns 0.0 or 1.0 but no value in between. |
| 10180 | * |
| 10181 | * Subclasses should override this method to provide a smoother fade transition |
| 10182 | * when scrolling occurs. |
| 10183 | * |
| 10184 | * @return the intensity of the bottom fade as a float between 0.0f and 1.0f |
| 10185 | */ |
| 10186 | protected float getBottomFadingEdgeStrength() { |
| 10187 | return computeVerticalScrollOffset() + computeVerticalScrollExtent() < |
| 10188 | computeVerticalScrollRange() ? 1.0f : 0.0f; |
| 10189 | } |
| 10190 | |
| 10191 | /** |
| 10192 | * Returns the strength, or intensity, of the left faded edge. The strength is |
| 10193 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10194 | * returns 0.0 or 1.0 but no value in between. |
| 10195 | * |
| 10196 | * Subclasses should override this method to provide a smoother fade transition |
| 10197 | * when scrolling occurs. |
| 10198 | * |
| 10199 | * @return the intensity of the left fade as a float between 0.0f and 1.0f |
| 10200 | */ |
| 10201 | protected float getLeftFadingEdgeStrength() { |
| 10202 | return computeHorizontalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 10203 | } |
| 10204 | |
| 10205 | /** |
| 10206 | * Returns the strength, or intensity, of the right faded edge. The strength is |
| 10207 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10208 | * returns 0.0 or 1.0 but no value in between. |
| 10209 | * |
| 10210 | * Subclasses should override this method to provide a smoother fade transition |
| 10211 | * when scrolling occurs. |
| 10212 | * |
| 10213 | * @return the intensity of the right fade as a float between 0.0f and 1.0f |
| 10214 | */ |
| 10215 | protected float getRightFadingEdgeStrength() { |
| 10216 | return computeHorizontalScrollOffset() + computeHorizontalScrollExtent() < |
| 10217 | computeHorizontalScrollRange() ? 1.0f : 0.0f; |
| 10218 | } |
| 10219 | |
| 10220 | /** |
| 10221 | * <p>Indicate whether the horizontal scrollbar should be drawn or not. The |
| 10222 | * scrollbar is not drawn by default.</p> |
| 10223 | * |
| 10224 | * @return true if the horizontal scrollbar should be painted, false |
| 10225 | * otherwise |
| 10226 | * |
| 10227 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 10228 | */ |
| 10229 | public boolean isHorizontalScrollBarEnabled() { |
| 10230 | return (mViewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 10231 | } |
| 10232 | |
| 10233 | /** |
| 10234 | * <p>Define whether the horizontal scrollbar should be drawn or not. The |
| 10235 | * scrollbar is not drawn by default.</p> |
| 10236 | * |
| 10237 | * @param horizontalScrollBarEnabled true if the horizontal scrollbar should |
| 10238 | * be painted |
| 10239 | * |
| 10240 | * @see #isHorizontalScrollBarEnabled() |
| 10241 | */ |
| 10242 | public void setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled) { |
| 10243 | if (isHorizontalScrollBarEnabled() != horizontalScrollBarEnabled) { |
| 10244 | mViewFlags ^= SCROLLBARS_HORIZONTAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10245 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10246 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10247 | } |
| 10248 | } |
| 10249 | |
| 10250 | /** |
| 10251 | * <p>Indicate whether the vertical scrollbar should be drawn or not. The |
| 10252 | * scrollbar is not drawn by default.</p> |
| 10253 | * |
| 10254 | * @return true if the vertical scrollbar should be painted, false |
| 10255 | * otherwise |
| 10256 | * |
| 10257 | * @see #setVerticalScrollBarEnabled(boolean) |
| 10258 | */ |
| 10259 | public boolean isVerticalScrollBarEnabled() { |
| 10260 | return (mViewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL; |
| 10261 | } |
| 10262 | |
| 10263 | /** |
| 10264 | * <p>Define whether the vertical scrollbar should be drawn or not. The |
| 10265 | * scrollbar is not drawn by default.</p> |
| 10266 | * |
| 10267 | * @param verticalScrollBarEnabled true if the vertical scrollbar should |
| 10268 | * be painted |
| 10269 | * |
| 10270 | * @see #isVerticalScrollBarEnabled() |
| 10271 | */ |
| 10272 | public void setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled) { |
| 10273 | if (isVerticalScrollBarEnabled() != verticalScrollBarEnabled) { |
| 10274 | mViewFlags ^= SCROLLBARS_VERTICAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10275 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10276 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10277 | } |
| 10278 | } |
| 10279 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 10280 | /** |
| 10281 | * @hide |
| 10282 | */ |
| 10283 | protected void recomputePadding() { |
| 10284 | setPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, mUserPaddingBottom); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10285 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10286 | |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10287 | /** |
| 10288 | * Define whether scrollbars will fade when the view is not scrolling. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10289 | * |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10290 | * @param fadeScrollbars wheter to enable fading |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10291 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10292 | * @attr ref android.R.styleable#View_fadeScrollbars |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10293 | */ |
| 10294 | public void setScrollbarFadingEnabled(boolean fadeScrollbars) { |
| 10295 | initScrollCache(); |
| 10296 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
| 10297 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10298 | if (fadeScrollbars) { |
| 10299 | scrollabilityCache.state = ScrollabilityCache.OFF; |
| 10300 | } else { |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10301 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 10302 | } |
| 10303 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10304 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10305 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10306 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10307 | * Returns true if scrollbars will fade when this view is not scrolling |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10308 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10309 | * @return true if scrollbar fading is enabled |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10310 | * |
| 10311 | * @attr ref android.R.styleable#View_fadeScrollbars |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10312 | */ |
| 10313 | public boolean isScrollbarFadingEnabled() { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10314 | return mScrollCache != null && mScrollCache.fadeScrollBars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10315 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10316 | |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10317 | /** |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10318 | * |
| 10319 | * Returns the delay before scrollbars fade. |
| 10320 | * |
| 10321 | * @return the delay before scrollbars fade |
| 10322 | * |
| 10323 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 10324 | */ |
| 10325 | public int getScrollBarDefaultDelayBeforeFade() { |
| 10326 | return mScrollCache == null ? ViewConfiguration.getScrollDefaultDelay() : |
| 10327 | mScrollCache.scrollBarDefaultDelayBeforeFade; |
| 10328 | } |
| 10329 | |
| 10330 | /** |
| 10331 | * Define the delay before scrollbars fade. |
| 10332 | * |
| 10333 | * @param scrollBarDefaultDelayBeforeFade - the delay before scrollbars fade |
| 10334 | * |
| 10335 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 10336 | */ |
| 10337 | public void setScrollBarDefaultDelayBeforeFade(int scrollBarDefaultDelayBeforeFade) { |
| 10338 | getScrollCache().scrollBarDefaultDelayBeforeFade = scrollBarDefaultDelayBeforeFade; |
| 10339 | } |
| 10340 | |
| 10341 | /** |
| 10342 | * |
| 10343 | * Returns the scrollbar fade duration. |
| 10344 | * |
| 10345 | * @return the scrollbar fade duration |
| 10346 | * |
| 10347 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
| 10348 | */ |
| 10349 | public int getScrollBarFadeDuration() { |
| 10350 | return mScrollCache == null ? ViewConfiguration.getScrollBarFadeDuration() : |
| 10351 | mScrollCache.scrollBarFadeDuration; |
| 10352 | } |
| 10353 | |
| 10354 | /** |
| 10355 | * Define the scrollbar fade duration. |
| 10356 | * |
| 10357 | * @param scrollBarFadeDuration - the scrollbar fade duration |
| 10358 | * |
| 10359 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
| 10360 | */ |
| 10361 | public void setScrollBarFadeDuration(int scrollBarFadeDuration) { |
| 10362 | getScrollCache().scrollBarFadeDuration = scrollBarFadeDuration; |
| 10363 | } |
| 10364 | |
| 10365 | /** |
| 10366 | * |
| 10367 | * Returns the scrollbar size. |
| 10368 | * |
| 10369 | * @return the scrollbar size |
| 10370 | * |
| 10371 | * @attr ref android.R.styleable#View_scrollbarSize |
| 10372 | */ |
| 10373 | public int getScrollBarSize() { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 10374 | return mScrollCache == null ? ViewConfiguration.get(mContext).getScaledScrollBarSize() : |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10375 | mScrollCache.scrollBarSize; |
| 10376 | } |
| 10377 | |
| 10378 | /** |
| 10379 | * Define the scrollbar size. |
| 10380 | * |
| 10381 | * @param scrollBarSize - the scrollbar size |
| 10382 | * |
| 10383 | * @attr ref android.R.styleable#View_scrollbarSize |
| 10384 | */ |
| 10385 | public void setScrollBarSize(int scrollBarSize) { |
| 10386 | getScrollCache().scrollBarSize = scrollBarSize; |
| 10387 | } |
| 10388 | |
| 10389 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10390 | * <p>Specify the style of the scrollbars. The scrollbars can be overlaid or |
| 10391 | * inset. When inset, they add to the padding of the view. And the scrollbars |
| 10392 | * can be drawn inside the padding area or on the edge of the view. For example, |
| 10393 | * if a view has a background drawable and you want to draw the scrollbars |
| 10394 | * inside the padding specified by the drawable, you can use |
| 10395 | * SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to |
| 10396 | * appear at the edge of the view, ignoring the padding, then you can use |
| 10397 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.</p> |
| 10398 | * @param style the style of the scrollbars. Should be one of |
| 10399 | * SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, |
| 10400 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET. |
| 10401 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 10402 | * @see #SCROLLBARS_INSIDE_INSET |
| 10403 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 10404 | * @see #SCROLLBARS_OUTSIDE_INSET |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10405 | * |
| 10406 | * @attr ref android.R.styleable#View_scrollbarStyle |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10407 | */ |
| 10408 | public void setScrollBarStyle(int style) { |
| 10409 | if (style != (mViewFlags & SCROLLBARS_STYLE_MASK)) { |
| 10410 | mViewFlags = (mViewFlags & ~SCROLLBARS_STYLE_MASK) | (style & SCROLLBARS_STYLE_MASK); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10411 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10412 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10413 | } |
| 10414 | } |
| 10415 | |
| 10416 | /** |
| 10417 | * <p>Returns the current scrollbar style.</p> |
| 10418 | * @return the current scrollbar style |
| 10419 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 10420 | * @see #SCROLLBARS_INSIDE_INSET |
| 10421 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 10422 | * @see #SCROLLBARS_OUTSIDE_INSET |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10423 | * |
| 10424 | * @attr ref android.R.styleable#View_scrollbarStyle |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10425 | */ |
Jeff Sharkey | 010d7e5 | 2011-08-08 21:05:02 -0700 | [diff] [blame] | 10426 | @ViewDebug.ExportedProperty(mapping = { |
| 10427 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_OVERLAY, to = "INSIDE_OVERLAY"), |
| 10428 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_INSET, to = "INSIDE_INSET"), |
| 10429 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_OVERLAY, to = "OUTSIDE_OVERLAY"), |
| 10430 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_INSET, to = "OUTSIDE_INSET") |
| 10431 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10432 | public int getScrollBarStyle() { |
| 10433 | return mViewFlags & SCROLLBARS_STYLE_MASK; |
| 10434 | } |
| 10435 | |
| 10436 | /** |
| 10437 | * <p>Compute the horizontal range that the horizontal scrollbar |
| 10438 | * represents.</p> |
| 10439 | * |
| 10440 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 10441 | * units used by {@link #computeHorizontalScrollExtent()} and |
| 10442 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 10443 | * |
| 10444 | * <p>The default range is the drawing width of this view.</p> |
| 10445 | * |
| 10446 | * @return the total horizontal range represented by the horizontal |
| 10447 | * scrollbar |
| 10448 | * |
| 10449 | * @see #computeHorizontalScrollExtent() |
| 10450 | * @see #computeHorizontalScrollOffset() |
| 10451 | * @see android.widget.ScrollBarDrawable |
| 10452 | */ |
| 10453 | protected int computeHorizontalScrollRange() { |
| 10454 | return getWidth(); |
| 10455 | } |
| 10456 | |
| 10457 | /** |
| 10458 | * <p>Compute the horizontal offset of the horizontal scrollbar's thumb |
| 10459 | * within the horizontal range. This value is used to compute the position |
| 10460 | * of the thumb within the scrollbar's track.</p> |
| 10461 | * |
| 10462 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 10463 | * units used by {@link #computeHorizontalScrollRange()} and |
| 10464 | * {@link #computeHorizontalScrollExtent()}.</p> |
| 10465 | * |
| 10466 | * <p>The default offset is the scroll offset of this view.</p> |
| 10467 | * |
| 10468 | * @return the horizontal offset of the scrollbar's thumb |
| 10469 | * |
| 10470 | * @see #computeHorizontalScrollRange() |
| 10471 | * @see #computeHorizontalScrollExtent() |
| 10472 | * @see android.widget.ScrollBarDrawable |
| 10473 | */ |
| 10474 | protected int computeHorizontalScrollOffset() { |
| 10475 | return mScrollX; |
| 10476 | } |
| 10477 | |
| 10478 | /** |
| 10479 | * <p>Compute the horizontal extent of the horizontal scrollbar's thumb |
| 10480 | * within the horizontal range. This value is used to compute the length |
| 10481 | * of the thumb within the scrollbar's track.</p> |
| 10482 | * |
| 10483 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 10484 | * units used by {@link #computeHorizontalScrollRange()} and |
| 10485 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 10486 | * |
| 10487 | * <p>The default extent is the drawing width of this view.</p> |
| 10488 | * |
| 10489 | * @return the horizontal extent of the scrollbar's thumb |
| 10490 | * |
| 10491 | * @see #computeHorizontalScrollRange() |
| 10492 | * @see #computeHorizontalScrollOffset() |
| 10493 | * @see android.widget.ScrollBarDrawable |
| 10494 | */ |
| 10495 | protected int computeHorizontalScrollExtent() { |
| 10496 | return getWidth(); |
| 10497 | } |
| 10498 | |
| 10499 | /** |
| 10500 | * <p>Compute the vertical range that the vertical scrollbar represents.</p> |
| 10501 | * |
| 10502 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 10503 | * units used by {@link #computeVerticalScrollExtent()} and |
| 10504 | * {@link #computeVerticalScrollOffset()}.</p> |
| 10505 | * |
| 10506 | * @return the total vertical range represented by the vertical scrollbar |
| 10507 | * |
| 10508 | * <p>The default range is the drawing height of this view.</p> |
| 10509 | * |
| 10510 | * @see #computeVerticalScrollExtent() |
| 10511 | * @see #computeVerticalScrollOffset() |
| 10512 | * @see android.widget.ScrollBarDrawable |
| 10513 | */ |
| 10514 | protected int computeVerticalScrollRange() { |
| 10515 | return getHeight(); |
| 10516 | } |
| 10517 | |
| 10518 | /** |
| 10519 | * <p>Compute the vertical offset of the vertical scrollbar's thumb |
| 10520 | * within the horizontal range. This value is used to compute the position |
| 10521 | * of the thumb within the scrollbar's track.</p> |
| 10522 | * |
| 10523 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 10524 | * units used by {@link #computeVerticalScrollRange()} and |
| 10525 | * {@link #computeVerticalScrollExtent()}.</p> |
| 10526 | * |
| 10527 | * <p>The default offset is the scroll offset of this view.</p> |
| 10528 | * |
| 10529 | * @return the vertical offset of the scrollbar's thumb |
| 10530 | * |
| 10531 | * @see #computeVerticalScrollRange() |
| 10532 | * @see #computeVerticalScrollExtent() |
| 10533 | * @see android.widget.ScrollBarDrawable |
| 10534 | */ |
| 10535 | protected int computeVerticalScrollOffset() { |
| 10536 | return mScrollY; |
| 10537 | } |
| 10538 | |
| 10539 | /** |
| 10540 | * <p>Compute the vertical extent of the horizontal scrollbar's thumb |
| 10541 | * within the vertical range. This value is used to compute the length |
| 10542 | * of the thumb within the scrollbar's track.</p> |
| 10543 | * |
| 10544 | * <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] | 10545 | * units used by {@link #computeVerticalScrollRange()} and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10546 | * {@link #computeVerticalScrollOffset()}.</p> |
| 10547 | * |
| 10548 | * <p>The default extent is the drawing height of this view.</p> |
| 10549 | * |
| 10550 | * @return the vertical extent of the scrollbar's thumb |
| 10551 | * |
| 10552 | * @see #computeVerticalScrollRange() |
| 10553 | * @see #computeVerticalScrollOffset() |
| 10554 | * @see android.widget.ScrollBarDrawable |
| 10555 | */ |
| 10556 | protected int computeVerticalScrollExtent() { |
| 10557 | return getHeight(); |
| 10558 | } |
| 10559 | |
| 10560 | /** |
Adam Powell | 6915944 | 2011-06-13 17:53:06 -0700 | [diff] [blame] | 10561 | * Check if this view can be scrolled horizontally in a certain direction. |
| 10562 | * |
| 10563 | * @param direction Negative to check scrolling left, positive to check scrolling right. |
| 10564 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 10565 | */ |
| 10566 | public boolean canScrollHorizontally(int direction) { |
| 10567 | final int offset = computeHorizontalScrollOffset(); |
| 10568 | final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent(); |
| 10569 | if (range == 0) return false; |
| 10570 | if (direction < 0) { |
| 10571 | return offset > 0; |
| 10572 | } else { |
| 10573 | return offset < range - 1; |
| 10574 | } |
| 10575 | } |
| 10576 | |
| 10577 | /** |
| 10578 | * Check if this view can be scrolled vertically in a certain direction. |
| 10579 | * |
| 10580 | * @param direction Negative to check scrolling up, positive to check scrolling down. |
| 10581 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 10582 | */ |
| 10583 | public boolean canScrollVertically(int direction) { |
| 10584 | final int offset = computeVerticalScrollOffset(); |
| 10585 | final int range = computeVerticalScrollRange() - computeVerticalScrollExtent(); |
| 10586 | if (range == 0) return false; |
| 10587 | if (direction < 0) { |
| 10588 | return offset > 0; |
| 10589 | } else { |
| 10590 | return offset < range - 1; |
| 10591 | } |
| 10592 | } |
| 10593 | |
| 10594 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10595 | * <p>Request the drawing of the horizontal and the vertical scrollbar. The |
| 10596 | * scrollbars are painted only if they have been awakened first.</p> |
| 10597 | * |
| 10598 | * @param canvas the canvas on which to draw the scrollbars |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10599 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10600 | * @see #awakenScrollBars(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10601 | */ |
Romain Guy | 1d5b3a6 | 2009-11-05 18:44:12 -0800 | [diff] [blame] | 10602 | protected final void onDrawScrollBars(Canvas canvas) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10603 | // scrollbars are drawn only when the animation is running |
| 10604 | final ScrollabilityCache cache = mScrollCache; |
| 10605 | if (cache != null) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10606 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10607 | int state = cache.state; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10608 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10609 | if (state == ScrollabilityCache.OFF) { |
| 10610 | return; |
| 10611 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10612 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10613 | boolean invalidate = false; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10614 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10615 | if (state == ScrollabilityCache.FADING) { |
| 10616 | // We're fading -- get our fade interpolation |
| 10617 | if (cache.interpolatorValues == null) { |
| 10618 | cache.interpolatorValues = new float[1]; |
| 10619 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10620 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10621 | float[] values = cache.interpolatorValues; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10622 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10623 | // Stops the animation if we're done |
| 10624 | if (cache.scrollBarInterpolator.timeToValues(values) == |
| 10625 | Interpolator.Result.FREEZE_END) { |
| 10626 | cache.state = ScrollabilityCache.OFF; |
| 10627 | } else { |
| 10628 | cache.scrollBar.setAlpha(Math.round(values[0])); |
| 10629 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10630 | |
| 10631 | // This will make the scroll bars inval themselves after |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10632 | // drawing. We only want this when we're fading so that |
| 10633 | // we prevent excessive redraws |
| 10634 | invalidate = true; |
| 10635 | } else { |
| 10636 | // We're just on -- but we may have been fading before so |
| 10637 | // reset alpha |
| 10638 | cache.scrollBar.setAlpha(255); |
| 10639 | } |
| 10640 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10641 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10642 | final int viewFlags = mViewFlags; |
| 10643 | |
| 10644 | final boolean drawHorizontalScrollBar = |
| 10645 | (viewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 10646 | final boolean drawVerticalScrollBar = |
| 10647 | (viewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL |
| 10648 | && !isVerticalScrollBarHidden(); |
| 10649 | |
| 10650 | if (drawVerticalScrollBar || drawHorizontalScrollBar) { |
| 10651 | final int width = mRight - mLeft; |
| 10652 | final int height = mBottom - mTop; |
| 10653 | |
| 10654 | final ScrollBarDrawable scrollBar = cache.scrollBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10655 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10656 | final int scrollX = mScrollX; |
| 10657 | final int scrollY = mScrollY; |
| 10658 | final int inside = (viewFlags & SCROLLBARS_OUTSIDE_MASK) == 0 ? ~0 : 0; |
| 10659 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10660 | int left, top, right, bottom; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10661 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10662 | if (drawHorizontalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 10663 | int size = scrollBar.getSize(false); |
| 10664 | if (size <= 0) { |
| 10665 | size = cache.scrollBarSize; |
| 10666 | } |
| 10667 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10668 | scrollBar.setParameters(computeHorizontalScrollRange(), |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10669 | computeHorizontalScrollOffset(), |
| 10670 | computeHorizontalScrollExtent(), false); |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10671 | final int verticalScrollBarGap = drawVerticalScrollBar ? |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10672 | getVerticalScrollbarWidth() : 0; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10673 | top = scrollY + height - size - (mUserPaddingBottom & inside); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10674 | left = scrollX + (mPaddingLeft & inside); |
| 10675 | right = scrollX + width - (mUserPaddingRight & inside) - verticalScrollBarGap; |
| 10676 | bottom = top + size; |
| 10677 | onDrawHorizontalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 10678 | if (invalidate) { |
| 10679 | invalidate(left, top, right, bottom); |
| 10680 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10681 | } |
| 10682 | |
| 10683 | if (drawVerticalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 10684 | int size = scrollBar.getSize(true); |
| 10685 | if (size <= 0) { |
| 10686 | size = cache.scrollBarSize; |
| 10687 | } |
| 10688 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10689 | scrollBar.setParameters(computeVerticalScrollRange(), |
| 10690 | computeVerticalScrollOffset(), |
| 10691 | computeVerticalScrollExtent(), true); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 10692 | switch (mVerticalScrollbarPosition) { |
| 10693 | default: |
| 10694 | case SCROLLBAR_POSITION_DEFAULT: |
| 10695 | case SCROLLBAR_POSITION_RIGHT: |
| 10696 | left = scrollX + width - size - (mUserPaddingRight & inside); |
| 10697 | break; |
| 10698 | case SCROLLBAR_POSITION_LEFT: |
| 10699 | left = scrollX + (mUserPaddingLeft & inside); |
| 10700 | break; |
| 10701 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10702 | top = scrollY + (mPaddingTop & inside); |
| 10703 | right = left + size; |
| 10704 | bottom = scrollY + height - (mUserPaddingBottom & inside); |
| 10705 | onDrawVerticalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 10706 | if (invalidate) { |
| 10707 | invalidate(left, top, right, bottom); |
| 10708 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10709 | } |
| 10710 | } |
| 10711 | } |
| 10712 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10713 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10714 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10715 | * 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] | 10716 | * FastScroller is visible. |
| 10717 | * @return whether to temporarily hide the vertical scrollbar |
| 10718 | * @hide |
| 10719 | */ |
| 10720 | protected boolean isVerticalScrollBarHidden() { |
| 10721 | return false; |
| 10722 | } |
| 10723 | |
| 10724 | /** |
| 10725 | * <p>Draw the horizontal scrollbar if |
| 10726 | * {@link #isHorizontalScrollBarEnabled()} returns true.</p> |
| 10727 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10728 | * @param canvas the canvas on which to draw the scrollbar |
| 10729 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10730 | * |
| 10731 | * @see #isHorizontalScrollBarEnabled() |
| 10732 | * @see #computeHorizontalScrollRange() |
| 10733 | * @see #computeHorizontalScrollExtent() |
| 10734 | * @see #computeHorizontalScrollOffset() |
| 10735 | * @see android.widget.ScrollBarDrawable |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10736 | * @hide |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 10737 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 10738 | protected void onDrawHorizontalScrollBar(Canvas canvas, Drawable scrollBar, |
| 10739 | int l, int t, int r, int b) { |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 10740 | scrollBar.setBounds(l, t, r, b); |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 10741 | scrollBar.draw(canvas); |
| 10742 | } |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10743 | |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 10744 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10745 | * <p>Draw the vertical scrollbar if {@link #isVerticalScrollBarEnabled()} |
| 10746 | * returns true.</p> |
| 10747 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10748 | * @param canvas the canvas on which to draw the scrollbar |
| 10749 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10750 | * |
| 10751 | * @see #isVerticalScrollBarEnabled() |
| 10752 | * @see #computeVerticalScrollRange() |
| 10753 | * @see #computeVerticalScrollExtent() |
| 10754 | * @see #computeVerticalScrollOffset() |
| 10755 | * @see android.widget.ScrollBarDrawable |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10756 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10757 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 10758 | protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, |
| 10759 | int l, int t, int r, int b) { |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10760 | scrollBar.setBounds(l, t, r, b); |
| 10761 | scrollBar.draw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10762 | } |
| 10763 | |
| 10764 | /** |
| 10765 | * Implement this to do your drawing. |
| 10766 | * |
| 10767 | * @param canvas the canvas on which the background will be drawn |
| 10768 | */ |
| 10769 | protected void onDraw(Canvas canvas) { |
| 10770 | } |
| 10771 | |
| 10772 | /* |
| 10773 | * Caller is responsible for calling requestLayout if necessary. |
| 10774 | * (This allows addViewInLayout to not request a new layout.) |
| 10775 | */ |
| 10776 | void assignParent(ViewParent parent) { |
| 10777 | if (mParent == null) { |
| 10778 | mParent = parent; |
| 10779 | } else if (parent == null) { |
| 10780 | mParent = null; |
| 10781 | } else { |
| 10782 | throw new RuntimeException("view " + this + " being added, but" |
| 10783 | + " it already has a parent"); |
| 10784 | } |
| 10785 | } |
| 10786 | |
| 10787 | /** |
| 10788 | * This is called when the view is attached to a window. At this point it |
| 10789 | * has a Surface and will start drawing. Note that this function is |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10790 | * guaranteed to be called before {@link #onDraw(android.graphics.Canvas)}, |
| 10791 | * however it may be called any time before the first onDraw -- including |
| 10792 | * before or after {@link #onMeasure(int, int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10793 | * |
| 10794 | * @see #onDetachedFromWindow() |
| 10795 | */ |
| 10796 | protected void onAttachedToWindow() { |
| 10797 | if ((mPrivateFlags & REQUEST_TRANSPARENT_REGIONS) != 0) { |
| 10798 | mParent.requestTransparentRegion(this); |
| 10799 | } |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 10800 | if ((mPrivateFlags & AWAKEN_SCROLL_BARS_ON_ATTACH) != 0) { |
| 10801 | initialAwakenScrollBars(); |
| 10802 | mPrivateFlags &= ~AWAKEN_SCROLL_BARS_ON_ATTACH; |
| 10803 | } |
Chet Haase | a9b61ac | 2010-12-20 07:40:25 -0800 | [diff] [blame] | 10804 | jumpDrawablesToCurrentState(); |
Fabrice Di Meglio | a646145 | 2011-08-19 15:42:04 -0700 | [diff] [blame] | 10805 | // Order is important here: LayoutDirection MUST be resolved before Padding |
| 10806 | // and TextDirection |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10807 | resolveLayoutDirection(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10808 | resolvePadding(); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 10809 | resolveTextDirection(); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 10810 | resolveTextAlignment(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 10811 | clearAccessibilityFocus(); |
Amith Yamasani | 4503c8d | 2011-06-17 12:36:14 -0700 | [diff] [blame] | 10812 | if (isFocused()) { |
| 10813 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 10814 | imm.focusIn(this); |
| 10815 | } |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 10816 | } |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 10817 | |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 10818 | /** |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 10819 | * @see #onScreenStateChanged(int) |
| 10820 | */ |
| 10821 | void dispatchScreenStateChanged(int screenState) { |
| 10822 | onScreenStateChanged(screenState); |
| 10823 | } |
| 10824 | |
| 10825 | /** |
| 10826 | * This method is called whenever the state of the screen this view is |
| 10827 | * attached to changes. A state change will usually occurs when the screen |
| 10828 | * turns on or off (whether it happens automatically or the user does it |
| 10829 | * manually.) |
| 10830 | * |
| 10831 | * @param screenState The new state of the screen. Can be either |
| 10832 | * {@link #SCREEN_STATE_ON} or {@link #SCREEN_STATE_OFF} |
| 10833 | */ |
| 10834 | public void onScreenStateChanged(int screenState) { |
| 10835 | } |
| 10836 | |
| 10837 | /** |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 10838 | * Return true if the application tag in the AndroidManifest has set "supportRtl" to true |
| 10839 | */ |
| 10840 | private boolean hasRtlSupport() { |
| 10841 | return mContext.getApplicationInfo().hasRtlSupport(); |
| 10842 | } |
| 10843 | |
| 10844 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10845 | * Resolve and cache the layout direction. LTR is set initially. This is implicitly supposing |
| 10846 | * 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] | 10847 | * Will call {@link View#onResolvedLayoutDirectionChanged} when resolution is done. |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 10848 | */ |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10849 | public void resolveLayoutDirection() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10850 | // Clear any previous layout direction resolution |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 10851 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_MASK; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10852 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 10853 | if (hasRtlSupport()) { |
| 10854 | // Set resolved depending on layout direction |
| 10855 | switch (getLayoutDirection()) { |
| 10856 | case LAYOUT_DIRECTION_INHERIT: |
| 10857 | // If this is root view, no need to look at parent's layout dir. |
| 10858 | if (canResolveLayoutDirection()) { |
| 10859 | ViewGroup viewGroup = ((ViewGroup) mParent); |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 10860 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 10861 | if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
| 10862 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
| 10863 | } |
| 10864 | } else { |
| 10865 | // Nothing to do, LTR by default |
| 10866 | } |
| 10867 | break; |
| 10868 | case LAYOUT_DIRECTION_RTL: |
| 10869 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
| 10870 | break; |
| 10871 | case LAYOUT_DIRECTION_LOCALE: |
| 10872 | if(isLayoutDirectionRtl(Locale.getDefault())) { |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 10873 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
| 10874 | } |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 10875 | break; |
| 10876 | default: |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10877 | // Nothing to do, LTR by default |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 10878 | } |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 10879 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10880 | |
| 10881 | // Set to resolved |
| 10882 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10883 | onResolvedLayoutDirectionChanged(); |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 10884 | // Resolve padding |
| 10885 | resolvePadding(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10886 | } |
| 10887 | |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 10888 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10889 | * Called when layout direction has been resolved. |
| 10890 | * |
| 10891 | * The default implementation does nothing. |
| 10892 | */ |
| 10893 | public void onResolvedLayoutDirectionChanged() { |
| 10894 | } |
| 10895 | |
| 10896 | /** |
| 10897 | * Resolve padding depending on layout direction. |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 10898 | */ |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 10899 | public void resolvePadding() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10900 | // If the user specified the absolute padding (either with android:padding or |
| 10901 | // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise |
| 10902 | // use the default padding or the padding from the background drawable |
| 10903 | // (stored at this point in mPadding*) |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 10904 | int resolvedLayoutDirection = getResolvedLayoutDirection(); |
| 10905 | switch (resolvedLayoutDirection) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10906 | case LAYOUT_DIRECTION_RTL: |
| 10907 | // Start user padding override Right user padding. Otherwise, if Right user |
| 10908 | // padding is not defined, use the default Right padding. If Right user padding |
| 10909 | // is defined, just use it. |
| 10910 | if (mUserPaddingStart >= 0) { |
| 10911 | mUserPaddingRight = mUserPaddingStart; |
| 10912 | } else if (mUserPaddingRight < 0) { |
| 10913 | mUserPaddingRight = mPaddingRight; |
| 10914 | } |
| 10915 | if (mUserPaddingEnd >= 0) { |
| 10916 | mUserPaddingLeft = mUserPaddingEnd; |
| 10917 | } else if (mUserPaddingLeft < 0) { |
| 10918 | mUserPaddingLeft = mPaddingLeft; |
| 10919 | } |
| 10920 | break; |
| 10921 | case LAYOUT_DIRECTION_LTR: |
| 10922 | default: |
| 10923 | // Start user padding override Left user padding. Otherwise, if Left user |
| 10924 | // padding is not defined, use the default left padding. If Left user padding |
| 10925 | // is defined, just use it. |
Fabrice Di Meglio | f3e1a93 | 2011-07-15 17:15:39 -0700 | [diff] [blame] | 10926 | if (mUserPaddingStart >= 0) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10927 | mUserPaddingLeft = mUserPaddingStart; |
| 10928 | } else if (mUserPaddingLeft < 0) { |
| 10929 | mUserPaddingLeft = mPaddingLeft; |
| 10930 | } |
Fabrice Di Meglio | f3e1a93 | 2011-07-15 17:15:39 -0700 | [diff] [blame] | 10931 | if (mUserPaddingEnd >= 0) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10932 | mUserPaddingRight = mUserPaddingEnd; |
| 10933 | } else if (mUserPaddingRight < 0) { |
| 10934 | mUserPaddingRight = mPaddingRight; |
| 10935 | } |
| 10936 | } |
| 10937 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10938 | mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom; |
| 10939 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 10940 | if(isPaddingRelative()) { |
| 10941 | setPaddingRelative(mUserPaddingStart, mPaddingTop, mUserPaddingEnd, mUserPaddingBottom); |
| 10942 | } else { |
| 10943 | recomputePadding(); |
| 10944 | } |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10945 | onPaddingChanged(resolvedLayoutDirection); |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 10946 | } |
| 10947 | |
| 10948 | /** |
| 10949 | * Resolve padding depending on the layout direction. Subclasses that care about |
| 10950 | * padding resolution should override this method. The default implementation does |
| 10951 | * nothing. |
| 10952 | * |
| 10953 | * @param layoutDirection the direction of the layout |
| 10954 | * |
Fabrice Di Meglio | e8dc07d | 2012-03-09 17:10:19 -0800 | [diff] [blame] | 10955 | * @see {@link #LAYOUT_DIRECTION_LTR} |
| 10956 | * @see {@link #LAYOUT_DIRECTION_RTL} |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 10957 | */ |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10958 | public void onPaddingChanged(int layoutDirection) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10959 | } |
| 10960 | |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 10961 | /** |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10962 | * Check if layout direction resolution can be done. |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 10963 | * |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10964 | * @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] | 10965 | */ |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10966 | public boolean canResolveLayoutDirection() { |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 10967 | switch (getLayoutDirection()) { |
| 10968 | case LAYOUT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10969 | return (mParent != null) && (mParent instanceof ViewGroup); |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 10970 | default: |
| 10971 | return true; |
| 10972 | } |
| 10973 | } |
| 10974 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10975 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10976 | * Reset the resolved layout direction. Will call {@link View#onResolvedLayoutDirectionReset} |
| 10977 | * when reset is done. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10978 | */ |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10979 | public void resetResolvedLayoutDirection() { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 10980 | // Reset the current resolved bits |
| 10981 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_MASK; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10982 | onResolvedLayoutDirectionReset(); |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 10983 | // Reset also the text direction |
| 10984 | resetResolvedTextDirection(); |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 10985 | } |
| 10986 | |
| 10987 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10988 | * Called during reset of resolved layout direction. |
| 10989 | * |
| 10990 | * Subclasses need to override this method to clear cached information that depends on the |
| 10991 | * resolved layout direction, or to inform child views that inherit their layout direction. |
| 10992 | * |
| 10993 | * The default implementation does nothing. |
| 10994 | */ |
| 10995 | public void onResolvedLayoutDirectionReset() { |
| 10996 | } |
| 10997 | |
| 10998 | /** |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 10999 | * Check if a Locale uses an RTL script. |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 11000 | * |
| 11001 | * @param locale Locale to check |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 11002 | * @return true if the Locale uses an RTL script. |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 11003 | */ |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 11004 | protected static boolean isLayoutDirectionRtl(Locale locale) { |
Fabrice Di Meglio | 3fb824b | 2012-02-28 17:58:31 -0800 | [diff] [blame] | 11005 | return (LAYOUT_DIRECTION_RTL == LocaleUtil.getLayoutDirectionFromLocale(locale)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11006 | } |
| 11007 | |
| 11008 | /** |
| 11009 | * This is called when the view is detached from a window. At this point it |
| 11010 | * no longer has a surface for drawing. |
| 11011 | * |
| 11012 | * @see #onAttachedToWindow() |
| 11013 | */ |
| 11014 | protected void onDetachedFromWindow() { |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 11015 | mPrivateFlags &= ~CANCEL_NEXT_UP_EVENT; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11016 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 11017 | removeUnsetPressCallback(); |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 11018 | removeLongPressCallback(); |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 11019 | removePerformClickCallback(); |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 11020 | removeSendViewScrolledAccessibilityEventCallback(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11022 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11023 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 11024 | destroyLayer(false); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 11025 | |
| 11026 | if (mAttachInfo != null) { |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 11027 | if (mDisplayList != null) { |
| 11028 | mAttachInfo.mViewRootImpl.invalidateDisplayList(mDisplayList); |
| 11029 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 11030 | mAttachInfo.mViewRootImpl.cancelInvalidate(this); |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 11031 | } else { |
| 11032 | if (mDisplayList != null) { |
| 11033 | // Should never happen |
| 11034 | mDisplayList.invalidate(); |
| 11035 | } |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 11036 | } |
| 11037 | |
Patrick Dubroy | ec84c3a | 2011-01-13 17:55:37 -0800 | [diff] [blame] | 11038 | mCurrentAnimation = null; |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 11039 | |
| 11040 | resetResolvedLayoutDirection(); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 11041 | resetResolvedTextAlignment(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 11042 | resetAccessibilityStateChanged(); |
| 11043 | clearAccessibilityFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11044 | } |
| 11045 | |
| 11046 | /** |
| 11047 | * @return The number of times this view has been attached to a window |
| 11048 | */ |
| 11049 | protected int getWindowAttachCount() { |
| 11050 | return mWindowAttachCount; |
| 11051 | } |
| 11052 | |
| 11053 | /** |
| 11054 | * Retrieve a unique token identifying the window this view is attached to. |
| 11055 | * @return Return the window's token for use in |
| 11056 | * {@link WindowManager.LayoutParams#token WindowManager.LayoutParams.token}. |
| 11057 | */ |
| 11058 | public IBinder getWindowToken() { |
| 11059 | return mAttachInfo != null ? mAttachInfo.mWindowToken : null; |
| 11060 | } |
| 11061 | |
| 11062 | /** |
| 11063 | * Retrieve a unique token identifying the top-level "real" window of |
| 11064 | * the window that this view is attached to. That is, this is like |
| 11065 | * {@link #getWindowToken}, except if the window this view in is a panel |
| 11066 | * window (attached to another containing window), then the token of |
| 11067 | * the containing window is returned instead. |
| 11068 | * |
| 11069 | * @return Returns the associated window token, either |
| 11070 | * {@link #getWindowToken()} or the containing window's token. |
| 11071 | */ |
| 11072 | public IBinder getApplicationWindowToken() { |
| 11073 | AttachInfo ai = mAttachInfo; |
| 11074 | if (ai != null) { |
| 11075 | IBinder appWindowToken = ai.mPanelParentWindowToken; |
| 11076 | if (appWindowToken == null) { |
| 11077 | appWindowToken = ai.mWindowToken; |
| 11078 | } |
| 11079 | return appWindowToken; |
| 11080 | } |
| 11081 | return null; |
| 11082 | } |
| 11083 | |
| 11084 | /** |
| 11085 | * Retrieve private session object this view hierarchy is using to |
| 11086 | * communicate with the window manager. |
| 11087 | * @return the session object to communicate with the window manager |
| 11088 | */ |
| 11089 | /*package*/ IWindowSession getWindowSession() { |
| 11090 | return mAttachInfo != null ? mAttachInfo.mSession : null; |
| 11091 | } |
| 11092 | |
| 11093 | /** |
| 11094 | * @param info the {@link android.view.View.AttachInfo} to associated with |
| 11095 | * this view |
| 11096 | */ |
| 11097 | void dispatchAttachedToWindow(AttachInfo info, int visibility) { |
| 11098 | //System.out.println("Attached! " + this); |
| 11099 | mAttachInfo = info; |
| 11100 | mWindowAttachCount++; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 11101 | // We will need to evaluate the drawable state at least once. |
| 11102 | mPrivateFlags |= DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11103 | if (mFloatingTreeObserver != null) { |
| 11104 | info.mTreeObserver.merge(mFloatingTreeObserver); |
| 11105 | mFloatingTreeObserver = null; |
| 11106 | } |
| 11107 | if ((mPrivateFlags&SCROLL_CONTAINER) != 0) { |
| 11108 | mAttachInfo.mScrollContainers.add(this); |
| 11109 | mPrivateFlags |= SCROLL_CONTAINER_ADDED; |
| 11110 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 11111 | performCollectViewAttributes(mAttachInfo, visibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11112 | onAttachedToWindow(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11113 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11114 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11115 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11116 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11117 | if (listeners != null && listeners.size() > 0) { |
| 11118 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 11119 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 11120 | // could mutate the list by calling the various add/remove methods. This prevents |
| 11121 | // the array from being modified while we iterate it. |
| 11122 | for (OnAttachStateChangeListener listener : listeners) { |
| 11123 | listener.onViewAttachedToWindow(this); |
| 11124 | } |
| 11125 | } |
| 11126 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11127 | int vis = info.mWindowVisibility; |
| 11128 | if (vis != GONE) { |
| 11129 | onWindowVisibilityChanged(vis); |
| 11130 | } |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 11131 | if ((mPrivateFlags&DRAWABLE_STATE_DIRTY) != 0) { |
| 11132 | // If nobody has evaluated the drawable state yet, then do it now. |
| 11133 | refreshDrawableState(); |
| 11134 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11135 | } |
| 11136 | |
| 11137 | void dispatchDetachedFromWindow() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11138 | AttachInfo info = mAttachInfo; |
| 11139 | if (info != null) { |
| 11140 | int vis = info.mWindowVisibility; |
| 11141 | if (vis != GONE) { |
| 11142 | onWindowVisibilityChanged(GONE); |
| 11143 | } |
| 11144 | } |
| 11145 | |
| 11146 | onDetachedFromWindow(); |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 11147 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11148 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11149 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11150 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11151 | if (listeners != null && listeners.size() > 0) { |
| 11152 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 11153 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 11154 | // could mutate the list by calling the various add/remove methods. This prevents |
| 11155 | // the array from being modified while we iterate it. |
| 11156 | for (OnAttachStateChangeListener listener : listeners) { |
| 11157 | listener.onViewDetachedFromWindow(this); |
| 11158 | } |
| 11159 | } |
| 11160 | |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 11161 | if ((mPrivateFlags & SCROLL_CONTAINER_ADDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11162 | mAttachInfo.mScrollContainers.remove(this); |
| 11163 | mPrivateFlags &= ~SCROLL_CONTAINER_ADDED; |
| 11164 | } |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 11165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11166 | mAttachInfo = null; |
| 11167 | } |
| 11168 | |
| 11169 | /** |
| 11170 | * Store this view hierarchy's frozen state into the given container. |
| 11171 | * |
| 11172 | * @param container The SparseArray in which to save the view's state. |
| 11173 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11174 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 11175 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 11176 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11177 | */ |
| 11178 | public void saveHierarchyState(SparseArray<Parcelable> container) { |
| 11179 | dispatchSaveInstanceState(container); |
| 11180 | } |
| 11181 | |
| 11182 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11183 | * Called by {@link #saveHierarchyState(android.util.SparseArray)} to store the state for |
| 11184 | * this view and its children. May be overridden to modify how freezing happens to a |
| 11185 | * 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] | 11186 | * |
| 11187 | * @param container The SparseArray in which to save the view's state. |
| 11188 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11189 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 11190 | * @see #saveHierarchyState(android.util.SparseArray) |
| 11191 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11192 | */ |
| 11193 | protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { |
| 11194 | if (mID != NO_ID && (mViewFlags & SAVE_DISABLED_MASK) == 0) { |
| 11195 | mPrivateFlags &= ~SAVE_STATE_CALLED; |
| 11196 | Parcelable state = onSaveInstanceState(); |
| 11197 | if ((mPrivateFlags & SAVE_STATE_CALLED) == 0) { |
| 11198 | throw new IllegalStateException( |
| 11199 | "Derived class did not call super.onSaveInstanceState()"); |
| 11200 | } |
| 11201 | if (state != null) { |
| 11202 | // Log.i("View", "Freezing #" + Integer.toHexString(mID) |
| 11203 | // + ": " + state); |
| 11204 | container.put(mID, state); |
| 11205 | } |
| 11206 | } |
| 11207 | } |
| 11208 | |
| 11209 | /** |
| 11210 | * Hook allowing a view to generate a representation of its internal state |
| 11211 | * that can later be used to create a new instance with that same state. |
| 11212 | * This state should only contain information that is not persistent or can |
| 11213 | * not be reconstructed later. For example, you will never store your |
| 11214 | * current position on screen because that will be computed again when a |
| 11215 | * new instance of the view is placed in its view hierarchy. |
| 11216 | * <p> |
| 11217 | * Some examples of things you may store here: the current cursor position |
| 11218 | * in a text view (but usually not the text itself since that is stored in a |
| 11219 | * content provider or other persistent storage), the currently selected |
| 11220 | * item in a list view. |
| 11221 | * |
| 11222 | * @return Returns a Parcelable object containing the view's current dynamic |
| 11223 | * state, or null if there is nothing interesting to save. The |
| 11224 | * default implementation returns null. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11225 | * @see #onRestoreInstanceState(android.os.Parcelable) |
| 11226 | * @see #saveHierarchyState(android.util.SparseArray) |
| 11227 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11228 | * @see #setSaveEnabled(boolean) |
| 11229 | */ |
| 11230 | protected Parcelable onSaveInstanceState() { |
| 11231 | mPrivateFlags |= SAVE_STATE_CALLED; |
| 11232 | return BaseSavedState.EMPTY_STATE; |
| 11233 | } |
| 11234 | |
| 11235 | /** |
| 11236 | * Restore this view hierarchy's frozen state from the given container. |
| 11237 | * |
| 11238 | * @param container The SparseArray which holds previously frozen states. |
| 11239 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11240 | * @see #saveHierarchyState(android.util.SparseArray) |
| 11241 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 11242 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11243 | */ |
| 11244 | public void restoreHierarchyState(SparseArray<Parcelable> container) { |
| 11245 | dispatchRestoreInstanceState(container); |
| 11246 | } |
| 11247 | |
| 11248 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11249 | * Called by {@link #restoreHierarchyState(android.util.SparseArray)} to retrieve the |
| 11250 | * state for this view and its children. May be overridden to modify how restoring |
| 11251 | * happens to a view's children; for example, some views may want to not store state |
| 11252 | * for their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11253 | * |
| 11254 | * @param container The SparseArray which holds previously saved state. |
| 11255 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11256 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 11257 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 11258 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11259 | */ |
| 11260 | protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 11261 | if (mID != NO_ID) { |
| 11262 | Parcelable state = container.get(mID); |
| 11263 | if (state != null) { |
| 11264 | // Log.i("View", "Restoreing #" + Integer.toHexString(mID) |
| 11265 | // + ": " + state); |
| 11266 | mPrivateFlags &= ~SAVE_STATE_CALLED; |
| 11267 | onRestoreInstanceState(state); |
| 11268 | if ((mPrivateFlags & SAVE_STATE_CALLED) == 0) { |
| 11269 | throw new IllegalStateException( |
| 11270 | "Derived class did not call super.onRestoreInstanceState()"); |
| 11271 | } |
| 11272 | } |
| 11273 | } |
| 11274 | } |
| 11275 | |
| 11276 | /** |
| 11277 | * Hook allowing a view to re-apply a representation of its internal state that had previously |
| 11278 | * been generated by {@link #onSaveInstanceState}. This function will never be called with a |
| 11279 | * null state. |
| 11280 | * |
| 11281 | * @param state The frozen state that had previously been returned by |
| 11282 | * {@link #onSaveInstanceState}. |
| 11283 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11284 | * @see #onSaveInstanceState() |
| 11285 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 11286 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11287 | */ |
| 11288 | protected void onRestoreInstanceState(Parcelable state) { |
| 11289 | mPrivateFlags |= SAVE_STATE_CALLED; |
| 11290 | if (state != BaseSavedState.EMPTY_STATE && state != null) { |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 11291 | throw new IllegalArgumentException("Wrong state class, expecting View State but " |
| 11292 | + "received " + state.getClass().toString() + " instead. This usually happens " |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11293 | + "when two views of different type have the same id in the same hierarchy. " |
| 11294 | + "This view's id is " + ViewDebug.resolveId(mContext, getId()) + ". Make sure " |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 11295 | + "other views do not use the same id."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11296 | } |
| 11297 | } |
| 11298 | |
| 11299 | /** |
| 11300 | * <p>Return the time at which the drawing of the view hierarchy started.</p> |
| 11301 | * |
| 11302 | * @return the drawing start time in milliseconds |
| 11303 | */ |
| 11304 | public long getDrawingTime() { |
| 11305 | return mAttachInfo != null ? mAttachInfo.mDrawingTime : 0; |
| 11306 | } |
| 11307 | |
| 11308 | /** |
| 11309 | * <p>Enables or disables the duplication of the parent's state into this view. When |
| 11310 | * duplication is enabled, this view gets its drawable state from its parent rather |
| 11311 | * than from its own internal properties.</p> |
| 11312 | * |
| 11313 | * <p>Note: in the current implementation, setting this property to true after the |
| 11314 | * view was added to a ViewGroup might have no effect at all. This property should |
| 11315 | * always be used from XML or set to true before adding this view to a ViewGroup.</p> |
| 11316 | * |
| 11317 | * <p>Note: if this view's parent addStateFromChildren property is enabled and this |
| 11318 | * property is enabled, an exception will be thrown.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11319 | * |
Gilles Debunne | fb81703 | 2011-01-13 13:52:49 -0800 | [diff] [blame] | 11320 | * <p>Note: if the child view uses and updates additionnal states which are unknown to the |
| 11321 | * 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] | 11322 | * |
| 11323 | * @param enabled True to enable duplication of the parent's drawable state, false |
| 11324 | * to disable it. |
| 11325 | * |
| 11326 | * @see #getDrawableState() |
| 11327 | * @see #isDuplicateParentStateEnabled() |
| 11328 | */ |
| 11329 | public void setDuplicateParentStateEnabled(boolean enabled) { |
| 11330 | setFlags(enabled ? DUPLICATE_PARENT_STATE : 0, DUPLICATE_PARENT_STATE); |
| 11331 | } |
| 11332 | |
| 11333 | /** |
| 11334 | * <p>Indicates whether this duplicates its drawable state from its parent.</p> |
| 11335 | * |
| 11336 | * @return True if this view's drawable state is duplicated from the parent, |
| 11337 | * false otherwise |
| 11338 | * |
| 11339 | * @see #getDrawableState() |
| 11340 | * @see #setDuplicateParentStateEnabled(boolean) |
| 11341 | */ |
| 11342 | public boolean isDuplicateParentStateEnabled() { |
| 11343 | return (mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE; |
| 11344 | } |
| 11345 | |
| 11346 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11347 | * <p>Specifies the type of layer backing this view. The layer can be |
| 11348 | * {@link #LAYER_TYPE_NONE disabled}, {@link #LAYER_TYPE_SOFTWARE software} or |
| 11349 | * {@link #LAYER_TYPE_HARDWARE hardware}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11350 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11351 | * <p>A layer is associated with an optional {@link android.graphics.Paint} |
| 11352 | * instance that controls how the layer is composed on screen. The following |
| 11353 | * properties of the paint are taken into account when composing the layer:</p> |
| 11354 | * <ul> |
| 11355 | * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> |
| 11356 | * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> |
| 11357 | * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> |
| 11358 | * </ul> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11359 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11360 | * <p>If this view has an alpha value set to < 1.0 by calling |
| 11361 | * {@link #setAlpha(float)}, the alpha value of the layer's paint is replaced by |
| 11362 | * this view's alpha value. Calling {@link #setAlpha(float)} is therefore |
| 11363 | * equivalent to setting a hardware layer on this view and providing a paint with |
| 11364 | * the desired alpha value.<p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11365 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11366 | * <p>Refer to the documentation of {@link #LAYER_TYPE_NONE disabled}, |
| 11367 | * {@link #LAYER_TYPE_SOFTWARE software} and {@link #LAYER_TYPE_HARDWARE hardware} |
| 11368 | * for more information on when and how to use layers.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11369 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11370 | * @param layerType The ype of layer to use with this view, must be one of |
| 11371 | * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 11372 | * {@link #LAYER_TYPE_HARDWARE} |
| 11373 | * @param paint The paint used to compose the layer. This argument is optional |
| 11374 | * and can be null. It is ignored when the layer type is |
| 11375 | * {@link #LAYER_TYPE_NONE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11376 | * |
| 11377 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11378 | * @see #LAYER_TYPE_NONE |
| 11379 | * @see #LAYER_TYPE_SOFTWARE |
| 11380 | * @see #LAYER_TYPE_HARDWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11381 | * @see #setAlpha(float) |
| 11382 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11383 | * @attr ref android.R.styleable#View_layerType |
| 11384 | */ |
| 11385 | public void setLayerType(int layerType, Paint paint) { |
| 11386 | if (layerType < LAYER_TYPE_NONE || layerType > LAYER_TYPE_HARDWARE) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11387 | 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] | 11388 | + "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE"); |
| 11389 | } |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11390 | |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 11391 | if (layerType == mLayerType) { |
| 11392 | if (layerType != LAYER_TYPE_NONE && paint != mLayerPaint) { |
| 11393 | mLayerPaint = paint == null ? new Paint() : paint; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 11394 | invalidateParentCaches(); |
| 11395 | invalidate(true); |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 11396 | } |
| 11397 | return; |
| 11398 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11399 | |
| 11400 | // Destroy any previous software drawing cache if needed |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11401 | switch (mLayerType) { |
Chet Haase | 6f33e81 | 2011-05-17 12:42:19 -0700 | [diff] [blame] | 11402 | case LAYER_TYPE_HARDWARE: |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 11403 | destroyLayer(false); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 11404 | // fall through - non-accelerated views may use software layer mechanism instead |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11405 | case LAYER_TYPE_SOFTWARE: |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 11406 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11407 | break; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11408 | default: |
| 11409 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11410 | } |
| 11411 | |
| 11412 | mLayerType = layerType; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 11413 | final boolean layerDisabled = mLayerType == LAYER_TYPE_NONE; |
| 11414 | mLayerPaint = layerDisabled ? null : (paint == null ? new Paint() : paint); |
| 11415 | mLocalDirtyRect = layerDisabled ? null : new Rect(); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11416 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 11417 | invalidateParentCaches(); |
| 11418 | invalidate(true); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11419 | } |
| 11420 | |
| 11421 | /** |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 11422 | * Indicates whether this view has a static layer. A view with layer type |
| 11423 | * {@link #LAYER_TYPE_NONE} is a static layer. Other types of layers are |
| 11424 | * dynamic. |
| 11425 | */ |
| 11426 | boolean hasStaticLayer() { |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 11427 | return true; |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 11428 | } |
| 11429 | |
| 11430 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11431 | * Indicates what type of layer is currently associated with this view. By default |
| 11432 | * a view does not have a layer, and the layer type is {@link #LAYER_TYPE_NONE}. |
| 11433 | * Refer to the documentation of {@link #setLayerType(int, android.graphics.Paint)} |
| 11434 | * for more information on the different types of layers. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11435 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11436 | * @return {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 11437 | * {@link #LAYER_TYPE_HARDWARE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11438 | * |
| 11439 | * @see #setLayerType(int, android.graphics.Paint) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11440 | * @see #buildLayer() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11441 | * @see #LAYER_TYPE_NONE |
| 11442 | * @see #LAYER_TYPE_SOFTWARE |
| 11443 | * @see #LAYER_TYPE_HARDWARE |
| 11444 | */ |
| 11445 | public int getLayerType() { |
| 11446 | return mLayerType; |
| 11447 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11448 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11449 | /** |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 11450 | * Forces this view's layer to be created and this view to be rendered |
| 11451 | * into its layer. If this view's layer type is set to {@link #LAYER_TYPE_NONE}, |
| 11452 | * invoking this method will have no effect. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11453 | * |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 11454 | * This method can for instance be used to render a view into its layer before |
| 11455 | * starting an animation. If this view is complex, rendering into the layer |
| 11456 | * before starting the animation will avoid skipping frames. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11457 | * |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 11458 | * @throws IllegalStateException If this view is not attached to a window |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11459 | * |
| 11460 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 11461 | */ |
| 11462 | public void buildLayer() { |
| 11463 | if (mLayerType == LAYER_TYPE_NONE) return; |
| 11464 | |
| 11465 | if (mAttachInfo == null) { |
| 11466 | throw new IllegalStateException("This view must be attached to a window first"); |
| 11467 | } |
| 11468 | |
| 11469 | switch (mLayerType) { |
| 11470 | case LAYER_TYPE_HARDWARE: |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 11471 | if (mAttachInfo.mHardwareRenderer != null && |
| 11472 | mAttachInfo.mHardwareRenderer.isEnabled() && |
| 11473 | mAttachInfo.mHardwareRenderer.validate()) { |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 11474 | getHardwareLayer(); |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 11475 | } |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 11476 | break; |
| 11477 | case LAYER_TYPE_SOFTWARE: |
| 11478 | buildDrawingCache(true); |
| 11479 | break; |
| 11480 | } |
| 11481 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11482 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 11483 | // Make sure the HardwareRenderer.validate() was invoked before calling this method |
| 11484 | void flushLayer() { |
| 11485 | if (mLayerType == LAYER_TYPE_HARDWARE && mHardwareLayer != null) { |
| 11486 | mHardwareLayer.flush(); |
| 11487 | } |
| 11488 | } |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 11489 | |
| 11490 | /** |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11491 | * <p>Returns a hardware layer that can be used to draw this view again |
| 11492 | * without executing its draw method.</p> |
| 11493 | * |
| 11494 | * @return A HardwareLayer ready to render, or null if an error occurred. |
| 11495 | */ |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 11496 | HardwareLayer getHardwareLayer() { |
Romain Guy | ea83503 | 2011-07-28 19:24:37 -0700 | [diff] [blame] | 11497 | if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null || |
| 11498 | !mAttachInfo.mHardwareRenderer.isEnabled()) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11499 | return null; |
| 11500 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11501 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 11502 | if (!mAttachInfo.mHardwareRenderer.validate()) return null; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11503 | |
| 11504 | final int width = mRight - mLeft; |
| 11505 | final int height = mBottom - mTop; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11506 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11507 | if (width == 0 || height == 0) { |
| 11508 | return null; |
| 11509 | } |
| 11510 | |
| 11511 | if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || mHardwareLayer == null) { |
| 11512 | if (mHardwareLayer == null) { |
| 11513 | mHardwareLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer( |
| 11514 | width, height, isOpaque()); |
Michael Jurka | 952e02b | 2012-03-13 18:34:35 -0700 | [diff] [blame] | 11515 | mLocalDirtyRect.set(0, 0, width, height); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11516 | } else if (mHardwareLayer.getWidth() != width || mHardwareLayer.getHeight() != height) { |
| 11517 | mHardwareLayer.resize(width, height); |
Michael Jurka | 952e02b | 2012-03-13 18:34:35 -0700 | [diff] [blame] | 11518 | mLocalDirtyRect.set(0, 0, width, height); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11519 | } |
| 11520 | |
Romain Guy | 5cd5c3f | 2011-10-17 17:10:02 -0700 | [diff] [blame] | 11521 | // The layer is not valid if the underlying GPU resources cannot be allocated |
| 11522 | if (!mHardwareLayer.isValid()) { |
| 11523 | return null; |
| 11524 | } |
| 11525 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11526 | mHardwareLayer.redraw(getHardwareLayerDisplayList(mHardwareLayer), mLocalDirtyRect); |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 11527 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11528 | } |
| 11529 | |
| 11530 | return mHardwareLayer; |
| 11531 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11532 | |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 11533 | /** |
| 11534 | * Destroys this View's hardware layer if possible. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11535 | * |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 11536 | * @return True if the layer was destroyed, false otherwise. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11537 | * |
| 11538 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 11539 | * @see #LAYER_TYPE_HARDWARE |
| 11540 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 11541 | boolean destroyLayer(boolean valid) { |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 11542 | if (mHardwareLayer != null) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 11543 | AttachInfo info = mAttachInfo; |
| 11544 | if (info != null && info.mHardwareRenderer != null && |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 11545 | info.mHardwareRenderer.isEnabled() && |
| 11546 | (valid || info.mHardwareRenderer.validate())) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 11547 | mHardwareLayer.destroy(); |
| 11548 | mHardwareLayer = null; |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 11549 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 11550 | invalidate(true); |
| 11551 | invalidateParentCaches(); |
| 11552 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 11553 | return true; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 11554 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 11555 | return false; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 11556 | } |
| 11557 | |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11558 | /** |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 11559 | * Destroys all hardware rendering resources. This method is invoked |
| 11560 | * when the system needs to reclaim resources. Upon execution of this |
| 11561 | * method, you should free any OpenGL resources created by the view. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11562 | * |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 11563 | * Note: you <strong>must</strong> call |
| 11564 | * <code>super.destroyHardwareResources()</code> when overriding |
| 11565 | * this method. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11566 | * |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 11567 | * @hide |
| 11568 | */ |
| 11569 | protected void destroyHardwareResources() { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 11570 | destroyLayer(true); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 11571 | } |
| 11572 | |
| 11573 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11574 | * <p>Enables or disables the drawing cache. When the drawing cache is enabled, the next call |
| 11575 | * to {@link #getDrawingCache()} or {@link #buildDrawingCache()} will draw the view in a |
| 11576 | * bitmap. Calling {@link #draw(android.graphics.Canvas)} will not draw from the cache when |
| 11577 | * the cache is enabled. To benefit from the cache, you must request the drawing cache by |
| 11578 | * calling {@link #getDrawingCache()} and draw it on screen if the returned bitmap is not |
| 11579 | * null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11580 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11581 | * <p>Enabling the drawing cache is similar to |
| 11582 | * {@link #setLayerType(int, android.graphics.Paint) setting a layer} when hardware |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11583 | * acceleration is turned off. When hardware acceleration is turned on, enabling the |
| 11584 | * drawing cache has no effect on rendering because the system uses a different mechanism |
| 11585 | * for acceleration which ignores the flag. If you want to use a Bitmap for the view, even |
| 11586 | * when hardware acceleration is enabled, see {@link #setLayerType(int, android.graphics.Paint)} |
| 11587 | * for information on how to enable software and hardware layers.</p> |
| 11588 | * |
| 11589 | * <p>This API can be used to manually generate |
| 11590 | * a bitmap copy of this view, by setting the flag to <code>true</code> and calling |
| 11591 | * {@link #getDrawingCache()}.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11592 | * |
| 11593 | * @param enabled true to enable the drawing cache, false otherwise |
| 11594 | * |
| 11595 | * @see #isDrawingCacheEnabled() |
| 11596 | * @see #getDrawingCache() |
| 11597 | * @see #buildDrawingCache() |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11598 | * @see #setLayerType(int, android.graphics.Paint) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11599 | */ |
| 11600 | public void setDrawingCacheEnabled(boolean enabled) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 11601 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11602 | setFlags(enabled ? DRAWING_CACHE_ENABLED : 0, DRAWING_CACHE_ENABLED); |
| 11603 | } |
| 11604 | |
| 11605 | /** |
| 11606 | * <p>Indicates whether the drawing cache is enabled for this view.</p> |
| 11607 | * |
| 11608 | * @return true if the drawing cache is enabled |
| 11609 | * |
| 11610 | * @see #setDrawingCacheEnabled(boolean) |
| 11611 | * @see #getDrawingCache() |
| 11612 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 11613 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11614 | public boolean isDrawingCacheEnabled() { |
| 11615 | return (mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED; |
| 11616 | } |
| 11617 | |
| 11618 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11619 | * Debugging utility which recursively outputs the dirty state of a view and its |
| 11620 | * descendants. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11621 | * |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11622 | * @hide |
| 11623 | */ |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 11624 | @SuppressWarnings({"UnusedDeclaration"}) |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11625 | public void outputDirtyFlags(String indent, boolean clear, int clearMask) { |
| 11626 | Log.d("View", indent + this + " DIRTY(" + (mPrivateFlags & View.DIRTY_MASK) + |
| 11627 | ") DRAWN(" + (mPrivateFlags & DRAWN) + ")" + " CACHE_VALID(" + |
| 11628 | (mPrivateFlags & View.DRAWING_CACHE_VALID) + |
| 11629 | ") INVALIDATED(" + (mPrivateFlags & INVALIDATED) + ")"); |
| 11630 | if (clear) { |
| 11631 | mPrivateFlags &= clearMask; |
| 11632 | } |
| 11633 | if (this instanceof ViewGroup) { |
| 11634 | ViewGroup parent = (ViewGroup) this; |
| 11635 | final int count = parent.getChildCount(); |
| 11636 | for (int i = 0; i < count; i++) { |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 11637 | final View child = parent.getChildAt(i); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11638 | child.outputDirtyFlags(indent + " ", clear, clearMask); |
| 11639 | } |
| 11640 | } |
| 11641 | } |
| 11642 | |
| 11643 | /** |
| 11644 | * This method is used by ViewGroup to cause its children to restore or recreate their |
| 11645 | * display lists. It is called by getDisplayList() when the parent ViewGroup does not need |
| 11646 | * to recreate its own display list, which would happen if it went through the normal |
| 11647 | * draw/dispatchDraw mechanisms. |
| 11648 | * |
| 11649 | * @hide |
| 11650 | */ |
| 11651 | protected void dispatchGetDisplayList() {} |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 11652 | |
| 11653 | /** |
| 11654 | * A view that is not attached or hardware accelerated cannot create a display list. |
| 11655 | * This method checks these conditions and returns the appropriate result. |
| 11656 | * |
| 11657 | * @return true if view has the ability to create a display list, false otherwise. |
| 11658 | * |
| 11659 | * @hide |
| 11660 | */ |
| 11661 | public boolean canHaveDisplayList() { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 11662 | return !(mAttachInfo == null || mAttachInfo.mHardwareRenderer == null); |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 11663 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11664 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11665 | /** |
Gilles Debunne | b35ab7b | 2011-12-05 15:54:00 -0800 | [diff] [blame] | 11666 | * @return The HardwareRenderer associated with that view or null if hardware rendering |
| 11667 | * is not supported or this this has not been attached to a window. |
| 11668 | * |
| 11669 | * @hide |
| 11670 | */ |
| 11671 | public HardwareRenderer getHardwareRenderer() { |
| 11672 | if (mAttachInfo != null) { |
| 11673 | return mAttachInfo.mHardwareRenderer; |
| 11674 | } |
| 11675 | return null; |
| 11676 | } |
| 11677 | |
| 11678 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11679 | * Returns a DisplayList. If the incoming displayList is null, one will be created. |
| 11680 | * Otherwise, the same display list will be returned (after having been rendered into |
| 11681 | * along the way, depending on the invalidation state of the view). |
| 11682 | * |
| 11683 | * @param displayList The previous version of this displayList, could be null. |
| 11684 | * @param isLayer Whether the requester of the display list is a layer. If so, |
| 11685 | * the view will avoid creating a layer inside the resulting display list. |
| 11686 | * @return A new or reused DisplayList object. |
| 11687 | */ |
| 11688 | private DisplayList getDisplayList(DisplayList displayList, boolean isLayer) { |
| 11689 | if (!canHaveDisplayList()) { |
| 11690 | return null; |
| 11691 | } |
| 11692 | |
| 11693 | if (((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || |
| 11694 | displayList == null || !displayList.isValid() || |
| 11695 | (!isLayer && mRecreateDisplayList))) { |
| 11696 | // Don't need to recreate the display list, just need to tell our |
| 11697 | // children to restore/recreate theirs |
| 11698 | if (displayList != null && displayList.isValid() && |
| 11699 | !isLayer && !mRecreateDisplayList) { |
| 11700 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 11701 | mPrivateFlags &= ~DIRTY_MASK; |
| 11702 | dispatchGetDisplayList(); |
| 11703 | |
| 11704 | return displayList; |
| 11705 | } |
| 11706 | |
| 11707 | if (!isLayer) { |
| 11708 | // If we got here, we're recreating it. Mark it as such to ensure that |
| 11709 | // we copy in child display lists into ours in drawChild() |
| 11710 | mRecreateDisplayList = true; |
| 11711 | } |
| 11712 | if (displayList == null) { |
| 11713 | final String name = getClass().getSimpleName(); |
| 11714 | displayList = mAttachInfo.mHardwareRenderer.createDisplayList(name); |
| 11715 | // If we're creating a new display list, make sure our parent gets invalidated |
| 11716 | // since they will need to recreate their display list to account for this |
| 11717 | // new child display list. |
| 11718 | invalidateParentCaches(); |
| 11719 | } |
| 11720 | |
| 11721 | boolean caching = false; |
| 11722 | final HardwareCanvas canvas = displayList.start(); |
| 11723 | int restoreCount = 0; |
| 11724 | int width = mRight - mLeft; |
| 11725 | int height = mBottom - mTop; |
| 11726 | |
| 11727 | try { |
| 11728 | canvas.setViewport(width, height); |
| 11729 | // The dirty rect should always be null for a display list |
| 11730 | canvas.onPreDraw(null); |
| 11731 | int layerType = ( |
| 11732 | !(mParent instanceof ViewGroup) || ((ViewGroup)mParent).mDrawLayers) ? |
| 11733 | getLayerType() : LAYER_TYPE_NONE; |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 11734 | if (!isLayer && layerType != LAYER_TYPE_NONE && USE_DISPLAY_LIST_PROPERTIES) { |
| 11735 | if (layerType == LAYER_TYPE_HARDWARE) { |
| 11736 | final HardwareLayer layer = getHardwareLayer(); |
| 11737 | if (layer != null && layer.isValid()) { |
| 11738 | canvas.drawHardwareLayer(layer, 0, 0, mLayerPaint); |
| 11739 | } else { |
| 11740 | canvas.saveLayer(0, 0, mRight - mLeft, mBottom - mTop, mLayerPaint, |
| 11741 | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | |
| 11742 | Canvas.CLIP_TO_LAYER_SAVE_FLAG); |
| 11743 | } |
| 11744 | caching = true; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11745 | } else { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 11746 | buildDrawingCache(true); |
| 11747 | Bitmap cache = getDrawingCache(true); |
| 11748 | if (cache != null) { |
| 11749 | canvas.drawBitmap(cache, 0, 0, mLayerPaint); |
| 11750 | caching = true; |
| 11751 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11752 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11753 | } else { |
| 11754 | |
| 11755 | computeScroll(); |
| 11756 | |
| 11757 | if (!USE_DISPLAY_LIST_PROPERTIES) { |
| 11758 | restoreCount = canvas.save(); |
| 11759 | } |
| 11760 | canvas.translate(-mScrollX, -mScrollY); |
| 11761 | if (!isLayer) { |
| 11762 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 11763 | mPrivateFlags &= ~DIRTY_MASK; |
| 11764 | } |
| 11765 | |
| 11766 | // Fast path for layouts with no backgrounds |
| 11767 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 11768 | dispatchDraw(canvas); |
| 11769 | } else { |
| 11770 | draw(canvas); |
| 11771 | } |
| 11772 | } |
| 11773 | } finally { |
| 11774 | if (USE_DISPLAY_LIST_PROPERTIES) { |
| 11775 | canvas.restoreToCount(restoreCount); |
| 11776 | } |
| 11777 | canvas.onPostDraw(); |
| 11778 | |
| 11779 | displayList.end(); |
| 11780 | if (USE_DISPLAY_LIST_PROPERTIES) { |
| 11781 | displayList.setCaching(caching); |
| 11782 | } |
| 11783 | if (isLayer && USE_DISPLAY_LIST_PROPERTIES) { |
| 11784 | displayList.setLeftTopRightBottom(0, 0, width, height); |
| 11785 | } else { |
| 11786 | setDisplayListProperties(displayList); |
| 11787 | } |
| 11788 | } |
| 11789 | } else if (!isLayer) { |
| 11790 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 11791 | mPrivateFlags &= ~DIRTY_MASK; |
| 11792 | } |
| 11793 | |
| 11794 | return displayList; |
| 11795 | } |
| 11796 | |
| 11797 | /** |
| 11798 | * Get the DisplayList for the HardwareLayer |
| 11799 | * |
| 11800 | * @param layer The HardwareLayer whose DisplayList we want |
| 11801 | * @return A DisplayList fopr the specified HardwareLayer |
| 11802 | */ |
| 11803 | private DisplayList getHardwareLayerDisplayList(HardwareLayer layer) { |
| 11804 | DisplayList displayList = getDisplayList(layer.getDisplayList(), true); |
| 11805 | layer.setDisplayList(displayList); |
| 11806 | return displayList; |
| 11807 | } |
| 11808 | |
| 11809 | |
| 11810 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 11811 | * <p>Returns a display list that can be used to draw this view again |
| 11812 | * without executing its draw method.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11813 | * |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 11814 | * @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] | 11815 | * |
| 11816 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 11817 | */ |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11818 | public DisplayList getDisplayList() { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11819 | mDisplayList = getDisplayList(mDisplayList, false); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 11820 | return mDisplayList; |
| 11821 | } |
| 11822 | |
| 11823 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11824 | * <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] | 11825 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11826 | * @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] | 11827 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11828 | * @see #getDrawingCache(boolean) |
| 11829 | */ |
| 11830 | public Bitmap getDrawingCache() { |
| 11831 | return getDrawingCache(false); |
| 11832 | } |
| 11833 | |
| 11834 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11835 | * <p>Returns the bitmap in which this view drawing is cached. The returned bitmap |
| 11836 | * is null when caching is disabled. If caching is enabled and the cache is not ready, |
| 11837 | * this method will create it. Calling {@link #draw(android.graphics.Canvas)} will not |
| 11838 | * draw from the cache when the cache is enabled. To benefit from the cache, you must |
| 11839 | * request the drawing cache by calling this method and draw it on screen if the |
| 11840 | * returned bitmap is not null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11841 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11842 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 11843 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 11844 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 11845 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 11846 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 11847 | * size than the view. This implies that your application must be able to handle this |
| 11848 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11849 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11850 | * @param autoScale Indicates whether the generated bitmap should be scaled based on |
| 11851 | * the current density of the screen when the application is in compatibility |
| 11852 | * mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11853 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11854 | * @return A bitmap representing this view or null if cache is disabled. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11855 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11856 | * @see #setDrawingCacheEnabled(boolean) |
| 11857 | * @see #isDrawingCacheEnabled() |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11858 | * @see #buildDrawingCache(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11859 | * @see #destroyDrawingCache() |
| 11860 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11861 | public Bitmap getDrawingCache(boolean autoScale) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11862 | if ((mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING) { |
| 11863 | return null; |
| 11864 | } |
| 11865 | if ((mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11866 | buildDrawingCache(autoScale); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11867 | } |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11868 | return autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11869 | } |
| 11870 | |
| 11871 | /** |
| 11872 | * <p>Frees the resources used by the drawing cache. If you call |
| 11873 | * {@link #buildDrawingCache()} manually without calling |
| 11874 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 11875 | * should cleanup the cache with this method afterwards.</p> |
| 11876 | * |
| 11877 | * @see #setDrawingCacheEnabled(boolean) |
| 11878 | * @see #buildDrawingCache() |
| 11879 | * @see #getDrawingCache() |
| 11880 | */ |
| 11881 | public void destroyDrawingCache() { |
| 11882 | if (mDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11883 | mDrawingCache.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11884 | mDrawingCache = null; |
| 11885 | } |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11886 | if (mUnscaledDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11887 | mUnscaledDrawingCache.recycle(); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11888 | mUnscaledDrawingCache = null; |
| 11889 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11890 | } |
| 11891 | |
| 11892 | /** |
| 11893 | * 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] | 11894 | * 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] | 11895 | * view will always be drawn on top of a solid color. |
| 11896 | * |
| 11897 | * @param color The background color to use for the drawing cache's bitmap |
| 11898 | * |
| 11899 | * @see #setDrawingCacheEnabled(boolean) |
| 11900 | * @see #buildDrawingCache() |
| 11901 | * @see #getDrawingCache() |
| 11902 | */ |
| 11903 | public void setDrawingCacheBackgroundColor(int color) { |
Romain Guy | 52e2ef8 | 2010-01-14 12:11:48 -0800 | [diff] [blame] | 11904 | if (color != mDrawingCacheBackgroundColor) { |
| 11905 | mDrawingCacheBackgroundColor = color; |
| 11906 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 11907 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11908 | } |
| 11909 | |
| 11910 | /** |
| 11911 | * @see #setDrawingCacheBackgroundColor(int) |
| 11912 | * |
| 11913 | * @return The background color to used for the drawing cache's bitmap |
| 11914 | */ |
| 11915 | public int getDrawingCacheBackgroundColor() { |
| 11916 | return mDrawingCacheBackgroundColor; |
| 11917 | } |
| 11918 | |
| 11919 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11920 | * <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] | 11921 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11922 | * @see #buildDrawingCache(boolean) |
| 11923 | */ |
| 11924 | public void buildDrawingCache() { |
| 11925 | buildDrawingCache(false); |
| 11926 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 11927 | |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11928 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11929 | * <p>Forces the drawing cache to be built if the drawing cache is invalid.</p> |
| 11930 | * |
| 11931 | * <p>If you call {@link #buildDrawingCache()} manually without calling |
| 11932 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 11933 | * should cleanup the cache by calling {@link #destroyDrawingCache()} afterwards.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11934 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11935 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 11936 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 11937 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 11938 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 11939 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 11940 | * size than the view. This implies that your application must be able to handle this |
| 11941 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11942 | * |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 11943 | * <p>You should avoid calling this method when hardware acceleration is enabled. If |
| 11944 | * 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] | 11945 | * 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] | 11946 | * performance.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11947 | * |
| 11948 | * @see #getDrawingCache() |
| 11949 | * @see #destroyDrawingCache() |
| 11950 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11951 | public void buildDrawingCache(boolean autoScale) { |
| 11952 | if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || (autoScale ? |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11953 | mDrawingCache == null : mUnscaledDrawingCache == null)) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 11954 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11955 | |
| 11956 | if (ViewDebug.TRACE_HIERARCHY) { |
| 11957 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.BUILD_CACHE); |
| 11958 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11959 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11960 | int width = mRight - mLeft; |
| 11961 | int height = mBottom - mTop; |
| 11962 | |
| 11963 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 11964 | final boolean scalingRequired = attachInfo != null && attachInfo.mScalingRequired; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11965 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 11966 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11967 | width = (int) ((width * attachInfo.mApplicationScale) + 0.5f); |
| 11968 | height = (int) ((height * attachInfo.mApplicationScale) + 0.5f); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11969 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11970 | |
| 11971 | final int drawingCacheBackgroundColor = mDrawingCacheBackgroundColor; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 11972 | final boolean opaque = drawingCacheBackgroundColor != 0 || isOpaque(); |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 11973 | final boolean use32BitCache = attachInfo != null && attachInfo.mUse32BitDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11974 | |
| 11975 | if (width <= 0 || height <= 0 || |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 11976 | // Projected bitmap size in bytes |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 11977 | (width * height * (opaque && !use32BitCache ? 2 : 4) > |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11978 | ViewConfiguration.get(mContext).getScaledMaximumDrawingCacheSize())) { |
| 11979 | destroyDrawingCache(); |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 11980 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11981 | return; |
| 11982 | } |
| 11983 | |
| 11984 | boolean clear = true; |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11985 | Bitmap bitmap = autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11986 | |
| 11987 | if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11988 | Bitmap.Config quality; |
| 11989 | if (!opaque) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 11990 | // Never pick ARGB_4444 because it looks awful |
| 11991 | // 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] | 11992 | switch (mViewFlags & DRAWING_CACHE_QUALITY_MASK) { |
| 11993 | case DRAWING_CACHE_QUALITY_AUTO: |
| 11994 | quality = Bitmap.Config.ARGB_8888; |
| 11995 | break; |
| 11996 | case DRAWING_CACHE_QUALITY_LOW: |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 11997 | quality = Bitmap.Config.ARGB_8888; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11998 | break; |
| 11999 | case DRAWING_CACHE_QUALITY_HIGH: |
| 12000 | quality = Bitmap.Config.ARGB_8888; |
| 12001 | break; |
| 12002 | default: |
| 12003 | quality = Bitmap.Config.ARGB_8888; |
| 12004 | break; |
| 12005 | } |
| 12006 | } else { |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 12007 | // Optimization for translucent windows |
| 12008 | // 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] | 12009 | 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] | 12010 | } |
| 12011 | |
| 12012 | // Try to cleanup memory |
| 12013 | if (bitmap != null) bitmap.recycle(); |
| 12014 | |
| 12015 | try { |
| 12016 | bitmap = Bitmap.createBitmap(width, height, quality); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 12017 | bitmap.setDensity(getResources().getDisplayMetrics().densityDpi); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12018 | if (autoScale) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12019 | mDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12020 | } else { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12021 | mUnscaledDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12022 | } |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 12023 | if (opaque && use32BitCache) bitmap.setHasAlpha(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12024 | } catch (OutOfMemoryError e) { |
| 12025 | // If there is not enough memory to create the bitmap cache, just |
| 12026 | // ignore the issue as bitmap caches are not required to draw the |
| 12027 | // view hierarchy |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12028 | if (autoScale) { |
| 12029 | mDrawingCache = null; |
| 12030 | } else { |
| 12031 | mUnscaledDrawingCache = null; |
| 12032 | } |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12033 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12034 | return; |
| 12035 | } |
| 12036 | |
| 12037 | clear = drawingCacheBackgroundColor != 0; |
| 12038 | } |
| 12039 | |
| 12040 | Canvas canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12041 | if (attachInfo != null) { |
| 12042 | canvas = attachInfo.mCanvas; |
| 12043 | if (canvas == null) { |
| 12044 | canvas = new Canvas(); |
| 12045 | } |
| 12046 | canvas.setBitmap(bitmap); |
| 12047 | // Temporarily clobber the cached Canvas in case one of our children |
| 12048 | // is also using a drawing cache. Without this, the children would |
| 12049 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 12050 | // thing would happen (invisible views, corrupted drawings, etc.) |
| 12051 | attachInfo.mCanvas = null; |
| 12052 | } else { |
| 12053 | // This case should hopefully never or seldom happen |
| 12054 | canvas = new Canvas(bitmap); |
| 12055 | } |
| 12056 | |
| 12057 | if (clear) { |
| 12058 | bitmap.eraseColor(drawingCacheBackgroundColor); |
| 12059 | } |
| 12060 | |
| 12061 | computeScroll(); |
| 12062 | final int restoreCount = canvas.save(); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12063 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 12064 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12065 | final float scale = attachInfo.mApplicationScale; |
| 12066 | canvas.scale(scale, scale); |
| 12067 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12068 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12069 | canvas.translate(-mScrollX, -mScrollY); |
| 12070 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12071 | mPrivateFlags |= DRAWN; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12072 | if (mAttachInfo == null || !mAttachInfo.mHardwareAccelerated || |
| 12073 | mLayerType != LAYER_TYPE_NONE) { |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 12074 | mPrivateFlags |= DRAWING_CACHE_VALID; |
| 12075 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12076 | |
| 12077 | // Fast path for layouts with no backgrounds |
| 12078 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 12079 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12080 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW); |
| 12081 | } |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12082 | mPrivateFlags &= ~DIRTY_MASK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12083 | dispatchDraw(canvas); |
| 12084 | } else { |
| 12085 | draw(canvas); |
| 12086 | } |
| 12087 | |
| 12088 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 12089 | canvas.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12090 | |
| 12091 | if (attachInfo != null) { |
| 12092 | // Restore the cached Canvas for our siblings |
| 12093 | attachInfo.mCanvas = canvas; |
| 12094 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12095 | } |
| 12096 | } |
| 12097 | |
| 12098 | /** |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12099 | * Create a snapshot of the view into a bitmap. We should probably make |
| 12100 | * some form of this public, but should think about the API. |
| 12101 | */ |
Romain Guy | 223ff5c | 2010-03-02 17:07:47 -0800 | [diff] [blame] | 12102 | Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipChildren) { |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12103 | int width = mRight - mLeft; |
| 12104 | int height = mBottom - mTop; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12105 | |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12106 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 12107 | final float scale = attachInfo != null ? attachInfo.mApplicationScale : 1.0f; |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12108 | width = (int) ((width * scale) + 0.5f); |
| 12109 | height = (int) ((height * scale) + 0.5f); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12110 | |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 12111 | 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] | 12112 | if (bitmap == null) { |
| 12113 | throw new OutOfMemoryError(); |
| 12114 | } |
| 12115 | |
Romain Guy | c529d8d | 2011-09-06 15:01:39 -0700 | [diff] [blame] | 12116 | Resources resources = getResources(); |
| 12117 | if (resources != null) { |
| 12118 | bitmap.setDensity(resources.getDisplayMetrics().densityDpi); |
| 12119 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12120 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12121 | Canvas canvas; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12122 | if (attachInfo != null) { |
| 12123 | canvas = attachInfo.mCanvas; |
| 12124 | if (canvas == null) { |
| 12125 | canvas = new Canvas(); |
| 12126 | } |
| 12127 | canvas.setBitmap(bitmap); |
| 12128 | // Temporarily clobber the cached Canvas in case one of our children |
| 12129 | // is also using a drawing cache. Without this, the children would |
| 12130 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 12131 | // things would happen (invisible views, corrupted drawings, etc.) |
| 12132 | attachInfo.mCanvas = null; |
| 12133 | } else { |
| 12134 | // This case should hopefully never or seldom happen |
| 12135 | canvas = new Canvas(bitmap); |
| 12136 | } |
| 12137 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12138 | if ((backgroundColor & 0xff000000) != 0) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12139 | bitmap.eraseColor(backgroundColor); |
| 12140 | } |
| 12141 | |
| 12142 | computeScroll(); |
| 12143 | final int restoreCount = canvas.save(); |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12144 | canvas.scale(scale, scale); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12145 | canvas.translate(-mScrollX, -mScrollY); |
| 12146 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12147 | // Temporarily remove the dirty mask |
| 12148 | int flags = mPrivateFlags; |
| 12149 | mPrivateFlags &= ~DIRTY_MASK; |
| 12150 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12151 | // Fast path for layouts with no backgrounds |
| 12152 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 12153 | dispatchDraw(canvas); |
| 12154 | } else { |
| 12155 | draw(canvas); |
| 12156 | } |
| 12157 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12158 | mPrivateFlags = flags; |
| 12159 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12160 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 12161 | canvas.setBitmap(null); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12162 | |
| 12163 | if (attachInfo != null) { |
| 12164 | // Restore the cached Canvas for our siblings |
| 12165 | attachInfo.mCanvas = canvas; |
| 12166 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12167 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12168 | return bitmap; |
| 12169 | } |
| 12170 | |
| 12171 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12172 | * Indicates whether this View is currently in edit mode. A View is usually |
| 12173 | * in edit mode when displayed within a developer tool. For instance, if |
| 12174 | * this View is being drawn by a visual user interface builder, this method |
| 12175 | * should return true. |
| 12176 | * |
| 12177 | * Subclasses should check the return value of this method to provide |
| 12178 | * different behaviors if their normal behavior might interfere with the |
| 12179 | * host environment. For instance: the class spawns a thread in its |
| 12180 | * constructor, the drawing code relies on device-specific features, etc. |
| 12181 | * |
| 12182 | * This method is usually checked in the drawing code of custom widgets. |
| 12183 | * |
| 12184 | * @return True if this View is in edit mode, false otherwise. |
| 12185 | */ |
| 12186 | public boolean isInEditMode() { |
| 12187 | return false; |
| 12188 | } |
| 12189 | |
| 12190 | /** |
| 12191 | * If the View draws content inside its padding and enables fading edges, |
| 12192 | * it needs to support padding offsets. Padding offsets are added to the |
| 12193 | * fading edges to extend the length of the fade so that it covers pixels |
| 12194 | * drawn inside the padding. |
| 12195 | * |
| 12196 | * Subclasses of this class should override this method if they need |
| 12197 | * to draw content inside the padding. |
| 12198 | * |
| 12199 | * @return True if padding offset must be applied, false otherwise. |
| 12200 | * |
| 12201 | * @see #getLeftPaddingOffset() |
| 12202 | * @see #getRightPaddingOffset() |
| 12203 | * @see #getTopPaddingOffset() |
| 12204 | * @see #getBottomPaddingOffset() |
| 12205 | * |
| 12206 | * @since CURRENT |
| 12207 | */ |
| 12208 | protected boolean isPaddingOffsetRequired() { |
| 12209 | return false; |
| 12210 | } |
| 12211 | |
| 12212 | /** |
| 12213 | * Amount by which to extend the left fading region. Called only when |
| 12214 | * {@link #isPaddingOffsetRequired()} returns true. |
| 12215 | * |
| 12216 | * @return The left padding offset in pixels. |
| 12217 | * |
| 12218 | * @see #isPaddingOffsetRequired() |
| 12219 | * |
| 12220 | * @since CURRENT |
| 12221 | */ |
| 12222 | protected int getLeftPaddingOffset() { |
| 12223 | return 0; |
| 12224 | } |
| 12225 | |
| 12226 | /** |
| 12227 | * Amount by which to extend the right fading region. Called only when |
| 12228 | * {@link #isPaddingOffsetRequired()} returns true. |
| 12229 | * |
| 12230 | * @return The right padding offset in pixels. |
| 12231 | * |
| 12232 | * @see #isPaddingOffsetRequired() |
| 12233 | * |
| 12234 | * @since CURRENT |
| 12235 | */ |
| 12236 | protected int getRightPaddingOffset() { |
| 12237 | return 0; |
| 12238 | } |
| 12239 | |
| 12240 | /** |
| 12241 | * Amount by which to extend the top fading region. Called only when |
| 12242 | * {@link #isPaddingOffsetRequired()} returns true. |
| 12243 | * |
| 12244 | * @return The top padding offset in pixels. |
| 12245 | * |
| 12246 | * @see #isPaddingOffsetRequired() |
| 12247 | * |
| 12248 | * @since CURRENT |
| 12249 | */ |
| 12250 | protected int getTopPaddingOffset() { |
| 12251 | return 0; |
| 12252 | } |
| 12253 | |
| 12254 | /** |
| 12255 | * Amount by which to extend the bottom fading region. Called only when |
| 12256 | * {@link #isPaddingOffsetRequired()} returns true. |
| 12257 | * |
| 12258 | * @return The bottom padding offset in pixels. |
| 12259 | * |
| 12260 | * @see #isPaddingOffsetRequired() |
| 12261 | * |
| 12262 | * @since CURRENT |
| 12263 | */ |
| 12264 | protected int getBottomPaddingOffset() { |
| 12265 | return 0; |
| 12266 | } |
| 12267 | |
| 12268 | /** |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 12269 | * @hide |
| 12270 | * @param offsetRequired |
| 12271 | */ |
| 12272 | protected int getFadeTop(boolean offsetRequired) { |
| 12273 | int top = mPaddingTop; |
| 12274 | if (offsetRequired) top += getTopPaddingOffset(); |
| 12275 | return top; |
| 12276 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12277 | |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 12278 | /** |
| 12279 | * @hide |
| 12280 | * @param offsetRequired |
| 12281 | */ |
| 12282 | protected int getFadeHeight(boolean offsetRequired) { |
| 12283 | int padding = mPaddingTop; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12284 | if (offsetRequired) padding += getTopPaddingOffset(); |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 12285 | return mBottom - mTop - mPaddingBottom - padding; |
| 12286 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12287 | |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 12288 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 12289 | * <p>Indicates whether this view is attached to a hardware accelerated |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 12290 | * window or not.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12291 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 12292 | * <p>Even if this method returns true, it does not mean that every call |
| 12293 | * to {@link #draw(android.graphics.Canvas)} will be made with an hardware |
| 12294 | * accelerated {@link android.graphics.Canvas}. For instance, if this view |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 12295 | * is drawn onto an offscreen {@link android.graphics.Bitmap} and its |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 12296 | * window is hardware accelerated, |
| 12297 | * {@link android.graphics.Canvas#isHardwareAccelerated()} will likely |
| 12298 | * return false, and this method will return true.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12299 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 12300 | * @return True if the view is attached to a window and the window is |
| 12301 | * hardware accelerated; false in any other case. |
| 12302 | */ |
| 12303 | public boolean isHardwareAccelerated() { |
| 12304 | return mAttachInfo != null && mAttachInfo.mHardwareAccelerated; |
| 12305 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12306 | |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 12307 | /** |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12308 | * Utility function, called by draw(canvas, parent, drawingTime) to handle the less common |
| 12309 | * case of an active Animation being run on the view. |
| 12310 | */ |
| 12311 | private boolean drawAnimation(ViewGroup parent, long drawingTime, |
| 12312 | Animation a, boolean scalingRequired) { |
| 12313 | Transformation invalidationTransform; |
| 12314 | final int flags = parent.mGroupFlags; |
| 12315 | final boolean initialized = a.isInitialized(); |
| 12316 | if (!initialized) { |
Chet Haase | 1fb8a9e | 2012-04-19 09:22:34 -0700 | [diff] [blame] | 12317 | a.initialize(mRight - mLeft, mBottom - mTop, parent.getWidth(), parent.getHeight()); |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12318 | a.initializeInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop); |
| 12319 | onAnimationStart(); |
| 12320 | } |
| 12321 | |
| 12322 | boolean more = a.getTransformation(drawingTime, parent.mChildTransformation, 1f); |
| 12323 | if (scalingRequired && mAttachInfo.mApplicationScale != 1f) { |
| 12324 | if (parent.mInvalidationTransformation == null) { |
| 12325 | parent.mInvalidationTransformation = new Transformation(); |
| 12326 | } |
| 12327 | invalidationTransform = parent.mInvalidationTransformation; |
| 12328 | a.getTransformation(drawingTime, invalidationTransform, 1f); |
| 12329 | } else { |
| 12330 | invalidationTransform = parent.mChildTransformation; |
| 12331 | } |
| 12332 | if (more) { |
| 12333 | if (!a.willChangeBounds()) { |
| 12334 | if ((flags & (parent.FLAG_OPTIMIZE_INVALIDATE | parent.FLAG_ANIMATION_DONE)) == |
| 12335 | parent.FLAG_OPTIMIZE_INVALIDATE) { |
| 12336 | parent.mGroupFlags |= parent.FLAG_INVALIDATE_REQUIRED; |
| 12337 | } else if ((flags & parent.FLAG_INVALIDATE_REQUIRED) == 0) { |
| 12338 | // The child need to draw an animation, potentially offscreen, so |
| 12339 | // make sure we do not cancel invalidate requests |
| 12340 | parent.mPrivateFlags |= DRAW_ANIMATION; |
| 12341 | parent.invalidate(mLeft, mTop, mRight, mBottom); |
| 12342 | } |
| 12343 | } else { |
| 12344 | if (parent.mInvalidateRegion == null) { |
| 12345 | parent.mInvalidateRegion = new RectF(); |
| 12346 | } |
| 12347 | final RectF region = parent.mInvalidateRegion; |
| 12348 | a.getInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop, region, |
| 12349 | invalidationTransform); |
| 12350 | |
| 12351 | // The child need to draw an animation, potentially offscreen, so |
| 12352 | // make sure we do not cancel invalidate requests |
| 12353 | parent.mPrivateFlags |= DRAW_ANIMATION; |
| 12354 | |
| 12355 | final int left = mLeft + (int) region.left; |
| 12356 | final int top = mTop + (int) region.top; |
| 12357 | parent.invalidate(left, top, left + (int) (region.width() + .5f), |
| 12358 | top + (int) (region.height() + .5f)); |
| 12359 | } |
| 12360 | } |
| 12361 | return more; |
| 12362 | } |
| 12363 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12364 | void setDisplayListProperties() { |
| 12365 | setDisplayListProperties(mDisplayList); |
| 12366 | } |
| 12367 | |
| 12368 | /** |
| 12369 | * This method is called by getDisplayList() when a display list is created or re-rendered. |
| 12370 | * It sets or resets the current value of all properties on that display list (resetting is |
| 12371 | * necessary when a display list is being re-created, because we need to make sure that |
| 12372 | * previously-set transform values |
| 12373 | */ |
| 12374 | void setDisplayListProperties(DisplayList displayList) { |
| 12375 | if (USE_DISPLAY_LIST_PROPERTIES && displayList != null) { |
| 12376 | displayList.setLeftTopRightBottom(mLeft, mTop, mRight, mBottom); |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 12377 | displayList.setHasOverlappingRendering(hasOverlappingRendering()); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12378 | if (mParent instanceof ViewGroup) { |
| 12379 | displayList.setClipChildren( |
| 12380 | (((ViewGroup)mParent).mGroupFlags & ViewGroup.FLAG_CLIP_CHILDREN) != 0); |
| 12381 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12382 | float alpha = 1; |
| 12383 | if (mParent instanceof ViewGroup && (((ViewGroup) mParent).mGroupFlags & |
| 12384 | ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
| 12385 | ViewGroup parentVG = (ViewGroup) mParent; |
| 12386 | final boolean hasTransform = |
| 12387 | parentVG.getChildStaticTransformation(this, parentVG.mChildTransformation); |
| 12388 | if (hasTransform) { |
| 12389 | Transformation transform = parentVG.mChildTransformation; |
| 12390 | final int transformType = parentVG.mChildTransformation.getTransformationType(); |
| 12391 | if (transformType != Transformation.TYPE_IDENTITY) { |
| 12392 | if ((transformType & Transformation.TYPE_ALPHA) != 0) { |
| 12393 | alpha = transform.getAlpha(); |
| 12394 | } |
| 12395 | if ((transformType & Transformation.TYPE_MATRIX) != 0) { |
| 12396 | displayList.setStaticMatrix(transform.getMatrix()); |
| 12397 | } |
| 12398 | } |
| 12399 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12400 | } |
| 12401 | if (mTransformationInfo != null) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12402 | alpha *= mTransformationInfo.mAlpha; |
| 12403 | if (alpha < 1) { |
| 12404 | final int multipliedAlpha = (int) (255 * alpha); |
| 12405 | if (onSetAlpha(multipliedAlpha)) { |
| 12406 | alpha = 1; |
| 12407 | } |
| 12408 | } |
| 12409 | displayList.setTransformationInfo(alpha, |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12410 | mTransformationInfo.mTranslationX, mTransformationInfo.mTranslationY, |
| 12411 | mTransformationInfo.mRotation, mTransformationInfo.mRotationX, |
| 12412 | mTransformationInfo.mRotationY, mTransformationInfo.mScaleX, |
| 12413 | mTransformationInfo.mScaleY); |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 12414 | if (mTransformationInfo.mCamera == null) { |
| 12415 | mTransformationInfo.mCamera = new Camera(); |
| 12416 | mTransformationInfo.matrix3D = new Matrix(); |
| 12417 | } |
| 12418 | displayList.setCameraDistance(mTransformationInfo.mCamera.getLocationZ()); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12419 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == PIVOT_EXPLICITLY_SET) { |
| 12420 | displayList.setPivotX(getPivotX()); |
| 12421 | displayList.setPivotY(getPivotY()); |
| 12422 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12423 | } else if (alpha < 1) { |
| 12424 | displayList.setAlpha(alpha); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12425 | } |
| 12426 | } |
| 12427 | } |
| 12428 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12429 | /** |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12430 | * This method is called by ViewGroup.drawChild() to have each child view draw itself. |
| 12431 | * This draw() method is an implementation detail and is not intended to be overridden or |
| 12432 | * to be called from anywhere else other than ViewGroup.drawChild(). |
| 12433 | */ |
| 12434 | boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12435 | boolean useDisplayListProperties = USE_DISPLAY_LIST_PROPERTIES && mAttachInfo != null && |
| 12436 | mAttachInfo.mHardwareAccelerated; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12437 | boolean more = false; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12438 | final boolean childHasIdentityMatrix = hasIdentityMatrix(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12439 | final int flags = parent.mGroupFlags; |
| 12440 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12441 | if ((flags & ViewGroup.FLAG_CLEAR_TRANSFORMATION) == ViewGroup.FLAG_CLEAR_TRANSFORMATION) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12442 | parent.mChildTransformation.clear(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12443 | parent.mGroupFlags &= ~ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12444 | } |
| 12445 | |
| 12446 | Transformation transformToApply = null; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12447 | boolean concatMatrix = false; |
| 12448 | |
| 12449 | boolean scalingRequired = false; |
| 12450 | boolean caching; |
| 12451 | int layerType = parent.mDrawLayers ? getLayerType() : LAYER_TYPE_NONE; |
| 12452 | |
| 12453 | final boolean hardwareAccelerated = canvas.isHardwareAccelerated(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12454 | if ((flags & ViewGroup.FLAG_CHILDREN_DRAWN_WITH_CACHE) != 0 || |
| 12455 | (flags & ViewGroup.FLAG_ALWAYS_DRAWN_WITH_CACHE) != 0) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12456 | caching = true; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12457 | // 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] | 12458 | if (mAttachInfo != null) scalingRequired = mAttachInfo.mScalingRequired; |
| 12459 | } else { |
| 12460 | caching = (layerType != LAYER_TYPE_NONE) || hardwareAccelerated; |
| 12461 | } |
| 12462 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12463 | final Animation a = getAnimation(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12464 | if (a != null) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12465 | more = drawAnimation(parent, drawingTime, a, scalingRequired); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12466 | concatMatrix = a.willChangeTransformationMatrix(); |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12467 | transformToApply = parent.mChildTransformation; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12468 | } else if (!useDisplayListProperties && |
| 12469 | (flags & ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12470 | final boolean hasTransform = |
| 12471 | parent.getChildStaticTransformation(this, parent.mChildTransformation); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12472 | if (hasTransform) { |
| 12473 | final int transformType = parent.mChildTransformation.getTransformationType(); |
| 12474 | transformToApply = transformType != Transformation.TYPE_IDENTITY ? |
| 12475 | parent.mChildTransformation : null; |
| 12476 | concatMatrix = (transformType & Transformation.TYPE_MATRIX) != 0; |
| 12477 | } |
| 12478 | } |
| 12479 | |
| 12480 | concatMatrix |= !childHasIdentityMatrix; |
| 12481 | |
| 12482 | // Sets the flag as early as possible to allow draw() implementations |
| 12483 | // to call invalidate() successfully when doing animations |
| 12484 | mPrivateFlags |= DRAWN; |
| 12485 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12486 | if (!concatMatrix && canvas.quickReject(mLeft, mTop, mRight, mBottom, Canvas.EdgeType.BW) && |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12487 | (mPrivateFlags & DRAW_ANIMATION) == 0) { |
| 12488 | return more; |
| 12489 | } |
| 12490 | |
| 12491 | if (hardwareAccelerated) { |
| 12492 | // Clear INVALIDATED flag to allow invalidation to occur during rendering, but |
| 12493 | // retain the flag's value temporarily in the mRecreateDisplayList flag |
| 12494 | mRecreateDisplayList = (mPrivateFlags & INVALIDATED) == INVALIDATED; |
| 12495 | mPrivateFlags &= ~INVALIDATED; |
| 12496 | } |
| 12497 | |
| 12498 | computeScroll(); |
| 12499 | |
| 12500 | final int sx = mScrollX; |
| 12501 | final int sy = mScrollY; |
| 12502 | |
| 12503 | DisplayList displayList = null; |
| 12504 | Bitmap cache = null; |
| 12505 | boolean hasDisplayList = false; |
| 12506 | if (caching) { |
| 12507 | if (!hardwareAccelerated) { |
| 12508 | if (layerType != LAYER_TYPE_NONE) { |
| 12509 | layerType = LAYER_TYPE_SOFTWARE; |
| 12510 | buildDrawingCache(true); |
| 12511 | } |
| 12512 | cache = getDrawingCache(true); |
| 12513 | } else { |
| 12514 | switch (layerType) { |
| 12515 | case LAYER_TYPE_SOFTWARE: |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 12516 | if (useDisplayListProperties) { |
| 12517 | hasDisplayList = canHaveDisplayList(); |
| 12518 | } else { |
| 12519 | buildDrawingCache(true); |
| 12520 | cache = getDrawingCache(true); |
| 12521 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12522 | break; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12523 | case LAYER_TYPE_HARDWARE: |
| 12524 | if (useDisplayListProperties) { |
| 12525 | hasDisplayList = canHaveDisplayList(); |
| 12526 | } |
| 12527 | break; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12528 | case LAYER_TYPE_NONE: |
| 12529 | // Delay getting the display list until animation-driven alpha values are |
| 12530 | // set up and possibly passed on to the view |
| 12531 | hasDisplayList = canHaveDisplayList(); |
| 12532 | break; |
| 12533 | } |
| 12534 | } |
| 12535 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12536 | useDisplayListProperties &= hasDisplayList; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12537 | if (useDisplayListProperties) { |
| 12538 | displayList = getDisplayList(); |
| 12539 | if (!displayList.isValid()) { |
| 12540 | // Uncommon, but possible. If a view is removed from the hierarchy during the call |
| 12541 | // to getDisplayList(), the display list will be marked invalid and we should not |
| 12542 | // try to use it again. |
| 12543 | displayList = null; |
| 12544 | hasDisplayList = false; |
| 12545 | useDisplayListProperties = false; |
| 12546 | } |
| 12547 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12548 | |
| 12549 | final boolean hasNoCache = cache == null || hasDisplayList; |
| 12550 | final boolean offsetForScroll = cache == null && !hasDisplayList && |
| 12551 | layerType != LAYER_TYPE_HARDWARE; |
| 12552 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12553 | int restoreTo = -1; |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 12554 | if (!useDisplayListProperties || transformToApply != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12555 | restoreTo = canvas.save(); |
| 12556 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12557 | if (offsetForScroll) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12558 | canvas.translate(mLeft - sx, mTop - sy); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12559 | } else { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12560 | if (!useDisplayListProperties) { |
| 12561 | canvas.translate(mLeft, mTop); |
| 12562 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12563 | if (scalingRequired) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12564 | if (useDisplayListProperties) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12565 | // TODO: Might not need this if we put everything inside the DL |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12566 | restoreTo = canvas.save(); |
| 12567 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12568 | // mAttachInfo cannot be null, otherwise scalingRequired == false |
| 12569 | final float scale = 1.0f / mAttachInfo.mApplicationScale; |
| 12570 | canvas.scale(scale, scale); |
| 12571 | } |
| 12572 | } |
| 12573 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12574 | float alpha = useDisplayListProperties ? 1 : getAlpha(); |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12575 | if (transformToApply != null || alpha < 1 || !hasIdentityMatrix()) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12576 | if (transformToApply != null || !childHasIdentityMatrix) { |
| 12577 | int transX = 0; |
| 12578 | int transY = 0; |
| 12579 | |
| 12580 | if (offsetForScroll) { |
| 12581 | transX = -sx; |
| 12582 | transY = -sy; |
| 12583 | } |
| 12584 | |
| 12585 | if (transformToApply != null) { |
| 12586 | if (concatMatrix) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12587 | if (useDisplayListProperties) { |
| 12588 | displayList.setAnimationMatrix(transformToApply.getMatrix()); |
| 12589 | } else { |
| 12590 | // Undo the scroll translation, apply the transformation matrix, |
| 12591 | // then redo the scroll translate to get the correct result. |
| 12592 | canvas.translate(-transX, -transY); |
| 12593 | canvas.concat(transformToApply.getMatrix()); |
| 12594 | canvas.translate(transX, transY); |
| 12595 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12596 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12597 | } |
| 12598 | |
| 12599 | float transformAlpha = transformToApply.getAlpha(); |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12600 | if (transformAlpha < 1) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12601 | alpha *= transformToApply.getAlpha(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12602 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12603 | } |
| 12604 | } |
| 12605 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12606 | if (!childHasIdentityMatrix && !useDisplayListProperties) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12607 | canvas.translate(-transX, -transY); |
| 12608 | canvas.concat(getMatrix()); |
| 12609 | canvas.translate(transX, transY); |
| 12610 | } |
| 12611 | } |
| 12612 | |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12613 | if (alpha < 1) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12614 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12615 | if (hasNoCache) { |
| 12616 | final int multipliedAlpha = (int) (255 * alpha); |
| 12617 | if (!onSetAlpha(multipliedAlpha)) { |
| 12618 | int layerFlags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12619 | if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) != 0 || |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12620 | layerType != LAYER_TYPE_NONE) { |
| 12621 | layerFlags |= Canvas.CLIP_TO_LAYER_SAVE_FLAG; |
| 12622 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12623 | if (useDisplayListProperties) { |
| 12624 | displayList.setAlpha(alpha * getAlpha()); |
| 12625 | } else if (layerType == LAYER_TYPE_NONE) { |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 12626 | final int scrollX = hasDisplayList ? 0 : sx; |
| 12627 | final int scrollY = hasDisplayList ? 0 : sy; |
| 12628 | canvas.saveLayerAlpha(scrollX, scrollY, scrollX + mRight - mLeft, |
| 12629 | scrollY + mBottom - mTop, multipliedAlpha, layerFlags); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12630 | } |
| 12631 | } else { |
| 12632 | // Alpha is handled by the child directly, clobber the layer's alpha |
| 12633 | mPrivateFlags |= ALPHA_SET; |
| 12634 | } |
| 12635 | } |
| 12636 | } |
| 12637 | } else if ((mPrivateFlags & ALPHA_SET) == ALPHA_SET) { |
| 12638 | onSetAlpha(255); |
| 12639 | mPrivateFlags &= ~ALPHA_SET; |
| 12640 | } |
| 12641 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12642 | if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) == ViewGroup.FLAG_CLIP_CHILDREN && |
| 12643 | !useDisplayListProperties) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12644 | if (offsetForScroll) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12645 | canvas.clipRect(sx, sy, sx + (mRight - mLeft), sy + (mBottom - mTop)); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12646 | } else { |
| 12647 | if (!scalingRequired || cache == null) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12648 | canvas.clipRect(0, 0, mRight - mLeft, mBottom - mTop); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12649 | } else { |
| 12650 | canvas.clipRect(0, 0, cache.getWidth(), cache.getHeight()); |
| 12651 | } |
| 12652 | } |
| 12653 | } |
| 12654 | |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12655 | if (!useDisplayListProperties && hasDisplayList) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12656 | displayList = getDisplayList(); |
| 12657 | if (!displayList.isValid()) { |
| 12658 | // Uncommon, but possible. If a view is removed from the hierarchy during the call |
| 12659 | // to getDisplayList(), the display list will be marked invalid and we should not |
| 12660 | // try to use it again. |
| 12661 | displayList = null; |
| 12662 | hasDisplayList = false; |
| 12663 | } |
| 12664 | } |
| 12665 | |
| 12666 | if (hasNoCache) { |
| 12667 | boolean layerRendered = false; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12668 | if (layerType == LAYER_TYPE_HARDWARE && !useDisplayListProperties) { |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 12669 | final HardwareLayer layer = getHardwareLayer(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12670 | if (layer != null && layer.isValid()) { |
| 12671 | mLayerPaint.setAlpha((int) (alpha * 255)); |
| 12672 | ((HardwareCanvas) canvas).drawHardwareLayer(layer, 0, 0, mLayerPaint); |
| 12673 | layerRendered = true; |
| 12674 | } else { |
| 12675 | final int scrollX = hasDisplayList ? 0 : sx; |
| 12676 | final int scrollY = hasDisplayList ? 0 : sy; |
| 12677 | canvas.saveLayer(scrollX, scrollY, |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12678 | scrollX + mRight - mLeft, scrollY + mBottom - mTop, mLayerPaint, |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12679 | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); |
| 12680 | } |
| 12681 | } |
| 12682 | |
| 12683 | if (!layerRendered) { |
| 12684 | if (!hasDisplayList) { |
| 12685 | // Fast path for layouts with no backgrounds |
| 12686 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 12687 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12688 | ViewDebug.trace(parent, ViewDebug.HierarchyTraceType.DRAW); |
| 12689 | } |
| 12690 | mPrivateFlags &= ~DIRTY_MASK; |
| 12691 | dispatchDraw(canvas); |
| 12692 | } else { |
| 12693 | draw(canvas); |
| 12694 | } |
| 12695 | } else { |
| 12696 | mPrivateFlags &= ~DIRTY_MASK; |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12697 | ((HardwareCanvas) canvas).drawDisplayList(displayList, |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 12698 | mRight - mLeft, mBottom - mTop, null, flags); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12699 | } |
| 12700 | } |
| 12701 | } else if (cache != null) { |
| 12702 | mPrivateFlags &= ~DIRTY_MASK; |
| 12703 | Paint cachePaint; |
| 12704 | |
| 12705 | if (layerType == LAYER_TYPE_NONE) { |
| 12706 | cachePaint = parent.mCachePaint; |
| 12707 | if (cachePaint == null) { |
| 12708 | cachePaint = new Paint(); |
| 12709 | cachePaint.setDither(false); |
| 12710 | parent.mCachePaint = cachePaint; |
| 12711 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12712 | if (alpha < 1) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12713 | cachePaint.setAlpha((int) (alpha * 255)); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12714 | parent.mGroupFlags |= ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE; |
| 12715 | } else if ((flags & ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE) != 0) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12716 | cachePaint.setAlpha(255); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12717 | parent.mGroupFlags &= ~ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12718 | } |
| 12719 | } else { |
| 12720 | cachePaint = mLayerPaint; |
| 12721 | cachePaint.setAlpha((int) (alpha * 255)); |
| 12722 | } |
| 12723 | canvas.drawBitmap(cache, 0.0f, 0.0f, cachePaint); |
| 12724 | } |
| 12725 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12726 | if (restoreTo >= 0) { |
| 12727 | canvas.restoreToCount(restoreTo); |
| 12728 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12729 | |
| 12730 | if (a != null && !more) { |
| 12731 | if (!hardwareAccelerated && !a.getFillAfter()) { |
| 12732 | onSetAlpha(255); |
| 12733 | } |
| 12734 | parent.finishAnimatingView(this, a); |
| 12735 | } |
| 12736 | |
| 12737 | if (more && hardwareAccelerated) { |
| 12738 | // invalidation is the trigger to recreate display lists, so if we're using |
| 12739 | // display lists to render, force an invalidate to allow the animation to |
| 12740 | // continue drawing another frame |
| 12741 | parent.invalidate(true); |
| 12742 | if (a.hasAlpha() && (mPrivateFlags & ALPHA_SET) == ALPHA_SET) { |
| 12743 | // alpha animations should cause the child to recreate its display list |
| 12744 | invalidate(true); |
| 12745 | } |
| 12746 | } |
| 12747 | |
| 12748 | mRecreateDisplayList = false; |
| 12749 | |
| 12750 | return more; |
| 12751 | } |
| 12752 | |
| 12753 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12754 | * Manually render this view (and all of its children) to the given Canvas. |
| 12755 | * 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] | 12756 | * called. When implementing a view, implement |
| 12757 | * {@link #onDraw(android.graphics.Canvas)} instead of overriding this method. |
| 12758 | * 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] | 12759 | * |
| 12760 | * @param canvas The Canvas to which the View is rendered. |
| 12761 | */ |
| 12762 | public void draw(Canvas canvas) { |
| 12763 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12764 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW); |
| 12765 | } |
| 12766 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12767 | final int privateFlags = mPrivateFlags; |
| 12768 | final boolean dirtyOpaque = (privateFlags & DIRTY_MASK) == DIRTY_OPAQUE && |
| 12769 | (mAttachInfo == null || !mAttachInfo.mIgnoreDirtyState); |
| 12770 | mPrivateFlags = (privateFlags & ~DIRTY_MASK) | DRAWN; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12771 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12772 | /* |
| 12773 | * Draw traversal performs several drawing steps which must be executed |
| 12774 | * in the appropriate order: |
| 12775 | * |
| 12776 | * 1. Draw the background |
| 12777 | * 2. If necessary, save the canvas' layers to prepare for fading |
| 12778 | * 3. Draw view's content |
| 12779 | * 4. Draw children |
| 12780 | * 5. If necessary, draw the fading edges and restore layers |
| 12781 | * 6. Draw decorations (scrollbars for instance) |
| 12782 | */ |
| 12783 | |
| 12784 | // Step 1, draw the background, if needed |
| 12785 | int saveCount; |
| 12786 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12787 | if (!dirtyOpaque) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12788 | final Drawable background = mBackground; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12789 | if (background != null) { |
| 12790 | final int scrollX = mScrollX; |
| 12791 | final int scrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12792 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12793 | if (mBackgroundSizeChanged) { |
| 12794 | background.setBounds(0, 0, mRight - mLeft, mBottom - mTop); |
| 12795 | mBackgroundSizeChanged = false; |
| 12796 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12797 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12798 | if ((scrollX | scrollY) == 0) { |
| 12799 | background.draw(canvas); |
| 12800 | } else { |
| 12801 | canvas.translate(scrollX, scrollY); |
| 12802 | background.draw(canvas); |
| 12803 | canvas.translate(-scrollX, -scrollY); |
| 12804 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12805 | } |
| 12806 | } |
| 12807 | |
| 12808 | // skip step 2 & 5 if possible (common case) |
| 12809 | final int viewFlags = mViewFlags; |
| 12810 | boolean horizontalEdges = (viewFlags & FADING_EDGE_HORIZONTAL) != 0; |
| 12811 | boolean verticalEdges = (viewFlags & FADING_EDGE_VERTICAL) != 0; |
| 12812 | if (!verticalEdges && !horizontalEdges) { |
| 12813 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12814 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12815 | |
| 12816 | // Step 4, draw the children |
| 12817 | dispatchDraw(canvas); |
| 12818 | |
| 12819 | // Step 6, draw decorations (scrollbars) |
| 12820 | onDrawScrollBars(canvas); |
| 12821 | |
| 12822 | // we're done... |
| 12823 | return; |
| 12824 | } |
| 12825 | |
| 12826 | /* |
| 12827 | * Here we do the full fledged routine... |
| 12828 | * (this is an uncommon case where speed matters less, |
| 12829 | * this is why we repeat some of the tests that have been |
| 12830 | * done above) |
| 12831 | */ |
| 12832 | |
| 12833 | boolean drawTop = false; |
| 12834 | boolean drawBottom = false; |
| 12835 | boolean drawLeft = false; |
| 12836 | boolean drawRight = false; |
| 12837 | |
| 12838 | float topFadeStrength = 0.0f; |
| 12839 | float bottomFadeStrength = 0.0f; |
| 12840 | float leftFadeStrength = 0.0f; |
| 12841 | float rightFadeStrength = 0.0f; |
| 12842 | |
| 12843 | // Step 2, save the canvas' layers |
| 12844 | int paddingLeft = mPaddingLeft; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12845 | |
| 12846 | final boolean offsetRequired = isPaddingOffsetRequired(); |
| 12847 | if (offsetRequired) { |
| 12848 | paddingLeft += getLeftPaddingOffset(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12849 | } |
| 12850 | |
| 12851 | int left = mScrollX + paddingLeft; |
| 12852 | int right = left + mRight - mLeft - mPaddingRight - paddingLeft; |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 12853 | int top = mScrollY + getFadeTop(offsetRequired); |
| 12854 | int bottom = top + getFadeHeight(offsetRequired); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12855 | |
| 12856 | if (offsetRequired) { |
| 12857 | right += getRightPaddingOffset(); |
| 12858 | bottom += getBottomPaddingOffset(); |
| 12859 | } |
| 12860 | |
| 12861 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12862 | final float fadeHeight = scrollabilityCache.fadingEdgeLength; |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12863 | int length = (int) fadeHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12864 | |
| 12865 | // clip the fade length if top and bottom fades overlap |
| 12866 | // overlapping fades produce odd-looking artifacts |
| 12867 | if (verticalEdges && (top + length > bottom - length)) { |
| 12868 | length = (bottom - top) / 2; |
| 12869 | } |
| 12870 | |
| 12871 | // also clip horizontal fades if necessary |
| 12872 | if (horizontalEdges && (left + length > right - length)) { |
| 12873 | length = (right - left) / 2; |
| 12874 | } |
| 12875 | |
| 12876 | if (verticalEdges) { |
| 12877 | topFadeStrength = Math.max(0.0f, Math.min(1.0f, getTopFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12878 | drawTop = topFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12879 | bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, getBottomFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12880 | drawBottom = bottomFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12881 | } |
| 12882 | |
| 12883 | if (horizontalEdges) { |
| 12884 | leftFadeStrength = Math.max(0.0f, Math.min(1.0f, getLeftFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12885 | drawLeft = leftFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12886 | rightFadeStrength = Math.max(0.0f, Math.min(1.0f, getRightFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12887 | drawRight = rightFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12888 | } |
| 12889 | |
| 12890 | saveCount = canvas.getSaveCount(); |
| 12891 | |
| 12892 | int solidColor = getSolidColor(); |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 12893 | if (solidColor == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12894 | final int flags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
| 12895 | |
| 12896 | if (drawTop) { |
| 12897 | canvas.saveLayer(left, top, right, top + length, null, flags); |
| 12898 | } |
| 12899 | |
| 12900 | if (drawBottom) { |
| 12901 | canvas.saveLayer(left, bottom - length, right, bottom, null, flags); |
| 12902 | } |
| 12903 | |
| 12904 | if (drawLeft) { |
| 12905 | canvas.saveLayer(left, top, left + length, bottom, null, flags); |
| 12906 | } |
| 12907 | |
| 12908 | if (drawRight) { |
| 12909 | canvas.saveLayer(right - length, top, right, bottom, null, flags); |
| 12910 | } |
| 12911 | } else { |
| 12912 | scrollabilityCache.setFadeColor(solidColor); |
| 12913 | } |
| 12914 | |
| 12915 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12916 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12917 | |
| 12918 | // Step 4, draw the children |
| 12919 | dispatchDraw(canvas); |
| 12920 | |
| 12921 | // Step 5, draw the fade effect and restore layers |
| 12922 | final Paint p = scrollabilityCache.paint; |
| 12923 | final Matrix matrix = scrollabilityCache.matrix; |
| 12924 | final Shader fade = scrollabilityCache.shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12925 | |
| 12926 | if (drawTop) { |
| 12927 | matrix.setScale(1, fadeHeight * topFadeStrength); |
| 12928 | matrix.postTranslate(left, top); |
| 12929 | fade.setLocalMatrix(matrix); |
| 12930 | canvas.drawRect(left, top, right, top + length, p); |
| 12931 | } |
| 12932 | |
| 12933 | if (drawBottom) { |
| 12934 | matrix.setScale(1, fadeHeight * bottomFadeStrength); |
| 12935 | matrix.postRotate(180); |
| 12936 | matrix.postTranslate(left, bottom); |
| 12937 | fade.setLocalMatrix(matrix); |
| 12938 | canvas.drawRect(left, bottom - length, right, bottom, p); |
| 12939 | } |
| 12940 | |
| 12941 | if (drawLeft) { |
| 12942 | matrix.setScale(1, fadeHeight * leftFadeStrength); |
| 12943 | matrix.postRotate(-90); |
| 12944 | matrix.postTranslate(left, top); |
| 12945 | fade.setLocalMatrix(matrix); |
| 12946 | canvas.drawRect(left, top, left + length, bottom, p); |
| 12947 | } |
| 12948 | |
| 12949 | if (drawRight) { |
| 12950 | matrix.setScale(1, fadeHeight * rightFadeStrength); |
| 12951 | matrix.postRotate(90); |
| 12952 | matrix.postTranslate(right, top); |
| 12953 | fade.setLocalMatrix(matrix); |
| 12954 | canvas.drawRect(right - length, top, right, bottom, p); |
| 12955 | } |
| 12956 | |
| 12957 | canvas.restoreToCount(saveCount); |
| 12958 | |
| 12959 | // Step 6, draw decorations (scrollbars) |
| 12960 | onDrawScrollBars(canvas); |
| 12961 | } |
| 12962 | |
| 12963 | /** |
| 12964 | * Override this if your view is known to always be drawn on top of a solid color background, |
| 12965 | * and needs to draw fading edges. Returning a non-zero color enables the view system to |
| 12966 | * optimize the drawing of the fading edges. If you do return a non-zero color, the alpha |
| 12967 | * should be set to 0xFF. |
| 12968 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12969 | * @see #setVerticalFadingEdgeEnabled(boolean) |
| 12970 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12971 | * |
| 12972 | * @return The known solid color background for this view, or 0 if the color may vary |
| 12973 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12974 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12975 | public int getSolidColor() { |
| 12976 | return 0; |
| 12977 | } |
| 12978 | |
| 12979 | /** |
| 12980 | * Build a human readable string representation of the specified view flags. |
| 12981 | * |
| 12982 | * @param flags the view flags to convert to a string |
| 12983 | * @return a String representing the supplied flags |
| 12984 | */ |
| 12985 | private static String printFlags(int flags) { |
| 12986 | String output = ""; |
| 12987 | int numFlags = 0; |
| 12988 | if ((flags & FOCUSABLE_MASK) == FOCUSABLE) { |
| 12989 | output += "TAKES_FOCUS"; |
| 12990 | numFlags++; |
| 12991 | } |
| 12992 | |
| 12993 | switch (flags & VISIBILITY_MASK) { |
| 12994 | case INVISIBLE: |
| 12995 | if (numFlags > 0) { |
| 12996 | output += " "; |
| 12997 | } |
| 12998 | output += "INVISIBLE"; |
| 12999 | // USELESS HERE numFlags++; |
| 13000 | break; |
| 13001 | case GONE: |
| 13002 | if (numFlags > 0) { |
| 13003 | output += " "; |
| 13004 | } |
| 13005 | output += "GONE"; |
| 13006 | // USELESS HERE numFlags++; |
| 13007 | break; |
| 13008 | default: |
| 13009 | break; |
| 13010 | } |
| 13011 | return output; |
| 13012 | } |
| 13013 | |
| 13014 | /** |
| 13015 | * Build a human readable string representation of the specified private |
| 13016 | * view flags. |
| 13017 | * |
| 13018 | * @param privateFlags the private view flags to convert to a string |
| 13019 | * @return a String representing the supplied flags |
| 13020 | */ |
| 13021 | private static String printPrivateFlags(int privateFlags) { |
| 13022 | String output = ""; |
| 13023 | int numFlags = 0; |
| 13024 | |
| 13025 | if ((privateFlags & WANTS_FOCUS) == WANTS_FOCUS) { |
| 13026 | output += "WANTS_FOCUS"; |
| 13027 | numFlags++; |
| 13028 | } |
| 13029 | |
| 13030 | if ((privateFlags & FOCUSED) == FOCUSED) { |
| 13031 | if (numFlags > 0) { |
| 13032 | output += " "; |
| 13033 | } |
| 13034 | output += "FOCUSED"; |
| 13035 | numFlags++; |
| 13036 | } |
| 13037 | |
| 13038 | if ((privateFlags & SELECTED) == SELECTED) { |
| 13039 | if (numFlags > 0) { |
| 13040 | output += " "; |
| 13041 | } |
| 13042 | output += "SELECTED"; |
| 13043 | numFlags++; |
| 13044 | } |
| 13045 | |
| 13046 | if ((privateFlags & IS_ROOT_NAMESPACE) == IS_ROOT_NAMESPACE) { |
| 13047 | if (numFlags > 0) { |
| 13048 | output += " "; |
| 13049 | } |
| 13050 | output += "IS_ROOT_NAMESPACE"; |
| 13051 | numFlags++; |
| 13052 | } |
| 13053 | |
| 13054 | if ((privateFlags & HAS_BOUNDS) == HAS_BOUNDS) { |
| 13055 | if (numFlags > 0) { |
| 13056 | output += " "; |
| 13057 | } |
| 13058 | output += "HAS_BOUNDS"; |
| 13059 | numFlags++; |
| 13060 | } |
| 13061 | |
| 13062 | if ((privateFlags & DRAWN) == DRAWN) { |
| 13063 | if (numFlags > 0) { |
| 13064 | output += " "; |
| 13065 | } |
| 13066 | output += "DRAWN"; |
| 13067 | // USELESS HERE numFlags++; |
| 13068 | } |
| 13069 | return output; |
| 13070 | } |
| 13071 | |
| 13072 | /** |
| 13073 | * <p>Indicates whether or not this view's layout will be requested during |
| 13074 | * the next hierarchy layout pass.</p> |
| 13075 | * |
| 13076 | * @return true if the layout will be forced during next layout pass |
| 13077 | */ |
| 13078 | public boolean isLayoutRequested() { |
| 13079 | return (mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT; |
| 13080 | } |
| 13081 | |
| 13082 | /** |
| 13083 | * Assign a size and position to a view and all of its |
| 13084 | * descendants |
| 13085 | * |
| 13086 | * <p>This is the second phase of the layout mechanism. |
| 13087 | * (The first is measuring). In this phase, each parent calls |
| 13088 | * layout on all of its children to position them. |
| 13089 | * This is typically done using the child measurements |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 13090 | * that were stored in the measure pass().</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13091 | * |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 13092 | * <p>Derived classes should not override this method. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13093 | * Derived classes with children should override |
| 13094 | * onLayout. In that method, they should |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 13095 | * call layout on each of their children.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13096 | * |
| 13097 | * @param l Left position, relative to parent |
| 13098 | * @param t Top position, relative to parent |
| 13099 | * @param r Right position, relative to parent |
| 13100 | * @param b Bottom position, relative to parent |
| 13101 | */ |
Romain Guy | 5429e1d | 2010-09-07 12:38:00 -0700 | [diff] [blame] | 13102 | @SuppressWarnings({"unchecked"}) |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 13103 | public void layout(int l, int t, int r, int b) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13104 | int oldL = mLeft; |
| 13105 | int oldT = mTop; |
| 13106 | int oldB = mBottom; |
| 13107 | int oldR = mRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13108 | boolean changed = setFrame(l, t, r, b); |
| 13109 | if (changed || (mPrivateFlags & LAYOUT_REQUIRED) == LAYOUT_REQUIRED) { |
| 13110 | if (ViewDebug.TRACE_HIERARCHY) { |
| 13111 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_LAYOUT); |
| 13112 | } |
| 13113 | |
| 13114 | onLayout(changed, l, t, r, b); |
| 13115 | mPrivateFlags &= ~LAYOUT_REQUIRED; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13116 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 13117 | ListenerInfo li = mListenerInfo; |
| 13118 | if (li != null && li.mOnLayoutChangeListeners != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13119 | ArrayList<OnLayoutChangeListener> listenersCopy = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 13120 | (ArrayList<OnLayoutChangeListener>)li.mOnLayoutChangeListeners.clone(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13121 | int numListeners = listenersCopy.size(); |
| 13122 | for (int i = 0; i < numListeners; ++i) { |
Chet Haase | 7c608f2 | 2010-10-22 17:54:04 -0700 | [diff] [blame] | 13123 | 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] | 13124 | } |
| 13125 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13126 | } |
| 13127 | mPrivateFlags &= ~FORCE_LAYOUT; |
| 13128 | } |
| 13129 | |
| 13130 | /** |
| 13131 | * Called from layout when this view should |
| 13132 | * assign a size and position to each of its children. |
| 13133 | * |
| 13134 | * Derived classes with children should override |
| 13135 | * this method and call layout on each of |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13136 | * their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13137 | * @param changed This is a new size or position for this view |
| 13138 | * @param left Left position, relative to parent |
| 13139 | * @param top Top position, relative to parent |
| 13140 | * @param right Right position, relative to parent |
| 13141 | * @param bottom Bottom position, relative to parent |
| 13142 | */ |
| 13143 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 13144 | } |
| 13145 | |
| 13146 | /** |
| 13147 | * Assign a size and position to this view. |
| 13148 | * |
| 13149 | * This is called from layout. |
| 13150 | * |
| 13151 | * @param left Left position, relative to parent |
| 13152 | * @param top Top position, relative to parent |
| 13153 | * @param right Right position, relative to parent |
| 13154 | * @param bottom Bottom position, relative to parent |
| 13155 | * @return true if the new size and position are different than the |
| 13156 | * previous ones |
| 13157 | * {@hide} |
| 13158 | */ |
| 13159 | protected boolean setFrame(int left, int top, int right, int bottom) { |
| 13160 | boolean changed = false; |
| 13161 | |
| 13162 | if (DBG) { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 13163 | Log.d("View", this + " View.setFrame(" + left + "," + top + "," |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13164 | + right + "," + bottom + ")"); |
| 13165 | } |
| 13166 | |
| 13167 | if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) { |
| 13168 | changed = true; |
| 13169 | |
| 13170 | // Remember our drawn bit |
| 13171 | int drawn = mPrivateFlags & DRAWN; |
| 13172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13173 | int oldWidth = mRight - mLeft; |
| 13174 | int oldHeight = mBottom - mTop; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 13175 | int newWidth = right - left; |
| 13176 | int newHeight = bottom - top; |
| 13177 | boolean sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight); |
| 13178 | |
| 13179 | // Invalidate our old position |
| 13180 | invalidate(sizeChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13181 | |
| 13182 | mLeft = left; |
| 13183 | mTop = top; |
| 13184 | mRight = right; |
| 13185 | mBottom = bottom; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13186 | if (USE_DISPLAY_LIST_PROPERTIES && mDisplayList != null) { |
| 13187 | mDisplayList.setLeftTopRightBottom(mLeft, mTop, mRight, mBottom); |
| 13188 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13189 | |
| 13190 | mPrivateFlags |= HAS_BOUNDS; |
| 13191 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13192 | |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 13193 | if (sizeChanged) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 13194 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 13195 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 13196 | if (mTransformationInfo != null) { |
| 13197 | mTransformationInfo.mMatrixDirty = true; |
| 13198 | } |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 13199 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13200 | onSizeChanged(newWidth, newHeight, oldWidth, oldHeight); |
| 13201 | } |
| 13202 | |
| 13203 | if ((mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 13204 | // If we are visible, force the DRAWN bit to on so that |
| 13205 | // this invalidate will go through (at least to our parent). |
| 13206 | // This is because someone may have invalidated this view |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 13207 | // before this call to setFrame came in, thereby clearing |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13208 | // the DRAWN bit. |
| 13209 | mPrivateFlags |= DRAWN; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 13210 | invalidate(sizeChanged); |
Chet Haase | f28595e | 2011-01-31 18:52:12 -0800 | [diff] [blame] | 13211 | // parent display list may need to be recreated based on a change in the bounds |
| 13212 | // of any child |
| 13213 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13214 | } |
| 13215 | |
| 13216 | // Reset drawn bit to original value (invalidate turns it off) |
| 13217 | mPrivateFlags |= drawn; |
| 13218 | |
| 13219 | mBackgroundSizeChanged = true; |
| 13220 | } |
| 13221 | return changed; |
| 13222 | } |
| 13223 | |
| 13224 | /** |
| 13225 | * Finalize inflating a view from XML. This is called as the last phase |
| 13226 | * of inflation, after all child views have been added. |
| 13227 | * |
| 13228 | * <p>Even if the subclass overrides onFinishInflate, they should always be |
| 13229 | * sure to call the super method, so that we get called. |
| 13230 | */ |
| 13231 | protected void onFinishInflate() { |
| 13232 | } |
| 13233 | |
| 13234 | /** |
| 13235 | * Returns the resources associated with this view. |
| 13236 | * |
| 13237 | * @return Resources object. |
| 13238 | */ |
| 13239 | public Resources getResources() { |
| 13240 | return mResources; |
| 13241 | } |
| 13242 | |
| 13243 | /** |
| 13244 | * Invalidates the specified Drawable. |
| 13245 | * |
| 13246 | * @param drawable the drawable to invalidate |
| 13247 | */ |
| 13248 | public void invalidateDrawable(Drawable drawable) { |
| 13249 | if (verifyDrawable(drawable)) { |
| 13250 | final Rect dirty = drawable.getBounds(); |
| 13251 | final int scrollX = mScrollX; |
| 13252 | final int scrollY = mScrollY; |
| 13253 | |
| 13254 | invalidate(dirty.left + scrollX, dirty.top + scrollY, |
| 13255 | dirty.right + scrollX, dirty.bottom + scrollY); |
| 13256 | } |
| 13257 | } |
| 13258 | |
| 13259 | /** |
| 13260 | * Schedules an action on a drawable to occur at a specified time. |
| 13261 | * |
| 13262 | * @param who the recipient of the action |
| 13263 | * @param what the action to run on the drawable |
| 13264 | * @param when the time at which the action must occur. Uses the |
| 13265 | * {@link SystemClock#uptimeMillis} timebase. |
| 13266 | */ |
| 13267 | public void scheduleDrawable(Drawable who, Runnable what, long when) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13268 | if (verifyDrawable(who) && what != null) { |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 13269 | final long delay = when - SystemClock.uptimeMillis(); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13270 | if (mAttachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 13271 | mAttachInfo.mViewRootImpl.mChoreographer.postCallbackDelayed( |
| 13272 | Choreographer.CALLBACK_ANIMATION, what, who, |
| 13273 | Choreographer.subtractFrameDelay(delay)); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13274 | } else { |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 13275 | ViewRootImpl.getRunQueue().postDelayed(what, delay); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13276 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13277 | } |
| 13278 | } |
| 13279 | |
| 13280 | /** |
| 13281 | * Cancels a scheduled action on a drawable. |
| 13282 | * |
| 13283 | * @param who the recipient of the action |
| 13284 | * @param what the action to cancel |
| 13285 | */ |
| 13286 | public void unscheduleDrawable(Drawable who, Runnable what) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13287 | if (verifyDrawable(who) && what != null) { |
| 13288 | if (mAttachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 13289 | mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 13290 | Choreographer.CALLBACK_ANIMATION, what, who); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13291 | } else { |
| 13292 | ViewRootImpl.getRunQueue().removeCallbacks(what); |
| 13293 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13294 | } |
| 13295 | } |
| 13296 | |
| 13297 | /** |
| 13298 | * Unschedule any events associated with the given Drawable. This can be |
| 13299 | * used when selecting a new Drawable into a view, so that the previous |
| 13300 | * one is completely unscheduled. |
| 13301 | * |
| 13302 | * @param who The Drawable to unschedule. |
| 13303 | * |
| 13304 | * @see #drawableStateChanged |
| 13305 | */ |
| 13306 | public void unscheduleDrawable(Drawable who) { |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 13307 | if (mAttachInfo != null && who != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 13308 | mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 13309 | Choreographer.CALLBACK_ANIMATION, null, who); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13310 | } |
| 13311 | } |
| 13312 | |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 13313 | /** |
| 13314 | * Return the layout direction of a given Drawable. |
| 13315 | * |
| 13316 | * @param who the Drawable to query |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 13317 | */ |
| 13318 | public int getResolvedLayoutDirection(Drawable who) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13319 | return (who == mBackground) ? getResolvedLayoutDirection() : LAYOUT_DIRECTION_DEFAULT; |
Fabrice Di Meglio | 6a03640 | 2011-05-23 14:43:23 -0700 | [diff] [blame] | 13320 | } |
| 13321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13322 | /** |
| 13323 | * If your view subclass is displaying its own Drawable objects, it should |
| 13324 | * override this function and return true for any Drawable it is |
| 13325 | * displaying. This allows animations for those drawables to be |
| 13326 | * scheduled. |
| 13327 | * |
| 13328 | * <p>Be sure to call through to the super class when overriding this |
| 13329 | * function. |
| 13330 | * |
| 13331 | * @param who The Drawable to verify. Return true if it is one you are |
| 13332 | * displaying, else return the result of calling through to the |
| 13333 | * super class. |
| 13334 | * |
| 13335 | * @return boolean If true than the Drawable is being displayed in the |
| 13336 | * view; else false and it is not allowed to animate. |
| 13337 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13338 | * @see #unscheduleDrawable(android.graphics.drawable.Drawable) |
| 13339 | * @see #drawableStateChanged() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13340 | */ |
| 13341 | protected boolean verifyDrawable(Drawable who) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13342 | return who == mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13343 | } |
| 13344 | |
| 13345 | /** |
| 13346 | * This function is called whenever the state of the view changes in such |
| 13347 | * a way that it impacts the state of drawables being shown. |
| 13348 | * |
| 13349 | * <p>Be sure to call through to the superclass when overriding this |
| 13350 | * function. |
| 13351 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13352 | * @see Drawable#setState(int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13353 | */ |
| 13354 | protected void drawableStateChanged() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13355 | Drawable d = mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13356 | if (d != null && d.isStateful()) { |
| 13357 | d.setState(getDrawableState()); |
| 13358 | } |
| 13359 | } |
| 13360 | |
| 13361 | /** |
| 13362 | * Call this to force a view to update its drawable state. This will cause |
| 13363 | * drawableStateChanged to be called on this view. Views that are interested |
| 13364 | * in the new state should call getDrawableState. |
| 13365 | * |
| 13366 | * @see #drawableStateChanged |
| 13367 | * @see #getDrawableState |
| 13368 | */ |
| 13369 | public void refreshDrawableState() { |
| 13370 | mPrivateFlags |= DRAWABLE_STATE_DIRTY; |
| 13371 | drawableStateChanged(); |
| 13372 | |
| 13373 | ViewParent parent = mParent; |
| 13374 | if (parent != null) { |
| 13375 | parent.childDrawableStateChanged(this); |
| 13376 | } |
| 13377 | } |
| 13378 | |
| 13379 | /** |
| 13380 | * Return an array of resource IDs of the drawable states representing the |
| 13381 | * current state of the view. |
| 13382 | * |
| 13383 | * @return The current drawable state |
| 13384 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13385 | * @see Drawable#setState(int[]) |
| 13386 | * @see #drawableStateChanged() |
| 13387 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13388 | */ |
| 13389 | public final int[] getDrawableState() { |
| 13390 | if ((mDrawableState != null) && ((mPrivateFlags & DRAWABLE_STATE_DIRTY) == 0)) { |
| 13391 | return mDrawableState; |
| 13392 | } else { |
| 13393 | mDrawableState = onCreateDrawableState(0); |
| 13394 | mPrivateFlags &= ~DRAWABLE_STATE_DIRTY; |
| 13395 | return mDrawableState; |
| 13396 | } |
| 13397 | } |
| 13398 | |
| 13399 | /** |
| 13400 | * Generate the new {@link android.graphics.drawable.Drawable} state for |
| 13401 | * this view. This is called by the view |
| 13402 | * system when the cached Drawable state is determined to be invalid. To |
| 13403 | * retrieve the current state, you should use {@link #getDrawableState}. |
| 13404 | * |
| 13405 | * @param extraSpace if non-zero, this is the number of extra entries you |
| 13406 | * would like in the returned array in which you can place your own |
| 13407 | * states. |
| 13408 | * |
| 13409 | * @return Returns an array holding the current {@link Drawable} state of |
| 13410 | * the view. |
| 13411 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13412 | * @see #mergeDrawableStates(int[], int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13413 | */ |
| 13414 | protected int[] onCreateDrawableState(int extraSpace) { |
| 13415 | if ((mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE && |
| 13416 | mParent instanceof View) { |
| 13417 | return ((View) mParent).onCreateDrawableState(extraSpace); |
| 13418 | } |
| 13419 | |
| 13420 | int[] drawableState; |
| 13421 | |
| 13422 | int privateFlags = mPrivateFlags; |
| 13423 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 13424 | int viewStateIndex = 0; |
| 13425 | if ((privateFlags & PRESSED) != 0) viewStateIndex |= VIEW_STATE_PRESSED; |
| 13426 | if ((mViewFlags & ENABLED_MASK) == ENABLED) viewStateIndex |= VIEW_STATE_ENABLED; |
| 13427 | if (isFocused()) viewStateIndex |= VIEW_STATE_FOCUSED; |
Neel Parekh | e537858 | 2010-10-06 11:36:50 -0700 | [diff] [blame] | 13428 | if ((privateFlags & SELECTED) != 0) viewStateIndex |= VIEW_STATE_SELECTED; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 13429 | if (hasWindowFocus()) viewStateIndex |= VIEW_STATE_WINDOW_FOCUSED; |
| 13430 | if ((privateFlags & ACTIVATED) != 0) viewStateIndex |= VIEW_STATE_ACTIVATED; |
Adam Powell | 5a7e94e | 2011-04-25 15:30:43 -0700 | [diff] [blame] | 13431 | if (mAttachInfo != null && mAttachInfo.mHardwareAccelerationRequested && |
| 13432 | HardwareRenderer.isAvailable()) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 13433 | // This is set if HW acceleration is requested, even if the current |
| 13434 | // process doesn't allow it. This is just to allow app preview |
| 13435 | // windows to better match their app. |
| 13436 | viewStateIndex |= VIEW_STATE_ACCELERATED; |
| 13437 | } |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 13438 | if ((privateFlags & HOVERED) != 0) viewStateIndex |= VIEW_STATE_HOVERED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13439 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 13440 | final int privateFlags2 = mPrivateFlags2; |
| 13441 | if ((privateFlags2 & DRAG_CAN_ACCEPT) != 0) viewStateIndex |= VIEW_STATE_DRAG_CAN_ACCEPT; |
| 13442 | if ((privateFlags2 & DRAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_DRAG_HOVERED; |
| 13443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13444 | drawableState = VIEW_STATE_SETS[viewStateIndex]; |
| 13445 | |
| 13446 | //noinspection ConstantIfStatement |
| 13447 | if (false) { |
| 13448 | Log.i("View", "drawableStateIndex=" + viewStateIndex); |
| 13449 | Log.i("View", toString() |
| 13450 | + " pressed=" + ((privateFlags & PRESSED) != 0) |
| 13451 | + " en=" + ((mViewFlags & ENABLED_MASK) == ENABLED) |
| 13452 | + " fo=" + hasFocus() |
| 13453 | + " sl=" + ((privateFlags & SELECTED) != 0) |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 13454 | + " wf=" + hasWindowFocus() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13455 | + ": " + Arrays.toString(drawableState)); |
| 13456 | } |
| 13457 | |
| 13458 | if (extraSpace == 0) { |
| 13459 | return drawableState; |
| 13460 | } |
| 13461 | |
| 13462 | final int[] fullState; |
| 13463 | if (drawableState != null) { |
| 13464 | fullState = new int[drawableState.length + extraSpace]; |
| 13465 | System.arraycopy(drawableState, 0, fullState, 0, drawableState.length); |
| 13466 | } else { |
| 13467 | fullState = new int[extraSpace]; |
| 13468 | } |
| 13469 | |
| 13470 | return fullState; |
| 13471 | } |
| 13472 | |
| 13473 | /** |
| 13474 | * Merge your own state values in <var>additionalState</var> into the base |
| 13475 | * state values <var>baseState</var> that were returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 13476 | * {@link #onCreateDrawableState(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13477 | * |
| 13478 | * @param baseState The base state values returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 13479 | * {@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] | 13480 | * own additional state values. |
| 13481 | * |
| 13482 | * @param additionalState The additional state values you would like |
| 13483 | * added to <var>baseState</var>; this array is not modified. |
| 13484 | * |
| 13485 | * @return As a convenience, the <var>baseState</var> array you originally |
| 13486 | * passed into the function is returned. |
| 13487 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13488 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13489 | */ |
| 13490 | protected static int[] mergeDrawableStates(int[] baseState, int[] additionalState) { |
| 13491 | final int N = baseState.length; |
| 13492 | int i = N - 1; |
| 13493 | while (i >= 0 && baseState[i] == 0) { |
| 13494 | i--; |
| 13495 | } |
| 13496 | System.arraycopy(additionalState, 0, baseState, i + 1, additionalState.length); |
| 13497 | return baseState; |
| 13498 | } |
| 13499 | |
| 13500 | /** |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 13501 | * Call {@link Drawable#jumpToCurrentState() Drawable.jumpToCurrentState()} |
| 13502 | * on all Drawable objects associated with this view. |
| 13503 | */ |
| 13504 | public void jumpDrawablesToCurrentState() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13505 | if (mBackground != null) { |
| 13506 | mBackground.jumpToCurrentState(); |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 13507 | } |
| 13508 | } |
| 13509 | |
| 13510 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13511 | * Sets the background color for this view. |
| 13512 | * @param color the color of the background |
| 13513 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 13514 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13515 | public void setBackgroundColor(int color) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13516 | if (mBackground instanceof ColorDrawable) { |
| 13517 | ((ColorDrawable) mBackground).setColor(color); |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 13518 | } else { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13519 | setBackground(new ColorDrawable(color)); |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 13520 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13521 | } |
| 13522 | |
| 13523 | /** |
| 13524 | * Set the background to a given resource. The resource should refer to |
Wink Saville | 7cd88e1 | 2009-08-04 14:45:10 -0700 | [diff] [blame] | 13525 | * a Drawable object or 0 to remove the background. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13526 | * @param resid The identifier of the resource. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13527 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13528 | * @attr ref android.R.styleable#View_background |
| 13529 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 13530 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13531 | public void setBackgroundResource(int resid) { |
| 13532 | if (resid != 0 && resid == mBackgroundResource) { |
| 13533 | return; |
| 13534 | } |
| 13535 | |
| 13536 | Drawable d= null; |
| 13537 | if (resid != 0) { |
| 13538 | d = mResources.getDrawable(resid); |
| 13539 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13540 | setBackground(d); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13541 | |
| 13542 | mBackgroundResource = resid; |
| 13543 | } |
| 13544 | |
| 13545 | /** |
| 13546 | * Set the background to a given Drawable, or remove the background. If the |
| 13547 | * background has padding, this View's padding is set to the background's |
| 13548 | * padding. However, when a background is removed, this View's padding isn't |
| 13549 | * touched. If setting the padding is desired, please use |
| 13550 | * {@link #setPadding(int, int, int, int)}. |
| 13551 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13552 | * @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] | 13553 | * background |
| 13554 | */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13555 | public void setBackground(Drawable background) { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 13556 | //noinspection deprecation |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13557 | setBackgroundDrawable(background); |
| 13558 | } |
| 13559 | |
| 13560 | /** |
| 13561 | * @deprecated use {@link #setBackground(Drawable)} instead |
| 13562 | */ |
| 13563 | @Deprecated |
| 13564 | public void setBackgroundDrawable(Drawable background) { |
| 13565 | if (background == mBackground) { |
Adam Powell | 4d36ec1 | 2011-07-17 16:44:16 -0700 | [diff] [blame] | 13566 | return; |
| 13567 | } |
| 13568 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13569 | boolean requestLayout = false; |
| 13570 | |
| 13571 | mBackgroundResource = 0; |
| 13572 | |
| 13573 | /* |
| 13574 | * Regardless of whether we're setting a new background or not, we want |
| 13575 | * to clear the previous drawable. |
| 13576 | */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13577 | if (mBackground != null) { |
| 13578 | mBackground.setCallback(null); |
| 13579 | unscheduleDrawable(mBackground); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13580 | } |
| 13581 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13582 | if (background != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13583 | Rect padding = sThreadLocal.get(); |
| 13584 | if (padding == null) { |
| 13585 | padding = new Rect(); |
| 13586 | sThreadLocal.set(padding); |
| 13587 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13588 | if (background.getPadding(padding)) { |
| 13589 | switch (background.getResolvedLayoutDirectionSelf()) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13590 | case LAYOUT_DIRECTION_RTL: |
| 13591 | setPadding(padding.right, padding.top, padding.left, padding.bottom); |
| 13592 | break; |
| 13593 | case LAYOUT_DIRECTION_LTR: |
| 13594 | default: |
| 13595 | setPadding(padding.left, padding.top, padding.right, padding.bottom); |
| 13596 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13597 | } |
| 13598 | |
| 13599 | // Compare the minimum sizes of the old Drawable and the new. If there isn't an old or |
| 13600 | // if it has a different minimum size, we should layout again |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13601 | if (mBackground == null || mBackground.getMinimumHeight() != background.getMinimumHeight() || |
| 13602 | mBackground.getMinimumWidth() != background.getMinimumWidth()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13603 | requestLayout = true; |
| 13604 | } |
| 13605 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13606 | background.setCallback(this); |
| 13607 | if (background.isStateful()) { |
| 13608 | background.setState(getDrawableState()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13609 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13610 | background.setVisible(getVisibility() == VISIBLE, false); |
| 13611 | mBackground = background; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13612 | |
| 13613 | if ((mPrivateFlags & SKIP_DRAW) != 0) { |
| 13614 | mPrivateFlags &= ~SKIP_DRAW; |
| 13615 | mPrivateFlags |= ONLY_DRAWS_BACKGROUND; |
| 13616 | requestLayout = true; |
| 13617 | } |
| 13618 | } else { |
| 13619 | /* Remove the background */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13620 | mBackground = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13621 | |
| 13622 | if ((mPrivateFlags & ONLY_DRAWS_BACKGROUND) != 0) { |
| 13623 | /* |
| 13624 | * This view ONLY drew the background before and we're removing |
| 13625 | * the background, so now it won't draw anything |
| 13626 | * (hence we SKIP_DRAW) |
| 13627 | */ |
| 13628 | mPrivateFlags &= ~ONLY_DRAWS_BACKGROUND; |
| 13629 | mPrivateFlags |= SKIP_DRAW; |
| 13630 | } |
| 13631 | |
| 13632 | /* |
| 13633 | * When the background is set, we try to apply its padding to this |
| 13634 | * View. When the background is removed, we don't touch this View's |
| 13635 | * padding. This is noted in the Javadocs. Hence, we don't need to |
| 13636 | * requestLayout(), the invalidate() below is sufficient. |
| 13637 | */ |
| 13638 | |
| 13639 | // The old background's minimum size could have affected this |
| 13640 | // View's layout, so let's requestLayout |
| 13641 | requestLayout = true; |
| 13642 | } |
| 13643 | |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 13644 | computeOpaqueFlags(); |
| 13645 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13646 | if (requestLayout) { |
| 13647 | requestLayout(); |
| 13648 | } |
| 13649 | |
| 13650 | mBackgroundSizeChanged = true; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 13651 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13652 | } |
| 13653 | |
| 13654 | /** |
| 13655 | * Gets the background drawable |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13656 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13657 | * @return The drawable used as the background for this view, if any. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13658 | * |
| 13659 | * @see #setBackground(Drawable) |
| 13660 | * |
| 13661 | * @attr ref android.R.styleable#View_background |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13662 | */ |
| 13663 | public Drawable getBackground() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13664 | return mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13665 | } |
| 13666 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13667 | /** |
| 13668 | * Sets the padding. The view may add on the space required to display |
| 13669 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 13670 | * So the values returned from {@link #getPaddingLeft}, {@link #getPaddingTop}, |
| 13671 | * {@link #getPaddingRight} and {@link #getPaddingBottom} may be different |
| 13672 | * from the values set in this call. |
| 13673 | * |
| 13674 | * @attr ref android.R.styleable#View_padding |
| 13675 | * @attr ref android.R.styleable#View_paddingBottom |
| 13676 | * @attr ref android.R.styleable#View_paddingLeft |
| 13677 | * @attr ref android.R.styleable#View_paddingRight |
| 13678 | * @attr ref android.R.styleable#View_paddingTop |
| 13679 | * @param left the left padding in pixels |
| 13680 | * @param top the top padding in pixels |
| 13681 | * @param right the right padding in pixels |
| 13682 | * @param bottom the bottom padding in pixels |
| 13683 | */ |
| 13684 | public void setPadding(int left, int top, int right, int bottom) { |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13685 | mUserPaddingStart = -1; |
| 13686 | mUserPaddingEnd = -1; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13687 | mUserPaddingRelative = false; |
| 13688 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13689 | internalSetPadding(left, top, right, bottom); |
| 13690 | } |
| 13691 | |
| 13692 | private void internalSetPadding(int left, int top, int right, int bottom) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 13693 | mUserPaddingLeft = left; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13694 | mUserPaddingRight = right; |
| 13695 | mUserPaddingBottom = bottom; |
| 13696 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13697 | final int viewFlags = mViewFlags; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13698 | boolean changed = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13699 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13700 | // Common case is there are no scroll bars. |
| 13701 | if ((viewFlags & (SCROLLBARS_VERTICAL|SCROLLBARS_HORIZONTAL)) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13702 | if ((viewFlags & SCROLLBARS_VERTICAL) != 0) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 13703 | final int offset = (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13704 | ? 0 : getVerticalScrollbarWidth(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 13705 | switch (mVerticalScrollbarPosition) { |
| 13706 | case SCROLLBAR_POSITION_DEFAULT: |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13707 | if (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
| 13708 | left += offset; |
| 13709 | } else { |
| 13710 | right += offset; |
| 13711 | } |
| 13712 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 13713 | case SCROLLBAR_POSITION_RIGHT: |
| 13714 | right += offset; |
| 13715 | break; |
| 13716 | case SCROLLBAR_POSITION_LEFT: |
| 13717 | left += offset; |
| 13718 | break; |
| 13719 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13720 | } |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 13721 | if ((viewFlags & SCROLLBARS_HORIZONTAL) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13722 | bottom += (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
| 13723 | ? 0 : getHorizontalScrollbarHeight(); |
| 13724 | } |
| 13725 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13726 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13727 | if (mPaddingLeft != left) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13728 | changed = true; |
| 13729 | mPaddingLeft = left; |
| 13730 | } |
| 13731 | if (mPaddingTop != top) { |
| 13732 | changed = true; |
| 13733 | mPaddingTop = top; |
| 13734 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13735 | if (mPaddingRight != right) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13736 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13737 | mPaddingRight = right; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13738 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13739 | if (mPaddingBottom != bottom) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13740 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13741 | mPaddingBottom = bottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13742 | } |
| 13743 | |
| 13744 | if (changed) { |
| 13745 | requestLayout(); |
| 13746 | } |
| 13747 | } |
| 13748 | |
| 13749 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13750 | * Sets the relative padding. The view may add on the space required to display |
| 13751 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 13752 | * So the values returned from {@link #getPaddingStart}, {@link #getPaddingTop}, |
| 13753 | * {@link #getPaddingEnd} and {@link #getPaddingBottom} may be different |
| 13754 | * from the values set in this call. |
| 13755 | * |
| 13756 | * @attr ref android.R.styleable#View_padding |
| 13757 | * @attr ref android.R.styleable#View_paddingBottom |
| 13758 | * @attr ref android.R.styleable#View_paddingStart |
| 13759 | * @attr ref android.R.styleable#View_paddingEnd |
| 13760 | * @attr ref android.R.styleable#View_paddingTop |
| 13761 | * @param start the start padding in pixels |
| 13762 | * @param top the top padding in pixels |
| 13763 | * @param end the end padding in pixels |
| 13764 | * @param bottom the bottom padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13765 | */ |
| 13766 | public void setPaddingRelative(int start, int top, int end, int bottom) { |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 13767 | mUserPaddingStart = start; |
| 13768 | mUserPaddingEnd = end; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13769 | mUserPaddingRelative = true; |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 13770 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13771 | switch(getResolvedLayoutDirection()) { |
| 13772 | case LAYOUT_DIRECTION_RTL: |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13773 | internalSetPadding(end, top, start, bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13774 | break; |
| 13775 | case LAYOUT_DIRECTION_LTR: |
| 13776 | default: |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13777 | internalSetPadding(start, top, end, bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13778 | } |
| 13779 | } |
| 13780 | |
| 13781 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13782 | * Returns the top padding of this view. |
| 13783 | * |
| 13784 | * @return the top padding in pixels |
| 13785 | */ |
| 13786 | public int getPaddingTop() { |
| 13787 | return mPaddingTop; |
| 13788 | } |
| 13789 | |
| 13790 | /** |
| 13791 | * Returns the bottom padding of this view. If there are inset and enabled |
| 13792 | * scrollbars, this value may include the space required to display the |
| 13793 | * scrollbars as well. |
| 13794 | * |
| 13795 | * @return the bottom padding in pixels |
| 13796 | */ |
| 13797 | public int getPaddingBottom() { |
| 13798 | return mPaddingBottom; |
| 13799 | } |
| 13800 | |
| 13801 | /** |
| 13802 | * Returns the left padding of this view. If there are inset and enabled |
| 13803 | * scrollbars, this value may include the space required to display the |
| 13804 | * scrollbars as well. |
| 13805 | * |
| 13806 | * @return the left padding in pixels |
| 13807 | */ |
| 13808 | public int getPaddingLeft() { |
| 13809 | return mPaddingLeft; |
| 13810 | } |
| 13811 | |
| 13812 | /** |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 13813 | * Returns the start padding of this view depending on its resolved layout direction. |
| 13814 | * If there are inset and enabled scrollbars, this value may include the space |
| 13815 | * required to display the scrollbars as well. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13816 | * |
| 13817 | * @return the start padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13818 | */ |
| 13819 | public int getPaddingStart() { |
| 13820 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
| 13821 | mPaddingRight : mPaddingLeft; |
| 13822 | } |
| 13823 | |
| 13824 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13825 | * Returns the right padding of this view. If there are inset and enabled |
| 13826 | * scrollbars, this value may include the space required to display the |
| 13827 | * scrollbars as well. |
| 13828 | * |
| 13829 | * @return the right padding in pixels |
| 13830 | */ |
| 13831 | public int getPaddingRight() { |
| 13832 | return mPaddingRight; |
| 13833 | } |
| 13834 | |
| 13835 | /** |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 13836 | * Returns the end padding of this view depending on its resolved layout direction. |
| 13837 | * If there are inset and enabled scrollbars, this value may include the space |
| 13838 | * required to display the scrollbars as well. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13839 | * |
| 13840 | * @return the end padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13841 | */ |
| 13842 | public int getPaddingEnd() { |
| 13843 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
| 13844 | mPaddingLeft : mPaddingRight; |
| 13845 | } |
| 13846 | |
| 13847 | /** |
| 13848 | * Return if the padding as been set thru relative values |
| 13849 | * {@link #setPaddingRelative(int, int, int, int)} or thru |
| 13850 | * @attr ref android.R.styleable#View_paddingStart or |
| 13851 | * @attr ref android.R.styleable#View_paddingEnd |
| 13852 | * |
| 13853 | * @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] | 13854 | */ |
| 13855 | public boolean isPaddingRelative() { |
| 13856 | return mUserPaddingRelative; |
| 13857 | } |
| 13858 | |
| 13859 | /** |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 13860 | * @hide |
| 13861 | */ |
| 13862 | public Insets getLayoutInsets() { |
| 13863 | if (mLayoutInsets == null) { |
Philip Milne | bbd51f1 | 2012-04-18 15:09:05 -0700 | [diff] [blame] | 13864 | mLayoutInsets = (mBackground == null) ? Insets.NONE : mBackground.getLayoutInsets(); |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 13865 | } |
| 13866 | return mLayoutInsets; |
| 13867 | } |
| 13868 | |
| 13869 | /** |
| 13870 | * @hide |
| 13871 | */ |
| 13872 | public void setLayoutInsets(Insets layoutInsets) { |
| 13873 | mLayoutInsets = layoutInsets; |
| 13874 | } |
| 13875 | |
| 13876 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13877 | * Changes the selection state of this view. A view can be selected or not. |
| 13878 | * Note that selection is not the same as focus. Views are typically |
| 13879 | * selected in the context of an AdapterView like ListView or GridView; |
| 13880 | * the selected view is the view that is highlighted. |
| 13881 | * |
| 13882 | * @param selected true if the view must be selected, false otherwise |
| 13883 | */ |
| 13884 | public void setSelected(boolean selected) { |
| 13885 | if (((mPrivateFlags & SELECTED) != 0) != selected) { |
| 13886 | mPrivateFlags = (mPrivateFlags & ~SELECTED) | (selected ? SELECTED : 0); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 13887 | if (!selected) resetPressedState(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 13888 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13889 | refreshDrawableState(); |
| 13890 | dispatchSetSelected(selected); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 13891 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 13892 | notifyAccessibilityStateChanged(); |
| 13893 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13894 | } |
| 13895 | } |
| 13896 | |
| 13897 | /** |
| 13898 | * Dispatch setSelected to all of this View's children. |
| 13899 | * |
| 13900 | * @see #setSelected(boolean) |
| 13901 | * |
| 13902 | * @param selected The new selected state |
| 13903 | */ |
| 13904 | protected void dispatchSetSelected(boolean selected) { |
| 13905 | } |
| 13906 | |
| 13907 | /** |
| 13908 | * Indicates the selection state of this view. |
| 13909 | * |
| 13910 | * @return true if the view is selected, false otherwise |
| 13911 | */ |
| 13912 | @ViewDebug.ExportedProperty |
| 13913 | public boolean isSelected() { |
| 13914 | return (mPrivateFlags & SELECTED) != 0; |
| 13915 | } |
| 13916 | |
| 13917 | /** |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 13918 | * Changes the activated state of this view. A view can be activated or not. |
| 13919 | * Note that activation is not the same as selection. Selection is |
| 13920 | * a transient property, representing the view (hierarchy) the user is |
| 13921 | * currently interacting with. Activation is a longer-term state that the |
| 13922 | * user can move views in and out of. For example, in a list view with |
| 13923 | * single or multiple selection enabled, the views in the current selection |
| 13924 | * set are activated. (Um, yeah, we are deeply sorry about the terminology |
| 13925 | * here.) The activated state is propagated down to children of the view it |
| 13926 | * is set on. |
| 13927 | * |
| 13928 | * @param activated true if the view must be activated, false otherwise |
| 13929 | */ |
| 13930 | public void setActivated(boolean activated) { |
| 13931 | if (((mPrivateFlags & ACTIVATED) != 0) != activated) { |
| 13932 | mPrivateFlags = (mPrivateFlags & ~ACTIVATED) | (activated ? ACTIVATED : 0); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 13933 | invalidate(true); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 13934 | refreshDrawableState(); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 13935 | dispatchSetActivated(activated); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 13936 | } |
| 13937 | } |
| 13938 | |
| 13939 | /** |
| 13940 | * Dispatch setActivated to all of this View's children. |
| 13941 | * |
| 13942 | * @see #setActivated(boolean) |
| 13943 | * |
| 13944 | * @param activated The new activated state |
| 13945 | */ |
| 13946 | protected void dispatchSetActivated(boolean activated) { |
| 13947 | } |
| 13948 | |
| 13949 | /** |
| 13950 | * Indicates the activation state of this view. |
| 13951 | * |
| 13952 | * @return true if the view is activated, false otherwise |
| 13953 | */ |
| 13954 | @ViewDebug.ExportedProperty |
| 13955 | public boolean isActivated() { |
| 13956 | return (mPrivateFlags & ACTIVATED) != 0; |
| 13957 | } |
| 13958 | |
| 13959 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13960 | * Returns the ViewTreeObserver for this view's hierarchy. The view tree |
| 13961 | * observer can be used to get notifications when global events, like |
| 13962 | * layout, happen. |
| 13963 | * |
| 13964 | * The returned ViewTreeObserver observer is not guaranteed to remain |
| 13965 | * valid for the lifetime of this View. If the caller of this method keeps |
| 13966 | * a long-lived reference to ViewTreeObserver, it should always check for |
| 13967 | * the return value of {@link ViewTreeObserver#isAlive()}. |
| 13968 | * |
| 13969 | * @return The ViewTreeObserver for this view's hierarchy. |
| 13970 | */ |
| 13971 | public ViewTreeObserver getViewTreeObserver() { |
| 13972 | if (mAttachInfo != null) { |
| 13973 | return mAttachInfo.mTreeObserver; |
| 13974 | } |
| 13975 | if (mFloatingTreeObserver == null) { |
| 13976 | mFloatingTreeObserver = new ViewTreeObserver(); |
| 13977 | } |
| 13978 | return mFloatingTreeObserver; |
| 13979 | } |
| 13980 | |
| 13981 | /** |
| 13982 | * <p>Finds the topmost view in the current view hierarchy.</p> |
| 13983 | * |
| 13984 | * @return the topmost view containing this view |
| 13985 | */ |
| 13986 | public View getRootView() { |
| 13987 | if (mAttachInfo != null) { |
| 13988 | final View v = mAttachInfo.mRootView; |
| 13989 | if (v != null) { |
| 13990 | return v; |
| 13991 | } |
| 13992 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13993 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13994 | View parent = this; |
| 13995 | |
| 13996 | while (parent.mParent != null && parent.mParent instanceof View) { |
| 13997 | parent = (View) parent.mParent; |
| 13998 | } |
| 13999 | |
| 14000 | return parent; |
| 14001 | } |
| 14002 | |
| 14003 | /** |
| 14004 | * <p>Computes the coordinates of this view on the screen. The argument |
| 14005 | * must be an array of two integers. After the method returns, the array |
| 14006 | * contains the x and y location in that order.</p> |
| 14007 | * |
| 14008 | * @param location an array of two integers in which to hold the coordinates |
| 14009 | */ |
| 14010 | public void getLocationOnScreen(int[] location) { |
| 14011 | getLocationInWindow(location); |
| 14012 | |
| 14013 | final AttachInfo info = mAttachInfo; |
Romain Guy | 779398e | 2009-06-16 13:17:50 -0700 | [diff] [blame] | 14014 | if (info != null) { |
| 14015 | location[0] += info.mWindowLeft; |
| 14016 | location[1] += info.mWindowTop; |
| 14017 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14018 | } |
| 14019 | |
| 14020 | /** |
| 14021 | * <p>Computes the coordinates of this view in its window. The argument |
| 14022 | * must be an array of two integers. After the method returns, the array |
| 14023 | * contains the x and y location in that order.</p> |
| 14024 | * |
| 14025 | * @param location an array of two integers in which to hold the coordinates |
| 14026 | */ |
| 14027 | public void getLocationInWindow(int[] location) { |
| 14028 | if (location == null || location.length < 2) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14029 | 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] | 14030 | } |
| 14031 | |
Gilles Debunne | 6583ce5 | 2011-12-06 18:09:02 -0800 | [diff] [blame] | 14032 | if (mAttachInfo == null) { |
| 14033 | // When the view is not attached to a window, this method does not make sense |
| 14034 | location[0] = location[1] = 0; |
| 14035 | return; |
| 14036 | } |
| 14037 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14038 | float[] position = mAttachInfo.mTmpTransformLocation; |
| 14039 | position[0] = position[1] = 0.0f; |
| 14040 | |
| 14041 | if (!hasIdentityMatrix()) { |
| 14042 | getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 14043 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14044 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14045 | position[0] += mLeft; |
| 14046 | position[1] += mTop; |
| 14047 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14048 | ViewParent viewParent = mParent; |
| 14049 | while (viewParent instanceof View) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14050 | final View view = (View) viewParent; |
| 14051 | |
| 14052 | position[0] -= view.mScrollX; |
| 14053 | position[1] -= view.mScrollY; |
| 14054 | |
| 14055 | if (!view.hasIdentityMatrix()) { |
| 14056 | view.getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 14057 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14058 | |
| 14059 | position[0] += view.mLeft; |
| 14060 | position[1] += view.mTop; |
| 14061 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14062 | viewParent = view.mParent; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 14063 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14064 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 14065 | if (viewParent instanceof ViewRootImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14066 | // *cough* |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14067 | final ViewRootImpl vr = (ViewRootImpl) viewParent; |
| 14068 | position[1] -= vr.mCurScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14069 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14070 | |
| 14071 | location[0] = (int) (position[0] + 0.5f); |
| 14072 | location[1] = (int) (position[1] + 0.5f); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14073 | } |
| 14074 | |
| 14075 | /** |
| 14076 | * {@hide} |
| 14077 | * @param id the id of the view to be found |
| 14078 | * @return the view of the specified id, null if cannot be found |
| 14079 | */ |
| 14080 | protected View findViewTraversal(int id) { |
| 14081 | if (id == mID) { |
| 14082 | return this; |
| 14083 | } |
| 14084 | return null; |
| 14085 | } |
| 14086 | |
| 14087 | /** |
| 14088 | * {@hide} |
| 14089 | * @param tag the tag of the view to be found |
| 14090 | * @return the view of specified tag, null if cannot be found |
| 14091 | */ |
| 14092 | protected View findViewWithTagTraversal(Object tag) { |
| 14093 | if (tag != null && tag.equals(mTag)) { |
| 14094 | return this; |
| 14095 | } |
| 14096 | return null; |
| 14097 | } |
| 14098 | |
| 14099 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 14100 | * {@hide} |
| 14101 | * @param predicate The predicate to evaluate. |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 14102 | * @param childToSkip If not null, ignores this child during the recursive traversal. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 14103 | * @return The first view that matches the predicate or null. |
| 14104 | */ |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 14105 | protected View findViewByPredicateTraversal(Predicate<View> predicate, View childToSkip) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 14106 | if (predicate.apply(this)) { |
| 14107 | return this; |
| 14108 | } |
| 14109 | return null; |
| 14110 | } |
| 14111 | |
| 14112 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14113 | * Look for a child view with the given id. If this view has the given |
| 14114 | * id, return this view. |
| 14115 | * |
| 14116 | * @param id The id to search for. |
| 14117 | * @return The view that has the given id in the hierarchy or null |
| 14118 | */ |
| 14119 | public final View findViewById(int id) { |
| 14120 | if (id < 0) { |
| 14121 | return null; |
| 14122 | } |
| 14123 | return findViewTraversal(id); |
| 14124 | } |
| 14125 | |
| 14126 | /** |
Svetoslav Ganov | 2cdedff | 2011-10-03 14:18:42 -0700 | [diff] [blame] | 14127 | * Finds a view by its unuque and stable accessibility id. |
| 14128 | * |
| 14129 | * @param accessibilityId The searched accessibility id. |
| 14130 | * @return The found view. |
| 14131 | */ |
| 14132 | final View findViewByAccessibilityId(int accessibilityId) { |
| 14133 | if (accessibilityId < 0) { |
| 14134 | return null; |
| 14135 | } |
| 14136 | return findViewByAccessibilityIdTraversal(accessibilityId); |
| 14137 | } |
| 14138 | |
| 14139 | /** |
| 14140 | * Performs the traversal to find a view by its unuque and stable accessibility id. |
| 14141 | * |
| 14142 | * <strong>Note:</strong>This method does not stop at the root namespace |
| 14143 | * boundary since the user can touch the screen at an arbitrary location |
| 14144 | * potentially crossing the root namespace bounday which will send an |
| 14145 | * accessibility event to accessibility services and they should be able |
| 14146 | * to obtain the event source. Also accessibility ids are guaranteed to be |
| 14147 | * unique in the window. |
| 14148 | * |
| 14149 | * @param accessibilityId The accessibility id. |
| 14150 | * @return The found view. |
| 14151 | */ |
| 14152 | View findViewByAccessibilityIdTraversal(int accessibilityId) { |
| 14153 | if (getAccessibilityViewId() == accessibilityId) { |
| 14154 | return this; |
| 14155 | } |
| 14156 | return null; |
| 14157 | } |
| 14158 | |
| 14159 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14160 | * Look for a child view with the given tag. If this view has the given |
| 14161 | * tag, return this view. |
| 14162 | * |
| 14163 | * @param tag The tag to search for, using "tag.equals(getTag())". |
| 14164 | * @return The View that has the given tag in the hierarchy or null |
| 14165 | */ |
| 14166 | public final View findViewWithTag(Object tag) { |
| 14167 | if (tag == null) { |
| 14168 | return null; |
| 14169 | } |
| 14170 | return findViewWithTagTraversal(tag); |
| 14171 | } |
| 14172 | |
| 14173 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 14174 | * {@hide} |
| 14175 | * Look for a child view that matches the specified predicate. |
| 14176 | * If this view matches the predicate, return this view. |
| 14177 | * |
| 14178 | * @param predicate The predicate to evaluate. |
| 14179 | * @return The first view that matches the predicate or null. |
| 14180 | */ |
| 14181 | public final View findViewByPredicate(Predicate<View> predicate) { |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 14182 | return findViewByPredicateTraversal(predicate, null); |
| 14183 | } |
| 14184 | |
| 14185 | /** |
| 14186 | * {@hide} |
| 14187 | * Look for a child view that matches the specified predicate, |
| 14188 | * starting with the specified view and its descendents and then |
| 14189 | * recusively searching the ancestors and siblings of that view |
| 14190 | * until this view is reached. |
| 14191 | * |
| 14192 | * This method is useful in cases where the predicate does not match |
| 14193 | * a single unique view (perhaps multiple views use the same id) |
| 14194 | * and we are trying to find the view that is "closest" in scope to the |
| 14195 | * starting view. |
| 14196 | * |
| 14197 | * @param start The view to start from. |
| 14198 | * @param predicate The predicate to evaluate. |
| 14199 | * @return The first view that matches the predicate or null. |
| 14200 | */ |
| 14201 | public final View findViewByPredicateInsideOut(View start, Predicate<View> predicate) { |
| 14202 | View childToSkip = null; |
| 14203 | for (;;) { |
| 14204 | View view = start.findViewByPredicateTraversal(predicate, childToSkip); |
| 14205 | if (view != null || start == this) { |
| 14206 | return view; |
| 14207 | } |
| 14208 | |
| 14209 | ViewParent parent = start.getParent(); |
| 14210 | if (parent == null || !(parent instanceof View)) { |
| 14211 | return null; |
| 14212 | } |
| 14213 | |
| 14214 | childToSkip = start; |
| 14215 | start = (View) parent; |
| 14216 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 14217 | } |
| 14218 | |
| 14219 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14220 | * Sets the identifier for this view. The identifier does not have to be |
| 14221 | * unique in this view's hierarchy. The identifier should be a positive |
| 14222 | * number. |
| 14223 | * |
| 14224 | * @see #NO_ID |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14225 | * @see #getId() |
| 14226 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14227 | * |
| 14228 | * @param id a number used to identify the view |
| 14229 | * |
| 14230 | * @attr ref android.R.styleable#View_id |
| 14231 | */ |
| 14232 | public void setId(int id) { |
| 14233 | mID = id; |
| 14234 | } |
| 14235 | |
| 14236 | /** |
| 14237 | * {@hide} |
| 14238 | * |
| 14239 | * @param isRoot true if the view belongs to the root namespace, false |
| 14240 | * otherwise |
| 14241 | */ |
| 14242 | public void setIsRootNamespace(boolean isRoot) { |
| 14243 | if (isRoot) { |
| 14244 | mPrivateFlags |= IS_ROOT_NAMESPACE; |
| 14245 | } else { |
| 14246 | mPrivateFlags &= ~IS_ROOT_NAMESPACE; |
| 14247 | } |
| 14248 | } |
| 14249 | |
| 14250 | /** |
| 14251 | * {@hide} |
| 14252 | * |
| 14253 | * @return true if the view belongs to the root namespace, false otherwise |
| 14254 | */ |
| 14255 | public boolean isRootNamespace() { |
| 14256 | return (mPrivateFlags&IS_ROOT_NAMESPACE) != 0; |
| 14257 | } |
| 14258 | |
| 14259 | /** |
| 14260 | * Returns this view's identifier. |
| 14261 | * |
| 14262 | * @return a positive integer used to identify the view or {@link #NO_ID} |
| 14263 | * if the view has no ID |
| 14264 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14265 | * @see #setId(int) |
| 14266 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14267 | * @attr ref android.R.styleable#View_id |
| 14268 | */ |
| 14269 | @ViewDebug.CapturedViewProperty |
| 14270 | public int getId() { |
| 14271 | return mID; |
| 14272 | } |
| 14273 | |
| 14274 | /** |
| 14275 | * Returns this view's tag. |
| 14276 | * |
| 14277 | * @return the Object stored in this view as a tag |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14278 | * |
| 14279 | * @see #setTag(Object) |
| 14280 | * @see #getTag(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14281 | */ |
| 14282 | @ViewDebug.ExportedProperty |
| 14283 | public Object getTag() { |
| 14284 | return mTag; |
| 14285 | } |
| 14286 | |
| 14287 | /** |
| 14288 | * Sets the tag associated with this view. A tag can be used to mark |
| 14289 | * a view in its hierarchy and does not have to be unique within the |
| 14290 | * hierarchy. Tags can also be used to store data within a view without |
| 14291 | * resorting to another data structure. |
| 14292 | * |
| 14293 | * @param tag an Object to tag the view with |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14294 | * |
| 14295 | * @see #getTag() |
| 14296 | * @see #setTag(int, Object) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14297 | */ |
| 14298 | public void setTag(final Object tag) { |
| 14299 | mTag = tag; |
| 14300 | } |
| 14301 | |
| 14302 | /** |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14303 | * Returns the tag associated with this view and the specified key. |
| 14304 | * |
| 14305 | * @param key The key identifying the tag |
| 14306 | * |
| 14307 | * @return the Object stored in this view as a tag |
| 14308 | * |
| 14309 | * @see #setTag(int, Object) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14310 | * @see #getTag() |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14311 | */ |
| 14312 | public Object getTag(int key) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 14313 | if (mKeyedTags != null) return mKeyedTags.get(key); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14314 | return null; |
| 14315 | } |
| 14316 | |
| 14317 | /** |
| 14318 | * Sets a tag associated with this view and a key. A tag can be used |
| 14319 | * to mark a view in its hierarchy and does not have to be unique within |
| 14320 | * the hierarchy. Tags can also be used to store data within a view |
| 14321 | * without resorting to another data structure. |
| 14322 | * |
| 14323 | * 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] | 14324 | * application to ensure it is unique (see the <a |
| 14325 | * href={@docRoot}guide/topics/resources/more-resources.html#Id">ID resource type</a>). |
| 14326 | * Keys identified as belonging to |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14327 | * the Android framework or not associated with any package will cause |
| 14328 | * an {@link IllegalArgumentException} to be thrown. |
| 14329 | * |
| 14330 | * @param key The key identifying the tag |
| 14331 | * @param tag An Object to tag the view with |
| 14332 | * |
| 14333 | * @throws IllegalArgumentException If they specified key is not valid |
| 14334 | * |
| 14335 | * @see #setTag(Object) |
| 14336 | * @see #getTag(int) |
| 14337 | */ |
| 14338 | public void setTag(int key, final Object tag) { |
| 14339 | // If the package id is 0x00 or 0x01, it's either an undefined package |
| 14340 | // or a framework id |
| 14341 | if ((key >>> 24) < 2) { |
| 14342 | throw new IllegalArgumentException("The key must be an application-specific " |
| 14343 | + "resource id."); |
| 14344 | } |
| 14345 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 14346 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14347 | } |
| 14348 | |
| 14349 | /** |
| 14350 | * Variation of {@link #setTag(int, Object)} that enforces the key to be a |
| 14351 | * framework id. |
| 14352 | * |
| 14353 | * @hide |
| 14354 | */ |
| 14355 | public void setTagInternal(int key, Object tag) { |
| 14356 | if ((key >>> 24) != 0x1) { |
| 14357 | throw new IllegalArgumentException("The key must be a framework-specific " |
| 14358 | + "resource id."); |
| 14359 | } |
| 14360 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 14361 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14362 | } |
| 14363 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 14364 | private void setKeyedTag(int key, Object tag) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 14365 | if (mKeyedTags == null) { |
| 14366 | mKeyedTags = new SparseArray<Object>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14367 | } |
| 14368 | |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 14369 | mKeyedTags.put(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14370 | } |
| 14371 | |
| 14372 | /** |
Romain Guy | 13922e0 | 2009-05-12 17:56:14 -0700 | [diff] [blame] | 14373 | * @param consistency The type of consistency. See ViewDebug for more information. |
| 14374 | * |
| 14375 | * @hide |
| 14376 | */ |
| 14377 | protected boolean dispatchConsistencyCheck(int consistency) { |
| 14378 | return onConsistencyCheck(consistency); |
| 14379 | } |
| 14380 | |
| 14381 | /** |
| 14382 | * Method that subclasses should implement to check their consistency. The type of |
| 14383 | * consistency check is indicated by the bit field passed as a parameter. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14384 | * |
Romain Guy | 13922e0 | 2009-05-12 17:56:14 -0700 | [diff] [blame] | 14385 | * @param consistency The type of consistency. See ViewDebug for more information. |
| 14386 | * |
| 14387 | * @throws IllegalStateException if the view is in an inconsistent state. |
| 14388 | * |
| 14389 | * @hide |
| 14390 | */ |
| 14391 | protected boolean onConsistencyCheck(int consistency) { |
| 14392 | boolean result = true; |
| 14393 | |
| 14394 | final boolean checkLayout = (consistency & ViewDebug.CONSISTENCY_LAYOUT) != 0; |
| 14395 | final boolean checkDrawing = (consistency & ViewDebug.CONSISTENCY_DRAWING) != 0; |
| 14396 | |
| 14397 | if (checkLayout) { |
| 14398 | if (getParent() == null) { |
| 14399 | result = false; |
| 14400 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 14401 | "View " + this + " does not have a parent."); |
| 14402 | } |
| 14403 | |
| 14404 | if (mAttachInfo == null) { |
| 14405 | result = false; |
| 14406 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 14407 | "View " + this + " is not attached to a window."); |
| 14408 | } |
| 14409 | } |
| 14410 | |
| 14411 | if (checkDrawing) { |
| 14412 | // Do not check the DIRTY/DRAWN flags because views can call invalidate() |
| 14413 | // from their draw() method |
| 14414 | |
| 14415 | if ((mPrivateFlags & DRAWN) != DRAWN && |
| 14416 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) { |
| 14417 | result = false; |
| 14418 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 14419 | "View " + this + " was invalidated but its drawing cache is valid."); |
| 14420 | } |
| 14421 | } |
| 14422 | |
| 14423 | return result; |
| 14424 | } |
| 14425 | |
| 14426 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14427 | * Prints information about this view in the log output, with the tag |
| 14428 | * {@link #VIEW_LOG_TAG}. |
| 14429 | * |
| 14430 | * @hide |
| 14431 | */ |
| 14432 | public void debug() { |
| 14433 | debug(0); |
| 14434 | } |
| 14435 | |
| 14436 | /** |
| 14437 | * Prints information about this view in the log output, with the tag |
| 14438 | * {@link #VIEW_LOG_TAG}. Each line in the output is preceded with an |
| 14439 | * indentation defined by the <code>depth</code>. |
| 14440 | * |
| 14441 | * @param depth the indentation level |
| 14442 | * |
| 14443 | * @hide |
| 14444 | */ |
| 14445 | protected void debug(int depth) { |
| 14446 | String output = debugIndent(depth - 1); |
| 14447 | |
| 14448 | output += "+ " + this; |
| 14449 | int id = getId(); |
| 14450 | if (id != -1) { |
| 14451 | output += " (id=" + id + ")"; |
| 14452 | } |
| 14453 | Object tag = getTag(); |
| 14454 | if (tag != null) { |
| 14455 | output += " (tag=" + tag + ")"; |
| 14456 | } |
| 14457 | Log.d(VIEW_LOG_TAG, output); |
| 14458 | |
| 14459 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 14460 | output = debugIndent(depth) + " FOCUSED"; |
| 14461 | Log.d(VIEW_LOG_TAG, output); |
| 14462 | } |
| 14463 | |
| 14464 | output = debugIndent(depth); |
| 14465 | output += "frame={" + mLeft + ", " + mTop + ", " + mRight |
| 14466 | + ", " + mBottom + "} scroll={" + mScrollX + ", " + mScrollY |
| 14467 | + "} "; |
| 14468 | Log.d(VIEW_LOG_TAG, output); |
| 14469 | |
| 14470 | if (mPaddingLeft != 0 || mPaddingTop != 0 || mPaddingRight != 0 |
| 14471 | || mPaddingBottom != 0) { |
| 14472 | output = debugIndent(depth); |
| 14473 | output += "padding={" + mPaddingLeft + ", " + mPaddingTop |
| 14474 | + ", " + mPaddingRight + ", " + mPaddingBottom + "}"; |
| 14475 | Log.d(VIEW_LOG_TAG, output); |
| 14476 | } |
| 14477 | |
| 14478 | output = debugIndent(depth); |
| 14479 | output += "mMeasureWidth=" + mMeasuredWidth + |
| 14480 | " mMeasureHeight=" + mMeasuredHeight; |
| 14481 | Log.d(VIEW_LOG_TAG, output); |
| 14482 | |
| 14483 | output = debugIndent(depth); |
| 14484 | if (mLayoutParams == null) { |
| 14485 | output += "BAD! no layout params"; |
| 14486 | } else { |
| 14487 | output = mLayoutParams.debug(output); |
| 14488 | } |
| 14489 | Log.d(VIEW_LOG_TAG, output); |
| 14490 | |
| 14491 | output = debugIndent(depth); |
| 14492 | output += "flags={"; |
| 14493 | output += View.printFlags(mViewFlags); |
| 14494 | output += "}"; |
| 14495 | Log.d(VIEW_LOG_TAG, output); |
| 14496 | |
| 14497 | output = debugIndent(depth); |
| 14498 | output += "privateFlags={"; |
| 14499 | output += View.printPrivateFlags(mPrivateFlags); |
| 14500 | output += "}"; |
| 14501 | Log.d(VIEW_LOG_TAG, output); |
| 14502 | } |
| 14503 | |
| 14504 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 14505 | * Creates a string of whitespaces used for indentation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14506 | * |
| 14507 | * @param depth the indentation level |
| 14508 | * @return a String containing (depth * 2 + 3) * 2 white spaces |
| 14509 | * |
| 14510 | * @hide |
| 14511 | */ |
| 14512 | protected static String debugIndent(int depth) { |
| 14513 | StringBuilder spaces = new StringBuilder((depth * 2 + 3) * 2); |
| 14514 | for (int i = 0; i < (depth * 2) + 3; i++) { |
| 14515 | spaces.append(' ').append(' '); |
| 14516 | } |
| 14517 | return spaces.toString(); |
| 14518 | } |
| 14519 | |
| 14520 | /** |
| 14521 | * <p>Return the offset of the widget's text baseline from the widget's top |
| 14522 | * boundary. If this widget does not support baseline alignment, this |
| 14523 | * method returns -1. </p> |
| 14524 | * |
| 14525 | * @return the offset of the baseline within the widget's bounds or -1 |
| 14526 | * if baseline alignment is not supported |
| 14527 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 14528 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14529 | public int getBaseline() { |
| 14530 | return -1; |
| 14531 | } |
| 14532 | |
| 14533 | /** |
| 14534 | * Call this when something has changed which has invalidated the |
| 14535 | * layout of this view. This will schedule a layout pass of the view |
| 14536 | * tree. |
| 14537 | */ |
| 14538 | public void requestLayout() { |
| 14539 | if (ViewDebug.TRACE_HIERARCHY) { |
| 14540 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.REQUEST_LAYOUT); |
| 14541 | } |
| 14542 | |
| 14543 | mPrivateFlags |= FORCE_LAYOUT; |
Chet Haase | 5af048c | 2011-01-24 17:00:32 -0800 | [diff] [blame] | 14544 | mPrivateFlags |= INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14545 | |
Fabrice Di Meglio | 4a526885 | 2012-03-30 15:56:48 -0700 | [diff] [blame] | 14546 | if (mLayoutParams != null) { |
| 14547 | mLayoutParams.onResolveLayoutDirection(getResolvedLayoutDirection()); |
| 14548 | } |
| 14549 | |
| 14550 | if (mParent != null && !mParent.isLayoutRequested()) { |
| 14551 | mParent.requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14552 | } |
| 14553 | } |
| 14554 | |
| 14555 | /** |
| 14556 | * Forces this view to be laid out during the next layout pass. |
| 14557 | * This method does not call requestLayout() or forceLayout() |
| 14558 | * on the parent. |
| 14559 | */ |
| 14560 | public void forceLayout() { |
| 14561 | mPrivateFlags |= FORCE_LAYOUT; |
Chet Haase | 5af048c | 2011-01-24 17:00:32 -0800 | [diff] [blame] | 14562 | mPrivateFlags |= INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14563 | } |
| 14564 | |
| 14565 | /** |
| 14566 | * <p> |
| 14567 | * This is called to find out how big a view should be. The parent |
| 14568 | * supplies constraint information in the width and height parameters. |
| 14569 | * </p> |
| 14570 | * |
| 14571 | * <p> |
Romain Guy | 967e2bf | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 14572 | * 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] | 14573 | * {@link #onMeasure(int, int)}, called by this method. Therefore, only |
Romain Guy | 967e2bf | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 14574 | * {@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] | 14575 | * </p> |
| 14576 | * |
| 14577 | * |
| 14578 | * @param widthMeasureSpec Horizontal space requirements as imposed by the |
| 14579 | * parent |
| 14580 | * @param heightMeasureSpec Vertical space requirements as imposed by the |
| 14581 | * parent |
| 14582 | * |
| 14583 | * @see #onMeasure(int, int) |
| 14584 | */ |
| 14585 | public final void measure(int widthMeasureSpec, int heightMeasureSpec) { |
| 14586 | if ((mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT || |
| 14587 | widthMeasureSpec != mOldWidthMeasureSpec || |
| 14588 | heightMeasureSpec != mOldHeightMeasureSpec) { |
| 14589 | |
| 14590 | // first clears the measured dimension flag |
| 14591 | mPrivateFlags &= ~MEASURED_DIMENSION_SET; |
| 14592 | |
| 14593 | if (ViewDebug.TRACE_HIERARCHY) { |
| 14594 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_MEASURE); |
| 14595 | } |
| 14596 | |
| 14597 | // measure ourselves, this should set the measured dimension flag back |
| 14598 | onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 14599 | |
| 14600 | // flag not set, setMeasuredDimension() was not invoked, we raise |
| 14601 | // an exception to warn the developer |
| 14602 | if ((mPrivateFlags & MEASURED_DIMENSION_SET) != MEASURED_DIMENSION_SET) { |
| 14603 | throw new IllegalStateException("onMeasure() did not set the" |
| 14604 | + " measured dimension by calling" |
| 14605 | + " setMeasuredDimension()"); |
| 14606 | } |
| 14607 | |
| 14608 | mPrivateFlags |= LAYOUT_REQUIRED; |
| 14609 | } |
| 14610 | |
| 14611 | mOldWidthMeasureSpec = widthMeasureSpec; |
| 14612 | mOldHeightMeasureSpec = heightMeasureSpec; |
| 14613 | } |
| 14614 | |
| 14615 | /** |
| 14616 | * <p> |
| 14617 | * Measure the view and its content to determine the measured width and the |
| 14618 | * measured height. This method is invoked by {@link #measure(int, int)} and |
| 14619 | * should be overriden by subclasses to provide accurate and efficient |
| 14620 | * measurement of their contents. |
| 14621 | * </p> |
| 14622 | * |
| 14623 | * <p> |
| 14624 | * <strong>CONTRACT:</strong> When overriding this method, you |
| 14625 | * <em>must</em> call {@link #setMeasuredDimension(int, int)} to store the |
| 14626 | * measured width and height of this view. Failure to do so will trigger an |
| 14627 | * <code>IllegalStateException</code>, thrown by |
| 14628 | * {@link #measure(int, int)}. Calling the superclass' |
| 14629 | * {@link #onMeasure(int, int)} is a valid use. |
| 14630 | * </p> |
| 14631 | * |
| 14632 | * <p> |
| 14633 | * The base class implementation of measure defaults to the background size, |
| 14634 | * unless a larger size is allowed by the MeasureSpec. Subclasses should |
| 14635 | * override {@link #onMeasure(int, int)} to provide better measurements of |
| 14636 | * their content. |
| 14637 | * </p> |
| 14638 | * |
| 14639 | * <p> |
| 14640 | * If this method is overridden, it is the subclass's responsibility to make |
| 14641 | * sure the measured height and width are at least the view's minimum height |
| 14642 | * and width ({@link #getSuggestedMinimumHeight()} and |
| 14643 | * {@link #getSuggestedMinimumWidth()}). |
| 14644 | * </p> |
| 14645 | * |
| 14646 | * @param widthMeasureSpec horizontal space requirements as imposed by the parent. |
| 14647 | * The requirements are encoded with |
| 14648 | * {@link android.view.View.MeasureSpec}. |
| 14649 | * @param heightMeasureSpec vertical space requirements as imposed by the parent. |
| 14650 | * The requirements are encoded with |
| 14651 | * {@link android.view.View.MeasureSpec}. |
| 14652 | * |
| 14653 | * @see #getMeasuredWidth() |
| 14654 | * @see #getMeasuredHeight() |
| 14655 | * @see #setMeasuredDimension(int, int) |
| 14656 | * @see #getSuggestedMinimumHeight() |
| 14657 | * @see #getSuggestedMinimumWidth() |
| 14658 | * @see android.view.View.MeasureSpec#getMode(int) |
| 14659 | * @see android.view.View.MeasureSpec#getSize(int) |
| 14660 | */ |
| 14661 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 14662 | setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), |
| 14663 | getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec)); |
| 14664 | } |
| 14665 | |
| 14666 | /** |
| 14667 | * <p>This mehod must be called by {@link #onMeasure(int, int)} to store the |
| 14668 | * measured width and measured height. Failing to do so will trigger an |
| 14669 | * exception at measurement time.</p> |
| 14670 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14671 | * @param measuredWidth The measured width of this view. May be a complex |
| 14672 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 14673 | * {@link #MEASURED_STATE_TOO_SMALL}. |
| 14674 | * @param measuredHeight The measured height of this view. May be a complex |
| 14675 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 14676 | * {@link #MEASURED_STATE_TOO_SMALL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14677 | */ |
| 14678 | protected final void setMeasuredDimension(int measuredWidth, int measuredHeight) { |
| 14679 | mMeasuredWidth = measuredWidth; |
| 14680 | mMeasuredHeight = measuredHeight; |
| 14681 | |
| 14682 | mPrivateFlags |= MEASURED_DIMENSION_SET; |
| 14683 | } |
| 14684 | |
| 14685 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14686 | * Merge two states as returned by {@link #getMeasuredState()}. |
| 14687 | * @param curState The current state as returned from a view or the result |
| 14688 | * of combining multiple views. |
| 14689 | * @param newState The new view state to combine. |
| 14690 | * @return Returns a new integer reflecting the combination of the two |
| 14691 | * states. |
| 14692 | */ |
| 14693 | public static int combineMeasuredStates(int curState, int newState) { |
| 14694 | return curState | newState; |
| 14695 | } |
| 14696 | |
| 14697 | /** |
| 14698 | * Version of {@link #resolveSizeAndState(int, int, int)} |
| 14699 | * returning only the {@link #MEASURED_SIZE_MASK} bits of the result. |
| 14700 | */ |
| 14701 | public static int resolveSize(int size, int measureSpec) { |
| 14702 | return resolveSizeAndState(size, measureSpec, 0) & MEASURED_SIZE_MASK; |
| 14703 | } |
| 14704 | |
| 14705 | /** |
| 14706 | * Utility to reconcile a desired size and state, with constraints imposed |
| 14707 | * by a MeasureSpec. Will take the desired size, unless a different size |
| 14708 | * is imposed by the constraints. The returned value is a compound integer, |
| 14709 | * with the resolved size in the {@link #MEASURED_SIZE_MASK} bits and |
| 14710 | * optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the resulting |
| 14711 | * 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] | 14712 | * |
| 14713 | * @param size How big the view wants to be |
| 14714 | * @param measureSpec Constraints imposed by the parent |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14715 | * @return Size information bit mask as defined by |
| 14716 | * {@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] | 14717 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14718 | 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] | 14719 | int result = size; |
| 14720 | int specMode = MeasureSpec.getMode(measureSpec); |
| 14721 | int specSize = MeasureSpec.getSize(measureSpec); |
| 14722 | switch (specMode) { |
| 14723 | case MeasureSpec.UNSPECIFIED: |
| 14724 | result = size; |
| 14725 | break; |
| 14726 | case MeasureSpec.AT_MOST: |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14727 | if (specSize < size) { |
| 14728 | result = specSize | MEASURED_STATE_TOO_SMALL; |
| 14729 | } else { |
| 14730 | result = size; |
| 14731 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14732 | break; |
| 14733 | case MeasureSpec.EXACTLY: |
| 14734 | result = specSize; |
| 14735 | break; |
| 14736 | } |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14737 | return result | (childMeasuredState&MEASURED_STATE_MASK); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14738 | } |
| 14739 | |
| 14740 | /** |
| 14741 | * Utility to return a default size. Uses the supplied size if the |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 14742 | * MeasureSpec imposed no constraints. Will get larger if allowed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14743 | * by the MeasureSpec. |
| 14744 | * |
| 14745 | * @param size Default size for this view |
| 14746 | * @param measureSpec Constraints imposed by the parent |
| 14747 | * @return The size this view should be. |
| 14748 | */ |
| 14749 | public static int getDefaultSize(int size, int measureSpec) { |
| 14750 | int result = size; |
| 14751 | int specMode = MeasureSpec.getMode(measureSpec); |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 14752 | int specSize = MeasureSpec.getSize(measureSpec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14753 | |
| 14754 | switch (specMode) { |
| 14755 | case MeasureSpec.UNSPECIFIED: |
| 14756 | result = size; |
| 14757 | break; |
| 14758 | case MeasureSpec.AT_MOST: |
| 14759 | case MeasureSpec.EXACTLY: |
| 14760 | result = specSize; |
| 14761 | break; |
| 14762 | } |
| 14763 | return result; |
| 14764 | } |
| 14765 | |
| 14766 | /** |
| 14767 | * Returns the suggested minimum height that the view should use. This |
| 14768 | * returns the maximum of the view's minimum height |
| 14769 | * and the background's minimum height |
| 14770 | * ({@link android.graphics.drawable.Drawable#getMinimumHeight()}). |
| 14771 | * <p> |
| 14772 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 14773 | * ensure the returned height is within the requirements of the parent. |
| 14774 | * |
| 14775 | * @return The suggested minimum height of the view. |
| 14776 | */ |
| 14777 | protected int getSuggestedMinimumHeight() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14778 | return (mBackground == null) ? mMinHeight : max(mMinHeight, mBackground.getMinimumHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14779 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14780 | } |
| 14781 | |
| 14782 | /** |
| 14783 | * Returns the suggested minimum width that the view should use. This |
| 14784 | * returns the maximum of the view's minimum width) |
| 14785 | * and the background's minimum width |
| 14786 | * ({@link android.graphics.drawable.Drawable#getMinimumWidth()}). |
| 14787 | * <p> |
| 14788 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 14789 | * ensure the returned width is within the requirements of the parent. |
| 14790 | * |
| 14791 | * @return The suggested minimum width of the view. |
| 14792 | */ |
| 14793 | protected int getSuggestedMinimumWidth() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14794 | return (mBackground == null) ? mMinWidth : max(mMinWidth, mBackground.getMinimumWidth()); |
| 14795 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14796 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14797 | /** |
| 14798 | * Returns the minimum height of the view. |
| 14799 | * |
| 14800 | * @return the minimum height the view will try to be. |
| 14801 | * |
| 14802 | * @see #setMinimumHeight(int) |
| 14803 | * |
| 14804 | * @attr ref android.R.styleable#View_minHeight |
| 14805 | */ |
| 14806 | public int getMinimumHeight() { |
| 14807 | return mMinHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14808 | } |
| 14809 | |
| 14810 | /** |
| 14811 | * Sets the minimum height of the view. It is not guaranteed the view will |
| 14812 | * be able to achieve this minimum height (for example, if its parent layout |
| 14813 | * constrains it with less available height). |
| 14814 | * |
| 14815 | * @param minHeight The minimum height the view will try to be. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14816 | * |
| 14817 | * @see #getMinimumHeight() |
| 14818 | * |
| 14819 | * @attr ref android.R.styleable#View_minHeight |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14820 | */ |
| 14821 | public void setMinimumHeight(int minHeight) { |
| 14822 | mMinHeight = minHeight; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14823 | requestLayout(); |
| 14824 | } |
| 14825 | |
| 14826 | /** |
| 14827 | * Returns the minimum width of the view. |
| 14828 | * |
| 14829 | * @return the minimum width the view will try to be. |
| 14830 | * |
| 14831 | * @see #setMinimumWidth(int) |
| 14832 | * |
| 14833 | * @attr ref android.R.styleable#View_minWidth |
| 14834 | */ |
| 14835 | public int getMinimumWidth() { |
| 14836 | return mMinWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14837 | } |
| 14838 | |
| 14839 | /** |
| 14840 | * Sets the minimum width of the view. It is not guaranteed the view will |
| 14841 | * be able to achieve this minimum width (for example, if its parent layout |
| 14842 | * constrains it with less available width). |
| 14843 | * |
| 14844 | * @param minWidth The minimum width the view will try to be. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14845 | * |
| 14846 | * @see #getMinimumWidth() |
| 14847 | * |
| 14848 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14849 | */ |
| 14850 | public void setMinimumWidth(int minWidth) { |
| 14851 | mMinWidth = minWidth; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14852 | requestLayout(); |
| 14853 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14854 | } |
| 14855 | |
| 14856 | /** |
| 14857 | * Get the animation currently associated with this view. |
| 14858 | * |
| 14859 | * @return The animation that is currently playing or |
| 14860 | * scheduled to play for this view. |
| 14861 | */ |
| 14862 | public Animation getAnimation() { |
| 14863 | return mCurrentAnimation; |
| 14864 | } |
| 14865 | |
| 14866 | /** |
| 14867 | * Start the specified animation now. |
| 14868 | * |
| 14869 | * @param animation the animation to start now |
| 14870 | */ |
| 14871 | public void startAnimation(Animation animation) { |
| 14872 | animation.setStartTime(Animation.START_ON_FIRST_FRAME); |
| 14873 | setAnimation(animation); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14874 | invalidateParentCaches(); |
| 14875 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14876 | } |
| 14877 | |
| 14878 | /** |
| 14879 | * Cancels any animations for this view. |
| 14880 | */ |
| 14881 | public void clearAnimation() { |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 14882 | if (mCurrentAnimation != null) { |
Romain Guy | b4a107d | 2010-02-09 18:50:08 -0800 | [diff] [blame] | 14883 | mCurrentAnimation.detach(); |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 14884 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14885 | mCurrentAnimation = null; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14886 | invalidateParentIfNeeded(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14887 | } |
| 14888 | |
| 14889 | /** |
| 14890 | * Sets the next animation to play for this view. |
| 14891 | * If you want the animation to play immediately, use |
| 14892 | * startAnimation. This method provides allows fine-grained |
| 14893 | * control over the start time and invalidation, but you |
| 14894 | * must make sure that 1) the animation has a start time set, and |
| 14895 | * 2) the view will be invalidated when the animation is supposed to |
| 14896 | * start. |
| 14897 | * |
| 14898 | * @param animation The next animation, or null. |
| 14899 | */ |
| 14900 | public void setAnimation(Animation animation) { |
| 14901 | mCurrentAnimation = animation; |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 14902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14903 | if (animation != null) { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 14904 | // If the screen is off assume the animation start time is now instead of |
| 14905 | // the next frame we draw. Keeping the START_ON_FIRST_FRAME start time |
| 14906 | // would cause the animation to start when the screen turns back on |
| 14907 | if (mAttachInfo != null && !mAttachInfo.mScreenOn && |
| 14908 | animation.getStartTime() == Animation.START_ON_FIRST_FRAME) { |
| 14909 | animation.setStartTime(AnimationUtils.currentAnimationTimeMillis()); |
| 14910 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14911 | animation.reset(); |
| 14912 | } |
| 14913 | } |
| 14914 | |
| 14915 | /** |
| 14916 | * Invoked by a parent ViewGroup to notify the start of the animation |
| 14917 | * currently associated with this view. If you override this method, |
| 14918 | * always call super.onAnimationStart(); |
| 14919 | * |
| 14920 | * @see #setAnimation(android.view.animation.Animation) |
| 14921 | * @see #getAnimation() |
| 14922 | */ |
| 14923 | protected void onAnimationStart() { |
| 14924 | mPrivateFlags |= ANIMATION_STARTED; |
| 14925 | } |
| 14926 | |
| 14927 | /** |
| 14928 | * Invoked by a parent ViewGroup to notify the end of the animation |
| 14929 | * currently associated with this view. If you override this method, |
| 14930 | * always call super.onAnimationEnd(); |
| 14931 | * |
| 14932 | * @see #setAnimation(android.view.animation.Animation) |
| 14933 | * @see #getAnimation() |
| 14934 | */ |
| 14935 | protected void onAnimationEnd() { |
| 14936 | mPrivateFlags &= ~ANIMATION_STARTED; |
| 14937 | } |
| 14938 | |
| 14939 | /** |
| 14940 | * Invoked if there is a Transform that involves alpha. Subclass that can |
| 14941 | * draw themselves with the specified alpha should return true, and then |
| 14942 | * respect that alpha when their onDraw() is called. If this returns false |
| 14943 | * then the view may be redirected to draw into an offscreen buffer to |
| 14944 | * fulfill the request, which will look fine, but may be slower than if the |
| 14945 | * subclass handles it internally. The default implementation returns false. |
| 14946 | * |
| 14947 | * @param alpha The alpha (0..255) to apply to the view's drawing |
| 14948 | * @return true if the view can draw with the specified alpha. |
| 14949 | */ |
| 14950 | protected boolean onSetAlpha(int alpha) { |
| 14951 | return false; |
| 14952 | } |
| 14953 | |
| 14954 | /** |
| 14955 | * This is used by the RootView to perform an optimization when |
| 14956 | * the view hierarchy contains one or several SurfaceView. |
| 14957 | * SurfaceView is always considered transparent, but its children are not, |
| 14958 | * therefore all View objects remove themselves from the global transparent |
| 14959 | * region (passed as a parameter to this function). |
| 14960 | * |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 14961 | * @param region The transparent region for this ViewAncestor (window). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14962 | * |
| 14963 | * @return Returns true if the effective visibility of the view at this |
| 14964 | * point is opaque, regardless of the transparent region; returns false |
| 14965 | * if it is possible for underlying windows to be seen behind the view. |
| 14966 | * |
| 14967 | * {@hide} |
| 14968 | */ |
| 14969 | public boolean gatherTransparentRegion(Region region) { |
| 14970 | final AttachInfo attachInfo = mAttachInfo; |
| 14971 | if (region != null && attachInfo != null) { |
| 14972 | final int pflags = mPrivateFlags; |
| 14973 | if ((pflags & SKIP_DRAW) == 0) { |
| 14974 | // The SKIP_DRAW flag IS NOT set, so this view draws. We need to |
| 14975 | // remove it from the transparent region. |
| 14976 | final int[] location = attachInfo.mTransparentLocation; |
| 14977 | getLocationInWindow(location); |
| 14978 | region.op(location[0], location[1], location[0] + mRight - mLeft, |
| 14979 | location[1] + mBottom - mTop, Region.Op.DIFFERENCE); |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14980 | } else if ((pflags & ONLY_DRAWS_BACKGROUND) != 0 && mBackground != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14981 | // The ONLY_DRAWS_BACKGROUND flag IS set and the background drawable |
| 14982 | // exists, so we remove the background drawable's non-transparent |
| 14983 | // parts from this transparent region. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14984 | applyDrawableToTransparentRegion(mBackground, region); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14985 | } |
| 14986 | } |
| 14987 | return true; |
| 14988 | } |
| 14989 | |
| 14990 | /** |
| 14991 | * Play a sound effect for this view. |
| 14992 | * |
| 14993 | * <p>The framework will play sound effects for some built in actions, such as |
| 14994 | * clicking, but you may wish to play these effects in your widget, |
| 14995 | * for instance, for internal navigation. |
| 14996 | * |
| 14997 | * <p>The sound effect will only be played if sound effects are enabled by the user, and |
| 14998 | * {@link #isSoundEffectsEnabled()} is true. |
| 14999 | * |
| 15000 | * @param soundConstant One of the constants defined in {@link SoundEffectConstants} |
| 15001 | */ |
| 15002 | public void playSoundEffect(int soundConstant) { |
| 15003 | if (mAttachInfo == null || mAttachInfo.mRootCallbacks == null || !isSoundEffectsEnabled()) { |
| 15004 | return; |
| 15005 | } |
| 15006 | mAttachInfo.mRootCallbacks.playSoundEffect(soundConstant); |
| 15007 | } |
| 15008 | |
| 15009 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15010 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15011 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15012 | * <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] | 15013 | * |
| 15014 | * <p>The framework will provide haptic feedback for some built in actions, |
| 15015 | * such as long presses, but you may wish to provide feedback for your |
| 15016 | * own widget. |
| 15017 | * |
| 15018 | * <p>The feedback will only be performed if |
| 15019 | * {@link #isHapticFeedbackEnabled()} is true. |
| 15020 | * |
| 15021 | * @param feedbackConstant One of the constants defined in |
| 15022 | * {@link HapticFeedbackConstants} |
| 15023 | */ |
| 15024 | public boolean performHapticFeedback(int feedbackConstant) { |
| 15025 | return performHapticFeedback(feedbackConstant, 0); |
| 15026 | } |
| 15027 | |
| 15028 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15029 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15030 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15031 | * <p>Like {@link #performHapticFeedback(int)}, with additional options. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15032 | * |
| 15033 | * @param feedbackConstant One of the constants defined in |
| 15034 | * {@link HapticFeedbackConstants} |
| 15035 | * @param flags Additional flags as per {@link HapticFeedbackConstants}. |
| 15036 | */ |
| 15037 | public boolean performHapticFeedback(int feedbackConstant, int flags) { |
| 15038 | if (mAttachInfo == null) { |
| 15039 | return false; |
| 15040 | } |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 15041 | //noinspection SimplifiableIfStatement |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 15042 | if ((flags & HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING) == 0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15043 | && !isHapticFeedbackEnabled()) { |
| 15044 | return false; |
| 15045 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 15046 | return mAttachInfo.mRootCallbacks.performHapticFeedback(feedbackConstant, |
| 15047 | (flags & HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15048 | } |
| 15049 | |
| 15050 | /** |
Dianne Hackborn | 9801435 | 2012-04-05 18:31:41 -0700 | [diff] [blame] | 15051 | * Request that the visibility of the status bar or other screen/window |
| 15052 | * decorations be changed. |
| 15053 | * |
| 15054 | * <p>This method is used to put the over device UI into temporary modes |
| 15055 | * where the user's attention is focused more on the application content, |
| 15056 | * by dimming or hiding surrounding system affordances. This is typically |
| 15057 | * used in conjunction with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 15058 | * Window.FEATURE_ACTION_BAR_OVERLAY}, allowing the applications content |
| 15059 | * to be placed behind the action bar (and with these flags other system |
| 15060 | * affordances) so that smooth transitions between hiding and showing them |
| 15061 | * can be done. |
| 15062 | * |
| 15063 | * <p>Two representative examples of the use of system UI visibility is |
| 15064 | * implementing a content browsing application (like a magazine reader) |
| 15065 | * and a video playing application. |
| 15066 | * |
| 15067 | * <p>The first code shows a typical implementation of a View in a content |
| 15068 | * browsing application. In this implementation, the application goes |
| 15069 | * into a content-oriented mode by hiding the status bar and action bar, |
| 15070 | * and putting the navigation elements into lights out mode. The user can |
| 15071 | * then interact with content while in this mode. Such an application should |
| 15072 | * provide an easy way for the user to toggle out of the mode (such as to |
| 15073 | * check information in the status bar or access notifications). In the |
| 15074 | * implementation here, this is done simply by tapping on the content. |
| 15075 | * |
| 15076 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/view/ContentBrowserActivity.java |
| 15077 | * content} |
| 15078 | * |
| 15079 | * <p>This second code sample shows a typical implementation of a View |
| 15080 | * in a video playing application. In this situation, while the video is |
| 15081 | * playing the application would like to go into a complete full-screen mode, |
| 15082 | * to use as much of the display as possible for the video. When in this state |
| 15083 | * the user can not interact with the application; the system intercepts |
| 15084 | * touching on the screen to pop the UI out of full screen mode. |
| 15085 | * |
| 15086 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/view/VideoPlayerActivity.java |
| 15087 | * content} |
| 15088 | * |
| 15089 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, |
| 15090 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN}, |
| 15091 | * {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, |
| 15092 | * and {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15093 | */ |
| 15094 | public void setSystemUiVisibility(int visibility) { |
Daniel Sandler | 7052406 | 2011-09-21 00:30:47 -0400 | [diff] [blame] | 15095 | if (visibility != mSystemUiVisibility) { |
| 15096 | mSystemUiVisibility = visibility; |
| 15097 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 15098 | mParent.recomputeViewAttributes(this); |
| 15099 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15100 | } |
| 15101 | } |
| 15102 | |
| 15103 | /** |
Dianne Hackborn | 9801435 | 2012-04-05 18:31:41 -0700 | [diff] [blame] | 15104 | * Returns the last {@link #setSystemUiVisibility(int) that this view has requested. |
| 15105 | * @return Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, |
| 15106 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN}, |
| 15107 | * {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, |
| 15108 | * and {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15109 | */ |
Joe Onorato | e595cad | 2011-01-24 09:22:12 -0800 | [diff] [blame] | 15110 | public int getSystemUiVisibility() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15111 | return mSystemUiVisibility; |
| 15112 | } |
| 15113 | |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 15114 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 15115 | * Returns the current system UI visibility that is currently set for |
| 15116 | * the entire window. This is the combination of the |
| 15117 | * {@link #setSystemUiVisibility(int)} values supplied by all of the |
| 15118 | * views in the window. |
| 15119 | */ |
| 15120 | public int getWindowSystemUiVisibility() { |
| 15121 | return mAttachInfo != null ? mAttachInfo.mSystemUiVisibility : 0; |
| 15122 | } |
| 15123 | |
| 15124 | /** |
| 15125 | * Override to find out when the window's requested system UI visibility |
| 15126 | * has changed, that is the value returned by {@link #getWindowSystemUiVisibility()}. |
| 15127 | * This is different from the callbacks recieved through |
| 15128 | * {@link #setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener)} |
| 15129 | * in that this is only telling you about the local request of the window, |
| 15130 | * not the actual values applied by the system. |
| 15131 | */ |
| 15132 | public void onWindowSystemUiVisibilityChanged(int visible) { |
| 15133 | } |
| 15134 | |
| 15135 | /** |
| 15136 | * Dispatch callbacks to {@link #onWindowSystemUiVisibilityChanged(int)} down |
| 15137 | * the view hierarchy. |
| 15138 | */ |
| 15139 | public void dispatchWindowSystemUiVisiblityChanged(int visible) { |
| 15140 | onWindowSystemUiVisibilityChanged(visible); |
| 15141 | } |
| 15142 | |
| 15143 | /** |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 15144 | * Set a listener to receive callbacks when the visibility of the system bar changes. |
| 15145 | * @param l The {@link OnSystemUiVisibilityChangeListener} to receive callbacks. |
| 15146 | */ |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15147 | public void setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 15148 | getListenerInfo().mOnSystemUiVisibilityChangeListener = l; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15149 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 15150 | mParent.recomputeViewAttributes(this); |
| 15151 | } |
| 15152 | } |
| 15153 | |
| 15154 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 15155 | * Dispatch callbacks to {@link #setOnSystemUiVisibilityChangeListener} down |
| 15156 | * the view hierarchy. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15157 | */ |
| 15158 | public void dispatchSystemUiVisibilityChanged(int visibility) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 15159 | ListenerInfo li = mListenerInfo; |
| 15160 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
| 15161 | li.mOnSystemUiVisibilityChangeListener.onSystemUiVisibilityChange( |
Joe Onorato | 6ab77bd | 2011-01-31 11:21:10 -0800 | [diff] [blame] | 15162 | visibility & PUBLIC_STATUS_BAR_VISIBILITY_MASK); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15163 | } |
| 15164 | } |
| 15165 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 15166 | void updateLocalSystemUiVisibility(int localValue, int localChanges) { |
| 15167 | int val = (mSystemUiVisibility&~localChanges) | (localValue&localChanges); |
| 15168 | if (val != mSystemUiVisibility) { |
| 15169 | setSystemUiVisibility(val); |
| 15170 | } |
| 15171 | } |
| 15172 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15173 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15174 | * Creates an image that the system displays during the drag and drop |
| 15175 | * operation. This is called a "drag shadow". The default implementation |
| 15176 | * for a DragShadowBuilder based on a View returns an image that has exactly the same |
| 15177 | * appearance as the given View. The default also positions the center of the drag shadow |
| 15178 | * directly under the touch point. If no View is provided (the constructor with no parameters |
| 15179 | * is used), and {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} and |
| 15180 | * {@link #onDrawShadow(Canvas) onDrawShadow()} are not overriden, then the |
| 15181 | * default is an invisible drag shadow. |
| 15182 | * <p> |
| 15183 | * You are not required to use the View you provide to the constructor as the basis of the |
| 15184 | * drag shadow. The {@link #onDrawShadow(Canvas) onDrawShadow()} method allows you to draw |
| 15185 | * anything you want as the drag shadow. |
| 15186 | * </p> |
| 15187 | * <p> |
| 15188 | * You pass a DragShadowBuilder object to the system when you start the drag. The system |
| 15189 | * calls {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} to get the |
| 15190 | * size and position of the drag shadow. It uses this data to construct a |
| 15191 | * {@link android.graphics.Canvas} object, then it calls {@link #onDrawShadow(Canvas) onDrawShadow()} |
| 15192 | * so that your application can draw the shadow image in the Canvas. |
| 15193 | * </p> |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 15194 | * |
| 15195 | * <div class="special reference"> |
| 15196 | * <h3>Developer Guides</h3> |
| 15197 | * <p>For a guide to implementing drag and drop features, read the |
| 15198 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 15199 | * </div> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15200 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15201 | public static class DragShadowBuilder { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 15202 | private final WeakReference<View> mView; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15203 | |
| 15204 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15205 | * Constructs a shadow image builder based on a View. By default, the resulting drag |
| 15206 | * shadow will have the same appearance and dimensions as the View, with the touch point |
| 15207 | * over the center of the View. |
| 15208 | * @param view A View. Any View in scope can be used. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15209 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15210 | public DragShadowBuilder(View view) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 15211 | mView = new WeakReference<View>(view); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15212 | } |
| 15213 | |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 15214 | /** |
| 15215 | * Construct a shadow builder object with no associated View. This |
| 15216 | * constructor variant is only useful when the {@link #onProvideShadowMetrics(Point, Point)} |
| 15217 | * and {@link #onDrawShadow(Canvas)} methods are also overridden in order |
| 15218 | * to supply the drag shadow's dimensions and appearance without |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15219 | * reference to any View object. If they are not overridden, then the result is an |
| 15220 | * invisible drag shadow. |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 15221 | */ |
| 15222 | public DragShadowBuilder() { |
| 15223 | mView = new WeakReference<View>(null); |
| 15224 | } |
| 15225 | |
| 15226 | /** |
| 15227 | * Returns the View object that had been passed to the |
| 15228 | * {@link #View.DragShadowBuilder(View)} |
| 15229 | * constructor. If that View parameter was {@code null} or if the |
| 15230 | * {@link #View.DragShadowBuilder()} |
| 15231 | * constructor was used to instantiate the builder object, this method will return |
| 15232 | * null. |
| 15233 | * |
| 15234 | * @return The View object associate with this builder object. |
| 15235 | */ |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 15236 | @SuppressWarnings({"JavadocReference"}) |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 15237 | final public View getView() { |
| 15238 | return mView.get(); |
| 15239 | } |
| 15240 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15241 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15242 | * Provides the metrics for the shadow image. These include the dimensions of |
| 15243 | * the shadow image, and the point within that shadow that should |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15244 | * be centered under the touch location while dragging. |
| 15245 | * <p> |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15246 | * The default implementation sets the dimensions of the shadow to be the |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15247 | * same as the dimensions of the View itself and centers the shadow under |
| 15248 | * the touch point. |
| 15249 | * </p> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15250 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15251 | * @param shadowSize A {@link android.graphics.Point} containing the width and height |
| 15252 | * of the shadow image. Your application must set {@link android.graphics.Point#x} to the |
| 15253 | * desired width and must set {@link android.graphics.Point#y} to the desired height of the |
| 15254 | * image. |
| 15255 | * |
| 15256 | * @param shadowTouchPoint A {@link android.graphics.Point} for the position within the |
| 15257 | * shadow image that should be underneath the touch point during the drag and drop |
| 15258 | * operation. Your application must set {@link android.graphics.Point#x} to the |
| 15259 | * 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] | 15260 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15261 | public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 15262 | final View view = mView.get(); |
| 15263 | if (view != null) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15264 | shadowSize.set(view.getWidth(), view.getHeight()); |
| 15265 | shadowTouchPoint.set(shadowSize.x / 2, shadowSize.y / 2); |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 15266 | } else { |
| 15267 | Log.e(View.VIEW_LOG_TAG, "Asked for drag thumb metrics but no view"); |
| 15268 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15269 | } |
| 15270 | |
| 15271 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15272 | * Draws the shadow image. The system creates the {@link android.graphics.Canvas} object |
| 15273 | * based on the dimensions it received from the |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15274 | * {@link #onProvideShadowMetrics(Point, Point)} callback. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15275 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15276 | * @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] | 15277 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15278 | public void onDrawShadow(Canvas canvas) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 15279 | final View view = mView.get(); |
| 15280 | if (view != null) { |
| 15281 | view.draw(canvas); |
| 15282 | } else { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15283 | 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] | 15284 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15285 | } |
| 15286 | } |
| 15287 | |
| 15288 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15289 | * Starts a drag and drop operation. When your application calls this method, it passes a |
| 15290 | * {@link android.view.View.DragShadowBuilder} object to the system. The |
| 15291 | * system calls this object's {@link DragShadowBuilder#onProvideShadowMetrics(Point, Point)} |
| 15292 | * to get metrics for the drag shadow, and then calls the object's |
| 15293 | * {@link DragShadowBuilder#onDrawShadow(Canvas)} to draw the drag shadow itself. |
| 15294 | * <p> |
| 15295 | * Once the system has the drag shadow, it begins the drag and drop operation by sending |
| 15296 | * drag events to all the View objects in your application that are currently visible. It does |
| 15297 | * this either by calling the View object's drag listener (an implementation of |
| 15298 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent) onDrag()} or by calling the |
| 15299 | * View object's {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} method. |
| 15300 | * Both are passed a {@link android.view.DragEvent} object that has a |
| 15301 | * {@link android.view.DragEvent#getAction()} value of |
| 15302 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED}. |
| 15303 | * </p> |
| 15304 | * <p> |
| 15305 | * Your application can invoke startDrag() on any attached View object. The View object does not |
| 15306 | * need to be the one used in {@link android.view.View.DragShadowBuilder}, nor does it need to |
| 15307 | * be related to the View the user selected for dragging. |
| 15308 | * </p> |
| 15309 | * @param data A {@link android.content.ClipData} object pointing to the data to be |
| 15310 | * transferred by the drag and drop operation. |
| 15311 | * @param shadowBuilder A {@link android.view.View.DragShadowBuilder} object for building the |
| 15312 | * drag shadow. |
| 15313 | * @param myLocalState An {@link java.lang.Object} containing local data about the drag and |
| 15314 | * drop operation. This Object is put into every DragEvent object sent by the system during the |
| 15315 | * current drag. |
| 15316 | * <p> |
| 15317 | * myLocalState is a lightweight mechanism for the sending information from the dragged View |
| 15318 | * to the target Views. For example, it can contain flags that differentiate between a |
| 15319 | * a copy operation and a move operation. |
| 15320 | * </p> |
| 15321 | * @param flags Flags that control the drag and drop operation. No flags are currently defined, |
| 15322 | * so the parameter should be set to 0. |
| 15323 | * @return {@code true} if the method completes successfully, or |
| 15324 | * {@code false} if it fails anywhere. Returning {@code false} means the system was unable to |
| 15325 | * do a drag, and so no drag operation is in progress. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15326 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15327 | public final boolean startDrag(ClipData data, DragShadowBuilder shadowBuilder, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 15328 | Object myLocalState, int flags) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15329 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 15330 | Log.d(VIEW_LOG_TAG, "startDrag: data=" + data + " flags=" + flags); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15331 | } |
| 15332 | boolean okay = false; |
| 15333 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15334 | Point shadowSize = new Point(); |
| 15335 | Point shadowTouchPoint = new Point(); |
| 15336 | shadowBuilder.onProvideShadowMetrics(shadowSize, shadowTouchPoint); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15337 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15338 | if ((shadowSize.x < 0) || (shadowSize.y < 0) || |
| 15339 | (shadowTouchPoint.x < 0) || (shadowTouchPoint.y < 0)) { |
| 15340 | throw new IllegalStateException("Drag shadow dimensions must not be negative"); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15341 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15342 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 15343 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15344 | Log.d(VIEW_LOG_TAG, "drag shadow: width=" + shadowSize.x + " height=" + shadowSize.y |
| 15345 | + " shadowX=" + shadowTouchPoint.x + " shadowY=" + shadowTouchPoint.y); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 15346 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15347 | Surface surface = new Surface(); |
| 15348 | try { |
| 15349 | IBinder token = mAttachInfo.mSession.prepareDrag(mAttachInfo.mWindow, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 15350 | flags, shadowSize.x, shadowSize.y, surface); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15351 | 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] | 15352 | + " surface=" + surface); |
| 15353 | if (token != null) { |
| 15354 | Canvas canvas = surface.lockCanvas(null); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 15355 | try { |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 15356 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15357 | shadowBuilder.onDrawShadow(canvas); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 15358 | } finally { |
| 15359 | surface.unlockCanvasAndPost(canvas); |
| 15360 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15361 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 15362 | final ViewRootImpl root = getViewRootImpl(); |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 15363 | |
| 15364 | // Cache the local state object for delivery with DragEvents |
| 15365 | root.setLocalDragState(myLocalState); |
| 15366 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15367 | // repurpose 'shadowSize' for the last touch point |
| 15368 | root.getLastTouchPoint(shadowSize); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15369 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15370 | okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, token, |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15371 | shadowSize.x, shadowSize.y, |
| 15372 | shadowTouchPoint.x, shadowTouchPoint.y, data); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15373 | if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "performDrag returned " + okay); |
Christopher Tate | 8f73b5d | 2011-09-12 15:22:12 -0700 | [diff] [blame] | 15374 | |
| 15375 | // Off and running! Release our local surface instance; the drag |
| 15376 | // shadow surface is now managed by the system process. |
| 15377 | surface.release(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15378 | } |
| 15379 | } catch (Exception e) { |
| 15380 | Log.e(VIEW_LOG_TAG, "Unable to initiate drag", e); |
| 15381 | surface.destroy(); |
| 15382 | } |
| 15383 | |
| 15384 | return okay; |
| 15385 | } |
| 15386 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15387 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15388 | * Handles drag events sent by the system following a call to |
| 15389 | * {@link android.view.View#startDrag(ClipData,DragShadowBuilder,Object,int) startDrag()}. |
| 15390 | *<p> |
| 15391 | * When the system calls this method, it passes a |
| 15392 | * {@link android.view.DragEvent} object. A call to |
| 15393 | * {@link android.view.DragEvent#getAction()} returns one of the action type constants defined |
| 15394 | * in DragEvent. The method uses these to determine what is happening in the drag and drop |
| 15395 | * operation. |
| 15396 | * @param event The {@link android.view.DragEvent} sent by the system. |
| 15397 | * The {@link android.view.DragEvent#getAction()} method returns an action type constant defined |
| 15398 | * in DragEvent, indicating the type of drag event represented by this object. |
| 15399 | * @return {@code true} if the method was successful, otherwise {@code false}. |
| 15400 | * <p> |
| 15401 | * The method should return {@code true} in response to an action type of |
| 15402 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED} to receive drag events for the current |
| 15403 | * operation. |
| 15404 | * </p> |
| 15405 | * <p> |
| 15406 | * The method should also return {@code true} in response to an action type of |
| 15407 | * {@link android.view.DragEvent#ACTION_DROP} if it consumed the drop, or |
| 15408 | * {@code false} if it didn't. |
| 15409 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15410 | */ |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 15411 | public boolean onDragEvent(DragEvent event) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15412 | return false; |
| 15413 | } |
| 15414 | |
| 15415 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15416 | * Detects if this View is enabled and has a drag event listener. |
| 15417 | * If both are true, then it calls the drag event listener with the |
| 15418 | * {@link android.view.DragEvent} it received. If the drag event listener returns |
| 15419 | * {@code true}, then dispatchDragEvent() returns {@code true}. |
| 15420 | * <p> |
| 15421 | * For all other cases, the method calls the |
| 15422 | * {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} drag event handler |
| 15423 | * method and returns its result. |
| 15424 | * </p> |
| 15425 | * <p> |
| 15426 | * This ensures that a drag event is always consumed, even if the View does not have a drag |
| 15427 | * event listener. However, if the View has a listener and the listener returns true, then |
| 15428 | * onDragEvent() is not called. |
| 15429 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15430 | */ |
| 15431 | public boolean dispatchDragEvent(DragEvent event) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 15432 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 15433 | ListenerInfo li = mListenerInfo; |
| 15434 | if (li != null && li.mOnDragListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 15435 | && li.mOnDragListener.onDrag(this, event)) { |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 15436 | return true; |
| 15437 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15438 | return onDragEvent(event); |
| 15439 | } |
| 15440 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 15441 | boolean canAcceptDrag() { |
| 15442 | return (mPrivateFlags2 & DRAG_CAN_ACCEPT) != 0; |
| 15443 | } |
| 15444 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15445 | /** |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 15446 | * This needs to be a better API (NOT ON VIEW) before it is exposed. If |
| 15447 | * it is ever exposed at all. |
Dianne Hackborn | 29e4a3c | 2009-09-30 22:35:40 -0700 | [diff] [blame] | 15448 | * @hide |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 15449 | */ |
| 15450 | public void onCloseSystemDialogs(String reason) { |
| 15451 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15452 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 15453 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15454 | * 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] | 15455 | * update a Region being computed for |
| 15456 | * {@link #gatherTransparentRegion(android.graphics.Region)} so |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15457 | * that any non-transparent parts of the Drawable are removed from the |
| 15458 | * given transparent region. |
| 15459 | * |
| 15460 | * @param dr The Drawable whose transparency is to be applied to the region. |
| 15461 | * @param region A Region holding the current transparency information, |
| 15462 | * where any parts of the region that are set are considered to be |
| 15463 | * transparent. On return, this region will be modified to have the |
| 15464 | * transparency information reduced by the corresponding parts of the |
| 15465 | * Drawable that are not transparent. |
| 15466 | * {@hide} |
| 15467 | */ |
| 15468 | public void applyDrawableToTransparentRegion(Drawable dr, Region region) { |
| 15469 | if (DBG) { |
| 15470 | Log.i("View", "Getting transparent region for: " + this); |
| 15471 | } |
| 15472 | final Region r = dr.getTransparentRegion(); |
| 15473 | final Rect db = dr.getBounds(); |
| 15474 | final AttachInfo attachInfo = mAttachInfo; |
| 15475 | if (r != null && attachInfo != null) { |
| 15476 | final int w = getRight()-getLeft(); |
| 15477 | final int h = getBottom()-getTop(); |
| 15478 | if (db.left > 0) { |
| 15479 | //Log.i("VIEW", "Drawable left " + db.left + " > view 0"); |
| 15480 | r.op(0, 0, db.left, h, Region.Op.UNION); |
| 15481 | } |
| 15482 | if (db.right < w) { |
| 15483 | //Log.i("VIEW", "Drawable right " + db.right + " < view " + w); |
| 15484 | r.op(db.right, 0, w, h, Region.Op.UNION); |
| 15485 | } |
| 15486 | if (db.top > 0) { |
| 15487 | //Log.i("VIEW", "Drawable top " + db.top + " > view 0"); |
| 15488 | r.op(0, 0, w, db.top, Region.Op.UNION); |
| 15489 | } |
| 15490 | if (db.bottom < h) { |
| 15491 | //Log.i("VIEW", "Drawable bottom " + db.bottom + " < view " + h); |
| 15492 | r.op(0, db.bottom, w, h, Region.Op.UNION); |
| 15493 | } |
| 15494 | final int[] location = attachInfo.mTransparentLocation; |
| 15495 | getLocationInWindow(location); |
| 15496 | r.translate(location[0], location[1]); |
| 15497 | region.op(r, Region.Op.INTERSECT); |
| 15498 | } else { |
| 15499 | region.op(db, Region.Op.DIFFERENCE); |
| 15500 | } |
| 15501 | } |
| 15502 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 15503 | private void checkForLongClick(int delayOffset) { |
| 15504 | if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) { |
| 15505 | mHasPerformedLongPress = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15506 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 15507 | if (mPendingCheckForLongPress == null) { |
| 15508 | mPendingCheckForLongPress = new CheckForLongPress(); |
| 15509 | } |
| 15510 | mPendingCheckForLongPress.rememberWindowAttachCount(); |
| 15511 | postDelayed(mPendingCheckForLongPress, |
| 15512 | ViewConfiguration.getLongPressTimeout() - delayOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15513 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15514 | } |
| 15515 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15516 | /** |
| 15517 | * Inflate a view from an XML resource. This convenience method wraps the {@link |
| 15518 | * LayoutInflater} class, which provides a full range of options for view inflation. |
| 15519 | * |
| 15520 | * @param context The Context object for your activity or application. |
| 15521 | * @param resource The resource ID to inflate |
| 15522 | * @param root A view group that will be the parent. Used to properly inflate the |
| 15523 | * layout_* parameters. |
| 15524 | * @see LayoutInflater |
| 15525 | */ |
| 15526 | public static View inflate(Context context, int resource, ViewGroup root) { |
| 15527 | LayoutInflater factory = LayoutInflater.from(context); |
| 15528 | return factory.inflate(resource, root); |
| 15529 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 15530 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15531 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 15532 | * Scroll the view with standard behavior for scrolling beyond the normal |
| 15533 | * content boundaries. Views that call this method should override |
| 15534 | * {@link #onOverScrolled(int, int, boolean, boolean)} to respond to the |
| 15535 | * results of an over-scroll operation. |
| 15536 | * |
| 15537 | * Views can use this method to handle any touch or fling-based scrolling. |
| 15538 | * |
| 15539 | * @param deltaX Change in X in pixels |
| 15540 | * @param deltaY Change in Y in pixels |
| 15541 | * @param scrollX Current X scroll value in pixels before applying deltaX |
| 15542 | * @param scrollY Current Y scroll value in pixels before applying deltaY |
| 15543 | * @param scrollRangeX Maximum content scroll range along the X axis |
| 15544 | * @param scrollRangeY Maximum content scroll range along the Y axis |
| 15545 | * @param maxOverScrollX Number of pixels to overscroll by in either direction |
| 15546 | * along the X axis. |
| 15547 | * @param maxOverScrollY Number of pixels to overscroll by in either direction |
| 15548 | * along the Y axis. |
| 15549 | * @param isTouchEvent true if this scroll operation is the result of a touch event. |
| 15550 | * @return true if scrolling was clamped to an over-scroll boundary along either |
| 15551 | * axis, false otherwise. |
| 15552 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 15553 | @SuppressWarnings({"UnusedParameters"}) |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 15554 | protected boolean overScrollBy(int deltaX, int deltaY, |
| 15555 | int scrollX, int scrollY, |
| 15556 | int scrollRangeX, int scrollRangeY, |
| 15557 | int maxOverScrollX, int maxOverScrollY, |
| 15558 | boolean isTouchEvent) { |
| 15559 | final int overScrollMode = mOverScrollMode; |
| 15560 | final boolean canScrollHorizontal = |
| 15561 | computeHorizontalScrollRange() > computeHorizontalScrollExtent(); |
| 15562 | final boolean canScrollVertical = |
| 15563 | computeVerticalScrollRange() > computeVerticalScrollExtent(); |
| 15564 | final boolean overScrollHorizontal = overScrollMode == OVER_SCROLL_ALWAYS || |
| 15565 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollHorizontal); |
| 15566 | final boolean overScrollVertical = overScrollMode == OVER_SCROLL_ALWAYS || |
| 15567 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollVertical); |
| 15568 | |
| 15569 | int newScrollX = scrollX + deltaX; |
| 15570 | if (!overScrollHorizontal) { |
| 15571 | maxOverScrollX = 0; |
| 15572 | } |
| 15573 | |
| 15574 | int newScrollY = scrollY + deltaY; |
| 15575 | if (!overScrollVertical) { |
| 15576 | maxOverScrollY = 0; |
| 15577 | } |
| 15578 | |
| 15579 | // Clamp values if at the limits and record |
| 15580 | final int left = -maxOverScrollX; |
| 15581 | final int right = maxOverScrollX + scrollRangeX; |
| 15582 | final int top = -maxOverScrollY; |
| 15583 | final int bottom = maxOverScrollY + scrollRangeY; |
| 15584 | |
| 15585 | boolean clampedX = false; |
| 15586 | if (newScrollX > right) { |
| 15587 | newScrollX = right; |
| 15588 | clampedX = true; |
| 15589 | } else if (newScrollX < left) { |
| 15590 | newScrollX = left; |
| 15591 | clampedX = true; |
| 15592 | } |
| 15593 | |
| 15594 | boolean clampedY = false; |
| 15595 | if (newScrollY > bottom) { |
| 15596 | newScrollY = bottom; |
| 15597 | clampedY = true; |
| 15598 | } else if (newScrollY < top) { |
| 15599 | newScrollY = top; |
| 15600 | clampedY = true; |
| 15601 | } |
| 15602 | |
| 15603 | onOverScrolled(newScrollX, newScrollY, clampedX, clampedY); |
| 15604 | |
| 15605 | return clampedX || clampedY; |
| 15606 | } |
| 15607 | |
| 15608 | /** |
| 15609 | * Called by {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)} to |
| 15610 | * respond to the results of an over-scroll operation. |
| 15611 | * |
| 15612 | * @param scrollX New X scroll value in pixels |
| 15613 | * @param scrollY New Y scroll value in pixels |
| 15614 | * @param clampedX True if scrollX was clamped to an over-scroll boundary |
| 15615 | * @param clampedY True if scrollY was clamped to an over-scroll boundary |
| 15616 | */ |
| 15617 | protected void onOverScrolled(int scrollX, int scrollY, |
| 15618 | boolean clampedX, boolean clampedY) { |
| 15619 | // Intentionally empty. |
| 15620 | } |
| 15621 | |
| 15622 | /** |
| 15623 | * Returns the over-scroll mode for this view. The result will be |
| 15624 | * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 15625 | * (allow over-scrolling only if the view content is larger than the container), |
| 15626 | * or {@link #OVER_SCROLL_NEVER}. |
| 15627 | * |
| 15628 | * @return This view's over-scroll mode. |
| 15629 | */ |
| 15630 | public int getOverScrollMode() { |
| 15631 | return mOverScrollMode; |
| 15632 | } |
| 15633 | |
| 15634 | /** |
| 15635 | * Set the over-scroll mode for this view. Valid over-scroll modes are |
| 15636 | * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 15637 | * (allow over-scrolling only if the view content is larger than the container), |
| 15638 | * or {@link #OVER_SCROLL_NEVER}. |
| 15639 | * |
| 15640 | * Setting the over-scroll mode of a view will have an effect only if the |
| 15641 | * view is capable of scrolling. |
| 15642 | * |
| 15643 | * @param overScrollMode The new over-scroll mode for this view. |
| 15644 | */ |
| 15645 | public void setOverScrollMode(int overScrollMode) { |
| 15646 | if (overScrollMode != OVER_SCROLL_ALWAYS && |
| 15647 | overScrollMode != OVER_SCROLL_IF_CONTENT_SCROLLS && |
| 15648 | overScrollMode != OVER_SCROLL_NEVER) { |
| 15649 | throw new IllegalArgumentException("Invalid overscroll mode " + overScrollMode); |
| 15650 | } |
| 15651 | mOverScrollMode = overScrollMode; |
| 15652 | } |
| 15653 | |
| 15654 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 15655 | * Gets a scale factor that determines the distance the view should scroll |
| 15656 | * vertically in response to {@link MotionEvent#ACTION_SCROLL}. |
| 15657 | * @return The vertical scroll scale factor. |
| 15658 | * @hide |
| 15659 | */ |
| 15660 | protected float getVerticalScrollFactor() { |
| 15661 | if (mVerticalScrollFactor == 0) { |
| 15662 | TypedValue outValue = new TypedValue(); |
| 15663 | if (!mContext.getTheme().resolveAttribute( |
| 15664 | com.android.internal.R.attr.listPreferredItemHeight, outValue, true)) { |
| 15665 | throw new IllegalStateException( |
| 15666 | "Expected theme to define listPreferredItemHeight."); |
| 15667 | } |
| 15668 | mVerticalScrollFactor = outValue.getDimension( |
| 15669 | mContext.getResources().getDisplayMetrics()); |
| 15670 | } |
| 15671 | return mVerticalScrollFactor; |
| 15672 | } |
| 15673 | |
| 15674 | /** |
| 15675 | * Gets a scale factor that determines the distance the view should scroll |
| 15676 | * horizontally in response to {@link MotionEvent#ACTION_SCROLL}. |
| 15677 | * @return The horizontal scroll scale factor. |
| 15678 | * @hide |
| 15679 | */ |
| 15680 | protected float getHorizontalScrollFactor() { |
| 15681 | // TODO: Should use something else. |
| 15682 | return getVerticalScrollFactor(); |
| 15683 | } |
| 15684 | |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15685 | /** |
| 15686 | * Return the value specifying the text direction or policy that was set with |
| 15687 | * {@link #setTextDirection(int)}. |
| 15688 | * |
| 15689 | * @return the defined text direction. It can be one of: |
| 15690 | * |
| 15691 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 15692 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 15693 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 15694 | * {@link #TEXT_DIRECTION_LTR}, |
| 15695 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15696 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15697 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15698 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 15699 | @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), |
| 15700 | @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), |
| 15701 | @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), |
| 15702 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), |
| 15703 | @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"), |
| 15704 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE") |
| 15705 | }) |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15706 | public int getTextDirection() { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15707 | return (mPrivateFlags2 & TEXT_DIRECTION_MASK) >> TEXT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15708 | } |
| 15709 | |
| 15710 | /** |
| 15711 | * Set the text direction. |
| 15712 | * |
| 15713 | * @param textDirection the direction to set. Should be one of: |
| 15714 | * |
| 15715 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 15716 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 15717 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 15718 | * {@link #TEXT_DIRECTION_LTR}, |
| 15719 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15720 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15721 | */ |
| 15722 | public void setTextDirection(int textDirection) { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15723 | if (getTextDirection() != textDirection) { |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 15724 | // Reset the current text direction and the resolved one |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15725 | mPrivateFlags2 &= ~TEXT_DIRECTION_MASK; |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 15726 | resetResolvedTextDirection(); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15727 | // Set the new text direction |
| 15728 | mPrivateFlags2 |= ((textDirection << TEXT_DIRECTION_MASK_SHIFT) & TEXT_DIRECTION_MASK); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15729 | // Refresh |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15730 | requestLayout(); |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 15731 | invalidate(true); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15732 | } |
| 15733 | } |
| 15734 | |
| 15735 | /** |
| 15736 | * Return the resolved text direction. |
| 15737 | * |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15738 | * This needs resolution if the value is TEXT_DIRECTION_INHERIT. The resolution matches |
| 15739 | * {@link #getTextDirection()}if it is not TEXT_DIRECTION_INHERIT, otherwise resolution proceeds |
| 15740 | * up the parent chain of the view. if there is no parent, then it will return the default |
| 15741 | * {@link #TEXT_DIRECTION_FIRST_STRONG}. |
| 15742 | * |
| 15743 | * @return the resolved text direction. Returns one of: |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15744 | * |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 15745 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 15746 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15747 | * {@link #TEXT_DIRECTION_LTR}, |
| 15748 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15749 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15750 | */ |
| 15751 | public int getResolvedTextDirection() { |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 15752 | // The text direction will be resolved only if needed |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15753 | if ((mPrivateFlags2 & TEXT_DIRECTION_RESOLVED) != TEXT_DIRECTION_RESOLVED) { |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15754 | resolveTextDirection(); |
| 15755 | } |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15756 | return (mPrivateFlags2 & TEXT_DIRECTION_RESOLVED_MASK) >> TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15757 | } |
| 15758 | |
| 15759 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15760 | * Resolve the text direction. Will call {@link View#onResolvedTextDirectionChanged} when |
| 15761 | * resolution is done. |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15762 | */ |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15763 | public void resolveTextDirection() { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15764 | // Reset any previous text direction resolution |
| 15765 | mPrivateFlags2 &= ~(TEXT_DIRECTION_RESOLVED | TEXT_DIRECTION_RESOLVED_MASK); |
| 15766 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 15767 | if (hasRtlSupport()) { |
| 15768 | // Set resolved text direction flag depending on text direction flag |
| 15769 | final int textDirection = getTextDirection(); |
| 15770 | switch(textDirection) { |
| 15771 | case TEXT_DIRECTION_INHERIT: |
| 15772 | if (canResolveTextDirection()) { |
| 15773 | ViewGroup viewGroup = ((ViewGroup) mParent); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15774 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 15775 | // Set current resolved direction to the same value as the parent's one |
| 15776 | final int parentResolvedDirection = viewGroup.getResolvedTextDirection(); |
| 15777 | switch (parentResolvedDirection) { |
| 15778 | case TEXT_DIRECTION_FIRST_STRONG: |
| 15779 | case TEXT_DIRECTION_ANY_RTL: |
| 15780 | case TEXT_DIRECTION_LTR: |
| 15781 | case TEXT_DIRECTION_RTL: |
| 15782 | case TEXT_DIRECTION_LOCALE: |
| 15783 | mPrivateFlags2 |= |
| 15784 | (parentResolvedDirection << TEXT_DIRECTION_RESOLVED_MASK_SHIFT); |
| 15785 | break; |
| 15786 | default: |
| 15787 | // Default resolved direction is "first strong" heuristic |
| 15788 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT; |
| 15789 | } |
| 15790 | } else { |
| 15791 | // We cannot do the resolution if there is no parent, so use the default one |
| 15792 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15793 | } |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 15794 | break; |
| 15795 | case TEXT_DIRECTION_FIRST_STRONG: |
| 15796 | case TEXT_DIRECTION_ANY_RTL: |
| 15797 | case TEXT_DIRECTION_LTR: |
| 15798 | case TEXT_DIRECTION_RTL: |
| 15799 | case TEXT_DIRECTION_LOCALE: |
| 15800 | // Resolved direction is the same as text direction |
| 15801 | mPrivateFlags2 |= (textDirection << TEXT_DIRECTION_RESOLVED_MASK_SHIFT); |
| 15802 | break; |
| 15803 | default: |
| 15804 | // Default resolved direction is "first strong" heuristic |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15805 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 15806 | } |
| 15807 | } else { |
| 15808 | // Default resolved direction is "first strong" heuristic |
| 15809 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15810 | } |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15811 | |
| 15812 | // Set to resolved |
| 15813 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15814 | onResolvedTextDirectionChanged(); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15815 | } |
| 15816 | |
| 15817 | /** |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15818 | * 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] | 15819 | * resolution should override this method. |
| 15820 | * |
| 15821 | * The default implementation does nothing. |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15822 | */ |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15823 | public void onResolvedTextDirectionChanged() { |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15824 | } |
| 15825 | |
| 15826 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15827 | * Check if text direction resolution can be done. |
| 15828 | * |
| 15829 | * @return true if text direction resolution can be done otherwise return false. |
| 15830 | */ |
| 15831 | public boolean canResolveTextDirection() { |
| 15832 | switch (getTextDirection()) { |
| 15833 | case TEXT_DIRECTION_INHERIT: |
| 15834 | return (mParent != null) && (mParent instanceof ViewGroup); |
| 15835 | default: |
| 15836 | return true; |
| 15837 | } |
| 15838 | } |
| 15839 | |
| 15840 | /** |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15841 | * 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] | 15842 | * getResolvedTextDirection(). Will call {@link View#onResolvedTextDirectionReset} when |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15843 | * reset is done. |
| 15844 | */ |
| 15845 | public void resetResolvedTextDirection() { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15846 | mPrivateFlags2 &= ~(TEXT_DIRECTION_RESOLVED | TEXT_DIRECTION_RESOLVED_MASK); |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15847 | onResolvedTextDirectionReset(); |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15848 | } |
| 15849 | |
| 15850 | /** |
| 15851 | * Called when text direction is reset. Subclasses that care about text direction reset should |
| 15852 | * override this method and do a reset of the text direction of their children. The default |
| 15853 | * implementation does nothing. |
| 15854 | */ |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15855 | public void onResolvedTextDirectionReset() { |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15856 | } |
| 15857 | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15858 | /** |
| 15859 | * Return the value specifying the text alignment or policy that was set with |
| 15860 | * {@link #setTextAlignment(int)}. |
| 15861 | * |
| 15862 | * @return the defined text alignment. It can be one of: |
| 15863 | * |
| 15864 | * {@link #TEXT_ALIGNMENT_INHERIT}, |
| 15865 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 15866 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 15867 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 15868 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 15869 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 15870 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
| 15871 | */ |
| 15872 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 15873 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_INHERIT, to = "INHERIT"), |
| 15874 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_GRAVITY, to = "GRAVITY"), |
| 15875 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_START, to = "TEXT_START"), |
| 15876 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_END, to = "TEXT_END"), |
| 15877 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_CENTER, to = "CENTER"), |
| 15878 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), |
| 15879 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") |
| 15880 | }) |
| 15881 | public int getTextAlignment() { |
| 15882 | return (mPrivateFlags2 & TEXT_ALIGNMENT_MASK) >> TEXT_ALIGNMENT_MASK_SHIFT; |
| 15883 | } |
| 15884 | |
| 15885 | /** |
| 15886 | * Set the text alignment. |
| 15887 | * |
| 15888 | * @param textAlignment The text alignment to set. Should be one of |
| 15889 | * |
| 15890 | * {@link #TEXT_ALIGNMENT_INHERIT}, |
| 15891 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 15892 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 15893 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 15894 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 15895 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 15896 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
| 15897 | * |
| 15898 | * @attr ref android.R.styleable#View_textAlignment |
| 15899 | */ |
| 15900 | public void setTextAlignment(int textAlignment) { |
| 15901 | if (textAlignment != getTextAlignment()) { |
| 15902 | // Reset the current and resolved text alignment |
| 15903 | mPrivateFlags2 &= ~TEXT_ALIGNMENT_MASK; |
| 15904 | resetResolvedTextAlignment(); |
| 15905 | // Set the new text alignment |
| 15906 | mPrivateFlags2 |= ((textAlignment << TEXT_ALIGNMENT_MASK_SHIFT) & TEXT_ALIGNMENT_MASK); |
| 15907 | // Refresh |
| 15908 | requestLayout(); |
| 15909 | invalidate(true); |
| 15910 | } |
| 15911 | } |
| 15912 | |
| 15913 | /** |
| 15914 | * Return the resolved text alignment. |
| 15915 | * |
| 15916 | * The resolved text alignment. This needs resolution if the value is |
| 15917 | * TEXT_ALIGNMENT_INHERIT. The resolution matches {@link #setTextAlignment(int)} if it is |
| 15918 | * not TEXT_ALIGNMENT_INHERIT, otherwise resolution proceeds up the parent chain of the view. |
| 15919 | * |
| 15920 | * @return the resolved text alignment. Returns one of: |
| 15921 | * |
| 15922 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 15923 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 15924 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 15925 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 15926 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 15927 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
| 15928 | */ |
| 15929 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 15930 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_INHERIT, to = "INHERIT"), |
| 15931 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_GRAVITY, to = "GRAVITY"), |
| 15932 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_START, to = "TEXT_START"), |
| 15933 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_END, to = "TEXT_END"), |
| 15934 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_CENTER, to = "CENTER"), |
| 15935 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), |
| 15936 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") |
| 15937 | }) |
| 15938 | public int getResolvedTextAlignment() { |
| 15939 | // If text alignment is not resolved, then resolve it |
| 15940 | if ((mPrivateFlags2 & TEXT_ALIGNMENT_RESOLVED) != TEXT_ALIGNMENT_RESOLVED) { |
| 15941 | resolveTextAlignment(); |
| 15942 | } |
| 15943 | return (mPrivateFlags2 & TEXT_ALIGNMENT_RESOLVED_MASK) >> TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
| 15944 | } |
| 15945 | |
| 15946 | /** |
| 15947 | * Resolve the text alignment. Will call {@link View#onResolvedTextAlignmentChanged} when |
| 15948 | * resolution is done. |
| 15949 | */ |
| 15950 | public void resolveTextAlignment() { |
| 15951 | // Reset any previous text alignment resolution |
| 15952 | mPrivateFlags2 &= ~(TEXT_ALIGNMENT_RESOLVED | TEXT_ALIGNMENT_RESOLVED_MASK); |
| 15953 | |
| 15954 | if (hasRtlSupport()) { |
| 15955 | // Set resolved text alignment flag depending on text alignment flag |
| 15956 | final int textAlignment = getTextAlignment(); |
| 15957 | switch (textAlignment) { |
| 15958 | case TEXT_ALIGNMENT_INHERIT: |
| 15959 | // Check if we can resolve the text alignment |
| 15960 | if (canResolveLayoutDirection() && mParent instanceof View) { |
| 15961 | View view = (View) mParent; |
| 15962 | |
| 15963 | final int parentResolvedTextAlignment = view.getResolvedTextAlignment(); |
| 15964 | switch (parentResolvedTextAlignment) { |
| 15965 | case TEXT_ALIGNMENT_GRAVITY: |
| 15966 | case TEXT_ALIGNMENT_TEXT_START: |
| 15967 | case TEXT_ALIGNMENT_TEXT_END: |
| 15968 | case TEXT_ALIGNMENT_CENTER: |
| 15969 | case TEXT_ALIGNMENT_VIEW_START: |
| 15970 | case TEXT_ALIGNMENT_VIEW_END: |
| 15971 | // Resolved text alignment is the same as the parent resolved |
| 15972 | // text alignment |
| 15973 | mPrivateFlags2 |= |
| 15974 | (parentResolvedTextAlignment << TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT); |
| 15975 | break; |
| 15976 | default: |
| 15977 | // Use default resolved text alignment |
| 15978 | mPrivateFlags2 |= TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 15979 | } |
| 15980 | } |
| 15981 | else { |
| 15982 | // We cannot do the resolution if there is no parent so use the default |
| 15983 | mPrivateFlags2 |= TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 15984 | } |
| 15985 | break; |
| 15986 | case TEXT_ALIGNMENT_GRAVITY: |
| 15987 | case TEXT_ALIGNMENT_TEXT_START: |
| 15988 | case TEXT_ALIGNMENT_TEXT_END: |
| 15989 | case TEXT_ALIGNMENT_CENTER: |
| 15990 | case TEXT_ALIGNMENT_VIEW_START: |
| 15991 | case TEXT_ALIGNMENT_VIEW_END: |
| 15992 | // Resolved text alignment is the same as text alignment |
| 15993 | mPrivateFlags2 |= (textAlignment << TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT); |
| 15994 | break; |
| 15995 | default: |
| 15996 | // Use default resolved text alignment |
| 15997 | mPrivateFlags2 |= TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 15998 | } |
| 15999 | } else { |
| 16000 | // Use default resolved text alignment |
| 16001 | mPrivateFlags2 |= TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 16002 | } |
| 16003 | |
| 16004 | // Set the resolved |
| 16005 | mPrivateFlags2 |= TEXT_ALIGNMENT_RESOLVED; |
| 16006 | onResolvedTextAlignmentChanged(); |
| 16007 | } |
| 16008 | |
| 16009 | /** |
| 16010 | * Check if text alignment resolution can be done. |
| 16011 | * |
| 16012 | * @return true if text alignment resolution can be done otherwise return false. |
| 16013 | */ |
| 16014 | public boolean canResolveTextAlignment() { |
| 16015 | switch (getTextAlignment()) { |
| 16016 | case TEXT_DIRECTION_INHERIT: |
| 16017 | return (mParent != null); |
| 16018 | default: |
| 16019 | return true; |
| 16020 | } |
| 16021 | } |
| 16022 | |
| 16023 | /** |
| 16024 | * Called when text alignment has been resolved. Subclasses that care about text alignment |
| 16025 | * resolution should override this method. |
| 16026 | * |
| 16027 | * The default implementation does nothing. |
| 16028 | */ |
| 16029 | public void onResolvedTextAlignmentChanged() { |
| 16030 | } |
| 16031 | |
| 16032 | /** |
| 16033 | * Reset resolved text alignment. Text alignment can be resolved with a call to |
| 16034 | * getResolvedTextAlignment(). Will call {@link View#onResolvedTextAlignmentReset} when |
| 16035 | * reset is done. |
| 16036 | */ |
| 16037 | public void resetResolvedTextAlignment() { |
| 16038 | // Reset any previous text alignment resolution |
| 16039 | mPrivateFlags2 &= ~(TEXT_ALIGNMENT_RESOLVED | TEXT_ALIGNMENT_RESOLVED_MASK); |
| 16040 | onResolvedTextAlignmentReset(); |
| 16041 | } |
| 16042 | |
| 16043 | /** |
| 16044 | * Called when text alignment is reset. Subclasses that care about text alignment reset should |
| 16045 | * override this method and do a reset of the text alignment of their children. The default |
| 16046 | * implementation does nothing. |
| 16047 | */ |
| 16048 | public void onResolvedTextAlignmentReset() { |
| 16049 | } |
| 16050 | |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16051 | // |
| 16052 | // Properties |
| 16053 | // |
| 16054 | /** |
| 16055 | * A Property wrapper around the <code>alpha</code> functionality handled by the |
| 16056 | * {@link View#setAlpha(float)} and {@link View#getAlpha()} methods. |
| 16057 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16058 | public static final Property<View, Float> ALPHA = new FloatProperty<View>("alpha") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16059 | @Override |
| 16060 | public void setValue(View object, float value) { |
| 16061 | object.setAlpha(value); |
| 16062 | } |
| 16063 | |
| 16064 | @Override |
| 16065 | public Float get(View object) { |
| 16066 | return object.getAlpha(); |
| 16067 | } |
| 16068 | }; |
| 16069 | |
| 16070 | /** |
| 16071 | * A Property wrapper around the <code>translationX</code> functionality handled by the |
| 16072 | * {@link View#setTranslationX(float)} and {@link View#getTranslationX()} methods. |
| 16073 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16074 | public static final Property<View, Float> TRANSLATION_X = new FloatProperty<View>("translationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16075 | @Override |
| 16076 | public void setValue(View object, float value) { |
| 16077 | object.setTranslationX(value); |
| 16078 | } |
| 16079 | |
| 16080 | @Override |
| 16081 | public Float get(View object) { |
| 16082 | return object.getTranslationX(); |
| 16083 | } |
| 16084 | }; |
| 16085 | |
| 16086 | /** |
| 16087 | * A Property wrapper around the <code>translationY</code> functionality handled by the |
| 16088 | * {@link View#setTranslationY(float)} and {@link View#getTranslationY()} methods. |
| 16089 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16090 | public static final Property<View, Float> TRANSLATION_Y = new FloatProperty<View>("translationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16091 | @Override |
| 16092 | public void setValue(View object, float value) { |
| 16093 | object.setTranslationY(value); |
| 16094 | } |
| 16095 | |
| 16096 | @Override |
| 16097 | public Float get(View object) { |
| 16098 | return object.getTranslationY(); |
| 16099 | } |
| 16100 | }; |
| 16101 | |
| 16102 | /** |
| 16103 | * A Property wrapper around the <code>x</code> functionality handled by the |
| 16104 | * {@link View#setX(float)} and {@link View#getX()} methods. |
| 16105 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16106 | public static final Property<View, Float> X = new FloatProperty<View>("x") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16107 | @Override |
| 16108 | public void setValue(View object, float value) { |
| 16109 | object.setX(value); |
| 16110 | } |
| 16111 | |
| 16112 | @Override |
| 16113 | public Float get(View object) { |
| 16114 | return object.getX(); |
| 16115 | } |
| 16116 | }; |
| 16117 | |
| 16118 | /** |
| 16119 | * A Property wrapper around the <code>y</code> functionality handled by the |
| 16120 | * {@link View#setY(float)} and {@link View#getY()} methods. |
| 16121 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16122 | public static final Property<View, Float> Y = new FloatProperty<View>("y") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16123 | @Override |
| 16124 | public void setValue(View object, float value) { |
| 16125 | object.setY(value); |
| 16126 | } |
| 16127 | |
| 16128 | @Override |
| 16129 | public Float get(View object) { |
| 16130 | return object.getY(); |
| 16131 | } |
| 16132 | }; |
| 16133 | |
| 16134 | /** |
| 16135 | * A Property wrapper around the <code>rotation</code> functionality handled by the |
| 16136 | * {@link View#setRotation(float)} and {@link View#getRotation()} methods. |
| 16137 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16138 | public static final Property<View, Float> ROTATION = new FloatProperty<View>("rotation") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16139 | @Override |
| 16140 | public void setValue(View object, float value) { |
| 16141 | object.setRotation(value); |
| 16142 | } |
| 16143 | |
| 16144 | @Override |
| 16145 | public Float get(View object) { |
| 16146 | return object.getRotation(); |
| 16147 | } |
| 16148 | }; |
| 16149 | |
| 16150 | /** |
| 16151 | * A Property wrapper around the <code>rotationX</code> functionality handled by the |
| 16152 | * {@link View#setRotationX(float)} and {@link View#getRotationX()} methods. |
| 16153 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16154 | public static final Property<View, Float> ROTATION_X = new FloatProperty<View>("rotationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16155 | @Override |
| 16156 | public void setValue(View object, float value) { |
| 16157 | object.setRotationX(value); |
| 16158 | } |
| 16159 | |
| 16160 | @Override |
| 16161 | public Float get(View object) { |
| 16162 | return object.getRotationX(); |
| 16163 | } |
| 16164 | }; |
| 16165 | |
| 16166 | /** |
| 16167 | * A Property wrapper around the <code>rotationY</code> functionality handled by the |
| 16168 | * {@link View#setRotationY(float)} and {@link View#getRotationY()} methods. |
| 16169 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16170 | public static final Property<View, Float> ROTATION_Y = new FloatProperty<View>("rotationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16171 | @Override |
| 16172 | public void setValue(View object, float value) { |
| 16173 | object.setRotationY(value); |
| 16174 | } |
| 16175 | |
| 16176 | @Override |
| 16177 | public Float get(View object) { |
| 16178 | return object.getRotationY(); |
| 16179 | } |
| 16180 | }; |
| 16181 | |
| 16182 | /** |
| 16183 | * A Property wrapper around the <code>scaleX</code> functionality handled by the |
| 16184 | * {@link View#setScaleX(float)} and {@link View#getScaleX()} methods. |
| 16185 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16186 | public static final Property<View, Float> SCALE_X = new FloatProperty<View>("scaleX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16187 | @Override |
| 16188 | public void setValue(View object, float value) { |
| 16189 | object.setScaleX(value); |
| 16190 | } |
| 16191 | |
| 16192 | @Override |
| 16193 | public Float get(View object) { |
| 16194 | return object.getScaleX(); |
| 16195 | } |
| 16196 | }; |
| 16197 | |
| 16198 | /** |
| 16199 | * A Property wrapper around the <code>scaleY</code> functionality handled by the |
| 16200 | * {@link View#setScaleY(float)} and {@link View#getScaleY()} methods. |
| 16201 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16202 | public static final Property<View, Float> SCALE_Y = new FloatProperty<View>("scaleY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16203 | @Override |
| 16204 | public void setValue(View object, float value) { |
| 16205 | object.setScaleY(value); |
| 16206 | } |
| 16207 | |
| 16208 | @Override |
| 16209 | public Float get(View object) { |
| 16210 | return object.getScaleY(); |
| 16211 | } |
| 16212 | }; |
| 16213 | |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 16214 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16215 | * A MeasureSpec encapsulates the layout requirements passed from parent to child. |
| 16216 | * Each MeasureSpec represents a requirement for either the width or the height. |
| 16217 | * A MeasureSpec is comprised of a size and a mode. There are three possible |
| 16218 | * modes: |
| 16219 | * <dl> |
| 16220 | * <dt>UNSPECIFIED</dt> |
| 16221 | * <dd> |
| 16222 | * The parent has not imposed any constraint on the child. It can be whatever size |
| 16223 | * it wants. |
| 16224 | * </dd> |
| 16225 | * |
| 16226 | * <dt>EXACTLY</dt> |
| 16227 | * <dd> |
| 16228 | * The parent has determined an exact size for the child. The child is going to be |
| 16229 | * given those bounds regardless of how big it wants to be. |
| 16230 | * </dd> |
| 16231 | * |
| 16232 | * <dt>AT_MOST</dt> |
| 16233 | * <dd> |
| 16234 | * The child can be as large as it wants up to the specified size. |
| 16235 | * </dd> |
| 16236 | * </dl> |
| 16237 | * |
| 16238 | * MeasureSpecs are implemented as ints to reduce object allocation. This class |
| 16239 | * is provided to pack and unpack the <size, mode> tuple into the int. |
| 16240 | */ |
| 16241 | public static class MeasureSpec { |
| 16242 | private static final int MODE_SHIFT = 30; |
| 16243 | private static final int MODE_MASK = 0x3 << MODE_SHIFT; |
| 16244 | |
| 16245 | /** |
| 16246 | * Measure specification mode: The parent has not imposed any constraint |
| 16247 | * on the child. It can be whatever size it wants. |
| 16248 | */ |
| 16249 | public static final int UNSPECIFIED = 0 << MODE_SHIFT; |
| 16250 | |
| 16251 | /** |
| 16252 | * Measure specification mode: The parent has determined an exact size |
| 16253 | * for the child. The child is going to be given those bounds regardless |
| 16254 | * of how big it wants to be. |
| 16255 | */ |
| 16256 | public static final int EXACTLY = 1 << MODE_SHIFT; |
| 16257 | |
| 16258 | /** |
| 16259 | * Measure specification mode: The child can be as large as it wants up |
| 16260 | * to the specified size. |
| 16261 | */ |
| 16262 | public static final int AT_MOST = 2 << MODE_SHIFT; |
| 16263 | |
| 16264 | /** |
| 16265 | * Creates a measure specification based on the supplied size and mode. |
| 16266 | * |
| 16267 | * The mode must always be one of the following: |
| 16268 | * <ul> |
| 16269 | * <li>{@link android.view.View.MeasureSpec#UNSPECIFIED}</li> |
| 16270 | * <li>{@link android.view.View.MeasureSpec#EXACTLY}</li> |
| 16271 | * <li>{@link android.view.View.MeasureSpec#AT_MOST}</li> |
| 16272 | * </ul> |
| 16273 | * |
| 16274 | * @param size the size of the measure specification |
| 16275 | * @param mode the mode of the measure specification |
| 16276 | * @return the measure specification based on size and mode |
| 16277 | */ |
| 16278 | public static int makeMeasureSpec(int size, int mode) { |
| 16279 | return size + mode; |
| 16280 | } |
| 16281 | |
| 16282 | /** |
| 16283 | * Extracts the mode from the supplied measure specification. |
| 16284 | * |
| 16285 | * @param measureSpec the measure specification to extract the mode from |
| 16286 | * @return {@link android.view.View.MeasureSpec#UNSPECIFIED}, |
| 16287 | * {@link android.view.View.MeasureSpec#AT_MOST} or |
| 16288 | * {@link android.view.View.MeasureSpec#EXACTLY} |
| 16289 | */ |
| 16290 | public static int getMode(int measureSpec) { |
| 16291 | return (measureSpec & MODE_MASK); |
| 16292 | } |
| 16293 | |
| 16294 | /** |
| 16295 | * Extracts the size from the supplied measure specification. |
| 16296 | * |
| 16297 | * @param measureSpec the measure specification to extract the size from |
| 16298 | * @return the size in pixels defined in the supplied measure specification |
| 16299 | */ |
| 16300 | public static int getSize(int measureSpec) { |
| 16301 | return (measureSpec & ~MODE_MASK); |
| 16302 | } |
| 16303 | |
| 16304 | /** |
| 16305 | * Returns a String representation of the specified measure |
| 16306 | * specification. |
| 16307 | * |
| 16308 | * @param measureSpec the measure specification to convert to a String |
| 16309 | * @return a String with the following format: "MeasureSpec: MODE SIZE" |
| 16310 | */ |
| 16311 | public static String toString(int measureSpec) { |
| 16312 | int mode = getMode(measureSpec); |
| 16313 | int size = getSize(measureSpec); |
| 16314 | |
| 16315 | StringBuilder sb = new StringBuilder("MeasureSpec: "); |
| 16316 | |
| 16317 | if (mode == UNSPECIFIED) |
| 16318 | sb.append("UNSPECIFIED "); |
| 16319 | else if (mode == EXACTLY) |
| 16320 | sb.append("EXACTLY "); |
| 16321 | else if (mode == AT_MOST) |
| 16322 | sb.append("AT_MOST "); |
| 16323 | else |
| 16324 | sb.append(mode).append(" "); |
| 16325 | |
| 16326 | sb.append(size); |
| 16327 | return sb.toString(); |
| 16328 | } |
| 16329 | } |
| 16330 | |
| 16331 | class CheckForLongPress implements Runnable { |
| 16332 | |
| 16333 | private int mOriginalWindowAttachCount; |
| 16334 | |
| 16335 | public void run() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 16336 | if (isPressed() && (mParent != null) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16337 | && mOriginalWindowAttachCount == mWindowAttachCount) { |
| 16338 | if (performLongClick()) { |
| 16339 | mHasPerformedLongPress = true; |
| 16340 | } |
| 16341 | } |
| 16342 | } |
| 16343 | |
| 16344 | public void rememberWindowAttachCount() { |
| 16345 | mOriginalWindowAttachCount = mWindowAttachCount; |
| 16346 | } |
| 16347 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16348 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 16349 | private final class CheckForTap implements Runnable { |
| 16350 | public void run() { |
| 16351 | mPrivateFlags &= ~PREPRESSED; |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 16352 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 16353 | checkForLongClick(ViewConfiguration.getTapTimeout()); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 16354 | } |
| 16355 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16356 | |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 16357 | private final class PerformClick implements Runnable { |
| 16358 | public void run() { |
| 16359 | performClick(); |
| 16360 | } |
| 16361 | } |
| 16362 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 16363 | /** @hide */ |
| 16364 | public void hackTurnOffWindowResizeAnim(boolean off) { |
| 16365 | mAttachInfo.mTurnOffWindowResizeAnim = off; |
| 16366 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16368 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 16369 | * This method returns a ViewPropertyAnimator object, which can be used to animate |
| 16370 | * specific properties on this View. |
| 16371 | * |
| 16372 | * @return ViewPropertyAnimator The ViewPropertyAnimator associated with this View. |
| 16373 | */ |
| 16374 | public ViewPropertyAnimator animate() { |
| 16375 | if (mAnimator == null) { |
| 16376 | mAnimator = new ViewPropertyAnimator(this); |
| 16377 | } |
| 16378 | return mAnimator; |
| 16379 | } |
| 16380 | |
| 16381 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16382 | * Interface definition for a callback to be invoked when a key event is |
| 16383 | * dispatched to this view. The callback will be invoked before the key |
| 16384 | * event is given to the view. |
| 16385 | */ |
| 16386 | public interface OnKeyListener { |
| 16387 | /** |
| 16388 | * Called when a key is dispatched to a view. This allows listeners to |
| 16389 | * get a chance to respond before the target view. |
| 16390 | * |
| 16391 | * @param v The view the key has been dispatched to. |
| 16392 | * @param keyCode The code for the physical key that was pressed |
| 16393 | * @param event The KeyEvent object containing full information about |
| 16394 | * the event. |
| 16395 | * @return True if the listener has consumed the event, false otherwise. |
| 16396 | */ |
| 16397 | boolean onKey(View v, int keyCode, KeyEvent event); |
| 16398 | } |
| 16399 | |
| 16400 | /** |
| 16401 | * Interface definition for a callback to be invoked when a touch event is |
| 16402 | * dispatched to this view. The callback will be invoked before the touch |
| 16403 | * event is given to the view. |
| 16404 | */ |
| 16405 | public interface OnTouchListener { |
| 16406 | /** |
| 16407 | * Called when a touch event is dispatched to a view. This allows listeners to |
| 16408 | * get a chance to respond before the target view. |
| 16409 | * |
| 16410 | * @param v The view the touch event has been dispatched to. |
| 16411 | * @param event The MotionEvent object containing full information about |
| 16412 | * the event. |
| 16413 | * @return True if the listener has consumed the event, false otherwise. |
| 16414 | */ |
| 16415 | boolean onTouch(View v, MotionEvent event); |
| 16416 | } |
| 16417 | |
| 16418 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 16419 | * Interface definition for a callback to be invoked when a hover event is |
| 16420 | * dispatched to this view. The callback will be invoked before the hover |
| 16421 | * event is given to the view. |
| 16422 | */ |
| 16423 | public interface OnHoverListener { |
| 16424 | /** |
| 16425 | * Called when a hover event is dispatched to a view. This allows listeners to |
| 16426 | * get a chance to respond before the target view. |
| 16427 | * |
| 16428 | * @param v The view the hover event has been dispatched to. |
| 16429 | * @param event The MotionEvent object containing full information about |
| 16430 | * the event. |
| 16431 | * @return True if the listener has consumed the event, false otherwise. |
| 16432 | */ |
| 16433 | boolean onHover(View v, MotionEvent event); |
| 16434 | } |
| 16435 | |
| 16436 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 16437 | * Interface definition for a callback to be invoked when a generic motion event is |
| 16438 | * dispatched to this view. The callback will be invoked before the generic motion |
| 16439 | * event is given to the view. |
| 16440 | */ |
| 16441 | public interface OnGenericMotionListener { |
| 16442 | /** |
| 16443 | * Called when a generic motion event is dispatched to a view. This allows listeners to |
| 16444 | * get a chance to respond before the target view. |
| 16445 | * |
| 16446 | * @param v The view the generic motion event has been dispatched to. |
| 16447 | * @param event The MotionEvent object containing full information about |
| 16448 | * the event. |
| 16449 | * @return True if the listener has consumed the event, false otherwise. |
| 16450 | */ |
| 16451 | boolean onGenericMotion(View v, MotionEvent event); |
| 16452 | } |
| 16453 | |
| 16454 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16455 | * Interface definition for a callback to be invoked when a view has been clicked and held. |
| 16456 | */ |
| 16457 | public interface OnLongClickListener { |
| 16458 | /** |
| 16459 | * Called when a view has been clicked and held. |
| 16460 | * |
| 16461 | * @param v The view that was clicked and held. |
| 16462 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 16463 | * @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] | 16464 | */ |
| 16465 | boolean onLongClick(View v); |
| 16466 | } |
| 16467 | |
| 16468 | /** |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 16469 | * Interface definition for a callback to be invoked when a drag is being dispatched |
| 16470 | * to this view. The callback will be invoked before the hosting view's own |
| 16471 | * onDrag(event) method. If the listener wants to fall back to the hosting view's |
| 16472 | * onDrag(event) behavior, it should return 'false' from this callback. |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 16473 | * |
| 16474 | * <div class="special reference"> |
| 16475 | * <h3>Developer Guides</h3> |
| 16476 | * <p>For a guide to implementing drag and drop features, read the |
| 16477 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 16478 | * </div> |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 16479 | */ |
| 16480 | public interface OnDragListener { |
| 16481 | /** |
| 16482 | * Called when a drag event is dispatched to a view. This allows listeners |
| 16483 | * to get a chance to override base View behavior. |
| 16484 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16485 | * @param v The View that received the drag event. |
| 16486 | * @param event The {@link android.view.DragEvent} object for the drag event. |
| 16487 | * @return {@code true} if the drag event was handled successfully, or {@code false} |
| 16488 | * if the drag event was not handled. Note that {@code false} will trigger the View |
| 16489 | * to call its {@link #onDragEvent(DragEvent) onDragEvent()} handler. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 16490 | */ |
| 16491 | boolean onDrag(View v, DragEvent event); |
| 16492 | } |
| 16493 | |
| 16494 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16495 | * Interface definition for a callback to be invoked when the focus state of |
| 16496 | * a view changed. |
| 16497 | */ |
| 16498 | public interface OnFocusChangeListener { |
| 16499 | /** |
| 16500 | * Called when the focus state of a view has changed. |
| 16501 | * |
| 16502 | * @param v The view whose state has changed. |
| 16503 | * @param hasFocus The new focus state of v. |
| 16504 | */ |
| 16505 | void onFocusChange(View v, boolean hasFocus); |
| 16506 | } |
| 16507 | |
| 16508 | /** |
| 16509 | * Interface definition for a callback to be invoked when a view is clicked. |
| 16510 | */ |
| 16511 | public interface OnClickListener { |
| 16512 | /** |
| 16513 | * Called when a view has been clicked. |
| 16514 | * |
| 16515 | * @param v The view that was clicked. |
| 16516 | */ |
| 16517 | void onClick(View v); |
| 16518 | } |
| 16519 | |
| 16520 | /** |
| 16521 | * Interface definition for a callback to be invoked when the context menu |
| 16522 | * for this view is being built. |
| 16523 | */ |
| 16524 | public interface OnCreateContextMenuListener { |
| 16525 | /** |
| 16526 | * Called when the context menu for this view is being built. It is not |
| 16527 | * safe to hold onto the menu after this method returns. |
| 16528 | * |
| 16529 | * @param menu The context menu that is being built |
| 16530 | * @param v The view for which the context menu is being built |
| 16531 | * @param menuInfo Extra information about the item for which the |
| 16532 | * context menu should be shown. This information will vary |
| 16533 | * depending on the class of v. |
| 16534 | */ |
| 16535 | void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo); |
| 16536 | } |
| 16537 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16538 | /** |
| 16539 | * 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] | 16540 | * visibility. This reports <strong>global</strong> changes to the system UI |
| 16541 | * state, not just what the application is requesting. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16542 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 16543 | * @see View#setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16544 | */ |
| 16545 | public interface OnSystemUiVisibilityChangeListener { |
| 16546 | /** |
| 16547 | * Called when the status bar changes visibility because of a call to |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 16548 | * {@link View#setSystemUiVisibility(int)}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16549 | * |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 16550 | * @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] | 16551 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. This tells you the |
| 16552 | * <strong>global</strong> state of the UI visibility flags, not what your |
| 16553 | * app is currently applying. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16554 | */ |
| 16555 | public void onSystemUiVisibilityChange(int visibility); |
| 16556 | } |
| 16557 | |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 16558 | /** |
| 16559 | * Interface definition for a callback to be invoked when this view is attached |
| 16560 | * or detached from its window. |
| 16561 | */ |
| 16562 | public interface OnAttachStateChangeListener { |
| 16563 | /** |
| 16564 | * Called when the view is attached to a window. |
| 16565 | * @param v The view that was attached |
| 16566 | */ |
| 16567 | public void onViewAttachedToWindow(View v); |
| 16568 | /** |
| 16569 | * Called when the view is detached from a window. |
| 16570 | * @param v The view that was detached |
| 16571 | */ |
| 16572 | public void onViewDetachedFromWindow(View v); |
| 16573 | } |
| 16574 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16575 | private final class UnsetPressedState implements Runnable { |
| 16576 | public void run() { |
| 16577 | setPressed(false); |
| 16578 | } |
| 16579 | } |
| 16580 | |
| 16581 | /** |
| 16582 | * Base class for derived classes that want to save and restore their own |
| 16583 | * state in {@link android.view.View#onSaveInstanceState()}. |
| 16584 | */ |
| 16585 | public static class BaseSavedState extends AbsSavedState { |
| 16586 | /** |
| 16587 | * Constructor used when reading from a parcel. Reads the state of the superclass. |
| 16588 | * |
| 16589 | * @param source |
| 16590 | */ |
| 16591 | public BaseSavedState(Parcel source) { |
| 16592 | super(source); |
| 16593 | } |
| 16594 | |
| 16595 | /** |
| 16596 | * Constructor called by derived classes when creating their SavedState objects |
| 16597 | * |
| 16598 | * @param superState The state of the superclass of this view |
| 16599 | */ |
| 16600 | public BaseSavedState(Parcelable superState) { |
| 16601 | super(superState); |
| 16602 | } |
| 16603 | |
| 16604 | public static final Parcelable.Creator<BaseSavedState> CREATOR = |
| 16605 | new Parcelable.Creator<BaseSavedState>() { |
| 16606 | public BaseSavedState createFromParcel(Parcel in) { |
| 16607 | return new BaseSavedState(in); |
| 16608 | } |
| 16609 | |
| 16610 | public BaseSavedState[] newArray(int size) { |
| 16611 | return new BaseSavedState[size]; |
| 16612 | } |
| 16613 | }; |
| 16614 | } |
| 16615 | |
| 16616 | /** |
| 16617 | * A set of information given to a view when it is attached to its parent |
| 16618 | * window. |
| 16619 | */ |
| 16620 | static class AttachInfo { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16621 | interface Callbacks { |
| 16622 | void playSoundEffect(int effectId); |
| 16623 | boolean performHapticFeedback(int effectId, boolean always); |
| 16624 | } |
| 16625 | |
| 16626 | /** |
| 16627 | * InvalidateInfo is used to post invalidate(int, int, int, int) messages |
| 16628 | * to a Handler. This class contains the target (View) to invalidate and |
| 16629 | * the coordinates of the dirty rectangle. |
| 16630 | * |
| 16631 | * For performance purposes, this class also implements a pool of up to |
| 16632 | * POOL_LIMIT objects that get reused. This reduces memory allocations |
| 16633 | * whenever possible. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16634 | */ |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16635 | static class InvalidateInfo implements Poolable<InvalidateInfo> { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16636 | private static final int POOL_LIMIT = 10; |
Romain Guy | 2e9bbce | 2009-04-01 10:40:10 -0700 | [diff] [blame] | 16637 | private static final Pool<InvalidateInfo> sPool = Pools.synchronizedPool( |
| 16638 | Pools.finitePool(new PoolableManager<InvalidateInfo>() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16639 | public InvalidateInfo newInstance() { |
| 16640 | return new InvalidateInfo(); |
| 16641 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16642 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16643 | public void onAcquired(InvalidateInfo element) { |
| 16644 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16645 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16646 | public void onReleased(InvalidateInfo element) { |
Romain Guy | 40c18f5 | 2011-09-01 17:01:18 -0700 | [diff] [blame] | 16647 | element.target = null; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16648 | } |
| 16649 | }, POOL_LIMIT) |
| 16650 | ); |
| 16651 | |
| 16652 | private InvalidateInfo mNext; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 16653 | private boolean mIsPooled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16654 | |
| 16655 | View target; |
| 16656 | |
| 16657 | int left; |
| 16658 | int top; |
| 16659 | int right; |
| 16660 | int bottom; |
| 16661 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16662 | public void setNextPoolable(InvalidateInfo element) { |
| 16663 | mNext = element; |
| 16664 | } |
| 16665 | |
| 16666 | public InvalidateInfo getNextPoolable() { |
| 16667 | return mNext; |
| 16668 | } |
| 16669 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16670 | static InvalidateInfo acquire() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16671 | return sPool.acquire(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16672 | } |
| 16673 | |
| 16674 | void release() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16675 | sPool.release(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16676 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 16677 | |
| 16678 | public boolean isPooled() { |
| 16679 | return mIsPooled; |
| 16680 | } |
| 16681 | |
| 16682 | public void setPooled(boolean isPooled) { |
| 16683 | mIsPooled = isPooled; |
| 16684 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16685 | } |
| 16686 | |
| 16687 | final IWindowSession mSession; |
| 16688 | |
| 16689 | final IWindow mWindow; |
| 16690 | |
| 16691 | final IBinder mWindowToken; |
| 16692 | |
| 16693 | final Callbacks mRootCallbacks; |
| 16694 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 16695 | HardwareCanvas mHardwareCanvas; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 16696 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16697 | /** |
| 16698 | * The top view of the hierarchy. |
| 16699 | */ |
| 16700 | View mRootView; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 16701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16702 | IBinder mPanelParentWindowToken; |
| 16703 | Surface mSurface; |
| 16704 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 16705 | boolean mHardwareAccelerated; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 16706 | boolean mHardwareAccelerationRequested; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 16707 | HardwareRenderer mHardwareRenderer; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16708 | |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 16709 | boolean mScreenOn; |
| 16710 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16711 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 16712 | * Scale factor used by the compatibility mode |
| 16713 | */ |
| 16714 | float mApplicationScale; |
| 16715 | |
| 16716 | /** |
| 16717 | * Indicates whether the application is in compatibility mode |
| 16718 | */ |
| 16719 | boolean mScalingRequired; |
| 16720 | |
| 16721 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 16722 | * 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] | 16723 | */ |
| 16724 | boolean mTurnOffWindowResizeAnim; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16725 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 16726 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16727 | * Left position of this view's window |
| 16728 | */ |
| 16729 | int mWindowLeft; |
| 16730 | |
| 16731 | /** |
| 16732 | * Top position of this view's window |
| 16733 | */ |
| 16734 | int mWindowTop; |
| 16735 | |
| 16736 | /** |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 16737 | * Indicates whether views need to use 32-bit drawing caches |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 16738 | */ |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 16739 | boolean mUse32BitDrawingCache; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 16740 | |
| 16741 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16742 | * For windows that are full-screen but using insets to layout inside |
| 16743 | * of the screen decorations, these are the current insets for the |
| 16744 | * content of the window. |
| 16745 | */ |
| 16746 | final Rect mContentInsets = new Rect(); |
| 16747 | |
| 16748 | /** |
| 16749 | * For windows that are full-screen but using insets to layout inside |
| 16750 | * of the screen decorations, these are the current insets for the |
| 16751 | * actual visible parts of the window. |
| 16752 | */ |
| 16753 | final Rect mVisibleInsets = new Rect(); |
| 16754 | |
| 16755 | /** |
| 16756 | * The internal insets given by this window. This value is |
| 16757 | * supplied by the client (through |
| 16758 | * {@link ViewTreeObserver.OnComputeInternalInsetsListener}) and will |
| 16759 | * be given to the window manager when changed to be used in laying |
| 16760 | * out windows behind it. |
| 16761 | */ |
| 16762 | final ViewTreeObserver.InternalInsetsInfo mGivenInternalInsets |
| 16763 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 16764 | |
| 16765 | /** |
| 16766 | * All views in the window's hierarchy that serve as scroll containers, |
| 16767 | * used to determine if the window can be resized or must be panned |
| 16768 | * to adjust for a soft input area. |
| 16769 | */ |
| 16770 | final ArrayList<View> mScrollContainers = new ArrayList<View>(); |
| 16771 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 16772 | final KeyEvent.DispatcherState mKeyDispatchState |
| 16773 | = new KeyEvent.DispatcherState(); |
| 16774 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16775 | /** |
| 16776 | * Indicates whether the view's window currently has the focus. |
| 16777 | */ |
| 16778 | boolean mHasWindowFocus; |
| 16779 | |
| 16780 | /** |
| 16781 | * The current visibility of the window. |
| 16782 | */ |
| 16783 | int mWindowVisibility; |
| 16784 | |
| 16785 | /** |
| 16786 | * Indicates the time at which drawing started to occur. |
| 16787 | */ |
| 16788 | long mDrawingTime; |
| 16789 | |
| 16790 | /** |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 16791 | * Indicates whether or not ignoring the DIRTY_MASK flags. |
| 16792 | */ |
| 16793 | boolean mIgnoreDirtyState; |
| 16794 | |
| 16795 | /** |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 16796 | * This flag tracks when the mIgnoreDirtyState flag is set during draw(), |
| 16797 | * to avoid clearing that flag prematurely. |
| 16798 | */ |
| 16799 | boolean mSetIgnoreDirtyState = false; |
| 16800 | |
| 16801 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16802 | * Indicates whether the view's window is currently in touch mode. |
| 16803 | */ |
| 16804 | boolean mInTouchMode; |
| 16805 | |
| 16806 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 16807 | * Indicates that ViewAncestor should trigger a global layout change |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16808 | * the next time it performs a traversal |
| 16809 | */ |
| 16810 | boolean mRecomputeGlobalAttributes; |
| 16811 | |
| 16812 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16813 | * Always report new attributes at next traversal. |
| 16814 | */ |
| 16815 | boolean mForceReportNewAttributes; |
| 16816 | |
| 16817 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16818 | * Set during a traveral if any views want to keep the screen on. |
| 16819 | */ |
| 16820 | boolean mKeepScreenOn; |
| 16821 | |
| 16822 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16823 | * Bitwise-or of all of the values that views have passed to setSystemUiVisibility(). |
| 16824 | */ |
| 16825 | int mSystemUiVisibility; |
| 16826 | |
| 16827 | /** |
| 16828 | * True if a view in this hierarchy has an OnSystemUiVisibilityChangeListener |
| 16829 | * attached. |
| 16830 | */ |
| 16831 | boolean mHasSystemUiListeners; |
| 16832 | |
| 16833 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16834 | * Set if the visibility of any views has changed. |
| 16835 | */ |
| 16836 | boolean mViewVisibilityChanged; |
| 16837 | |
| 16838 | /** |
| 16839 | * Set to true if a view has been scrolled. |
| 16840 | */ |
| 16841 | boolean mViewScrollChanged; |
| 16842 | |
| 16843 | /** |
| 16844 | * Global to the view hierarchy used as a temporary for dealing with |
| 16845 | * x/y points in the transparent region computations. |
| 16846 | */ |
| 16847 | final int[] mTransparentLocation = new int[2]; |
| 16848 | |
| 16849 | /** |
| 16850 | * Global to the view hierarchy used as a temporary for dealing with |
| 16851 | * x/y points in the ViewGroup.invalidateChild implementation. |
| 16852 | */ |
| 16853 | final int[] mInvalidateChildLocation = new int[2]; |
| 16854 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 16855 | |
| 16856 | /** |
| 16857 | * Global to the view hierarchy used as a temporary for dealing with |
| 16858 | * x/y location when view is transformed. |
| 16859 | */ |
| 16860 | final float[] mTmpTransformLocation = new float[2]; |
| 16861 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16862 | /** |
| 16863 | * The view tree observer used to dispatch global events like |
| 16864 | * layout, pre-draw, touch mode change, etc. |
| 16865 | */ |
| 16866 | final ViewTreeObserver mTreeObserver = new ViewTreeObserver(); |
| 16867 | |
| 16868 | /** |
| 16869 | * A Canvas used by the view hierarchy to perform bitmap caching. |
| 16870 | */ |
| 16871 | Canvas mCanvas; |
| 16872 | |
| 16873 | /** |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 16874 | * The view root impl. |
| 16875 | */ |
| 16876 | final ViewRootImpl mViewRootImpl; |
| 16877 | |
| 16878 | /** |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 16879 | * 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] | 16880 | * handler can be used to pump events in the UI events queue. |
| 16881 | */ |
| 16882 | final Handler mHandler; |
| 16883 | |
| 16884 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16885 | * Temporary for use in computing invalidate rectangles while |
| 16886 | * calling up the hierarchy. |
| 16887 | */ |
| 16888 | final Rect mTmpInvalRect = new Rect(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 16889 | |
| 16890 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 16891 | * Temporary for use in computing hit areas with transformed views |
| 16892 | */ |
| 16893 | final RectF mTmpTransformRect = new RectF(); |
| 16894 | |
| 16895 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 16896 | * Temporary list for use in collecting focusable descendents of a view. |
| 16897 | */ |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 16898 | final ArrayList<View> mTempArrayList = new ArrayList<View>(24); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 16899 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16900 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 16901 | * The id of the window for accessibility purposes. |
| 16902 | */ |
| 16903 | int mAccessibilityWindowId = View.NO_ID; |
| 16904 | |
| 16905 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 16906 | * Whether to ingore not exposed for accessibility Views when |
| 16907 | * reporting the view tree to accessibility services. |
| 16908 | */ |
| 16909 | boolean mIncludeNotImportantViews; |
| 16910 | |
| 16911 | /** |
| 16912 | * The drawable for highlighting accessibility focus. |
| 16913 | */ |
| 16914 | Drawable mAccessibilityFocusDrawable; |
| 16915 | |
| 16916 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16917 | * Creates a new set of attachment information with the specified |
| 16918 | * events handler and thread. |
| 16919 | * |
| 16920 | * @param handler the events handler the view must use |
| 16921 | */ |
| 16922 | AttachInfo(IWindowSession session, IWindow window, |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 16923 | ViewRootImpl viewRootImpl, Handler handler, Callbacks effectPlayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16924 | mSession = session; |
| 16925 | mWindow = window; |
| 16926 | mWindowToken = window.asBinder(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 16927 | mViewRootImpl = viewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16928 | mHandler = handler; |
| 16929 | mRootCallbacks = effectPlayer; |
| 16930 | } |
| 16931 | } |
| 16932 | |
| 16933 | /** |
| 16934 | * <p>ScrollabilityCache holds various fields used by a View when scrolling |
| 16935 | * is supported. This avoids keeping too many unused fields in most |
| 16936 | * instances of View.</p> |
| 16937 | */ |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16938 | private static class ScrollabilityCache implements Runnable { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16939 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16940 | /** |
| 16941 | * Scrollbars are not visible |
| 16942 | */ |
| 16943 | public static final int OFF = 0; |
| 16944 | |
| 16945 | /** |
| 16946 | * Scrollbars are visible |
| 16947 | */ |
| 16948 | public static final int ON = 1; |
| 16949 | |
| 16950 | /** |
| 16951 | * Scrollbars are fading away |
| 16952 | */ |
| 16953 | public static final int FADING = 2; |
| 16954 | |
| 16955 | public boolean fadeScrollBars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16956 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16957 | public int fadingEdgeLength; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16958 | public int scrollBarDefaultDelayBeforeFade; |
| 16959 | public int scrollBarFadeDuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16960 | |
| 16961 | public int scrollBarSize; |
| 16962 | public ScrollBarDrawable scrollBar; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16963 | public float[] interpolatorValues; |
| 16964 | public View host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16965 | |
| 16966 | public final Paint paint; |
| 16967 | public final Matrix matrix; |
| 16968 | public Shader shader; |
| 16969 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16970 | public final Interpolator scrollBarInterpolator = new Interpolator(1, 2); |
| 16971 | |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 16972 | private static final float[] OPAQUE = { 255 }; |
| 16973 | private static final float[] TRANSPARENT = { 0.0f }; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16974 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16975 | /** |
| 16976 | * When fading should start. This time moves into the future every time |
| 16977 | * a new scroll happens. Measured based on SystemClock.uptimeMillis() |
| 16978 | */ |
| 16979 | public long fadeStartTime; |
| 16980 | |
| 16981 | |
| 16982 | /** |
| 16983 | * The current state of the scrollbars: ON, OFF, or FADING |
| 16984 | */ |
| 16985 | public int state = OFF; |
| 16986 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16987 | private int mLastColor; |
| 16988 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 16989 | public ScrollabilityCache(ViewConfiguration configuration, View host) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16990 | fadingEdgeLength = configuration.getScaledFadingEdgeLength(); |
| 16991 | scrollBarSize = configuration.getScaledScrollBarSize(); |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 16992 | scrollBarDefaultDelayBeforeFade = ViewConfiguration.getScrollDefaultDelay(); |
| 16993 | scrollBarFadeDuration = ViewConfiguration.getScrollBarFadeDuration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16994 | |
| 16995 | paint = new Paint(); |
| 16996 | matrix = new Matrix(); |
| 16997 | // use use a height of 1, and then wack the matrix each time we |
| 16998 | // actually use it. |
| 16999 | shader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17001 | paint.setShader(shader); |
| 17002 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17003 | this.host = host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17004 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17005 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17006 | public void setFadeColor(int color) { |
| 17007 | if (color != 0 && color != mLastColor) { |
| 17008 | mLastColor = color; |
| 17009 | color |= 0xFF000000; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17010 | |
Romain Guy | e55e1a7 | 2009-08-27 10:42:26 -0700 | [diff] [blame] | 17011 | shader = new LinearGradient(0, 0, 0, 1, color | 0xFF000000, |
| 17012 | color & 0x00FFFFFF, Shader.TileMode.CLAMP); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17013 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17014 | paint.setShader(shader); |
| 17015 | // Restore the default transfer mode (src_over) |
| 17016 | paint.setXfermode(null); |
| 17017 | } |
| 17018 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17019 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17020 | public void run() { |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 17021 | long now = AnimationUtils.currentAnimationTimeMillis(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17022 | if (now >= fadeStartTime) { |
| 17023 | |
| 17024 | // the animation fades the scrollbars out by changing |
| 17025 | // the opacity (alpha) from fully opaque to fully |
| 17026 | // transparent |
| 17027 | int nextFrame = (int) now; |
| 17028 | int framesCount = 0; |
| 17029 | |
| 17030 | Interpolator interpolator = scrollBarInterpolator; |
| 17031 | |
| 17032 | // Start opaque |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 17033 | interpolator.setKeyFrame(framesCount++, nextFrame, OPAQUE); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17034 | |
| 17035 | // End transparent |
| 17036 | nextFrame += scrollBarFadeDuration; |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 17037 | interpolator.setKeyFrame(framesCount, nextFrame, TRANSPARENT); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17038 | |
| 17039 | state = FADING; |
| 17040 | |
| 17041 | // Kick off the fade animation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 17042 | host.invalidate(true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17043 | } |
| 17044 | } |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 17045 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17046 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 17047 | /** |
| 17048 | * Resuable callback for sending |
| 17049 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 17050 | */ |
| 17051 | private class SendViewScrolledAccessibilityEvent implements Runnable { |
| 17052 | public volatile boolean mIsPending; |
| 17053 | |
| 17054 | public void run() { |
| 17055 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED); |
| 17056 | mIsPending = false; |
| 17057 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17058 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 17059 | |
| 17060 | /** |
| 17061 | * <p> |
| 17062 | * This class represents a delegate that can be registered in a {@link View} |
| 17063 | * to enhance accessibility support via composition rather via inheritance. |
| 17064 | * It is specifically targeted to widget developers that extend basic View |
| 17065 | * classes i.e. classes in package android.view, that would like their |
| 17066 | * applications to be backwards compatible. |
| 17067 | * </p> |
Joe Fernandez | e1302ed | 2012-02-06 14:30:15 -0800 | [diff] [blame] | 17068 | * <div class="special reference"> |
| 17069 | * <h3>Developer Guides</h3> |
| 17070 | * <p>For more information about making applications accessible, read the |
| 17071 | * <a href="{@docRoot}guide/topics/ui/accessibility/index.html">Accessibility</a> |
| 17072 | * developer guide.</p> |
| 17073 | * </div> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 17074 | * <p> |
| 17075 | * A scenario in which a developer would like to use an accessibility delegate |
| 17076 | * is overriding a method introduced in a later API version then the minimal API |
| 17077 | * version supported by the application. For example, the method |
| 17078 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} is not available |
| 17079 | * in API version 4 when the accessibility APIs were first introduced. If a |
| 17080 | * developer would like his application to run on API version 4 devices (assuming |
| 17081 | * all other APIs used by the application are version 4 or lower) and take advantage |
| 17082 | * of this method, instead of overriding the method which would break the application's |
| 17083 | * backwards compatibility, he can override the corresponding method in this |
| 17084 | * delegate and register the delegate in the target View if the API version of |
| 17085 | * the system is high enough i.e. the API version is same or higher to the API |
| 17086 | * version that introduced |
| 17087 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)}. |
| 17088 | * </p> |
| 17089 | * <p> |
| 17090 | * Here is an example implementation: |
| 17091 | * </p> |
| 17092 | * <code><pre><p> |
| 17093 | * if (Build.VERSION.SDK_INT >= 14) { |
| 17094 | * // If the API version is equal of higher than the version in |
| 17095 | * // which onInitializeAccessibilityNodeInfo was introduced we |
| 17096 | * // register a delegate with a customized implementation. |
| 17097 | * View view = findViewById(R.id.view_id); |
| 17098 | * view.setAccessibilityDelegate(new AccessibilityDelegate() { |
| 17099 | * public void onInitializeAccessibilityNodeInfo(View host, |
| 17100 | * AccessibilityNodeInfo info) { |
| 17101 | * // Let the default implementation populate the info. |
| 17102 | * super.onInitializeAccessibilityNodeInfo(host, info); |
| 17103 | * // Set some other information. |
| 17104 | * info.setEnabled(host.isEnabled()); |
| 17105 | * } |
| 17106 | * }); |
| 17107 | * } |
| 17108 | * </code></pre></p> |
| 17109 | * <p> |
| 17110 | * This delegate contains methods that correspond to the accessibility methods |
| 17111 | * in View. If a delegate has been specified the implementation in View hands |
| 17112 | * off handling to the corresponding method in this delegate. The default |
| 17113 | * implementation the delegate methods behaves exactly as the corresponding |
| 17114 | * method in View for the case of no accessibility delegate been set. Hence, |
| 17115 | * to customize the behavior of a View method, clients can override only the |
| 17116 | * corresponding delegate method without altering the behavior of the rest |
| 17117 | * accessibility related methods of the host view. |
| 17118 | * </p> |
| 17119 | */ |
| 17120 | public static class AccessibilityDelegate { |
| 17121 | |
| 17122 | /** |
| 17123 | * Sends an accessibility event of the given type. If accessibility is not |
| 17124 | * enabled this method has no effect. |
| 17125 | * <p> |
| 17126 | * The default implementation behaves as {@link View#sendAccessibilityEvent(int) |
| 17127 | * View#sendAccessibilityEvent(int)} for the case of no accessibility delegate |
| 17128 | * been set. |
| 17129 | * </p> |
| 17130 | * |
| 17131 | * @param host The View hosting the delegate. |
| 17132 | * @param eventType The type of the event to send. |
| 17133 | * |
| 17134 | * @see View#sendAccessibilityEvent(int) View#sendAccessibilityEvent(int) |
| 17135 | */ |
| 17136 | public void sendAccessibilityEvent(View host, int eventType) { |
| 17137 | host.sendAccessibilityEventInternal(eventType); |
| 17138 | } |
| 17139 | |
| 17140 | /** |
| 17141 | * Sends an accessibility event. This method behaves exactly as |
| 17142 | * {@link #sendAccessibilityEvent(View, int)} but takes as an argument an |
| 17143 | * empty {@link AccessibilityEvent} and does not perform a check whether |
| 17144 | * accessibility is enabled. |
| 17145 | * <p> |
| 17146 | * The default implementation behaves as |
| 17147 | * {@link View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 17148 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent)} for |
| 17149 | * the case of no accessibility delegate been set. |
| 17150 | * </p> |
| 17151 | * |
| 17152 | * @param host The View hosting the delegate. |
| 17153 | * @param event The event to send. |
| 17154 | * |
| 17155 | * @see View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 17156 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 17157 | */ |
| 17158 | public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) { |
| 17159 | host.sendAccessibilityEventUncheckedInternal(event); |
| 17160 | } |
| 17161 | |
| 17162 | /** |
| 17163 | * Dispatches an {@link AccessibilityEvent} to the host {@link View} first and then |
| 17164 | * to its children for adding their text content to the event. |
| 17165 | * <p> |
| 17166 | * The default implementation behaves as |
| 17167 | * {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 17168 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 17169 | * the case of no accessibility delegate been set. |
| 17170 | * </p> |
| 17171 | * |
| 17172 | * @param host The View hosting the delegate. |
| 17173 | * @param event The event. |
| 17174 | * @return True if the event population was completed. |
| 17175 | * |
| 17176 | * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 17177 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 17178 | */ |
| 17179 | public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 17180 | return host.dispatchPopulateAccessibilityEventInternal(event); |
| 17181 | } |
| 17182 | |
| 17183 | /** |
| 17184 | * Gives a chance to the host View to populate the accessibility event with its |
| 17185 | * text content. |
| 17186 | * <p> |
| 17187 | * The default implementation behaves as |
| 17188 | * {@link View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 17189 | * View#onPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 17190 | * the case of no accessibility delegate been set. |
| 17191 | * </p> |
| 17192 | * |
| 17193 | * @param host The View hosting the delegate. |
| 17194 | * @param event The accessibility event which to populate. |
| 17195 | * |
| 17196 | * @see View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 17197 | * View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 17198 | */ |
| 17199 | public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 17200 | host.onPopulateAccessibilityEventInternal(event); |
| 17201 | } |
| 17202 | |
| 17203 | /** |
| 17204 | * Initializes an {@link AccessibilityEvent} with information about the |
| 17205 | * the host View which is the event source. |
| 17206 | * <p> |
| 17207 | * The default implementation behaves as |
| 17208 | * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 17209 | * View#onInitializeAccessibilityEvent(AccessibilityEvent)} for |
| 17210 | * the case of no accessibility delegate been set. |
| 17211 | * </p> |
| 17212 | * |
| 17213 | * @param host The View hosting the delegate. |
| 17214 | * @param event The event to initialize. |
| 17215 | * |
| 17216 | * @see View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 17217 | * View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 17218 | */ |
| 17219 | public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { |
| 17220 | host.onInitializeAccessibilityEventInternal(event); |
| 17221 | } |
| 17222 | |
| 17223 | /** |
| 17224 | * Initializes an {@link AccessibilityNodeInfo} with information about the host view. |
| 17225 | * <p> |
| 17226 | * The default implementation behaves as |
| 17227 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 17228 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} for |
| 17229 | * the case of no accessibility delegate been set. |
| 17230 | * </p> |
| 17231 | * |
| 17232 | * @param host The View hosting the delegate. |
| 17233 | * @param info The instance to initialize. |
| 17234 | * |
| 17235 | * @see View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 17236 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 17237 | */ |
| 17238 | public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 17239 | host.onInitializeAccessibilityNodeInfoInternal(info); |
| 17240 | } |
| 17241 | |
| 17242 | /** |
| 17243 | * Called when a child of the host View has requested sending an |
| 17244 | * {@link AccessibilityEvent} and gives an opportunity to the parent (the host) |
| 17245 | * to augment the event. |
| 17246 | * <p> |
| 17247 | * The default implementation behaves as |
| 17248 | * {@link ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 17249 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent)} for |
| 17250 | * the case of no accessibility delegate been set. |
| 17251 | * </p> |
| 17252 | * |
| 17253 | * @param host The View hosting the delegate. |
| 17254 | * @param child The child which requests sending the event. |
| 17255 | * @param event The event to be sent. |
| 17256 | * @return True if the event should be sent |
| 17257 | * |
| 17258 | * @see ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 17259 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 17260 | */ |
| 17261 | public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, |
| 17262 | AccessibilityEvent event) { |
| 17263 | return host.onRequestSendAccessibilityEventInternal(child, event); |
| 17264 | } |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 17265 | |
| 17266 | /** |
| 17267 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 17268 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 17269 | * that explore the window content. |
| 17270 | * <p> |
| 17271 | * The default implementation behaves as |
| 17272 | * {@link View#getAccessibilityNodeProvider() View#getAccessibilityNodeProvider()} for |
| 17273 | * the case of no accessibility delegate been set. |
| 17274 | * </p> |
| 17275 | * |
| 17276 | * @return The provider. |
| 17277 | * |
| 17278 | * @see AccessibilityNodeProvider |
| 17279 | */ |
| 17280 | public AccessibilityNodeProvider getAccessibilityNodeProvider(View host) { |
| 17281 | return null; |
| 17282 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 17283 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17284 | } |