The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.view; |
| 18 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 19 | import android.content.ClipData; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 21 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.res.Resources; |
| 23 | import android.content.res.TypedArray; |
| 24 | import android.graphics.Bitmap; |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 25 | import android.graphics.Camera; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.graphics.Canvas; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 27 | import android.graphics.Interpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.graphics.LinearGradient; |
| 29 | import android.graphics.Matrix; |
| 30 | import android.graphics.Paint; |
| 31 | import android.graphics.PixelFormat; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 32 | import android.graphics.Point; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.graphics.PorterDuff; |
| 34 | import android.graphics.PorterDuffXfermode; |
| 35 | import android.graphics.Rect; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 36 | import android.graphics.RectF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.graphics.Region; |
| 38 | import android.graphics.Shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.graphics.drawable.ColorDrawable; |
| 40 | import android.graphics.drawable.Drawable; |
| 41 | import android.os.Handler; |
| 42 | import android.os.IBinder; |
| 43 | import android.os.Message; |
| 44 | import android.os.Parcel; |
| 45 | import android.os.Parcelable; |
| 46 | import android.os.RemoteException; |
| 47 | import android.os.SystemClock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.util.AttributeSet; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 49 | import android.util.FloatProperty; |
| 50 | import android.util.LocaleUtil; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.util.Log; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 52 | import android.util.Pool; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 53 | import android.util.Poolable; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 54 | import android.util.PoolableManager; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 55 | import android.util.Pools; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 56 | import android.util.Property; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 57 | import android.util.SparseArray; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 58 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.view.ContextMenu.ContextMenuInfo; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 60 | import android.view.accessibility.AccessibilityEvent; |
| 61 | import android.view.accessibility.AccessibilityEventSource; |
| 62 | import android.view.accessibility.AccessibilityManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 63 | import android.view.accessibility.AccessibilityNodeInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.view.animation.Animation; |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 65 | import android.view.animation.AnimationUtils; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 66 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.view.inputmethod.InputConnection; |
| 68 | import android.view.inputmethod.InputMethodManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.widget.ScrollBarDrawable; |
| 70 | |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 71 | import com.android.internal.R; |
| 72 | import com.android.internal.util.Predicate; |
| 73 | import com.android.internal.view.menu.MenuBuilder; |
| 74 | |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 75 | import java.lang.ref.WeakReference; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 76 | import java.lang.reflect.InvocationTargetException; |
| 77 | import java.lang.reflect.Method; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | import java.util.ArrayList; |
| 79 | import java.util.Arrays; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 80 | import java.util.Locale; |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 81 | import java.util.WeakHashMap; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 82 | import java.util.concurrent.CopyOnWriteArrayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * <p> |
| 86 | * This class represents the basic building block for user interface components. A View |
| 87 | * occupies a rectangular area on the screen and is responsible for drawing and |
| 88 | * 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] | 89 | * 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] | 90 | * {@link android.view.ViewGroup} subclass is the base class for <em>layouts</em>, which |
| 91 | * are invisible containers that hold other Views (or other ViewGroups) and define |
| 92 | * their layout properties. |
| 93 | * </p> |
| 94 | * |
| 95 | * <div class="special"> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 96 | * <p>For an introduction to using this class to develop your |
| 97 | * application's user interface, read the Developer Guide documentation on |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | * <strong><a href="{@docRoot}guide/topics/ui/index.html">User Interface</a></strong>. Special topics |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 99 | * include: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | * <br/><a href="{@docRoot}guide/topics/ui/declaring-layout.html">Declaring Layout</a> |
| 101 | * <br/><a href="{@docRoot}guide/topics/ui/menus.html">Creating Menus</a> |
| 102 | * <br/><a href="{@docRoot}guide/topics/ui/layout-objects.html">Common Layout Objects</a> |
| 103 | * <br/><a href="{@docRoot}guide/topics/ui/binding.html">Binding to Data with AdapterView</a> |
| 104 | * <br/><a href="{@docRoot}guide/topics/ui/ui-events.html">Handling UI Events</a> |
| 105 | * <br/><a href="{@docRoot}guide/topics/ui/themes.html">Applying Styles and Themes</a> |
| 106 | * <br/><a href="{@docRoot}guide/topics/ui/custom-components.html">Building Custom Components</a> |
| 107 | * <br/><a href="{@docRoot}guide/topics/ui/how-android-draws.html">How Android Draws Views</a>. |
| 108 | * </p> |
| 109 | * </div> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 110 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | * <a name="Using"></a> |
| 112 | * <h3>Using Views</h3> |
| 113 | * <p> |
| 114 | * All of the views in a window are arranged in a single tree. You can add views |
| 115 | * either from code or by specifying a tree of views in one or more XML layout |
| 116 | * files. There are many specialized subclasses of views that act as controls or |
| 117 | * are capable of displaying text, images, or other content. |
| 118 | * </p> |
| 119 | * <p> |
| 120 | * Once you have created a tree of views, there are typically a few types of |
| 121 | * common operations you may wish to perform: |
| 122 | * <ul> |
| 123 | * <li><strong>Set properties:</strong> for example setting the text of a |
| 124 | * {@link android.widget.TextView}. The available properties and the methods |
| 125 | * that set them will vary among the different subclasses of views. Note that |
| 126 | * properties that are known at build time can be set in the XML layout |
| 127 | * files.</li> |
| 128 | * <li><strong>Set focus:</strong> The framework will handled moving focus in |
| 129 | * response to user input. To force focus to a specific view, call |
| 130 | * {@link #requestFocus}.</li> |
| 131 | * <li><strong>Set up listeners:</strong> Views allow clients to set listeners |
| 132 | * that will be notified when something interesting happens to the view. For |
| 133 | * example, all views will let you set a listener to be notified when the view |
| 134 | * gains or loses focus. You can register such a listener using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 135 | * {@link #setOnFocusChangeListener(android.view.View.OnFocusChangeListener)}. |
| 136 | * Other view subclasses offer more specialized listeners. For example, a Button |
| 137 | * 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] | 138 | * <li><strong>Set visibility:</strong> You can hide or show views using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 139 | * {@link #setVisibility(int)}.</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | * </ul> |
| 141 | * </p> |
| 142 | * <p><em> |
| 143 | * Note: The Android framework is responsible for measuring, laying out and |
| 144 | * drawing views. You should not call methods that perform these actions on |
| 145 | * views yourself unless you are actually implementing a |
| 146 | * {@link android.view.ViewGroup}. |
| 147 | * </em></p> |
| 148 | * |
| 149 | * <a name="Lifecycle"></a> |
| 150 | * <h3>Implementing a Custom View</h3> |
| 151 | * |
| 152 | * <p> |
| 153 | * To implement a custom view, you will usually begin by providing overrides for |
| 154 | * some of the standard methods that the framework calls on all views. You do |
| 155 | * not need to override all of these methods. In fact, you can start by just |
| 156 | * overriding {@link #onDraw(android.graphics.Canvas)}. |
| 157 | * <table border="2" width="85%" align="center" cellpadding="5"> |
| 158 | * <thead> |
| 159 | * <tr><th>Category</th> <th>Methods</th> <th>Description</th></tr> |
| 160 | * </thead> |
| 161 | * |
| 162 | * <tbody> |
| 163 | * <tr> |
| 164 | * <td rowspan="2">Creation</td> |
| 165 | * <td>Constructors</td> |
| 166 | * <td>There is a form of the constructor that are called when the view |
| 167 | * is created from code and a form that is called when the view is |
| 168 | * inflated from a layout file. The second form should parse and apply |
| 169 | * any attributes defined in the layout file. |
| 170 | * </td> |
| 171 | * </tr> |
| 172 | * <tr> |
| 173 | * <td><code>{@link #onFinishInflate()}</code></td> |
| 174 | * <td>Called after a view and all of its children has been inflated |
| 175 | * from XML.</td> |
| 176 | * </tr> |
| 177 | * |
| 178 | * <tr> |
| 179 | * <td rowspan="3">Layout</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 180 | * <td><code>{@link #onMeasure(int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | * <td>Called to determine the size requirements for this view and all |
| 182 | * of its children. |
| 183 | * </td> |
| 184 | * </tr> |
| 185 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 186 | * <td><code>{@link #onLayout(boolean, int, int, int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | * <td>Called when this view should assign a size and position to all |
| 188 | * of its children. |
| 189 | * </td> |
| 190 | * </tr> |
| 191 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 192 | * <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] | 193 | * <td>Called when the size of this view has changed. |
| 194 | * </td> |
| 195 | * </tr> |
| 196 | * |
| 197 | * <tr> |
| 198 | * <td>Drawing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 199 | * <td><code>{@link #onDraw(android.graphics.Canvas)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | * <td>Called when the view should render its content. |
| 201 | * </td> |
| 202 | * </tr> |
| 203 | * |
| 204 | * <tr> |
| 205 | * <td rowspan="4">Event processing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 206 | * <td><code>{@link #onKeyDown(int, KeyEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | * <td>Called when a new key event occurs. |
| 208 | * </td> |
| 209 | * </tr> |
| 210 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 211 | * <td><code>{@link #onKeyUp(int, KeyEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | * <td>Called when a key up event occurs. |
| 213 | * </td> |
| 214 | * </tr> |
| 215 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 216 | * <td><code>{@link #onTrackballEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | * <td>Called when a trackball motion event occurs. |
| 218 | * </td> |
| 219 | * </tr> |
| 220 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 221 | * <td><code>{@link #onTouchEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | * <td>Called when a touch screen motion event occurs. |
| 223 | * </td> |
| 224 | * </tr> |
| 225 | * |
| 226 | * <tr> |
| 227 | * <td rowspan="2">Focus</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 228 | * <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] | 229 | * <td>Called when the view gains or loses focus. |
| 230 | * </td> |
| 231 | * </tr> |
| 232 | * |
| 233 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 234 | * <td><code>{@link #onWindowFocusChanged(boolean)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | * <td>Called when the window containing the view gains or loses focus. |
| 236 | * </td> |
| 237 | * </tr> |
| 238 | * |
| 239 | * <tr> |
| 240 | * <td rowspan="3">Attaching</td> |
| 241 | * <td><code>{@link #onAttachedToWindow()}</code></td> |
| 242 | * <td>Called when the view is attached to a window. |
| 243 | * </td> |
| 244 | * </tr> |
| 245 | * |
| 246 | * <tr> |
| 247 | * <td><code>{@link #onDetachedFromWindow}</code></td> |
| 248 | * <td>Called when the view is detached from its window. |
| 249 | * </td> |
| 250 | * </tr> |
| 251 | * |
| 252 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 253 | * <td><code>{@link #onWindowVisibilityChanged(int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | * <td>Called when the visibility of the window containing the view |
| 255 | * has changed. |
| 256 | * </td> |
| 257 | * </tr> |
| 258 | * </tbody> |
| 259 | * |
| 260 | * </table> |
| 261 | * </p> |
| 262 | * |
| 263 | * <a name="IDs"></a> |
| 264 | * <h3>IDs</h3> |
| 265 | * Views may have an integer id associated with them. These ids are typically |
| 266 | * assigned in the layout XML files, and are used to find specific views within |
| 267 | * the view tree. A common pattern is to: |
| 268 | * <ul> |
| 269 | * <li>Define a Button in the layout file and assign it a unique ID. |
| 270 | * <pre> |
Gilles Debunne | 0243caf | 2010-08-24 23:06:35 -0700 | [diff] [blame] | 271 | * <Button |
| 272 | * android:id="@+id/my_button" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | * android:layout_width="wrap_content" |
| 274 | * android:layout_height="wrap_content" |
| 275 | * android:text="@string/my_button_text"/> |
| 276 | * </pre></li> |
| 277 | * <li>From the onCreate method of an Activity, find the Button |
| 278 | * <pre class="prettyprint"> |
| 279 | * Button myButton = (Button) findViewById(R.id.my_button); |
| 280 | * </pre></li> |
| 281 | * </ul> |
| 282 | * <p> |
| 283 | * View IDs need not be unique throughout the tree, but it is good practice to |
| 284 | * ensure that they are at least unique within the part of the tree you are |
| 285 | * searching. |
| 286 | * </p> |
| 287 | * |
| 288 | * <a name="Position"></a> |
| 289 | * <h3>Position</h3> |
| 290 | * <p> |
| 291 | * The geometry of a view is that of a rectangle. A view has a location, |
| 292 | * expressed as a pair of <em>left</em> and <em>top</em> coordinates, and |
| 293 | * two dimensions, expressed as a width and a height. The unit for location |
| 294 | * and dimensions is the pixel. |
| 295 | * </p> |
| 296 | * |
| 297 | * <p> |
| 298 | * It is possible to retrieve the location of a view by invoking the methods |
| 299 | * {@link #getLeft()} and {@link #getTop()}. The former returns the left, or X, |
| 300 | * coordinate of the rectangle representing the view. The latter returns the |
| 301 | * top, or Y, coordinate of the rectangle representing the view. These methods |
| 302 | * both return the location of the view relative to its parent. For instance, |
| 303 | * when getLeft() returns 20, that means the view is located 20 pixels to the |
| 304 | * right of the left edge of its direct parent. |
| 305 | * </p> |
| 306 | * |
| 307 | * <p> |
| 308 | * In addition, several convenience methods are offered to avoid unnecessary |
| 309 | * computations, namely {@link #getRight()} and {@link #getBottom()}. |
| 310 | * These methods return the coordinates of the right and bottom edges of the |
| 311 | * rectangle representing the view. For instance, calling {@link #getRight()} |
| 312 | * is similar to the following computation: <code>getLeft() + getWidth()</code> |
| 313 | * (see <a href="#SizePaddingMargins">Size</a> for more information about the width.) |
| 314 | * </p> |
| 315 | * |
| 316 | * <a name="SizePaddingMargins"></a> |
| 317 | * <h3>Size, padding and margins</h3> |
| 318 | * <p> |
| 319 | * The size of a view is expressed with a width and a height. A view actually |
| 320 | * possess two pairs of width and height values. |
| 321 | * </p> |
| 322 | * |
| 323 | * <p> |
| 324 | * The first pair is known as <em>measured width</em> and |
| 325 | * <em>measured height</em>. These dimensions define how big a view wants to be |
| 326 | * within its parent (see <a href="#Layout">Layout</a> for more details.) The |
| 327 | * measured dimensions can be obtained by calling {@link #getMeasuredWidth()} |
| 328 | * and {@link #getMeasuredHeight()}. |
| 329 | * </p> |
| 330 | * |
| 331 | * <p> |
| 332 | * The second pair is simply known as <em>width</em> and <em>height</em>, or |
| 333 | * sometimes <em>drawing width</em> and <em>drawing height</em>. These |
| 334 | * dimensions define the actual size of the view on screen, at drawing time and |
| 335 | * after layout. These values may, but do not have to, be different from the |
| 336 | * measured width and height. The width and height can be obtained by calling |
| 337 | * {@link #getWidth()} and {@link #getHeight()}. |
| 338 | * </p> |
| 339 | * |
| 340 | * <p> |
| 341 | * To measure its dimensions, a view takes into account its padding. The padding |
| 342 | * is expressed in pixels for the left, top, right and bottom parts of the view. |
| 343 | * Padding can be used to offset the content of the view by a specific amount of |
| 344 | * pixels. For instance, a left padding of 2 will push the view's content by |
| 345 | * 2 pixels to the right of the left edge. Padding can be set using the |
| 346 | * {@link #setPadding(int, int, int, int)} method and queried by calling |
| 347 | * {@link #getPaddingLeft()}, {@link #getPaddingTop()}, |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 348 | * {@link #getPaddingRight()}, {@link #getPaddingBottom()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | * </p> |
| 350 | * |
| 351 | * <p> |
| 352 | * Even though a view can define a padding, it does not provide any support for |
| 353 | * margins. However, view groups provide such a support. Refer to |
| 354 | * {@link android.view.ViewGroup} and |
| 355 | * {@link android.view.ViewGroup.MarginLayoutParams} for further information. |
| 356 | * </p> |
| 357 | * |
| 358 | * <a name="Layout"></a> |
| 359 | * <h3>Layout</h3> |
| 360 | * <p> |
| 361 | * Layout is a two pass process: a measure pass and a layout pass. The measuring |
| 362 | * pass is implemented in {@link #measure(int, int)} and is a top-down traversal |
| 363 | * of the view tree. Each view pushes dimension specifications down the tree |
| 364 | * during the recursion. At the end of the measure pass, every view has stored |
| 365 | * its measurements. The second pass happens in |
| 366 | * {@link #layout(int,int,int,int)} and is also top-down. During |
| 367 | * this pass each parent is responsible for positioning all of its children |
| 368 | * using the sizes computed in the measure pass. |
| 369 | * </p> |
| 370 | * |
| 371 | * <p> |
| 372 | * When a view's measure() method returns, its {@link #getMeasuredWidth()} and |
| 373 | * {@link #getMeasuredHeight()} values must be set, along with those for all of |
| 374 | * that view's descendants. A view's measured width and measured height values |
| 375 | * must respect the constraints imposed by the view's parents. This guarantees |
| 376 | * that at the end of the measure pass, all parents accept all of their |
| 377 | * children's measurements. A parent view may call measure() more than once on |
| 378 | * its children. For example, the parent may measure each child once with |
| 379 | * unspecified dimensions to find out how big they want to be, then call |
| 380 | * measure() on them again with actual numbers if the sum of all the children's |
| 381 | * unconstrained sizes is too big or too small. |
| 382 | * </p> |
| 383 | * |
| 384 | * <p> |
| 385 | * The measure pass uses two classes to communicate dimensions. The |
| 386 | * {@link MeasureSpec} class is used by views to tell their parents how they |
| 387 | * want to be measured and positioned. The base LayoutParams class just |
| 388 | * describes how big the view wants to be for both width and height. For each |
| 389 | * dimension, it can specify one of: |
| 390 | * <ul> |
| 391 | * <li> an exact number |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 392 | * <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] | 393 | * (minus padding) |
| 394 | * <li> WRAP_CONTENT, which means that the view wants to be just big enough to |
| 395 | * enclose its content (plus padding). |
| 396 | * </ul> |
| 397 | * There are subclasses of LayoutParams for different subclasses of ViewGroup. |
| 398 | * For example, AbsoluteLayout has its own subclass of LayoutParams which adds |
| 399 | * an X and Y value. |
| 400 | * </p> |
| 401 | * |
| 402 | * <p> |
| 403 | * MeasureSpecs are used to push requirements down the tree from parent to |
| 404 | * child. A MeasureSpec can be in one of three modes: |
| 405 | * <ul> |
| 406 | * <li>UNSPECIFIED: This is used by a parent to determine the desired dimension |
| 407 | * of a child view. For example, a LinearLayout may call measure() on its child |
| 408 | * with the height set to UNSPECIFIED and a width of EXACTLY 240 to find out how |
| 409 | * tall the child view wants to be given a width of 240 pixels. |
| 410 | * <li>EXACTLY: This is used by the parent to impose an exact size on the |
| 411 | * child. The child must use this size, and guarantee that all of its |
| 412 | * descendants will fit within this size. |
| 413 | * <li>AT_MOST: This is used by the parent to impose a maximum size on the |
| 414 | * child. The child must gurantee that it and all of its descendants will fit |
| 415 | * within this size. |
| 416 | * </ul> |
| 417 | * </p> |
| 418 | * |
| 419 | * <p> |
| 420 | * To intiate a layout, call {@link #requestLayout}. This method is typically |
| 421 | * called by a view on itself when it believes that is can no longer fit within |
| 422 | * its current bounds. |
| 423 | * </p> |
| 424 | * |
| 425 | * <a name="Drawing"></a> |
| 426 | * <h3>Drawing</h3> |
| 427 | * <p> |
| 428 | * Drawing is handled by walking the tree and rendering each view that |
| 429 | * intersects the the invalid region. Because the tree is traversed in-order, |
| 430 | * this means that parents will draw before (i.e., behind) their children, with |
| 431 | * siblings drawn in the order they appear in the tree. |
| 432 | * If you set a background drawable for a View, then the View will draw it for you |
| 433 | * before calling back to its <code>onDraw()</code> method. |
| 434 | * </p> |
| 435 | * |
| 436 | * <p> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 437 | * 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] | 438 | * </p> |
| 439 | * |
| 440 | * <p> |
| 441 | * To force a view to draw, call {@link #invalidate()}. |
| 442 | * </p> |
| 443 | * |
| 444 | * <a name="EventHandlingThreading"></a> |
| 445 | * <h3>Event Handling and Threading</h3> |
| 446 | * <p> |
| 447 | * The basic cycle of a view is as follows: |
| 448 | * <ol> |
| 449 | * <li>An event comes in and is dispatched to the appropriate view. The view |
| 450 | * handles the event and notifies any listeners.</li> |
| 451 | * <li>If in the course of processing the event, the view's bounds may need |
| 452 | * to be changed, the view will call {@link #requestLayout()}.</li> |
| 453 | * <li>Similarly, if in the course of processing the event the view's appearance |
| 454 | * may need to be changed, the view will call {@link #invalidate()}.</li> |
| 455 | * <li>If either {@link #requestLayout()} or {@link #invalidate()} were called, |
| 456 | * the framework will take care of measuring, laying out, and drawing the tree |
| 457 | * as appropriate.</li> |
| 458 | * </ol> |
| 459 | * </p> |
| 460 | * |
| 461 | * <p><em>Note: The entire view tree is single threaded. You must always be on |
| 462 | * the UI thread when calling any method on any view.</em> |
| 463 | * If you are doing work on other threads and want to update the state of a view |
| 464 | * from that thread, you should use a {@link Handler}. |
| 465 | * </p> |
| 466 | * |
| 467 | * <a name="FocusHandling"></a> |
| 468 | * <h3>Focus Handling</h3> |
| 469 | * <p> |
| 470 | * The framework will handle routine focus movement in response to user input. |
| 471 | * This includes changing the focus as views are removed or hidden, or as new |
| 472 | * views become available. Views indicate their willingness to take focus |
| 473 | * through the {@link #isFocusable} method. To change whether a view can take |
| 474 | * focus, call {@link #setFocusable(boolean)}. When in touch mode (see notes below) |
| 475 | * views indicate whether they still would like focus via {@link #isFocusableInTouchMode} |
| 476 | * and can change this via {@link #setFocusableInTouchMode(boolean)}. |
| 477 | * </p> |
| 478 | * <p> |
| 479 | * Focus movement is based on an algorithm which finds the nearest neighbor in a |
| 480 | * given direction. In rare cases, the default algorithm may not match the |
| 481 | * intended behavior of the developer. In these situations, you can provide |
| 482 | * explicit overrides by using these XML attributes in the layout file: |
| 483 | * <pre> |
| 484 | * nextFocusDown |
| 485 | * nextFocusLeft |
| 486 | * nextFocusRight |
| 487 | * nextFocusUp |
| 488 | * </pre> |
| 489 | * </p> |
| 490 | * |
| 491 | * |
| 492 | * <p> |
| 493 | * To get a particular view to take focus, call {@link #requestFocus()}. |
| 494 | * </p> |
| 495 | * |
| 496 | * <a name="TouchMode"></a> |
| 497 | * <h3>Touch Mode</h3> |
| 498 | * <p> |
| 499 | * When a user is navigating a user interface via directional keys such as a D-pad, it is |
| 500 | * necessary to give focus to actionable items such as buttons so the user can see |
| 501 | * what will take input. If the device has touch capabilities, however, and the user |
| 502 | * begins interacting with the interface by touching it, it is no longer necessary to |
| 503 | * always highlight, or give focus to, a particular view. This motivates a mode |
| 504 | * for interaction named 'touch mode'. |
| 505 | * </p> |
| 506 | * <p> |
| 507 | * For a touch capable device, once the user touches the screen, the device |
| 508 | * will enter touch mode. From this point onward, only views for which |
| 509 | * {@link #isFocusableInTouchMode} is true will be focusable, such as text editing widgets. |
| 510 | * Other views that are touchable, like buttons, will not take focus when touched; they will |
| 511 | * only fire the on click listeners. |
| 512 | * </p> |
| 513 | * <p> |
| 514 | * Any time a user hits a directional key, such as a D-pad direction, the view device will |
| 515 | * exit touch mode, and find a view to take focus, so that the user may resume interacting |
| 516 | * with the user interface without touching the screen again. |
| 517 | * </p> |
| 518 | * <p> |
| 519 | * The touch mode state is maintained across {@link android.app.Activity}s. Call |
| 520 | * {@link #isInTouchMode} to see whether the device is currently in touch mode. |
| 521 | * </p> |
| 522 | * |
| 523 | * <a name="Scrolling"></a> |
| 524 | * <h3>Scrolling</h3> |
| 525 | * <p> |
| 526 | * The framework provides basic support for views that wish to internally |
| 527 | * scroll their content. This includes keeping track of the X and Y scroll |
| 528 | * offset as well as mechanisms for drawing scrollbars. See |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 529 | * {@link #scrollBy(int, int)}, {@link #scrollTo(int, int)}, and |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 530 | * {@link #awakenScrollBars()} for more details. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | * </p> |
| 532 | * |
| 533 | * <a name="Tags"></a> |
| 534 | * <h3>Tags</h3> |
| 535 | * <p> |
| 536 | * Unlike IDs, tags are not used to identify views. Tags are essentially an |
| 537 | * extra piece of information that can be associated with a view. They are most |
| 538 | * often used as a convenience to store data related to views in the views |
| 539 | * themselves rather than by putting them in a separate structure. |
| 540 | * </p> |
| 541 | * |
| 542 | * <a name="Animation"></a> |
| 543 | * <h3>Animation</h3> |
| 544 | * <p> |
| 545 | * You can attach an {@link Animation} object to a view using |
| 546 | * {@link #setAnimation(Animation)} or |
| 547 | * {@link #startAnimation(Animation)}. The animation can alter the scale, |
| 548 | * rotation, translation and alpha of a view over time. If the animation is |
| 549 | * attached to a view that has children, the animation will affect the entire |
| 550 | * subtree rooted by that node. When an animation is started, the framework will |
| 551 | * take care of redrawing the appropriate views until the animation completes. |
| 552 | * </p> |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 553 | * <p> |
| 554 | * Starting with Android 3.0, the preferred way of animating views is to use the |
| 555 | * {@link android.animation} package APIs. |
| 556 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 557 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 558 | * <a name="Security"></a> |
| 559 | * <h3>Security</h3> |
| 560 | * <p> |
| 561 | * Sometimes it is essential that an application be able to verify that an action |
| 562 | * is being performed with the full knowledge and consent of the user, such as |
| 563 | * granting a permission request, making a purchase or clicking on an advertisement. |
| 564 | * Unfortunately, a malicious application could try to spoof the user into |
| 565 | * performing these actions, unaware, by concealing the intended purpose of the view. |
| 566 | * As a remedy, the framework offers a touch filtering mechanism that can be used to |
| 567 | * improve the security of views that provide access to sensitive functionality. |
| 568 | * </p><p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 569 | * To enable touch filtering, call {@link #setFilterTouchesWhenObscured(boolean)} or set the |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 570 | * android:filterTouchesWhenObscured layout attribute to true. When enabled, the framework |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 571 | * will discard touches that are received whenever the view's window is obscured by |
| 572 | * another visible window. As a result, the view will not receive touches whenever a |
| 573 | * toast, dialog or other window appears above the view's window. |
| 574 | * </p><p> |
| 575 | * For more fine-grained control over security, consider overriding the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 576 | * {@link #onFilterTouchEventForSecurity(MotionEvent)} method to implement your own |
| 577 | * security policy. See also {@link MotionEvent#FLAG_WINDOW_IS_OBSCURED}. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 578 | * </p> |
| 579 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 580 | * @attr ref android.R.styleable#View_alpha |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 581 | * @attr ref android.R.styleable#View_background |
| 582 | * @attr ref android.R.styleable#View_clickable |
| 583 | * @attr ref android.R.styleable#View_contentDescription |
| 584 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 585 | * @attr ref android.R.styleable#View_duplicateParentState |
| 586 | * @attr ref android.R.styleable#View_id |
| 587 | * @attr ref android.R.styleable#View_fadingEdge |
| 588 | * @attr ref android.R.styleable#View_fadingEdgeLength |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 589 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 591 | * @attr ref android.R.styleable#View_isScrollContainer |
| 592 | * @attr ref android.R.styleable#View_focusable |
| 593 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 594 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 595 | * @attr ref android.R.styleable#View_keepScreenOn |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 596 | * @attr ref android.R.styleable#View_layerType |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 597 | * @attr ref android.R.styleable#View_longClickable |
| 598 | * @attr ref android.R.styleable#View_minHeight |
| 599 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 600 | * @attr ref android.R.styleable#View_nextFocusDown |
| 601 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 602 | * @attr ref android.R.styleable#View_nextFocusRight |
| 603 | * @attr ref android.R.styleable#View_nextFocusUp |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 604 | * @attr ref android.R.styleable#View_onClick |
| 605 | * @attr ref android.R.styleable#View_padding |
| 606 | * @attr ref android.R.styleable#View_paddingBottom |
| 607 | * @attr ref android.R.styleable#View_paddingLeft |
| 608 | * @attr ref android.R.styleable#View_paddingRight |
| 609 | * @attr ref android.R.styleable#View_paddingTop |
| 610 | * @attr ref android.R.styleable#View_saveEnabled |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 611 | * @attr ref android.R.styleable#View_rotation |
| 612 | * @attr ref android.R.styleable#View_rotationX |
| 613 | * @attr ref android.R.styleable#View_rotationY |
| 614 | * @attr ref android.R.styleable#View_scaleX |
| 615 | * @attr ref android.R.styleable#View_scaleY |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | * @attr ref android.R.styleable#View_scrollX |
| 617 | * @attr ref android.R.styleable#View_scrollY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 618 | * @attr ref android.R.styleable#View_scrollbarSize |
| 619 | * @attr ref android.R.styleable#View_scrollbarStyle |
| 620 | * @attr ref android.R.styleable#View_scrollbars |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 621 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 622 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 623 | * @attr ref android.R.styleable#View_scrollbarTrackHorizontal |
| 624 | * @attr ref android.R.styleable#View_scrollbarThumbHorizontal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | * @attr ref android.R.styleable#View_scrollbarThumbVertical |
| 626 | * @attr ref android.R.styleable#View_scrollbarTrackVertical |
| 627 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawHorizontalTrack |
| 628 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawVerticalTrack |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 629 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 630 | * @attr ref android.R.styleable#View_tag |
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 | */ |
Fabrice Di Meglio | 6a03640 | 2011-05-23 14:43:23 -0700 | [diff] [blame] | 639 | public class View implements Drawable.Callback2, KeyEvent.Callback, AccessibilityEventSource { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | private static final boolean DBG = false; |
| 641 | |
| 642 | /** |
| 643 | * The logging tag used by this class with android.util.Log. |
| 644 | */ |
| 645 | protected static final String VIEW_LOG_TAG = "View"; |
| 646 | |
| 647 | /** |
| 648 | * Used to mark a View that has no ID. |
| 649 | */ |
| 650 | public static final int NO_ID = -1; |
| 651 | |
| 652 | /** |
| 653 | * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when |
| 654 | * calling setFlags. |
| 655 | */ |
| 656 | private static final int NOT_FOCUSABLE = 0x00000000; |
| 657 | |
| 658 | /** |
| 659 | * This view wants keystrokes. Use with TAKES_FOCUS_MASK when calling |
| 660 | * setFlags. |
| 661 | */ |
| 662 | private static final int FOCUSABLE = 0x00000001; |
| 663 | |
| 664 | /** |
| 665 | * Mask for use with setFlags indicating bits used for focus. |
| 666 | */ |
| 667 | private static final int FOCUSABLE_MASK = 0x00000001; |
| 668 | |
| 669 | /** |
| 670 | * This view will adjust its padding to fit sytem windows (e.g. status bar) |
| 671 | */ |
| 672 | private static final int FITS_SYSTEM_WINDOWS = 0x00000002; |
| 673 | |
| 674 | /** |
Scott Main | 812634c2 | 2011-07-27 13:22:35 -0700 | [diff] [blame] | 675 | * This view is visible. |
| 676 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 677 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 678 | */ |
| 679 | public static final int VISIBLE = 0x00000000; |
| 680 | |
| 681 | /** |
| 682 | * This view is invisible, but it still takes up space for layout purposes. |
Scott Main | 812634c2 | 2011-07-27 13:22:35 -0700 | [diff] [blame] | 683 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 684 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | */ |
| 686 | public static final int INVISIBLE = 0x00000004; |
| 687 | |
| 688 | /** |
| 689 | * This view is invisible, and it doesn't take any space for layout |
Scott Main | 812634c2 | 2011-07-27 13:22:35 -0700 | [diff] [blame] | 690 | * purposes. Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 691 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 692 | */ |
| 693 | public static final int GONE = 0x00000008; |
| 694 | |
| 695 | /** |
| 696 | * Mask for use with setFlags indicating bits used for visibility. |
| 697 | * {@hide} |
| 698 | */ |
| 699 | static final int VISIBILITY_MASK = 0x0000000C; |
| 700 | |
| 701 | private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE}; |
| 702 | |
| 703 | /** |
| 704 | * This view is enabled. Intrepretation varies by subclass. |
| 705 | * Use with ENABLED_MASK when calling setFlags. |
| 706 | * {@hide} |
| 707 | */ |
| 708 | static final int ENABLED = 0x00000000; |
| 709 | |
| 710 | /** |
| 711 | * This view is disabled. Intrepretation varies by subclass. |
| 712 | * Use with ENABLED_MASK when calling setFlags. |
| 713 | * {@hide} |
| 714 | */ |
| 715 | static final int DISABLED = 0x00000020; |
| 716 | |
| 717 | /** |
| 718 | * Mask for use with setFlags indicating bits used for indicating whether |
| 719 | * this view is enabled |
| 720 | * {@hide} |
| 721 | */ |
| 722 | static final int ENABLED_MASK = 0x00000020; |
| 723 | |
| 724 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 725 | * This view won't draw. {@link #onDraw(android.graphics.Canvas)} won't be |
| 726 | * called and further optimizations will be performed. It is okay to have |
| 727 | * this flag set and a background. Use with DRAW_MASK when calling setFlags. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | * {@hide} |
| 729 | */ |
| 730 | static final int WILL_NOT_DRAW = 0x00000080; |
| 731 | |
| 732 | /** |
| 733 | * Mask for use with setFlags indicating bits used for indicating whether |
| 734 | * this view is will draw |
| 735 | * {@hide} |
| 736 | */ |
| 737 | static final int DRAW_MASK = 0x00000080; |
| 738 | |
| 739 | /** |
| 740 | * <p>This view doesn't show scrollbars.</p> |
| 741 | * {@hide} |
| 742 | */ |
| 743 | static final int SCROLLBARS_NONE = 0x00000000; |
| 744 | |
| 745 | /** |
| 746 | * <p>This view shows horizontal scrollbars.</p> |
| 747 | * {@hide} |
| 748 | */ |
| 749 | static final int SCROLLBARS_HORIZONTAL = 0x00000100; |
| 750 | |
| 751 | /** |
| 752 | * <p>This view shows vertical scrollbars.</p> |
| 753 | * {@hide} |
| 754 | */ |
| 755 | static final int SCROLLBARS_VERTICAL = 0x00000200; |
| 756 | |
| 757 | /** |
| 758 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 759 | * scrollbars are enabled.</p> |
| 760 | * {@hide} |
| 761 | */ |
| 762 | static final int SCROLLBARS_MASK = 0x00000300; |
| 763 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 764 | /** |
| 765 | * Indicates that the view should filter touches when its window is obscured. |
| 766 | * Refer to the class comments for more information about this security feature. |
| 767 | * {@hide} |
| 768 | */ |
| 769 | static final int FILTER_TOUCHES_WHEN_OBSCURED = 0x00000400; |
| 770 | |
| 771 | // note flag value 0x00000800 is now available for next flags... |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | |
| 773 | /** |
| 774 | * <p>This view doesn't show fading edges.</p> |
| 775 | * {@hide} |
| 776 | */ |
| 777 | static final int FADING_EDGE_NONE = 0x00000000; |
| 778 | |
| 779 | /** |
| 780 | * <p>This view shows horizontal fading edges.</p> |
| 781 | * {@hide} |
| 782 | */ |
| 783 | static final int FADING_EDGE_HORIZONTAL = 0x00001000; |
| 784 | |
| 785 | /** |
| 786 | * <p>This view shows vertical fading edges.</p> |
| 787 | * {@hide} |
| 788 | */ |
| 789 | static final int FADING_EDGE_VERTICAL = 0x00002000; |
| 790 | |
| 791 | /** |
| 792 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 793 | * fading edges are enabled.</p> |
| 794 | * {@hide} |
| 795 | */ |
| 796 | static final int FADING_EDGE_MASK = 0x00003000; |
| 797 | |
| 798 | /** |
| 799 | * <p>Indicates this view can be clicked. When clickable, a View reacts |
| 800 | * to clicks by notifying the OnClickListener.<p> |
| 801 | * {@hide} |
| 802 | */ |
| 803 | static final int CLICKABLE = 0x00004000; |
| 804 | |
| 805 | /** |
| 806 | * <p>Indicates this view is caching its drawing into a bitmap.</p> |
| 807 | * {@hide} |
| 808 | */ |
| 809 | static final int DRAWING_CACHE_ENABLED = 0x00008000; |
| 810 | |
| 811 | /** |
| 812 | * <p>Indicates that no icicle should be saved for this view.<p> |
| 813 | * {@hide} |
| 814 | */ |
| 815 | static final int SAVE_DISABLED = 0x000010000; |
| 816 | |
| 817 | /** |
| 818 | * <p>Mask for use with setFlags indicating bits used for the saveEnabled |
| 819 | * property.</p> |
| 820 | * {@hide} |
| 821 | */ |
| 822 | static final int SAVE_DISABLED_MASK = 0x000010000; |
| 823 | |
| 824 | /** |
| 825 | * <p>Indicates that no drawing cache should ever be created for this view.<p> |
| 826 | * {@hide} |
| 827 | */ |
| 828 | static final int WILL_NOT_CACHE_DRAWING = 0x000020000; |
| 829 | |
| 830 | /** |
| 831 | * <p>Indicates this view can take / keep focus when int touch mode.</p> |
| 832 | * {@hide} |
| 833 | */ |
| 834 | static final int FOCUSABLE_IN_TOUCH_MODE = 0x00040000; |
| 835 | |
| 836 | /** |
| 837 | * <p>Enables low quality mode for the drawing cache.</p> |
| 838 | */ |
| 839 | public static final int DRAWING_CACHE_QUALITY_LOW = 0x00080000; |
| 840 | |
| 841 | /** |
| 842 | * <p>Enables high quality mode for the drawing cache.</p> |
| 843 | */ |
| 844 | public static final int DRAWING_CACHE_QUALITY_HIGH = 0x00100000; |
| 845 | |
| 846 | /** |
| 847 | * <p>Enables automatic quality mode for the drawing cache.</p> |
| 848 | */ |
| 849 | public static final int DRAWING_CACHE_QUALITY_AUTO = 0x00000000; |
| 850 | |
| 851 | private static final int[] DRAWING_CACHE_QUALITY_FLAGS = { |
| 852 | DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_LOW, DRAWING_CACHE_QUALITY_HIGH |
| 853 | }; |
| 854 | |
| 855 | /** |
| 856 | * <p>Mask for use with setFlags indicating bits used for the cache |
| 857 | * quality property.</p> |
| 858 | * {@hide} |
| 859 | */ |
| 860 | static final int DRAWING_CACHE_QUALITY_MASK = 0x00180000; |
| 861 | |
| 862 | /** |
| 863 | * <p> |
| 864 | * Indicates this view can be long clicked. When long clickable, a View |
| 865 | * reacts to long clicks by notifying the OnLongClickListener or showing a |
| 866 | * context menu. |
| 867 | * </p> |
| 868 | * {@hide} |
| 869 | */ |
| 870 | static final int LONG_CLICKABLE = 0x00200000; |
| 871 | |
| 872 | /** |
| 873 | * <p>Indicates that this view gets its drawable states from its direct parent |
| 874 | * and ignores its original internal states.</p> |
| 875 | * |
| 876 | * @hide |
| 877 | */ |
| 878 | static final int DUPLICATE_PARENT_STATE = 0x00400000; |
| 879 | |
| 880 | /** |
| 881 | * The scrollbar style to display the scrollbars inside the content area, |
| 882 | * without increasing the padding. The scrollbars will be overlaid with |
| 883 | * translucency on the view's content. |
| 884 | */ |
| 885 | public static final int SCROLLBARS_INSIDE_OVERLAY = 0; |
| 886 | |
| 887 | /** |
| 888 | * The scrollbar style to display the scrollbars inside the padded area, |
| 889 | * increasing the padding of the view. The scrollbars will not overlap the |
| 890 | * content area of the view. |
| 891 | */ |
| 892 | public static final int SCROLLBARS_INSIDE_INSET = 0x01000000; |
| 893 | |
| 894 | /** |
| 895 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 896 | * without increasing the padding. The scrollbars will be overlaid with |
| 897 | * translucency. |
| 898 | */ |
| 899 | public static final int SCROLLBARS_OUTSIDE_OVERLAY = 0x02000000; |
| 900 | |
| 901 | /** |
| 902 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 903 | * increasing the padding of the view. The scrollbars will only overlap the |
| 904 | * background, if any. |
| 905 | */ |
| 906 | public static final int SCROLLBARS_OUTSIDE_INSET = 0x03000000; |
| 907 | |
| 908 | /** |
| 909 | * Mask to check if the scrollbar style is overlay or inset. |
| 910 | * {@hide} |
| 911 | */ |
| 912 | static final int SCROLLBARS_INSET_MASK = 0x01000000; |
| 913 | |
| 914 | /** |
| 915 | * Mask to check if the scrollbar style is inside or outside. |
| 916 | * {@hide} |
| 917 | */ |
| 918 | static final int SCROLLBARS_OUTSIDE_MASK = 0x02000000; |
| 919 | |
| 920 | /** |
| 921 | * Mask for scrollbar style. |
| 922 | * {@hide} |
| 923 | */ |
| 924 | static final int SCROLLBARS_STYLE_MASK = 0x03000000; |
| 925 | |
| 926 | /** |
| 927 | * View flag indicating that the screen should remain on while the |
| 928 | * window containing this view is visible to the user. This effectively |
| 929 | * takes care of automatically setting the WindowManager's |
| 930 | * {@link WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON}. |
| 931 | */ |
| 932 | public static final int KEEP_SCREEN_ON = 0x04000000; |
| 933 | |
| 934 | /** |
| 935 | * View flag indicating whether this view should have sound effects enabled |
| 936 | * for events such as clicking and touching. |
| 937 | */ |
| 938 | public static final int SOUND_EFFECTS_ENABLED = 0x08000000; |
| 939 | |
| 940 | /** |
| 941 | * View flag indicating whether this view should have haptic feedback |
| 942 | * enabled for events such as long presses. |
| 943 | */ |
| 944 | public static final int HAPTIC_FEEDBACK_ENABLED = 0x10000000; |
| 945 | |
| 946 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 947 | * <p>Indicates that the view hierarchy should stop saving state when |
| 948 | * it reaches this view. If state saving is initiated immediately at |
| 949 | * the view, it will be allowed. |
| 950 | * {@hide} |
| 951 | */ |
| 952 | static final int PARENT_SAVE_DISABLED = 0x20000000; |
| 953 | |
| 954 | /** |
| 955 | * <p>Mask for use with setFlags indicating bits used for PARENT_SAVE_DISABLED.</p> |
| 956 | * {@hide} |
| 957 | */ |
| 958 | static final int PARENT_SAVE_DISABLED_MASK = 0x20000000; |
| 959 | |
| 960 | /** |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 961 | * Horizontal direction of this view is from Left to Right. |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 962 | * Use with {@link #setLayoutDirection}. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 963 | * {@hide} |
| 964 | */ |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 965 | public static final int LAYOUT_DIRECTION_LTR = 0x00000000; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 966 | |
| 967 | /** |
| 968 | * Horizontal direction of this view is from Right to Left. |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 969 | * Use with {@link #setLayoutDirection}. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 970 | * {@hide} |
| 971 | */ |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 972 | public static final int LAYOUT_DIRECTION_RTL = 0x40000000; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 973 | |
| 974 | /** |
| 975 | * Horizontal direction of this view is inherited from its parent. |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 976 | * Use with {@link #setLayoutDirection}. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 977 | * {@hide} |
| 978 | */ |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 979 | public static final int LAYOUT_DIRECTION_INHERIT = 0x80000000; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 980 | |
| 981 | /** |
| 982 | * Horizontal direction of this view is from deduced from the default language |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 983 | * script for the locale. Use with {@link #setLayoutDirection}. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 984 | * {@hide} |
| 985 | */ |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 986 | public static final int LAYOUT_DIRECTION_LOCALE = 0xC0000000; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 987 | |
| 988 | /** |
| 989 | * Mask for use with setFlags indicating bits used for horizontalDirection. |
| 990 | * {@hide} |
| 991 | */ |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 992 | static final int LAYOUT_DIRECTION_MASK = 0xC0000000; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 993 | |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 994 | /* |
| 995 | * Array of horizontal direction flags for mapping attribute "horizontalDirection" to correct |
| 996 | * flag value. |
| 997 | * {@hide} |
| 998 | */ |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 999 | private static final int[] LAYOUT_DIRECTION_FLAGS = {LAYOUT_DIRECTION_LTR, |
| 1000 | LAYOUT_DIRECTION_RTL, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE}; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1001 | |
| 1002 | /** |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 1003 | * Default horizontalDirection. |
| 1004 | * {@hide} |
| 1005 | */ |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 1006 | private static final int LAYOUT_DIRECTION_DEFAULT = LAYOUT_DIRECTION_INHERIT; |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 1007 | |
| 1008 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1009 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 1010 | * should add all focusable Views regardless if they are focusable in touch mode. |
| 1011 | */ |
| 1012 | public static final int FOCUSABLES_ALL = 0x00000000; |
| 1013 | |
| 1014 | /** |
| 1015 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 1016 | * should add only Views focusable in touch mode. |
| 1017 | */ |
| 1018 | public static final int FOCUSABLES_TOUCH_MODE = 0x00000001; |
| 1019 | |
| 1020 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1021 | * 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] | 1022 | * item. |
| 1023 | */ |
| 1024 | public static final int FOCUS_BACKWARD = 0x00000001; |
| 1025 | |
| 1026 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1027 | * 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] | 1028 | * item. |
| 1029 | */ |
| 1030 | public static final int FOCUS_FORWARD = 0x00000002; |
| 1031 | |
| 1032 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1033 | * 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] | 1034 | */ |
| 1035 | public static final int FOCUS_LEFT = 0x00000011; |
| 1036 | |
| 1037 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1038 | * Use with {@link #focusSearch(int)}. Move focus up. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1039 | */ |
| 1040 | public static final int FOCUS_UP = 0x00000021; |
| 1041 | |
| 1042 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1043 | * 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] | 1044 | */ |
| 1045 | public static final int FOCUS_RIGHT = 0x00000042; |
| 1046 | |
| 1047 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1048 | * Use with {@link #focusSearch(int)}. Move focus down. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | */ |
| 1050 | public static final int FOCUS_DOWN = 0x00000082; |
| 1051 | |
| 1052 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1053 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1054 | * {@link #getMeasuredWidthAndState()} that provide the actual measured size. |
| 1055 | */ |
| 1056 | public static final int MEASURED_SIZE_MASK = 0x00ffffff; |
| 1057 | |
| 1058 | /** |
| 1059 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1060 | * {@link #getMeasuredWidthAndState()} that provide the additional state bits. |
| 1061 | */ |
| 1062 | public static final int MEASURED_STATE_MASK = 0xff000000; |
| 1063 | |
| 1064 | /** |
| 1065 | * Bit shift of {@link #MEASURED_STATE_MASK} to get to the height bits |
| 1066 | * for functions that combine both width and height into a single int, |
| 1067 | * such as {@link #getMeasuredState()} and the childState argument of |
| 1068 | * {@link #resolveSizeAndState(int, int, int)}. |
| 1069 | */ |
| 1070 | public static final int MEASURED_HEIGHT_STATE_SHIFT = 16; |
| 1071 | |
| 1072 | /** |
| 1073 | * Bit of {@link #getMeasuredWidthAndState()} and |
| 1074 | * {@link #getMeasuredWidthAndState()} that indicates the measured size |
| 1075 | * is smaller that the space the view would like to have. |
| 1076 | */ |
| 1077 | public static final int MEASURED_STATE_TOO_SMALL = 0x01000000; |
| 1078 | |
| 1079 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1080 | * Base View state sets |
| 1081 | */ |
| 1082 | // Singles |
| 1083 | /** |
| 1084 | * Indicates the view has no states set. States are used with |
| 1085 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1086 | * view depending on its state. |
| 1087 | * |
| 1088 | * @see android.graphics.drawable.Drawable |
| 1089 | * @see #getDrawableState() |
| 1090 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1091 | protected static final int[] EMPTY_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | /** |
| 1093 | * Indicates the view is enabled. States are used with |
| 1094 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1095 | * view depending on its state. |
| 1096 | * |
| 1097 | * @see android.graphics.drawable.Drawable |
| 1098 | * @see #getDrawableState() |
| 1099 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1100 | protected static final int[] ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1101 | /** |
| 1102 | * Indicates the view is focused. States are used with |
| 1103 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1104 | * view depending on its state. |
| 1105 | * |
| 1106 | * @see android.graphics.drawable.Drawable |
| 1107 | * @see #getDrawableState() |
| 1108 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1109 | protected static final int[] FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | /** |
| 1111 | * Indicates the view is selected. States are used with |
| 1112 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1113 | * view depending on its state. |
| 1114 | * |
| 1115 | * @see android.graphics.drawable.Drawable |
| 1116 | * @see #getDrawableState() |
| 1117 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1118 | protected static final int[] SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1119 | /** |
| 1120 | * Indicates the view is pressed. States are used with |
| 1121 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1122 | * view depending on its state. |
| 1123 | * |
| 1124 | * @see android.graphics.drawable.Drawable |
| 1125 | * @see #getDrawableState() |
| 1126 | * @hide |
| 1127 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1128 | protected static final int[] PRESSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1129 | /** |
| 1130 | * Indicates the view's window has focus. States are used with |
| 1131 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1132 | * view depending on its state. |
| 1133 | * |
| 1134 | * @see android.graphics.drawable.Drawable |
| 1135 | * @see #getDrawableState() |
| 1136 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1137 | protected static final int[] WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1138 | // Doubles |
| 1139 | /** |
| 1140 | * Indicates the view is enabled and has the focus. |
| 1141 | * |
| 1142 | * @see #ENABLED_STATE_SET |
| 1143 | * @see #FOCUSED_STATE_SET |
| 1144 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1145 | protected static final int[] ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1146 | /** |
| 1147 | * Indicates the view is enabled and selected. |
| 1148 | * |
| 1149 | * @see #ENABLED_STATE_SET |
| 1150 | * @see #SELECTED_STATE_SET |
| 1151 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1152 | protected static final int[] ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1153 | /** |
| 1154 | * Indicates the view is enabled and that its window has focus. |
| 1155 | * |
| 1156 | * @see #ENABLED_STATE_SET |
| 1157 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1158 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1159 | protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | /** |
| 1161 | * Indicates the view is focused and selected. |
| 1162 | * |
| 1163 | * @see #FOCUSED_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[] FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1167 | /** |
| 1168 | * Indicates the view has the focus and that its window has the focus. |
| 1169 | * |
| 1170 | * @see #FOCUSED_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[] FOCUSED_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 selected and that its window has the focus. |
| 1176 | * |
| 1177 | * @see #SELECTED_STATE_SET |
| 1178 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1179 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1180 | protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1181 | // Triples |
| 1182 | /** |
| 1183 | * Indicates the view is enabled, focused and selected. |
| 1184 | * |
| 1185 | * @see #ENABLED_STATE_SET |
| 1186 | * @see #FOCUSED_STATE_SET |
| 1187 | * @see #SELECTED_STATE_SET |
| 1188 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1189 | protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1190 | /** |
| 1191 | * Indicates the view is enabled, focused and its window has the focus. |
| 1192 | * |
| 1193 | * @see #ENABLED_STATE_SET |
| 1194 | * @see #FOCUSED_STATE_SET |
| 1195 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1196 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1197 | 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] | 1198 | /** |
| 1199 | * Indicates the view is enabled, selected and its window has the focus. |
| 1200 | * |
| 1201 | * @see #ENABLED_STATE_SET |
| 1202 | * @see #SELECTED_STATE_SET |
| 1203 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1204 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1205 | 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] | 1206 | /** |
| 1207 | * Indicates the view is focused, selected and its window has the focus. |
| 1208 | * |
| 1209 | * @see #FOCUSED_STATE_SET |
| 1210 | * @see #SELECTED_STATE_SET |
| 1211 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1212 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1213 | 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] | 1214 | /** |
| 1215 | * Indicates the view is enabled, focused, selected and its window |
| 1216 | * has the focus. |
| 1217 | * |
| 1218 | * @see #ENABLED_STATE_SET |
| 1219 | * @see #FOCUSED_STATE_SET |
| 1220 | * @see #SELECTED_STATE_SET |
| 1221 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1222 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1223 | 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] | 1224 | /** |
| 1225 | * Indicates the view is pressed and its window has the focus. |
| 1226 | * |
| 1227 | * @see #PRESSED_STATE_SET |
| 1228 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1229 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1230 | protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1231 | /** |
| 1232 | * Indicates the view is pressed and selected. |
| 1233 | * |
| 1234 | * @see #PRESSED_STATE_SET |
| 1235 | * @see #SELECTED_STATE_SET |
| 1236 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1237 | protected static final int[] PRESSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1238 | /** |
| 1239 | * Indicates the view is pressed, selected and its window has the focus. |
| 1240 | * |
| 1241 | * @see #PRESSED_STATE_SET |
| 1242 | * @see #SELECTED_STATE_SET |
| 1243 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1244 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1245 | 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] | 1246 | /** |
| 1247 | * Indicates the view is pressed and focused. |
| 1248 | * |
| 1249 | * @see #PRESSED_STATE_SET |
| 1250 | * @see #FOCUSED_STATE_SET |
| 1251 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1252 | protected static final int[] PRESSED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1253 | /** |
| 1254 | * Indicates the view is pressed, focused and its window has the focus. |
| 1255 | * |
| 1256 | * @see #PRESSED_STATE_SET |
| 1257 | * @see #FOCUSED_STATE_SET |
| 1258 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1259 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1260 | 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] | 1261 | /** |
| 1262 | * Indicates the view is pressed, focused and selected. |
| 1263 | * |
| 1264 | * @see #PRESSED_STATE_SET |
| 1265 | * @see #SELECTED_STATE_SET |
| 1266 | * @see #FOCUSED_STATE_SET |
| 1267 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1268 | protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1269 | /** |
| 1270 | * Indicates the view is pressed, focused, selected and its window has the focus. |
| 1271 | * |
| 1272 | * @see #PRESSED_STATE_SET |
| 1273 | * @see #FOCUSED_STATE_SET |
| 1274 | * @see #SELECTED_STATE_SET |
| 1275 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1276 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1277 | 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] | 1278 | /** |
| 1279 | * Indicates the view is pressed and enabled. |
| 1280 | * |
| 1281 | * @see #PRESSED_STATE_SET |
| 1282 | * @see #ENABLED_STATE_SET |
| 1283 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1284 | protected static final int[] PRESSED_ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1285 | /** |
| 1286 | * Indicates the view is pressed, enabled and its window has the focus. |
| 1287 | * |
| 1288 | * @see #PRESSED_STATE_SET |
| 1289 | * @see #ENABLED_STATE_SET |
| 1290 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1291 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1292 | 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] | 1293 | /** |
| 1294 | * Indicates the view is pressed, enabled and selected. |
| 1295 | * |
| 1296 | * @see #PRESSED_STATE_SET |
| 1297 | * @see #ENABLED_STATE_SET |
| 1298 | * @see #SELECTED_STATE_SET |
| 1299 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1300 | protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | /** |
| 1302 | * Indicates the view is pressed, enabled, selected and its window has the |
| 1303 | * focus. |
| 1304 | * |
| 1305 | * @see #PRESSED_STATE_SET |
| 1306 | * @see #ENABLED_STATE_SET |
| 1307 | * @see #SELECTED_STATE_SET |
| 1308 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1309 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1310 | 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] | 1311 | /** |
| 1312 | * Indicates the view is pressed, enabled and focused. |
| 1313 | * |
| 1314 | * @see #PRESSED_STATE_SET |
| 1315 | * @see #ENABLED_STATE_SET |
| 1316 | * @see #FOCUSED_STATE_SET |
| 1317 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1318 | protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1319 | /** |
| 1320 | * Indicates the view is pressed, enabled, focused and its window has the |
| 1321 | * focus. |
| 1322 | * |
| 1323 | * @see #PRESSED_STATE_SET |
| 1324 | * @see #ENABLED_STATE_SET |
| 1325 | * @see #FOCUSED_STATE_SET |
| 1326 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1327 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1328 | 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] | 1329 | /** |
| 1330 | * Indicates the view is pressed, enabled, focused and selected. |
| 1331 | * |
| 1332 | * @see #PRESSED_STATE_SET |
| 1333 | * @see #ENABLED_STATE_SET |
| 1334 | * @see #SELECTED_STATE_SET |
| 1335 | * @see #FOCUSED_STATE_SET |
| 1336 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1337 | 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] | 1338 | /** |
| 1339 | * Indicates the view is pressed, enabled, focused, selected and its window |
| 1340 | * has the focus. |
| 1341 | * |
| 1342 | * @see #PRESSED_STATE_SET |
| 1343 | * @see #ENABLED_STATE_SET |
| 1344 | * @see #SELECTED_STATE_SET |
| 1345 | * @see #FOCUSED_STATE_SET |
| 1346 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1347 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1348 | 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] | 1349 | |
| 1350 | /** |
| 1351 | * The order here is very important to {@link #getDrawableState()} |
| 1352 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1353 | private static final int[][] VIEW_STATE_SETS; |
| 1354 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1355 | static final int VIEW_STATE_WINDOW_FOCUSED = 1; |
| 1356 | static final int VIEW_STATE_SELECTED = 1 << 1; |
| 1357 | static final int VIEW_STATE_FOCUSED = 1 << 2; |
| 1358 | static final int VIEW_STATE_ENABLED = 1 << 3; |
| 1359 | static final int VIEW_STATE_PRESSED = 1 << 4; |
| 1360 | static final int VIEW_STATE_ACTIVATED = 1 << 5; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1361 | static final int VIEW_STATE_ACCELERATED = 1 << 6; |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1362 | static final int VIEW_STATE_HOVERED = 1 << 7; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1363 | static final int VIEW_STATE_DRAG_CAN_ACCEPT = 1 << 8; |
| 1364 | static final int VIEW_STATE_DRAG_HOVERED = 1 << 9; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1365 | |
| 1366 | static final int[] VIEW_STATE_IDS = new int[] { |
| 1367 | R.attr.state_window_focused, VIEW_STATE_WINDOW_FOCUSED, |
| 1368 | R.attr.state_selected, VIEW_STATE_SELECTED, |
| 1369 | R.attr.state_focused, VIEW_STATE_FOCUSED, |
| 1370 | R.attr.state_enabled, VIEW_STATE_ENABLED, |
| 1371 | R.attr.state_pressed, VIEW_STATE_PRESSED, |
| 1372 | R.attr.state_activated, VIEW_STATE_ACTIVATED, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1373 | R.attr.state_accelerated, VIEW_STATE_ACCELERATED, |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1374 | R.attr.state_hovered, VIEW_STATE_HOVERED, |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1375 | R.attr.state_drag_can_accept, VIEW_STATE_DRAG_CAN_ACCEPT, |
| 1376 | R.attr.state_drag_hovered, VIEW_STATE_DRAG_HOVERED, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | }; |
| 1378 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1379 | static { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1380 | if ((VIEW_STATE_IDS.length/2) != R.styleable.ViewDrawableStates.length) { |
| 1381 | throw new IllegalStateException( |
| 1382 | "VIEW_STATE_IDs array length does not match ViewDrawableStates style array"); |
| 1383 | } |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1384 | int[] orderedIds = new int[VIEW_STATE_IDS.length]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1385 | for (int i = 0; i < R.styleable.ViewDrawableStates.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1386 | int viewState = R.styleable.ViewDrawableStates[i]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1387 | for (int j = 0; j<VIEW_STATE_IDS.length; j += 2) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1388 | if (VIEW_STATE_IDS[j] == viewState) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1389 | orderedIds[i * 2] = viewState; |
| 1390 | orderedIds[i * 2 + 1] = VIEW_STATE_IDS[j + 1]; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1391 | } |
| 1392 | } |
| 1393 | } |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1394 | final int NUM_BITS = VIEW_STATE_IDS.length / 2; |
| 1395 | VIEW_STATE_SETS = new int[1 << NUM_BITS][]; |
| 1396 | for (int i = 0; i < VIEW_STATE_SETS.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1397 | int numBits = Integer.bitCount(i); |
| 1398 | int[] set = new int[numBits]; |
| 1399 | int pos = 0; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1400 | for (int j = 0; j < orderedIds.length; j += 2) { |
| 1401 | if ((i & orderedIds[j+1]) != 0) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1402 | set[pos++] = orderedIds[j]; |
| 1403 | } |
| 1404 | } |
| 1405 | VIEW_STATE_SETS[i] = set; |
| 1406 | } |
| 1407 | |
| 1408 | EMPTY_STATE_SET = VIEW_STATE_SETS[0]; |
| 1409 | WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_WINDOW_FOCUSED]; |
| 1410 | SELECTED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_SELECTED]; |
| 1411 | SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1412 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED]; |
| 1413 | FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_FOCUSED]; |
| 1414 | FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1415 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED]; |
| 1416 | FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1417 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED]; |
| 1418 | FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1419 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1420 | | VIEW_STATE_FOCUSED]; |
| 1421 | ENABLED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_ENABLED]; |
| 1422 | ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1423 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED]; |
| 1424 | ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1425 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED]; |
| 1426 | ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1427 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1428 | | VIEW_STATE_ENABLED]; |
| 1429 | ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1430 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED]; |
| 1431 | ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1432 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1433 | | VIEW_STATE_ENABLED]; |
| 1434 | ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1435 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1436 | | VIEW_STATE_ENABLED]; |
| 1437 | ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1438 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1439 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED]; |
| 1440 | |
| 1441 | PRESSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_PRESSED]; |
| 1442 | PRESSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1443 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_PRESSED]; |
| 1444 | PRESSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1445 | VIEW_STATE_SELECTED | VIEW_STATE_PRESSED]; |
| 1446 | PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1447 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1448 | | VIEW_STATE_PRESSED]; |
| 1449 | PRESSED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1450 | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1451 | PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1452 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1453 | | VIEW_STATE_PRESSED]; |
| 1454 | PRESSED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1455 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1456 | | VIEW_STATE_PRESSED]; |
| 1457 | PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1458 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1459 | | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1460 | PRESSED_ENABLED_STATE_SET = VIEW_STATE_SETS[ |
| 1461 | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1462 | PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1463 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED |
| 1464 | | VIEW_STATE_PRESSED]; |
| 1465 | PRESSED_ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1466 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED |
| 1467 | | VIEW_STATE_PRESSED]; |
| 1468 | PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1469 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1470 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1471 | PRESSED_ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1472 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED |
| 1473 | | VIEW_STATE_PRESSED]; |
| 1474 | PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1475 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1476 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1477 | PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1478 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1479 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1480 | PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1481 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1482 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED |
| 1483 | | VIEW_STATE_PRESSED]; |
| 1484 | } |
| 1485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1486 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1487 | * Temporary Rect currently for use in setBackground(). This will probably |
| 1488 | * be extended in the future to hold our own class with more than just |
| 1489 | * a Rect. :) |
| 1490 | */ |
| 1491 | static final ThreadLocal<Rect> sThreadLocal = new ThreadLocal<Rect>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1492 | |
| 1493 | /** |
| 1494 | * Map used to store views' tags. |
| 1495 | */ |
| 1496 | private static WeakHashMap<View, SparseArray<Object>> sTags; |
| 1497 | |
| 1498 | /** |
| 1499 | * Lock used to access sTags. |
| 1500 | */ |
| 1501 | private static final Object sTagsLock = new Object(); |
| 1502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1503 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1504 | * The next available accessiiblity id. |
| 1505 | */ |
| 1506 | private static int sNextAccessibilityViewId; |
| 1507 | |
| 1508 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1509 | * The animation currently associated with this view. |
| 1510 | * @hide |
| 1511 | */ |
| 1512 | protected Animation mCurrentAnimation = null; |
| 1513 | |
| 1514 | /** |
| 1515 | * Width as measured during measure pass. |
| 1516 | * {@hide} |
| 1517 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1518 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1519 | int mMeasuredWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1520 | |
| 1521 | /** |
| 1522 | * Height as measured during measure pass. |
| 1523 | * {@hide} |
| 1524 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1525 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1526 | int mMeasuredHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1527 | |
| 1528 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1529 | * Flag to indicate that this view was marked INVALIDATED, or had its display list |
| 1530 | * invalidated, prior to the current drawing iteration. If true, the view must re-draw |
| 1531 | * its display list. This flag, used only when hw accelerated, allows us to clear the |
| 1532 | * flag while retaining this information until it's needed (at getDisplayList() time and |
| 1533 | * in drawChild(), when we decide to draw a view's children's display lists into our own). |
| 1534 | * |
| 1535 | * {@hide} |
| 1536 | */ |
| 1537 | boolean mRecreateDisplayList = false; |
| 1538 | |
| 1539 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1540 | * The view's identifier. |
| 1541 | * {@hide} |
| 1542 | * |
| 1543 | * @see #setId(int) |
| 1544 | * @see #getId() |
| 1545 | */ |
| 1546 | @ViewDebug.ExportedProperty(resolveId = true) |
| 1547 | int mID = NO_ID; |
| 1548 | |
| 1549 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1550 | * The stable ID of this view for accessibility porposes. |
| 1551 | */ |
| 1552 | int mAccessibilityViewId = NO_ID; |
| 1553 | |
| 1554 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1555 | * The view's tag. |
| 1556 | * {@hide} |
| 1557 | * |
| 1558 | * @see #setTag(Object) |
| 1559 | * @see #getTag() |
| 1560 | */ |
| 1561 | protected Object mTag; |
| 1562 | |
| 1563 | // for mPrivateFlags: |
| 1564 | /** {@hide} */ |
| 1565 | static final int WANTS_FOCUS = 0x00000001; |
| 1566 | /** {@hide} */ |
| 1567 | static final int FOCUSED = 0x00000002; |
| 1568 | /** {@hide} */ |
| 1569 | static final int SELECTED = 0x00000004; |
| 1570 | /** {@hide} */ |
| 1571 | static final int IS_ROOT_NAMESPACE = 0x00000008; |
| 1572 | /** {@hide} */ |
| 1573 | static final int HAS_BOUNDS = 0x00000010; |
| 1574 | /** {@hide} */ |
| 1575 | static final int DRAWN = 0x00000020; |
| 1576 | /** |
| 1577 | * When this flag is set, this view is running an animation on behalf of its |
| 1578 | * children and should therefore not cancel invalidate requests, even if they |
| 1579 | * lie outside of this view's bounds. |
| 1580 | * |
| 1581 | * {@hide} |
| 1582 | */ |
| 1583 | static final int DRAW_ANIMATION = 0x00000040; |
| 1584 | /** {@hide} */ |
| 1585 | static final int SKIP_DRAW = 0x00000080; |
| 1586 | /** {@hide} */ |
| 1587 | static final int ONLY_DRAWS_BACKGROUND = 0x00000100; |
| 1588 | /** {@hide} */ |
| 1589 | static final int REQUEST_TRANSPARENT_REGIONS = 0x00000200; |
| 1590 | /** {@hide} */ |
| 1591 | static final int DRAWABLE_STATE_DIRTY = 0x00000400; |
| 1592 | /** {@hide} */ |
| 1593 | static final int MEASURED_DIMENSION_SET = 0x00000800; |
| 1594 | /** {@hide} */ |
| 1595 | static final int FORCE_LAYOUT = 0x00001000; |
Konstantin Lopyrev | c6dc457 | 2010-08-06 15:01:52 -0700 | [diff] [blame] | 1596 | /** {@hide} */ |
| 1597 | static final int LAYOUT_REQUIRED = 0x00002000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1598 | |
| 1599 | private static final int PRESSED = 0x00004000; |
| 1600 | |
| 1601 | /** {@hide} */ |
| 1602 | static final int DRAWING_CACHE_VALID = 0x00008000; |
| 1603 | /** |
| 1604 | * Flag used to indicate that this view should be drawn once more (and only once |
| 1605 | * more) after its animation has completed. |
| 1606 | * {@hide} |
| 1607 | */ |
| 1608 | static final int ANIMATION_STARTED = 0x00010000; |
| 1609 | |
| 1610 | private static final int SAVE_STATE_CALLED = 0x00020000; |
| 1611 | |
| 1612 | /** |
| 1613 | * Indicates that the View returned true when onSetAlpha() was called and that |
| 1614 | * the alpha must be restored. |
| 1615 | * {@hide} |
| 1616 | */ |
| 1617 | static final int ALPHA_SET = 0x00040000; |
| 1618 | |
| 1619 | /** |
| 1620 | * Set by {@link #setScrollContainer(boolean)}. |
| 1621 | */ |
| 1622 | static final int SCROLL_CONTAINER = 0x00080000; |
| 1623 | |
| 1624 | /** |
| 1625 | * Set by {@link #setScrollContainer(boolean)}. |
| 1626 | */ |
| 1627 | static final int SCROLL_CONTAINER_ADDED = 0x00100000; |
| 1628 | |
| 1629 | /** |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1630 | * View flag indicating whether this view was invalidated (fully or partially.) |
| 1631 | * |
| 1632 | * @hide |
| 1633 | */ |
| 1634 | static final int DIRTY = 0x00200000; |
| 1635 | |
| 1636 | /** |
| 1637 | * View flag indicating whether this view was invalidated by an opaque |
| 1638 | * invalidate request. |
| 1639 | * |
| 1640 | * @hide |
| 1641 | */ |
| 1642 | static final int DIRTY_OPAQUE = 0x00400000; |
| 1643 | |
| 1644 | /** |
| 1645 | * Mask for {@link #DIRTY} and {@link #DIRTY_OPAQUE}. |
| 1646 | * |
| 1647 | * @hide |
| 1648 | */ |
| 1649 | static final int DIRTY_MASK = 0x00600000; |
| 1650 | |
| 1651 | /** |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1652 | * Indicates whether the background is opaque. |
| 1653 | * |
| 1654 | * @hide |
| 1655 | */ |
| 1656 | static final int OPAQUE_BACKGROUND = 0x00800000; |
| 1657 | |
| 1658 | /** |
| 1659 | * Indicates whether the scrollbars are opaque. |
| 1660 | * |
| 1661 | * @hide |
| 1662 | */ |
| 1663 | static final int OPAQUE_SCROLLBARS = 0x01000000; |
| 1664 | |
| 1665 | /** |
| 1666 | * Indicates whether the view is opaque. |
| 1667 | * |
| 1668 | * @hide |
| 1669 | */ |
| 1670 | static final int OPAQUE_MASK = 0x01800000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1671 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1672 | /** |
| 1673 | * Indicates a prepressed state; |
| 1674 | * the short time between ACTION_DOWN and recognizing |
| 1675 | * a 'real' press. Prepressed is used to recognize quick taps |
| 1676 | * even when they are shorter than ViewConfiguration.getTapTimeout(). |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1677 | * |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1678 | * @hide |
| 1679 | */ |
| 1680 | private static final int PREPRESSED = 0x02000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1681 | |
Adam Powell | c9fbaab | 2010-02-16 17:16:19 -0800 | [diff] [blame] | 1682 | /** |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 1683 | * Indicates whether the view is temporarily detached. |
| 1684 | * |
| 1685 | * @hide |
| 1686 | */ |
| 1687 | static final int CANCEL_NEXT_UP_EVENT = 0x04000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1688 | |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1689 | /** |
| 1690 | * Indicates that we should awaken scroll bars once attached |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1691 | * |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1692 | * @hide |
| 1693 | */ |
| 1694 | private static final int AWAKEN_SCROLL_BARS_ON_ATTACH = 0x08000000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1695 | |
| 1696 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1697 | * Indicates that the view has received HOVER_ENTER. Cleared on HOVER_EXIT. |
| 1698 | * @hide |
| 1699 | */ |
| 1700 | private static final int HOVERED = 0x10000000; |
| 1701 | |
| 1702 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1703 | * Indicates that pivotX or pivotY were explicitly set and we should not assume the center |
| 1704 | * for transform operations |
| 1705 | * |
| 1706 | * @hide |
| 1707 | */ |
Adam Powell | f37df07 | 2010-09-17 16:22:49 -0700 | [diff] [blame] | 1708 | private static final int PIVOT_EXPLICITLY_SET = 0x20000000; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1709 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1710 | /** {@hide} */ |
Adam Powell | f37df07 | 2010-09-17 16:22:49 -0700 | [diff] [blame] | 1711 | static final int ACTIVATED = 0x40000000; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1712 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1713 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1714 | * Indicates that this view was specifically invalidated, not just dirtied because some |
| 1715 | * child view was invalidated. The flag is used to determine when we need to recreate |
| 1716 | * a view's display list (as opposed to just returning a reference to its existing |
| 1717 | * display list). |
| 1718 | * |
| 1719 | * @hide |
| 1720 | */ |
| 1721 | static final int INVALIDATED = 0x80000000; |
| 1722 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1723 | /* Masks for mPrivateFlags2 */ |
| 1724 | |
| 1725 | /** |
| 1726 | * Indicates that this view has reported that it can accept the current drag's content. |
| 1727 | * Cleared when the drag operation concludes. |
| 1728 | * @hide |
| 1729 | */ |
| 1730 | static final int DRAG_CAN_ACCEPT = 0x00000001; |
| 1731 | |
| 1732 | /** |
| 1733 | * Indicates that this view is currently directly under the drag location in a |
| 1734 | * drag-and-drop operation involving content that it can accept. Cleared when |
| 1735 | * the drag exits the view, or when the drag operation concludes. |
| 1736 | * @hide |
| 1737 | */ |
| 1738 | static final int DRAG_HOVERED = 0x00000002; |
| 1739 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1740 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1741 | * Indicates whether the view layout direction has been resolved and drawn to the |
| 1742 | * right-to-left direction. |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1743 | * |
| 1744 | * @hide |
| 1745 | */ |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1746 | static final int LAYOUT_DIRECTION_RESOLVED_RTL = 0x00000004; |
| 1747 | |
| 1748 | /** |
| 1749 | * Indicates whether the view layout direction has been resolved. |
| 1750 | * |
| 1751 | * @hide |
| 1752 | */ |
| 1753 | static final int LAYOUT_DIRECTION_RESOLVED = 0x00000008; |
| 1754 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1755 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1756 | /* End of masks for mPrivateFlags2 */ |
| 1757 | |
| 1758 | static final int DRAG_MASK = DRAG_CAN_ACCEPT | DRAG_HOVERED; |
| 1759 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1760 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 1761 | * Always allow a user to over-scroll this view, provided it is a |
| 1762 | * view that can scroll. |
| 1763 | * |
| 1764 | * @see #getOverScrollMode() |
| 1765 | * @see #setOverScrollMode(int) |
| 1766 | */ |
| 1767 | public static final int OVER_SCROLL_ALWAYS = 0; |
| 1768 | |
| 1769 | /** |
| 1770 | * Allow a user to over-scroll this view only if the content is large |
| 1771 | * enough to meaningfully scroll, provided it is a view that can scroll. |
| 1772 | * |
| 1773 | * @see #getOverScrollMode() |
| 1774 | * @see #setOverScrollMode(int) |
| 1775 | */ |
| 1776 | public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1; |
| 1777 | |
| 1778 | /** |
| 1779 | * Never allow a user to over-scroll this view. |
| 1780 | * |
| 1781 | * @see #getOverScrollMode() |
| 1782 | * @see #setOverScrollMode(int) |
| 1783 | */ |
| 1784 | public static final int OVER_SCROLL_NEVER = 2; |
| 1785 | |
| 1786 | /** |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1787 | * View has requested the system UI (status bar) to be visible (the default). |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1788 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1789 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1790 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1791 | public static final int SYSTEM_UI_FLAG_VISIBLE = 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1792 | |
| 1793 | /** |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1794 | * View has requested the system UI to enter an unobtrusive "low profile" mode. |
| 1795 | * |
| 1796 | * This is for use in games, book readers, video players, or any other "immersive" application |
| 1797 | * where the usual system chrome is deemed too distracting. |
| 1798 | * |
| 1799 | * 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] | 1800 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1801 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1802 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1803 | public static final int SYSTEM_UI_FLAG_LOW_PROFILE = 0x00000001; |
| 1804 | |
| 1805 | /** |
| 1806 | * View has requested that the system navigation be temporarily hidden. |
| 1807 | * |
| 1808 | * This is an even less obtrusive state than that called for by |
| 1809 | * {@link #SYSTEM_UI_FLAG_LOW_PROFILE}; on devices that draw essential navigation controls |
| 1810 | * (Home, Back, and the like) on screen, <code>SYSTEM_UI_FLAG_HIDE_NAVIGATION</code> will cause |
| 1811 | * those to disappear. This is useful (in conjunction with the |
| 1812 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN FLAG_FULLSCREEN} and |
| 1813 | * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN FLAG_LAYOUT_IN_SCREEN} |
| 1814 | * window flags) for displaying content using every last pixel on the display. |
| 1815 | * |
| 1816 | * There is a limitation: because navigation controls are so important, the least user |
| 1817 | * interaction will cause them to reappear immediately. |
| 1818 | * |
| 1819 | * @see #setSystemUiVisibility(int) |
| 1820 | */ |
| 1821 | public static final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 0x00000002; |
| 1822 | |
| 1823 | /** |
| 1824 | * @deprecated Use {@link #SYSTEM_UI_FLAG_LOW_PROFILE} instead. |
| 1825 | */ |
| 1826 | public static final int STATUS_BAR_HIDDEN = SYSTEM_UI_FLAG_LOW_PROFILE; |
| 1827 | |
| 1828 | /** |
| 1829 | * @deprecated Use {@link #SYSTEM_UI_FLAG_VISIBLE} instead. |
| 1830 | */ |
| 1831 | public static final int STATUS_BAR_VISIBLE = SYSTEM_UI_FLAG_VISIBLE; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1832 | |
| 1833 | /** |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 1834 | * @hide |
| 1835 | * |
| 1836 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1837 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1838 | * |
| 1839 | * Flag to make the status bar not expandable. Unless you also |
| 1840 | * set {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show. |
| 1841 | */ |
| 1842 | public static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000; |
| 1843 | |
| 1844 | /** |
| 1845 | * @hide |
| 1846 | * |
| 1847 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1848 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1849 | * |
| 1850 | * Flag to hide notification icons and scrolling ticker text. |
| 1851 | */ |
| 1852 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ICONS = 0x00020000; |
| 1853 | |
| 1854 | /** |
| 1855 | * @hide |
| 1856 | * |
| 1857 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1858 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1859 | * |
| 1860 | * Flag to disable incoming notification alerts. This will not block |
| 1861 | * icons, but it will block sound, vibrating and other visual or aural notifications. |
| 1862 | */ |
| 1863 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ALERTS = 0x00040000; |
| 1864 | |
| 1865 | /** |
| 1866 | * @hide |
| 1867 | * |
| 1868 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1869 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1870 | * |
| 1871 | * Flag to hide only the scrolling ticker. Note that |
| 1872 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS} implies |
| 1873 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_TICKER}. |
| 1874 | */ |
| 1875 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_TICKER = 0x00080000; |
| 1876 | |
| 1877 | /** |
| 1878 | * @hide |
| 1879 | * |
| 1880 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1881 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1882 | * |
| 1883 | * Flag to hide the center system info area. |
| 1884 | */ |
| 1885 | public static final int STATUS_BAR_DISABLE_SYSTEM_INFO = 0x00100000; |
| 1886 | |
| 1887 | /** |
| 1888 | * @hide |
| 1889 | * |
| 1890 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1891 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1892 | * |
| 1893 | * Flag to hide only the navigation buttons. Don't use this |
| 1894 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 1895 | * |
| 1896 | * THIS DOES NOT DISABLE THE BACK BUTTON |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 1897 | */ |
| 1898 | public static final int STATUS_BAR_DISABLE_NAVIGATION = 0x00200000; |
| 1899 | |
| 1900 | /** |
| 1901 | * @hide |
| 1902 | * |
| 1903 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1904 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1905 | * |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 1906 | * Flag to hide only the back button. Don't use this |
| 1907 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 1908 | */ |
| 1909 | public static final int STATUS_BAR_DISABLE_BACK = 0x00400000; |
| 1910 | |
| 1911 | /** |
| 1912 | * @hide |
| 1913 | * |
| 1914 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1915 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1916 | * |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 1917 | * Flag to hide only the clock. You might use this if your activity has |
| 1918 | * its own clock making the status bar's clock redundant. |
| 1919 | */ |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 1920 | public static final int STATUS_BAR_DISABLE_CLOCK = 0x00800000; |
| 1921 | |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 1922 | /** |
| 1923 | * @hide |
| 1924 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1925 | public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK = 0x0000FFFF; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 1926 | |
| 1927 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 1928 | * Controls the over-scroll mode for this view. |
| 1929 | * See {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)}, |
| 1930 | * {@link #OVER_SCROLL_ALWAYS}, {@link #OVER_SCROLL_IF_CONTENT_SCROLLS}, |
| 1931 | * and {@link #OVER_SCROLL_NEVER}. |
| 1932 | */ |
| 1933 | private int mOverScrollMode; |
| 1934 | |
| 1935 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1936 | * The parent this view is attached to. |
| 1937 | * {@hide} |
| 1938 | * |
| 1939 | * @see #getParent() |
| 1940 | */ |
| 1941 | protected ViewParent mParent; |
| 1942 | |
| 1943 | /** |
| 1944 | * {@hide} |
| 1945 | */ |
| 1946 | AttachInfo mAttachInfo; |
| 1947 | |
| 1948 | /** |
| 1949 | * {@hide} |
| 1950 | */ |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1951 | @ViewDebug.ExportedProperty(flagMapping = { |
| 1952 | @ViewDebug.FlagToString(mask = FORCE_LAYOUT, equals = FORCE_LAYOUT, |
| 1953 | name = "FORCE_LAYOUT"), |
| 1954 | @ViewDebug.FlagToString(mask = LAYOUT_REQUIRED, equals = LAYOUT_REQUIRED, |
| 1955 | name = "LAYOUT_REQUIRED"), |
| 1956 | @ViewDebug.FlagToString(mask = DRAWING_CACHE_VALID, equals = DRAWING_CACHE_VALID, |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 1957 | name = "DRAWING_CACHE_INVALID", outputIf = false), |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1958 | @ViewDebug.FlagToString(mask = DRAWN, equals = DRAWN, name = "DRAWN", outputIf = true), |
| 1959 | @ViewDebug.FlagToString(mask = DRAWN, equals = DRAWN, name = "NOT_DRAWN", outputIf = false), |
| 1960 | @ViewDebug.FlagToString(mask = DIRTY_MASK, equals = DIRTY_OPAQUE, name = "DIRTY_OPAQUE"), |
| 1961 | @ViewDebug.FlagToString(mask = DIRTY_MASK, equals = DIRTY, name = "DIRTY") |
| 1962 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1963 | int mPrivateFlags; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1964 | int mPrivateFlags2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1965 | |
| 1966 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1967 | * This view's request for the visibility of the status bar. |
| 1968 | * @hide |
| 1969 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1970 | @ViewDebug.ExportedProperty(flagMapping = { |
| 1971 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 1972 | equals = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 1973 | name = "SYSTEM_UI_FLAG_LOW_PROFILE", outputIf = true), |
| 1974 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 1975 | equals = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 1976 | name = "SYSTEM_UI_FLAG_HIDE_NAVIGATION", outputIf = true), |
| 1977 | @ViewDebug.FlagToString(mask = PUBLIC_STATUS_BAR_VISIBILITY_MASK, |
| 1978 | equals = SYSTEM_UI_FLAG_VISIBLE, |
| 1979 | name = "SYSTEM_UI_FLAG_VISIBLE", outputIf = true) |
| 1980 | }) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1981 | int mSystemUiVisibility; |
| 1982 | |
| 1983 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1984 | * Count of how many windows this view has been attached to. |
| 1985 | */ |
| 1986 | int mWindowAttachCount; |
| 1987 | |
| 1988 | /** |
| 1989 | * The layout parameters associated with this view and used by the parent |
| 1990 | * {@link android.view.ViewGroup} to determine how this view should be |
| 1991 | * laid out. |
| 1992 | * {@hide} |
| 1993 | */ |
| 1994 | protected ViewGroup.LayoutParams mLayoutParams; |
| 1995 | |
| 1996 | /** |
| 1997 | * The view flags hold various views states. |
| 1998 | * {@hide} |
| 1999 | */ |
| 2000 | @ViewDebug.ExportedProperty |
| 2001 | int mViewFlags; |
| 2002 | |
| 2003 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2004 | * The transform matrix for the View. This transform is calculated internally |
| 2005 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2006 | * is used by default. Do *not* use this variable directly; instead call |
| 2007 | * getMatrix(), which will automatically recalculate the matrix if necessary |
| 2008 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2009 | */ |
| 2010 | private final Matrix mMatrix = new Matrix(); |
| 2011 | |
| 2012 | /** |
| 2013 | * The transform matrix for the View. This transform is calculated internally |
| 2014 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2015 | * is used by default. Do *not* use this variable directly; instead call |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 2016 | * getInverseMatrix(), which will automatically recalculate the matrix if necessary |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2017 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2018 | */ |
| 2019 | private Matrix mInverseMatrix; |
| 2020 | |
| 2021 | /** |
| 2022 | * An internal variable that tracks whether we need to recalculate the |
| 2023 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2024 | * have changed since the matrix was last calculated. |
| 2025 | */ |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2026 | boolean mMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2027 | |
| 2028 | /** |
| 2029 | * An internal variable that tracks whether we need to recalculate the |
| 2030 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2031 | * have changed since the matrix was last calculated. |
| 2032 | */ |
| 2033 | private boolean mInverseMatrixDirty = true; |
| 2034 | |
| 2035 | /** |
| 2036 | * A variable that tracks whether we need to recalculate the |
| 2037 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2038 | * have changed since the matrix was last calculated. This variable |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 2039 | * is only valid after a call to updateMatrix() or to a function that |
| 2040 | * calls it such as getMatrix(), hasIdentityMatrix() and getInverseMatrix(). |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2041 | */ |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 2042 | private boolean mMatrixIsIdentity = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2043 | |
| 2044 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2045 | * The Camera object is used to compute a 3D matrix when rotationX or rotationY are set. |
| 2046 | */ |
| 2047 | private Camera mCamera = null; |
| 2048 | |
| 2049 | /** |
| 2050 | * This matrix is used when computing the matrix for 3D rotations. |
| 2051 | */ |
| 2052 | private Matrix matrix3D = null; |
| 2053 | |
| 2054 | /** |
| 2055 | * These prev values are used to recalculate a centered pivot point when necessary. The |
| 2056 | * pivot point is only used in matrix operations (when rotation, scale, or translation are |
| 2057 | * set), so thes values are only used then as well. |
| 2058 | */ |
| 2059 | private int mPrevWidth = -1; |
| 2060 | private int mPrevHeight = -1; |
| 2061 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2062 | private boolean mLastIsOpaque; |
| 2063 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2064 | /** |
| 2065 | * Convenience value to check for float values that are close enough to zero to be considered |
| 2066 | * zero. |
| 2067 | */ |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame] | 2068 | private static final float NONZERO_EPSILON = .001f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2069 | |
| 2070 | /** |
| 2071 | * The degrees rotation around the vertical axis through the pivot point. |
| 2072 | */ |
| 2073 | @ViewDebug.ExportedProperty |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2074 | float mRotationY = 0f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2075 | |
| 2076 | /** |
| 2077 | * The degrees rotation around the horizontal axis through the pivot point. |
| 2078 | */ |
| 2079 | @ViewDebug.ExportedProperty |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2080 | float mRotationX = 0f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2081 | |
| 2082 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2083 | * The degrees rotation around the pivot point. |
| 2084 | */ |
| 2085 | @ViewDebug.ExportedProperty |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2086 | float mRotation = 0f; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2087 | |
| 2088 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 2089 | * The amount of translation of the object away from its left property (post-layout). |
| 2090 | */ |
| 2091 | @ViewDebug.ExportedProperty |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2092 | float mTranslationX = 0f; |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 2093 | |
| 2094 | /** |
| 2095 | * The amount of translation of the object away from its top property (post-layout). |
| 2096 | */ |
| 2097 | @ViewDebug.ExportedProperty |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2098 | float mTranslationY = 0f; |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 2099 | |
| 2100 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2101 | * The amount of scale in the x direction around the pivot point. A |
| 2102 | * value of 1 means no scaling is applied. |
| 2103 | */ |
| 2104 | @ViewDebug.ExportedProperty |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2105 | float mScaleX = 1f; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2106 | |
| 2107 | /** |
| 2108 | * The amount of scale in the y direction around the pivot point. A |
| 2109 | * value of 1 means no scaling is applied. |
| 2110 | */ |
| 2111 | @ViewDebug.ExportedProperty |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2112 | float mScaleY = 1f; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2113 | |
| 2114 | /** |
| 2115 | * The amount of scale in the x direction around the pivot point. A |
| 2116 | * value of 1 means no scaling is applied. |
| 2117 | */ |
| 2118 | @ViewDebug.ExportedProperty |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2119 | float mPivotX = 0f; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2120 | |
| 2121 | /** |
| 2122 | * The amount of scale in the y direction around the pivot point. A |
| 2123 | * value of 1 means no scaling is applied. |
| 2124 | */ |
| 2125 | @ViewDebug.ExportedProperty |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2126 | float mPivotY = 0f; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2127 | |
| 2128 | /** |
| 2129 | * The opacity of the View. This is a value from 0 to 1, where 0 means |
| 2130 | * completely transparent and 1 means completely opaque. |
| 2131 | */ |
| 2132 | @ViewDebug.ExportedProperty |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2133 | float mAlpha = 1f; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2134 | |
| 2135 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2136 | * The distance in pixels from the left edge of this view's parent |
| 2137 | * to the left edge of this view. |
| 2138 | * {@hide} |
| 2139 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2140 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2141 | protected int mLeft; |
| 2142 | /** |
| 2143 | * The distance in pixels from the left edge of this view's parent |
| 2144 | * to the right edge of this view. |
| 2145 | * {@hide} |
| 2146 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2147 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2148 | protected int mRight; |
| 2149 | /** |
| 2150 | * The distance in pixels from the top edge of this view's parent |
| 2151 | * to the top edge of this view. |
| 2152 | * {@hide} |
| 2153 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2154 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2155 | protected int mTop; |
| 2156 | /** |
| 2157 | * The distance in pixels from the top edge of this view's parent |
| 2158 | * to the bottom edge of this view. |
| 2159 | * {@hide} |
| 2160 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2161 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2162 | protected int mBottom; |
| 2163 | |
| 2164 | /** |
| 2165 | * The offset, in pixels, by which the content of this view is scrolled |
| 2166 | * horizontally. |
| 2167 | * {@hide} |
| 2168 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2169 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2170 | protected int mScrollX; |
| 2171 | /** |
| 2172 | * The offset, in pixels, by which the content of this view is scrolled |
| 2173 | * vertically. |
| 2174 | * {@hide} |
| 2175 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2176 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2177 | protected int mScrollY; |
| 2178 | |
| 2179 | /** |
| 2180 | * The left padding in pixels, that is the distance in pixels between the |
| 2181 | * left edge of this view and the left edge of its content. |
| 2182 | * {@hide} |
| 2183 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2184 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2185 | protected int mPaddingLeft; |
| 2186 | /** |
| 2187 | * The right padding in pixels, that is the distance in pixels between the |
| 2188 | * right edge of this view and the right edge of its content. |
| 2189 | * {@hide} |
| 2190 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2191 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2192 | protected int mPaddingRight; |
| 2193 | /** |
| 2194 | * The top padding in pixels, that is the distance in pixels between the |
| 2195 | * top edge of this view and the top edge of its content. |
| 2196 | * {@hide} |
| 2197 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2198 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2199 | protected int mPaddingTop; |
| 2200 | /** |
| 2201 | * The bottom padding in pixels, that is the distance in pixels between the |
| 2202 | * bottom edge of this view and the bottom edge of its content. |
| 2203 | * {@hide} |
| 2204 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2205 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2206 | protected int mPaddingBottom; |
| 2207 | |
| 2208 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2209 | * Briefly describes the view and is primarily used for accessibility support. |
| 2210 | */ |
| 2211 | private CharSequence mContentDescription; |
| 2212 | |
| 2213 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2214 | * 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] | 2215 | * |
| 2216 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2217 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2218 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2219 | protected int mUserPaddingRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2220 | |
| 2221 | /** |
| 2222 | * 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] | 2223 | * |
| 2224 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2225 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2226 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2227 | protected int mUserPaddingBottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2228 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2229 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2230 | * 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] | 2231 | * |
| 2232 | * @hide |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2233 | */ |
| 2234 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2235 | protected int mUserPaddingLeft; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2236 | |
| 2237 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 2238 | * Cache if the user padding is relative. |
| 2239 | * |
| 2240 | */ |
| 2241 | @ViewDebug.ExportedProperty(category = "padding") |
| 2242 | boolean mUserPaddingRelative; |
| 2243 | |
| 2244 | /** |
| 2245 | * Cache the paddingStart set by the user to append to the scrollbar's size. |
| 2246 | * |
| 2247 | */ |
| 2248 | @ViewDebug.ExportedProperty(category = "padding") |
| 2249 | int mUserPaddingStart; |
| 2250 | |
| 2251 | /** |
| 2252 | * Cache the paddingEnd set by the user to append to the scrollbar's size. |
| 2253 | * |
| 2254 | */ |
| 2255 | @ViewDebug.ExportedProperty(category = "padding") |
| 2256 | int mUserPaddingEnd; |
| 2257 | |
| 2258 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2259 | * @hide |
| 2260 | */ |
| 2261 | int mOldWidthMeasureSpec = Integer.MIN_VALUE; |
| 2262 | /** |
| 2263 | * @hide |
| 2264 | */ |
| 2265 | int mOldHeightMeasureSpec = Integer.MIN_VALUE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2266 | |
| 2267 | private Resources mResources = null; |
| 2268 | |
| 2269 | private Drawable mBGDrawable; |
| 2270 | |
| 2271 | private int mBackgroundResource; |
| 2272 | private boolean mBackgroundSizeChanged; |
| 2273 | |
| 2274 | /** |
| 2275 | * Listener used to dispatch focus change events. |
| 2276 | * This field should be made private, so it is hidden from the SDK. |
| 2277 | * {@hide} |
| 2278 | */ |
| 2279 | protected OnFocusChangeListener mOnFocusChangeListener; |
| 2280 | |
| 2281 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 2282 | * Listeners for layout change events. |
| 2283 | */ |
| 2284 | private ArrayList<OnLayoutChangeListener> mOnLayoutChangeListeners; |
| 2285 | |
| 2286 | /** |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 2287 | * Listeners for attach events. |
| 2288 | */ |
| 2289 | private CopyOnWriteArrayList<OnAttachStateChangeListener> mOnAttachStateChangeListeners; |
| 2290 | |
| 2291 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2292 | * Listener used to dispatch click events. |
| 2293 | * This field should be made private, so it is hidden from the SDK. |
| 2294 | * {@hide} |
| 2295 | */ |
| 2296 | protected OnClickListener mOnClickListener; |
| 2297 | |
| 2298 | /** |
| 2299 | * Listener used to dispatch long click events. |
| 2300 | * This field should be made private, so it is hidden from the SDK. |
| 2301 | * {@hide} |
| 2302 | */ |
| 2303 | protected OnLongClickListener mOnLongClickListener; |
| 2304 | |
| 2305 | /** |
| 2306 | * Listener used to build the context menu. |
| 2307 | * This field should be made private, so it is hidden from the SDK. |
| 2308 | * {@hide} |
| 2309 | */ |
| 2310 | protected OnCreateContextMenuListener mOnCreateContextMenuListener; |
| 2311 | |
| 2312 | private OnKeyListener mOnKeyListener; |
| 2313 | |
| 2314 | private OnTouchListener mOnTouchListener; |
| 2315 | |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2316 | private OnHoverListener mOnHoverListener; |
| 2317 | |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2318 | private OnGenericMotionListener mOnGenericMotionListener; |
| 2319 | |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 2320 | private OnDragListener mOnDragListener; |
| 2321 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2322 | private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener; |
| 2323 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2324 | /** |
| 2325 | * The application environment this view lives in. |
| 2326 | * This field should be made private, so it is hidden from the SDK. |
| 2327 | * {@hide} |
| 2328 | */ |
| 2329 | protected Context mContext; |
| 2330 | |
| 2331 | private ScrollabilityCache mScrollCache; |
| 2332 | |
| 2333 | private int[] mDrawableState = null; |
| 2334 | |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2335 | /** |
| 2336 | * Set to true when drawing cache is enabled and cannot be created. |
| 2337 | * |
| 2338 | * @hide |
| 2339 | */ |
| 2340 | public boolean mCachingFailed; |
| 2341 | |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 2342 | private Bitmap mDrawingCache; |
| 2343 | private Bitmap mUnscaledDrawingCache; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 2344 | private HardwareLayer mHardwareLayer; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2345 | DisplayList mDisplayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2346 | |
| 2347 | /** |
| 2348 | * When this view has focus and the next focus is {@link #FOCUS_LEFT}, |
| 2349 | * the user may specify which view to go to next. |
| 2350 | */ |
| 2351 | private int mNextFocusLeftId = View.NO_ID; |
| 2352 | |
| 2353 | /** |
| 2354 | * When this view has focus and the next focus is {@link #FOCUS_RIGHT}, |
| 2355 | * the user may specify which view to go to next. |
| 2356 | */ |
| 2357 | private int mNextFocusRightId = View.NO_ID; |
| 2358 | |
| 2359 | /** |
| 2360 | * When this view has focus and the next focus is {@link #FOCUS_UP}, |
| 2361 | * the user may specify which view to go to next. |
| 2362 | */ |
| 2363 | private int mNextFocusUpId = View.NO_ID; |
| 2364 | |
| 2365 | /** |
| 2366 | * When this view has focus and the next focus is {@link #FOCUS_DOWN}, |
| 2367 | * the user may specify which view to go to next. |
| 2368 | */ |
| 2369 | private int mNextFocusDownId = View.NO_ID; |
| 2370 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 2371 | /** |
| 2372 | * When this view has focus and the next focus is {@link #FOCUS_FORWARD}, |
| 2373 | * the user may specify which view to go to next. |
| 2374 | */ |
| 2375 | int mNextFocusForwardId = View.NO_ID; |
| 2376 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2377 | private CheckForLongPress mPendingCheckForLongPress; |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2378 | private CheckForTap mPendingCheckForTap = null; |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 2379 | private PerformClick mPerformClick; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 2380 | private SendViewScrolledAccessibilityEvent mSendViewScrolledAccessibilityEvent; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2382 | private UnsetPressedState mUnsetPressedState; |
| 2383 | |
| 2384 | /** |
| 2385 | * Whether the long press's action has been invoked. The tap's action is invoked on the |
| 2386 | * up event while a long press is invoked as soon as the long press duration is reached, so |
| 2387 | * a long press could be performed before the tap is checked, in which case the tap's action |
| 2388 | * should not be invoked. |
| 2389 | */ |
| 2390 | private boolean mHasPerformedLongPress; |
| 2391 | |
| 2392 | /** |
| 2393 | * The minimum height of the view. We'll try our best to have the height |
| 2394 | * of this view to at least this amount. |
| 2395 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2396 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2397 | private int mMinHeight; |
| 2398 | |
| 2399 | /** |
| 2400 | * The minimum width of the view. We'll try our best to have the width |
| 2401 | * of this view to at least this amount. |
| 2402 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2403 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2404 | private int mMinWidth; |
| 2405 | |
| 2406 | /** |
| 2407 | * The delegate to handle touch events that are physically in this view |
| 2408 | * but should be handled by another view. |
| 2409 | */ |
| 2410 | private TouchDelegate mTouchDelegate = null; |
| 2411 | |
| 2412 | /** |
| 2413 | * Solid color to use as a background when creating the drawing cache. Enables |
| 2414 | * the cache to use 16 bit bitmaps instead of 32 bit. |
| 2415 | */ |
| 2416 | private int mDrawingCacheBackgroundColor = 0; |
| 2417 | |
| 2418 | /** |
| 2419 | * Special tree observer used when mAttachInfo is null. |
| 2420 | */ |
| 2421 | private ViewTreeObserver mFloatingTreeObserver; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2422 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2423 | /** |
| 2424 | * Cache the touch slop from the context that created the view. |
| 2425 | */ |
| 2426 | private int mTouchSlop; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2427 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2428 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2429 | * Object that handles automatic animation of view properties. |
| 2430 | */ |
| 2431 | private ViewPropertyAnimator mAnimator = null; |
| 2432 | |
| 2433 | /** |
Christopher Tate | 251602f | 2011-01-28 17:54:12 -0800 | [diff] [blame] | 2434 | * Flag indicating that a drag can cross window boundaries. When |
| 2435 | * {@link #startDrag(ClipData, DragShadowBuilder, Object, int)} is called |
| 2436 | * with this flag set, all visible applications will be able to participate |
| 2437 | * in the drag operation and receive the dragged content. |
Christopher Tate | 7f9ff9d | 2011-02-14 17:31:13 -0800 | [diff] [blame] | 2438 | * |
| 2439 | * @hide |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 2440 | */ |
| 2441 | public static final int DRAG_FLAG_GLOBAL = 1; |
| 2442 | |
| 2443 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2444 | * Vertical scroll factor cached by {@link #getVerticalScrollFactor}. |
| 2445 | */ |
| 2446 | private float mVerticalScrollFactor; |
| 2447 | |
| 2448 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2449 | * Position of the vertical scroll bar. |
| 2450 | */ |
| 2451 | private int mVerticalScrollbarPosition; |
| 2452 | |
| 2453 | /** |
| 2454 | * Position the scroll bar at the default position as determined by the system. |
| 2455 | */ |
| 2456 | public static final int SCROLLBAR_POSITION_DEFAULT = 0; |
| 2457 | |
| 2458 | /** |
| 2459 | * Position the scroll bar along the left edge. |
| 2460 | */ |
| 2461 | public static final int SCROLLBAR_POSITION_LEFT = 1; |
| 2462 | |
| 2463 | /** |
| 2464 | * Position the scroll bar along the right edge. |
| 2465 | */ |
| 2466 | public static final int SCROLLBAR_POSITION_RIGHT = 2; |
| 2467 | |
| 2468 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2469 | * Indicates that the view does not have a layer. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2470 | * |
| 2471 | * @see #getLayerType() |
| 2472 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2473 | * @see #LAYER_TYPE_SOFTWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2474 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2475 | */ |
| 2476 | public static final int LAYER_TYPE_NONE = 0; |
| 2477 | |
| 2478 | /** |
| 2479 | * <p>Indicates that the view has a software layer. A software layer is backed |
| 2480 | * by a bitmap and causes the view to be rendered using Android's software |
| 2481 | * rendering pipeline, even if hardware acceleration is enabled.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2482 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2483 | * <p>Software layers have various usages:</p> |
| 2484 | * <p>When the application is not using hardware acceleration, a software layer |
| 2485 | * is useful to apply a specific color filter and/or blending mode and/or |
| 2486 | * translucency to a view and all its children.</p> |
| 2487 | * <p>When the application is using hardware acceleration, a software layer |
| 2488 | * is useful to render drawing primitives not supported by the hardware |
| 2489 | * accelerated pipeline. It can also be used to cache a complex view tree |
| 2490 | * into a texture and reduce the complexity of drawing operations. For instance, |
| 2491 | * when animating a complex view tree with a translation, a software layer can |
| 2492 | * be used to render the view tree only once.</p> |
| 2493 | * <p>Software layers should be avoided when the affected view tree updates |
| 2494 | * often. Every update will require to re-render the software layer, which can |
| 2495 | * potentially be slow (particularly when hardware acceleration is turned on |
| 2496 | * since the layer will have to be uploaded into a hardware texture after every |
| 2497 | * update.)</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2498 | * |
| 2499 | * @see #getLayerType() |
| 2500 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2501 | * @see #LAYER_TYPE_NONE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2502 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2503 | */ |
| 2504 | public static final int LAYER_TYPE_SOFTWARE = 1; |
| 2505 | |
| 2506 | /** |
| 2507 | * <p>Indicates that the view has a hardware layer. A hardware layer is backed |
| 2508 | * by a hardware specific texture (generally Frame Buffer Objects or FBO on |
| 2509 | * OpenGL hardware) and causes the view to be rendered using Android's hardware |
| 2510 | * rendering pipeline, but only if hardware acceleration is turned on for the |
| 2511 | * view hierarchy. When hardware acceleration is turned off, hardware layers |
| 2512 | * behave exactly as {@link #LAYER_TYPE_SOFTWARE software layers}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2513 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2514 | * <p>A hardware layer is useful to apply a specific color filter and/or |
| 2515 | * 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] | 2516 | * <p>A hardware layer can be used to cache a complex view tree into a |
| 2517 | * texture and reduce the complexity of drawing operations. For instance, |
| 2518 | * when animating a complex view tree with a translation, a hardware layer can |
| 2519 | * be used to render the view tree only once.</p> |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2520 | * <p>A hardware layer can also be used to increase the rendering quality when |
| 2521 | * rotation transformations are applied on a view. It can also be used to |
| 2522 | * prevent potential clipping issues when applying 3D transforms on a view.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2523 | * |
| 2524 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2525 | * @see #setLayerType(int, android.graphics.Paint) |
| 2526 | * @see #LAYER_TYPE_NONE |
| 2527 | * @see #LAYER_TYPE_SOFTWARE |
| 2528 | */ |
| 2529 | public static final int LAYER_TYPE_HARDWARE = 2; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2530 | |
Romain Guy | 3aaff3a | 2011-01-12 14:18:47 -0800 | [diff] [blame] | 2531 | @ViewDebug.ExportedProperty(category = "drawing", mapping = { |
| 2532 | @ViewDebug.IntToString(from = LAYER_TYPE_NONE, to = "NONE"), |
| 2533 | @ViewDebug.IntToString(from = LAYER_TYPE_SOFTWARE, to = "SOFTWARE"), |
| 2534 | @ViewDebug.IntToString(from = LAYER_TYPE_HARDWARE, to = "HARDWARE") |
| 2535 | }) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2536 | int mLayerType = LAYER_TYPE_NONE; |
| 2537 | Paint mLayerPaint; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 2538 | Rect mLocalDirtyRect; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2539 | |
| 2540 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 2541 | * Set to true when the view is sending hover accessibility events because it |
| 2542 | * is the innermost hovered view. |
| 2543 | */ |
| 2544 | private boolean mSendingHoverAccessibilityEvents; |
| 2545 | |
| 2546 | /** |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2547 | * Text direction is inherited thru {@link ViewGroup} |
| 2548 | * @hide |
| 2549 | */ |
| 2550 | public static final int TEXT_DIRECTION_INHERIT = 0; |
| 2551 | |
| 2552 | /** |
| 2553 | * Text direction is using "first strong algorithm". The first strong directional character |
| 2554 | * determines the paragraph direction. If there is no strong directional character, the |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 2555 | * paragraph direction is the view's resolved ayout direction. |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2556 | * |
| 2557 | * @hide |
| 2558 | */ |
| 2559 | public static final int TEXT_DIRECTION_FIRST_STRONG = 1; |
| 2560 | |
| 2561 | /** |
| 2562 | * Text direction is using "any-RTL" algorithm. The paragraph direction is RTL if it contains |
| 2563 | * any strong RTL character, otherwise it is LTR if it contains any strong LTR characters. |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 2564 | * If there are neither, the paragraph direction is the view's resolved layout direction. |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2565 | * |
| 2566 | * @hide |
| 2567 | */ |
| 2568 | public static final int TEXT_DIRECTION_ANY_RTL = 2; |
| 2569 | |
| 2570 | /** |
| 2571 | * Text direction is forced to LTR. |
| 2572 | * |
| 2573 | * @hide |
| 2574 | */ |
Fabrice Di Meglio | e3bf88d | 2011-09-06 11:08:45 -0700 | [diff] [blame^] | 2575 | public static final int TEXT_DIRECTION_LTR = 3; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2576 | |
| 2577 | /** |
| 2578 | * Text direction is forced to RTL. |
| 2579 | * |
| 2580 | * @hide |
| 2581 | */ |
Fabrice Di Meglio | e3bf88d | 2011-09-06 11:08:45 -0700 | [diff] [blame^] | 2582 | public static final int TEXT_DIRECTION_RTL = 4; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2583 | |
| 2584 | /** |
| 2585 | * Default text direction is inherited |
| 2586 | */ |
| 2587 | protected static int DEFAULT_TEXT_DIRECTION = TEXT_DIRECTION_INHERIT; |
| 2588 | |
| 2589 | /** |
| 2590 | * The text direction that has been defined by {@link #setTextDirection(int)}. |
| 2591 | * |
| 2592 | * {@hide} |
| 2593 | */ |
| 2594 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2595 | @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), |
| 2596 | @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), |
| 2597 | @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), |
| 2598 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), |
| 2599 | @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL") |
| 2600 | }) |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 2601 | private int mTextDirection = DEFAULT_TEXT_DIRECTION; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2602 | |
| 2603 | /** |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 2604 | * The resolved text direction. This needs resolution if the value is |
| 2605 | * TEXT_DIRECTION_INHERIT. The resolution matches mTextDirection if that is |
| 2606 | * not TEXT_DIRECTION_INHERIT, otherwise resolution proceeds up the parent |
| 2607 | * chain of the view. |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2608 | * |
| 2609 | * {@hide} |
| 2610 | */ |
| 2611 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 2612 | @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), |
| 2613 | @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), |
| 2614 | @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2615 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), |
| 2616 | @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL") |
| 2617 | }) |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 2618 | private int mResolvedTextDirection = TEXT_DIRECTION_INHERIT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2619 | |
| 2620 | /** |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 2621 | * Consistency verifier for debugging purposes. |
| 2622 | * @hide |
| 2623 | */ |
| 2624 | protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = |
| 2625 | InputEventConsistencyVerifier.isInstrumentationEnabled() ? |
| 2626 | new InputEventConsistencyVerifier(this, 0) : null; |
| 2627 | |
| 2628 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2629 | * Simple constructor to use when creating a view from code. |
| 2630 | * |
| 2631 | * @param context The Context the view is running in, through which it can |
| 2632 | * access the current theme, resources, etc. |
| 2633 | */ |
| 2634 | public View(Context context) { |
| 2635 | mContext = context; |
| 2636 | mResources = context != null ? context.getResources() : null; |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 2637 | mViewFlags = SOUND_EFFECTS_ENABLED | HAPTIC_FEEDBACK_ENABLED | LAYOUT_DIRECTION_INHERIT; |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2638 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2639 | setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS); |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 2640 | mUserPaddingStart = -1; |
| 2641 | mUserPaddingEnd = -1; |
| 2642 | mUserPaddingRelative = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | /** |
| 2646 | * Constructor that is called when inflating a view from XML. This is called |
| 2647 | * when a view is being constructed from an XML file, supplying attributes |
| 2648 | * that were specified in the XML file. This version uses a default style of |
| 2649 | * 0, so the only attribute values applied are those in the Context's Theme |
| 2650 | * and the given AttributeSet. |
| 2651 | * |
| 2652 | * <p> |
| 2653 | * The method onFinishInflate() will be called after all children have been |
| 2654 | * added. |
| 2655 | * |
| 2656 | * @param context The Context the view is running in, through which it can |
| 2657 | * access the current theme, resources, etc. |
| 2658 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 2659 | * @see #View(Context, AttributeSet, int) |
| 2660 | */ |
| 2661 | public View(Context context, AttributeSet attrs) { |
| 2662 | this(context, attrs, 0); |
| 2663 | } |
| 2664 | |
| 2665 | /** |
| 2666 | * Perform inflation from XML and apply a class-specific base style. This |
| 2667 | * constructor of View allows subclasses to use their own base style when |
| 2668 | * they are inflating. For example, a Button class's constructor would call |
| 2669 | * this version of the super class constructor and supply |
| 2670 | * <code>R.attr.buttonStyle</code> for <var>defStyle</var>; this allows |
| 2671 | * the theme's button style to modify all of the base view attributes (in |
| 2672 | * particular its background) as well as the Button class's attributes. |
| 2673 | * |
| 2674 | * @param context The Context the view is running in, through which it can |
| 2675 | * access the current theme, resources, etc. |
| 2676 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 2677 | * @param defStyle The default style to apply to this view. If 0, no style |
| 2678 | * will be applied (beyond what is included in the theme). This may |
| 2679 | * either be an attribute resource, whose value will be retrieved |
| 2680 | * from the current theme, or an explicit style resource. |
| 2681 | * @see #View(Context, AttributeSet) |
| 2682 | */ |
| 2683 | public View(Context context, AttributeSet attrs, int defStyle) { |
| 2684 | this(context); |
| 2685 | |
| 2686 | TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View, |
| 2687 | defStyle, 0); |
| 2688 | |
| 2689 | Drawable background = null; |
| 2690 | |
| 2691 | int leftPadding = -1; |
| 2692 | int topPadding = -1; |
| 2693 | int rightPadding = -1; |
| 2694 | int bottomPadding = -1; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 2695 | int startPadding = -1; |
| 2696 | int endPadding = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2697 | |
| 2698 | int padding = -1; |
| 2699 | |
| 2700 | int viewFlagValues = 0; |
| 2701 | int viewFlagMasks = 0; |
| 2702 | |
| 2703 | boolean setScrollContainer = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2704 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2705 | int x = 0; |
| 2706 | int y = 0; |
| 2707 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 2708 | float tx = 0; |
| 2709 | float ty = 0; |
| 2710 | float rotation = 0; |
| 2711 | float rotationX = 0; |
| 2712 | float rotationY = 0; |
| 2713 | float sx = 1f; |
| 2714 | float sy = 1f; |
| 2715 | boolean transformSet = false; |
| 2716 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2717 | int scrollbarStyle = SCROLLBARS_INSIDE_OVERLAY; |
| 2718 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2719 | int overScrollMode = mOverScrollMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2720 | final int N = a.getIndexCount(); |
| 2721 | for (int i = 0; i < N; i++) { |
| 2722 | int attr = a.getIndex(i); |
| 2723 | switch (attr) { |
| 2724 | case com.android.internal.R.styleable.View_background: |
| 2725 | background = a.getDrawable(attr); |
| 2726 | break; |
| 2727 | case com.android.internal.R.styleable.View_padding: |
| 2728 | padding = a.getDimensionPixelSize(attr, -1); |
| 2729 | break; |
| 2730 | case com.android.internal.R.styleable.View_paddingLeft: |
| 2731 | leftPadding = a.getDimensionPixelSize(attr, -1); |
| 2732 | break; |
| 2733 | case com.android.internal.R.styleable.View_paddingTop: |
| 2734 | topPadding = a.getDimensionPixelSize(attr, -1); |
| 2735 | break; |
| 2736 | case com.android.internal.R.styleable.View_paddingRight: |
| 2737 | rightPadding = a.getDimensionPixelSize(attr, -1); |
| 2738 | break; |
| 2739 | case com.android.internal.R.styleable.View_paddingBottom: |
| 2740 | bottomPadding = a.getDimensionPixelSize(attr, -1); |
| 2741 | break; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 2742 | case com.android.internal.R.styleable.View_paddingStart: |
| 2743 | startPadding = a.getDimensionPixelSize(attr, -1); |
| 2744 | break; |
| 2745 | case com.android.internal.R.styleable.View_paddingEnd: |
| 2746 | endPadding = a.getDimensionPixelSize(attr, -1); |
| 2747 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2748 | case com.android.internal.R.styleable.View_scrollX: |
| 2749 | x = a.getDimensionPixelOffset(attr, 0); |
| 2750 | break; |
| 2751 | case com.android.internal.R.styleable.View_scrollY: |
| 2752 | y = a.getDimensionPixelOffset(attr, 0); |
| 2753 | break; |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 2754 | case com.android.internal.R.styleable.View_alpha: |
| 2755 | setAlpha(a.getFloat(attr, 1f)); |
| 2756 | break; |
| 2757 | case com.android.internal.R.styleable.View_transformPivotX: |
| 2758 | setPivotX(a.getDimensionPixelOffset(attr, 0)); |
| 2759 | break; |
| 2760 | case com.android.internal.R.styleable.View_transformPivotY: |
| 2761 | setPivotY(a.getDimensionPixelOffset(attr, 0)); |
| 2762 | break; |
| 2763 | case com.android.internal.R.styleable.View_translationX: |
| 2764 | tx = a.getDimensionPixelOffset(attr, 0); |
| 2765 | transformSet = true; |
| 2766 | break; |
| 2767 | case com.android.internal.R.styleable.View_translationY: |
| 2768 | ty = a.getDimensionPixelOffset(attr, 0); |
| 2769 | transformSet = true; |
| 2770 | break; |
| 2771 | case com.android.internal.R.styleable.View_rotation: |
| 2772 | rotation = a.getFloat(attr, 0); |
| 2773 | transformSet = true; |
| 2774 | break; |
| 2775 | case com.android.internal.R.styleable.View_rotationX: |
| 2776 | rotationX = a.getFloat(attr, 0); |
| 2777 | transformSet = true; |
| 2778 | break; |
| 2779 | case com.android.internal.R.styleable.View_rotationY: |
| 2780 | rotationY = a.getFloat(attr, 0); |
| 2781 | transformSet = true; |
| 2782 | break; |
| 2783 | case com.android.internal.R.styleable.View_scaleX: |
| 2784 | sx = a.getFloat(attr, 1f); |
| 2785 | transformSet = true; |
| 2786 | break; |
| 2787 | case com.android.internal.R.styleable.View_scaleY: |
| 2788 | sy = a.getFloat(attr, 1f); |
| 2789 | transformSet = true; |
| 2790 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2791 | case com.android.internal.R.styleable.View_id: |
| 2792 | mID = a.getResourceId(attr, NO_ID); |
| 2793 | break; |
| 2794 | case com.android.internal.R.styleable.View_tag: |
| 2795 | mTag = a.getText(attr); |
| 2796 | break; |
| 2797 | case com.android.internal.R.styleable.View_fitsSystemWindows: |
| 2798 | if (a.getBoolean(attr, false)) { |
| 2799 | viewFlagValues |= FITS_SYSTEM_WINDOWS; |
| 2800 | viewFlagMasks |= FITS_SYSTEM_WINDOWS; |
| 2801 | } |
| 2802 | break; |
| 2803 | case com.android.internal.R.styleable.View_focusable: |
| 2804 | if (a.getBoolean(attr, false)) { |
| 2805 | viewFlagValues |= FOCUSABLE; |
| 2806 | viewFlagMasks |= FOCUSABLE_MASK; |
| 2807 | } |
| 2808 | break; |
| 2809 | case com.android.internal.R.styleable.View_focusableInTouchMode: |
| 2810 | if (a.getBoolean(attr, false)) { |
| 2811 | viewFlagValues |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE; |
| 2812 | viewFlagMasks |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE_MASK; |
| 2813 | } |
| 2814 | break; |
| 2815 | case com.android.internal.R.styleable.View_clickable: |
| 2816 | if (a.getBoolean(attr, false)) { |
| 2817 | viewFlagValues |= CLICKABLE; |
| 2818 | viewFlagMasks |= CLICKABLE; |
| 2819 | } |
| 2820 | break; |
| 2821 | case com.android.internal.R.styleable.View_longClickable: |
| 2822 | if (a.getBoolean(attr, false)) { |
| 2823 | viewFlagValues |= LONG_CLICKABLE; |
| 2824 | viewFlagMasks |= LONG_CLICKABLE; |
| 2825 | } |
| 2826 | break; |
| 2827 | case com.android.internal.R.styleable.View_saveEnabled: |
| 2828 | if (!a.getBoolean(attr, true)) { |
| 2829 | viewFlagValues |= SAVE_DISABLED; |
| 2830 | viewFlagMasks |= SAVE_DISABLED_MASK; |
| 2831 | } |
| 2832 | break; |
| 2833 | case com.android.internal.R.styleable.View_duplicateParentState: |
| 2834 | if (a.getBoolean(attr, false)) { |
| 2835 | viewFlagValues |= DUPLICATE_PARENT_STATE; |
| 2836 | viewFlagMasks |= DUPLICATE_PARENT_STATE; |
| 2837 | } |
| 2838 | break; |
| 2839 | case com.android.internal.R.styleable.View_visibility: |
| 2840 | final int visibility = a.getInt(attr, 0); |
| 2841 | if (visibility != 0) { |
| 2842 | viewFlagValues |= VISIBILITY_FLAGS[visibility]; |
| 2843 | viewFlagMasks |= VISIBILITY_MASK; |
| 2844 | } |
| 2845 | break; |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 2846 | case com.android.internal.R.styleable.View_layoutDirection: |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 2847 | // Clear any HORIZONTAL_DIRECTION flag already set |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 2848 | viewFlagValues &= ~LAYOUT_DIRECTION_MASK; |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 2849 | // Set the HORIZONTAL_DIRECTION flags depending on the value of the attribute |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 2850 | final int layoutDirection = a.getInt(attr, -1); |
| 2851 | if (layoutDirection != -1) { |
| 2852 | viewFlagValues |= LAYOUT_DIRECTION_FLAGS[layoutDirection]; |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 2853 | } else { |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 2854 | // Set to default (LAYOUT_DIRECTION_INHERIT) |
| 2855 | viewFlagValues |= LAYOUT_DIRECTION_DEFAULT; |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 2856 | } |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 2857 | viewFlagMasks |= LAYOUT_DIRECTION_MASK; |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 2858 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2859 | case com.android.internal.R.styleable.View_drawingCacheQuality: |
| 2860 | final int cacheQuality = a.getInt(attr, 0); |
| 2861 | if (cacheQuality != 0) { |
| 2862 | viewFlagValues |= DRAWING_CACHE_QUALITY_FLAGS[cacheQuality]; |
| 2863 | viewFlagMasks |= DRAWING_CACHE_QUALITY_MASK; |
| 2864 | } |
| 2865 | break; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2866 | case com.android.internal.R.styleable.View_contentDescription: |
| 2867 | mContentDescription = a.getString(attr); |
| 2868 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2869 | case com.android.internal.R.styleable.View_soundEffectsEnabled: |
| 2870 | if (!a.getBoolean(attr, true)) { |
| 2871 | viewFlagValues &= ~SOUND_EFFECTS_ENABLED; |
| 2872 | viewFlagMasks |= SOUND_EFFECTS_ENABLED; |
| 2873 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 2874 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2875 | case com.android.internal.R.styleable.View_hapticFeedbackEnabled: |
| 2876 | if (!a.getBoolean(attr, true)) { |
| 2877 | viewFlagValues &= ~HAPTIC_FEEDBACK_ENABLED; |
| 2878 | viewFlagMasks |= HAPTIC_FEEDBACK_ENABLED; |
| 2879 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 2880 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2881 | case R.styleable.View_scrollbars: |
| 2882 | final int scrollbars = a.getInt(attr, SCROLLBARS_NONE); |
| 2883 | if (scrollbars != SCROLLBARS_NONE) { |
| 2884 | viewFlagValues |= scrollbars; |
| 2885 | viewFlagMasks |= SCROLLBARS_MASK; |
| 2886 | initializeScrollbars(a); |
| 2887 | } |
| 2888 | break; |
| 2889 | case R.styleable.View_fadingEdge: |
| 2890 | final int fadingEdge = a.getInt(attr, FADING_EDGE_NONE); |
| 2891 | if (fadingEdge != FADING_EDGE_NONE) { |
| 2892 | viewFlagValues |= fadingEdge; |
| 2893 | viewFlagMasks |= FADING_EDGE_MASK; |
| 2894 | initializeFadingEdge(a); |
| 2895 | } |
| 2896 | break; |
| 2897 | case R.styleable.View_scrollbarStyle: |
| 2898 | scrollbarStyle = a.getInt(attr, SCROLLBARS_INSIDE_OVERLAY); |
| 2899 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 2900 | viewFlagValues |= scrollbarStyle & SCROLLBARS_STYLE_MASK; |
| 2901 | viewFlagMasks |= SCROLLBARS_STYLE_MASK; |
| 2902 | } |
| 2903 | break; |
| 2904 | case R.styleable.View_isScrollContainer: |
| 2905 | setScrollContainer = true; |
| 2906 | if (a.getBoolean(attr, false)) { |
| 2907 | setScrollContainer(true); |
| 2908 | } |
| 2909 | break; |
| 2910 | case com.android.internal.R.styleable.View_keepScreenOn: |
| 2911 | if (a.getBoolean(attr, false)) { |
| 2912 | viewFlagValues |= KEEP_SCREEN_ON; |
| 2913 | viewFlagMasks |= KEEP_SCREEN_ON; |
| 2914 | } |
| 2915 | break; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 2916 | case R.styleable.View_filterTouchesWhenObscured: |
| 2917 | if (a.getBoolean(attr, false)) { |
| 2918 | viewFlagValues |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 2919 | viewFlagMasks |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 2920 | } |
| 2921 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2922 | case R.styleable.View_nextFocusLeft: |
| 2923 | mNextFocusLeftId = a.getResourceId(attr, View.NO_ID); |
| 2924 | break; |
| 2925 | case R.styleable.View_nextFocusRight: |
| 2926 | mNextFocusRightId = a.getResourceId(attr, View.NO_ID); |
| 2927 | break; |
| 2928 | case R.styleable.View_nextFocusUp: |
| 2929 | mNextFocusUpId = a.getResourceId(attr, View.NO_ID); |
| 2930 | break; |
| 2931 | case R.styleable.View_nextFocusDown: |
| 2932 | mNextFocusDownId = a.getResourceId(attr, View.NO_ID); |
| 2933 | break; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 2934 | case R.styleable.View_nextFocusForward: |
| 2935 | mNextFocusForwardId = a.getResourceId(attr, View.NO_ID); |
| 2936 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2937 | case R.styleable.View_minWidth: |
| 2938 | mMinWidth = a.getDimensionPixelSize(attr, 0); |
| 2939 | break; |
| 2940 | case R.styleable.View_minHeight: |
| 2941 | mMinHeight = a.getDimensionPixelSize(attr, 0); |
| 2942 | break; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 2943 | case R.styleable.View_onClick: |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 2944 | if (context.isRestricted()) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2945 | throw new IllegalStateException("The android:onClick attribute cannot " |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 2946 | + "be used within a restricted context"); |
| 2947 | } |
| 2948 | |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 2949 | final String handlerName = a.getString(attr); |
| 2950 | if (handlerName != null) { |
| 2951 | setOnClickListener(new OnClickListener() { |
| 2952 | private Method mHandler; |
| 2953 | |
| 2954 | public void onClick(View v) { |
| 2955 | if (mHandler == null) { |
| 2956 | try { |
| 2957 | mHandler = getContext().getClass().getMethod(handlerName, |
| 2958 | View.class); |
| 2959 | } catch (NoSuchMethodException e) { |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 2960 | int id = getId(); |
| 2961 | String idText = id == NO_ID ? "" : " with id '" |
| 2962 | + getContext().getResources().getResourceEntryName( |
| 2963 | id) + "'"; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 2964 | throw new IllegalStateException("Could not find a method " + |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 2965 | handlerName + "(View) in the activity " |
| 2966 | + getContext().getClass() + " for onClick handler" |
| 2967 | + " on view " + View.this.getClass() + idText, e); |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 2968 | } |
| 2969 | } |
| 2970 | |
| 2971 | try { |
| 2972 | mHandler.invoke(getContext(), View.this); |
| 2973 | } catch (IllegalAccessException e) { |
| 2974 | throw new IllegalStateException("Could not execute non " |
| 2975 | + "public method of the activity", e); |
| 2976 | } catch (InvocationTargetException e) { |
| 2977 | throw new IllegalStateException("Could not execute " |
| 2978 | + "method of the activity", e); |
| 2979 | } |
| 2980 | } |
| 2981 | }); |
| 2982 | } |
| 2983 | break; |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2984 | case R.styleable.View_overScrollMode: |
| 2985 | overScrollMode = a.getInt(attr, OVER_SCROLL_IF_CONTENT_SCROLLS); |
| 2986 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2987 | case R.styleable.View_verticalScrollbarPosition: |
| 2988 | mVerticalScrollbarPosition = a.getInt(attr, SCROLLBAR_POSITION_DEFAULT); |
| 2989 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2990 | case R.styleable.View_layerType: |
| 2991 | setLayerType(a.getInt(attr, LAYER_TYPE_NONE), null); |
| 2992 | break; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2993 | case R.styleable.View_textDirection: |
| 2994 | mTextDirection = a.getInt(attr, DEFAULT_TEXT_DIRECTION); |
| 2995 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2996 | } |
| 2997 | } |
| 2998 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2999 | setOverScrollMode(overScrollMode); |
| 3000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3001 | if (background != null) { |
| 3002 | setBackgroundDrawable(background); |
| 3003 | } |
| 3004 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3005 | mUserPaddingRelative = (startPadding >= 0 || endPadding >= 0); |
| 3006 | |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 3007 | // Cache user padding as we cannot fully resolve padding here (we dont have yet the resolved |
| 3008 | // layout direction). Those cached values will be used later during padding resolution. |
| 3009 | mUserPaddingStart = startPadding; |
| 3010 | mUserPaddingEnd = endPadding; |
| 3011 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3012 | if (padding >= 0) { |
| 3013 | leftPadding = padding; |
| 3014 | topPadding = padding; |
| 3015 | rightPadding = padding; |
| 3016 | bottomPadding = padding; |
| 3017 | } |
| 3018 | |
| 3019 | // If the user specified the padding (either with android:padding or |
| 3020 | // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise |
| 3021 | // use the default padding or the padding from the background drawable |
| 3022 | // (stored at this point in mPadding*) |
| 3023 | setPadding(leftPadding >= 0 ? leftPadding : mPaddingLeft, |
| 3024 | topPadding >= 0 ? topPadding : mPaddingTop, |
| 3025 | rightPadding >= 0 ? rightPadding : mPaddingRight, |
| 3026 | bottomPadding >= 0 ? bottomPadding : mPaddingBottom); |
| 3027 | |
| 3028 | if (viewFlagMasks != 0) { |
| 3029 | setFlags(viewFlagValues, viewFlagMasks); |
| 3030 | } |
| 3031 | |
| 3032 | // Needs to be called after mViewFlags is set |
| 3033 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3034 | recomputePadding(); |
| 3035 | } |
| 3036 | |
| 3037 | if (x != 0 || y != 0) { |
| 3038 | scrollTo(x, y); |
| 3039 | } |
| 3040 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3041 | if (transformSet) { |
| 3042 | setTranslationX(tx); |
| 3043 | setTranslationY(ty); |
| 3044 | setRotation(rotation); |
| 3045 | setRotationX(rotationX); |
| 3046 | setRotationY(rotationY); |
| 3047 | setScaleX(sx); |
| 3048 | setScaleY(sy); |
| 3049 | } |
| 3050 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3051 | if (!setScrollContainer && (viewFlagValues&SCROLLBARS_VERTICAL) != 0) { |
| 3052 | setScrollContainer(true); |
| 3053 | } |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 3054 | |
| 3055 | computeOpaqueFlags(); |
| 3056 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3057 | a.recycle(); |
| 3058 | } |
| 3059 | |
| 3060 | /** |
| 3061 | * Non-public constructor for use in testing |
| 3062 | */ |
| 3063 | View() { |
| 3064 | } |
| 3065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3066 | /** |
| 3067 | * <p> |
| 3068 | * Initializes the fading edges from a given set of styled attributes. This |
| 3069 | * method should be called by subclasses that need fading edges and when an |
| 3070 | * instance of these subclasses is created programmatically rather than |
| 3071 | * being inflated from XML. This method is automatically called when the XML |
| 3072 | * is inflated. |
| 3073 | * </p> |
| 3074 | * |
| 3075 | * @param a the styled attributes set to initialize the fading edges from |
| 3076 | */ |
| 3077 | protected void initializeFadingEdge(TypedArray a) { |
| 3078 | initScrollCache(); |
| 3079 | |
| 3080 | mScrollCache.fadingEdgeLength = a.getDimensionPixelSize( |
| 3081 | R.styleable.View_fadingEdgeLength, |
| 3082 | ViewConfiguration.get(mContext).getScaledFadingEdgeLength()); |
| 3083 | } |
| 3084 | |
| 3085 | /** |
| 3086 | * Returns the size of the vertical faded edges used to indicate that more |
| 3087 | * content in this view is visible. |
| 3088 | * |
| 3089 | * @return The size in pixels of the vertical faded edge or 0 if vertical |
| 3090 | * faded edges are not enabled for this view. |
| 3091 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3092 | */ |
| 3093 | public int getVerticalFadingEdgeLength() { |
| 3094 | if (isVerticalFadingEdgeEnabled()) { |
| 3095 | ScrollabilityCache cache = mScrollCache; |
| 3096 | if (cache != null) { |
| 3097 | return cache.fadingEdgeLength; |
| 3098 | } |
| 3099 | } |
| 3100 | return 0; |
| 3101 | } |
| 3102 | |
| 3103 | /** |
| 3104 | * Set the size of the faded edge used to indicate that more content in this |
| 3105 | * 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] | 3106 | * {@link #setVerticalFadingEdgeEnabled(boolean)} or |
| 3107 | * {@link #setHorizontalFadingEdgeEnabled(boolean)} to enable the fading edge |
| 3108 | * for the vertical or horizontal fading edges. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3109 | * |
| 3110 | * @param length The size in pixels of the faded edge used to indicate that more |
| 3111 | * content in this view is visible. |
| 3112 | */ |
| 3113 | public void setFadingEdgeLength(int length) { |
| 3114 | initScrollCache(); |
| 3115 | mScrollCache.fadingEdgeLength = length; |
| 3116 | } |
| 3117 | |
| 3118 | /** |
| 3119 | * Returns the size of the horizontal faded edges used to indicate that more |
| 3120 | * content in this view is visible. |
| 3121 | * |
| 3122 | * @return The size in pixels of the horizontal faded edge or 0 if horizontal |
| 3123 | * faded edges are not enabled for this view. |
| 3124 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3125 | */ |
| 3126 | public int getHorizontalFadingEdgeLength() { |
| 3127 | if (isHorizontalFadingEdgeEnabled()) { |
| 3128 | ScrollabilityCache cache = mScrollCache; |
| 3129 | if (cache != null) { |
| 3130 | return cache.fadingEdgeLength; |
| 3131 | } |
| 3132 | } |
| 3133 | return 0; |
| 3134 | } |
| 3135 | |
| 3136 | /** |
| 3137 | * Returns the width of the vertical scrollbar. |
| 3138 | * |
| 3139 | * @return The width in pixels of the vertical scrollbar or 0 if there |
| 3140 | * is no vertical scrollbar. |
| 3141 | */ |
| 3142 | public int getVerticalScrollbarWidth() { |
| 3143 | ScrollabilityCache cache = mScrollCache; |
| 3144 | if (cache != null) { |
| 3145 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3146 | if (scrollBar != null) { |
| 3147 | int size = scrollBar.getSize(true); |
| 3148 | if (size <= 0) { |
| 3149 | size = cache.scrollBarSize; |
| 3150 | } |
| 3151 | return size; |
| 3152 | } |
| 3153 | return 0; |
| 3154 | } |
| 3155 | return 0; |
| 3156 | } |
| 3157 | |
| 3158 | /** |
| 3159 | * Returns the height of the horizontal scrollbar. |
| 3160 | * |
| 3161 | * @return The height in pixels of the horizontal scrollbar or 0 if |
| 3162 | * there is no horizontal scrollbar. |
| 3163 | */ |
| 3164 | protected int getHorizontalScrollbarHeight() { |
| 3165 | ScrollabilityCache cache = mScrollCache; |
| 3166 | if (cache != null) { |
| 3167 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3168 | if (scrollBar != null) { |
| 3169 | int size = scrollBar.getSize(false); |
| 3170 | if (size <= 0) { |
| 3171 | size = cache.scrollBarSize; |
| 3172 | } |
| 3173 | return size; |
| 3174 | } |
| 3175 | return 0; |
| 3176 | } |
| 3177 | return 0; |
| 3178 | } |
| 3179 | |
| 3180 | /** |
| 3181 | * <p> |
| 3182 | * Initializes the scrollbars from a given set of styled attributes. This |
| 3183 | * method should be called by subclasses that need scrollbars and when an |
| 3184 | * instance of these subclasses is created programmatically rather than |
| 3185 | * being inflated from XML. This method is automatically called when the XML |
| 3186 | * is inflated. |
| 3187 | * </p> |
| 3188 | * |
| 3189 | * @param a the styled attributes set to initialize the scrollbars from |
| 3190 | */ |
| 3191 | protected void initializeScrollbars(TypedArray a) { |
| 3192 | initScrollCache(); |
| 3193 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3194 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3195 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3196 | if (scrollabilityCache.scrollBar == null) { |
| 3197 | scrollabilityCache.scrollBar = new ScrollBarDrawable(); |
| 3198 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3199 | |
Romain Guy | 8bda248 | 2010-03-02 11:42:11 -0800 | [diff] [blame] | 3200 | 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] | 3201 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3202 | if (!fadeScrollbars) { |
| 3203 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 3204 | } |
| 3205 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3206 | |
| 3207 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3208 | scrollabilityCache.scrollBarFadeDuration = a.getInt( |
| 3209 | R.styleable.View_scrollbarFadeDuration, ViewConfiguration |
| 3210 | .getScrollBarFadeDuration()); |
| 3211 | scrollabilityCache.scrollBarDefaultDelayBeforeFade = a.getInt( |
| 3212 | R.styleable.View_scrollbarDefaultDelayBeforeFade, |
| 3213 | ViewConfiguration.getScrollDefaultDelay()); |
| 3214 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3215 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3216 | scrollabilityCache.scrollBarSize = a.getDimensionPixelSize( |
| 3217 | com.android.internal.R.styleable.View_scrollbarSize, |
| 3218 | ViewConfiguration.get(mContext).getScaledScrollBarSize()); |
| 3219 | |
| 3220 | Drawable track = a.getDrawable(R.styleable.View_scrollbarTrackHorizontal); |
| 3221 | scrollabilityCache.scrollBar.setHorizontalTrackDrawable(track); |
| 3222 | |
| 3223 | Drawable thumb = a.getDrawable(R.styleable.View_scrollbarThumbHorizontal); |
| 3224 | if (thumb != null) { |
| 3225 | scrollabilityCache.scrollBar.setHorizontalThumbDrawable(thumb); |
| 3226 | } |
| 3227 | |
| 3228 | boolean alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawHorizontalTrack, |
| 3229 | false); |
| 3230 | if (alwaysDraw) { |
| 3231 | scrollabilityCache.scrollBar.setAlwaysDrawHorizontalTrack(true); |
| 3232 | } |
| 3233 | |
| 3234 | track = a.getDrawable(R.styleable.View_scrollbarTrackVertical); |
| 3235 | scrollabilityCache.scrollBar.setVerticalTrackDrawable(track); |
| 3236 | |
| 3237 | thumb = a.getDrawable(R.styleable.View_scrollbarThumbVertical); |
| 3238 | if (thumb != null) { |
| 3239 | scrollabilityCache.scrollBar.setVerticalThumbDrawable(thumb); |
| 3240 | } |
| 3241 | |
| 3242 | alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawVerticalTrack, |
| 3243 | false); |
| 3244 | if (alwaysDraw) { |
| 3245 | scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true); |
| 3246 | } |
| 3247 | |
| 3248 | // Re-apply user/background padding so that scrollbar(s) get added |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3249 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | /** |
| 3253 | * <p> |
| 3254 | * Initalizes the scrollability cache if necessary. |
| 3255 | * </p> |
| 3256 | */ |
| 3257 | private void initScrollCache() { |
| 3258 | if (mScrollCache == null) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3259 | mScrollCache = new ScrollabilityCache(ViewConfiguration.get(mContext), this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3260 | } |
| 3261 | } |
| 3262 | |
| 3263 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3264 | * Set the position of the vertical scroll bar. Should be one of |
| 3265 | * {@link #SCROLLBAR_POSITION_DEFAULT}, {@link #SCROLLBAR_POSITION_LEFT} or |
| 3266 | * {@link #SCROLLBAR_POSITION_RIGHT}. |
| 3267 | * |
| 3268 | * @param position Where the vertical scroll bar should be positioned. |
| 3269 | */ |
| 3270 | public void setVerticalScrollbarPosition(int position) { |
| 3271 | if (mVerticalScrollbarPosition != position) { |
| 3272 | mVerticalScrollbarPosition = position; |
| 3273 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3274 | resolvePadding(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3275 | } |
| 3276 | } |
| 3277 | |
| 3278 | /** |
| 3279 | * @return The position where the vertical scroll bar will show, if applicable. |
| 3280 | * @see #setVerticalScrollbarPosition(int) |
| 3281 | */ |
| 3282 | public int getVerticalScrollbarPosition() { |
| 3283 | return mVerticalScrollbarPosition; |
| 3284 | } |
| 3285 | |
| 3286 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3287 | * Register a callback to be invoked when focus of this view changed. |
| 3288 | * |
| 3289 | * @param l The callback that will run. |
| 3290 | */ |
| 3291 | public void setOnFocusChangeListener(OnFocusChangeListener l) { |
| 3292 | mOnFocusChangeListener = l; |
| 3293 | } |
| 3294 | |
| 3295 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3296 | * Add a listener that will be called when the bounds of the view change due to |
| 3297 | * layout processing. |
| 3298 | * |
| 3299 | * @param listener The listener that will be called when layout bounds change. |
| 3300 | */ |
| 3301 | public void addOnLayoutChangeListener(OnLayoutChangeListener listener) { |
| 3302 | if (mOnLayoutChangeListeners == null) { |
| 3303 | mOnLayoutChangeListeners = new ArrayList<OnLayoutChangeListener>(); |
| 3304 | } |
| 3305 | mOnLayoutChangeListeners.add(listener); |
| 3306 | } |
| 3307 | |
| 3308 | /** |
| 3309 | * Remove a listener for layout changes. |
| 3310 | * |
| 3311 | * @param listener The listener for layout bounds change. |
| 3312 | */ |
| 3313 | public void removeOnLayoutChangeListener(OnLayoutChangeListener listener) { |
| 3314 | if (mOnLayoutChangeListeners == null) { |
| 3315 | return; |
| 3316 | } |
| 3317 | mOnLayoutChangeListeners.remove(listener); |
| 3318 | } |
| 3319 | |
| 3320 | /** |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3321 | * Add a listener for attach state changes. |
| 3322 | * |
| 3323 | * This listener will be called whenever this view is attached or detached |
| 3324 | * from a window. Remove the listener using |
| 3325 | * {@link #removeOnAttachStateChangeListener(OnAttachStateChangeListener)}. |
| 3326 | * |
| 3327 | * @param listener Listener to attach |
| 3328 | * @see #removeOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 3329 | */ |
| 3330 | public void addOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
| 3331 | if (mOnAttachStateChangeListeners == null) { |
| 3332 | mOnAttachStateChangeListeners = new CopyOnWriteArrayList<OnAttachStateChangeListener>(); |
| 3333 | } |
| 3334 | mOnAttachStateChangeListeners.add(listener); |
| 3335 | } |
| 3336 | |
| 3337 | /** |
| 3338 | * Remove a listener for attach state changes. The listener will receive no further |
| 3339 | * notification of window attach/detach events. |
| 3340 | * |
| 3341 | * @param listener Listener to remove |
| 3342 | * @see #addOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 3343 | */ |
| 3344 | public void removeOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
| 3345 | if (mOnAttachStateChangeListeners == null) { |
| 3346 | return; |
| 3347 | } |
| 3348 | mOnAttachStateChangeListeners.remove(listener); |
| 3349 | } |
| 3350 | |
| 3351 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3352 | * Returns the focus-change callback registered for this view. |
| 3353 | * |
| 3354 | * @return The callback, or null if one is not registered. |
| 3355 | */ |
| 3356 | public OnFocusChangeListener getOnFocusChangeListener() { |
| 3357 | return mOnFocusChangeListener; |
| 3358 | } |
| 3359 | |
| 3360 | /** |
| 3361 | * Register a callback to be invoked when this view is clicked. If this view is not |
| 3362 | * clickable, it becomes clickable. |
| 3363 | * |
| 3364 | * @param l The callback that will run |
| 3365 | * |
| 3366 | * @see #setClickable(boolean) |
| 3367 | */ |
| 3368 | public void setOnClickListener(OnClickListener l) { |
| 3369 | if (!isClickable()) { |
| 3370 | setClickable(true); |
| 3371 | } |
| 3372 | mOnClickListener = l; |
| 3373 | } |
| 3374 | |
| 3375 | /** |
| 3376 | * Register a callback to be invoked when this view is clicked and held. If this view is not |
| 3377 | * long clickable, it becomes long clickable. |
| 3378 | * |
| 3379 | * @param l The callback that will run |
| 3380 | * |
| 3381 | * @see #setLongClickable(boolean) |
| 3382 | */ |
| 3383 | public void setOnLongClickListener(OnLongClickListener l) { |
| 3384 | if (!isLongClickable()) { |
| 3385 | setLongClickable(true); |
| 3386 | } |
| 3387 | mOnLongClickListener = l; |
| 3388 | } |
| 3389 | |
| 3390 | /** |
| 3391 | * Register a callback to be invoked when the context menu for this view is |
| 3392 | * being built. If this view is not long clickable, it becomes long clickable. |
| 3393 | * |
| 3394 | * @param l The callback that will run |
| 3395 | * |
| 3396 | */ |
| 3397 | public void setOnCreateContextMenuListener(OnCreateContextMenuListener l) { |
| 3398 | if (!isLongClickable()) { |
| 3399 | setLongClickable(true); |
| 3400 | } |
| 3401 | mOnCreateContextMenuListener = l; |
| 3402 | } |
| 3403 | |
| 3404 | /** |
| 3405 | * Call this view's OnClickListener, if it is defined. |
| 3406 | * |
| 3407 | * @return True there was an assigned OnClickListener that was called, false |
| 3408 | * otherwise is returned. |
| 3409 | */ |
| 3410 | public boolean performClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3411 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); |
| 3412 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3413 | if (mOnClickListener != null) { |
| 3414 | playSoundEffect(SoundEffectConstants.CLICK); |
| 3415 | mOnClickListener.onClick(this); |
| 3416 | return true; |
| 3417 | } |
| 3418 | |
| 3419 | return false; |
| 3420 | } |
| 3421 | |
| 3422 | /** |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 3423 | * Call this view's OnLongClickListener, if it is defined. Invokes the context menu if the |
| 3424 | * OnLongClickListener did not consume the event. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3425 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 3426 | * @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] | 3427 | */ |
| 3428 | public boolean performLongClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3429 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); |
| 3430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3431 | boolean handled = false; |
| 3432 | if (mOnLongClickListener != null) { |
| 3433 | handled = mOnLongClickListener.onLongClick(View.this); |
| 3434 | } |
| 3435 | if (!handled) { |
| 3436 | handled = showContextMenu(); |
| 3437 | } |
| 3438 | if (handled) { |
| 3439 | performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); |
| 3440 | } |
| 3441 | return handled; |
| 3442 | } |
| 3443 | |
| 3444 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3445 | * Performs button-related actions during a touch down event. |
| 3446 | * |
| 3447 | * @param event The event. |
| 3448 | * @return True if the down was consumed. |
| 3449 | * |
| 3450 | * @hide |
| 3451 | */ |
| 3452 | protected boolean performButtonActionOnTouchDown(MotionEvent event) { |
| 3453 | if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) { |
| 3454 | if (showContextMenu(event.getX(), event.getY(), event.getMetaState())) { |
| 3455 | return true; |
| 3456 | } |
| 3457 | } |
| 3458 | return false; |
| 3459 | } |
| 3460 | |
| 3461 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3462 | * Bring up the context menu for this view. |
| 3463 | * |
| 3464 | * @return Whether a context menu was displayed. |
| 3465 | */ |
| 3466 | public boolean showContextMenu() { |
| 3467 | return getParent().showContextMenuForChild(this); |
| 3468 | } |
| 3469 | |
| 3470 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3471 | * Bring up the context menu for this view, referring to the item under the specified point. |
| 3472 | * |
| 3473 | * @param x The referenced x coordinate. |
| 3474 | * @param y The referenced y coordinate. |
| 3475 | * @param metaState The keyboard modifiers that were pressed. |
| 3476 | * @return Whether a context menu was displayed. |
| 3477 | * |
| 3478 | * @hide |
| 3479 | */ |
| 3480 | public boolean showContextMenu(float x, float y, int metaState) { |
| 3481 | return showContextMenu(); |
| 3482 | } |
| 3483 | |
| 3484 | /** |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 3485 | * Start an action mode. |
| 3486 | * |
| 3487 | * @param callback Callback that will control the lifecycle of the action mode |
| 3488 | * @return The new action mode if it is started, null otherwise |
| 3489 | * |
| 3490 | * @see ActionMode |
| 3491 | */ |
| 3492 | public ActionMode startActionMode(ActionMode.Callback callback) { |
| 3493 | return getParent().startActionModeForChild(this, callback); |
| 3494 | } |
| 3495 | |
| 3496 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3497 | * Register a callback to be invoked when a key is pressed in this view. |
| 3498 | * @param l the key listener to attach to this view |
| 3499 | */ |
| 3500 | public void setOnKeyListener(OnKeyListener l) { |
| 3501 | mOnKeyListener = l; |
| 3502 | } |
| 3503 | |
| 3504 | /** |
| 3505 | * Register a callback to be invoked when a touch event is sent to this view. |
| 3506 | * @param l the touch listener to attach to this view |
| 3507 | */ |
| 3508 | public void setOnTouchListener(OnTouchListener l) { |
| 3509 | mOnTouchListener = l; |
| 3510 | } |
| 3511 | |
| 3512 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3513 | * Register a callback to be invoked when a generic motion event is sent to this view. |
| 3514 | * @param l the generic motion listener to attach to this view |
| 3515 | */ |
| 3516 | public void setOnGenericMotionListener(OnGenericMotionListener l) { |
| 3517 | mOnGenericMotionListener = l; |
| 3518 | } |
| 3519 | |
| 3520 | /** |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 3521 | * Register a callback to be invoked when a hover event is sent to this view. |
| 3522 | * @param l the hover listener to attach to this view |
| 3523 | */ |
| 3524 | public void setOnHoverListener(OnHoverListener l) { |
| 3525 | mOnHoverListener = l; |
| 3526 | } |
| 3527 | |
| 3528 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3529 | * Register a drag event listener callback object for this View. The parameter is |
| 3530 | * an implementation of {@link android.view.View.OnDragListener}. To send a drag event to a |
| 3531 | * View, the system calls the |
| 3532 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent)} method. |
| 3533 | * @param l An implementation of {@link android.view.View.OnDragListener}. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 3534 | */ |
| 3535 | public void setOnDragListener(OnDragListener l) { |
| 3536 | mOnDragListener = l; |
| 3537 | } |
| 3538 | |
| 3539 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 3540 | * Give this view focus. This will cause |
| 3541 | * {@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] | 3542 | * |
| 3543 | * Note: this does not check whether this {@link View} should get focus, it just |
| 3544 | * gives it focus no matter what. It should only be called internally by framework |
| 3545 | * code that knows what it is doing, namely {@link #requestFocus(int, Rect)}. |
| 3546 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 3547 | * @param direction values are {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN}, |
| 3548 | * {@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] | 3549 | * focus moved when requestFocus() is called. It may not always |
| 3550 | * apply, in which case use the default View.FOCUS_DOWN. |
| 3551 | * @param previouslyFocusedRect The rectangle of the view that had focus |
| 3552 | * prior in this View's coordinate system. |
| 3553 | */ |
| 3554 | void handleFocusGainInternal(int direction, Rect previouslyFocusedRect) { |
| 3555 | if (DBG) { |
| 3556 | System.out.println(this + " requestFocus()"); |
| 3557 | } |
| 3558 | |
| 3559 | if ((mPrivateFlags & FOCUSED) == 0) { |
| 3560 | mPrivateFlags |= FOCUSED; |
| 3561 | |
| 3562 | if (mParent != null) { |
| 3563 | mParent.requestChildFocus(this, this); |
| 3564 | } |
| 3565 | |
| 3566 | onFocusChanged(true, direction, previouslyFocusedRect); |
| 3567 | refreshDrawableState(); |
| 3568 | } |
| 3569 | } |
| 3570 | |
| 3571 | /** |
| 3572 | * Request that a rectangle of this view be visible on the screen, |
| 3573 | * scrolling if necessary just enough. |
| 3574 | * |
| 3575 | * <p>A View should call this if it maintains some notion of which part |
| 3576 | * of its content is interesting. For example, a text editing view |
| 3577 | * should call this when its cursor moves. |
| 3578 | * |
| 3579 | * @param rectangle The rectangle. |
| 3580 | * @return Whether any parent scrolled. |
| 3581 | */ |
| 3582 | public boolean requestRectangleOnScreen(Rect rectangle) { |
| 3583 | return requestRectangleOnScreen(rectangle, false); |
| 3584 | } |
| 3585 | |
| 3586 | /** |
| 3587 | * Request that a rectangle of this view be visible on the screen, |
| 3588 | * scrolling if necessary just enough. |
| 3589 | * |
| 3590 | * <p>A View should call this if it maintains some notion of which part |
| 3591 | * of its content is interesting. For example, a text editing view |
| 3592 | * should call this when its cursor moves. |
| 3593 | * |
| 3594 | * <p>When <code>immediate</code> is set to true, scrolling will not be |
| 3595 | * animated. |
| 3596 | * |
| 3597 | * @param rectangle The rectangle. |
| 3598 | * @param immediate True to forbid animated scrolling, false otherwise |
| 3599 | * @return Whether any parent scrolled. |
| 3600 | */ |
| 3601 | public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) { |
| 3602 | View child = this; |
| 3603 | ViewParent parent = mParent; |
| 3604 | boolean scrolled = false; |
| 3605 | while (parent != null) { |
| 3606 | scrolled |= parent.requestChildRectangleOnScreen(child, |
| 3607 | rectangle, immediate); |
| 3608 | |
| 3609 | // offset rect so next call has the rectangle in the |
| 3610 | // coordinate system of its direct child. |
| 3611 | rectangle.offset(child.getLeft(), child.getTop()); |
| 3612 | rectangle.offset(-child.getScrollX(), -child.getScrollY()); |
| 3613 | |
| 3614 | if (!(parent instanceof View)) { |
| 3615 | break; |
| 3616 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3617 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3618 | child = (View) parent; |
| 3619 | parent = child.getParent(); |
| 3620 | } |
| 3621 | return scrolled; |
| 3622 | } |
| 3623 | |
| 3624 | /** |
| 3625 | * Called when this view wants to give up focus. This will cause |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 3626 | * {@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] | 3627 | */ |
| 3628 | public void clearFocus() { |
| 3629 | if (DBG) { |
| 3630 | System.out.println(this + " clearFocus()"); |
| 3631 | } |
| 3632 | |
| 3633 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 3634 | mPrivateFlags &= ~FOCUSED; |
| 3635 | |
| 3636 | if (mParent != null) { |
| 3637 | mParent.clearChildFocus(this); |
| 3638 | } |
| 3639 | |
| 3640 | onFocusChanged(false, 0, null); |
| 3641 | refreshDrawableState(); |
| 3642 | } |
| 3643 | } |
| 3644 | |
| 3645 | /** |
| 3646 | * Called to clear the focus of a view that is about to be removed. |
| 3647 | * Doesn't call clearChildFocus, which prevents this view from taking |
| 3648 | * focus again before it has been removed from the parent |
| 3649 | */ |
| 3650 | void clearFocusForRemoval() { |
| 3651 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 3652 | mPrivateFlags &= ~FOCUSED; |
| 3653 | |
| 3654 | onFocusChanged(false, 0, null); |
| 3655 | refreshDrawableState(); |
| 3656 | } |
| 3657 | } |
| 3658 | |
| 3659 | /** |
| 3660 | * Called internally by the view system when a new view is getting focus. |
| 3661 | * This is what clears the old focus. |
| 3662 | */ |
| 3663 | void unFocus() { |
| 3664 | if (DBG) { |
| 3665 | System.out.println(this + " unFocus()"); |
| 3666 | } |
| 3667 | |
| 3668 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 3669 | mPrivateFlags &= ~FOCUSED; |
| 3670 | |
| 3671 | onFocusChanged(false, 0, null); |
| 3672 | refreshDrawableState(); |
| 3673 | } |
| 3674 | } |
| 3675 | |
| 3676 | /** |
| 3677 | * Returns true if this view has focus iteself, or is the ancestor of the |
| 3678 | * view that has focus. |
| 3679 | * |
| 3680 | * @return True if this view has or contains focus, false otherwise. |
| 3681 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 3682 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3683 | public boolean hasFocus() { |
| 3684 | return (mPrivateFlags & FOCUSED) != 0; |
| 3685 | } |
| 3686 | |
| 3687 | /** |
| 3688 | * Returns true if this view is focusable or if it contains a reachable View |
| 3689 | * for which {@link #hasFocusable()} returns true. A "reachable hasFocusable()" |
| 3690 | * is a View whose parents do not block descendants focus. |
| 3691 | * |
| 3692 | * Only {@link #VISIBLE} views are considered focusable. |
| 3693 | * |
| 3694 | * @return True if the view is focusable or if the view contains a focusable |
| 3695 | * View, false otherwise. |
| 3696 | * |
| 3697 | * @see ViewGroup#FOCUS_BLOCK_DESCENDANTS |
| 3698 | */ |
| 3699 | public boolean hasFocusable() { |
| 3700 | return (mViewFlags & VISIBILITY_MASK) == VISIBLE && isFocusable(); |
| 3701 | } |
| 3702 | |
| 3703 | /** |
| 3704 | * Called by the view system when the focus state of this view changes. |
| 3705 | * When the focus change event is caused by directional navigation, direction |
| 3706 | * and previouslyFocusedRect provide insight into where the focus is coming from. |
| 3707 | * When overriding, be sure to call up through to the super class so that |
| 3708 | * the standard focus handling will occur. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3709 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3710 | * @param gainFocus True if the View has focus; false otherwise. |
| 3711 | * @param direction The direction focus has moved when requestFocus() |
| 3712 | * is called to give this view focus. Values are |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 3713 | * {@link #FOCUS_UP}, {@link #FOCUS_DOWN}, {@link #FOCUS_LEFT}, |
| 3714 | * {@link #FOCUS_RIGHT}, {@link #FOCUS_FORWARD}, or {@link #FOCUS_BACKWARD}. |
| 3715 | * 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] | 3716 | * @param previouslyFocusedRect The rectangle, in this view's coordinate |
| 3717 | * system, of the previously focused view. If applicable, this will be |
| 3718 | * passed in as finer grained information about where the focus is coming |
| 3719 | * from (in addition to direction). Will be <code>null</code> otherwise. |
| 3720 | */ |
| 3721 | protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3722 | if (gainFocus) { |
| 3723 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 3724 | } |
| 3725 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3726 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 3727 | if (!gainFocus) { |
| 3728 | if (isPressed()) { |
| 3729 | setPressed(false); |
| 3730 | } |
| 3731 | if (imm != null && mAttachInfo != null |
| 3732 | && mAttachInfo.mHasWindowFocus) { |
| 3733 | imm.focusOut(this); |
| 3734 | } |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 3735 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3736 | } else if (imm != null && mAttachInfo != null |
| 3737 | && mAttachInfo.mHasWindowFocus) { |
| 3738 | imm.focusIn(this); |
| 3739 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3740 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 3741 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3742 | if (mOnFocusChangeListener != null) { |
| 3743 | mOnFocusChangeListener.onFocusChange(this, gainFocus); |
| 3744 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3745 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3746 | if (mAttachInfo != null) { |
| 3747 | mAttachInfo.mKeyDispatchState.reset(this); |
| 3748 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3752 | * Sends an accessibility event of the given type. If accessiiblity is |
| 3753 | * not enabled this method has no effect. The default implementation calls |
| 3754 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)} first |
| 3755 | * to populate information about the event source (this View), then calls |
| 3756 | * {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} to |
| 3757 | * populate the text content of the event source including its descendants, |
| 3758 | * and last calls |
| 3759 | * {@link ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)} |
| 3760 | * on its parent to resuest sending of the event to interested parties. |
| 3761 | * |
| 3762 | * @param eventType The type of the event to send. |
| 3763 | * |
| 3764 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 3765 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 3766 | * @see ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent) |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3767 | */ |
| 3768 | public void sendAccessibilityEvent(int eventType) { |
| 3769 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 3770 | sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType)); |
| 3771 | } |
| 3772 | } |
| 3773 | |
| 3774 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3775 | * This method behaves exactly as {@link #sendAccessibilityEvent(int)} but |
| 3776 | * takes as an argument an empty {@link AccessibilityEvent} and does not |
| 3777 | * perfrom a check whether accessibility is enabled. |
| 3778 | * |
| 3779 | * @param event The event to send. |
| 3780 | * |
| 3781 | * @see #sendAccessibilityEvent(int) |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3782 | */ |
| 3783 | public void sendAccessibilityEventUnchecked(AccessibilityEvent event) { |
Svetoslav Ganov | 9cd1eca | 2011-01-13 14:24:02 -0800 | [diff] [blame] | 3784 | if (!isShown()) { |
| 3785 | return; |
| 3786 | } |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3787 | onInitializeAccessibilityEvent(event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3788 | dispatchPopulateAccessibilityEvent(event); |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 3789 | // In the beginning we called #isShown(), so we know that getParent() is not null. |
| 3790 | getParent().requestSendAccessibilityEvent(this, event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3791 | } |
| 3792 | |
| 3793 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3794 | * Dispatches an {@link AccessibilityEvent} to the {@link View} first and then |
| 3795 | * to its children for adding their text content to the event. Note that the |
| 3796 | * event text is populated in a separate dispatch path since we add to the |
| 3797 | * event not only the text of the source but also the text of all its descendants. |
| 3798 | * </p> |
| 3799 | * A typical implementation will call |
| 3800 | * {@link #onPopulateAccessibilityEvent(AccessibilityEvent)} on the this view |
| 3801 | * and then call the {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
| 3802 | * on each child. Override this method if custom population of the event text |
| 3803 | * content is required. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3804 | * |
| 3805 | * @param event The event. |
| 3806 | * |
| 3807 | * @return True if the event population was completed. |
| 3808 | */ |
| 3809 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 3810 | onPopulateAccessibilityEvent(event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3811 | return false; |
| 3812 | } |
| 3813 | |
| 3814 | /** |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 3815 | * Called from {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3816 | * giving a chance to this View to populate the accessibility event with its |
| 3817 | * text content. While the implementation is free to modify other event |
| 3818 | * attributes this should be performed in |
| 3819 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)}. |
| 3820 | * <p> |
| 3821 | * Example: Adding formatted date string to an accessibility event in addition |
| 3822 | * to the text added by the super implementation. |
| 3823 | * </p><p><pre><code> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3824 | * public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
| 3825 | * super.onPopulateAccessibilityEvent(event); |
| 3826 | * final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; |
| 3827 | * String selectedDateUtterance = DateUtils.formatDateTime(mContext, |
| 3828 | * mCurrentDate.getTimeInMillis(), flags); |
| 3829 | * event.getText().add(selectedDateUtterance); |
| 3830 | * } |
| 3831 | * </code></pre></p> |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 3832 | * |
| 3833 | * @param event The accessibility event which to populate. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3834 | * |
| 3835 | * @see #sendAccessibilityEvent(int) |
| 3836 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 3837 | */ |
| 3838 | public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3842 | * Initializes an {@link AccessibilityEvent} with information about the |
| 3843 | * the type of the event and this View which is the event source. In other |
| 3844 | * words, the source of an accessibility event is the view whose state |
| 3845 | * change triggered firing the event. |
| 3846 | * <p> |
| 3847 | * Example: Setting the password property of an event in addition |
| 3848 | * to properties set by the super implementation. |
| 3849 | * </p><p><pre><code> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3850 | * public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 3851 | * super.onInitializeAccessibilityEvent(event); |
| 3852 | * event.setPassword(true); |
| 3853 | * } |
| 3854 | * </code></pre></p> |
| 3855 | * @param event The event to initialeze. |
| 3856 | * |
| 3857 | * @see #sendAccessibilityEvent(int) |
| 3858 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 3859 | */ |
| 3860 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3861 | event.setSource(this); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3862 | event.setClassName(getClass().getName()); |
| 3863 | event.setPackageName(getContext().getPackageName()); |
| 3864 | event.setEnabled(isEnabled()); |
| 3865 | event.setContentDescription(mContentDescription); |
| 3866 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 3867 | final int eventType = event.getEventType(); |
| 3868 | switch (eventType) { |
| 3869 | case AccessibilityEvent.TYPE_VIEW_FOCUSED: { |
| 3870 | if (mAttachInfo != null) { |
| 3871 | ArrayList<View> focusablesTempList = mAttachInfo.mFocusablesTempList; |
| 3872 | getRootView().addFocusables(focusablesTempList, View.FOCUS_FORWARD, |
| 3873 | FOCUSABLES_ALL); |
| 3874 | event.setItemCount(focusablesTempList.size()); |
| 3875 | event.setCurrentItemIndex(focusablesTempList.indexOf(this)); |
| 3876 | focusablesTempList.clear(); |
| 3877 | } |
| 3878 | } break; |
| 3879 | case AccessibilityEvent.TYPE_VIEW_SCROLLED: { |
| 3880 | event.setScrollX(mScrollX); |
| 3881 | event.setScrollY(mScrollY); |
| 3882 | event.setItemCount(getHeight()); |
| 3883 | } break; |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3884 | } |
| 3885 | } |
| 3886 | |
| 3887 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3888 | * Returns an {@link AccessibilityNodeInfo} representing this view from the |
| 3889 | * point of view of an {@link android.accessibilityservice.AccessibilityService}. |
| 3890 | * This method is responsible for obtaining an accessibility node info from a |
| 3891 | * pool of reusable instances and calling |
| 3892 | * {@link #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} on this view to |
| 3893 | * initialize the former. |
| 3894 | * <p> |
| 3895 | * Note: The client is responsible for recycling the obtained instance by calling |
| 3896 | * {@link AccessibilityNodeInfo#recycle()} to minimize object creation. |
| 3897 | * </p> |
| 3898 | * @return A populated {@link AccessibilityNodeInfo}. |
| 3899 | * |
| 3900 | * @see AccessibilityNodeInfo |
| 3901 | */ |
| 3902 | public AccessibilityNodeInfo createAccessibilityNodeInfo() { |
| 3903 | AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(this); |
| 3904 | onInitializeAccessibilityNodeInfo(info); |
| 3905 | return info; |
| 3906 | } |
| 3907 | |
| 3908 | /** |
| 3909 | * Initializes an {@link AccessibilityNodeInfo} with information about this view. |
| 3910 | * The base implementation sets: |
| 3911 | * <ul> |
| 3912 | * <li>{@link AccessibilityNodeInfo#setParent(View)},</li> |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 3913 | * <li>{@link AccessibilityNodeInfo#setBoundsInParent(Rect)},</li> |
| 3914 | * <li>{@link AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li> |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3915 | * <li>{@link AccessibilityNodeInfo#setPackageName(CharSequence)},</li> |
| 3916 | * <li>{@link AccessibilityNodeInfo#setClassName(CharSequence)},</li> |
| 3917 | * <li>{@link AccessibilityNodeInfo#setContentDescription(CharSequence)},</li> |
| 3918 | * <li>{@link AccessibilityNodeInfo#setEnabled(boolean)},</li> |
| 3919 | * <li>{@link AccessibilityNodeInfo#setClickable(boolean)},</li> |
| 3920 | * <li>{@link AccessibilityNodeInfo#setFocusable(boolean)},</li> |
| 3921 | * <li>{@link AccessibilityNodeInfo#setFocused(boolean)},</li> |
| 3922 | * <li>{@link AccessibilityNodeInfo#setLongClickable(boolean)},</li> |
| 3923 | * <li>{@link AccessibilityNodeInfo#setSelected(boolean)},</li> |
| 3924 | * </ul> |
| 3925 | * <p> |
| 3926 | * Subclasses should override this method, call the super implementation, |
| 3927 | * and set additional attributes. |
| 3928 | * </p> |
| 3929 | * @param info The instance to initialize. |
| 3930 | */ |
| 3931 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 3932 | Rect bounds = mAttachInfo.mTmpInvalRect; |
| 3933 | getDrawingRect(bounds); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 3934 | info.setBoundsInParent(bounds); |
| 3935 | |
| 3936 | int[] locationOnScreen = mAttachInfo.mInvalidateChildLocation; |
| 3937 | getLocationOnScreen(locationOnScreen); |
Alan Viverette | 326804f | 2011-07-22 16:20:41 -0700 | [diff] [blame] | 3938 | bounds.offsetTo(0, 0); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 3939 | bounds.offset(locationOnScreen[0], locationOnScreen[1]); |
| 3940 | info.setBoundsInScreen(bounds); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3941 | |
| 3942 | ViewParent parent = getParent(); |
| 3943 | if (parent instanceof View) { |
| 3944 | View parentView = (View) parent; |
| 3945 | info.setParent(parentView); |
| 3946 | } |
| 3947 | |
| 3948 | info.setPackageName(mContext.getPackageName()); |
| 3949 | info.setClassName(getClass().getName()); |
| 3950 | info.setContentDescription(getContentDescription()); |
| 3951 | |
| 3952 | info.setEnabled(isEnabled()); |
| 3953 | info.setClickable(isClickable()); |
| 3954 | info.setFocusable(isFocusable()); |
| 3955 | info.setFocused(isFocused()); |
| 3956 | info.setSelected(isSelected()); |
| 3957 | info.setLongClickable(isLongClickable()); |
| 3958 | |
| 3959 | // TODO: These make sense only if we are in an AdapterView but all |
| 3960 | // views can be selected. Maybe from accessiiblity perspective |
| 3961 | // we should report as selectable view in an AdapterView. |
| 3962 | info.addAction(AccessibilityNodeInfo.ACTION_SELECT); |
| 3963 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_SELECTION); |
| 3964 | |
| 3965 | if (isFocusable()) { |
| 3966 | if (isFocused()) { |
| 3967 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS); |
| 3968 | } else { |
| 3969 | info.addAction(AccessibilityNodeInfo.ACTION_FOCUS); |
| 3970 | } |
| 3971 | } |
| 3972 | } |
| 3973 | |
| 3974 | /** |
| 3975 | * Gets the unique identifier of this view on the screen for accessibility purposes. |
| 3976 | * If this {@link View} is not attached to any window, {@value #NO_ID} is returned. |
| 3977 | * |
| 3978 | * @return The view accessibility id. |
| 3979 | * |
| 3980 | * @hide |
| 3981 | */ |
| 3982 | public int getAccessibilityViewId() { |
| 3983 | if (mAccessibilityViewId == NO_ID) { |
| 3984 | mAccessibilityViewId = sNextAccessibilityViewId++; |
| 3985 | } |
| 3986 | return mAccessibilityViewId; |
| 3987 | } |
| 3988 | |
| 3989 | /** |
| 3990 | * Gets the unique identifier of the window in which this View reseides. |
| 3991 | * |
| 3992 | * @return The window accessibility id. |
| 3993 | * |
| 3994 | * @hide |
| 3995 | */ |
| 3996 | public int getAccessibilityWindowId() { |
| 3997 | return mAttachInfo != null ? mAttachInfo.mAccessibilityWindowId : NO_ID; |
| 3998 | } |
| 3999 | |
| 4000 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4001 | * Gets the {@link View} description. It briefly describes the view and is |
| 4002 | * primarily used for accessibility support. Set this property to enable |
| 4003 | * better accessibility support for your application. This is especially |
| 4004 | * true for views that do not have textual representation (For example, |
| 4005 | * ImageButton). |
| 4006 | * |
| 4007 | * @return The content descriptiopn. |
| 4008 | * |
| 4009 | * @attr ref android.R.styleable#View_contentDescription |
| 4010 | */ |
| 4011 | public CharSequence getContentDescription() { |
| 4012 | return mContentDescription; |
| 4013 | } |
| 4014 | |
| 4015 | /** |
| 4016 | * Sets the {@link View} description. It briefly describes the view and is |
| 4017 | * primarily used for accessibility support. Set this property to enable |
| 4018 | * better accessibility support for your application. This is especially |
| 4019 | * true for views that do not have textual representation (For example, |
| 4020 | * ImageButton). |
| 4021 | * |
| 4022 | * @param contentDescription The content description. |
| 4023 | * |
| 4024 | * @attr ref android.R.styleable#View_contentDescription |
| 4025 | */ |
| 4026 | public void setContentDescription(CharSequence contentDescription) { |
| 4027 | mContentDescription = contentDescription; |
| 4028 | } |
| 4029 | |
| 4030 | /** |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4031 | * Invoked whenever this view loses focus, either by losing window focus or by losing |
| 4032 | * focus within its window. This method can be used to clear any state tied to the |
| 4033 | * focus. For instance, if a button is held pressed with the trackball and the window |
| 4034 | * loses focus, this method can be used to cancel the press. |
| 4035 | * |
| 4036 | * Subclasses of View overriding this method should always call super.onFocusLost(). |
| 4037 | * |
| 4038 | * @see #onFocusChanged(boolean, int, android.graphics.Rect) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4039 | * @see #onWindowFocusChanged(boolean) |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4040 | * |
| 4041 | * @hide pending API council approval |
| 4042 | */ |
| 4043 | protected void onFocusLost() { |
| 4044 | resetPressedState(); |
| 4045 | } |
| 4046 | |
| 4047 | private void resetPressedState() { |
| 4048 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 4049 | return; |
| 4050 | } |
| 4051 | |
| 4052 | if (isPressed()) { |
| 4053 | setPressed(false); |
| 4054 | |
| 4055 | if (!mHasPerformedLongPress) { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 4056 | removeLongPressCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4057 | } |
| 4058 | } |
| 4059 | } |
| 4060 | |
| 4061 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4062 | * Returns true if this view has focus |
| 4063 | * |
| 4064 | * @return True if this view has focus, false otherwise. |
| 4065 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4066 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4067 | public boolean isFocused() { |
| 4068 | return (mPrivateFlags & FOCUSED) != 0; |
| 4069 | } |
| 4070 | |
| 4071 | /** |
| 4072 | * Find the view in the hierarchy rooted at this view that currently has |
| 4073 | * focus. |
| 4074 | * |
| 4075 | * @return The view that currently has focus, or null if no focused view can |
| 4076 | * be found. |
| 4077 | */ |
| 4078 | public View findFocus() { |
| 4079 | return (mPrivateFlags & FOCUSED) != 0 ? this : null; |
| 4080 | } |
| 4081 | |
| 4082 | /** |
| 4083 | * Change whether this view is one of the set of scrollable containers in |
| 4084 | * its window. This will be used to determine whether the window can |
| 4085 | * resize or must pan when a soft input area is open -- scrollable |
| 4086 | * containers allow the window to use resize mode since the container |
| 4087 | * will appropriately shrink. |
| 4088 | */ |
| 4089 | public void setScrollContainer(boolean isScrollContainer) { |
| 4090 | if (isScrollContainer) { |
| 4091 | if (mAttachInfo != null && (mPrivateFlags&SCROLL_CONTAINER_ADDED) == 0) { |
| 4092 | mAttachInfo.mScrollContainers.add(this); |
| 4093 | mPrivateFlags |= SCROLL_CONTAINER_ADDED; |
| 4094 | } |
| 4095 | mPrivateFlags |= SCROLL_CONTAINER; |
| 4096 | } else { |
| 4097 | if ((mPrivateFlags&SCROLL_CONTAINER_ADDED) != 0) { |
| 4098 | mAttachInfo.mScrollContainers.remove(this); |
| 4099 | } |
| 4100 | mPrivateFlags &= ~(SCROLL_CONTAINER|SCROLL_CONTAINER_ADDED); |
| 4101 | } |
| 4102 | } |
| 4103 | |
| 4104 | /** |
| 4105 | * Returns the quality of the drawing cache. |
| 4106 | * |
| 4107 | * @return One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 4108 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 4109 | * |
| 4110 | * @see #setDrawingCacheQuality(int) |
| 4111 | * @see #setDrawingCacheEnabled(boolean) |
| 4112 | * @see #isDrawingCacheEnabled() |
| 4113 | * |
| 4114 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 4115 | */ |
| 4116 | public int getDrawingCacheQuality() { |
| 4117 | return mViewFlags & DRAWING_CACHE_QUALITY_MASK; |
| 4118 | } |
| 4119 | |
| 4120 | /** |
| 4121 | * Set the drawing cache quality of this view. This value is used only when the |
| 4122 | * drawing cache is enabled |
| 4123 | * |
| 4124 | * @param quality One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 4125 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 4126 | * |
| 4127 | * @see #getDrawingCacheQuality() |
| 4128 | * @see #setDrawingCacheEnabled(boolean) |
| 4129 | * @see #isDrawingCacheEnabled() |
| 4130 | * |
| 4131 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 4132 | */ |
| 4133 | public void setDrawingCacheQuality(int quality) { |
| 4134 | setFlags(quality, DRAWING_CACHE_QUALITY_MASK); |
| 4135 | } |
| 4136 | |
| 4137 | /** |
| 4138 | * Returns whether the screen should remain on, corresponding to the current |
| 4139 | * value of {@link #KEEP_SCREEN_ON}. |
| 4140 | * |
| 4141 | * @return Returns true if {@link #KEEP_SCREEN_ON} is set. |
| 4142 | * |
| 4143 | * @see #setKeepScreenOn(boolean) |
| 4144 | * |
| 4145 | * @attr ref android.R.styleable#View_keepScreenOn |
| 4146 | */ |
| 4147 | public boolean getKeepScreenOn() { |
| 4148 | return (mViewFlags & KEEP_SCREEN_ON) != 0; |
| 4149 | } |
| 4150 | |
| 4151 | /** |
| 4152 | * Controls whether the screen should remain on, modifying the |
| 4153 | * value of {@link #KEEP_SCREEN_ON}. |
| 4154 | * |
| 4155 | * @param keepScreenOn Supply true to set {@link #KEEP_SCREEN_ON}. |
| 4156 | * |
| 4157 | * @see #getKeepScreenOn() |
| 4158 | * |
| 4159 | * @attr ref android.R.styleable#View_keepScreenOn |
| 4160 | */ |
| 4161 | public void setKeepScreenOn(boolean keepScreenOn) { |
| 4162 | setFlags(keepScreenOn ? KEEP_SCREEN_ON : 0, KEEP_SCREEN_ON); |
| 4163 | } |
| 4164 | |
| 4165 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4166 | * Gets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 4167 | * @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] | 4168 | * |
| 4169 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 4170 | */ |
| 4171 | public int getNextFocusLeftId() { |
| 4172 | return mNextFocusLeftId; |
| 4173 | } |
| 4174 | |
| 4175 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4176 | * Sets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 4177 | * @param nextFocusLeftId The next focus ID, or {@link #NO_ID} if the framework should |
| 4178 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4179 | * |
| 4180 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 4181 | */ |
| 4182 | public void setNextFocusLeftId(int nextFocusLeftId) { |
| 4183 | mNextFocusLeftId = nextFocusLeftId; |
| 4184 | } |
| 4185 | |
| 4186 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4187 | * Gets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 4188 | * @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] | 4189 | * |
| 4190 | * @attr ref android.R.styleable#View_nextFocusRight |
| 4191 | */ |
| 4192 | public int getNextFocusRightId() { |
| 4193 | return mNextFocusRightId; |
| 4194 | } |
| 4195 | |
| 4196 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4197 | * Sets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 4198 | * @param nextFocusRightId The next focus ID, or {@link #NO_ID} if the framework should |
| 4199 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4200 | * |
| 4201 | * @attr ref android.R.styleable#View_nextFocusRight |
| 4202 | */ |
| 4203 | public void setNextFocusRightId(int nextFocusRightId) { |
| 4204 | mNextFocusRightId = nextFocusRightId; |
| 4205 | } |
| 4206 | |
| 4207 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4208 | * Gets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 4209 | * @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] | 4210 | * |
| 4211 | * @attr ref android.R.styleable#View_nextFocusUp |
| 4212 | */ |
| 4213 | public int getNextFocusUpId() { |
| 4214 | return mNextFocusUpId; |
| 4215 | } |
| 4216 | |
| 4217 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4218 | * Sets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 4219 | * @param nextFocusUpId The next focus ID, or {@link #NO_ID} if the framework should |
| 4220 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4221 | * |
| 4222 | * @attr ref android.R.styleable#View_nextFocusUp |
| 4223 | */ |
| 4224 | public void setNextFocusUpId(int nextFocusUpId) { |
| 4225 | mNextFocusUpId = nextFocusUpId; |
| 4226 | } |
| 4227 | |
| 4228 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4229 | * Gets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 4230 | * @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] | 4231 | * |
| 4232 | * @attr ref android.R.styleable#View_nextFocusDown |
| 4233 | */ |
| 4234 | public int getNextFocusDownId() { |
| 4235 | return mNextFocusDownId; |
| 4236 | } |
| 4237 | |
| 4238 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4239 | * Sets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 4240 | * @param nextFocusDownId The next focus ID, or {@link #NO_ID} if the framework should |
| 4241 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4242 | * |
| 4243 | * @attr ref android.R.styleable#View_nextFocusDown |
| 4244 | */ |
| 4245 | public void setNextFocusDownId(int nextFocusDownId) { |
| 4246 | mNextFocusDownId = nextFocusDownId; |
| 4247 | } |
| 4248 | |
| 4249 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4250 | * Gets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 4251 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
| 4252 | * |
| 4253 | * @attr ref android.R.styleable#View_nextFocusForward |
| 4254 | */ |
| 4255 | public int getNextFocusForwardId() { |
| 4256 | return mNextFocusForwardId; |
| 4257 | } |
| 4258 | |
| 4259 | /** |
| 4260 | * Sets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 4261 | * @param nextFocusForwardId The next focus ID, or {@link #NO_ID} if the framework should |
| 4262 | * decide automatically. |
| 4263 | * |
| 4264 | * @attr ref android.R.styleable#View_nextFocusForward |
| 4265 | */ |
| 4266 | public void setNextFocusForwardId(int nextFocusForwardId) { |
| 4267 | mNextFocusForwardId = nextFocusForwardId; |
| 4268 | } |
| 4269 | |
| 4270 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4271 | * Returns the visibility of this view and all of its ancestors |
| 4272 | * |
| 4273 | * @return True if this view and all of its ancestors are {@link #VISIBLE} |
| 4274 | */ |
| 4275 | public boolean isShown() { |
| 4276 | View current = this; |
| 4277 | //noinspection ConstantConditions |
| 4278 | do { |
| 4279 | if ((current.mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 4280 | return false; |
| 4281 | } |
| 4282 | ViewParent parent = current.mParent; |
| 4283 | if (parent == null) { |
| 4284 | return false; // We are not attached to the view root |
| 4285 | } |
| 4286 | if (!(parent instanceof View)) { |
| 4287 | return true; |
| 4288 | } |
| 4289 | current = (View) parent; |
| 4290 | } while (current != null); |
| 4291 | |
| 4292 | return false; |
| 4293 | } |
| 4294 | |
| 4295 | /** |
| 4296 | * Apply the insets for system windows to this view, if the FITS_SYSTEM_WINDOWS flag |
| 4297 | * is set |
| 4298 | * |
| 4299 | * @param insets Insets for system windows |
| 4300 | * |
| 4301 | * @return True if this view applied the insets, false otherwise |
| 4302 | */ |
| 4303 | protected boolean fitSystemWindows(Rect insets) { |
| 4304 | if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) { |
| 4305 | mPaddingLeft = insets.left; |
| 4306 | mPaddingTop = insets.top; |
| 4307 | mPaddingRight = insets.right; |
| 4308 | mPaddingBottom = insets.bottom; |
| 4309 | requestLayout(); |
| 4310 | return true; |
| 4311 | } |
| 4312 | return false; |
| 4313 | } |
| 4314 | |
| 4315 | /** |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 4316 | * Set whether or not this view should account for system screen decorations |
| 4317 | * such as the status bar and inset its content. This allows this view to be |
| 4318 | * positioned in absolute screen coordinates and remain visible to the user. |
| 4319 | * |
| 4320 | * <p>This should only be used by top-level window decor views. |
| 4321 | * |
| 4322 | * @param fitSystemWindows true to inset content for system screen decorations, false for |
| 4323 | * default behavior. |
| 4324 | * |
| 4325 | * @attr ref android.R.styleable#View_fitsSystemWindows |
| 4326 | */ |
| 4327 | public void setFitsSystemWindows(boolean fitSystemWindows) { |
| 4328 | setFlags(fitSystemWindows ? FITS_SYSTEM_WINDOWS : 0, FITS_SYSTEM_WINDOWS); |
| 4329 | } |
| 4330 | |
| 4331 | /** |
| 4332 | * Check for the FITS_SYSTEM_WINDOWS flag. If this method returns true, this view |
| 4333 | * will account for system screen decorations such as the status bar and inset its |
| 4334 | * content. This allows the view to be positioned in absolute screen coordinates |
| 4335 | * and remain visible to the user. |
| 4336 | * |
| 4337 | * @return true if this view will adjust its content bounds for system screen decorations. |
| 4338 | * |
| 4339 | * @attr ref android.R.styleable#View_fitsSystemWindows |
| 4340 | */ |
| 4341 | public boolean fitsSystemWindows() { |
| 4342 | return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS; |
| 4343 | } |
| 4344 | |
| 4345 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4346 | * Returns the visibility status for this view. |
| 4347 | * |
| 4348 | * @return One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 4349 | * @attr ref android.R.styleable#View_visibility |
| 4350 | */ |
| 4351 | @ViewDebug.ExportedProperty(mapping = { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 4352 | @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), |
| 4353 | @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), |
| 4354 | @ViewDebug.IntToString(from = GONE, to = "GONE") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4355 | }) |
| 4356 | public int getVisibility() { |
| 4357 | return mViewFlags & VISIBILITY_MASK; |
| 4358 | } |
| 4359 | |
| 4360 | /** |
| 4361 | * Set the enabled state of this view. |
| 4362 | * |
| 4363 | * @param visibility One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 4364 | * @attr ref android.R.styleable#View_visibility |
| 4365 | */ |
| 4366 | @RemotableViewMethod |
| 4367 | public void setVisibility(int visibility) { |
| 4368 | setFlags(visibility, VISIBILITY_MASK); |
| 4369 | if (mBGDrawable != null) mBGDrawable.setVisible(visibility == VISIBLE, false); |
| 4370 | } |
| 4371 | |
| 4372 | /** |
| 4373 | * Returns the enabled status for this view. The interpretation of the |
| 4374 | * enabled state varies by subclass. |
| 4375 | * |
| 4376 | * @return True if this view is enabled, false otherwise. |
| 4377 | */ |
| 4378 | @ViewDebug.ExportedProperty |
| 4379 | public boolean isEnabled() { |
| 4380 | return (mViewFlags & ENABLED_MASK) == ENABLED; |
| 4381 | } |
| 4382 | |
| 4383 | /** |
| 4384 | * Set the enabled state of this view. The interpretation of the enabled |
| 4385 | * state varies by subclass. |
| 4386 | * |
| 4387 | * @param enabled True if this view is enabled, false otherwise. |
| 4388 | */ |
Jeff Sharkey | 2b95c24 | 2010-02-08 17:40:30 -0800 | [diff] [blame] | 4389 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4390 | public void setEnabled(boolean enabled) { |
Amith Yamasani | a2ef00b | 2009-07-30 16:14:34 -0700 | [diff] [blame] | 4391 | if (enabled == isEnabled()) return; |
| 4392 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4393 | setFlags(enabled ? ENABLED : DISABLED, ENABLED_MASK); |
| 4394 | |
| 4395 | /* |
| 4396 | * The View most likely has to change its appearance, so refresh |
| 4397 | * the drawable state. |
| 4398 | */ |
| 4399 | refreshDrawableState(); |
| 4400 | |
| 4401 | // Invalidate too, since the default behavior for views is to be |
| 4402 | // be drawn at 50% alpha rather than to change the drawable. |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 4403 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4404 | } |
| 4405 | |
| 4406 | /** |
| 4407 | * Set whether this view can receive the focus. |
| 4408 | * |
| 4409 | * Setting this to false will also ensure that this view is not focusable |
| 4410 | * in touch mode. |
| 4411 | * |
| 4412 | * @param focusable If true, this view can receive the focus. |
| 4413 | * |
| 4414 | * @see #setFocusableInTouchMode(boolean) |
| 4415 | * @attr ref android.R.styleable#View_focusable |
| 4416 | */ |
| 4417 | public void setFocusable(boolean focusable) { |
| 4418 | if (!focusable) { |
| 4419 | setFlags(0, FOCUSABLE_IN_TOUCH_MODE); |
| 4420 | } |
| 4421 | setFlags(focusable ? FOCUSABLE : NOT_FOCUSABLE, FOCUSABLE_MASK); |
| 4422 | } |
| 4423 | |
| 4424 | /** |
| 4425 | * Set whether this view can receive focus while in touch mode. |
| 4426 | * |
| 4427 | * Setting this to true will also ensure that this view is focusable. |
| 4428 | * |
| 4429 | * @param focusableInTouchMode If true, this view can receive the focus while |
| 4430 | * in touch mode. |
| 4431 | * |
| 4432 | * @see #setFocusable(boolean) |
| 4433 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 4434 | */ |
| 4435 | public void setFocusableInTouchMode(boolean focusableInTouchMode) { |
| 4436 | // Focusable in touch mode should always be set before the focusable flag |
| 4437 | // otherwise, setting the focusable flag will trigger a focusableViewAvailable() |
| 4438 | // which, in touch mode, will not successfully request focus on this view |
| 4439 | // because the focusable in touch mode flag is not set |
| 4440 | setFlags(focusableInTouchMode ? FOCUSABLE_IN_TOUCH_MODE : 0, FOCUSABLE_IN_TOUCH_MODE); |
| 4441 | if (focusableInTouchMode) { |
| 4442 | setFlags(FOCUSABLE, FOCUSABLE_MASK); |
| 4443 | } |
| 4444 | } |
| 4445 | |
| 4446 | /** |
| 4447 | * Set whether this view should have sound effects enabled for events such as |
| 4448 | * clicking and touching. |
| 4449 | * |
| 4450 | * <p>You may wish to disable sound effects for a view if you already play sounds, |
| 4451 | * for instance, a dial key that plays dtmf tones. |
| 4452 | * |
| 4453 | * @param soundEffectsEnabled whether sound effects are enabled for this view. |
| 4454 | * @see #isSoundEffectsEnabled() |
| 4455 | * @see #playSoundEffect(int) |
| 4456 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 4457 | */ |
| 4458 | public void setSoundEffectsEnabled(boolean soundEffectsEnabled) { |
| 4459 | setFlags(soundEffectsEnabled ? SOUND_EFFECTS_ENABLED: 0, SOUND_EFFECTS_ENABLED); |
| 4460 | } |
| 4461 | |
| 4462 | /** |
| 4463 | * @return whether this view should have sound effects enabled for events such as |
| 4464 | * clicking and touching. |
| 4465 | * |
| 4466 | * @see #setSoundEffectsEnabled(boolean) |
| 4467 | * @see #playSoundEffect(int) |
| 4468 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 4469 | */ |
| 4470 | @ViewDebug.ExportedProperty |
| 4471 | public boolean isSoundEffectsEnabled() { |
| 4472 | return SOUND_EFFECTS_ENABLED == (mViewFlags & SOUND_EFFECTS_ENABLED); |
| 4473 | } |
| 4474 | |
| 4475 | /** |
| 4476 | * Set whether this view should have haptic feedback for events such as |
| 4477 | * long presses. |
| 4478 | * |
| 4479 | * <p>You may wish to disable haptic feedback if your view already controls |
| 4480 | * its own haptic feedback. |
| 4481 | * |
| 4482 | * @param hapticFeedbackEnabled whether haptic feedback enabled for this view. |
| 4483 | * @see #isHapticFeedbackEnabled() |
| 4484 | * @see #performHapticFeedback(int) |
| 4485 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 4486 | */ |
| 4487 | public void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled) { |
| 4488 | setFlags(hapticFeedbackEnabled ? HAPTIC_FEEDBACK_ENABLED: 0, HAPTIC_FEEDBACK_ENABLED); |
| 4489 | } |
| 4490 | |
| 4491 | /** |
| 4492 | * @return whether this view should have haptic feedback enabled for events |
| 4493 | * long presses. |
| 4494 | * |
| 4495 | * @see #setHapticFeedbackEnabled(boolean) |
| 4496 | * @see #performHapticFeedback(int) |
| 4497 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 4498 | */ |
| 4499 | @ViewDebug.ExportedProperty |
| 4500 | public boolean isHapticFeedbackEnabled() { |
| 4501 | return HAPTIC_FEEDBACK_ENABLED == (mViewFlags & HAPTIC_FEEDBACK_ENABLED); |
| 4502 | } |
| 4503 | |
| 4504 | /** |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4505 | * Returns the layout direction for this view. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4506 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4507 | * @return One of {@link #LAYOUT_DIRECTION_LTR}, |
| 4508 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 4509 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 4510 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
| 4511 | * @attr ref android.R.styleable#View_layoutDirection |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 4512 | * |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4513 | * @hide |
| 4514 | */ |
Fabrice Di Meglio | bce84d2 | 2011-06-02 15:57:01 -0700 | [diff] [blame] | 4515 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4516 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "LTR"), |
| 4517 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RTL"), |
| 4518 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"), |
| 4519 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE, to = "LOCALE") |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4520 | }) |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4521 | public int getLayoutDirection() { |
| 4522 | return mViewFlags & LAYOUT_DIRECTION_MASK; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4523 | } |
| 4524 | |
| 4525 | /** |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 4526 | * Set the layout direction for this view. This will propagate a reset of layout direction |
| 4527 | * 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] | 4528 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4529 | * @param layoutDirection One of {@link #LAYOUT_DIRECTION_LTR}, |
| 4530 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 4531 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 4532 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 4533 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4534 | * @attr ref android.R.styleable#View_layoutDirection |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 4535 | * |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4536 | * @hide |
| 4537 | */ |
| 4538 | @RemotableViewMethod |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4539 | public void setLayoutDirection(int layoutDirection) { |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 4540 | if (getLayoutDirection() != layoutDirection) { |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 4541 | resetResolvedLayoutDirection(); |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 4542 | // Setting the flag will also request a layout. |
| 4543 | setFlags(layoutDirection, LAYOUT_DIRECTION_MASK); |
| 4544 | } |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4545 | } |
| 4546 | |
| 4547 | /** |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 4548 | * Returns the resolved layout direction for this view. |
| 4549 | * |
| 4550 | * @return {@link #LAYOUT_DIRECTION_RTL} if the layout direction is RTL or returns |
| 4551 | * {@link #LAYOUT_DIRECTION_LTR} id the layout direction is not RTL. |
| 4552 | * |
| 4553 | * @hide |
| 4554 | */ |
| 4555 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
| 4556 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"), |
| 4557 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL") |
| 4558 | }) |
| 4559 | public int getResolvedLayoutDirection() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 4560 | resolveLayoutDirectionIfNeeded(); |
| 4561 | return ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED_RTL) == LAYOUT_DIRECTION_RESOLVED_RTL) ? |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 4562 | LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR; |
| 4563 | } |
| 4564 | |
| 4565 | /** |
| 4566 | * <p>Indicates whether or not this view's layout is right-to-left. This is resolved from |
| 4567 | * layout attribute and/or the inherited value from the parent.</p> |
| 4568 | * |
| 4569 | * @return true if the layout is right-to-left. |
| 4570 | * |
| 4571 | * @hide |
| 4572 | */ |
| 4573 | @ViewDebug.ExportedProperty(category = "layout") |
| 4574 | public boolean isLayoutRtl() { |
| 4575 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL); |
| 4576 | } |
| 4577 | |
| 4578 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4579 | * If this view doesn't do any drawing on its own, set this flag to |
| 4580 | * allow further optimizations. By default, this flag is not set on |
| 4581 | * View, but could be set on some View subclasses such as ViewGroup. |
| 4582 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 4583 | * Typically, if you override {@link #onDraw(android.graphics.Canvas)} |
| 4584 | * you should clear this flag. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4585 | * |
| 4586 | * @param willNotDraw whether or not this View draw on its own |
| 4587 | */ |
| 4588 | public void setWillNotDraw(boolean willNotDraw) { |
| 4589 | setFlags(willNotDraw ? WILL_NOT_DRAW : 0, DRAW_MASK); |
| 4590 | } |
| 4591 | |
| 4592 | /** |
| 4593 | * Returns whether or not this View draws on its own. |
| 4594 | * |
| 4595 | * @return true if this view has nothing to draw, false otherwise |
| 4596 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4597 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4598 | public boolean willNotDraw() { |
| 4599 | return (mViewFlags & DRAW_MASK) == WILL_NOT_DRAW; |
| 4600 | } |
| 4601 | |
| 4602 | /** |
| 4603 | * When a View's drawing cache is enabled, drawing is redirected to an |
| 4604 | * offscreen bitmap. Some views, like an ImageView, must be able to |
| 4605 | * bypass this mechanism if they already draw a single bitmap, to avoid |
| 4606 | * unnecessary usage of the memory. |
| 4607 | * |
| 4608 | * @param willNotCacheDrawing true if this view does not cache its |
| 4609 | * drawing, false otherwise |
| 4610 | */ |
| 4611 | public void setWillNotCacheDrawing(boolean willNotCacheDrawing) { |
| 4612 | setFlags(willNotCacheDrawing ? WILL_NOT_CACHE_DRAWING : 0, WILL_NOT_CACHE_DRAWING); |
| 4613 | } |
| 4614 | |
| 4615 | /** |
| 4616 | * Returns whether or not this View can cache its drawing or not. |
| 4617 | * |
| 4618 | * @return true if this view does not cache its drawing, false otherwise |
| 4619 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4620 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4621 | public boolean willNotCacheDrawing() { |
| 4622 | return (mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING; |
| 4623 | } |
| 4624 | |
| 4625 | /** |
| 4626 | * Indicates whether this view reacts to click events or not. |
| 4627 | * |
| 4628 | * @return true if the view is clickable, false otherwise |
| 4629 | * |
| 4630 | * @see #setClickable(boolean) |
| 4631 | * @attr ref android.R.styleable#View_clickable |
| 4632 | */ |
| 4633 | @ViewDebug.ExportedProperty |
| 4634 | public boolean isClickable() { |
| 4635 | return (mViewFlags & CLICKABLE) == CLICKABLE; |
| 4636 | } |
| 4637 | |
| 4638 | /** |
| 4639 | * Enables or disables click events for this view. When a view |
| 4640 | * is clickable it will change its state to "pressed" on every click. |
| 4641 | * Subclasses should set the view clickable to visually react to |
| 4642 | * user's clicks. |
| 4643 | * |
| 4644 | * @param clickable true to make the view clickable, false otherwise |
| 4645 | * |
| 4646 | * @see #isClickable() |
| 4647 | * @attr ref android.R.styleable#View_clickable |
| 4648 | */ |
| 4649 | public void setClickable(boolean clickable) { |
| 4650 | setFlags(clickable ? CLICKABLE : 0, CLICKABLE); |
| 4651 | } |
| 4652 | |
| 4653 | /** |
| 4654 | * Indicates whether this view reacts to long click events or not. |
| 4655 | * |
| 4656 | * @return true if the view is long clickable, false otherwise |
| 4657 | * |
| 4658 | * @see #setLongClickable(boolean) |
| 4659 | * @attr ref android.R.styleable#View_longClickable |
| 4660 | */ |
| 4661 | public boolean isLongClickable() { |
| 4662 | return (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 4663 | } |
| 4664 | |
| 4665 | /** |
| 4666 | * Enables or disables long click events for this view. When a view is long |
| 4667 | * clickable it reacts to the user holding down the button for a longer |
| 4668 | * duration than a tap. This event can either launch the listener or a |
| 4669 | * context menu. |
| 4670 | * |
| 4671 | * @param longClickable true to make the view long clickable, false otherwise |
| 4672 | * @see #isLongClickable() |
| 4673 | * @attr ref android.R.styleable#View_longClickable |
| 4674 | */ |
| 4675 | public void setLongClickable(boolean longClickable) { |
| 4676 | setFlags(longClickable ? LONG_CLICKABLE : 0, LONG_CLICKABLE); |
| 4677 | } |
| 4678 | |
| 4679 | /** |
Chet Haase | 49afa5b | 2010-08-23 11:39:53 -0700 | [diff] [blame] | 4680 | * Sets the pressed state for this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4681 | * |
| 4682 | * @see #isClickable() |
| 4683 | * @see #setClickable(boolean) |
| 4684 | * |
| 4685 | * @param pressed Pass true to set the View's internal state to "pressed", or false to reverts |
| 4686 | * the View's internal state from a previously set "pressed" state. |
| 4687 | */ |
| 4688 | public void setPressed(boolean pressed) { |
| 4689 | if (pressed) { |
| 4690 | mPrivateFlags |= PRESSED; |
| 4691 | } else { |
| 4692 | mPrivateFlags &= ~PRESSED; |
| 4693 | } |
| 4694 | refreshDrawableState(); |
| 4695 | dispatchSetPressed(pressed); |
| 4696 | } |
| 4697 | |
| 4698 | /** |
| 4699 | * Dispatch setPressed to all of this View's children. |
| 4700 | * |
| 4701 | * @see #setPressed(boolean) |
| 4702 | * |
| 4703 | * @param pressed The new pressed state |
| 4704 | */ |
| 4705 | protected void dispatchSetPressed(boolean pressed) { |
| 4706 | } |
| 4707 | |
| 4708 | /** |
| 4709 | * Indicates whether the view is currently in pressed state. Unless |
| 4710 | * {@link #setPressed(boolean)} is explicitly called, only clickable views can enter |
| 4711 | * the pressed state. |
| 4712 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 4713 | * @see #setPressed(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4714 | * @see #isClickable() |
| 4715 | * @see #setClickable(boolean) |
| 4716 | * |
| 4717 | * @return true if the view is currently pressed, false otherwise |
| 4718 | */ |
| 4719 | public boolean isPressed() { |
| 4720 | return (mPrivateFlags & PRESSED) == PRESSED; |
| 4721 | } |
| 4722 | |
| 4723 | /** |
| 4724 | * Indicates whether this view will save its state (that is, |
| 4725 | * whether its {@link #onSaveInstanceState} method will be called). |
| 4726 | * |
| 4727 | * @return Returns true if the view state saving is enabled, else false. |
| 4728 | * |
| 4729 | * @see #setSaveEnabled(boolean) |
| 4730 | * @attr ref android.R.styleable#View_saveEnabled |
| 4731 | */ |
| 4732 | public boolean isSaveEnabled() { |
| 4733 | return (mViewFlags & SAVE_DISABLED_MASK) != SAVE_DISABLED; |
| 4734 | } |
| 4735 | |
| 4736 | /** |
| 4737 | * Controls whether the saving of this view's state is |
| 4738 | * enabled (that is, whether its {@link #onSaveInstanceState} method |
| 4739 | * will be called). Note that even if freezing is enabled, the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 4740 | * 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] | 4741 | * for its state to be saved. This flag can only disable the |
| 4742 | * saving of this view; any child views may still have their state saved. |
| 4743 | * |
| 4744 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 4745 | * (the default) to allow it. |
| 4746 | * |
| 4747 | * @see #isSaveEnabled() |
| 4748 | * @see #setId(int) |
| 4749 | * @see #onSaveInstanceState() |
| 4750 | * @attr ref android.R.styleable#View_saveEnabled |
| 4751 | */ |
| 4752 | public void setSaveEnabled(boolean enabled) { |
| 4753 | setFlags(enabled ? 0 : SAVE_DISABLED, SAVE_DISABLED_MASK); |
| 4754 | } |
| 4755 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 4756 | /** |
| 4757 | * Gets whether the framework should discard touches when the view's |
| 4758 | * window is obscured by another visible window. |
| 4759 | * Refer to the {@link View} security documentation for more details. |
| 4760 | * |
| 4761 | * @return True if touch filtering is enabled. |
| 4762 | * |
| 4763 | * @see #setFilterTouchesWhenObscured(boolean) |
| 4764 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 4765 | */ |
| 4766 | @ViewDebug.ExportedProperty |
| 4767 | public boolean getFilterTouchesWhenObscured() { |
| 4768 | return (mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0; |
| 4769 | } |
| 4770 | |
| 4771 | /** |
| 4772 | * Sets whether the framework should discard touches when the view's |
| 4773 | * window is obscured by another visible window. |
| 4774 | * Refer to the {@link View} security documentation for more details. |
| 4775 | * |
| 4776 | * @param enabled True if touch filtering should be enabled. |
| 4777 | * |
| 4778 | * @see #getFilterTouchesWhenObscured |
| 4779 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 4780 | */ |
| 4781 | public void setFilterTouchesWhenObscured(boolean enabled) { |
| 4782 | setFlags(enabled ? 0 : FILTER_TOUCHES_WHEN_OBSCURED, |
| 4783 | FILTER_TOUCHES_WHEN_OBSCURED); |
| 4784 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4785 | |
| 4786 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 4787 | * Indicates whether the entire hierarchy under this view will save its |
| 4788 | * state when a state saving traversal occurs from its parent. The default |
| 4789 | * is true; if false, these views will not be saved unless |
| 4790 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 4791 | * |
| 4792 | * @return Returns true if the view state saving from parent is enabled, else false. |
| 4793 | * |
| 4794 | * @see #setSaveFromParentEnabled(boolean) |
| 4795 | */ |
| 4796 | public boolean isSaveFromParentEnabled() { |
| 4797 | return (mViewFlags & PARENT_SAVE_DISABLED_MASK) != PARENT_SAVE_DISABLED; |
| 4798 | } |
| 4799 | |
| 4800 | /** |
| 4801 | * Controls whether the entire hierarchy under this view will save its |
| 4802 | * state when a state saving traversal occurs from its parent. The default |
| 4803 | * is true; if false, these views will not be saved unless |
| 4804 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 4805 | * |
| 4806 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 4807 | * (the default) to allow it. |
| 4808 | * |
| 4809 | * @see #isSaveFromParentEnabled() |
| 4810 | * @see #setId(int) |
| 4811 | * @see #onSaveInstanceState() |
| 4812 | */ |
| 4813 | public void setSaveFromParentEnabled(boolean enabled) { |
| 4814 | setFlags(enabled ? 0 : PARENT_SAVE_DISABLED, PARENT_SAVE_DISABLED_MASK); |
| 4815 | } |
| 4816 | |
| 4817 | |
| 4818 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4819 | * Returns whether this View is able to take focus. |
| 4820 | * |
| 4821 | * @return True if this view can take focus, or false otherwise. |
| 4822 | * @attr ref android.R.styleable#View_focusable |
| 4823 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4824 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4825 | public final boolean isFocusable() { |
| 4826 | return FOCUSABLE == (mViewFlags & FOCUSABLE_MASK); |
| 4827 | } |
| 4828 | |
| 4829 | /** |
| 4830 | * When a view is focusable, it may not want to take focus when in touch mode. |
| 4831 | * For example, a button would like focus when the user is navigating via a D-pad |
| 4832 | * so that the user can click on it, but once the user starts touching the screen, |
| 4833 | * the button shouldn't take focus |
| 4834 | * @return Whether the view is focusable in touch mode. |
| 4835 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 4836 | */ |
| 4837 | @ViewDebug.ExportedProperty |
| 4838 | public final boolean isFocusableInTouchMode() { |
| 4839 | return FOCUSABLE_IN_TOUCH_MODE == (mViewFlags & FOCUSABLE_IN_TOUCH_MODE); |
| 4840 | } |
| 4841 | |
| 4842 | /** |
| 4843 | * Find the nearest view in the specified direction that can take focus. |
| 4844 | * This does not actually give focus to that view. |
| 4845 | * |
| 4846 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 4847 | * |
| 4848 | * @return The nearest focusable in the specified direction, or null if none |
| 4849 | * can be found. |
| 4850 | */ |
| 4851 | public View focusSearch(int direction) { |
| 4852 | if (mParent != null) { |
| 4853 | return mParent.focusSearch(this, direction); |
| 4854 | } else { |
| 4855 | return null; |
| 4856 | } |
| 4857 | } |
| 4858 | |
| 4859 | /** |
| 4860 | * This method is the last chance for the focused view and its ancestors to |
| 4861 | * respond to an arrow key. This is called when the focused view did not |
| 4862 | * consume the key internally, nor could the view system find a new view in |
| 4863 | * the requested direction to give focus to. |
| 4864 | * |
| 4865 | * @param focused The currently focused view. |
| 4866 | * @param direction The direction focus wants to move. One of FOCUS_UP, |
| 4867 | * FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT. |
| 4868 | * @return True if the this view consumed this unhandled move. |
| 4869 | */ |
| 4870 | public boolean dispatchUnhandledMove(View focused, int direction) { |
| 4871 | return false; |
| 4872 | } |
| 4873 | |
| 4874 | /** |
| 4875 | * 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] | 4876 | * use the root to look up the view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4877 | * @param root The root view of the hierarchy containing this view. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4878 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, |
| 4879 | * or FOCUS_BACKWARD. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4880 | * @return The user specified next view, or null if there is none. |
| 4881 | */ |
| 4882 | View findUserSetNextFocus(View root, int direction) { |
| 4883 | switch (direction) { |
| 4884 | case FOCUS_LEFT: |
| 4885 | if (mNextFocusLeftId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 4886 | return findViewInsideOutShouldExist(root, mNextFocusLeftId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4887 | case FOCUS_RIGHT: |
| 4888 | if (mNextFocusRightId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 4889 | return findViewInsideOutShouldExist(root, mNextFocusRightId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4890 | case FOCUS_UP: |
| 4891 | if (mNextFocusUpId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 4892 | return findViewInsideOutShouldExist(root, mNextFocusUpId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4893 | case FOCUS_DOWN: |
| 4894 | if (mNextFocusDownId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 4895 | return findViewInsideOutShouldExist(root, mNextFocusDownId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4896 | case FOCUS_FORWARD: |
| 4897 | if (mNextFocusForwardId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 4898 | return findViewInsideOutShouldExist(root, mNextFocusForwardId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4899 | case FOCUS_BACKWARD: { |
| 4900 | final int id = mID; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 4901 | return root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4902 | @Override |
| 4903 | public boolean apply(View t) { |
| 4904 | return t.mNextFocusForwardId == id; |
| 4905 | } |
| 4906 | }); |
| 4907 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4908 | } |
| 4909 | return null; |
| 4910 | } |
| 4911 | |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 4912 | private View findViewInsideOutShouldExist(View root, final int childViewId) { |
| 4913 | View result = root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
| 4914 | @Override |
| 4915 | public boolean apply(View t) { |
| 4916 | return t.mID == childViewId; |
| 4917 | } |
| 4918 | }); |
| 4919 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4920 | if (result == null) { |
| 4921 | Log.w(VIEW_LOG_TAG, "couldn't find next focus view specified " |
| 4922 | + "by user for id " + childViewId); |
| 4923 | } |
| 4924 | return result; |
| 4925 | } |
| 4926 | |
| 4927 | /** |
| 4928 | * Find and return all focusable views that are descendants of this view, |
| 4929 | * possibly including this view if it is focusable itself. |
| 4930 | * |
| 4931 | * @param direction The direction of the focus |
| 4932 | * @return A list of focusable views |
| 4933 | */ |
| 4934 | public ArrayList<View> getFocusables(int direction) { |
| 4935 | ArrayList<View> result = new ArrayList<View>(24); |
| 4936 | addFocusables(result, direction); |
| 4937 | return result; |
| 4938 | } |
| 4939 | |
| 4940 | /** |
| 4941 | * Add any focusable views that are descendants of this view (possibly |
| 4942 | * including this view if it is focusable itself) to views. If we are in touch mode, |
| 4943 | * only add views that are also focusable in touch mode. |
| 4944 | * |
| 4945 | * @param views Focusable views found so far |
| 4946 | * @param direction The direction of the focus |
| 4947 | */ |
| 4948 | public void addFocusables(ArrayList<View> views, int direction) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4949 | addFocusables(views, direction, FOCUSABLES_TOUCH_MODE); |
| 4950 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4951 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4952 | /** |
| 4953 | * Adds any focusable views that are descendants of this view (possibly |
| 4954 | * including this view if it is focusable itself) to views. This method |
| 4955 | * adds all focusable views regardless if we are in touch mode or |
| 4956 | * only views focusable in touch mode if we are in touch mode depending on |
| 4957 | * the focusable mode paramater. |
| 4958 | * |
| 4959 | * @param views Focusable views found so far or null if all we are interested is |
| 4960 | * the number of focusables. |
| 4961 | * @param direction The direction of the focus. |
| 4962 | * @param focusableMode The type of focusables to be added. |
| 4963 | * |
| 4964 | * @see #FOCUSABLES_ALL |
| 4965 | * @see #FOCUSABLES_TOUCH_MODE |
| 4966 | */ |
| 4967 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
| 4968 | if (!isFocusable()) { |
| 4969 | return; |
| 4970 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4971 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4972 | if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && |
| 4973 | isInTouchMode() && !isFocusableInTouchMode()) { |
| 4974 | return; |
| 4975 | } |
| 4976 | |
| 4977 | if (views != null) { |
| 4978 | views.add(this); |
| 4979 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4980 | } |
| 4981 | |
| 4982 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4983 | * Finds the Views that contain given text. The containment is case insensitive. |
| 4984 | * As View's text is considered any text content that View renders. |
| 4985 | * |
| 4986 | * @param outViews The output list of matching Views. |
| 4987 | * @param text The text to match against. |
| 4988 | */ |
| 4989 | public void findViewsWithText(ArrayList<View> outViews, CharSequence text) { |
| 4990 | } |
| 4991 | |
| 4992 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4993 | * Find and return all touchable views that are descendants of this view, |
| 4994 | * possibly including this view if it is touchable itself. |
| 4995 | * |
| 4996 | * @return A list of touchable views |
| 4997 | */ |
| 4998 | public ArrayList<View> getTouchables() { |
| 4999 | ArrayList<View> result = new ArrayList<View>(); |
| 5000 | addTouchables(result); |
| 5001 | return result; |
| 5002 | } |
| 5003 | |
| 5004 | /** |
| 5005 | * Add any touchable views that are descendants of this view (possibly |
| 5006 | * including this view if it is touchable itself) to views. |
| 5007 | * |
| 5008 | * @param views Touchable views found so far |
| 5009 | */ |
| 5010 | public void addTouchables(ArrayList<View> views) { |
| 5011 | final int viewFlags = mViewFlags; |
| 5012 | |
| 5013 | if (((viewFlags & CLICKABLE) == CLICKABLE || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) |
| 5014 | && (viewFlags & ENABLED_MASK) == ENABLED) { |
| 5015 | views.add(this); |
| 5016 | } |
| 5017 | } |
| 5018 | |
| 5019 | /** |
| 5020 | * Call this to try to give focus to a specific view or to one of its |
| 5021 | * descendants. |
| 5022 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5023 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 5024 | * false), or if it is focusable and it is not focusable in touch mode |
| 5025 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5026 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5027 | * 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] | 5028 | * have focus, and you want your parent to look for the next one. |
| 5029 | * |
| 5030 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with arguments |
| 5031 | * {@link #FOCUS_DOWN} and <code>null</code>. |
| 5032 | * |
| 5033 | * @return Whether this view or one of its descendants actually took focus. |
| 5034 | */ |
| 5035 | public final boolean requestFocus() { |
| 5036 | return requestFocus(View.FOCUS_DOWN); |
| 5037 | } |
| 5038 | |
| 5039 | |
| 5040 | /** |
| 5041 | * Call this to try to give focus to a specific view or to one of its |
| 5042 | * descendants and give it a hint about what direction focus is heading. |
| 5043 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5044 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 5045 | * false), or if it is focusable and it is not focusable in touch mode |
| 5046 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5047 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5048 | * 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] | 5049 | * have focus, and you want your parent to look for the next one. |
| 5050 | * |
| 5051 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with |
| 5052 | * <code>null</code> set for the previously focused rectangle. |
| 5053 | * |
| 5054 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 5055 | * @return Whether this view or one of its descendants actually took focus. |
| 5056 | */ |
| 5057 | public final boolean requestFocus(int direction) { |
| 5058 | return requestFocus(direction, null); |
| 5059 | } |
| 5060 | |
| 5061 | /** |
| 5062 | * Call this to try to give focus to a specific view or to one of its descendants |
| 5063 | * and give it hints about the direction and a specific rectangle that the focus |
| 5064 | * is coming from. The rectangle can help give larger views a finer grained hint |
| 5065 | * about where focus is coming from, and therefore, where to show selection, or |
| 5066 | * forward focus change internally. |
| 5067 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5068 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 5069 | * false), or if it is focusable and it is not focusable in touch mode |
| 5070 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5071 | * |
| 5072 | * A View will not take focus if it is not visible. |
| 5073 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5074 | * A View will not take focus if one of its parents has |
| 5075 | * {@link android.view.ViewGroup#getDescendantFocusability()} equal to |
| 5076 | * {@link ViewGroup#FOCUS_BLOCK_DESCENDANTS}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5077 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5078 | * 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] | 5079 | * have focus, and you want your parent to look for the next one. |
| 5080 | * |
| 5081 | * You may wish to override this method if your custom {@link View} has an internal |
| 5082 | * {@link View} that it wishes to forward the request to. |
| 5083 | * |
| 5084 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 5085 | * @param previouslyFocusedRect The rectangle (in this View's coordinate system) |
| 5086 | * to give a finer grained hint about where focus is coming from. May be null |
| 5087 | * if there is no hint. |
| 5088 | * @return Whether this view or one of its descendants actually took focus. |
| 5089 | */ |
| 5090 | public boolean requestFocus(int direction, Rect previouslyFocusedRect) { |
| 5091 | // need to be focusable |
| 5092 | if ((mViewFlags & FOCUSABLE_MASK) != FOCUSABLE || |
| 5093 | (mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 5094 | return false; |
| 5095 | } |
| 5096 | |
| 5097 | // need to be focusable in touch mode if in touch mode |
| 5098 | if (isInTouchMode() && |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5099 | (FOCUSABLE_IN_TOUCH_MODE != (mViewFlags & FOCUSABLE_IN_TOUCH_MODE))) { |
| 5100 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5101 | } |
| 5102 | |
| 5103 | // need to not have any parents blocking us |
| 5104 | if (hasAncestorThatBlocksDescendantFocus()) { |
| 5105 | return false; |
| 5106 | } |
| 5107 | |
| 5108 | handleFocusGainInternal(direction, previouslyFocusedRect); |
| 5109 | return true; |
| 5110 | } |
| 5111 | |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 5112 | /** Gets the ViewAncestor, or null if not attached. */ |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 5113 | /*package*/ ViewRootImpl getViewRootImpl() { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5114 | View root = getRootView(); |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 5115 | return root != null ? (ViewRootImpl)root.getParent() : null; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5116 | } |
| 5117 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5118 | /** |
| 5119 | * Call this to try to give focus to a specific view or to one of its descendants. This is a |
| 5120 | * special variant of {@link #requestFocus() } that will allow views that are not focuable in |
| 5121 | * touch mode to request focus when they are touched. |
| 5122 | * |
| 5123 | * @return Whether this view or one of its descendants actually took focus. |
| 5124 | * |
| 5125 | * @see #isInTouchMode() |
| 5126 | * |
| 5127 | */ |
| 5128 | public final boolean requestFocusFromTouch() { |
| 5129 | // Leave touch mode if we need to |
| 5130 | if (isInTouchMode()) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 5131 | ViewRootImpl viewRoot = getViewRootImpl(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5132 | if (viewRoot != null) { |
| 5133 | viewRoot.ensureTouchMode(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5134 | } |
| 5135 | } |
| 5136 | return requestFocus(View.FOCUS_DOWN); |
| 5137 | } |
| 5138 | |
| 5139 | /** |
| 5140 | * @return Whether any ancestor of this view blocks descendant focus. |
| 5141 | */ |
| 5142 | private boolean hasAncestorThatBlocksDescendantFocus() { |
| 5143 | ViewParent ancestor = mParent; |
| 5144 | while (ancestor instanceof ViewGroup) { |
| 5145 | final ViewGroup vgAncestor = (ViewGroup) ancestor; |
| 5146 | if (vgAncestor.getDescendantFocusability() == ViewGroup.FOCUS_BLOCK_DESCENDANTS) { |
| 5147 | return true; |
| 5148 | } else { |
| 5149 | ancestor = vgAncestor.getParent(); |
| 5150 | } |
| 5151 | } |
| 5152 | return false; |
| 5153 | } |
| 5154 | |
| 5155 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5156 | * @hide |
| 5157 | */ |
| 5158 | public void dispatchStartTemporaryDetach() { |
| 5159 | onStartTemporaryDetach(); |
| 5160 | } |
| 5161 | |
| 5162 | /** |
| 5163 | * 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] | 5164 | * {@link ViewGroup#detachViewFromParent(View) ViewGroup.detachViewFromParent}. |
| 5165 | * It will either be followed by {@link #onFinishTemporaryDetach()} or |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5166 | * {@link #onDetachedFromWindow()} when the container is done. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5167 | */ |
| 5168 | public void onStartTemporaryDetach() { |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5169 | removeUnsetPressCallback(); |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 5170 | mPrivateFlags |= CANCEL_NEXT_UP_EVENT; |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5171 | } |
| 5172 | |
| 5173 | /** |
| 5174 | * @hide |
| 5175 | */ |
| 5176 | public void dispatchFinishTemporaryDetach() { |
| 5177 | onFinishTemporaryDetach(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5178 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5180 | /** |
| 5181 | * Called after {@link #onStartTemporaryDetach} when the container is done |
| 5182 | * changing the view. |
| 5183 | */ |
| 5184 | public void onFinishTemporaryDetach() { |
| 5185 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5186 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5187 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5188 | * Return the global {@link KeyEvent.DispatcherState KeyEvent.DispatcherState} |
| 5189 | * for this view's window. Returns null if the view is not currently attached |
| 5190 | * 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] | 5191 | * just use the standard high-level event callbacks like |
| 5192 | * {@link #onKeyDown(int, KeyEvent)}. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5193 | */ |
| 5194 | public KeyEvent.DispatcherState getKeyDispatcherState() { |
| 5195 | return mAttachInfo != null ? mAttachInfo.mKeyDispatchState : null; |
| 5196 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 5197 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5198 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5199 | * Dispatch a key event before it is processed by any input method |
| 5200 | * associated with the view hierarchy. This can be used to intercept |
| 5201 | * key events in special situations before the IME consumes them; a |
| 5202 | * typical example would be handling the BACK key to update the application's |
| 5203 | * UI instead of allowing the IME to see it and close itself. |
| 5204 | * |
| 5205 | * @param event The key event to be dispatched. |
| 5206 | * @return True if the event was handled, false otherwise. |
| 5207 | */ |
| 5208 | public boolean dispatchKeyEventPreIme(KeyEvent event) { |
| 5209 | return onKeyPreIme(event.getKeyCode(), event); |
| 5210 | } |
| 5211 | |
| 5212 | /** |
| 5213 | * Dispatch a key event to the next view on the focus path. This path runs |
| 5214 | * from the top of the view tree down to the currently focused view. If this |
| 5215 | * view has focus, it will dispatch to itself. Otherwise it will dispatch |
| 5216 | * the next node down the focus path. This method also fires any key |
| 5217 | * listeners. |
| 5218 | * |
| 5219 | * @param event The key event to be dispatched. |
| 5220 | * @return True if the event was handled, false otherwise. |
| 5221 | */ |
| 5222 | public boolean dispatchKeyEvent(KeyEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5223 | if (mInputEventConsistencyVerifier != null) { |
| 5224 | mInputEventConsistencyVerifier.onKeyEvent(event, 0); |
| 5225 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5226 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5227 | // Give any attached key listener a first crack at the event. |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 5228 | //noinspection SimplifiableIfStatement |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5229 | if (mOnKeyListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5230 | && mOnKeyListener.onKey(this, event.getKeyCode(), event)) { |
| 5231 | return true; |
| 5232 | } |
| 5233 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5234 | if (event.dispatch(this, mAttachInfo != null |
| 5235 | ? mAttachInfo.mKeyDispatchState : null, this)) { |
| 5236 | return true; |
| 5237 | } |
| 5238 | |
| 5239 | if (mInputEventConsistencyVerifier != null) { |
| 5240 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 5241 | } |
| 5242 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5243 | } |
| 5244 | |
| 5245 | /** |
| 5246 | * Dispatches a key shortcut event. |
| 5247 | * |
| 5248 | * @param event The key event to be dispatched. |
| 5249 | * @return True if the event was handled by the view, false otherwise. |
| 5250 | */ |
| 5251 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 5252 | return onKeyShortcut(event.getKeyCode(), event); |
| 5253 | } |
| 5254 | |
| 5255 | /** |
| 5256 | * Pass the touch screen motion event down to the target view, or this |
| 5257 | * view if it is the target. |
| 5258 | * |
| 5259 | * @param event The motion event to be dispatched. |
| 5260 | * @return True if the event was handled by the view, false otherwise. |
| 5261 | */ |
| 5262 | public boolean dispatchTouchEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5263 | if (mInputEventConsistencyVerifier != null) { |
| 5264 | mInputEventConsistencyVerifier.onTouchEvent(event, 0); |
| 5265 | } |
| 5266 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5267 | if (onFilterTouchEventForSecurity(event)) { |
| 5268 | //noinspection SimplifiableIfStatement |
| 5269 | if (mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED && |
| 5270 | mOnTouchListener.onTouch(this, event)) { |
| 5271 | return true; |
| 5272 | } |
| 5273 | |
| 5274 | if (onTouchEvent(event)) { |
| 5275 | return true; |
| 5276 | } |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5277 | } |
| 5278 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5279 | if (mInputEventConsistencyVerifier != null) { |
| 5280 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5281 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5282 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5283 | } |
| 5284 | |
| 5285 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5286 | * Filter the touch event to apply security policies. |
| 5287 | * |
| 5288 | * @param event The motion event to be filtered. |
| 5289 | * @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] | 5290 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5291 | * @see #getFilterTouchesWhenObscured |
| 5292 | */ |
| 5293 | public boolean onFilterTouchEventForSecurity(MotionEvent event) { |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 5294 | //noinspection RedundantIfStatement |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5295 | if ((mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0 |
| 5296 | && (event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) { |
| 5297 | // Window is obscured, drop this touch. |
| 5298 | return false; |
| 5299 | } |
| 5300 | return true; |
| 5301 | } |
| 5302 | |
| 5303 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5304 | * Pass a trackball motion event down to the focused view. |
| 5305 | * |
| 5306 | * @param event The motion event to be dispatched. |
| 5307 | * @return True if the event was handled by the view, false otherwise. |
| 5308 | */ |
| 5309 | public boolean dispatchTrackballEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5310 | if (mInputEventConsistencyVerifier != null) { |
| 5311 | mInputEventConsistencyVerifier.onTrackballEvent(event, 0); |
| 5312 | } |
| 5313 | |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 5314 | return onTrackballEvent(event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5315 | } |
| 5316 | |
| 5317 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5318 | * Dispatch a generic motion event. |
| 5319 | * <p> |
| 5320 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 5321 | * 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] | 5322 | * 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] | 5323 | * to {@link #onHoverEvent(MotionEvent)}. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5324 | * </p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5325 | * |
| 5326 | * @param event The motion event to be dispatched. |
| 5327 | * @return True if the event was handled by the view, false otherwise. |
| 5328 | */ |
| 5329 | public boolean dispatchGenericMotionEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5330 | if (mInputEventConsistencyVerifier != null) { |
| 5331 | mInputEventConsistencyVerifier.onGenericMotionEvent(event, 0); |
| 5332 | } |
| 5333 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5334 | final int source = event.getSource(); |
| 5335 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 5336 | final int action = event.getAction(); |
| 5337 | if (action == MotionEvent.ACTION_HOVER_ENTER |
| 5338 | || action == MotionEvent.ACTION_HOVER_MOVE |
| 5339 | || action == MotionEvent.ACTION_HOVER_EXIT) { |
| 5340 | if (dispatchHoverEvent(event)) { |
| 5341 | return true; |
| 5342 | } |
| 5343 | } else if (dispatchGenericPointerEvent(event)) { |
| 5344 | return true; |
| 5345 | } |
| 5346 | } else if (dispatchGenericFocusedEvent(event)) { |
| 5347 | return true; |
| 5348 | } |
| 5349 | |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 5350 | if (dispatchGenericMotionEventInternal(event)) { |
| 5351 | return true; |
| 5352 | } |
| 5353 | |
| 5354 | if (mInputEventConsistencyVerifier != null) { |
| 5355 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 5356 | } |
| 5357 | return false; |
| 5358 | } |
| 5359 | |
| 5360 | private boolean dispatchGenericMotionEventInternal(MotionEvent event) { |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 5361 | //noinspection SimplifiableIfStatement |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5362 | if (mOnGenericMotionListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5363 | && mOnGenericMotionListener.onGenericMotion(this, event)) { |
| 5364 | return true; |
| 5365 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5366 | |
| 5367 | if (onGenericMotionEvent(event)) { |
| 5368 | return true; |
| 5369 | } |
| 5370 | |
| 5371 | if (mInputEventConsistencyVerifier != null) { |
| 5372 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 5373 | } |
| 5374 | return false; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5375 | } |
| 5376 | |
| 5377 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5378 | * Dispatch a hover event. |
| 5379 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5380 | * Do not call this method directly. |
| 5381 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5382 | * </p> |
| 5383 | * |
| 5384 | * @param event The motion event to be dispatched. |
| 5385 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5386 | */ |
| 5387 | protected boolean dispatchHoverEvent(MotionEvent event) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 5388 | //noinspection SimplifiableIfStatement |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 5389 | if (mOnHoverListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5390 | && mOnHoverListener.onHover(this, event)) { |
| 5391 | return true; |
| 5392 | } |
| 5393 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5394 | return onHoverEvent(event); |
| 5395 | } |
| 5396 | |
| 5397 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 5398 | * Returns true if the view has a child to which it has recently sent |
| 5399 | * {@link MotionEvent#ACTION_HOVER_ENTER}. If this view is hovered and |
| 5400 | * it does not have a hovered child, then it must be the innermost hovered view. |
| 5401 | * @hide |
| 5402 | */ |
| 5403 | protected boolean hasHoveredChild() { |
| 5404 | return false; |
| 5405 | } |
| 5406 | |
| 5407 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5408 | * Dispatch a generic motion event to the view under the first pointer. |
| 5409 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5410 | * Do not call this method directly. |
| 5411 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5412 | * </p> |
| 5413 | * |
| 5414 | * @param event The motion event to be dispatched. |
| 5415 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5416 | */ |
| 5417 | protected boolean dispatchGenericPointerEvent(MotionEvent event) { |
| 5418 | return false; |
| 5419 | } |
| 5420 | |
| 5421 | /** |
| 5422 | * Dispatch a generic motion event to the currently focused view. |
| 5423 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5424 | * Do not call this method directly. |
| 5425 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5426 | * </p> |
| 5427 | * |
| 5428 | * @param event The motion event to be dispatched. |
| 5429 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5430 | */ |
| 5431 | protected boolean dispatchGenericFocusedEvent(MotionEvent event) { |
| 5432 | return false; |
| 5433 | } |
| 5434 | |
| 5435 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5436 | * Dispatch a pointer event. |
| 5437 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5438 | * Dispatches touch related pointer events to {@link #onTouchEvent(MotionEvent)} and all |
| 5439 | * other events to {@link #onGenericMotionEvent(MotionEvent)}. This separation of concerns |
| 5440 | * reinforces the invariant that {@link #onTouchEvent(MotionEvent)} is really about touches |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5441 | * and should not be expected to handle other pointing device features. |
| 5442 | * </p> |
| 5443 | * |
| 5444 | * @param event The motion event to be dispatched. |
| 5445 | * @return True if the event was handled by the view, false otherwise. |
| 5446 | * @hide |
| 5447 | */ |
| 5448 | public final boolean dispatchPointerEvent(MotionEvent event) { |
| 5449 | if (event.isTouchEvent()) { |
| 5450 | return dispatchTouchEvent(event); |
| 5451 | } else { |
| 5452 | return dispatchGenericMotionEvent(event); |
| 5453 | } |
| 5454 | } |
| 5455 | |
| 5456 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5457 | * Called when the window containing this view gains or loses window focus. |
| 5458 | * ViewGroups should override to route to their children. |
| 5459 | * |
| 5460 | * @param hasFocus True if the window containing this view now has focus, |
| 5461 | * false otherwise. |
| 5462 | */ |
| 5463 | public void dispatchWindowFocusChanged(boolean hasFocus) { |
| 5464 | onWindowFocusChanged(hasFocus); |
| 5465 | } |
| 5466 | |
| 5467 | /** |
| 5468 | * Called when the window containing this view gains or loses focus. Note |
| 5469 | * that this is separate from view focus: to receive key events, both |
| 5470 | * your view and its window must have focus. If a window is displayed |
| 5471 | * on top of yours that takes input focus, then your own window will lose |
| 5472 | * focus but the view focus will remain unchanged. |
| 5473 | * |
| 5474 | * @param hasWindowFocus True if the window containing this view now has |
| 5475 | * focus, false otherwise. |
| 5476 | */ |
| 5477 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 5478 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 5479 | if (!hasWindowFocus) { |
| 5480 | if (isPressed()) { |
| 5481 | setPressed(false); |
| 5482 | } |
| 5483 | if (imm != null && (mPrivateFlags & FOCUSED) != 0) { |
| 5484 | imm.focusOut(this); |
| 5485 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 5486 | removeLongPressCallback(); |
Tony Wu | 26edf20 | 2010-09-13 19:54:00 +0800 | [diff] [blame] | 5487 | removeTapCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 5488 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5489 | } else if (imm != null && (mPrivateFlags & FOCUSED) != 0) { |
| 5490 | imm.focusIn(this); |
| 5491 | } |
| 5492 | refreshDrawableState(); |
| 5493 | } |
| 5494 | |
| 5495 | /** |
| 5496 | * Returns true if this view is in a window that currently has window focus. |
| 5497 | * Note that this is not the same as the view itself having focus. |
| 5498 | * |
| 5499 | * @return True if this view is in a window that currently has window focus. |
| 5500 | */ |
| 5501 | public boolean hasWindowFocus() { |
| 5502 | return mAttachInfo != null && mAttachInfo.mHasWindowFocus; |
| 5503 | } |
| 5504 | |
| 5505 | /** |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 5506 | * Dispatch a view visibility change down the view hierarchy. |
| 5507 | * ViewGroups should override to route to their children. |
| 5508 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 5509 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 5510 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 5511 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 5512 | */ |
| 5513 | protected void dispatchVisibilityChanged(View changedView, int visibility) { |
| 5514 | onVisibilityChanged(changedView, visibility); |
| 5515 | } |
| 5516 | |
| 5517 | /** |
| 5518 | * Called when the visibility of the view or an ancestor of the view is changed. |
| 5519 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 5520 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 5521 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 5522 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 5523 | */ |
| 5524 | protected void onVisibilityChanged(View changedView, int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 5525 | if (visibility == VISIBLE) { |
| 5526 | if (mAttachInfo != null) { |
| 5527 | initialAwakenScrollBars(); |
| 5528 | } else { |
| 5529 | mPrivateFlags |= AWAKEN_SCROLL_BARS_ON_ATTACH; |
| 5530 | } |
| 5531 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 5532 | } |
| 5533 | |
| 5534 | /** |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 5535 | * Dispatch a hint about whether this view is displayed. For instance, when |
| 5536 | * a View moves out of the screen, it might receives a display hint indicating |
| 5537 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 5538 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 5539 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 5540 | * @param hint A hint about whether or not this view is displayed: |
| 5541 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 5542 | */ |
| 5543 | public void dispatchDisplayHint(int hint) { |
| 5544 | onDisplayHint(hint); |
| 5545 | } |
| 5546 | |
| 5547 | /** |
| 5548 | * Gives this view a hint about whether is displayed or not. For instance, when |
| 5549 | * a View moves out of the screen, it might receives a display hint indicating |
| 5550 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 5551 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 5552 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 5553 | * @param hint A hint about whether or not this view is displayed: |
| 5554 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 5555 | */ |
| 5556 | protected void onDisplayHint(int hint) { |
| 5557 | } |
| 5558 | |
| 5559 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5560 | * Dispatch a window visibility change down the view hierarchy. |
| 5561 | * ViewGroups should override to route to their children. |
| 5562 | * |
| 5563 | * @param visibility The new visibility of the window. |
| 5564 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5565 | * @see #onWindowVisibilityChanged(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5566 | */ |
| 5567 | public void dispatchWindowVisibilityChanged(int visibility) { |
| 5568 | onWindowVisibilityChanged(visibility); |
| 5569 | } |
| 5570 | |
| 5571 | /** |
| 5572 | * Called when the window containing has change its visibility |
| 5573 | * (between {@link #GONE}, {@link #INVISIBLE}, and {@link #VISIBLE}). Note |
| 5574 | * that this tells you whether or not your window is being made visible |
| 5575 | * to the window manager; this does <em>not</em> tell you whether or not |
| 5576 | * your window is obscured by other windows on the screen, even if it |
| 5577 | * is itself visible. |
| 5578 | * |
| 5579 | * @param visibility The new visibility of the window. |
| 5580 | */ |
| 5581 | protected void onWindowVisibilityChanged(int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 5582 | if (visibility == VISIBLE) { |
| 5583 | initialAwakenScrollBars(); |
| 5584 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5585 | } |
| 5586 | |
| 5587 | /** |
| 5588 | * Returns the current visibility of the window this view is attached to |
| 5589 | * (either {@link #GONE}, {@link #INVISIBLE}, or {@link #VISIBLE}). |
| 5590 | * |
| 5591 | * @return Returns the current visibility of the view's window. |
| 5592 | */ |
| 5593 | public int getWindowVisibility() { |
| 5594 | return mAttachInfo != null ? mAttachInfo.mWindowVisibility : GONE; |
| 5595 | } |
| 5596 | |
| 5597 | /** |
| 5598 | * Retrieve the overall visible display size in which the window this view is |
| 5599 | * attached to has been positioned in. This takes into account screen |
| 5600 | * decorations above the window, for both cases where the window itself |
| 5601 | * is being position inside of them or the window is being placed under |
| 5602 | * then and covered insets are used for the window to position its content |
| 5603 | * inside. In effect, this tells you the available area where content can |
| 5604 | * be placed and remain visible to users. |
| 5605 | * |
| 5606 | * <p>This function requires an IPC back to the window manager to retrieve |
| 5607 | * the requested information, so should not be used in performance critical |
| 5608 | * code like drawing. |
| 5609 | * |
| 5610 | * @param outRect Filled in with the visible display frame. If the view |
| 5611 | * is not attached to a window, this is simply the raw display size. |
| 5612 | */ |
| 5613 | public void getWindowVisibleDisplayFrame(Rect outRect) { |
| 5614 | if (mAttachInfo != null) { |
| 5615 | try { |
| 5616 | mAttachInfo.mSession.getDisplayFrame(mAttachInfo.mWindow, outRect); |
| 5617 | } catch (RemoteException e) { |
| 5618 | return; |
| 5619 | } |
| 5620 | // XXX This is really broken, and probably all needs to be done |
| 5621 | // in the window manager, and we need to know more about whether |
| 5622 | // we want the area behind or in front of the IME. |
| 5623 | final Rect insets = mAttachInfo.mVisibleInsets; |
| 5624 | outRect.left += insets.left; |
| 5625 | outRect.top += insets.top; |
| 5626 | outRect.right -= insets.right; |
| 5627 | outRect.bottom -= insets.bottom; |
| 5628 | return; |
| 5629 | } |
| 5630 | Display d = WindowManagerImpl.getDefault().getDefaultDisplay(); |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 5631 | d.getRectSize(outRect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5632 | } |
| 5633 | |
| 5634 | /** |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5635 | * Dispatch a notification about a resource configuration change down |
| 5636 | * the view hierarchy. |
| 5637 | * ViewGroups should override to route to their children. |
| 5638 | * |
| 5639 | * @param newConfig The new resource configuration. |
| 5640 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5641 | * @see #onConfigurationChanged(android.content.res.Configuration) |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5642 | */ |
| 5643 | public void dispatchConfigurationChanged(Configuration newConfig) { |
| 5644 | onConfigurationChanged(newConfig); |
| 5645 | } |
| 5646 | |
| 5647 | /** |
| 5648 | * Called when the current configuration of the resources being used |
| 5649 | * by the application have changed. You can use this to decide when |
| 5650 | * to reload resources that can changed based on orientation and other |
| 5651 | * configuration characterstics. You only need to use this if you are |
| 5652 | * not relying on the normal {@link android.app.Activity} mechanism of |
| 5653 | * recreating the activity instance upon a configuration change. |
| 5654 | * |
| 5655 | * @param newConfig The new resource configuration. |
| 5656 | */ |
| 5657 | protected void onConfigurationChanged(Configuration newConfig) { |
| 5658 | } |
| 5659 | |
| 5660 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5661 | * Private function to aggregate all per-view attributes in to the view |
| 5662 | * root. |
| 5663 | */ |
| 5664 | void dispatchCollectViewAttributes(int visibility) { |
| 5665 | performCollectViewAttributes(visibility); |
| 5666 | } |
| 5667 | |
| 5668 | void performCollectViewAttributes(int visibility) { |
Romain Guy | d30b36d | 2011-01-26 10:54:43 -0800 | [diff] [blame] | 5669 | if ((visibility & VISIBILITY_MASK) == VISIBLE && mAttachInfo != null) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5670 | if ((mViewFlags & KEEP_SCREEN_ON) == KEEP_SCREEN_ON) { |
| 5671 | mAttachInfo.mKeepScreenOn = true; |
| 5672 | } |
| 5673 | mAttachInfo.mSystemUiVisibility |= mSystemUiVisibility; |
| 5674 | if (mOnSystemUiVisibilityChangeListener != null) { |
| 5675 | mAttachInfo.mHasSystemUiListeners = true; |
| 5676 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5677 | } |
| 5678 | } |
| 5679 | |
| 5680 | void needGlobalAttributesUpdate(boolean force) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5681 | final AttachInfo ai = mAttachInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5682 | if (ai != null) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5683 | if (force || ai.mKeepScreenOn || (ai.mSystemUiVisibility != 0) |
| 5684 | || ai.mHasSystemUiListeners) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5685 | ai.mRecomputeGlobalAttributes = true; |
| 5686 | } |
| 5687 | } |
| 5688 | } |
| 5689 | |
| 5690 | /** |
| 5691 | * Returns whether the device is currently in touch mode. Touch mode is entered |
| 5692 | * once the user begins interacting with the device by touch, and affects various |
| 5693 | * things like whether focus is always visible to the user. |
| 5694 | * |
| 5695 | * @return Whether the device is in touch mode. |
| 5696 | */ |
| 5697 | @ViewDebug.ExportedProperty |
| 5698 | public boolean isInTouchMode() { |
| 5699 | if (mAttachInfo != null) { |
| 5700 | return mAttachInfo.mInTouchMode; |
| 5701 | } else { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 5702 | return ViewRootImpl.isInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5703 | } |
| 5704 | } |
| 5705 | |
| 5706 | /** |
| 5707 | * Returns the context the view is running in, through which it can |
| 5708 | * access the current theme, resources, etc. |
| 5709 | * |
| 5710 | * @return The view's Context. |
| 5711 | */ |
| 5712 | @ViewDebug.CapturedViewProperty |
| 5713 | public final Context getContext() { |
| 5714 | return mContext; |
| 5715 | } |
| 5716 | |
| 5717 | /** |
| 5718 | * Handle a key event before it is processed by any input method |
| 5719 | * associated with the view hierarchy. This can be used to intercept |
| 5720 | * key events in special situations before the IME consumes them; a |
| 5721 | * typical example would be handling the BACK key to update the application's |
| 5722 | * UI instead of allowing the IME to see it and close itself. |
| 5723 | * |
| 5724 | * @param keyCode The value in event.getKeyCode(). |
| 5725 | * @param event Description of the key event. |
| 5726 | * @return If you handled the event, return true. If you want to allow the |
| 5727 | * event to be handled by the next receiver, return false. |
| 5728 | */ |
| 5729 | public boolean onKeyPreIme(int keyCode, KeyEvent event) { |
| 5730 | return false; |
| 5731 | } |
| 5732 | |
| 5733 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 5734 | * Default implementation of {@link KeyEvent.Callback#onKeyDown(int, KeyEvent) |
| 5735 | * KeyEvent.Callback.onKeyDown()}: perform press of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5736 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or {@link KeyEvent#KEYCODE_ENTER} |
| 5737 | * is released, if the view is enabled and clickable. |
| 5738 | * |
| 5739 | * @param keyCode A key code that represents the button pressed, from |
| 5740 | * {@link android.view.KeyEvent}. |
| 5741 | * @param event The KeyEvent object that defines the button action. |
| 5742 | */ |
| 5743 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 5744 | boolean result = false; |
| 5745 | |
| 5746 | switch (keyCode) { |
| 5747 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 5748 | case KeyEvent.KEYCODE_ENTER: { |
| 5749 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 5750 | return true; |
| 5751 | } |
| 5752 | // Long clickable items don't necessarily have to be clickable |
| 5753 | if (((mViewFlags & CLICKABLE) == CLICKABLE || |
| 5754 | (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) && |
| 5755 | (event.getRepeatCount() == 0)) { |
| 5756 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 5757 | checkForLongClick(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5758 | return true; |
| 5759 | } |
| 5760 | break; |
| 5761 | } |
| 5762 | } |
| 5763 | return result; |
| 5764 | } |
| 5765 | |
| 5766 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5767 | * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
| 5768 | * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle |
| 5769 | * the event). |
| 5770 | */ |
| 5771 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 5772 | return false; |
| 5773 | } |
| 5774 | |
| 5775 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 5776 | * Default implementation of {@link KeyEvent.Callback#onKeyUp(int, KeyEvent) |
| 5777 | * KeyEvent.Callback.onKeyUp()}: perform clicking of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5778 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or |
| 5779 | * {@link KeyEvent#KEYCODE_ENTER} is released. |
| 5780 | * |
| 5781 | * @param keyCode A key code that represents the button pressed, from |
| 5782 | * {@link android.view.KeyEvent}. |
| 5783 | * @param event The KeyEvent object that defines the button action. |
| 5784 | */ |
| 5785 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 5786 | boolean result = false; |
| 5787 | |
| 5788 | switch (keyCode) { |
| 5789 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 5790 | case KeyEvent.KEYCODE_ENTER: { |
| 5791 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 5792 | return true; |
| 5793 | } |
| 5794 | if ((mViewFlags & CLICKABLE) == CLICKABLE && isPressed()) { |
| 5795 | setPressed(false); |
| 5796 | |
| 5797 | if (!mHasPerformedLongPress) { |
| 5798 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 5799 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5800 | |
| 5801 | result = performClick(); |
| 5802 | } |
| 5803 | } |
| 5804 | break; |
| 5805 | } |
| 5806 | } |
| 5807 | return result; |
| 5808 | } |
| 5809 | |
| 5810 | /** |
| 5811 | * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) |
| 5812 | * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle |
| 5813 | * the event). |
| 5814 | * |
| 5815 | * @param keyCode A key code that represents the button pressed, from |
| 5816 | * {@link android.view.KeyEvent}. |
| 5817 | * @param repeatCount The number of times the action was made. |
| 5818 | * @param event The KeyEvent object that defines the button action. |
| 5819 | */ |
| 5820 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 5821 | return false; |
| 5822 | } |
| 5823 | |
| 5824 | /** |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 5825 | * Called on the focused view when a key shortcut event is not handled. |
| 5826 | * Override this method to implement local key shortcuts for the View. |
| 5827 | * Key shortcuts can also be implemented by setting the |
| 5828 | * {@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] | 5829 | * |
| 5830 | * @param keyCode The value in event.getKeyCode(). |
| 5831 | * @param event Description of the key event. |
| 5832 | * @return If you handled the event, return true. If you want to allow the |
| 5833 | * event to be handled by the next receiver, return false. |
| 5834 | */ |
| 5835 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
| 5836 | return false; |
| 5837 | } |
| 5838 | |
| 5839 | /** |
| 5840 | * Check whether the called view is a text editor, in which case it |
| 5841 | * would make sense to automatically display a soft input window for |
| 5842 | * it. Subclasses should override this if they implement |
| 5843 | * {@link #onCreateInputConnection(EditorInfo)} to return true if |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 5844 | * a call on that method would return a non-null InputConnection, and |
| 5845 | * they are really a first-class editor that the user would normally |
| 5846 | * start typing on when the go into a window containing your view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5847 | * |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 5848 | * <p>The default implementation always returns false. This does |
| 5849 | * <em>not</em> mean that its {@link #onCreateInputConnection(EditorInfo)} |
| 5850 | * will not be called or the user can not otherwise perform edits on your |
| 5851 | * view; it is just a hint to the system that this is not the primary |
| 5852 | * purpose of this view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5853 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5854 | * @return Returns true if this view is a text editor, else false. |
| 5855 | */ |
| 5856 | public boolean onCheckIsTextEditor() { |
| 5857 | return false; |
| 5858 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5859 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5860 | /** |
| 5861 | * Create a new InputConnection for an InputMethod to interact |
| 5862 | * with the view. The default implementation returns null, since it doesn't |
| 5863 | * support input methods. You can override this to implement such support. |
| 5864 | * This is only needed for views that take focus and text input. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5865 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5866 | * <p>When implementing this, you probably also want to implement |
| 5867 | * {@link #onCheckIsTextEditor()} to indicate you will return a |
| 5868 | * non-null InputConnection. |
| 5869 | * |
| 5870 | * @param outAttrs Fill in with attribute information about the connection. |
| 5871 | */ |
| 5872 | public InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
| 5873 | return null; |
| 5874 | } |
| 5875 | |
| 5876 | /** |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 5877 | * Called by the {@link android.view.inputmethod.InputMethodManager} |
| 5878 | * when a view who is not the current |
| 5879 | * input connection target is trying to make a call on the manager. The |
| 5880 | * default implementation returns false; you can override this to return |
| 5881 | * true for certain views if you are performing InputConnection proxying |
| 5882 | * to them. |
| 5883 | * @param view The View that is making the InputMethodManager call. |
| 5884 | * @return Return true to allow the call, false to reject. |
| 5885 | */ |
| 5886 | public boolean checkInputConnectionProxy(View view) { |
| 5887 | return false; |
| 5888 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5889 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 5890 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5891 | * Show the context menu for this view. It is not safe to hold on to the |
| 5892 | * menu after returning from this method. |
| 5893 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 5894 | * You should normally not overload this method. Overload |
| 5895 | * {@link #onCreateContextMenu(ContextMenu)} or define an |
| 5896 | * {@link OnCreateContextMenuListener} to add items to the context menu. |
| 5897 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5898 | * @param menu The context menu to populate |
| 5899 | */ |
| 5900 | public void createContextMenu(ContextMenu menu) { |
| 5901 | ContextMenuInfo menuInfo = getContextMenuInfo(); |
| 5902 | |
| 5903 | // Sets the current menu info so all items added to menu will have |
| 5904 | // my extra info set. |
| 5905 | ((MenuBuilder)menu).setCurrentMenuInfo(menuInfo); |
| 5906 | |
| 5907 | onCreateContextMenu(menu); |
| 5908 | if (mOnCreateContextMenuListener != null) { |
| 5909 | mOnCreateContextMenuListener.onCreateContextMenu(menu, this, menuInfo); |
| 5910 | } |
| 5911 | |
| 5912 | // Clear the extra information so subsequent items that aren't mine don't |
| 5913 | // have my extra info. |
| 5914 | ((MenuBuilder)menu).setCurrentMenuInfo(null); |
| 5915 | |
| 5916 | if (mParent != null) { |
| 5917 | mParent.createContextMenu(menu); |
| 5918 | } |
| 5919 | } |
| 5920 | |
| 5921 | /** |
| 5922 | * Views should implement this if they have extra information to associate |
| 5923 | * with the context menu. The return result is supplied as a parameter to |
| 5924 | * the {@link OnCreateContextMenuListener#onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} |
| 5925 | * callback. |
| 5926 | * |
| 5927 | * @return Extra information about the item for which the context menu |
| 5928 | * should be shown. This information will vary across different |
| 5929 | * subclasses of View. |
| 5930 | */ |
| 5931 | protected ContextMenuInfo getContextMenuInfo() { |
| 5932 | return null; |
| 5933 | } |
| 5934 | |
| 5935 | /** |
| 5936 | * Views should implement this if the view itself is going to add items to |
| 5937 | * the context menu. |
| 5938 | * |
| 5939 | * @param menu the context menu to populate |
| 5940 | */ |
| 5941 | protected void onCreateContextMenu(ContextMenu menu) { |
| 5942 | } |
| 5943 | |
| 5944 | /** |
| 5945 | * Implement this method to handle trackball motion events. The |
| 5946 | * <em>relative</em> movement of the trackball since the last event |
| 5947 | * can be retrieve with {@link MotionEvent#getX MotionEvent.getX()} and |
| 5948 | * {@link MotionEvent#getY MotionEvent.getY()}. These are normalized so |
| 5949 | * that a movement of 1 corresponds to the user pressing one DPAD key (so |
| 5950 | * they will often be fractional values, representing the more fine-grained |
| 5951 | * movement information available from a trackball). |
| 5952 | * |
| 5953 | * @param event The motion event. |
| 5954 | * @return True if the event was handled, false otherwise. |
| 5955 | */ |
| 5956 | public boolean onTrackballEvent(MotionEvent event) { |
| 5957 | return false; |
| 5958 | } |
| 5959 | |
| 5960 | /** |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5961 | * Implement this method to handle generic motion events. |
| 5962 | * <p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5963 | * Generic motion events describe joystick movements, mouse hovers, track pad |
| 5964 | * touches, scroll wheel movements and other input events. The |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5965 | * {@link MotionEvent#getSource() source} of the motion event specifies |
| 5966 | * the class of input that was received. Implementations of this method |
| 5967 | * must examine the bits in the source before processing the event. |
| 5968 | * The following code example shows how this is done. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5969 | * </p><p> |
| 5970 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 5971 | * are delivered to the view under the pointer. All other generic motion events are |
| 5972 | * delivered to the focused view. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5973 | * </p> |
| 5974 | * <code> |
| 5975 | * public boolean onGenericMotionEvent(MotionEvent event) { |
| 5976 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5977 | * if (event.getAction() == MotionEvent.ACTION_MOVE) { |
| 5978 | * // process the joystick movement... |
| 5979 | * return true; |
| 5980 | * } |
| 5981 | * } |
| 5982 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 5983 | * switch (event.getAction()) { |
| 5984 | * case MotionEvent.ACTION_HOVER_MOVE: |
| 5985 | * // process the mouse hover movement... |
| 5986 | * return true; |
| 5987 | * case MotionEvent.ACTION_SCROLL: |
| 5988 | * // process the scroll wheel movement... |
| 5989 | * return true; |
| 5990 | * } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5991 | * } |
| 5992 | * return super.onGenericMotionEvent(event); |
| 5993 | * } |
| 5994 | * </code> |
| 5995 | * |
| 5996 | * @param event The generic motion event being processed. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5997 | * @return True if the event was handled, false otherwise. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5998 | */ |
| 5999 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 6000 | return false; |
| 6001 | } |
| 6002 | |
| 6003 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6004 | * Implement this method to handle hover events. |
| 6005 | * <p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6006 | * This method is called whenever a pointer is hovering into, over, or out of the |
| 6007 | * bounds of a view and the view is not currently being touched. |
| 6008 | * Hover events are represented as pointer events with action |
| 6009 | * {@link MotionEvent#ACTION_HOVER_ENTER}, {@link MotionEvent#ACTION_HOVER_MOVE}, |
| 6010 | * or {@link MotionEvent#ACTION_HOVER_EXIT}. |
| 6011 | * </p> |
| 6012 | * <ul> |
| 6013 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_ENTER} |
| 6014 | * when the pointer enters the bounds of the view.</li> |
| 6015 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_MOVE} |
| 6016 | * when the pointer has already entered the bounds of the view and has moved.</li> |
| 6017 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_EXIT} |
| 6018 | * when the pointer has exited the bounds of the view or when the pointer is |
| 6019 | * about to go down due to a button click, tap, or similar user action that |
| 6020 | * causes the view to be touched.</li> |
| 6021 | * </ul> |
| 6022 | * <p> |
| 6023 | * The view should implement this method to return true to indicate that it is |
| 6024 | * handling the hover event, such as by changing its drawable state. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6025 | * </p><p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6026 | * The default implementation calls {@link #setHovered} to update the hovered state |
| 6027 | * 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] | 6028 | * is enabled and is clickable. The default implementation also sends hover |
| 6029 | * accessibility events. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6030 | * </p> |
| 6031 | * |
| 6032 | * @param event The motion event that describes the hover. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6033 | * @return True if the view handled the hover event. |
| 6034 | * |
| 6035 | * @see #isHovered |
| 6036 | * @see #setHovered |
| 6037 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6038 | */ |
| 6039 | public boolean onHoverEvent(MotionEvent event) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 6040 | // The root view may receive hover (or touch) events that are outside the bounds of |
| 6041 | // the window. This code ensures that we only send accessibility events for |
| 6042 | // hovers that are actually within the bounds of the root view. |
| 6043 | final int action = event.getAction(); |
| 6044 | if (!mSendingHoverAccessibilityEvents) { |
| 6045 | if ((action == MotionEvent.ACTION_HOVER_ENTER |
| 6046 | || action == MotionEvent.ACTION_HOVER_MOVE) |
| 6047 | && !hasHoveredChild() |
| 6048 | && pointInView(event.getX(), event.getY())) { |
| 6049 | mSendingHoverAccessibilityEvents = true; |
| 6050 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER); |
| 6051 | } |
| 6052 | } else { |
| 6053 | if (action == MotionEvent.ACTION_HOVER_EXIT |
| 6054 | || (action == MotionEvent.ACTION_HOVER_MOVE |
| 6055 | && !pointInView(event.getX(), event.getY()))) { |
| 6056 | mSendingHoverAccessibilityEvents = false; |
| 6057 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT); |
| 6058 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 6059 | } |
| 6060 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6061 | if (isHoverable()) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 6062 | switch (action) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6063 | case MotionEvent.ACTION_HOVER_ENTER: |
| 6064 | setHovered(true); |
| 6065 | break; |
| 6066 | case MotionEvent.ACTION_HOVER_EXIT: |
| 6067 | setHovered(false); |
| 6068 | break; |
| 6069 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 6070 | |
| 6071 | // Dispatch the event to onGenericMotionEvent before returning true. |
| 6072 | // This is to provide compatibility with existing applications that |
| 6073 | // handled HOVER_MOVE events in onGenericMotionEvent and that would |
| 6074 | // break because of the new default handling for hoverable views |
| 6075 | // in onHoverEvent. |
| 6076 | // Note that onGenericMotionEvent will be called by default when |
| 6077 | // onHoverEvent returns false (refer to dispatchGenericMotionEvent). |
| 6078 | dispatchGenericMotionEventInternal(event); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6079 | return true; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6080 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6081 | return false; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6082 | } |
| 6083 | |
| 6084 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6085 | * Returns true if the view should handle {@link #onHoverEvent} |
| 6086 | * by calling {@link #setHovered} to change its hovered state. |
| 6087 | * |
| 6088 | * @return True if the view is hoverable. |
| 6089 | */ |
| 6090 | private boolean isHoverable() { |
| 6091 | final int viewFlags = mViewFlags; |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 6092 | //noinspection SimplifiableIfStatement |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6093 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
| 6094 | return false; |
| 6095 | } |
| 6096 | |
| 6097 | return (viewFlags & CLICKABLE) == CLICKABLE |
| 6098 | || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 6099 | } |
| 6100 | |
| 6101 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6102 | * Returns true if the view is currently hovered. |
| 6103 | * |
| 6104 | * @return True if the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6105 | * |
| 6106 | * @see #setHovered |
| 6107 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6108 | */ |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6109 | @ViewDebug.ExportedProperty |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6110 | public boolean isHovered() { |
| 6111 | return (mPrivateFlags & HOVERED) != 0; |
| 6112 | } |
| 6113 | |
| 6114 | /** |
| 6115 | * Sets whether the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6116 | * <p> |
| 6117 | * Calling this method also changes the drawable state of the view. This |
| 6118 | * enables the view to react to hover by using different drawable resources |
| 6119 | * to change its appearance. |
| 6120 | * </p><p> |
| 6121 | * The {@link #onHoverChanged} method is called when the hovered state changes. |
| 6122 | * </p> |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6123 | * |
| 6124 | * @param hovered True if the view is hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6125 | * |
| 6126 | * @see #isHovered |
| 6127 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6128 | */ |
| 6129 | public void setHovered(boolean hovered) { |
| 6130 | if (hovered) { |
| 6131 | if ((mPrivateFlags & HOVERED) == 0) { |
| 6132 | mPrivateFlags |= HOVERED; |
| 6133 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6134 | onHoverChanged(true); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6135 | } |
| 6136 | } else { |
| 6137 | if ((mPrivateFlags & HOVERED) != 0) { |
| 6138 | mPrivateFlags &= ~HOVERED; |
| 6139 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6140 | onHoverChanged(false); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6141 | } |
| 6142 | } |
| 6143 | } |
| 6144 | |
| 6145 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6146 | * Implement this method to handle hover state changes. |
| 6147 | * <p> |
| 6148 | * This method is called whenever the hover state changes as a result of a |
| 6149 | * call to {@link #setHovered}. |
| 6150 | * </p> |
| 6151 | * |
| 6152 | * @param hovered The current hover state, as returned by {@link #isHovered}. |
| 6153 | * |
| 6154 | * @see #isHovered |
| 6155 | * @see #setHovered |
| 6156 | */ |
| 6157 | public void onHoverChanged(boolean hovered) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6158 | } |
| 6159 | |
| 6160 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6161 | * Implement this method to handle touch screen motion events. |
| 6162 | * |
| 6163 | * @param event The motion event. |
| 6164 | * @return True if the event was handled, false otherwise. |
| 6165 | */ |
| 6166 | public boolean onTouchEvent(MotionEvent event) { |
| 6167 | final int viewFlags = mViewFlags; |
| 6168 | |
| 6169 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
Svetoslav Ganov | 77b80c0 | 2011-03-15 20:52:58 -0700 | [diff] [blame] | 6170 | if (event.getAction() == MotionEvent.ACTION_UP && (mPrivateFlags & PRESSED) != 0) { |
| 6171 | mPrivateFlags &= ~PRESSED; |
| 6172 | refreshDrawableState(); |
| 6173 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6174 | // A disabled view that is clickable still consumes the touch |
| 6175 | // events, it just doesn't respond to them. |
| 6176 | return (((viewFlags & CLICKABLE) == CLICKABLE || |
| 6177 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)); |
| 6178 | } |
| 6179 | |
| 6180 | if (mTouchDelegate != null) { |
| 6181 | if (mTouchDelegate.onTouchEvent(event)) { |
| 6182 | return true; |
| 6183 | } |
| 6184 | } |
| 6185 | |
| 6186 | if (((viewFlags & CLICKABLE) == CLICKABLE || |
| 6187 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)) { |
| 6188 | switch (event.getAction()) { |
| 6189 | case MotionEvent.ACTION_UP: |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6190 | boolean prepressed = (mPrivateFlags & PREPRESSED) != 0; |
| 6191 | if ((mPrivateFlags & PRESSED) != 0 || prepressed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6192 | // take focus if we don't have it already and we should in |
| 6193 | // touch mode. |
| 6194 | boolean focusTaken = false; |
| 6195 | if (isFocusable() && isFocusableInTouchMode() && !isFocused()) { |
| 6196 | focusTaken = requestFocus(); |
| 6197 | } |
| 6198 | |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 6199 | if (prepressed) { |
| 6200 | // The button is being released before we actually |
| 6201 | // showed it as pressed. Make it show the pressed |
| 6202 | // state now (before scheduling the click) to ensure |
| 6203 | // the user sees it. |
| 6204 | mPrivateFlags |= PRESSED; |
| 6205 | refreshDrawableState(); |
| 6206 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6208 | if (!mHasPerformedLongPress) { |
| 6209 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6210 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6211 | |
| 6212 | // Only perform take click actions if we were in the pressed state |
| 6213 | if (!focusTaken) { |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 6214 | // Use a Runnable and post this rather than calling |
| 6215 | // performClick directly. This lets other visual state |
| 6216 | // of the view update before click actions start. |
| 6217 | if (mPerformClick == null) { |
| 6218 | mPerformClick = new PerformClick(); |
| 6219 | } |
| 6220 | if (!post(mPerformClick)) { |
| 6221 | performClick(); |
| 6222 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6223 | } |
| 6224 | } |
| 6225 | |
| 6226 | if (mUnsetPressedState == null) { |
| 6227 | mUnsetPressedState = new UnsetPressedState(); |
| 6228 | } |
| 6229 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6230 | if (prepressed) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6231 | postDelayed(mUnsetPressedState, |
| 6232 | ViewConfiguration.getPressedStateDuration()); |
| 6233 | } else if (!post(mUnsetPressedState)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6234 | // If the post failed, unpress right now |
| 6235 | mUnsetPressedState.run(); |
| 6236 | } |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6237 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6238 | } |
| 6239 | break; |
| 6240 | |
| 6241 | case MotionEvent.ACTION_DOWN: |
Adam Powell | 3b02339 | 2010-03-11 16:30:28 -0800 | [diff] [blame] | 6242 | mHasPerformedLongPress = false; |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6243 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 6244 | if (performButtonActionOnTouchDown(event)) { |
| 6245 | break; |
| 6246 | } |
| 6247 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6248 | // 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] | 6249 | boolean isInScrollingContainer = isInScrollingContainer(); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6250 | |
| 6251 | // For views inside a scrolling container, delay the pressed feedback for |
| 6252 | // a short period in case this is a scroll. |
| 6253 | if (isInScrollingContainer) { |
| 6254 | mPrivateFlags |= PREPRESSED; |
| 6255 | if (mPendingCheckForTap == null) { |
| 6256 | mPendingCheckForTap = new CheckForTap(); |
| 6257 | } |
| 6258 | postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); |
| 6259 | } else { |
| 6260 | // Not inside a scrolling container, so show the feedback right away |
| 6261 | mPrivateFlags |= PRESSED; |
| 6262 | refreshDrawableState(); |
| 6263 | checkForLongClick(0); |
| 6264 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6265 | break; |
| 6266 | |
| 6267 | case MotionEvent.ACTION_CANCEL: |
| 6268 | mPrivateFlags &= ~PRESSED; |
| 6269 | refreshDrawableState(); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6270 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6271 | break; |
| 6272 | |
| 6273 | case MotionEvent.ACTION_MOVE: |
| 6274 | final int x = (int) event.getX(); |
| 6275 | final int y = (int) event.getY(); |
| 6276 | |
| 6277 | // Be lenient about moving outside of buttons |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6278 | if (!pointInView(x, y, mTouchSlop)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6279 | // Outside button |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6280 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6281 | if ((mPrivateFlags & PRESSED) != 0) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6282 | // Remove any future long press/tap checks |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6283 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6284 | |
| 6285 | // Need to switch from pressed to not pressed |
| 6286 | mPrivateFlags &= ~PRESSED; |
| 6287 | refreshDrawableState(); |
| 6288 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6289 | } |
| 6290 | break; |
| 6291 | } |
| 6292 | return true; |
| 6293 | } |
| 6294 | |
| 6295 | return false; |
| 6296 | } |
| 6297 | |
| 6298 | /** |
Adam Powell | 1029866 | 2011-08-14 18:26:30 -0700 | [diff] [blame] | 6299 | * @hide |
| 6300 | */ |
| 6301 | public boolean isInScrollingContainer() { |
| 6302 | ViewParent p = getParent(); |
| 6303 | while (p != null && p instanceof ViewGroup) { |
| 6304 | if (((ViewGroup) p).shouldDelayChildPressedState()) { |
| 6305 | return true; |
| 6306 | } |
| 6307 | p = p.getParent(); |
| 6308 | } |
| 6309 | return false; |
| 6310 | } |
| 6311 | |
| 6312 | /** |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6313 | * Remove the longpress detection timer. |
| 6314 | */ |
| 6315 | private void removeLongPressCallback() { |
| 6316 | if (mPendingCheckForLongPress != null) { |
| 6317 | removeCallbacks(mPendingCheckForLongPress); |
| 6318 | } |
| 6319 | } |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 6320 | |
| 6321 | /** |
| 6322 | * Remove the pending click action |
| 6323 | */ |
| 6324 | private void removePerformClickCallback() { |
| 6325 | if (mPerformClick != null) { |
| 6326 | removeCallbacks(mPerformClick); |
| 6327 | } |
| 6328 | } |
| 6329 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6330 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6331 | * Remove the prepress detection timer. |
| 6332 | */ |
| 6333 | private void removeUnsetPressCallback() { |
| 6334 | if ((mPrivateFlags & PRESSED) != 0 && mUnsetPressedState != null) { |
| 6335 | setPressed(false); |
| 6336 | removeCallbacks(mUnsetPressedState); |
| 6337 | } |
| 6338 | } |
| 6339 | |
| 6340 | /** |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6341 | * Remove the tap detection timer. |
| 6342 | */ |
| 6343 | private void removeTapCallback() { |
| 6344 | if (mPendingCheckForTap != null) { |
| 6345 | mPrivateFlags &= ~PREPRESSED; |
| 6346 | removeCallbacks(mPendingCheckForTap); |
| 6347 | } |
| 6348 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6349 | |
| 6350 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6351 | * Cancels a pending long press. Your subclass can use this if you |
| 6352 | * want the context menu to come up if the user presses and holds |
| 6353 | * at the same place, but you don't want it to come up if they press |
| 6354 | * and then move around enough to cause scrolling. |
| 6355 | */ |
| 6356 | public void cancelLongPress() { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6357 | removeLongPressCallback(); |
Adam Powell | 732ebb1 | 2010-02-02 15:28:14 -0800 | [diff] [blame] | 6358 | |
| 6359 | /* |
| 6360 | * The prepressed state handled by the tap callback is a display |
| 6361 | * construct, but the tap callback will post a long press callback |
| 6362 | * less its own timeout. Remove it here. |
| 6363 | */ |
| 6364 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6365 | } |
| 6366 | |
| 6367 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6368 | * Remove the pending callback for sending a |
| 6369 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 6370 | */ |
| 6371 | private void removeSendViewScrolledAccessibilityEventCallback() { |
| 6372 | if (mSendViewScrolledAccessibilityEvent != null) { |
| 6373 | removeCallbacks(mSendViewScrolledAccessibilityEvent); |
| 6374 | } |
| 6375 | } |
| 6376 | |
| 6377 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6378 | * Sets the TouchDelegate for this View. |
| 6379 | */ |
| 6380 | public void setTouchDelegate(TouchDelegate delegate) { |
| 6381 | mTouchDelegate = delegate; |
| 6382 | } |
| 6383 | |
| 6384 | /** |
| 6385 | * Gets the TouchDelegate for this View. |
| 6386 | */ |
| 6387 | public TouchDelegate getTouchDelegate() { |
| 6388 | return mTouchDelegate; |
| 6389 | } |
| 6390 | |
| 6391 | /** |
| 6392 | * Set flags controlling behavior of this view. |
| 6393 | * |
| 6394 | * @param flags Constant indicating the value which should be set |
| 6395 | * @param mask Constant indicating the bit range that should be changed |
| 6396 | */ |
| 6397 | void setFlags(int flags, int mask) { |
| 6398 | int old = mViewFlags; |
| 6399 | mViewFlags = (mViewFlags & ~mask) | (flags & mask); |
| 6400 | |
| 6401 | int changed = mViewFlags ^ old; |
| 6402 | if (changed == 0) { |
| 6403 | return; |
| 6404 | } |
| 6405 | int privateFlags = mPrivateFlags; |
| 6406 | |
| 6407 | /* Check if the FOCUSABLE bit has changed */ |
| 6408 | if (((changed & FOCUSABLE_MASK) != 0) && |
| 6409 | ((privateFlags & HAS_BOUNDS) !=0)) { |
| 6410 | if (((old & FOCUSABLE_MASK) == FOCUSABLE) |
| 6411 | && ((privateFlags & FOCUSED) != 0)) { |
| 6412 | /* Give up focus if we are no longer focusable */ |
| 6413 | clearFocus(); |
| 6414 | } else if (((old & FOCUSABLE_MASK) == NOT_FOCUSABLE) |
| 6415 | && ((privateFlags & FOCUSED) == 0)) { |
| 6416 | /* |
| 6417 | * Tell the view system that we are now available to take focus |
| 6418 | * if no one else already has it. |
| 6419 | */ |
| 6420 | if (mParent != null) mParent.focusableViewAvailable(this); |
| 6421 | } |
| 6422 | } |
| 6423 | |
| 6424 | if ((flags & VISIBILITY_MASK) == VISIBLE) { |
| 6425 | if ((changed & VISIBILITY_MASK) != 0) { |
| 6426 | /* |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 6427 | * 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] | 6428 | * it was not visible. Marking it drawn ensures that the invalidation will |
| 6429 | * go through. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6430 | */ |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 6431 | mPrivateFlags |= DRAWN; |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 6432 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6433 | |
| 6434 | needGlobalAttributesUpdate(true); |
| 6435 | |
| 6436 | // a view becoming visible is worth notifying the parent |
| 6437 | // about in case nothing has focus. even if this specific view |
| 6438 | // isn't focusable, it may contain something that is, so let |
| 6439 | // the root view try to give this focus if nothing else does. |
| 6440 | if ((mParent != null) && (mBottom > mTop) && (mRight > mLeft)) { |
| 6441 | mParent.focusableViewAvailable(this); |
| 6442 | } |
| 6443 | } |
| 6444 | } |
| 6445 | |
| 6446 | /* Check if the GONE bit has changed */ |
| 6447 | if ((changed & GONE) != 0) { |
| 6448 | needGlobalAttributesUpdate(false); |
| 6449 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6450 | |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 6451 | if (((mViewFlags & VISIBILITY_MASK) == GONE)) { |
| 6452 | if (hasFocus()) clearFocus(); |
| 6453 | destroyDrawingCache(); |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 6454 | if (mParent instanceof View) { |
| 6455 | // GONE views noop invalidation, so invalidate the parent |
| 6456 | ((View) mParent).invalidate(true); |
| 6457 | } |
| 6458 | // Mark the view drawn to ensure that it gets invalidated properly the next |
| 6459 | // time it is visible and gets invalidated |
| 6460 | mPrivateFlags |= DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6461 | } |
| 6462 | if (mAttachInfo != null) { |
| 6463 | mAttachInfo.mViewVisibilityChanged = true; |
| 6464 | } |
| 6465 | } |
| 6466 | |
| 6467 | /* Check if the VISIBLE bit has changed */ |
| 6468 | if ((changed & INVISIBLE) != 0) { |
| 6469 | needGlobalAttributesUpdate(false); |
Chet Haase | c8a9a70 | 2011-06-17 12:13:42 -0700 | [diff] [blame] | 6470 | /* |
| 6471 | * If this view is becoming invisible, set the DRAWN flag so that |
| 6472 | * the next invalidate() will not be skipped. |
| 6473 | */ |
| 6474 | mPrivateFlags |= DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6475 | |
| 6476 | if (((mViewFlags & VISIBILITY_MASK) == INVISIBLE) && hasFocus()) { |
| 6477 | // root view becoming invisible shouldn't clear focus |
| 6478 | if (getRootView() != this) { |
| 6479 | clearFocus(); |
| 6480 | } |
| 6481 | } |
| 6482 | if (mAttachInfo != null) { |
| 6483 | mAttachInfo.mViewVisibilityChanged = true; |
| 6484 | } |
| 6485 | } |
| 6486 | |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6487 | if ((changed & VISIBILITY_MASK) != 0) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 6488 | if (mParent instanceof ViewGroup) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 6489 | ((ViewGroup) mParent).onChildVisibilityChanged(this, (flags & VISIBILITY_MASK)); |
| 6490 | ((View) mParent).invalidate(true); |
Chet Haase | e4e6e20 | 2011-08-29 14:34:30 -0700 | [diff] [blame] | 6491 | } else if (mParent != null) { |
| 6492 | mParent.invalidateChild(this, null); |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 6493 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6494 | dispatchVisibilityChanged(this, (flags & VISIBILITY_MASK)); |
| 6495 | } |
| 6496 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6497 | if ((changed & WILL_NOT_CACHE_DRAWING) != 0) { |
| 6498 | destroyDrawingCache(); |
| 6499 | } |
| 6500 | |
| 6501 | if ((changed & DRAWING_CACHE_ENABLED) != 0) { |
| 6502 | destroyDrawingCache(); |
| 6503 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 6504 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6505 | } |
| 6506 | |
| 6507 | if ((changed & DRAWING_CACHE_QUALITY_MASK) != 0) { |
| 6508 | destroyDrawingCache(); |
| 6509 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 6510 | } |
| 6511 | |
| 6512 | if ((changed & DRAW_MASK) != 0) { |
| 6513 | if ((mViewFlags & WILL_NOT_DRAW) != 0) { |
| 6514 | if (mBGDrawable != null) { |
| 6515 | mPrivateFlags &= ~SKIP_DRAW; |
| 6516 | mPrivateFlags |= ONLY_DRAWS_BACKGROUND; |
| 6517 | } else { |
| 6518 | mPrivateFlags |= SKIP_DRAW; |
| 6519 | } |
| 6520 | } else { |
| 6521 | mPrivateFlags &= ~SKIP_DRAW; |
| 6522 | } |
| 6523 | requestLayout(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 6524 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6525 | } |
| 6526 | |
| 6527 | if ((changed & KEEP_SCREEN_ON) != 0) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6528 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6529 | mParent.recomputeViewAttributes(this); |
| 6530 | } |
| 6531 | } |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 6532 | |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 6533 | if ((changed & LAYOUT_DIRECTION_MASK) != 0) { |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 6534 | requestLayout(); |
| 6535 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6536 | } |
| 6537 | |
| 6538 | /** |
| 6539 | * Change the view's z order in the tree, so it's on top of other sibling |
| 6540 | * views |
| 6541 | */ |
| 6542 | public void bringToFront() { |
| 6543 | if (mParent != null) { |
| 6544 | mParent.bringChildToFront(this); |
| 6545 | } |
| 6546 | } |
| 6547 | |
| 6548 | /** |
| 6549 | * This is called in response to an internal scroll in this view (i.e., the |
| 6550 | * view scrolled its own contents). This is typically as a result of |
| 6551 | * {@link #scrollBy(int, int)} or {@link #scrollTo(int, int)} having been |
| 6552 | * called. |
| 6553 | * |
| 6554 | * @param l Current horizontal scroll origin. |
| 6555 | * @param t Current vertical scroll origin. |
| 6556 | * @param oldl Previous horizontal scroll origin. |
| 6557 | * @param oldt Previous vertical scroll origin. |
| 6558 | */ |
| 6559 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6560 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 6561 | postSendViewScrolledAccessibilityEventCallback(); |
| 6562 | } |
| 6563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6564 | mBackgroundSizeChanged = true; |
| 6565 | |
| 6566 | final AttachInfo ai = mAttachInfo; |
| 6567 | if (ai != null) { |
| 6568 | ai.mViewScrollChanged = true; |
| 6569 | } |
| 6570 | } |
| 6571 | |
| 6572 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 6573 | * Interface definition for a callback to be invoked when the layout bounds of a view |
| 6574 | * changes due to layout processing. |
| 6575 | */ |
| 6576 | public interface OnLayoutChangeListener { |
| 6577 | /** |
| 6578 | * Called when the focus state of a view has changed. |
| 6579 | * |
| 6580 | * @param v The view whose state has changed. |
| 6581 | * @param left The new value of the view's left property. |
| 6582 | * @param top The new value of the view's top property. |
| 6583 | * @param right The new value of the view's right property. |
| 6584 | * @param bottom The new value of the view's bottom property. |
| 6585 | * @param oldLeft The previous value of the view's left property. |
| 6586 | * @param oldTop The previous value of the view's top property. |
| 6587 | * @param oldRight The previous value of the view's right property. |
| 6588 | * @param oldBottom The previous value of the view's bottom property. |
| 6589 | */ |
| 6590 | void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 6591 | int oldLeft, int oldTop, int oldRight, int oldBottom); |
| 6592 | } |
| 6593 | |
| 6594 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6595 | * This is called during layout when the size of this view has changed. If |
| 6596 | * you were just added to the view hierarchy, you're called with the old |
| 6597 | * values of 0. |
| 6598 | * |
| 6599 | * @param w Current width of this view. |
| 6600 | * @param h Current height of this view. |
| 6601 | * @param oldw Old width of this view. |
| 6602 | * @param oldh Old height of this view. |
| 6603 | */ |
| 6604 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 6605 | } |
| 6606 | |
| 6607 | /** |
| 6608 | * Called by draw to draw the child views. This may be overridden |
| 6609 | * by derived classes to gain control just before its children are drawn |
| 6610 | * (but after its own view has been drawn). |
| 6611 | * @param canvas the canvas on which to draw the view |
| 6612 | */ |
| 6613 | protected void dispatchDraw(Canvas canvas) { |
| 6614 | } |
| 6615 | |
| 6616 | /** |
| 6617 | * Gets the parent of this view. Note that the parent is a |
| 6618 | * ViewParent and not necessarily a View. |
| 6619 | * |
| 6620 | * @return Parent of this view. |
| 6621 | */ |
| 6622 | public final ViewParent getParent() { |
| 6623 | return mParent; |
| 6624 | } |
| 6625 | |
| 6626 | /** |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 6627 | * Set the horizontal scrolled position of your view. This will cause a call to |
| 6628 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 6629 | * invalidated. |
| 6630 | * @param value the x position to scroll to |
| 6631 | */ |
| 6632 | public void setScrollX(int value) { |
| 6633 | scrollTo(value, mScrollY); |
| 6634 | } |
| 6635 | |
| 6636 | /** |
| 6637 | * Set the vertical scrolled position of your view. This will cause a call to |
| 6638 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 6639 | * invalidated. |
| 6640 | * @param value the y position to scroll to |
| 6641 | */ |
| 6642 | public void setScrollY(int value) { |
| 6643 | scrollTo(mScrollX, value); |
| 6644 | } |
| 6645 | |
| 6646 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6647 | * Return the scrolled left position of this view. This is the left edge of |
| 6648 | * the displayed part of your view. You do not need to draw any pixels |
| 6649 | * farther left, since those are outside of the frame of your view on |
| 6650 | * screen. |
| 6651 | * |
| 6652 | * @return The left edge of the displayed part of your view, in pixels. |
| 6653 | */ |
| 6654 | public final int getScrollX() { |
| 6655 | return mScrollX; |
| 6656 | } |
| 6657 | |
| 6658 | /** |
| 6659 | * Return the scrolled top position of this view. This is the top edge of |
| 6660 | * the displayed part of your view. You do not need to draw any pixels above |
| 6661 | * it, since those are outside of the frame of your view on screen. |
| 6662 | * |
| 6663 | * @return The top edge of the displayed part of your view, in pixels. |
| 6664 | */ |
| 6665 | public final int getScrollY() { |
| 6666 | return mScrollY; |
| 6667 | } |
| 6668 | |
| 6669 | /** |
| 6670 | * Return the width of the your view. |
| 6671 | * |
| 6672 | * @return The width of your view, in pixels. |
| 6673 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 6674 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6675 | public final int getWidth() { |
| 6676 | return mRight - mLeft; |
| 6677 | } |
| 6678 | |
| 6679 | /** |
| 6680 | * Return the height of your view. |
| 6681 | * |
| 6682 | * @return The height of your view, in pixels. |
| 6683 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 6684 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6685 | public final int getHeight() { |
| 6686 | return mBottom - mTop; |
| 6687 | } |
| 6688 | |
| 6689 | /** |
| 6690 | * Return the visible drawing bounds of your view. Fills in the output |
| 6691 | * rectangle with the values from getScrollX(), getScrollY(), |
| 6692 | * getWidth(), and getHeight(). |
| 6693 | * |
| 6694 | * @param outRect The (scrolled) drawing bounds of the view. |
| 6695 | */ |
| 6696 | public void getDrawingRect(Rect outRect) { |
| 6697 | outRect.left = mScrollX; |
| 6698 | outRect.top = mScrollY; |
| 6699 | outRect.right = mScrollX + (mRight - mLeft); |
| 6700 | outRect.bottom = mScrollY + (mBottom - mTop); |
| 6701 | } |
| 6702 | |
| 6703 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 6704 | * Like {@link #getMeasuredWidthAndState()}, but only returns the |
| 6705 | * raw width component (that is the result is masked by |
| 6706 | * {@link #MEASURED_SIZE_MASK}). |
| 6707 | * |
| 6708 | * @return The raw measured width of this view. |
| 6709 | */ |
| 6710 | public final int getMeasuredWidth() { |
| 6711 | return mMeasuredWidth & MEASURED_SIZE_MASK; |
| 6712 | } |
| 6713 | |
| 6714 | /** |
| 6715 | * Return the full width measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6716 | * 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] | 6717 | * 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] | 6718 | * This should be used during measurement and layout calculations only. Use |
| 6719 | * {@link #getWidth()} to see how wide a view is after layout. |
| 6720 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 6721 | * @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] | 6722 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 6723 | public final int getMeasuredWidthAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6724 | return mMeasuredWidth; |
| 6725 | } |
| 6726 | |
| 6727 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 6728 | * Like {@link #getMeasuredHeightAndState()}, but only returns the |
| 6729 | * raw width component (that is the result is masked by |
| 6730 | * {@link #MEASURED_SIZE_MASK}). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6731 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 6732 | * @return The raw measured height of this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6733 | */ |
| 6734 | public final int getMeasuredHeight() { |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 6735 | return mMeasuredHeight & MEASURED_SIZE_MASK; |
| 6736 | } |
| 6737 | |
| 6738 | /** |
| 6739 | * Return the full height measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6740 | * 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] | 6741 | * as defined by {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. |
| 6742 | * This should be used during measurement and layout calculations only. Use |
| 6743 | * {@link #getHeight()} to see how wide a view is after layout. |
| 6744 | * |
| 6745 | * @return The measured width of this view as a bit mask. |
| 6746 | */ |
| 6747 | public final int getMeasuredHeightAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6748 | return mMeasuredHeight; |
| 6749 | } |
| 6750 | |
| 6751 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 6752 | * Return only the state bits of {@link #getMeasuredWidthAndState()} |
| 6753 | * and {@link #getMeasuredHeightAndState()}, combined into one integer. |
| 6754 | * The width component is in the regular bits {@link #MEASURED_STATE_MASK} |
| 6755 | * and the height component is at the shifted bits |
| 6756 | * {@link #MEASURED_HEIGHT_STATE_SHIFT}>>{@link #MEASURED_STATE_MASK}. |
| 6757 | */ |
| 6758 | public final int getMeasuredState() { |
| 6759 | return (mMeasuredWidth&MEASURED_STATE_MASK) |
| 6760 | | ((mMeasuredHeight>>MEASURED_HEIGHT_STATE_SHIFT) |
| 6761 | & (MEASURED_STATE_MASK>>MEASURED_HEIGHT_STATE_SHIFT)); |
| 6762 | } |
| 6763 | |
| 6764 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6765 | * The transform matrix of this view, which is calculated based on the current |
| 6766 | * roation, scale, and pivot properties. |
| 6767 | * |
| 6768 | * @see #getRotation() |
| 6769 | * @see #getScaleX() |
| 6770 | * @see #getScaleY() |
| 6771 | * @see #getPivotX() |
| 6772 | * @see #getPivotY() |
| 6773 | * @return The current transform matrix for the view |
| 6774 | */ |
| 6775 | public Matrix getMatrix() { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 6776 | updateMatrix(); |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 6777 | return mMatrix; |
| 6778 | } |
| 6779 | |
| 6780 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 6781 | * Utility function to determine if the value is far enough away from zero to be |
| 6782 | * considered non-zero. |
| 6783 | * @param value A floating point value to check for zero-ness |
| 6784 | * @return whether the passed-in value is far enough away from zero to be considered non-zero |
| 6785 | */ |
| 6786 | private static boolean nonzero(float value) { |
| 6787 | return (value < -NONZERO_EPSILON || value > NONZERO_EPSILON); |
| 6788 | } |
| 6789 | |
| 6790 | /** |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 6791 | * Returns true if the transform matrix is the identity matrix. |
| 6792 | * Recomputes the matrix if necessary. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6793 | * |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 6794 | * @return True if the transform matrix is the identity matrix, false otherwise. |
| 6795 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 6796 | final boolean hasIdentityMatrix() { |
| 6797 | updateMatrix(); |
| 6798 | return mMatrixIsIdentity; |
| 6799 | } |
| 6800 | |
| 6801 | /** |
| 6802 | * Recomputes the transform matrix if necessary. |
| 6803 | */ |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 6804 | private void updateMatrix() { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6805 | if (mMatrixDirty) { |
| 6806 | // transform-related properties have changed since the last time someone |
| 6807 | // asked for the matrix; recalculate it with the current values |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 6808 | |
| 6809 | // Figure out if we need to update the pivot point |
| 6810 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 6811 | if ((mRight - mLeft) != mPrevWidth || (mBottom - mTop) != mPrevHeight) { |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 6812 | mPrevWidth = mRight - mLeft; |
| 6813 | mPrevHeight = mBottom - mTop; |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 6814 | mPivotX = mPrevWidth / 2f; |
| 6815 | mPivotY = mPrevHeight / 2f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 6816 | } |
| 6817 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6818 | mMatrix.reset(); |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 6819 | if (!nonzero(mRotationX) && !nonzero(mRotationY)) { |
| 6820 | mMatrix.setTranslate(mTranslationX, mTranslationY); |
| 6821 | mMatrix.preRotate(mRotation, mPivotX, mPivotY); |
| 6822 | mMatrix.preScale(mScaleX, mScaleY, mPivotX, mPivotY); |
| 6823 | } else { |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 6824 | if (mCamera == null) { |
| 6825 | mCamera = new Camera(); |
| 6826 | matrix3D = new Matrix(); |
| 6827 | } |
| 6828 | mCamera.save(); |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 6829 | mMatrix.preScale(mScaleX, mScaleY, mPivotX, mPivotY); |
Romain Guy | 47b8ade | 2011-02-23 19:46:33 -0800 | [diff] [blame] | 6830 | mCamera.rotate(mRotationX, mRotationY, -mRotation); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 6831 | mCamera.getMatrix(matrix3D); |
| 6832 | matrix3D.preTranslate(-mPivotX, -mPivotY); |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 6833 | matrix3D.postTranslate(mPivotX + mTranslationX, mPivotY + mTranslationY); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 6834 | mMatrix.postConcat(matrix3D); |
| 6835 | mCamera.restore(); |
| 6836 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6837 | mMatrixDirty = false; |
| 6838 | mMatrixIsIdentity = mMatrix.isIdentity(); |
| 6839 | mInverseMatrixDirty = true; |
| 6840 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6841 | } |
| 6842 | |
| 6843 | /** |
| 6844 | * Utility method to retrieve the inverse of the current mMatrix property. |
| 6845 | * We cache the matrix to avoid recalculating it when transform properties |
| 6846 | * have not changed. |
| 6847 | * |
| 6848 | * @return The inverse of the current matrix of this view. |
| 6849 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 6850 | final Matrix getInverseMatrix() { |
| 6851 | updateMatrix(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6852 | if (mInverseMatrixDirty) { |
| 6853 | if (mInverseMatrix == null) { |
| 6854 | mInverseMatrix = new Matrix(); |
| 6855 | } |
| 6856 | mMatrix.invert(mInverseMatrix); |
| 6857 | mInverseMatrixDirty = false; |
| 6858 | } |
| 6859 | return mInverseMatrix; |
| 6860 | } |
| 6861 | |
| 6862 | /** |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 6863 | * <p>Sets the distance along the Z axis (orthogonal to the X/Y plane on which |
| 6864 | * views are drawn) from the camera to this view. The camera's distance |
| 6865 | * affects 3D transformations, for instance rotations around the X and Y |
| 6866 | * axis. If the rotationX or rotationY properties are changed and this view is |
| 6867 | * large (more than half the size of the screen), it is recommended to always |
| 6868 | * use a camera distance that's greater than the height (X axis rotation) or |
| 6869 | * the width (Y axis rotation) of this view.</p> |
| 6870 | * |
| 6871 | * <p>The distance of the camera from the view plane can have an affect on the |
| 6872 | * perspective distortion of the view when it is rotated around the x or y axis. |
| 6873 | * For example, a large distance will result in a large viewing angle, and there |
| 6874 | * will not be much perspective distortion of the view as it rotates. A short |
| 6875 | * distance may cause much more perspective distortion upon rotation, and can |
| 6876 | * also result in some drawing artifacts if the rotated view ends up partially |
| 6877 | * behind the camera (which is why the recommendation is to use a distance at |
| 6878 | * least as far as the size of the view, if the view is to be rotated.)</p> |
| 6879 | * |
| 6880 | * <p>The distance is expressed in "depth pixels." The default distance depends |
| 6881 | * on the screen density. For instance, on a medium density display, the |
| 6882 | * default distance is 1280. On a high density display, the default distance |
| 6883 | * is 1920.</p> |
| 6884 | * |
| 6885 | * <p>If you want to specify a distance that leads to visually consistent |
| 6886 | * results across various densities, use the following formula:</p> |
| 6887 | * <pre> |
| 6888 | * float scale = context.getResources().getDisplayMetrics().density; |
| 6889 | * view.setCameraDistance(distance * scale); |
| 6890 | * </pre> |
| 6891 | * |
| 6892 | * <p>The density scale factor of a high density display is 1.5, |
| 6893 | * and 1920 = 1280 * 1.5.</p> |
| 6894 | * |
| 6895 | * @param distance The distance in "depth pixels", if negative the opposite |
| 6896 | * value is used |
| 6897 | * |
| 6898 | * @see #setRotationX(float) |
| 6899 | * @see #setRotationY(float) |
| 6900 | */ |
| 6901 | public void setCameraDistance(float distance) { |
| 6902 | invalidateParentCaches(); |
| 6903 | invalidate(false); |
| 6904 | |
| 6905 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
| 6906 | if (mCamera == null) { |
| 6907 | mCamera = new Camera(); |
| 6908 | matrix3D = new Matrix(); |
| 6909 | } |
| 6910 | |
| 6911 | mCamera.setLocation(0.0f, 0.0f, -Math.abs(distance) / dpi); |
| 6912 | mMatrixDirty = true; |
| 6913 | |
| 6914 | invalidate(false); |
| 6915 | } |
| 6916 | |
| 6917 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6918 | * The degrees that the view is rotated around the pivot point. |
| 6919 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 6920 | * @see #setRotation(float) |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6921 | * @see #getPivotX() |
| 6922 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 6923 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6924 | * @return The degrees of rotation. |
| 6925 | */ |
| 6926 | public float getRotation() { |
| 6927 | return mRotation; |
| 6928 | } |
| 6929 | |
| 6930 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 6931 | * Sets the degrees that the view is rotated around the pivot point. Increasing values |
| 6932 | * result in clockwise rotation. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6933 | * |
| 6934 | * @param rotation The degrees of rotation. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 6935 | * |
| 6936 | * @see #getRotation() |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6937 | * @see #getPivotX() |
| 6938 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 6939 | * @see #setRotationX(float) |
| 6940 | * @see #setRotationY(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 6941 | * |
| 6942 | * @attr ref android.R.styleable#View_rotation |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6943 | */ |
| 6944 | public void setRotation(float rotation) { |
| 6945 | if (mRotation != rotation) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 6946 | invalidateParentCaches(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6947 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 6948 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6949 | mRotation = rotation; |
| 6950 | mMatrixDirty = true; |
| 6951 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 6952 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6953 | } |
| 6954 | } |
| 6955 | |
| 6956 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 6957 | * The degrees that the view is rotated around the vertical axis through the pivot point. |
| 6958 | * |
| 6959 | * @see #getPivotX() |
| 6960 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 6961 | * @see #setRotationY(float) |
| 6962 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 6963 | * @return The degrees of Y rotation. |
| 6964 | */ |
| 6965 | public float getRotationY() { |
| 6966 | return mRotationY; |
| 6967 | } |
| 6968 | |
| 6969 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 6970 | * Sets the degrees that the view is rotated around the vertical axis through the pivot point. |
| 6971 | * Increasing values result in counter-clockwise rotation from the viewpoint of looking |
| 6972 | * down the y axis. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 6973 | * |
| 6974 | * When rotating large views, it is recommended to adjust the camera distance |
| 6975 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 6976 | * |
| 6977 | * @param rotationY The degrees of Y rotation. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 6978 | * |
| 6979 | * @see #getRotationY() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 6980 | * @see #getPivotX() |
| 6981 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 6982 | * @see #setRotation(float) |
| 6983 | * @see #setRotationX(float) |
| 6984 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 6985 | * |
| 6986 | * @attr ref android.R.styleable#View_rotationY |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 6987 | */ |
| 6988 | public void setRotationY(float rotationY) { |
| 6989 | if (mRotationY != rotationY) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 6990 | invalidateParentCaches(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 6991 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 6992 | invalidate(false); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 6993 | mRotationY = rotationY; |
| 6994 | mMatrixDirty = true; |
| 6995 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 6996 | invalidate(false); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 6997 | } |
| 6998 | } |
| 6999 | |
| 7000 | /** |
| 7001 | * The degrees that the view is rotated around the horizontal axis through the pivot point. |
| 7002 | * |
| 7003 | * @see #getPivotX() |
| 7004 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7005 | * @see #setRotationX(float) |
| 7006 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7007 | * @return The degrees of X rotation. |
| 7008 | */ |
| 7009 | public float getRotationX() { |
| 7010 | return mRotationX; |
| 7011 | } |
| 7012 | |
| 7013 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7014 | * Sets the degrees that the view is rotated around the horizontal axis through the pivot point. |
| 7015 | * Increasing values result in clockwise rotation from the viewpoint of looking down the |
| 7016 | * x axis. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7017 | * |
| 7018 | * When rotating large views, it is recommended to adjust the camera distance |
| 7019 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7020 | * |
| 7021 | * @param rotationX The degrees of X rotation. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7022 | * |
| 7023 | * @see #getRotationX() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7024 | * @see #getPivotX() |
| 7025 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7026 | * @see #setRotation(float) |
| 7027 | * @see #setRotationY(float) |
| 7028 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7029 | * |
| 7030 | * @attr ref android.R.styleable#View_rotationX |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7031 | */ |
| 7032 | public void setRotationX(float rotationX) { |
| 7033 | if (mRotationX != rotationX) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7034 | invalidateParentCaches(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7035 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7036 | invalidate(false); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7037 | mRotationX = rotationX; |
| 7038 | mMatrixDirty = true; |
| 7039 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7040 | invalidate(false); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7041 | } |
| 7042 | } |
| 7043 | |
| 7044 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7045 | * The amount that the view is scaled in x around the pivot point, as a proportion of |
| 7046 | * the view's unscaled width. A value of 1, the default, means that no scaling is applied. |
| 7047 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 7048 | * <p>By default, this is 1.0f. |
| 7049 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7050 | * @see #getPivotX() |
| 7051 | * @see #getPivotY() |
| 7052 | * @return The scaling factor. |
| 7053 | */ |
| 7054 | public float getScaleX() { |
| 7055 | return mScaleX; |
| 7056 | } |
| 7057 | |
| 7058 | /** |
| 7059 | * Sets the amount that the view is scaled in x around the pivot point, as a proportion of |
| 7060 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 7061 | * |
| 7062 | * @param scaleX The scaling factor. |
| 7063 | * @see #getPivotX() |
| 7064 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7065 | * |
| 7066 | * @attr ref android.R.styleable#View_scaleX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7067 | */ |
| 7068 | public void setScaleX(float scaleX) { |
| 7069 | if (mScaleX != scaleX) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7070 | invalidateParentCaches(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7071 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7072 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7073 | mScaleX = scaleX; |
| 7074 | mMatrixDirty = true; |
| 7075 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7076 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7077 | } |
| 7078 | } |
| 7079 | |
| 7080 | /** |
| 7081 | * The amount that the view is scaled in y around the pivot point, as a proportion of |
| 7082 | * the view's unscaled height. A value of 1, the default, means that no scaling is applied. |
| 7083 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 7084 | * <p>By default, this is 1.0f. |
| 7085 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7086 | * @see #getPivotX() |
| 7087 | * @see #getPivotY() |
| 7088 | * @return The scaling factor. |
| 7089 | */ |
| 7090 | public float getScaleY() { |
| 7091 | return mScaleY; |
| 7092 | } |
| 7093 | |
| 7094 | /** |
| 7095 | * Sets the amount that the view is scaled in Y around the pivot point, as a proportion of |
| 7096 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 7097 | * |
| 7098 | * @param scaleY The scaling factor. |
| 7099 | * @see #getPivotX() |
| 7100 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7101 | * |
| 7102 | * @attr ref android.R.styleable#View_scaleY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7103 | */ |
| 7104 | public void setScaleY(float scaleY) { |
| 7105 | if (mScaleY != scaleY) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7106 | invalidateParentCaches(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7107 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7108 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7109 | mScaleY = scaleY; |
| 7110 | mMatrixDirty = true; |
| 7111 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7112 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7113 | } |
| 7114 | } |
| 7115 | |
| 7116 | /** |
| 7117 | * The x location of the point around which the view is {@link #setRotation(float) rotated} |
| 7118 | * and {@link #setScaleX(float) scaled}. |
| 7119 | * |
| 7120 | * @see #getRotation() |
| 7121 | * @see #getScaleX() |
| 7122 | * @see #getScaleY() |
| 7123 | * @see #getPivotY() |
| 7124 | * @return The x location of the pivot point. |
| 7125 | */ |
| 7126 | public float getPivotX() { |
| 7127 | return mPivotX; |
| 7128 | } |
| 7129 | |
| 7130 | /** |
| 7131 | * Sets the x location of the point around which the view is |
| 7132 | * {@link #setRotation(float) rotated} and {@link #setScaleX(float) scaled}. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7133 | * By default, the pivot point is centered on the object. |
| 7134 | * Setting this property disables this behavior and causes the view to use only the |
| 7135 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7136 | * |
| 7137 | * @param pivotX The x location of the pivot point. |
| 7138 | * @see #getRotation() |
| 7139 | * @see #getScaleX() |
| 7140 | * @see #getScaleY() |
| 7141 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7142 | * |
| 7143 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7144 | */ |
| 7145 | public void setPivotX(float pivotX) { |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7146 | mPrivateFlags |= PIVOT_EXPLICITLY_SET; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7147 | if (mPivotX != pivotX) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7148 | invalidateParentCaches(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7149 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7150 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7151 | mPivotX = pivotX; |
| 7152 | mMatrixDirty = true; |
| 7153 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7154 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7155 | } |
| 7156 | } |
| 7157 | |
| 7158 | /** |
| 7159 | * The y location of the point around which the view is {@link #setRotation(float) rotated} |
| 7160 | * and {@link #setScaleY(float) scaled}. |
| 7161 | * |
| 7162 | * @see #getRotation() |
| 7163 | * @see #getScaleX() |
| 7164 | * @see #getScaleY() |
| 7165 | * @see #getPivotY() |
| 7166 | * @return The y location of the pivot point. |
| 7167 | */ |
| 7168 | public float getPivotY() { |
| 7169 | return mPivotY; |
| 7170 | } |
| 7171 | |
| 7172 | /** |
| 7173 | * 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] | 7174 | * and {@link #setScaleY(float) scaled}. By default, the pivot point is centered on the object. |
| 7175 | * Setting this property disables this behavior and causes the view to use only the |
| 7176 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7177 | * |
| 7178 | * @param pivotY The y location of the pivot point. |
| 7179 | * @see #getRotation() |
| 7180 | * @see #getScaleX() |
| 7181 | * @see #getScaleY() |
| 7182 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7183 | * |
| 7184 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7185 | */ |
| 7186 | public void setPivotY(float pivotY) { |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7187 | mPrivateFlags |= PIVOT_EXPLICITLY_SET; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7188 | if (mPivotY != pivotY) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7189 | invalidateParentCaches(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7190 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7191 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7192 | mPivotY = pivotY; |
| 7193 | mMatrixDirty = true; |
| 7194 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7195 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7196 | } |
| 7197 | } |
| 7198 | |
| 7199 | /** |
| 7200 | * The opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 7201 | * completely transparent and 1 means the view is completely opaque. |
| 7202 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 7203 | * <p>By default this is 1.0f. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7204 | * @return The opacity of the view. |
| 7205 | */ |
| 7206 | public float getAlpha() { |
| 7207 | return mAlpha; |
| 7208 | } |
| 7209 | |
| 7210 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 7211 | * <p>Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 7212 | * completely transparent and 1 means the view is completely opaque.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7213 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 7214 | * <p>If this view overrides {@link #onSetAlpha(int)} to return true, then this view is |
| 7215 | * responsible for applying the opacity itself. Otherwise, calling this method is |
| 7216 | * equivalent to calling {@link #setLayerType(int, android.graphics.Paint)} and |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7217 | * setting a hardware layer.</p> |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7218 | * |
| 7219 | * @param alpha The opacity of the view. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7220 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7221 | * @see #setLayerType(int, android.graphics.Paint) |
| 7222 | * |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7223 | * @attr ref android.R.styleable#View_alpha |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7224 | */ |
| 7225 | public void setAlpha(float alpha) { |
| 7226 | mAlpha = alpha; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7227 | invalidateParentCaches(); |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7228 | if (onSetAlpha((int) (alpha * 255))) { |
Romain Guy | a3496a9 | 2010-10-12 11:53:24 -0700 | [diff] [blame] | 7229 | mPrivateFlags |= ALPHA_SET; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7230 | // subclass is handling alpha - don't optimize rendering cache invalidation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7231 | invalidate(true); |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7232 | } else { |
Romain Guy | a3496a9 | 2010-10-12 11:53:24 -0700 | [diff] [blame] | 7233 | mPrivateFlags &= ~ALPHA_SET; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7234 | invalidate(false); |
| 7235 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7236 | } |
| 7237 | |
| 7238 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 7239 | * Faster version of setAlpha() which performs the same steps except there are |
| 7240 | * no calls to invalidate(). The caller of this function should perform proper invalidation |
| 7241 | * on the parent and this object. The return value indicates whether the subclass handles |
| 7242 | * alpha (the return value for onSetAlpha()). |
| 7243 | * |
| 7244 | * @param alpha The new value for the alpha property |
| 7245 | * @return true if the View subclass handles alpha (the return value for onSetAlpha()) |
| 7246 | */ |
| 7247 | boolean setAlphaNoInvalidation(float alpha) { |
| 7248 | mAlpha = alpha; |
| 7249 | boolean subclassHandlesAlpha = onSetAlpha((int) (alpha * 255)); |
| 7250 | if (subclassHandlesAlpha) { |
| 7251 | mPrivateFlags |= ALPHA_SET; |
| 7252 | } else { |
| 7253 | mPrivateFlags &= ~ALPHA_SET; |
| 7254 | } |
| 7255 | return subclassHandlesAlpha; |
| 7256 | } |
| 7257 | |
| 7258 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7259 | * Top position of this view relative to its parent. |
| 7260 | * |
| 7261 | * @return The top of this view, in pixels. |
| 7262 | */ |
| 7263 | @ViewDebug.CapturedViewProperty |
| 7264 | public final int getTop() { |
| 7265 | return mTop; |
| 7266 | } |
| 7267 | |
| 7268 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7269 | * Sets the top position of this view relative to its parent. This method is meant to be called |
| 7270 | * by the layout system and should not generally be called otherwise, because the property |
| 7271 | * may be changed at any time by the layout. |
| 7272 | * |
| 7273 | * @param top The top of this view, in pixels. |
| 7274 | */ |
| 7275 | public final void setTop(int top) { |
| 7276 | if (top != mTop) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7277 | updateMatrix(); |
| 7278 | if (mMatrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7279 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7280 | int minTop; |
| 7281 | int yLoc; |
| 7282 | if (top < mTop) { |
| 7283 | minTop = top; |
| 7284 | yLoc = top - mTop; |
| 7285 | } else { |
| 7286 | minTop = mTop; |
| 7287 | yLoc = 0; |
| 7288 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7289 | invalidate(0, yLoc, mRight - mLeft, mBottom - minTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7290 | } |
| 7291 | } else { |
| 7292 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7293 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7294 | } |
| 7295 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7296 | int width = mRight - mLeft; |
| 7297 | int oldHeight = mBottom - mTop; |
| 7298 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7299 | mTop = top; |
| 7300 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7301 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 7302 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7303 | if (!mMatrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7304 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 7305 | // A change in dimension means an auto-centered pivot point changes, too |
| 7306 | mMatrixDirty = true; |
| 7307 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7308 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7309 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7310 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 7311 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 7312 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7313 | } |
| 7314 | } |
| 7315 | |
| 7316 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7317 | * Bottom position of this view relative to its parent. |
| 7318 | * |
| 7319 | * @return The bottom of this view, in pixels. |
| 7320 | */ |
| 7321 | @ViewDebug.CapturedViewProperty |
| 7322 | public final int getBottom() { |
| 7323 | return mBottom; |
| 7324 | } |
| 7325 | |
| 7326 | /** |
Michael Jurka | dab559a | 2011-01-04 20:31:51 -0800 | [diff] [blame] | 7327 | * True if this view has changed since the last time being drawn. |
| 7328 | * |
| 7329 | * @return The dirty state of this view. |
| 7330 | */ |
| 7331 | public boolean isDirty() { |
| 7332 | return (mPrivateFlags & DIRTY_MASK) != 0; |
| 7333 | } |
| 7334 | |
| 7335 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7336 | * Sets the bottom position of this view relative to its parent. This method is meant to be |
| 7337 | * called by the layout system and should not generally be called otherwise, because the |
| 7338 | * property may be changed at any time by the layout. |
| 7339 | * |
| 7340 | * @param bottom The bottom of this view, in pixels. |
| 7341 | */ |
| 7342 | public final void setBottom(int bottom) { |
| 7343 | if (bottom != mBottom) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7344 | updateMatrix(); |
| 7345 | if (mMatrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7346 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7347 | int maxBottom; |
| 7348 | if (bottom < mBottom) { |
| 7349 | maxBottom = mBottom; |
| 7350 | } else { |
| 7351 | maxBottom = bottom; |
| 7352 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7353 | invalidate(0, 0, mRight - mLeft, maxBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7354 | } |
| 7355 | } else { |
| 7356 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7357 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7358 | } |
| 7359 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7360 | int width = mRight - mLeft; |
| 7361 | int oldHeight = mBottom - mTop; |
| 7362 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7363 | mBottom = bottom; |
| 7364 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7365 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 7366 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7367 | if (!mMatrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7368 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 7369 | // A change in dimension means an auto-centered pivot point changes, too |
| 7370 | mMatrixDirty = true; |
| 7371 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7372 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7373 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7374 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 7375 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 7376 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7377 | } |
| 7378 | } |
| 7379 | |
| 7380 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7381 | * Left position of this view relative to its parent. |
| 7382 | * |
| 7383 | * @return The left edge of this view, in pixels. |
| 7384 | */ |
| 7385 | @ViewDebug.CapturedViewProperty |
| 7386 | public final int getLeft() { |
| 7387 | return mLeft; |
| 7388 | } |
| 7389 | |
| 7390 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7391 | * Sets the left position of this view relative to its parent. This method is meant to be called |
| 7392 | * by the layout system and should not generally be called otherwise, because the property |
| 7393 | * may be changed at any time by the layout. |
| 7394 | * |
| 7395 | * @param left The bottom of this view, in pixels. |
| 7396 | */ |
| 7397 | public final void setLeft(int left) { |
| 7398 | if (left != mLeft) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7399 | updateMatrix(); |
| 7400 | if (mMatrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7401 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7402 | int minLeft; |
| 7403 | int xLoc; |
| 7404 | if (left < mLeft) { |
| 7405 | minLeft = left; |
| 7406 | xLoc = left - mLeft; |
| 7407 | } else { |
| 7408 | minLeft = mLeft; |
| 7409 | xLoc = 0; |
| 7410 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7411 | invalidate(xLoc, 0, mRight - minLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7412 | } |
| 7413 | } else { |
| 7414 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7415 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7416 | } |
| 7417 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7418 | int oldWidth = mRight - mLeft; |
| 7419 | int height = mBottom - mTop; |
| 7420 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7421 | mLeft = left; |
| 7422 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7423 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 7424 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7425 | if (!mMatrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7426 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 7427 | // A change in dimension means an auto-centered pivot point changes, too |
| 7428 | mMatrixDirty = true; |
| 7429 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7430 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7431 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7432 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 7433 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 7434 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7435 | } |
| 7436 | } |
| 7437 | |
| 7438 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7439 | * Right position of this view relative to its parent. |
| 7440 | * |
| 7441 | * @return The right edge of this view, in pixels. |
| 7442 | */ |
| 7443 | @ViewDebug.CapturedViewProperty |
| 7444 | public final int getRight() { |
| 7445 | return mRight; |
| 7446 | } |
| 7447 | |
| 7448 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7449 | * Sets the right position of this view relative to its parent. This method is meant to be called |
| 7450 | * by the layout system and should not generally be called otherwise, because the property |
| 7451 | * may be changed at any time by the layout. |
| 7452 | * |
| 7453 | * @param right The bottom of this view, in pixels. |
| 7454 | */ |
| 7455 | public final void setRight(int right) { |
| 7456 | if (right != mRight) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7457 | updateMatrix(); |
| 7458 | if (mMatrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7459 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7460 | int maxRight; |
| 7461 | if (right < mRight) { |
| 7462 | maxRight = mRight; |
| 7463 | } else { |
| 7464 | maxRight = right; |
| 7465 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7466 | invalidate(0, 0, maxRight - mLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7467 | } |
| 7468 | } else { |
| 7469 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7470 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7471 | } |
| 7472 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7473 | int oldWidth = mRight - mLeft; |
| 7474 | int height = mBottom - mTop; |
| 7475 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7476 | mRight = right; |
| 7477 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7478 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 7479 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7480 | if (!mMatrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7481 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 7482 | // A change in dimension means an auto-centered pivot point changes, too |
| 7483 | mMatrixDirty = true; |
| 7484 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7485 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7486 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7487 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 7488 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 7489 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7490 | } |
| 7491 | } |
| 7492 | |
| 7493 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7494 | * The visual x position of this view, in pixels. This is equivalent to the |
| 7495 | * {@link #setTranslationX(float) translationX} property plus the current |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7496 | * {@link #getLeft() left} property. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7497 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7498 | * @return The visual x position of this view, in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7499 | */ |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7500 | public float getX() { |
| 7501 | return mLeft + mTranslationX; |
| 7502 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7503 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7504 | /** |
| 7505 | * Sets the visual x position of this view, in pixels. This is equivalent to setting the |
| 7506 | * {@link #setTranslationX(float) translationX} property to be the difference between |
| 7507 | * the x value passed in and the current {@link #getLeft() left} property. |
| 7508 | * |
| 7509 | * @param x The visual x position of this view, in pixels. |
| 7510 | */ |
| 7511 | public void setX(float x) { |
| 7512 | setTranslationX(x - mLeft); |
| 7513 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7514 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7515 | /** |
| 7516 | * The visual y position of this view, in pixels. This is equivalent to the |
| 7517 | * {@link #setTranslationY(float) translationY} property plus the current |
| 7518 | * {@link #getTop() top} property. |
| 7519 | * |
| 7520 | * @return The visual y position of this view, in pixels. |
| 7521 | */ |
| 7522 | public float getY() { |
| 7523 | return mTop + mTranslationY; |
| 7524 | } |
| 7525 | |
| 7526 | /** |
| 7527 | * Sets the visual y position of this view, in pixels. This is equivalent to setting the |
| 7528 | * {@link #setTranslationY(float) translationY} property to be the difference between |
| 7529 | * the y value passed in and the current {@link #getTop() top} property. |
| 7530 | * |
| 7531 | * @param y The visual y position of this view, in pixels. |
| 7532 | */ |
| 7533 | public void setY(float y) { |
| 7534 | setTranslationY(y - mTop); |
| 7535 | } |
| 7536 | |
| 7537 | |
| 7538 | /** |
| 7539 | * The horizontal location of this view relative to its {@link #getLeft() left} position. |
| 7540 | * This position is post-layout, in addition to wherever the object's |
| 7541 | * layout placed it. |
| 7542 | * |
| 7543 | * @return The horizontal position of this view relative to its left position, in pixels. |
| 7544 | */ |
| 7545 | public float getTranslationX() { |
| 7546 | return mTranslationX; |
| 7547 | } |
| 7548 | |
| 7549 | /** |
| 7550 | * Sets the horizontal location of this view relative to its {@link #getLeft() left} position. |
| 7551 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 7552 | * layout placed it. |
| 7553 | * |
| 7554 | * @param translationX The horizontal position of this view relative to its left position, |
| 7555 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7556 | * |
| 7557 | * @attr ref android.R.styleable#View_translationX |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7558 | */ |
| 7559 | public void setTranslationX(float translationX) { |
| 7560 | if (mTranslationX != translationX) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7561 | invalidateParentCaches(); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7562 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7563 | invalidate(false); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7564 | mTranslationX = translationX; |
| 7565 | mMatrixDirty = true; |
| 7566 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7567 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7568 | } |
| 7569 | } |
| 7570 | |
| 7571 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7572 | * The horizontal location of this view relative to its {@link #getTop() top} position. |
| 7573 | * This position is post-layout, in addition to wherever the object's |
| 7574 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7575 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7576 | * @return The vertical position of this view relative to its top position, |
| 7577 | * in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7578 | */ |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7579 | public float getTranslationY() { |
| 7580 | return mTranslationY; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7581 | } |
| 7582 | |
| 7583 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7584 | * Sets the vertical location of this view relative to its {@link #getTop() top} position. |
| 7585 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 7586 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7587 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7588 | * @param translationY The vertical position of this view relative to its top position, |
| 7589 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7590 | * |
| 7591 | * @attr ref android.R.styleable#View_translationY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7592 | */ |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7593 | public void setTranslationY(float translationY) { |
| 7594 | if (mTranslationY != translationY) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7595 | invalidateParentCaches(); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7596 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7597 | invalidate(false); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7598 | mTranslationY = translationY; |
| 7599 | mMatrixDirty = true; |
| 7600 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7601 | invalidate(false); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7602 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7603 | } |
| 7604 | |
| 7605 | /** |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 7606 | * @hide |
| 7607 | */ |
Michael Jurka | dece29f | 2011-02-03 01:41:49 -0800 | [diff] [blame] | 7608 | public void setFastTranslationX(float x) { |
| 7609 | mTranslationX = x; |
| 7610 | mMatrixDirty = true; |
| 7611 | } |
| 7612 | |
| 7613 | /** |
| 7614 | * @hide |
| 7615 | */ |
| 7616 | public void setFastTranslationY(float y) { |
| 7617 | mTranslationY = y; |
| 7618 | mMatrixDirty = true; |
| 7619 | } |
| 7620 | |
| 7621 | /** |
| 7622 | * @hide |
| 7623 | */ |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 7624 | public void setFastX(float x) { |
| 7625 | mTranslationX = x - mLeft; |
| 7626 | mMatrixDirty = true; |
| 7627 | } |
| 7628 | |
| 7629 | /** |
| 7630 | * @hide |
| 7631 | */ |
| 7632 | public void setFastY(float y) { |
| 7633 | mTranslationY = y - mTop; |
| 7634 | mMatrixDirty = true; |
| 7635 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 7636 | |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 7637 | /** |
| 7638 | * @hide |
| 7639 | */ |
| 7640 | public void setFastScaleX(float x) { |
| 7641 | mScaleX = x; |
| 7642 | mMatrixDirty = true; |
| 7643 | } |
| 7644 | |
| 7645 | /** |
| 7646 | * @hide |
| 7647 | */ |
| 7648 | public void setFastScaleY(float y) { |
| 7649 | mScaleY = y; |
| 7650 | mMatrixDirty = true; |
| 7651 | } |
| 7652 | |
| 7653 | /** |
| 7654 | * @hide |
| 7655 | */ |
| 7656 | public void setFastAlpha(float alpha) { |
| 7657 | mAlpha = alpha; |
| 7658 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 7659 | |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 7660 | /** |
| 7661 | * @hide |
| 7662 | */ |
| 7663 | public void setFastRotationY(float y) { |
| 7664 | mRotationY = y; |
| 7665 | mMatrixDirty = true; |
| 7666 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 7667 | |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 7668 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7669 | * Hit rectangle in parent's coordinates |
| 7670 | * |
| 7671 | * @param outRect The hit rectangle of the view. |
| 7672 | */ |
| 7673 | public void getHitRect(Rect outRect) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7674 | updateMatrix(); |
| 7675 | if (mMatrixIsIdentity || mAttachInfo == null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7676 | outRect.set(mLeft, mTop, mRight, mBottom); |
| 7677 | } else { |
| 7678 | final RectF tmpRect = mAttachInfo.mTmpTransformRect; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7679 | tmpRect.set(-mPivotX, -mPivotY, getWidth() - mPivotX, getHeight() - mPivotY); |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7680 | mMatrix.mapRect(tmpRect); |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7681 | outRect.set((int) tmpRect.left + mLeft, (int) tmpRect.top + mTop, |
| 7682 | (int) tmpRect.right + mLeft, (int) tmpRect.bottom + mTop); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7683 | } |
| 7684 | } |
| 7685 | |
| 7686 | /** |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 7687 | * Determines whether the given point, in local coordinates is inside the view. |
| 7688 | */ |
| 7689 | /*package*/ final boolean pointInView(float localX, float localY) { |
| 7690 | return localX >= 0 && localX < (mRight - mLeft) |
| 7691 | && localY >= 0 && localY < (mBottom - mTop); |
| 7692 | } |
| 7693 | |
| 7694 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7695 | * Utility method to determine whether the given point, in local coordinates, |
| 7696 | * is inside the view, where the area of the view is expanded by the slop factor. |
| 7697 | * This method is called while processing touch-move events to determine if the event |
| 7698 | * is still within the view. |
| 7699 | */ |
| 7700 | private boolean pointInView(float localX, float localY, float slop) { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 7701 | return localX >= -slop && localY >= -slop && localX < ((mRight - mLeft) + slop) && |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7702 | localY < ((mBottom - mTop) + slop); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7703 | } |
| 7704 | |
| 7705 | /** |
| 7706 | * When a view has focus and the user navigates away from it, the next view is searched for |
| 7707 | * starting from the rectangle filled in by this method. |
| 7708 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7709 | * By default, the rectange is the {@link #getDrawingRect(android.graphics.Rect)}) |
| 7710 | * of the view. However, if your view maintains some idea of internal selection, |
| 7711 | * such as a cursor, or a selected row or column, you should override this method and |
| 7712 | * fill in a more specific rectangle. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7713 | * |
| 7714 | * @param r The rectangle to fill in, in this view's coordinates. |
| 7715 | */ |
| 7716 | public void getFocusedRect(Rect r) { |
| 7717 | getDrawingRect(r); |
| 7718 | } |
| 7719 | |
| 7720 | /** |
| 7721 | * If some part of this view is not clipped by any of its parents, then |
| 7722 | * return that area in r in global (root) coordinates. To convert r to local |
| 7723 | * coordinates, offset it by -globalOffset (e.g. r.offset(-globalOffset.x, |
| 7724 | * -globalOffset.y)) If the view is completely clipped or translated out, |
| 7725 | * return false. |
| 7726 | * |
| 7727 | * @param r If true is returned, r holds the global coordinates of the |
| 7728 | * visible portion of this view. |
| 7729 | * @param globalOffset If true is returned, globalOffset holds the dx,dy |
| 7730 | * between this view and its root. globalOffet may be null. |
| 7731 | * @return true if r is non-empty (i.e. part of the view is visible at the |
| 7732 | * root level. |
| 7733 | */ |
| 7734 | public boolean getGlobalVisibleRect(Rect r, Point globalOffset) { |
| 7735 | int width = mRight - mLeft; |
| 7736 | int height = mBottom - mTop; |
| 7737 | if (width > 0 && height > 0) { |
| 7738 | r.set(0, 0, width, height); |
| 7739 | if (globalOffset != null) { |
| 7740 | globalOffset.set(-mScrollX, -mScrollY); |
| 7741 | } |
| 7742 | return mParent == null || mParent.getChildVisibleRect(this, r, globalOffset); |
| 7743 | } |
| 7744 | return false; |
| 7745 | } |
| 7746 | |
| 7747 | public final boolean getGlobalVisibleRect(Rect r) { |
| 7748 | return getGlobalVisibleRect(r, null); |
| 7749 | } |
| 7750 | |
| 7751 | public final boolean getLocalVisibleRect(Rect r) { |
| 7752 | Point offset = new Point(); |
| 7753 | if (getGlobalVisibleRect(r, offset)) { |
| 7754 | r.offset(-offset.x, -offset.y); // make r local |
| 7755 | return true; |
| 7756 | } |
| 7757 | return false; |
| 7758 | } |
| 7759 | |
| 7760 | /** |
| 7761 | * Offset this view's vertical location by the specified number of pixels. |
| 7762 | * |
| 7763 | * @param offset the number of pixels to offset the view by |
| 7764 | */ |
| 7765 | public void offsetTopAndBottom(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7766 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7767 | updateMatrix(); |
| 7768 | if (mMatrixIsIdentity) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7769 | final ViewParent p = mParent; |
| 7770 | if (p != null && mAttachInfo != null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7771 | final Rect r = mAttachInfo.mTmpInvalRect; |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 7772 | int minTop; |
| 7773 | int maxBottom; |
| 7774 | int yLoc; |
| 7775 | if (offset < 0) { |
| 7776 | minTop = mTop + offset; |
| 7777 | maxBottom = mBottom; |
| 7778 | yLoc = offset; |
| 7779 | } else { |
| 7780 | minTop = mTop; |
| 7781 | maxBottom = mBottom + offset; |
| 7782 | yLoc = 0; |
| 7783 | } |
| 7784 | r.set(0, yLoc, mRight - mLeft, maxBottom - minTop); |
| 7785 | p.invalidateChild(this, r); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7786 | } |
| 7787 | } else { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7788 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7789 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7790 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7791 | mTop += offset; |
| 7792 | mBottom += offset; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7793 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7794 | if (!mMatrixIsIdentity) { |
| 7795 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7796 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7797 | } |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 7798 | invalidateParentIfNeeded(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7799 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7800 | } |
| 7801 | |
| 7802 | /** |
| 7803 | * Offset this view's horizontal location by the specified amount of pixels. |
| 7804 | * |
| 7805 | * @param offset the numer of pixels to offset the view by |
| 7806 | */ |
| 7807 | public void offsetLeftAndRight(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7808 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7809 | updateMatrix(); |
| 7810 | if (mMatrixIsIdentity) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7811 | final ViewParent p = mParent; |
| 7812 | if (p != null && mAttachInfo != null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7813 | final Rect r = mAttachInfo.mTmpInvalRect; |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 7814 | int minLeft; |
| 7815 | int maxRight; |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 7816 | if (offset < 0) { |
| 7817 | minLeft = mLeft + offset; |
| 7818 | maxRight = mRight; |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 7819 | } else { |
| 7820 | minLeft = mLeft; |
| 7821 | maxRight = mRight + offset; |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 7822 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7823 | r.set(0, 0, maxRight - minLeft, mBottom - mTop); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 7824 | p.invalidateChild(this, r); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7825 | } |
| 7826 | } else { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7827 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7828 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7829 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7830 | mLeft += offset; |
| 7831 | mRight += offset; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7832 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7833 | if (!mMatrixIsIdentity) { |
| 7834 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7835 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7836 | } |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 7837 | invalidateParentIfNeeded(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7838 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7839 | } |
| 7840 | |
| 7841 | /** |
| 7842 | * Get the LayoutParams associated with this view. All views should have |
| 7843 | * layout parameters. These supply parameters to the <i>parent</i> of this |
| 7844 | * view specifying how it should be arranged. There are many subclasses of |
| 7845 | * ViewGroup.LayoutParams, and these correspond to the different subclasses |
| 7846 | * of ViewGroup that are responsible for arranging their children. |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 7847 | * |
| 7848 | * This method may return null if this View is not attached to a parent |
| 7849 | * ViewGroup or {@link #setLayoutParams(android.view.ViewGroup.LayoutParams)} |
| 7850 | * was not invoked successfully. When a View is attached to a parent |
| 7851 | * ViewGroup, this method must not return null. |
| 7852 | * |
| 7853 | * @return The LayoutParams associated with this view, or null if no |
| 7854 | * parameters have been set yet |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7855 | */ |
Konstantin Lopyrev | 91a7f5f | 2010-08-10 18:54:54 -0700 | [diff] [blame] | 7856 | @ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7857 | public ViewGroup.LayoutParams getLayoutParams() { |
| 7858 | return mLayoutParams; |
| 7859 | } |
| 7860 | |
| 7861 | /** |
| 7862 | * Set the layout parameters associated with this view. These supply |
| 7863 | * parameters to the <i>parent</i> of this view specifying how it should be |
| 7864 | * arranged. There are many subclasses of ViewGroup.LayoutParams, and these |
| 7865 | * correspond to the different subclasses of ViewGroup that are responsible |
| 7866 | * for arranging their children. |
| 7867 | * |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 7868 | * @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] | 7869 | */ |
| 7870 | public void setLayoutParams(ViewGroup.LayoutParams params) { |
| 7871 | if (params == null) { |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 7872 | throw new NullPointerException("Layout parameters cannot be null"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7873 | } |
| 7874 | mLayoutParams = params; |
| 7875 | requestLayout(); |
| 7876 | } |
| 7877 | |
| 7878 | /** |
| 7879 | * Set the scrolled position of your view. This will cause a call to |
| 7880 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 7881 | * invalidated. |
| 7882 | * @param x the x position to scroll to |
| 7883 | * @param y the y position to scroll to |
| 7884 | */ |
| 7885 | public void scrollTo(int x, int y) { |
| 7886 | if (mScrollX != x || mScrollY != y) { |
| 7887 | int oldX = mScrollX; |
| 7888 | int oldY = mScrollY; |
| 7889 | mScrollX = x; |
| 7890 | mScrollY = y; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7891 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7892 | onScrollChanged(mScrollX, mScrollY, oldX, oldY); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 7893 | if (!awakenScrollBars()) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7894 | invalidate(true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 7895 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7896 | } |
| 7897 | } |
| 7898 | |
| 7899 | /** |
| 7900 | * Move the scrolled position of your view. This will cause a call to |
| 7901 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 7902 | * invalidated. |
| 7903 | * @param x the amount of pixels to scroll by horizontally |
| 7904 | * @param y the amount of pixels to scroll by vertically |
| 7905 | */ |
| 7906 | public void scrollBy(int x, int y) { |
| 7907 | scrollTo(mScrollX + x, mScrollY + y); |
| 7908 | } |
| 7909 | |
| 7910 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 7911 | * <p>Trigger the scrollbars to draw. When invoked this method starts an |
| 7912 | * animation to fade the scrollbars out after a default delay. If a subclass |
| 7913 | * provides animated scrolling, the start delay should equal the duration |
| 7914 | * of the scrolling animation.</p> |
| 7915 | * |
| 7916 | * <p>The animation starts only if at least one of the scrollbars is |
| 7917 | * enabled, as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 7918 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 7919 | * this method returns true, and false otherwise. If the animation is |
| 7920 | * started, this method calls {@link #invalidate()}; in that case the |
| 7921 | * caller should not call {@link #invalidate()}.</p> |
| 7922 | * |
| 7923 | * <p>This method should be invoked every time a subclass directly updates |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 7924 | * the scroll parameters.</p> |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 7925 | * |
| 7926 | * <p>This method is automatically invoked by {@link #scrollBy(int, int)} |
| 7927 | * and {@link #scrollTo(int, int)}.</p> |
| 7928 | * |
| 7929 | * @return true if the animation is played, false otherwise |
| 7930 | * |
| 7931 | * @see #awakenScrollBars(int) |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 7932 | * @see #scrollBy(int, int) |
| 7933 | * @see #scrollTo(int, int) |
| 7934 | * @see #isHorizontalScrollBarEnabled() |
| 7935 | * @see #isVerticalScrollBarEnabled() |
| 7936 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 7937 | * @see #setVerticalScrollBarEnabled(boolean) |
| 7938 | */ |
| 7939 | protected boolean awakenScrollBars() { |
| 7940 | return mScrollCache != null && |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 7941 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade, true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 7942 | } |
| 7943 | |
| 7944 | /** |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 7945 | * Trigger the scrollbars to draw. |
| 7946 | * This method differs from awakenScrollBars() only in its default duration. |
| 7947 | * initialAwakenScrollBars() will show the scroll bars for longer than |
| 7948 | * usual to give the user more of a chance to notice them. |
| 7949 | * |
| 7950 | * @return true if the animation is played, false otherwise. |
| 7951 | */ |
| 7952 | private boolean initialAwakenScrollBars() { |
| 7953 | return mScrollCache != null && |
| 7954 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade * 4, true); |
| 7955 | } |
| 7956 | |
| 7957 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 7958 | * <p> |
| 7959 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 7960 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 7961 | * provides animated scrolling, the start delay should equal the duration of |
| 7962 | * the scrolling animation. |
| 7963 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7964 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 7965 | * <p> |
| 7966 | * The animation starts only if at least one of the scrollbars is enabled, |
| 7967 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 7968 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 7969 | * this method returns true, and false otherwise. If the animation is |
| 7970 | * started, this method calls {@link #invalidate()}; in that case the caller |
| 7971 | * should not call {@link #invalidate()}. |
| 7972 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7973 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 7974 | * <p> |
| 7975 | * This method should be invoked everytime a subclass directly updates the |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 7976 | * scroll parameters. |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 7977 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7978 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 7979 | * @param startDelay the delay, in milliseconds, after which the animation |
| 7980 | * should start; when the delay is 0, the animation starts |
| 7981 | * immediately |
| 7982 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7983 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 7984 | * @see #scrollBy(int, int) |
| 7985 | * @see #scrollTo(int, int) |
| 7986 | * @see #isHorizontalScrollBarEnabled() |
| 7987 | * @see #isVerticalScrollBarEnabled() |
| 7988 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 7989 | * @see #setVerticalScrollBarEnabled(boolean) |
| 7990 | */ |
| 7991 | protected boolean awakenScrollBars(int startDelay) { |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 7992 | return awakenScrollBars(startDelay, true); |
| 7993 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7994 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 7995 | /** |
| 7996 | * <p> |
| 7997 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 7998 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 7999 | * provides animated scrolling, the start delay should equal the duration of |
| 8000 | * the scrolling animation. |
| 8001 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8002 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8003 | * <p> |
| 8004 | * The animation starts only if at least one of the scrollbars is enabled, |
| 8005 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 8006 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 8007 | * this method returns true, and false otherwise. If the animation is |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8008 | * started, this method calls {@link #invalidate()} if the invalidate parameter |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8009 | * is set to true; in that case the caller |
| 8010 | * should not call {@link #invalidate()}. |
| 8011 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8012 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8013 | * <p> |
| 8014 | * This method should be invoked everytime a subclass directly updates the |
| 8015 | * scroll parameters. |
| 8016 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8017 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8018 | * @param startDelay the delay, in milliseconds, after which the animation |
| 8019 | * should start; when the delay is 0, the animation starts |
| 8020 | * immediately |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8021 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8022 | * @param invalidate Wheter this method should call invalidate |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8023 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8024 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8025 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8026 | * @see #scrollBy(int, int) |
| 8027 | * @see #scrollTo(int, int) |
| 8028 | * @see #isHorizontalScrollBarEnabled() |
| 8029 | * @see #isVerticalScrollBarEnabled() |
| 8030 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 8031 | * @see #setVerticalScrollBarEnabled(boolean) |
| 8032 | */ |
| 8033 | protected boolean awakenScrollBars(int startDelay, boolean invalidate) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8034 | final ScrollabilityCache scrollCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8035 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8036 | if (scrollCache == null || !scrollCache.fadeScrollBars) { |
| 8037 | return false; |
| 8038 | } |
| 8039 | |
| 8040 | if (scrollCache.scrollBar == null) { |
| 8041 | scrollCache.scrollBar = new ScrollBarDrawable(); |
| 8042 | } |
| 8043 | |
| 8044 | if (isHorizontalScrollBarEnabled() || isVerticalScrollBarEnabled()) { |
| 8045 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8046 | if (invalidate) { |
| 8047 | // Invalidate to show the scrollbars |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8048 | invalidate(true); |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8049 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8050 | |
| 8051 | if (scrollCache.state == ScrollabilityCache.OFF) { |
| 8052 | // FIXME: this is copied from WindowManagerService. |
| 8053 | // We should get this value from the system when it |
| 8054 | // is possible to do so. |
| 8055 | final int KEY_REPEAT_FIRST_DELAY = 750; |
| 8056 | startDelay = Math.max(KEY_REPEAT_FIRST_DELAY, startDelay); |
| 8057 | } |
| 8058 | |
| 8059 | // Tell mScrollCache when we should start fading. This may |
| 8060 | // extend the fade start time if one was already scheduled |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 8061 | long fadeStartTime = AnimationUtils.currentAnimationTimeMillis() + startDelay; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8062 | scrollCache.fadeStartTime = fadeStartTime; |
| 8063 | scrollCache.state = ScrollabilityCache.ON; |
| 8064 | |
| 8065 | // Schedule our fader to run, unscheduling any old ones first |
| 8066 | if (mAttachInfo != null) { |
| 8067 | mAttachInfo.mHandler.removeCallbacks(scrollCache); |
| 8068 | mAttachInfo.mHandler.postAtTime(scrollCache, fadeStartTime); |
| 8069 | } |
| 8070 | |
| 8071 | return true; |
| 8072 | } |
| 8073 | |
| 8074 | return false; |
| 8075 | } |
| 8076 | |
| 8077 | /** |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8078 | * Do not invalidate views which are not visible and which are not running an animation. They |
| 8079 | * will not get drawn and they should not set dirty flags as if they will be drawn |
| 8080 | */ |
| 8081 | private boolean skipInvalidate() { |
| 8082 | return (mViewFlags & VISIBILITY_MASK) != VISIBLE && mCurrentAnimation == null && |
| 8083 | (!(mParent instanceof ViewGroup) || |
| 8084 | !((ViewGroup) mParent).isViewTransitioning(this)); |
| 8085 | } |
| 8086 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8087 | * Mark the 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] | 8088 | * visible, {@link #onDraw(android.graphics.Canvas)} will be called at some point |
| 8089 | * in the future. This must be called from a UI thread. To call from a non-UI |
| 8090 | * thread, call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8091 | * |
| 8092 | * WARNING: This method is destructive to dirty. |
| 8093 | * @param dirty the rectangle representing the bounds of the dirty region |
| 8094 | */ |
| 8095 | public void invalidate(Rect dirty) { |
| 8096 | if (ViewDebug.TRACE_HIERARCHY) { |
| 8097 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 8098 | } |
| 8099 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8100 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 8101 | return; |
| 8102 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8103 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8104 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || |
| 8105 | (mPrivateFlags & INVALIDATED) != INVALIDATED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8106 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8107 | mPrivateFlags |= INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8108 | final ViewParent p = mParent; |
| 8109 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8110 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 8111 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 8112 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 8113 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 8114 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8115 | p.invalidateChild(this, null); |
| 8116 | return; |
| 8117 | } |
Romain Guy | af636eb | 2010-12-09 17:47:21 -0800 | [diff] [blame] | 8118 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8119 | if (p != null && ai != null) { |
| 8120 | final int scrollX = mScrollX; |
| 8121 | final int scrollY = mScrollY; |
| 8122 | final Rect r = ai.mTmpInvalRect; |
| 8123 | r.set(dirty.left - scrollX, dirty.top - scrollY, |
| 8124 | dirty.right - scrollX, dirty.bottom - scrollY); |
| 8125 | mParent.invalidateChild(this, r); |
| 8126 | } |
| 8127 | } |
| 8128 | } |
| 8129 | |
| 8130 | /** |
| 8131 | * Mark the the area defined by the rect (l,t,r,b) as needing to be drawn. |
| 8132 | * The coordinates of the dirty rect are relative to the view. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8133 | * If the view is visible, {@link #onDraw(android.graphics.Canvas)} |
| 8134 | * will be called at some point in the future. This must be called from |
| 8135 | * 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] | 8136 | * @param l the left position of the dirty region |
| 8137 | * @param t the top position of the dirty region |
| 8138 | * @param r the right position of the dirty region |
| 8139 | * @param b the bottom position of the dirty region |
| 8140 | */ |
| 8141 | public void invalidate(int l, int t, int r, int b) { |
| 8142 | if (ViewDebug.TRACE_HIERARCHY) { |
| 8143 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 8144 | } |
| 8145 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8146 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 8147 | return; |
| 8148 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8149 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8150 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || |
| 8151 | (mPrivateFlags & INVALIDATED) != INVALIDATED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8152 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8153 | mPrivateFlags |= INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8154 | final ViewParent p = mParent; |
| 8155 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8156 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 8157 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 8158 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 8159 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 8160 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8161 | p.invalidateChild(this, null); |
| 8162 | return; |
| 8163 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 8164 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8165 | if (p != null && ai != null && l < r && t < b) { |
| 8166 | final int scrollX = mScrollX; |
| 8167 | final int scrollY = mScrollY; |
| 8168 | final Rect tmpr = ai.mTmpInvalRect; |
| 8169 | tmpr.set(l - scrollX, t - scrollY, r - scrollX, b - scrollY); |
| 8170 | p.invalidateChild(this, tmpr); |
| 8171 | } |
| 8172 | } |
| 8173 | } |
| 8174 | |
| 8175 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8176 | * Invalidate the whole view. If the view is visible, |
| 8177 | * {@link #onDraw(android.graphics.Canvas)} will be called at some point in |
| 8178 | * the future. This must be called from a UI thread. To call from a non-UI thread, |
| 8179 | * call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8180 | */ |
| 8181 | public void invalidate() { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8182 | invalidate(true); |
| 8183 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8184 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8185 | /** |
| 8186 | * This is where the invalidate() work actually happens. A full invalidate() |
| 8187 | * causes the drawing cache to be invalidated, but this function can be called with |
| 8188 | * invalidateCache set to false to skip that invalidation step for cases that do not |
| 8189 | * need it (for example, a component that remains at the same dimensions with the same |
| 8190 | * content). |
| 8191 | * |
| 8192 | * @param invalidateCache Whether the drawing cache for this view should be invalidated as |
| 8193 | * well. This is usually true for a full invalidate, but may be set to false if the |
| 8194 | * View's contents or dimensions have not changed. |
| 8195 | */ |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 8196 | void invalidate(boolean invalidateCache) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8197 | if (ViewDebug.TRACE_HIERARCHY) { |
| 8198 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 8199 | } |
| 8200 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8201 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 8202 | return; |
| 8203 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8204 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Romain Guy | c5d5586 | 2011-01-21 19:01:46 -0800 | [diff] [blame] | 8205 | (invalidateCache && (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) || |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8206 | (mPrivateFlags & INVALIDATED) != INVALIDATED || isOpaque() != mLastIsOpaque) { |
| 8207 | mLastIsOpaque = isOpaque(); |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8208 | mPrivateFlags &= ~DRAWN; |
| 8209 | if (invalidateCache) { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8210 | mPrivateFlags |= INVALIDATED; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8211 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 8212 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8213 | final AttachInfo ai = mAttachInfo; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 8214 | final ViewParent p = mParent; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8215 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 8216 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 8217 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 8218 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 8219 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8220 | p.invalidateChild(this, null); |
| 8221 | return; |
| 8222 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 8223 | } |
Michael Jurka | ebefea4 | 2010-11-15 16:04:01 -0800 | [diff] [blame] | 8224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8225 | if (p != null && ai != null) { |
| 8226 | final Rect r = ai.mTmpInvalRect; |
| 8227 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 8228 | // Don't call invalidate -- we don't want to internally scroll |
| 8229 | // our own bounds |
| 8230 | p.invalidateChild(this, r); |
| 8231 | } |
| 8232 | } |
| 8233 | } |
| 8234 | |
| 8235 | /** |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8236 | * @hide |
| 8237 | */ |
| 8238 | public void fastInvalidate() { |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8239 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 8240 | return; |
| 8241 | } |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8242 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
| 8243 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || |
| 8244 | (mPrivateFlags & INVALIDATED) != INVALIDATED) { |
| 8245 | if (mParent instanceof View) { |
| 8246 | ((View) mParent).mPrivateFlags |= INVALIDATED; |
| 8247 | } |
| 8248 | mPrivateFlags &= ~DRAWN; |
| 8249 | mPrivateFlags |= INVALIDATED; |
| 8250 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Michael Jurka | d0872bd | 2011-03-24 15:44:19 -0700 | [diff] [blame] | 8251 | if (mParent != null && mAttachInfo != null) { |
| 8252 | if (mAttachInfo.mHardwareAccelerated) { |
| 8253 | mParent.invalidateChild(this, null); |
| 8254 | } else { |
| 8255 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 8256 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 8257 | // Don't call invalidate -- we don't want to internally scroll |
| 8258 | // our own bounds |
| 8259 | mParent.invalidateChild(this, r); |
| 8260 | } |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8261 | } |
| 8262 | } |
| 8263 | } |
| 8264 | |
| 8265 | /** |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8266 | * 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] | 8267 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 8268 | * 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] | 8269 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method only |
| 8270 | * clears the parent caches and does not causes an invalidate event. |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8271 | * |
| 8272 | * @hide |
| 8273 | */ |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8274 | protected void invalidateParentCaches() { |
| 8275 | if (mParent instanceof View) { |
| 8276 | ((View) mParent).mPrivateFlags |= INVALIDATED; |
| 8277 | } |
| 8278 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8279 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8280 | /** |
| 8281 | * Used to indicate that the parent of this view should be invalidated. This functionality |
| 8282 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 8283 | * which is necessary when various parent-managed properties of the view change, such as |
| 8284 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method will propagate |
| 8285 | * an invalidation event to the parent. |
| 8286 | * |
| 8287 | * @hide |
| 8288 | */ |
| 8289 | protected void invalidateParentIfNeeded() { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8290 | if (isHardwareAccelerated() && mParent instanceof View) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8291 | ((View) mParent).invalidate(true); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8292 | } |
| 8293 | } |
| 8294 | |
| 8295 | /** |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 8296 | * Indicates whether this View is opaque. An opaque View guarantees that it will |
| 8297 | * draw all the pixels overlapping its bounds using a fully opaque color. |
| 8298 | * |
| 8299 | * Subclasses of View should override this method whenever possible to indicate |
| 8300 | * whether an instance is opaque. Opaque Views are treated in a special way by |
| 8301 | * the View hierarchy, possibly allowing it to perform optimizations during |
| 8302 | * invalidate/draw passes. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 8303 | * |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 8304 | * @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] | 8305 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 8306 | @ViewDebug.ExportedProperty(category = "drawing") |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 8307 | public boolean isOpaque() { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 8308 | return (mPrivateFlags & OPAQUE_MASK) == OPAQUE_MASK && |
| 8309 | (mAlpha >= 1.0f - ViewConfiguration.ALPHA_THRESHOLD); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 8310 | } |
| 8311 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 8312 | /** |
| 8313 | * @hide |
| 8314 | */ |
| 8315 | protected void computeOpaqueFlags() { |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 8316 | // Opaque if: |
| 8317 | // - Has a background |
| 8318 | // - Background is opaque |
| 8319 | // - Doesn't have scrollbars or scrollbars are inside overlay |
| 8320 | |
| 8321 | if (mBGDrawable != null && mBGDrawable.getOpacity() == PixelFormat.OPAQUE) { |
| 8322 | mPrivateFlags |= OPAQUE_BACKGROUND; |
| 8323 | } else { |
| 8324 | mPrivateFlags &= ~OPAQUE_BACKGROUND; |
| 8325 | } |
| 8326 | |
| 8327 | final int flags = mViewFlags; |
| 8328 | if (((flags & SCROLLBARS_VERTICAL) == 0 && (flags & SCROLLBARS_HORIZONTAL) == 0) || |
| 8329 | (flags & SCROLLBARS_STYLE_MASK) == SCROLLBARS_INSIDE_OVERLAY) { |
| 8330 | mPrivateFlags |= OPAQUE_SCROLLBARS; |
| 8331 | } else { |
| 8332 | mPrivateFlags &= ~OPAQUE_SCROLLBARS; |
| 8333 | } |
| 8334 | } |
| 8335 | |
| 8336 | /** |
| 8337 | * @hide |
| 8338 | */ |
| 8339 | protected boolean hasOpaqueScrollbars() { |
| 8340 | return (mPrivateFlags & OPAQUE_SCROLLBARS) == OPAQUE_SCROLLBARS; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 8341 | } |
| 8342 | |
| 8343 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8344 | * @return A handler associated with the thread running the View. This |
| 8345 | * handler can be used to pump events in the UI events queue. |
| 8346 | */ |
| 8347 | public Handler getHandler() { |
| 8348 | if (mAttachInfo != null) { |
| 8349 | return mAttachInfo.mHandler; |
| 8350 | } |
| 8351 | return null; |
| 8352 | } |
| 8353 | |
| 8354 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8355 | * <p>Causes the Runnable to be added to the message queue. |
| 8356 | * The runnable will be run on the user interface thread.</p> |
| 8357 | * |
| 8358 | * <p>This method can be invoked from outside of the UI thread |
| 8359 | * 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] | 8360 | * |
| 8361 | * @param action The Runnable that will be executed. |
| 8362 | * |
| 8363 | * @return Returns true if the Runnable was successfully placed in to the |
| 8364 | * message queue. Returns false on failure, usually because the |
| 8365 | * looper processing the message queue is exiting. |
| 8366 | */ |
| 8367 | public boolean post(Runnable action) { |
| 8368 | Handler handler; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8369 | AttachInfo attachInfo = mAttachInfo; |
| 8370 | if (attachInfo != null) { |
| 8371 | handler = attachInfo.mHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8372 | } else { |
| 8373 | // Assume that post will succeed later |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8374 | ViewRootImpl.getRunQueue().post(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8375 | return true; |
| 8376 | } |
| 8377 | |
| 8378 | return handler.post(action); |
| 8379 | } |
| 8380 | |
| 8381 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8382 | * <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] | 8383 | * after the specified amount of time elapses. |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8384 | * The runnable will be run on the user interface thread.</p> |
| 8385 | * |
| 8386 | * <p>This method can be invoked from outside of the UI thread |
| 8387 | * 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] | 8388 | * |
| 8389 | * @param action The Runnable that will be executed. |
| 8390 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 8391 | * will be executed. |
| 8392 | * |
| 8393 | * @return true if the Runnable was successfully placed in to the |
| 8394 | * message queue. Returns false on failure, usually because the |
| 8395 | * looper processing the message queue is exiting. Note that a |
| 8396 | * result of true does not mean the Runnable will be processed -- |
| 8397 | * if the looper is quit before the delivery time of the message |
| 8398 | * occurs then the message will be dropped. |
| 8399 | */ |
| 8400 | public boolean postDelayed(Runnable action, long delayMillis) { |
| 8401 | Handler handler; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8402 | AttachInfo attachInfo = mAttachInfo; |
| 8403 | if (attachInfo != null) { |
| 8404 | handler = attachInfo.mHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8405 | } else { |
| 8406 | // Assume that post will succeed later |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8407 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8408 | return true; |
| 8409 | } |
| 8410 | |
| 8411 | return handler.postDelayed(action, delayMillis); |
| 8412 | } |
| 8413 | |
| 8414 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8415 | * <p>Removes the specified Runnable from the message queue.</p> |
| 8416 | * |
| 8417 | * <p>This method can be invoked from outside of the UI thread |
| 8418 | * 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] | 8419 | * |
| 8420 | * @param action The Runnable to remove from the message handling queue |
| 8421 | * |
| 8422 | * @return true if this view could ask the Handler to remove the Runnable, |
| 8423 | * false otherwise. When the returned value is true, the Runnable |
| 8424 | * may or may not have been actually removed from the message queue |
| 8425 | * (for instance, if the Runnable was not in the queue already.) |
| 8426 | */ |
| 8427 | public boolean removeCallbacks(Runnable action) { |
| 8428 | Handler handler; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8429 | AttachInfo attachInfo = mAttachInfo; |
| 8430 | if (attachInfo != null) { |
| 8431 | handler = attachInfo.mHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8432 | } else { |
| 8433 | // Assume that post will succeed later |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8434 | ViewRootImpl.getRunQueue().removeCallbacks(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8435 | return true; |
| 8436 | } |
| 8437 | |
| 8438 | handler.removeCallbacks(action); |
| 8439 | return true; |
| 8440 | } |
| 8441 | |
| 8442 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8443 | * <p>Cause an invalidate to happen on a subsequent cycle through the event loop. |
| 8444 | * 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] | 8445 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8446 | * <p>This method can be invoked from outside of the UI thread |
| 8447 | * only when this View is attached to a window.</p> |
| 8448 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8449 | * @see #invalidate() |
| 8450 | */ |
| 8451 | public void postInvalidate() { |
| 8452 | postInvalidateDelayed(0); |
| 8453 | } |
| 8454 | |
| 8455 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8456 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 8457 | * through the event loop. Use this to invalidate the View from a non-UI thread.</p> |
| 8458 | * |
| 8459 | * <p>This method can be invoked from outside of the UI thread |
| 8460 | * 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] | 8461 | * |
| 8462 | * @param left The left coordinate of the rectangle to invalidate. |
| 8463 | * @param top The top coordinate of the rectangle to invalidate. |
| 8464 | * @param right The right coordinate of the rectangle to invalidate. |
| 8465 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 8466 | * |
| 8467 | * @see #invalidate(int, int, int, int) |
| 8468 | * @see #invalidate(Rect) |
| 8469 | */ |
| 8470 | public void postInvalidate(int left, int top, int right, int bottom) { |
| 8471 | postInvalidateDelayed(0, left, top, right, bottom); |
| 8472 | } |
| 8473 | |
| 8474 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8475 | * <p>Cause an invalidate to happen on a subsequent cycle through the event |
| 8476 | * loop. Waits for the specified amount of time.</p> |
| 8477 | * |
| 8478 | * <p>This method can be invoked from outside of the UI thread |
| 8479 | * 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] | 8480 | * |
| 8481 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 8482 | * invalidation by |
| 8483 | */ |
| 8484 | public void postInvalidateDelayed(long delayMilliseconds) { |
| 8485 | // We try only with the AttachInfo because there's no point in invalidating |
| 8486 | // if we are not attached to our window |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8487 | AttachInfo attachInfo = mAttachInfo; |
| 8488 | if (attachInfo != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8489 | Message msg = Message.obtain(); |
| 8490 | msg.what = AttachInfo.INVALIDATE_MSG; |
| 8491 | msg.obj = this; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8492 | attachInfo.mHandler.sendMessageDelayed(msg, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8493 | } |
| 8494 | } |
| 8495 | |
| 8496 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8497 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 8498 | * through the event loop. Waits for the specified amount of time.</p> |
| 8499 | * |
| 8500 | * <p>This method can be invoked from outside of the UI thread |
| 8501 | * 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] | 8502 | * |
| 8503 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 8504 | * invalidation by |
| 8505 | * @param left The left coordinate of the rectangle to invalidate. |
| 8506 | * @param top The top coordinate of the rectangle to invalidate. |
| 8507 | * @param right The right coordinate of the rectangle to invalidate. |
| 8508 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 8509 | */ |
| 8510 | public void postInvalidateDelayed(long delayMilliseconds, int left, int top, |
| 8511 | int right, int bottom) { |
| 8512 | |
| 8513 | // We try only with the AttachInfo because there's no point in invalidating |
| 8514 | // if we are not attached to our window |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8515 | AttachInfo attachInfo = mAttachInfo; |
| 8516 | if (attachInfo != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8517 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire(); |
| 8518 | info.target = this; |
| 8519 | info.left = left; |
| 8520 | info.top = top; |
| 8521 | info.right = right; |
| 8522 | info.bottom = bottom; |
| 8523 | |
| 8524 | final Message msg = Message.obtain(); |
| 8525 | msg.what = AttachInfo.INVALIDATE_RECT_MSG; |
| 8526 | msg.obj = info; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8527 | attachInfo.mHandler.sendMessageDelayed(msg, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8528 | } |
| 8529 | } |
| 8530 | |
| 8531 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 8532 | * Post a callback to send a {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} event. |
| 8533 | * This event is sent at most once every |
| 8534 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
| 8535 | */ |
| 8536 | private void postSendViewScrolledAccessibilityEventCallback() { |
| 8537 | if (mSendViewScrolledAccessibilityEvent == null) { |
| 8538 | mSendViewScrolledAccessibilityEvent = new SendViewScrolledAccessibilityEvent(); |
| 8539 | } |
| 8540 | if (!mSendViewScrolledAccessibilityEvent.mIsPending) { |
| 8541 | mSendViewScrolledAccessibilityEvent.mIsPending = true; |
| 8542 | postDelayed(mSendViewScrolledAccessibilityEvent, |
| 8543 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval()); |
| 8544 | } |
| 8545 | } |
| 8546 | |
| 8547 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8548 | * Called by a parent to request that a child update its values for mScrollX |
| 8549 | * and mScrollY if necessary. This will typically be done if the child is |
| 8550 | * animating a scroll using a {@link android.widget.Scroller Scroller} |
| 8551 | * object. |
| 8552 | */ |
| 8553 | public void computeScroll() { |
| 8554 | } |
| 8555 | |
| 8556 | /** |
| 8557 | * <p>Indicate whether the horizontal edges are faded when the view is |
| 8558 | * scrolled horizontally.</p> |
| 8559 | * |
| 8560 | * @return true if the horizontal edges should are faded on scroll, false |
| 8561 | * otherwise |
| 8562 | * |
| 8563 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
| 8564 | * @attr ref android.R.styleable#View_fadingEdge |
| 8565 | */ |
| 8566 | public boolean isHorizontalFadingEdgeEnabled() { |
| 8567 | return (mViewFlags & FADING_EDGE_HORIZONTAL) == FADING_EDGE_HORIZONTAL; |
| 8568 | } |
| 8569 | |
| 8570 | /** |
| 8571 | * <p>Define whether the horizontal edges should be faded when this view |
| 8572 | * is scrolled horizontally.</p> |
| 8573 | * |
| 8574 | * @param horizontalFadingEdgeEnabled true if the horizontal edges should |
| 8575 | * be faded when the view is scrolled |
| 8576 | * horizontally |
| 8577 | * |
| 8578 | * @see #isHorizontalFadingEdgeEnabled() |
| 8579 | * @attr ref android.R.styleable#View_fadingEdge |
| 8580 | */ |
| 8581 | public void setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled) { |
| 8582 | if (isHorizontalFadingEdgeEnabled() != horizontalFadingEdgeEnabled) { |
| 8583 | if (horizontalFadingEdgeEnabled) { |
| 8584 | initScrollCache(); |
| 8585 | } |
| 8586 | |
| 8587 | mViewFlags ^= FADING_EDGE_HORIZONTAL; |
| 8588 | } |
| 8589 | } |
| 8590 | |
| 8591 | /** |
| 8592 | * <p>Indicate whether the vertical edges are faded when the view is |
| 8593 | * scrolled horizontally.</p> |
| 8594 | * |
| 8595 | * @return true if the vertical edges should are faded on scroll, false |
| 8596 | * otherwise |
| 8597 | * |
| 8598 | * @see #setVerticalFadingEdgeEnabled(boolean) |
| 8599 | * @attr ref android.R.styleable#View_fadingEdge |
| 8600 | */ |
| 8601 | public boolean isVerticalFadingEdgeEnabled() { |
| 8602 | return (mViewFlags & FADING_EDGE_VERTICAL) == FADING_EDGE_VERTICAL; |
| 8603 | } |
| 8604 | |
| 8605 | /** |
| 8606 | * <p>Define whether the vertical edges should be faded when this view |
| 8607 | * is scrolled vertically.</p> |
| 8608 | * |
| 8609 | * @param verticalFadingEdgeEnabled true if the vertical edges should |
| 8610 | * be faded when the view is scrolled |
| 8611 | * vertically |
| 8612 | * |
| 8613 | * @see #isVerticalFadingEdgeEnabled() |
| 8614 | * @attr ref android.R.styleable#View_fadingEdge |
| 8615 | */ |
| 8616 | public void setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled) { |
| 8617 | if (isVerticalFadingEdgeEnabled() != verticalFadingEdgeEnabled) { |
| 8618 | if (verticalFadingEdgeEnabled) { |
| 8619 | initScrollCache(); |
| 8620 | } |
| 8621 | |
| 8622 | mViewFlags ^= FADING_EDGE_VERTICAL; |
| 8623 | } |
| 8624 | } |
| 8625 | |
| 8626 | /** |
| 8627 | * Returns the strength, or intensity, of the top faded edge. The strength is |
| 8628 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 8629 | * returns 0.0 or 1.0 but no value in between. |
| 8630 | * |
| 8631 | * Subclasses should override this method to provide a smoother fade transition |
| 8632 | * when scrolling occurs. |
| 8633 | * |
| 8634 | * @return the intensity of the top fade as a float between 0.0f and 1.0f |
| 8635 | */ |
| 8636 | protected float getTopFadingEdgeStrength() { |
| 8637 | return computeVerticalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 8638 | } |
| 8639 | |
| 8640 | /** |
| 8641 | * Returns the strength, or intensity, of the bottom faded edge. The strength is |
| 8642 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 8643 | * returns 0.0 or 1.0 but no value in between. |
| 8644 | * |
| 8645 | * Subclasses should override this method to provide a smoother fade transition |
| 8646 | * when scrolling occurs. |
| 8647 | * |
| 8648 | * @return the intensity of the bottom fade as a float between 0.0f and 1.0f |
| 8649 | */ |
| 8650 | protected float getBottomFadingEdgeStrength() { |
| 8651 | return computeVerticalScrollOffset() + computeVerticalScrollExtent() < |
| 8652 | computeVerticalScrollRange() ? 1.0f : 0.0f; |
| 8653 | } |
| 8654 | |
| 8655 | /** |
| 8656 | * Returns the strength, or intensity, of the left faded edge. The strength is |
| 8657 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 8658 | * returns 0.0 or 1.0 but no value in between. |
| 8659 | * |
| 8660 | * Subclasses should override this method to provide a smoother fade transition |
| 8661 | * when scrolling occurs. |
| 8662 | * |
| 8663 | * @return the intensity of the left fade as a float between 0.0f and 1.0f |
| 8664 | */ |
| 8665 | protected float getLeftFadingEdgeStrength() { |
| 8666 | return computeHorizontalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 8667 | } |
| 8668 | |
| 8669 | /** |
| 8670 | * Returns the strength, or intensity, of the right faded edge. The strength is |
| 8671 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 8672 | * returns 0.0 or 1.0 but no value in between. |
| 8673 | * |
| 8674 | * Subclasses should override this method to provide a smoother fade transition |
| 8675 | * when scrolling occurs. |
| 8676 | * |
| 8677 | * @return the intensity of the right fade as a float between 0.0f and 1.0f |
| 8678 | */ |
| 8679 | protected float getRightFadingEdgeStrength() { |
| 8680 | return computeHorizontalScrollOffset() + computeHorizontalScrollExtent() < |
| 8681 | computeHorizontalScrollRange() ? 1.0f : 0.0f; |
| 8682 | } |
| 8683 | |
| 8684 | /** |
| 8685 | * <p>Indicate whether the horizontal scrollbar should be drawn or not. The |
| 8686 | * scrollbar is not drawn by default.</p> |
| 8687 | * |
| 8688 | * @return true if the horizontal scrollbar should be painted, false |
| 8689 | * otherwise |
| 8690 | * |
| 8691 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 8692 | */ |
| 8693 | public boolean isHorizontalScrollBarEnabled() { |
| 8694 | return (mViewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 8695 | } |
| 8696 | |
| 8697 | /** |
| 8698 | * <p>Define whether the horizontal scrollbar should be drawn or not. The |
| 8699 | * scrollbar is not drawn by default.</p> |
| 8700 | * |
| 8701 | * @param horizontalScrollBarEnabled true if the horizontal scrollbar should |
| 8702 | * be painted |
| 8703 | * |
| 8704 | * @see #isHorizontalScrollBarEnabled() |
| 8705 | */ |
| 8706 | public void setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled) { |
| 8707 | if (isHorizontalScrollBarEnabled() != horizontalScrollBarEnabled) { |
| 8708 | mViewFlags ^= SCROLLBARS_HORIZONTAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 8709 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 8710 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8711 | } |
| 8712 | } |
| 8713 | |
| 8714 | /** |
| 8715 | * <p>Indicate whether the vertical scrollbar should be drawn or not. The |
| 8716 | * scrollbar is not drawn by default.</p> |
| 8717 | * |
| 8718 | * @return true if the vertical scrollbar should be painted, false |
| 8719 | * otherwise |
| 8720 | * |
| 8721 | * @see #setVerticalScrollBarEnabled(boolean) |
| 8722 | */ |
| 8723 | public boolean isVerticalScrollBarEnabled() { |
| 8724 | return (mViewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL; |
| 8725 | } |
| 8726 | |
| 8727 | /** |
| 8728 | * <p>Define whether the vertical scrollbar should be drawn or not. The |
| 8729 | * scrollbar is not drawn by default.</p> |
| 8730 | * |
| 8731 | * @param verticalScrollBarEnabled true if the vertical scrollbar should |
| 8732 | * be painted |
| 8733 | * |
| 8734 | * @see #isVerticalScrollBarEnabled() |
| 8735 | */ |
| 8736 | public void setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled) { |
| 8737 | if (isVerticalScrollBarEnabled() != verticalScrollBarEnabled) { |
| 8738 | mViewFlags ^= SCROLLBARS_VERTICAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 8739 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 8740 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8741 | } |
| 8742 | } |
| 8743 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 8744 | /** |
| 8745 | * @hide |
| 8746 | */ |
| 8747 | protected void recomputePadding() { |
| 8748 | setPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, mUserPaddingBottom); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8749 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8750 | |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 8751 | /** |
| 8752 | * Define whether scrollbars will fade when the view is not scrolling. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8753 | * |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 8754 | * @param fadeScrollbars wheter to enable fading |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8755 | * |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 8756 | */ |
| 8757 | public void setScrollbarFadingEnabled(boolean fadeScrollbars) { |
| 8758 | initScrollCache(); |
| 8759 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
| 8760 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 8761 | if (fadeScrollbars) { |
| 8762 | scrollabilityCache.state = ScrollabilityCache.OFF; |
| 8763 | } else { |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 8764 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 8765 | } |
| 8766 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8767 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8768 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8769 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 8770 | * Returns true if scrollbars will fade when this view is not scrolling |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8771 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 8772 | * @return true if scrollbar fading is enabled |
| 8773 | */ |
| 8774 | public boolean isScrollbarFadingEnabled() { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8775 | return mScrollCache != null && mScrollCache.fadeScrollBars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 8776 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8777 | |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 8778 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8779 | * <p>Specify the style of the scrollbars. The scrollbars can be overlaid or |
| 8780 | * inset. When inset, they add to the padding of the view. And the scrollbars |
| 8781 | * can be drawn inside the padding area or on the edge of the view. For example, |
| 8782 | * if a view has a background drawable and you want to draw the scrollbars |
| 8783 | * inside the padding specified by the drawable, you can use |
| 8784 | * SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to |
| 8785 | * appear at the edge of the view, ignoring the padding, then you can use |
| 8786 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.</p> |
| 8787 | * @param style the style of the scrollbars. Should be one of |
| 8788 | * SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, |
| 8789 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET. |
| 8790 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 8791 | * @see #SCROLLBARS_INSIDE_INSET |
| 8792 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 8793 | * @see #SCROLLBARS_OUTSIDE_INSET |
| 8794 | */ |
| 8795 | public void setScrollBarStyle(int style) { |
| 8796 | if (style != (mViewFlags & SCROLLBARS_STYLE_MASK)) { |
| 8797 | mViewFlags = (mViewFlags & ~SCROLLBARS_STYLE_MASK) | (style & SCROLLBARS_STYLE_MASK); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 8798 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 8799 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8800 | } |
| 8801 | } |
| 8802 | |
| 8803 | /** |
| 8804 | * <p>Returns the current scrollbar style.</p> |
| 8805 | * @return the current scrollbar style |
| 8806 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 8807 | * @see #SCROLLBARS_INSIDE_INSET |
| 8808 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 8809 | * @see #SCROLLBARS_OUTSIDE_INSET |
| 8810 | */ |
Jeff Sharkey | 010d7e5 | 2011-08-08 21:05:02 -0700 | [diff] [blame] | 8811 | @ViewDebug.ExportedProperty(mapping = { |
| 8812 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_OVERLAY, to = "INSIDE_OVERLAY"), |
| 8813 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_INSET, to = "INSIDE_INSET"), |
| 8814 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_OVERLAY, to = "OUTSIDE_OVERLAY"), |
| 8815 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_INSET, to = "OUTSIDE_INSET") |
| 8816 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8817 | public int getScrollBarStyle() { |
| 8818 | return mViewFlags & SCROLLBARS_STYLE_MASK; |
| 8819 | } |
| 8820 | |
| 8821 | /** |
| 8822 | * <p>Compute the horizontal range that the horizontal scrollbar |
| 8823 | * represents.</p> |
| 8824 | * |
| 8825 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 8826 | * units used by {@link #computeHorizontalScrollExtent()} and |
| 8827 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 8828 | * |
| 8829 | * <p>The default range is the drawing width of this view.</p> |
| 8830 | * |
| 8831 | * @return the total horizontal range represented by the horizontal |
| 8832 | * scrollbar |
| 8833 | * |
| 8834 | * @see #computeHorizontalScrollExtent() |
| 8835 | * @see #computeHorizontalScrollOffset() |
| 8836 | * @see android.widget.ScrollBarDrawable |
| 8837 | */ |
| 8838 | protected int computeHorizontalScrollRange() { |
| 8839 | return getWidth(); |
| 8840 | } |
| 8841 | |
| 8842 | /** |
| 8843 | * <p>Compute the horizontal offset of the horizontal scrollbar's thumb |
| 8844 | * within the horizontal range. This value is used to compute the position |
| 8845 | * of the thumb within the scrollbar's track.</p> |
| 8846 | * |
| 8847 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 8848 | * units used by {@link #computeHorizontalScrollRange()} and |
| 8849 | * {@link #computeHorizontalScrollExtent()}.</p> |
| 8850 | * |
| 8851 | * <p>The default offset is the scroll offset of this view.</p> |
| 8852 | * |
| 8853 | * @return the horizontal offset of the scrollbar's thumb |
| 8854 | * |
| 8855 | * @see #computeHorizontalScrollRange() |
| 8856 | * @see #computeHorizontalScrollExtent() |
| 8857 | * @see android.widget.ScrollBarDrawable |
| 8858 | */ |
| 8859 | protected int computeHorizontalScrollOffset() { |
| 8860 | return mScrollX; |
| 8861 | } |
| 8862 | |
| 8863 | /** |
| 8864 | * <p>Compute the horizontal extent of the horizontal scrollbar's thumb |
| 8865 | * within the horizontal range. This value is used to compute the length |
| 8866 | * of the thumb within the scrollbar's track.</p> |
| 8867 | * |
| 8868 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 8869 | * units used by {@link #computeHorizontalScrollRange()} and |
| 8870 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 8871 | * |
| 8872 | * <p>The default extent is the drawing width of this view.</p> |
| 8873 | * |
| 8874 | * @return the horizontal extent of the scrollbar's thumb |
| 8875 | * |
| 8876 | * @see #computeHorizontalScrollRange() |
| 8877 | * @see #computeHorizontalScrollOffset() |
| 8878 | * @see android.widget.ScrollBarDrawable |
| 8879 | */ |
| 8880 | protected int computeHorizontalScrollExtent() { |
| 8881 | return getWidth(); |
| 8882 | } |
| 8883 | |
| 8884 | /** |
| 8885 | * <p>Compute the vertical range that the vertical scrollbar represents.</p> |
| 8886 | * |
| 8887 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 8888 | * units used by {@link #computeVerticalScrollExtent()} and |
| 8889 | * {@link #computeVerticalScrollOffset()}.</p> |
| 8890 | * |
| 8891 | * @return the total vertical range represented by the vertical scrollbar |
| 8892 | * |
| 8893 | * <p>The default range is the drawing height of this view.</p> |
| 8894 | * |
| 8895 | * @see #computeVerticalScrollExtent() |
| 8896 | * @see #computeVerticalScrollOffset() |
| 8897 | * @see android.widget.ScrollBarDrawable |
| 8898 | */ |
| 8899 | protected int computeVerticalScrollRange() { |
| 8900 | return getHeight(); |
| 8901 | } |
| 8902 | |
| 8903 | /** |
| 8904 | * <p>Compute the vertical offset of the vertical scrollbar's thumb |
| 8905 | * within the horizontal range. This value is used to compute the position |
| 8906 | * of the thumb within the scrollbar's track.</p> |
| 8907 | * |
| 8908 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 8909 | * units used by {@link #computeVerticalScrollRange()} and |
| 8910 | * {@link #computeVerticalScrollExtent()}.</p> |
| 8911 | * |
| 8912 | * <p>The default offset is the scroll offset of this view.</p> |
| 8913 | * |
| 8914 | * @return the vertical offset of the scrollbar's thumb |
| 8915 | * |
| 8916 | * @see #computeVerticalScrollRange() |
| 8917 | * @see #computeVerticalScrollExtent() |
| 8918 | * @see android.widget.ScrollBarDrawable |
| 8919 | */ |
| 8920 | protected int computeVerticalScrollOffset() { |
| 8921 | return mScrollY; |
| 8922 | } |
| 8923 | |
| 8924 | /** |
| 8925 | * <p>Compute the vertical extent of the horizontal scrollbar's thumb |
| 8926 | * within the vertical range. This value is used to compute the length |
| 8927 | * of the thumb within the scrollbar's track.</p> |
| 8928 | * |
| 8929 | * <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] | 8930 | * units used by {@link #computeVerticalScrollRange()} and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8931 | * {@link #computeVerticalScrollOffset()}.</p> |
| 8932 | * |
| 8933 | * <p>The default extent is the drawing height of this view.</p> |
| 8934 | * |
| 8935 | * @return the vertical extent of the scrollbar's thumb |
| 8936 | * |
| 8937 | * @see #computeVerticalScrollRange() |
| 8938 | * @see #computeVerticalScrollOffset() |
| 8939 | * @see android.widget.ScrollBarDrawable |
| 8940 | */ |
| 8941 | protected int computeVerticalScrollExtent() { |
| 8942 | return getHeight(); |
| 8943 | } |
| 8944 | |
| 8945 | /** |
Adam Powell | 6915944 | 2011-06-13 17:53:06 -0700 | [diff] [blame] | 8946 | * Check if this view can be scrolled horizontally in a certain direction. |
| 8947 | * |
| 8948 | * @param direction Negative to check scrolling left, positive to check scrolling right. |
| 8949 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 8950 | */ |
| 8951 | public boolean canScrollHorizontally(int direction) { |
| 8952 | final int offset = computeHorizontalScrollOffset(); |
| 8953 | final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent(); |
| 8954 | if (range == 0) return false; |
| 8955 | if (direction < 0) { |
| 8956 | return offset > 0; |
| 8957 | } else { |
| 8958 | return offset < range - 1; |
| 8959 | } |
| 8960 | } |
| 8961 | |
| 8962 | /** |
| 8963 | * Check if this view can be scrolled vertically in a certain direction. |
| 8964 | * |
| 8965 | * @param direction Negative to check scrolling up, positive to check scrolling down. |
| 8966 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 8967 | */ |
| 8968 | public boolean canScrollVertically(int direction) { |
| 8969 | final int offset = computeVerticalScrollOffset(); |
| 8970 | final int range = computeVerticalScrollRange() - computeVerticalScrollExtent(); |
| 8971 | if (range == 0) return false; |
| 8972 | if (direction < 0) { |
| 8973 | return offset > 0; |
| 8974 | } else { |
| 8975 | return offset < range - 1; |
| 8976 | } |
| 8977 | } |
| 8978 | |
| 8979 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8980 | * <p>Request the drawing of the horizontal and the vertical scrollbar. The |
| 8981 | * scrollbars are painted only if they have been awakened first.</p> |
| 8982 | * |
| 8983 | * @param canvas the canvas on which to draw the scrollbars |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8984 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8985 | * @see #awakenScrollBars(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8986 | */ |
Romain Guy | 1d5b3a6 | 2009-11-05 18:44:12 -0800 | [diff] [blame] | 8987 | protected final void onDrawScrollBars(Canvas canvas) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8988 | // scrollbars are drawn only when the animation is running |
| 8989 | final ScrollabilityCache cache = mScrollCache; |
| 8990 | if (cache != null) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8991 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8992 | int state = cache.state; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8993 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8994 | if (state == ScrollabilityCache.OFF) { |
| 8995 | return; |
| 8996 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8997 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8998 | boolean invalidate = false; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8999 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9000 | if (state == ScrollabilityCache.FADING) { |
| 9001 | // We're fading -- get our fade interpolation |
| 9002 | if (cache.interpolatorValues == null) { |
| 9003 | cache.interpolatorValues = new float[1]; |
| 9004 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9005 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9006 | float[] values = cache.interpolatorValues; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9007 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9008 | // Stops the animation if we're done |
| 9009 | if (cache.scrollBarInterpolator.timeToValues(values) == |
| 9010 | Interpolator.Result.FREEZE_END) { |
| 9011 | cache.state = ScrollabilityCache.OFF; |
| 9012 | } else { |
| 9013 | cache.scrollBar.setAlpha(Math.round(values[0])); |
| 9014 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9015 | |
| 9016 | // This will make the scroll bars inval themselves after |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9017 | // drawing. We only want this when we're fading so that |
| 9018 | // we prevent excessive redraws |
| 9019 | invalidate = true; |
| 9020 | } else { |
| 9021 | // We're just on -- but we may have been fading before so |
| 9022 | // reset alpha |
| 9023 | cache.scrollBar.setAlpha(255); |
| 9024 | } |
| 9025 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9026 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9027 | final int viewFlags = mViewFlags; |
| 9028 | |
| 9029 | final boolean drawHorizontalScrollBar = |
| 9030 | (viewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 9031 | final boolean drawVerticalScrollBar = |
| 9032 | (viewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL |
| 9033 | && !isVerticalScrollBarHidden(); |
| 9034 | |
| 9035 | if (drawVerticalScrollBar || drawHorizontalScrollBar) { |
| 9036 | final int width = mRight - mLeft; |
| 9037 | final int height = mBottom - mTop; |
| 9038 | |
| 9039 | final ScrollBarDrawable scrollBar = cache.scrollBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9040 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9041 | final int scrollX = mScrollX; |
| 9042 | final int scrollY = mScrollY; |
| 9043 | final int inside = (viewFlags & SCROLLBARS_OUTSIDE_MASK) == 0 ? ~0 : 0; |
| 9044 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9045 | int left, top, right, bottom; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9046 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9047 | if (drawHorizontalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 9048 | int size = scrollBar.getSize(false); |
| 9049 | if (size <= 0) { |
| 9050 | size = cache.scrollBarSize; |
| 9051 | } |
| 9052 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9053 | scrollBar.setParameters(computeHorizontalScrollRange(), |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9054 | computeHorizontalScrollOffset(), |
| 9055 | computeHorizontalScrollExtent(), false); |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9056 | final int verticalScrollBarGap = drawVerticalScrollBar ? |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9057 | getVerticalScrollbarWidth() : 0; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9058 | top = scrollY + height - size - (mUserPaddingBottom & inside); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9059 | left = scrollX + (mPaddingLeft & inside); |
| 9060 | right = scrollX + width - (mUserPaddingRight & inside) - verticalScrollBarGap; |
| 9061 | bottom = top + size; |
| 9062 | onDrawHorizontalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 9063 | if (invalidate) { |
| 9064 | invalidate(left, top, right, bottom); |
| 9065 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9066 | } |
| 9067 | |
| 9068 | if (drawVerticalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 9069 | int size = scrollBar.getSize(true); |
| 9070 | if (size <= 0) { |
| 9071 | size = cache.scrollBarSize; |
| 9072 | } |
| 9073 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9074 | scrollBar.setParameters(computeVerticalScrollRange(), |
| 9075 | computeVerticalScrollOffset(), |
| 9076 | computeVerticalScrollExtent(), true); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 9077 | switch (mVerticalScrollbarPosition) { |
| 9078 | default: |
| 9079 | case SCROLLBAR_POSITION_DEFAULT: |
| 9080 | case SCROLLBAR_POSITION_RIGHT: |
| 9081 | left = scrollX + width - size - (mUserPaddingRight & inside); |
| 9082 | break; |
| 9083 | case SCROLLBAR_POSITION_LEFT: |
| 9084 | left = scrollX + (mUserPaddingLeft & inside); |
| 9085 | break; |
| 9086 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9087 | top = scrollY + (mPaddingTop & inside); |
| 9088 | right = left + size; |
| 9089 | bottom = scrollY + height - (mUserPaddingBottom & inside); |
| 9090 | onDrawVerticalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 9091 | if (invalidate) { |
| 9092 | invalidate(left, top, right, bottom); |
| 9093 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9094 | } |
| 9095 | } |
| 9096 | } |
| 9097 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 9098 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9099 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 9100 | * 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] | 9101 | * FastScroller is visible. |
| 9102 | * @return whether to temporarily hide the vertical scrollbar |
| 9103 | * @hide |
| 9104 | */ |
| 9105 | protected boolean isVerticalScrollBarHidden() { |
| 9106 | return false; |
| 9107 | } |
| 9108 | |
| 9109 | /** |
| 9110 | * <p>Draw the horizontal scrollbar if |
| 9111 | * {@link #isHorizontalScrollBarEnabled()} returns true.</p> |
| 9112 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9113 | * @param canvas the canvas on which to draw the scrollbar |
| 9114 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9115 | * |
| 9116 | * @see #isHorizontalScrollBarEnabled() |
| 9117 | * @see #computeHorizontalScrollRange() |
| 9118 | * @see #computeHorizontalScrollExtent() |
| 9119 | * @see #computeHorizontalScrollOffset() |
| 9120 | * @see android.widget.ScrollBarDrawable |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9121 | * @hide |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 9122 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 9123 | protected void onDrawHorizontalScrollBar(Canvas canvas, Drawable scrollBar, |
| 9124 | int l, int t, int r, int b) { |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 9125 | scrollBar.setBounds(l, t, r, b); |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 9126 | scrollBar.draw(canvas); |
| 9127 | } |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9128 | |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 9129 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9130 | * <p>Draw the vertical scrollbar if {@link #isVerticalScrollBarEnabled()} |
| 9131 | * returns true.</p> |
| 9132 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9133 | * @param canvas the canvas on which to draw the scrollbar |
| 9134 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9135 | * |
| 9136 | * @see #isVerticalScrollBarEnabled() |
| 9137 | * @see #computeVerticalScrollRange() |
| 9138 | * @see #computeVerticalScrollExtent() |
| 9139 | * @see #computeVerticalScrollOffset() |
| 9140 | * @see android.widget.ScrollBarDrawable |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9141 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9142 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 9143 | protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, |
| 9144 | int l, int t, int r, int b) { |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9145 | scrollBar.setBounds(l, t, r, b); |
| 9146 | scrollBar.draw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9147 | } |
| 9148 | |
| 9149 | /** |
| 9150 | * Implement this to do your drawing. |
| 9151 | * |
| 9152 | * @param canvas the canvas on which the background will be drawn |
| 9153 | */ |
| 9154 | protected void onDraw(Canvas canvas) { |
| 9155 | } |
| 9156 | |
| 9157 | /* |
| 9158 | * Caller is responsible for calling requestLayout if necessary. |
| 9159 | * (This allows addViewInLayout to not request a new layout.) |
| 9160 | */ |
| 9161 | void assignParent(ViewParent parent) { |
| 9162 | if (mParent == null) { |
| 9163 | mParent = parent; |
| 9164 | } else if (parent == null) { |
| 9165 | mParent = null; |
| 9166 | } else { |
| 9167 | throw new RuntimeException("view " + this + " being added, but" |
| 9168 | + " it already has a parent"); |
| 9169 | } |
| 9170 | } |
| 9171 | |
| 9172 | /** |
| 9173 | * This is called when the view is attached to a window. At this point it |
| 9174 | * has a Surface and will start drawing. Note that this function is |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9175 | * guaranteed to be called before {@link #onDraw(android.graphics.Canvas)}, |
| 9176 | * however it may be called any time before the first onDraw -- including |
| 9177 | * before or after {@link #onMeasure(int, int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9178 | * |
| 9179 | * @see #onDetachedFromWindow() |
| 9180 | */ |
| 9181 | protected void onAttachedToWindow() { |
| 9182 | if ((mPrivateFlags & REQUEST_TRANSPARENT_REGIONS) != 0) { |
| 9183 | mParent.requestTransparentRegion(this); |
| 9184 | } |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 9185 | if ((mPrivateFlags & AWAKEN_SCROLL_BARS_ON_ATTACH) != 0) { |
| 9186 | initialAwakenScrollBars(); |
| 9187 | mPrivateFlags &= ~AWAKEN_SCROLL_BARS_ON_ATTACH; |
| 9188 | } |
Chet Haase | a9b61ac | 2010-12-20 07:40:25 -0800 | [diff] [blame] | 9189 | jumpDrawablesToCurrentState(); |
Fabrice Di Meglio | a646145 | 2011-08-19 15:42:04 -0700 | [diff] [blame] | 9190 | // Order is important here: LayoutDirection MUST be resolved before Padding |
| 9191 | // and TextDirection |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9192 | resolveLayoutDirectionIfNeeded(); |
| 9193 | resolvePadding(); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 9194 | resolveTextDirection(); |
Amith Yamasani | 4503c8d | 2011-06-17 12:36:14 -0700 | [diff] [blame] | 9195 | if (isFocused()) { |
| 9196 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 9197 | imm.focusIn(this); |
| 9198 | } |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 9199 | } |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 9200 | |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 9201 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9202 | * Resolve and cache the layout direction. LTR is set initially. This is implicitly supposing |
| 9203 | * that the parent directionality can and will be resolved before its children. |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 9204 | */ |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9205 | private void resolveLayoutDirectionIfNeeded() { |
| 9206 | // Do not resolve if it is not needed |
| 9207 | if ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED) == LAYOUT_DIRECTION_RESOLVED) return; |
| 9208 | |
| 9209 | // Clear any previous layout direction resolution |
| 9210 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_RTL; |
| 9211 | |
Fabrice Di Meglio | 4b60c30 | 2011-08-17 16:56:55 -0700 | [diff] [blame] | 9212 | // Reset also TextDirection as a change into LayoutDirection may impact the selected |
| 9213 | // TextDirectionHeuristic |
| 9214 | resetResolvedTextDirection(); |
| 9215 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9216 | // Set resolved depending on layout direction |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 9217 | switch (getLayoutDirection()) { |
| 9218 | case LAYOUT_DIRECTION_INHERIT: |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 9219 | // We cannot do the resolution if there is no parent |
| 9220 | if (mParent == null) return; |
| 9221 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 9222 | // If this is root view, no need to look at parent's layout dir. |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 9223 | if (mParent instanceof ViewGroup) { |
| 9224 | ViewGroup viewGroup = ((ViewGroup) mParent); |
| 9225 | |
| 9226 | // Check if the parent view group can resolve |
| 9227 | if (! viewGroup.canResolveLayoutDirection()) { |
| 9228 | return; |
| 9229 | } |
| 9230 | if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
| 9231 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
| 9232 | } |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 9233 | } |
| 9234 | break; |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 9235 | case LAYOUT_DIRECTION_RTL: |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9236 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 9237 | break; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 9238 | case LAYOUT_DIRECTION_LOCALE: |
| 9239 | if(isLayoutDirectionRtl(Locale.getDefault())) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9240 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 9241 | } |
| 9242 | break; |
| 9243 | default: |
| 9244 | // Nothing to do, LTR by default |
| 9245 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9246 | |
| 9247 | // Set to resolved |
| 9248 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED; |
| 9249 | } |
| 9250 | |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 9251 | /** |
| 9252 | * @hide |
| 9253 | */ |
| 9254 | protected void resolvePadding() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9255 | // If the user specified the absolute padding (either with android:padding or |
| 9256 | // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise |
| 9257 | // use the default padding or the padding from the background drawable |
| 9258 | // (stored at this point in mPadding*) |
| 9259 | switch (getResolvedLayoutDirection()) { |
| 9260 | case LAYOUT_DIRECTION_RTL: |
| 9261 | // Start user padding override Right user padding. Otherwise, if Right user |
| 9262 | // padding is not defined, use the default Right padding. If Right user padding |
| 9263 | // is defined, just use it. |
| 9264 | if (mUserPaddingStart >= 0) { |
| 9265 | mUserPaddingRight = mUserPaddingStart; |
| 9266 | } else if (mUserPaddingRight < 0) { |
| 9267 | mUserPaddingRight = mPaddingRight; |
| 9268 | } |
| 9269 | if (mUserPaddingEnd >= 0) { |
| 9270 | mUserPaddingLeft = mUserPaddingEnd; |
| 9271 | } else if (mUserPaddingLeft < 0) { |
| 9272 | mUserPaddingLeft = mPaddingLeft; |
| 9273 | } |
| 9274 | break; |
| 9275 | case LAYOUT_DIRECTION_LTR: |
| 9276 | default: |
| 9277 | // Start user padding override Left user padding. Otherwise, if Left user |
| 9278 | // padding is not defined, use the default left padding. If Left user padding |
| 9279 | // is defined, just use it. |
Fabrice Di Meglio | f3e1a93 | 2011-07-15 17:15:39 -0700 | [diff] [blame] | 9280 | if (mUserPaddingStart >= 0) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9281 | mUserPaddingLeft = mUserPaddingStart; |
| 9282 | } else if (mUserPaddingLeft < 0) { |
| 9283 | mUserPaddingLeft = mPaddingLeft; |
| 9284 | } |
Fabrice Di Meglio | f3e1a93 | 2011-07-15 17:15:39 -0700 | [diff] [blame] | 9285 | if (mUserPaddingEnd >= 0) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9286 | mUserPaddingRight = mUserPaddingEnd; |
| 9287 | } else if (mUserPaddingRight < 0) { |
| 9288 | mUserPaddingRight = mPaddingRight; |
| 9289 | } |
| 9290 | } |
| 9291 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9292 | mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom; |
| 9293 | |
| 9294 | recomputePadding(); |
| 9295 | } |
| 9296 | |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 9297 | protected boolean canResolveLayoutDirection() { |
| 9298 | switch (getLayoutDirection()) { |
| 9299 | case LAYOUT_DIRECTION_INHERIT: |
| 9300 | return (mParent != null); |
| 9301 | default: |
| 9302 | return true; |
| 9303 | } |
| 9304 | } |
| 9305 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9306 | /** |
Doug Felt | c0ccf0c | 2011-06-23 16:13:18 -0700 | [diff] [blame] | 9307 | * Reset the resolved layout direction. |
| 9308 | * |
| 9309 | * Subclasses need to override this method to clear cached information that depends on the |
| 9310 | * resolved layout direction, or to inform child views that inherit their layout direction. |
| 9311 | * Overrides must also call the superclass implementation at the start of their implementation. |
| 9312 | * |
| 9313 | * @hide |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9314 | */ |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 9315 | protected void resetResolvedLayoutDirection() { |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 9316 | // Reset the current View resolution |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9317 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 9318 | } |
| 9319 | |
| 9320 | /** |
| 9321 | * Check if a Locale is corresponding to a RTL script. |
| 9322 | * |
| 9323 | * @param locale Locale to check |
| 9324 | * @return true if a Locale is corresponding to a RTL script. |
| 9325 | */ |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 9326 | protected static boolean isLayoutDirectionRtl(Locale locale) { |
Fabrice Di Meglio | a47f45e | 2011-06-15 14:22:12 -0700 | [diff] [blame] | 9327 | return (LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE == |
| 9328 | LocaleUtil.getLayoutDirectionFromLocale(locale)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9329 | } |
| 9330 | |
| 9331 | /** |
| 9332 | * This is called when the view is detached from a window. At this point it |
| 9333 | * no longer has a surface for drawing. |
| 9334 | * |
| 9335 | * @see #onAttachedToWindow() |
| 9336 | */ |
| 9337 | protected void onDetachedFromWindow() { |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 9338 | mPrivateFlags &= ~CANCEL_NEXT_UP_EVENT; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9339 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 9340 | removeUnsetPressCallback(); |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 9341 | removeLongPressCallback(); |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 9342 | removePerformClickCallback(); |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 9343 | removeSendViewScrolledAccessibilityEventCallback(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9344 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9345 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9346 | |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 9347 | destroyLayer(); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 9348 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9349 | if (mDisplayList != null) { |
| 9350 | mDisplayList.invalidate(); |
| 9351 | } |
| 9352 | |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 9353 | if (mAttachInfo != null) { |
| 9354 | mAttachInfo.mHandler.removeMessages(AttachInfo.INVALIDATE_MSG, this); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 9355 | } |
| 9356 | |
Patrick Dubroy | ec84c3a | 2011-01-13 17:55:37 -0800 | [diff] [blame] | 9357 | mCurrentAnimation = null; |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 9358 | |
| 9359 | resetResolvedLayoutDirection(); |
| 9360 | resetResolvedTextDirection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9361 | } |
| 9362 | |
| 9363 | /** |
| 9364 | * @return The number of times this view has been attached to a window |
| 9365 | */ |
| 9366 | protected int getWindowAttachCount() { |
| 9367 | return mWindowAttachCount; |
| 9368 | } |
| 9369 | |
| 9370 | /** |
| 9371 | * Retrieve a unique token identifying the window this view is attached to. |
| 9372 | * @return Return the window's token for use in |
| 9373 | * {@link WindowManager.LayoutParams#token WindowManager.LayoutParams.token}. |
| 9374 | */ |
| 9375 | public IBinder getWindowToken() { |
| 9376 | return mAttachInfo != null ? mAttachInfo.mWindowToken : null; |
| 9377 | } |
| 9378 | |
| 9379 | /** |
| 9380 | * Retrieve a unique token identifying the top-level "real" window of |
| 9381 | * the window that this view is attached to. That is, this is like |
| 9382 | * {@link #getWindowToken}, except if the window this view in is a panel |
| 9383 | * window (attached to another containing window), then the token of |
| 9384 | * the containing window is returned instead. |
| 9385 | * |
| 9386 | * @return Returns the associated window token, either |
| 9387 | * {@link #getWindowToken()} or the containing window's token. |
| 9388 | */ |
| 9389 | public IBinder getApplicationWindowToken() { |
| 9390 | AttachInfo ai = mAttachInfo; |
| 9391 | if (ai != null) { |
| 9392 | IBinder appWindowToken = ai.mPanelParentWindowToken; |
| 9393 | if (appWindowToken == null) { |
| 9394 | appWindowToken = ai.mWindowToken; |
| 9395 | } |
| 9396 | return appWindowToken; |
| 9397 | } |
| 9398 | return null; |
| 9399 | } |
| 9400 | |
| 9401 | /** |
| 9402 | * Retrieve private session object this view hierarchy is using to |
| 9403 | * communicate with the window manager. |
| 9404 | * @return the session object to communicate with the window manager |
| 9405 | */ |
| 9406 | /*package*/ IWindowSession getWindowSession() { |
| 9407 | return mAttachInfo != null ? mAttachInfo.mSession : null; |
| 9408 | } |
| 9409 | |
| 9410 | /** |
| 9411 | * @param info the {@link android.view.View.AttachInfo} to associated with |
| 9412 | * this view |
| 9413 | */ |
| 9414 | void dispatchAttachedToWindow(AttachInfo info, int visibility) { |
| 9415 | //System.out.println("Attached! " + this); |
| 9416 | mAttachInfo = info; |
| 9417 | mWindowAttachCount++; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 9418 | // We will need to evaluate the drawable state at least once. |
| 9419 | mPrivateFlags |= DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9420 | if (mFloatingTreeObserver != null) { |
| 9421 | info.mTreeObserver.merge(mFloatingTreeObserver); |
| 9422 | mFloatingTreeObserver = null; |
| 9423 | } |
| 9424 | if ((mPrivateFlags&SCROLL_CONTAINER) != 0) { |
| 9425 | mAttachInfo.mScrollContainers.add(this); |
| 9426 | mPrivateFlags |= SCROLL_CONTAINER_ADDED; |
| 9427 | } |
| 9428 | performCollectViewAttributes(visibility); |
| 9429 | onAttachedToWindow(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 9430 | |
| 9431 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
| 9432 | mOnAttachStateChangeListeners; |
| 9433 | if (listeners != null && listeners.size() > 0) { |
| 9434 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 9435 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 9436 | // could mutate the list by calling the various add/remove methods. This prevents |
| 9437 | // the array from being modified while we iterate it. |
| 9438 | for (OnAttachStateChangeListener listener : listeners) { |
| 9439 | listener.onViewAttachedToWindow(this); |
| 9440 | } |
| 9441 | } |
| 9442 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9443 | int vis = info.mWindowVisibility; |
| 9444 | if (vis != GONE) { |
| 9445 | onWindowVisibilityChanged(vis); |
| 9446 | } |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 9447 | if ((mPrivateFlags&DRAWABLE_STATE_DIRTY) != 0) { |
| 9448 | // If nobody has evaluated the drawable state yet, then do it now. |
| 9449 | refreshDrawableState(); |
| 9450 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9451 | } |
| 9452 | |
| 9453 | void dispatchDetachedFromWindow() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9454 | AttachInfo info = mAttachInfo; |
| 9455 | if (info != null) { |
| 9456 | int vis = info.mWindowVisibility; |
| 9457 | if (vis != GONE) { |
| 9458 | onWindowVisibilityChanged(GONE); |
| 9459 | } |
| 9460 | } |
| 9461 | |
| 9462 | onDetachedFromWindow(); |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 9463 | |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 9464 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
| 9465 | mOnAttachStateChangeListeners; |
| 9466 | if (listeners != null && listeners.size() > 0) { |
| 9467 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 9468 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 9469 | // could mutate the list by calling the various add/remove methods. This prevents |
| 9470 | // the array from being modified while we iterate it. |
| 9471 | for (OnAttachStateChangeListener listener : listeners) { |
| 9472 | listener.onViewDetachedFromWindow(this); |
| 9473 | } |
| 9474 | } |
| 9475 | |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 9476 | if ((mPrivateFlags & SCROLL_CONTAINER_ADDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9477 | mAttachInfo.mScrollContainers.remove(this); |
| 9478 | mPrivateFlags &= ~SCROLL_CONTAINER_ADDED; |
| 9479 | } |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 9480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9481 | mAttachInfo = null; |
| 9482 | } |
| 9483 | |
| 9484 | /** |
| 9485 | * Store this view hierarchy's frozen state into the given container. |
| 9486 | * |
| 9487 | * @param container The SparseArray in which to save the view's state. |
| 9488 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9489 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 9490 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 9491 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9492 | */ |
| 9493 | public void saveHierarchyState(SparseArray<Parcelable> container) { |
| 9494 | dispatchSaveInstanceState(container); |
| 9495 | } |
| 9496 | |
| 9497 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9498 | * Called by {@link #saveHierarchyState(android.util.SparseArray)} to store the state for |
| 9499 | * this view and its children. May be overridden to modify how freezing happens to a |
| 9500 | * 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] | 9501 | * |
| 9502 | * @param container The SparseArray in which to save the view's state. |
| 9503 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9504 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 9505 | * @see #saveHierarchyState(android.util.SparseArray) |
| 9506 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9507 | */ |
| 9508 | protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { |
| 9509 | if (mID != NO_ID && (mViewFlags & SAVE_DISABLED_MASK) == 0) { |
| 9510 | mPrivateFlags &= ~SAVE_STATE_CALLED; |
| 9511 | Parcelable state = onSaveInstanceState(); |
| 9512 | if ((mPrivateFlags & SAVE_STATE_CALLED) == 0) { |
| 9513 | throw new IllegalStateException( |
| 9514 | "Derived class did not call super.onSaveInstanceState()"); |
| 9515 | } |
| 9516 | if (state != null) { |
| 9517 | // Log.i("View", "Freezing #" + Integer.toHexString(mID) |
| 9518 | // + ": " + state); |
| 9519 | container.put(mID, state); |
| 9520 | } |
| 9521 | } |
| 9522 | } |
| 9523 | |
| 9524 | /** |
| 9525 | * Hook allowing a view to generate a representation of its internal state |
| 9526 | * that can later be used to create a new instance with that same state. |
| 9527 | * This state should only contain information that is not persistent or can |
| 9528 | * not be reconstructed later. For example, you will never store your |
| 9529 | * current position on screen because that will be computed again when a |
| 9530 | * new instance of the view is placed in its view hierarchy. |
| 9531 | * <p> |
| 9532 | * Some examples of things you may store here: the current cursor position |
| 9533 | * in a text view (but usually not the text itself since that is stored in a |
| 9534 | * content provider or other persistent storage), the currently selected |
| 9535 | * item in a list view. |
| 9536 | * |
| 9537 | * @return Returns a Parcelable object containing the view's current dynamic |
| 9538 | * state, or null if there is nothing interesting to save. The |
| 9539 | * default implementation returns null. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9540 | * @see #onRestoreInstanceState(android.os.Parcelable) |
| 9541 | * @see #saveHierarchyState(android.util.SparseArray) |
| 9542 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9543 | * @see #setSaveEnabled(boolean) |
| 9544 | */ |
| 9545 | protected Parcelable onSaveInstanceState() { |
| 9546 | mPrivateFlags |= SAVE_STATE_CALLED; |
| 9547 | return BaseSavedState.EMPTY_STATE; |
| 9548 | } |
| 9549 | |
| 9550 | /** |
| 9551 | * Restore this view hierarchy's frozen state from the given container. |
| 9552 | * |
| 9553 | * @param container The SparseArray which holds previously frozen states. |
| 9554 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9555 | * @see #saveHierarchyState(android.util.SparseArray) |
| 9556 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 9557 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9558 | */ |
| 9559 | public void restoreHierarchyState(SparseArray<Parcelable> container) { |
| 9560 | dispatchRestoreInstanceState(container); |
| 9561 | } |
| 9562 | |
| 9563 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9564 | * Called by {@link #restoreHierarchyState(android.util.SparseArray)} to retrieve the |
| 9565 | * state for this view and its children. May be overridden to modify how restoring |
| 9566 | * happens to a view's children; for example, some views may want to not store state |
| 9567 | * for their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9568 | * |
| 9569 | * @param container The SparseArray which holds previously saved state. |
| 9570 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9571 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 9572 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 9573 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9574 | */ |
| 9575 | protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 9576 | if (mID != NO_ID) { |
| 9577 | Parcelable state = container.get(mID); |
| 9578 | if (state != null) { |
| 9579 | // Log.i("View", "Restoreing #" + Integer.toHexString(mID) |
| 9580 | // + ": " + state); |
| 9581 | mPrivateFlags &= ~SAVE_STATE_CALLED; |
| 9582 | onRestoreInstanceState(state); |
| 9583 | if ((mPrivateFlags & SAVE_STATE_CALLED) == 0) { |
| 9584 | throw new IllegalStateException( |
| 9585 | "Derived class did not call super.onRestoreInstanceState()"); |
| 9586 | } |
| 9587 | } |
| 9588 | } |
| 9589 | } |
| 9590 | |
| 9591 | /** |
| 9592 | * Hook allowing a view to re-apply a representation of its internal state that had previously |
| 9593 | * been generated by {@link #onSaveInstanceState}. This function will never be called with a |
| 9594 | * null state. |
| 9595 | * |
| 9596 | * @param state The frozen state that had previously been returned by |
| 9597 | * {@link #onSaveInstanceState}. |
| 9598 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9599 | * @see #onSaveInstanceState() |
| 9600 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 9601 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9602 | */ |
| 9603 | protected void onRestoreInstanceState(Parcelable state) { |
| 9604 | mPrivateFlags |= SAVE_STATE_CALLED; |
| 9605 | if (state != BaseSavedState.EMPTY_STATE && state != null) { |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 9606 | throw new IllegalArgumentException("Wrong state class, expecting View State but " |
| 9607 | + "received " + state.getClass().toString() + " instead. This usually happens " |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9608 | + "when two views of different type have the same id in the same hierarchy. " |
| 9609 | + "This view's id is " + ViewDebug.resolveId(mContext, getId()) + ". Make sure " |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 9610 | + "other views do not use the same id."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9611 | } |
| 9612 | } |
| 9613 | |
| 9614 | /** |
| 9615 | * <p>Return the time at which the drawing of the view hierarchy started.</p> |
| 9616 | * |
| 9617 | * @return the drawing start time in milliseconds |
| 9618 | */ |
| 9619 | public long getDrawingTime() { |
| 9620 | return mAttachInfo != null ? mAttachInfo.mDrawingTime : 0; |
| 9621 | } |
| 9622 | |
| 9623 | /** |
| 9624 | * <p>Enables or disables the duplication of the parent's state into this view. When |
| 9625 | * duplication is enabled, this view gets its drawable state from its parent rather |
| 9626 | * than from its own internal properties.</p> |
| 9627 | * |
| 9628 | * <p>Note: in the current implementation, setting this property to true after the |
| 9629 | * view was added to a ViewGroup might have no effect at all. This property should |
| 9630 | * always be used from XML or set to true before adding this view to a ViewGroup.</p> |
| 9631 | * |
| 9632 | * <p>Note: if this view's parent addStateFromChildren property is enabled and this |
| 9633 | * property is enabled, an exception will be thrown.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9634 | * |
Gilles Debunne | fb81703 | 2011-01-13 13:52:49 -0800 | [diff] [blame] | 9635 | * <p>Note: if the child view uses and updates additionnal states which are unknown to the |
| 9636 | * 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] | 9637 | * |
| 9638 | * @param enabled True to enable duplication of the parent's drawable state, false |
| 9639 | * to disable it. |
| 9640 | * |
| 9641 | * @see #getDrawableState() |
| 9642 | * @see #isDuplicateParentStateEnabled() |
| 9643 | */ |
| 9644 | public void setDuplicateParentStateEnabled(boolean enabled) { |
| 9645 | setFlags(enabled ? DUPLICATE_PARENT_STATE : 0, DUPLICATE_PARENT_STATE); |
| 9646 | } |
| 9647 | |
| 9648 | /** |
| 9649 | * <p>Indicates whether this duplicates its drawable state from its parent.</p> |
| 9650 | * |
| 9651 | * @return True if this view's drawable state is duplicated from the parent, |
| 9652 | * false otherwise |
| 9653 | * |
| 9654 | * @see #getDrawableState() |
| 9655 | * @see #setDuplicateParentStateEnabled(boolean) |
| 9656 | */ |
| 9657 | public boolean isDuplicateParentStateEnabled() { |
| 9658 | return (mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE; |
| 9659 | } |
| 9660 | |
| 9661 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9662 | * <p>Specifies the type of layer backing this view. The layer can be |
| 9663 | * {@link #LAYER_TYPE_NONE disabled}, {@link #LAYER_TYPE_SOFTWARE software} or |
| 9664 | * {@link #LAYER_TYPE_HARDWARE hardware}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9665 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9666 | * <p>A layer is associated with an optional {@link android.graphics.Paint} |
| 9667 | * instance that controls how the layer is composed on screen. The following |
| 9668 | * properties of the paint are taken into account when composing the layer:</p> |
| 9669 | * <ul> |
| 9670 | * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> |
| 9671 | * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> |
| 9672 | * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> |
| 9673 | * </ul> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9674 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9675 | * <p>If this view has an alpha value set to < 1.0 by calling |
| 9676 | * {@link #setAlpha(float)}, the alpha value of the layer's paint is replaced by |
| 9677 | * this view's alpha value. Calling {@link #setAlpha(float)} is therefore |
| 9678 | * equivalent to setting a hardware layer on this view and providing a paint with |
| 9679 | * the desired alpha value.<p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9680 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9681 | * <p>Refer to the documentation of {@link #LAYER_TYPE_NONE disabled}, |
| 9682 | * {@link #LAYER_TYPE_SOFTWARE software} and {@link #LAYER_TYPE_HARDWARE hardware} |
| 9683 | * for more information on when and how to use layers.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9684 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9685 | * @param layerType The ype of layer to use with this view, must be one of |
| 9686 | * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 9687 | * {@link #LAYER_TYPE_HARDWARE} |
| 9688 | * @param paint The paint used to compose the layer. This argument is optional |
| 9689 | * and can be null. It is ignored when the layer type is |
| 9690 | * {@link #LAYER_TYPE_NONE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9691 | * |
| 9692 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9693 | * @see #LAYER_TYPE_NONE |
| 9694 | * @see #LAYER_TYPE_SOFTWARE |
| 9695 | * @see #LAYER_TYPE_HARDWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9696 | * @see #setAlpha(float) |
| 9697 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9698 | * @attr ref android.R.styleable#View_layerType |
| 9699 | */ |
| 9700 | public void setLayerType(int layerType, Paint paint) { |
| 9701 | if (layerType < LAYER_TYPE_NONE || layerType > LAYER_TYPE_HARDWARE) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9702 | 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] | 9703 | + "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE"); |
| 9704 | } |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9705 | |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 9706 | if (layerType == mLayerType) { |
| 9707 | if (layerType != LAYER_TYPE_NONE && paint != mLayerPaint) { |
| 9708 | mLayerPaint = paint == null ? new Paint() : paint; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9709 | invalidateParentCaches(); |
| 9710 | invalidate(true); |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 9711 | } |
| 9712 | return; |
| 9713 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9714 | |
| 9715 | // Destroy any previous software drawing cache if needed |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9716 | switch (mLayerType) { |
Chet Haase | 6f33e81 | 2011-05-17 12:42:19 -0700 | [diff] [blame] | 9717 | case LAYER_TYPE_HARDWARE: |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 9718 | destroyLayer(); |
Chet Haase | 6f33e81 | 2011-05-17 12:42:19 -0700 | [diff] [blame] | 9719 | // fall through - unaccelerated views may use software layer mechanism instead |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9720 | case LAYER_TYPE_SOFTWARE: |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 9721 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9722 | break; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9723 | default: |
| 9724 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9725 | } |
| 9726 | |
| 9727 | mLayerType = layerType; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 9728 | final boolean layerDisabled = mLayerType == LAYER_TYPE_NONE; |
| 9729 | mLayerPaint = layerDisabled ? null : (paint == null ? new Paint() : paint); |
| 9730 | mLocalDirtyRect = layerDisabled ? null : new Rect(); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9731 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9732 | invalidateParentCaches(); |
| 9733 | invalidate(true); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9734 | } |
| 9735 | |
| 9736 | /** |
| 9737 | * Indicates what type of layer is currently associated with this view. By default |
| 9738 | * a view does not have a layer, and the layer type is {@link #LAYER_TYPE_NONE}. |
| 9739 | * Refer to the documentation of {@link #setLayerType(int, android.graphics.Paint)} |
| 9740 | * for more information on the different types of layers. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9741 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9742 | * @return {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 9743 | * {@link #LAYER_TYPE_HARDWARE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9744 | * |
| 9745 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 9746 | * @see #buildLayer() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9747 | * @see #LAYER_TYPE_NONE |
| 9748 | * @see #LAYER_TYPE_SOFTWARE |
| 9749 | * @see #LAYER_TYPE_HARDWARE |
| 9750 | */ |
| 9751 | public int getLayerType() { |
| 9752 | return mLayerType; |
| 9753 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9754 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9755 | /** |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 9756 | * Forces this view's layer to be created and this view to be rendered |
| 9757 | * into its layer. If this view's layer type is set to {@link #LAYER_TYPE_NONE}, |
| 9758 | * invoking this method will have no effect. |
| 9759 | * |
| 9760 | * This method can for instance be used to render a view into its layer before |
| 9761 | * starting an animation. If this view is complex, rendering into the layer |
| 9762 | * before starting the animation will avoid skipping frames. |
| 9763 | * |
| 9764 | * @throws IllegalStateException If this view is not attached to a window |
| 9765 | * |
| 9766 | * @see #setLayerType(int, android.graphics.Paint) |
| 9767 | */ |
| 9768 | public void buildLayer() { |
| 9769 | if (mLayerType == LAYER_TYPE_NONE) return; |
| 9770 | |
| 9771 | if (mAttachInfo == null) { |
| 9772 | throw new IllegalStateException("This view must be attached to a window first"); |
| 9773 | } |
| 9774 | |
| 9775 | switch (mLayerType) { |
| 9776 | case LAYER_TYPE_HARDWARE: |
| 9777 | getHardwareLayer(); |
| 9778 | break; |
| 9779 | case LAYER_TYPE_SOFTWARE: |
| 9780 | buildDrawingCache(true); |
| 9781 | break; |
| 9782 | } |
| 9783 | } |
| 9784 | |
| 9785 | /** |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9786 | * <p>Returns a hardware layer that can be used to draw this view again |
| 9787 | * without executing its draw method.</p> |
| 9788 | * |
| 9789 | * @return A HardwareLayer ready to render, or null if an error occurred. |
| 9790 | */ |
Romain Guy | 5e7f766 | 2011-01-24 22:35:56 -0800 | [diff] [blame] | 9791 | HardwareLayer getHardwareLayer() { |
Romain Guy | ea83503 | 2011-07-28 19:24:37 -0700 | [diff] [blame] | 9792 | if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null || |
| 9793 | !mAttachInfo.mHardwareRenderer.isEnabled()) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9794 | return null; |
| 9795 | } |
| 9796 | |
| 9797 | final int width = mRight - mLeft; |
| 9798 | final int height = mBottom - mTop; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9799 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9800 | if (width == 0 || height == 0) { |
| 9801 | return null; |
| 9802 | } |
| 9803 | |
| 9804 | if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || mHardwareLayer == null) { |
| 9805 | if (mHardwareLayer == null) { |
| 9806 | mHardwareLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer( |
| 9807 | width, height, isOpaque()); |
Romain Guy | 62687ec | 2011-02-02 15:44:19 -0800 | [diff] [blame] | 9808 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9809 | } else if (mHardwareLayer.getWidth() != width || mHardwareLayer.getHeight() != height) { |
| 9810 | mHardwareLayer.resize(width, height); |
Romain Guy | 62687ec | 2011-02-02 15:44:19 -0800 | [diff] [blame] | 9811 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9812 | } |
| 9813 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 9814 | HardwareCanvas currentCanvas = mAttachInfo.mHardwareCanvas; |
Romain Guy | 5e7f766 | 2011-01-24 22:35:56 -0800 | [diff] [blame] | 9815 | final HardwareCanvas canvas = mHardwareLayer.start(currentCanvas); |
| 9816 | mAttachInfo.mHardwareCanvas = canvas; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9817 | try { |
| 9818 | canvas.setViewport(width, height); |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 9819 | canvas.onPreDraw(mLocalDirtyRect); |
Romain Guy | 62687ec | 2011-02-02 15:44:19 -0800 | [diff] [blame] | 9820 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9821 | |
Chet Haase | 88172fe | 2011-03-07 17:36:33 -0800 | [diff] [blame] | 9822 | final int restoreCount = canvas.save(); |
| 9823 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9824 | computeScroll(); |
| 9825 | canvas.translate(-mScrollX, -mScrollY); |
| 9826 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9827 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9828 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9829 | // Fast path for layouts with no backgrounds |
| 9830 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 9831 | mPrivateFlags &= ~DIRTY_MASK; |
| 9832 | dispatchDraw(canvas); |
| 9833 | } else { |
| 9834 | draw(canvas); |
| 9835 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9836 | |
Chet Haase | 88172fe | 2011-03-07 17:36:33 -0800 | [diff] [blame] | 9837 | canvas.restoreToCount(restoreCount); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9838 | } finally { |
| 9839 | canvas.onPostDraw(); |
Romain Guy | 5e7f766 | 2011-01-24 22:35:56 -0800 | [diff] [blame] | 9840 | mHardwareLayer.end(currentCanvas); |
| 9841 | mAttachInfo.mHardwareCanvas = currentCanvas; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9842 | } |
| 9843 | } |
| 9844 | |
| 9845 | return mHardwareLayer; |
| 9846 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9847 | |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 9848 | boolean destroyLayer() { |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 9849 | if (mHardwareLayer != null) { |
| 9850 | mHardwareLayer.destroy(); |
| 9851 | mHardwareLayer = null; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 9852 | return true; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 9853 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 9854 | return false; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 9855 | } |
| 9856 | |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9857 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9858 | * <p>Enables or disables the drawing cache. When the drawing cache is enabled, the next call |
| 9859 | * to {@link #getDrawingCache()} or {@link #buildDrawingCache()} will draw the view in a |
| 9860 | * bitmap. Calling {@link #draw(android.graphics.Canvas)} will not draw from the cache when |
| 9861 | * the cache is enabled. To benefit from the cache, you must request the drawing cache by |
| 9862 | * calling {@link #getDrawingCache()} and draw it on screen if the returned bitmap is not |
| 9863 | * null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9864 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9865 | * <p>Enabling the drawing cache is similar to |
| 9866 | * {@link #setLayerType(int, android.graphics.Paint) setting a layer} when hardware |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9867 | * acceleration is turned off. When hardware acceleration is turned on, enabling the |
| 9868 | * drawing cache has no effect on rendering because the system uses a different mechanism |
| 9869 | * for acceleration which ignores the flag. If you want to use a Bitmap for the view, even |
| 9870 | * when hardware acceleration is enabled, see {@link #setLayerType(int, android.graphics.Paint)} |
| 9871 | * for information on how to enable software and hardware layers.</p> |
| 9872 | * |
| 9873 | * <p>This API can be used to manually generate |
| 9874 | * a bitmap copy of this view, by setting the flag to <code>true</code> and calling |
| 9875 | * {@link #getDrawingCache()}.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9876 | * |
| 9877 | * @param enabled true to enable the drawing cache, false otherwise |
| 9878 | * |
| 9879 | * @see #isDrawingCacheEnabled() |
| 9880 | * @see #getDrawingCache() |
| 9881 | * @see #buildDrawingCache() |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9882 | * @see #setLayerType(int, android.graphics.Paint) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9883 | */ |
| 9884 | public void setDrawingCacheEnabled(boolean enabled) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 9885 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9886 | setFlags(enabled ? DRAWING_CACHE_ENABLED : 0, DRAWING_CACHE_ENABLED); |
| 9887 | } |
| 9888 | |
| 9889 | /** |
| 9890 | * <p>Indicates whether the drawing cache is enabled for this view.</p> |
| 9891 | * |
| 9892 | * @return true if the drawing cache is enabled |
| 9893 | * |
| 9894 | * @see #setDrawingCacheEnabled(boolean) |
| 9895 | * @see #getDrawingCache() |
| 9896 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 9897 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9898 | public boolean isDrawingCacheEnabled() { |
| 9899 | return (mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED; |
| 9900 | } |
| 9901 | |
| 9902 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9903 | * Debugging utility which recursively outputs the dirty state of a view and its |
| 9904 | * descendants. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9905 | * |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9906 | * @hide |
| 9907 | */ |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 9908 | @SuppressWarnings({"UnusedDeclaration"}) |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9909 | public void outputDirtyFlags(String indent, boolean clear, int clearMask) { |
| 9910 | Log.d("View", indent + this + " DIRTY(" + (mPrivateFlags & View.DIRTY_MASK) + |
| 9911 | ") DRAWN(" + (mPrivateFlags & DRAWN) + ")" + " CACHE_VALID(" + |
| 9912 | (mPrivateFlags & View.DRAWING_CACHE_VALID) + |
| 9913 | ") INVALIDATED(" + (mPrivateFlags & INVALIDATED) + ")"); |
| 9914 | if (clear) { |
| 9915 | mPrivateFlags &= clearMask; |
| 9916 | } |
| 9917 | if (this instanceof ViewGroup) { |
| 9918 | ViewGroup parent = (ViewGroup) this; |
| 9919 | final int count = parent.getChildCount(); |
| 9920 | for (int i = 0; i < count; i++) { |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 9921 | final View child = parent.getChildAt(i); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9922 | child.outputDirtyFlags(indent + " ", clear, clearMask); |
| 9923 | } |
| 9924 | } |
| 9925 | } |
| 9926 | |
| 9927 | /** |
| 9928 | * This method is used by ViewGroup to cause its children to restore or recreate their |
| 9929 | * display lists. It is called by getDisplayList() when the parent ViewGroup does not need |
| 9930 | * to recreate its own display list, which would happen if it went through the normal |
| 9931 | * draw/dispatchDraw mechanisms. |
| 9932 | * |
| 9933 | * @hide |
| 9934 | */ |
| 9935 | protected void dispatchGetDisplayList() {} |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 9936 | |
| 9937 | /** |
| 9938 | * A view that is not attached or hardware accelerated cannot create a display list. |
| 9939 | * This method checks these conditions and returns the appropriate result. |
| 9940 | * |
| 9941 | * @return true if view has the ability to create a display list, false otherwise. |
| 9942 | * |
| 9943 | * @hide |
| 9944 | */ |
| 9945 | public boolean canHaveDisplayList() { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 9946 | return !(mAttachInfo == null || mAttachInfo.mHardwareRenderer == null); |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 9947 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9948 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9949 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 9950 | * <p>Returns a display list that can be used to draw this view again |
| 9951 | * without executing its draw method.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9952 | * |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 9953 | * @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] | 9954 | * |
| 9955 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 9956 | */ |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9957 | public DisplayList getDisplayList() { |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 9958 | if (!canHaveDisplayList()) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 9959 | return null; |
| 9960 | } |
| 9961 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9962 | if (((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || |
| 9963 | mDisplayList == null || !mDisplayList.isValid() || |
| 9964 | mRecreateDisplayList)) { |
| 9965 | // Don't need to recreate the display list, just need to tell our |
| 9966 | // children to restore/recreate theirs |
| 9967 | if (mDisplayList != null && mDisplayList.isValid() && |
| 9968 | !mRecreateDisplayList) { |
| 9969 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 9970 | mPrivateFlags &= ~DIRTY_MASK; |
| 9971 | dispatchGetDisplayList(); |
| 9972 | |
| 9973 | return mDisplayList; |
| 9974 | } |
| 9975 | |
| 9976 | // If we got here, we're recreating it. Mark it as such to ensure that |
| 9977 | // we copy in child display lists into ours in drawChild() |
| 9978 | mRecreateDisplayList = true; |
Chet Haase | 9e90a99 | 2011-01-04 16:23:21 -0800 | [diff] [blame] | 9979 | if (mDisplayList == null) { |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 9980 | mDisplayList = mAttachInfo.mHardwareRenderer.createDisplayList(); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9981 | // If we're creating a new display list, make sure our parent gets invalidated |
| 9982 | // since they will need to recreate their display list to account for this |
| 9983 | // new child display list. |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9984 | invalidateParentCaches(); |
Chet Haase | 9e90a99 | 2011-01-04 16:23:21 -0800 | [diff] [blame] | 9985 | } |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 9986 | |
| 9987 | final HardwareCanvas canvas = mDisplayList.start(); |
| 9988 | try { |
| 9989 | int width = mRight - mLeft; |
| 9990 | int height = mBottom - mTop; |
| 9991 | |
| 9992 | canvas.setViewport(width, height); |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 9993 | // The dirty rect should always be null for a display list |
| 9994 | canvas.onPreDraw(null); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 9995 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9996 | computeScroll(); |
| 9997 | canvas.translate(-mScrollX, -mScrollY); |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 9998 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 9999 | mPrivateFlags &= ~DIRTY_MASK; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10000 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10001 | // Fast path for layouts with no backgrounds |
| 10002 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10003 | dispatchDraw(canvas); |
| 10004 | } else { |
| 10005 | draw(canvas); |
| 10006 | } |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10007 | } finally { |
| 10008 | canvas.onPostDraw(); |
| 10009 | |
| 10010 | mDisplayList.end(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10011 | } |
Chet Haase | 77785f9 | 2011-01-25 23:22:09 -0800 | [diff] [blame] | 10012 | } else { |
| 10013 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 10014 | mPrivateFlags &= ~DIRTY_MASK; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10015 | } |
| 10016 | |
| 10017 | return mDisplayList; |
| 10018 | } |
| 10019 | |
| 10020 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10021 | * <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] | 10022 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10023 | * @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] | 10024 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10025 | * @see #getDrawingCache(boolean) |
| 10026 | */ |
| 10027 | public Bitmap getDrawingCache() { |
| 10028 | return getDrawingCache(false); |
| 10029 | } |
| 10030 | |
| 10031 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10032 | * <p>Returns the bitmap in which this view drawing is cached. The returned bitmap |
| 10033 | * is null when caching is disabled. If caching is enabled and the cache is not ready, |
| 10034 | * this method will create it. Calling {@link #draw(android.graphics.Canvas)} will not |
| 10035 | * draw from the cache when the cache is enabled. To benefit from the cache, you must |
| 10036 | * request the drawing cache by calling this method and draw it on screen if the |
| 10037 | * returned bitmap is not null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10038 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10039 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 10040 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 10041 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 10042 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 10043 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 10044 | * size than the view. This implies that your application must be able to handle this |
| 10045 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10046 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10047 | * @param autoScale Indicates whether the generated bitmap should be scaled based on |
| 10048 | * the current density of the screen when the application is in compatibility |
| 10049 | * mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10050 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10051 | * @return A bitmap representing this view or null if cache is disabled. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10052 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10053 | * @see #setDrawingCacheEnabled(boolean) |
| 10054 | * @see #isDrawingCacheEnabled() |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10055 | * @see #buildDrawingCache(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10056 | * @see #destroyDrawingCache() |
| 10057 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10058 | public Bitmap getDrawingCache(boolean autoScale) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10059 | if ((mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING) { |
| 10060 | return null; |
| 10061 | } |
| 10062 | if ((mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10063 | buildDrawingCache(autoScale); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10064 | } |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10065 | return autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10066 | } |
| 10067 | |
| 10068 | /** |
| 10069 | * <p>Frees the resources used by the drawing cache. If you call |
| 10070 | * {@link #buildDrawingCache()} manually without calling |
| 10071 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 10072 | * should cleanup the cache with this method afterwards.</p> |
| 10073 | * |
| 10074 | * @see #setDrawingCacheEnabled(boolean) |
| 10075 | * @see #buildDrawingCache() |
| 10076 | * @see #getDrawingCache() |
| 10077 | */ |
| 10078 | public void destroyDrawingCache() { |
| 10079 | if (mDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10080 | mDrawingCache.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10081 | mDrawingCache = null; |
| 10082 | } |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10083 | if (mUnscaledDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10084 | mUnscaledDrawingCache.recycle(); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10085 | mUnscaledDrawingCache = null; |
| 10086 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10087 | } |
| 10088 | |
| 10089 | /** |
| 10090 | * Setting a solid background color for the drawing cache's bitmaps will improve |
| 10091 | * perfromance and memory usage. Note, though that this should only be used if this |
| 10092 | * view will always be drawn on top of a solid color. |
| 10093 | * |
| 10094 | * @param color The background color to use for the drawing cache's bitmap |
| 10095 | * |
| 10096 | * @see #setDrawingCacheEnabled(boolean) |
| 10097 | * @see #buildDrawingCache() |
| 10098 | * @see #getDrawingCache() |
| 10099 | */ |
| 10100 | public void setDrawingCacheBackgroundColor(int color) { |
Romain Guy | 52e2ef8 | 2010-01-14 12:11:48 -0800 | [diff] [blame] | 10101 | if (color != mDrawingCacheBackgroundColor) { |
| 10102 | mDrawingCacheBackgroundColor = color; |
| 10103 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 10104 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10105 | } |
| 10106 | |
| 10107 | /** |
| 10108 | * @see #setDrawingCacheBackgroundColor(int) |
| 10109 | * |
| 10110 | * @return The background color to used for the drawing cache's bitmap |
| 10111 | */ |
| 10112 | public int getDrawingCacheBackgroundColor() { |
| 10113 | return mDrawingCacheBackgroundColor; |
| 10114 | } |
| 10115 | |
| 10116 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10117 | * <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] | 10118 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10119 | * @see #buildDrawingCache(boolean) |
| 10120 | */ |
| 10121 | public void buildDrawingCache() { |
| 10122 | buildDrawingCache(false); |
| 10123 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 10124 | |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10125 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10126 | * <p>Forces the drawing cache to be built if the drawing cache is invalid.</p> |
| 10127 | * |
| 10128 | * <p>If you call {@link #buildDrawingCache()} manually without calling |
| 10129 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 10130 | * should cleanup the cache by calling {@link #destroyDrawingCache()} afterwards.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10131 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10132 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 10133 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 10134 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 10135 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 10136 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 10137 | * size than the view. This implies that your application must be able to handle this |
| 10138 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10139 | * |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 10140 | * <p>You should avoid calling this method when hardware acceleration is enabled. If |
| 10141 | * 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] | 10142 | * 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] | 10143 | * performance.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10144 | * |
| 10145 | * @see #getDrawingCache() |
| 10146 | * @see #destroyDrawingCache() |
| 10147 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10148 | public void buildDrawingCache(boolean autoScale) { |
| 10149 | if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || (autoScale ? |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10150 | mDrawingCache == null : mUnscaledDrawingCache == null)) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 10151 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10152 | |
| 10153 | if (ViewDebug.TRACE_HIERARCHY) { |
| 10154 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.BUILD_CACHE); |
| 10155 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10156 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10157 | int width = mRight - mLeft; |
| 10158 | int height = mBottom - mTop; |
| 10159 | |
| 10160 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 10161 | final boolean scalingRequired = attachInfo != null && attachInfo.mScalingRequired; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10162 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 10163 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10164 | width = (int) ((width * attachInfo.mApplicationScale) + 0.5f); |
| 10165 | height = (int) ((height * attachInfo.mApplicationScale) + 0.5f); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10166 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10167 | |
| 10168 | final int drawingCacheBackgroundColor = mDrawingCacheBackgroundColor; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 10169 | final boolean opaque = drawingCacheBackgroundColor != 0 || isOpaque(); |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 10170 | final boolean use32BitCache = attachInfo != null && attachInfo.mUse32BitDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10171 | |
| 10172 | if (width <= 0 || height <= 0 || |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 10173 | // Projected bitmap size in bytes |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 10174 | (width * height * (opaque && !use32BitCache ? 2 : 4) > |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10175 | ViewConfiguration.get(mContext).getScaledMaximumDrawingCacheSize())) { |
| 10176 | destroyDrawingCache(); |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 10177 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10178 | return; |
| 10179 | } |
| 10180 | |
| 10181 | boolean clear = true; |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10182 | Bitmap bitmap = autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10183 | |
| 10184 | if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10185 | Bitmap.Config quality; |
| 10186 | if (!opaque) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 10187 | // Never pick ARGB_4444 because it looks awful |
| 10188 | // 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] | 10189 | switch (mViewFlags & DRAWING_CACHE_QUALITY_MASK) { |
| 10190 | case DRAWING_CACHE_QUALITY_AUTO: |
| 10191 | quality = Bitmap.Config.ARGB_8888; |
| 10192 | break; |
| 10193 | case DRAWING_CACHE_QUALITY_LOW: |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 10194 | quality = Bitmap.Config.ARGB_8888; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10195 | break; |
| 10196 | case DRAWING_CACHE_QUALITY_HIGH: |
| 10197 | quality = Bitmap.Config.ARGB_8888; |
| 10198 | break; |
| 10199 | default: |
| 10200 | quality = Bitmap.Config.ARGB_8888; |
| 10201 | break; |
| 10202 | } |
| 10203 | } else { |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 10204 | // Optimization for translucent windows |
| 10205 | // 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] | 10206 | 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] | 10207 | } |
| 10208 | |
| 10209 | // Try to cleanup memory |
| 10210 | if (bitmap != null) bitmap.recycle(); |
| 10211 | |
| 10212 | try { |
| 10213 | bitmap = Bitmap.createBitmap(width, height, quality); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 10214 | bitmap.setDensity(getResources().getDisplayMetrics().densityDpi); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10215 | if (autoScale) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10216 | mDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10217 | } else { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10218 | mUnscaledDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10219 | } |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 10220 | if (opaque && use32BitCache) bitmap.setHasAlpha(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10221 | } catch (OutOfMemoryError e) { |
| 10222 | // If there is not enough memory to create the bitmap cache, just |
| 10223 | // ignore the issue as bitmap caches are not required to draw the |
| 10224 | // view hierarchy |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10225 | if (autoScale) { |
| 10226 | mDrawingCache = null; |
| 10227 | } else { |
| 10228 | mUnscaledDrawingCache = null; |
| 10229 | } |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 10230 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10231 | return; |
| 10232 | } |
| 10233 | |
| 10234 | clear = drawingCacheBackgroundColor != 0; |
| 10235 | } |
| 10236 | |
| 10237 | Canvas canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10238 | if (attachInfo != null) { |
| 10239 | canvas = attachInfo.mCanvas; |
| 10240 | if (canvas == null) { |
| 10241 | canvas = new Canvas(); |
| 10242 | } |
| 10243 | canvas.setBitmap(bitmap); |
| 10244 | // Temporarily clobber the cached Canvas in case one of our children |
| 10245 | // is also using a drawing cache. Without this, the children would |
| 10246 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 10247 | // thing would happen (invisible views, corrupted drawings, etc.) |
| 10248 | attachInfo.mCanvas = null; |
| 10249 | } else { |
| 10250 | // This case should hopefully never or seldom happen |
| 10251 | canvas = new Canvas(bitmap); |
| 10252 | } |
| 10253 | |
| 10254 | if (clear) { |
| 10255 | bitmap.eraseColor(drawingCacheBackgroundColor); |
| 10256 | } |
| 10257 | |
| 10258 | computeScroll(); |
| 10259 | final int restoreCount = canvas.save(); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10260 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 10261 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10262 | final float scale = attachInfo.mApplicationScale; |
| 10263 | canvas.scale(scale, scale); |
| 10264 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10265 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10266 | canvas.translate(-mScrollX, -mScrollY); |
| 10267 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10268 | mPrivateFlags |= DRAWN; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10269 | if (mAttachInfo == null || !mAttachInfo.mHardwareAccelerated || |
| 10270 | mLayerType != LAYER_TYPE_NONE) { |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 10271 | mPrivateFlags |= DRAWING_CACHE_VALID; |
| 10272 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10273 | |
| 10274 | // Fast path for layouts with no backgrounds |
| 10275 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 10276 | if (ViewDebug.TRACE_HIERARCHY) { |
| 10277 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW); |
| 10278 | } |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10279 | mPrivateFlags &= ~DIRTY_MASK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10280 | dispatchDraw(canvas); |
| 10281 | } else { |
| 10282 | draw(canvas); |
| 10283 | } |
| 10284 | |
| 10285 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 10286 | canvas.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10287 | |
| 10288 | if (attachInfo != null) { |
| 10289 | // Restore the cached Canvas for our siblings |
| 10290 | attachInfo.mCanvas = canvas; |
| 10291 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10292 | } |
| 10293 | } |
| 10294 | |
| 10295 | /** |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10296 | * Create a snapshot of the view into a bitmap. We should probably make |
| 10297 | * some form of this public, but should think about the API. |
| 10298 | */ |
Romain Guy | 223ff5c | 2010-03-02 17:07:47 -0800 | [diff] [blame] | 10299 | Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipChildren) { |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 10300 | int width = mRight - mLeft; |
| 10301 | int height = mBottom - mTop; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10302 | |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 10303 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 10304 | final float scale = attachInfo != null ? attachInfo.mApplicationScale : 1.0f; |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 10305 | width = (int) ((width * scale) + 0.5f); |
| 10306 | height = (int) ((height * scale) + 0.5f); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10307 | |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 10308 | 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] | 10309 | if (bitmap == null) { |
| 10310 | throw new OutOfMemoryError(); |
| 10311 | } |
| 10312 | |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 10313 | bitmap.setDensity(getResources().getDisplayMetrics().densityDpi); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10314 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10315 | Canvas canvas; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10316 | if (attachInfo != null) { |
| 10317 | canvas = attachInfo.mCanvas; |
| 10318 | if (canvas == null) { |
| 10319 | canvas = new Canvas(); |
| 10320 | } |
| 10321 | canvas.setBitmap(bitmap); |
| 10322 | // Temporarily clobber the cached Canvas in case one of our children |
| 10323 | // is also using a drawing cache. Without this, the children would |
| 10324 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 10325 | // things would happen (invisible views, corrupted drawings, etc.) |
| 10326 | attachInfo.mCanvas = null; |
| 10327 | } else { |
| 10328 | // This case should hopefully never or seldom happen |
| 10329 | canvas = new Canvas(bitmap); |
| 10330 | } |
| 10331 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10332 | if ((backgroundColor & 0xff000000) != 0) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10333 | bitmap.eraseColor(backgroundColor); |
| 10334 | } |
| 10335 | |
| 10336 | computeScroll(); |
| 10337 | final int restoreCount = canvas.save(); |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 10338 | canvas.scale(scale, scale); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10339 | canvas.translate(-mScrollX, -mScrollY); |
| 10340 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10341 | // Temporarily remove the dirty mask |
| 10342 | int flags = mPrivateFlags; |
| 10343 | mPrivateFlags &= ~DIRTY_MASK; |
| 10344 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10345 | // Fast path for layouts with no backgrounds |
| 10346 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 10347 | dispatchDraw(canvas); |
| 10348 | } else { |
| 10349 | draw(canvas); |
| 10350 | } |
| 10351 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10352 | mPrivateFlags = flags; |
| 10353 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10354 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 10355 | canvas.setBitmap(null); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10356 | |
| 10357 | if (attachInfo != null) { |
| 10358 | // Restore the cached Canvas for our siblings |
| 10359 | attachInfo.mCanvas = canvas; |
| 10360 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10361 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10362 | return bitmap; |
| 10363 | } |
| 10364 | |
| 10365 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10366 | * Indicates whether this View is currently in edit mode. A View is usually |
| 10367 | * in edit mode when displayed within a developer tool. For instance, if |
| 10368 | * this View is being drawn by a visual user interface builder, this method |
| 10369 | * should return true. |
| 10370 | * |
| 10371 | * Subclasses should check the return value of this method to provide |
| 10372 | * different behaviors if their normal behavior might interfere with the |
| 10373 | * host environment. For instance: the class spawns a thread in its |
| 10374 | * constructor, the drawing code relies on device-specific features, etc. |
| 10375 | * |
| 10376 | * This method is usually checked in the drawing code of custom widgets. |
| 10377 | * |
| 10378 | * @return True if this View is in edit mode, false otherwise. |
| 10379 | */ |
| 10380 | public boolean isInEditMode() { |
| 10381 | return false; |
| 10382 | } |
| 10383 | |
| 10384 | /** |
| 10385 | * If the View draws content inside its padding and enables fading edges, |
| 10386 | * it needs to support padding offsets. Padding offsets are added to the |
| 10387 | * fading edges to extend the length of the fade so that it covers pixels |
| 10388 | * drawn inside the padding. |
| 10389 | * |
| 10390 | * Subclasses of this class should override this method if they need |
| 10391 | * to draw content inside the padding. |
| 10392 | * |
| 10393 | * @return True if padding offset must be applied, false otherwise. |
| 10394 | * |
| 10395 | * @see #getLeftPaddingOffset() |
| 10396 | * @see #getRightPaddingOffset() |
| 10397 | * @see #getTopPaddingOffset() |
| 10398 | * @see #getBottomPaddingOffset() |
| 10399 | * |
| 10400 | * @since CURRENT |
| 10401 | */ |
| 10402 | protected boolean isPaddingOffsetRequired() { |
| 10403 | return false; |
| 10404 | } |
| 10405 | |
| 10406 | /** |
| 10407 | * Amount by which to extend the left fading region. Called only when |
| 10408 | * {@link #isPaddingOffsetRequired()} returns true. |
| 10409 | * |
| 10410 | * @return The left padding offset in pixels. |
| 10411 | * |
| 10412 | * @see #isPaddingOffsetRequired() |
| 10413 | * |
| 10414 | * @since CURRENT |
| 10415 | */ |
| 10416 | protected int getLeftPaddingOffset() { |
| 10417 | return 0; |
| 10418 | } |
| 10419 | |
| 10420 | /** |
| 10421 | * Amount by which to extend the right fading region. Called only when |
| 10422 | * {@link #isPaddingOffsetRequired()} returns true. |
| 10423 | * |
| 10424 | * @return The right padding offset in pixels. |
| 10425 | * |
| 10426 | * @see #isPaddingOffsetRequired() |
| 10427 | * |
| 10428 | * @since CURRENT |
| 10429 | */ |
| 10430 | protected int getRightPaddingOffset() { |
| 10431 | return 0; |
| 10432 | } |
| 10433 | |
| 10434 | /** |
| 10435 | * Amount by which to extend the top fading region. Called only when |
| 10436 | * {@link #isPaddingOffsetRequired()} returns true. |
| 10437 | * |
| 10438 | * @return The top padding offset in pixels. |
| 10439 | * |
| 10440 | * @see #isPaddingOffsetRequired() |
| 10441 | * |
| 10442 | * @since CURRENT |
| 10443 | */ |
| 10444 | protected int getTopPaddingOffset() { |
| 10445 | return 0; |
| 10446 | } |
| 10447 | |
| 10448 | /** |
| 10449 | * Amount by which to extend the bottom fading region. Called only when |
| 10450 | * {@link #isPaddingOffsetRequired()} returns true. |
| 10451 | * |
| 10452 | * @return The bottom padding offset in pixels. |
| 10453 | * |
| 10454 | * @see #isPaddingOffsetRequired() |
| 10455 | * |
| 10456 | * @since CURRENT |
| 10457 | */ |
| 10458 | protected int getBottomPaddingOffset() { |
| 10459 | return 0; |
| 10460 | } |
| 10461 | |
| 10462 | /** |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 10463 | * @hide |
| 10464 | * @param offsetRequired |
| 10465 | */ |
| 10466 | protected int getFadeTop(boolean offsetRequired) { |
| 10467 | int top = mPaddingTop; |
| 10468 | if (offsetRequired) top += getTopPaddingOffset(); |
| 10469 | return top; |
| 10470 | } |
| 10471 | |
| 10472 | /** |
| 10473 | * @hide |
| 10474 | * @param offsetRequired |
| 10475 | */ |
| 10476 | protected int getFadeHeight(boolean offsetRequired) { |
| 10477 | int padding = mPaddingTop; |
| 10478 | if (offsetRequired) padding += getTopPaddingOffset(); |
| 10479 | return mBottom - mTop - mPaddingBottom - padding; |
| 10480 | } |
| 10481 | |
| 10482 | /** |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 10483 | * <p>Indicates whether this view is attached to an hardware accelerated |
| 10484 | * window or not.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10485 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 10486 | * <p>Even if this method returns true, it does not mean that every call |
| 10487 | * to {@link #draw(android.graphics.Canvas)} will be made with an hardware |
| 10488 | * accelerated {@link android.graphics.Canvas}. For instance, if this view |
| 10489 | * is drawn onto an offscren {@link android.graphics.Bitmap} and its |
| 10490 | * window is hardware accelerated, |
| 10491 | * {@link android.graphics.Canvas#isHardwareAccelerated()} will likely |
| 10492 | * return false, and this method will return true.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10493 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 10494 | * @return True if the view is attached to a window and the window is |
| 10495 | * hardware accelerated; false in any other case. |
| 10496 | */ |
| 10497 | public boolean isHardwareAccelerated() { |
| 10498 | return mAttachInfo != null && mAttachInfo.mHardwareAccelerated; |
| 10499 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10500 | |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 10501 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10502 | * Manually render this view (and all of its children) to the given Canvas. |
| 10503 | * 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] | 10504 | * called. When implementing a view, implement |
| 10505 | * {@link #onDraw(android.graphics.Canvas)} instead of overriding this method. |
| 10506 | * 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] | 10507 | * |
| 10508 | * @param canvas The Canvas to which the View is rendered. |
| 10509 | */ |
| 10510 | public void draw(Canvas canvas) { |
| 10511 | if (ViewDebug.TRACE_HIERARCHY) { |
| 10512 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW); |
| 10513 | } |
| 10514 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10515 | final int privateFlags = mPrivateFlags; |
| 10516 | final boolean dirtyOpaque = (privateFlags & DIRTY_MASK) == DIRTY_OPAQUE && |
| 10517 | (mAttachInfo == null || !mAttachInfo.mIgnoreDirtyState); |
| 10518 | mPrivateFlags = (privateFlags & ~DIRTY_MASK) | DRAWN; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10520 | /* |
| 10521 | * Draw traversal performs several drawing steps which must be executed |
| 10522 | * in the appropriate order: |
| 10523 | * |
| 10524 | * 1. Draw the background |
| 10525 | * 2. If necessary, save the canvas' layers to prepare for fading |
| 10526 | * 3. Draw view's content |
| 10527 | * 4. Draw children |
| 10528 | * 5. If necessary, draw the fading edges and restore layers |
| 10529 | * 6. Draw decorations (scrollbars for instance) |
| 10530 | */ |
| 10531 | |
| 10532 | // Step 1, draw the background, if needed |
| 10533 | int saveCount; |
| 10534 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10535 | if (!dirtyOpaque) { |
| 10536 | final Drawable background = mBGDrawable; |
| 10537 | if (background != null) { |
| 10538 | final int scrollX = mScrollX; |
| 10539 | final int scrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10540 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10541 | if (mBackgroundSizeChanged) { |
| 10542 | background.setBounds(0, 0, mRight - mLeft, mBottom - mTop); |
| 10543 | mBackgroundSizeChanged = false; |
| 10544 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10545 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10546 | if ((scrollX | scrollY) == 0) { |
| 10547 | background.draw(canvas); |
| 10548 | } else { |
| 10549 | canvas.translate(scrollX, scrollY); |
| 10550 | background.draw(canvas); |
| 10551 | canvas.translate(-scrollX, -scrollY); |
| 10552 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10553 | } |
| 10554 | } |
| 10555 | |
| 10556 | // skip step 2 & 5 if possible (common case) |
| 10557 | final int viewFlags = mViewFlags; |
| 10558 | boolean horizontalEdges = (viewFlags & FADING_EDGE_HORIZONTAL) != 0; |
| 10559 | boolean verticalEdges = (viewFlags & FADING_EDGE_VERTICAL) != 0; |
| 10560 | if (!verticalEdges && !horizontalEdges) { |
| 10561 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10562 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10563 | |
| 10564 | // Step 4, draw the children |
| 10565 | dispatchDraw(canvas); |
| 10566 | |
| 10567 | // Step 6, draw decorations (scrollbars) |
| 10568 | onDrawScrollBars(canvas); |
| 10569 | |
| 10570 | // we're done... |
| 10571 | return; |
| 10572 | } |
| 10573 | |
| 10574 | /* |
| 10575 | * Here we do the full fledged routine... |
| 10576 | * (this is an uncommon case where speed matters less, |
| 10577 | * this is why we repeat some of the tests that have been |
| 10578 | * done above) |
| 10579 | */ |
| 10580 | |
| 10581 | boolean drawTop = false; |
| 10582 | boolean drawBottom = false; |
| 10583 | boolean drawLeft = false; |
| 10584 | boolean drawRight = false; |
| 10585 | |
| 10586 | float topFadeStrength = 0.0f; |
| 10587 | float bottomFadeStrength = 0.0f; |
| 10588 | float leftFadeStrength = 0.0f; |
| 10589 | float rightFadeStrength = 0.0f; |
| 10590 | |
| 10591 | // Step 2, save the canvas' layers |
| 10592 | int paddingLeft = mPaddingLeft; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10593 | |
| 10594 | final boolean offsetRequired = isPaddingOffsetRequired(); |
| 10595 | if (offsetRequired) { |
| 10596 | paddingLeft += getLeftPaddingOffset(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10597 | } |
| 10598 | |
| 10599 | int left = mScrollX + paddingLeft; |
| 10600 | int right = left + mRight - mLeft - mPaddingRight - paddingLeft; |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 10601 | int top = mScrollY + getFadeTop(offsetRequired); |
| 10602 | int bottom = top + getFadeHeight(offsetRequired); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10603 | |
| 10604 | if (offsetRequired) { |
| 10605 | right += getRightPaddingOffset(); |
| 10606 | bottom += getBottomPaddingOffset(); |
| 10607 | } |
| 10608 | |
| 10609 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 10610 | final float fadeHeight = scrollabilityCache.fadingEdgeLength; |
| 10611 | int length = (int) fadeHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10612 | |
| 10613 | // clip the fade length if top and bottom fades overlap |
| 10614 | // overlapping fades produce odd-looking artifacts |
| 10615 | if (verticalEdges && (top + length > bottom - length)) { |
| 10616 | length = (bottom - top) / 2; |
| 10617 | } |
| 10618 | |
| 10619 | // also clip horizontal fades if necessary |
| 10620 | if (horizontalEdges && (left + length > right - length)) { |
| 10621 | length = (right - left) / 2; |
| 10622 | } |
| 10623 | |
| 10624 | if (verticalEdges) { |
| 10625 | topFadeStrength = Math.max(0.0f, Math.min(1.0f, getTopFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 10626 | drawTop = topFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10627 | bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, getBottomFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 10628 | drawBottom = bottomFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10629 | } |
| 10630 | |
| 10631 | if (horizontalEdges) { |
| 10632 | leftFadeStrength = Math.max(0.0f, Math.min(1.0f, getLeftFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 10633 | drawLeft = leftFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10634 | rightFadeStrength = Math.max(0.0f, Math.min(1.0f, getRightFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 10635 | drawRight = rightFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10636 | } |
| 10637 | |
| 10638 | saveCount = canvas.getSaveCount(); |
| 10639 | |
| 10640 | int solidColor = getSolidColor(); |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 10641 | if (solidColor == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10642 | final int flags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
| 10643 | |
| 10644 | if (drawTop) { |
| 10645 | canvas.saveLayer(left, top, right, top + length, null, flags); |
| 10646 | } |
| 10647 | |
| 10648 | if (drawBottom) { |
| 10649 | canvas.saveLayer(left, bottom - length, right, bottom, null, flags); |
| 10650 | } |
| 10651 | |
| 10652 | if (drawLeft) { |
| 10653 | canvas.saveLayer(left, top, left + length, bottom, null, flags); |
| 10654 | } |
| 10655 | |
| 10656 | if (drawRight) { |
| 10657 | canvas.saveLayer(right - length, top, right, bottom, null, flags); |
| 10658 | } |
| 10659 | } else { |
| 10660 | scrollabilityCache.setFadeColor(solidColor); |
| 10661 | } |
| 10662 | |
| 10663 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10664 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10665 | |
| 10666 | // Step 4, draw the children |
| 10667 | dispatchDraw(canvas); |
| 10668 | |
| 10669 | // Step 5, draw the fade effect and restore layers |
| 10670 | final Paint p = scrollabilityCache.paint; |
| 10671 | final Matrix matrix = scrollabilityCache.matrix; |
| 10672 | final Shader fade = scrollabilityCache.shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10673 | |
| 10674 | if (drawTop) { |
| 10675 | matrix.setScale(1, fadeHeight * topFadeStrength); |
| 10676 | matrix.postTranslate(left, top); |
| 10677 | fade.setLocalMatrix(matrix); |
| 10678 | canvas.drawRect(left, top, right, top + length, p); |
| 10679 | } |
| 10680 | |
| 10681 | if (drawBottom) { |
| 10682 | matrix.setScale(1, fadeHeight * bottomFadeStrength); |
| 10683 | matrix.postRotate(180); |
| 10684 | matrix.postTranslate(left, bottom); |
| 10685 | fade.setLocalMatrix(matrix); |
| 10686 | canvas.drawRect(left, bottom - length, right, bottom, p); |
| 10687 | } |
| 10688 | |
| 10689 | if (drawLeft) { |
| 10690 | matrix.setScale(1, fadeHeight * leftFadeStrength); |
| 10691 | matrix.postRotate(-90); |
| 10692 | matrix.postTranslate(left, top); |
| 10693 | fade.setLocalMatrix(matrix); |
| 10694 | canvas.drawRect(left, top, left + length, bottom, p); |
| 10695 | } |
| 10696 | |
| 10697 | if (drawRight) { |
| 10698 | matrix.setScale(1, fadeHeight * rightFadeStrength); |
| 10699 | matrix.postRotate(90); |
| 10700 | matrix.postTranslate(right, top); |
| 10701 | fade.setLocalMatrix(matrix); |
| 10702 | canvas.drawRect(right - length, top, right, bottom, p); |
| 10703 | } |
| 10704 | |
| 10705 | canvas.restoreToCount(saveCount); |
| 10706 | |
| 10707 | // Step 6, draw decorations (scrollbars) |
| 10708 | onDrawScrollBars(canvas); |
| 10709 | } |
| 10710 | |
| 10711 | /** |
| 10712 | * Override this if your view is known to always be drawn on top of a solid color background, |
| 10713 | * and needs to draw fading edges. Returning a non-zero color enables the view system to |
| 10714 | * optimize the drawing of the fading edges. If you do return a non-zero color, the alpha |
| 10715 | * should be set to 0xFF. |
| 10716 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10717 | * @see #setVerticalFadingEdgeEnabled(boolean) |
| 10718 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10719 | * |
| 10720 | * @return The known solid color background for this view, or 0 if the color may vary |
| 10721 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 10722 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10723 | public int getSolidColor() { |
| 10724 | return 0; |
| 10725 | } |
| 10726 | |
| 10727 | /** |
| 10728 | * Build a human readable string representation of the specified view flags. |
| 10729 | * |
| 10730 | * @param flags the view flags to convert to a string |
| 10731 | * @return a String representing the supplied flags |
| 10732 | */ |
| 10733 | private static String printFlags(int flags) { |
| 10734 | String output = ""; |
| 10735 | int numFlags = 0; |
| 10736 | if ((flags & FOCUSABLE_MASK) == FOCUSABLE) { |
| 10737 | output += "TAKES_FOCUS"; |
| 10738 | numFlags++; |
| 10739 | } |
| 10740 | |
| 10741 | switch (flags & VISIBILITY_MASK) { |
| 10742 | case INVISIBLE: |
| 10743 | if (numFlags > 0) { |
| 10744 | output += " "; |
| 10745 | } |
| 10746 | output += "INVISIBLE"; |
| 10747 | // USELESS HERE numFlags++; |
| 10748 | break; |
| 10749 | case GONE: |
| 10750 | if (numFlags > 0) { |
| 10751 | output += " "; |
| 10752 | } |
| 10753 | output += "GONE"; |
| 10754 | // USELESS HERE numFlags++; |
| 10755 | break; |
| 10756 | default: |
| 10757 | break; |
| 10758 | } |
| 10759 | return output; |
| 10760 | } |
| 10761 | |
| 10762 | /** |
| 10763 | * Build a human readable string representation of the specified private |
| 10764 | * view flags. |
| 10765 | * |
| 10766 | * @param privateFlags the private view flags to convert to a string |
| 10767 | * @return a String representing the supplied flags |
| 10768 | */ |
| 10769 | private static String printPrivateFlags(int privateFlags) { |
| 10770 | String output = ""; |
| 10771 | int numFlags = 0; |
| 10772 | |
| 10773 | if ((privateFlags & WANTS_FOCUS) == WANTS_FOCUS) { |
| 10774 | output += "WANTS_FOCUS"; |
| 10775 | numFlags++; |
| 10776 | } |
| 10777 | |
| 10778 | if ((privateFlags & FOCUSED) == FOCUSED) { |
| 10779 | if (numFlags > 0) { |
| 10780 | output += " "; |
| 10781 | } |
| 10782 | output += "FOCUSED"; |
| 10783 | numFlags++; |
| 10784 | } |
| 10785 | |
| 10786 | if ((privateFlags & SELECTED) == SELECTED) { |
| 10787 | if (numFlags > 0) { |
| 10788 | output += " "; |
| 10789 | } |
| 10790 | output += "SELECTED"; |
| 10791 | numFlags++; |
| 10792 | } |
| 10793 | |
| 10794 | if ((privateFlags & IS_ROOT_NAMESPACE) == IS_ROOT_NAMESPACE) { |
| 10795 | if (numFlags > 0) { |
| 10796 | output += " "; |
| 10797 | } |
| 10798 | output += "IS_ROOT_NAMESPACE"; |
| 10799 | numFlags++; |
| 10800 | } |
| 10801 | |
| 10802 | if ((privateFlags & HAS_BOUNDS) == HAS_BOUNDS) { |
| 10803 | if (numFlags > 0) { |
| 10804 | output += " "; |
| 10805 | } |
| 10806 | output += "HAS_BOUNDS"; |
| 10807 | numFlags++; |
| 10808 | } |
| 10809 | |
| 10810 | if ((privateFlags & DRAWN) == DRAWN) { |
| 10811 | if (numFlags > 0) { |
| 10812 | output += " "; |
| 10813 | } |
| 10814 | output += "DRAWN"; |
| 10815 | // USELESS HERE numFlags++; |
| 10816 | } |
| 10817 | return output; |
| 10818 | } |
| 10819 | |
| 10820 | /** |
| 10821 | * <p>Indicates whether or not this view's layout will be requested during |
| 10822 | * the next hierarchy layout pass.</p> |
| 10823 | * |
| 10824 | * @return true if the layout will be forced during next layout pass |
| 10825 | */ |
| 10826 | public boolean isLayoutRequested() { |
| 10827 | return (mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT; |
| 10828 | } |
| 10829 | |
| 10830 | /** |
| 10831 | * Assign a size and position to a view and all of its |
| 10832 | * descendants |
| 10833 | * |
| 10834 | * <p>This is the second phase of the layout mechanism. |
| 10835 | * (The first is measuring). In this phase, each parent calls |
| 10836 | * layout on all of its children to position them. |
| 10837 | * This is typically done using the child measurements |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 10838 | * that were stored in the measure pass().</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10839 | * |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 10840 | * <p>Derived classes should not override this method. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10841 | * Derived classes with children should override |
| 10842 | * onLayout. In that method, they should |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 10843 | * call layout on each of their children.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10844 | * |
| 10845 | * @param l Left position, relative to parent |
| 10846 | * @param t Top position, relative to parent |
| 10847 | * @param r Right position, relative to parent |
| 10848 | * @param b Bottom position, relative to parent |
| 10849 | */ |
Romain Guy | 5429e1d | 2010-09-07 12:38:00 -0700 | [diff] [blame] | 10850 | @SuppressWarnings({"unchecked"}) |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 10851 | public void layout(int l, int t, int r, int b) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 10852 | int oldL = mLeft; |
| 10853 | int oldT = mTop; |
| 10854 | int oldB = mBottom; |
| 10855 | int oldR = mRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10856 | boolean changed = setFrame(l, t, r, b); |
| 10857 | if (changed || (mPrivateFlags & LAYOUT_REQUIRED) == LAYOUT_REQUIRED) { |
| 10858 | if (ViewDebug.TRACE_HIERARCHY) { |
| 10859 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_LAYOUT); |
| 10860 | } |
| 10861 | |
| 10862 | onLayout(changed, l, t, r, b); |
| 10863 | mPrivateFlags &= ~LAYOUT_REQUIRED; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 10864 | |
| 10865 | if (mOnLayoutChangeListeners != null) { |
| 10866 | ArrayList<OnLayoutChangeListener> listenersCopy = |
| 10867 | (ArrayList<OnLayoutChangeListener>) mOnLayoutChangeListeners.clone(); |
| 10868 | int numListeners = listenersCopy.size(); |
| 10869 | for (int i = 0; i < numListeners; ++i) { |
Chet Haase | 7c608f2 | 2010-10-22 17:54:04 -0700 | [diff] [blame] | 10870 | 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] | 10871 | } |
| 10872 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10873 | } |
| 10874 | mPrivateFlags &= ~FORCE_LAYOUT; |
| 10875 | } |
| 10876 | |
| 10877 | /** |
| 10878 | * Called from layout when this view should |
| 10879 | * assign a size and position to each of its children. |
| 10880 | * |
| 10881 | * Derived classes with children should override |
| 10882 | * this method and call layout on each of |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 10883 | * their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10884 | * @param changed This is a new size or position for this view |
| 10885 | * @param left Left position, relative to parent |
| 10886 | * @param top Top position, relative to parent |
| 10887 | * @param right Right position, relative to parent |
| 10888 | * @param bottom Bottom position, relative to parent |
| 10889 | */ |
| 10890 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 10891 | } |
| 10892 | |
| 10893 | /** |
| 10894 | * Assign a size and position to this view. |
| 10895 | * |
| 10896 | * This is called from layout. |
| 10897 | * |
| 10898 | * @param left Left position, relative to parent |
| 10899 | * @param top Top position, relative to parent |
| 10900 | * @param right Right position, relative to parent |
| 10901 | * @param bottom Bottom position, relative to parent |
| 10902 | * @return true if the new size and position are different than the |
| 10903 | * previous ones |
| 10904 | * {@hide} |
| 10905 | */ |
| 10906 | protected boolean setFrame(int left, int top, int right, int bottom) { |
| 10907 | boolean changed = false; |
| 10908 | |
| 10909 | if (DBG) { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 10910 | Log.d("View", this + " View.setFrame(" + left + "," + top + "," |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10911 | + right + "," + bottom + ")"); |
| 10912 | } |
| 10913 | |
| 10914 | if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) { |
| 10915 | changed = true; |
| 10916 | |
| 10917 | // Remember our drawn bit |
| 10918 | int drawn = mPrivateFlags & DRAWN; |
| 10919 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10920 | int oldWidth = mRight - mLeft; |
| 10921 | int oldHeight = mBottom - mTop; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 10922 | int newWidth = right - left; |
| 10923 | int newHeight = bottom - top; |
| 10924 | boolean sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight); |
| 10925 | |
| 10926 | // Invalidate our old position |
| 10927 | invalidate(sizeChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10928 | |
| 10929 | mLeft = left; |
| 10930 | mTop = top; |
| 10931 | mRight = right; |
| 10932 | mBottom = bottom; |
| 10933 | |
| 10934 | mPrivateFlags |= HAS_BOUNDS; |
| 10935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10936 | |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 10937 | if (sizeChanged) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 10938 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 10939 | // A change in dimension means an auto-centered pivot point changes, too |
| 10940 | mMatrixDirty = true; |
| 10941 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10942 | onSizeChanged(newWidth, newHeight, oldWidth, oldHeight); |
| 10943 | } |
| 10944 | |
| 10945 | if ((mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 10946 | // If we are visible, force the DRAWN bit to on so that |
| 10947 | // this invalidate will go through (at least to our parent). |
| 10948 | // This is because someone may have invalidated this view |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 10949 | // before this call to setFrame came in, thereby clearing |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10950 | // the DRAWN bit. |
| 10951 | mPrivateFlags |= DRAWN; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 10952 | invalidate(sizeChanged); |
Chet Haase | f28595e | 2011-01-31 18:52:12 -0800 | [diff] [blame] | 10953 | // parent display list may need to be recreated based on a change in the bounds |
| 10954 | // of any child |
| 10955 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10956 | } |
| 10957 | |
| 10958 | // Reset drawn bit to original value (invalidate turns it off) |
| 10959 | mPrivateFlags |= drawn; |
| 10960 | |
| 10961 | mBackgroundSizeChanged = true; |
| 10962 | } |
| 10963 | return changed; |
| 10964 | } |
| 10965 | |
| 10966 | /** |
| 10967 | * Finalize inflating a view from XML. This is called as the last phase |
| 10968 | * of inflation, after all child views have been added. |
| 10969 | * |
| 10970 | * <p>Even if the subclass overrides onFinishInflate, they should always be |
| 10971 | * sure to call the super method, so that we get called. |
| 10972 | */ |
| 10973 | protected void onFinishInflate() { |
| 10974 | } |
| 10975 | |
| 10976 | /** |
| 10977 | * Returns the resources associated with this view. |
| 10978 | * |
| 10979 | * @return Resources object. |
| 10980 | */ |
| 10981 | public Resources getResources() { |
| 10982 | return mResources; |
| 10983 | } |
| 10984 | |
| 10985 | /** |
| 10986 | * Invalidates the specified Drawable. |
| 10987 | * |
| 10988 | * @param drawable the drawable to invalidate |
| 10989 | */ |
| 10990 | public void invalidateDrawable(Drawable drawable) { |
| 10991 | if (verifyDrawable(drawable)) { |
| 10992 | final Rect dirty = drawable.getBounds(); |
| 10993 | final int scrollX = mScrollX; |
| 10994 | final int scrollY = mScrollY; |
| 10995 | |
| 10996 | invalidate(dirty.left + scrollX, dirty.top + scrollY, |
| 10997 | dirty.right + scrollX, dirty.bottom + scrollY); |
| 10998 | } |
| 10999 | } |
| 11000 | |
| 11001 | /** |
| 11002 | * Schedules an action on a drawable to occur at a specified time. |
| 11003 | * |
| 11004 | * @param who the recipient of the action |
| 11005 | * @param what the action to run on the drawable |
| 11006 | * @param when the time at which the action must occur. Uses the |
| 11007 | * {@link SystemClock#uptimeMillis} timebase. |
| 11008 | */ |
| 11009 | public void scheduleDrawable(Drawable who, Runnable what, long when) { |
| 11010 | if (verifyDrawable(who) && what != null && mAttachInfo != null) { |
| 11011 | mAttachInfo.mHandler.postAtTime(what, who, when); |
| 11012 | } |
| 11013 | } |
| 11014 | |
| 11015 | /** |
| 11016 | * Cancels a scheduled action on a drawable. |
| 11017 | * |
| 11018 | * @param who the recipient of the action |
| 11019 | * @param what the action to cancel |
| 11020 | */ |
| 11021 | public void unscheduleDrawable(Drawable who, Runnable what) { |
| 11022 | if (verifyDrawable(who) && what != null && mAttachInfo != null) { |
| 11023 | mAttachInfo.mHandler.removeCallbacks(what, who); |
| 11024 | } |
| 11025 | } |
| 11026 | |
| 11027 | /** |
| 11028 | * Unschedule any events associated with the given Drawable. This can be |
| 11029 | * used when selecting a new Drawable into a view, so that the previous |
| 11030 | * one is completely unscheduled. |
| 11031 | * |
| 11032 | * @param who The Drawable to unschedule. |
| 11033 | * |
| 11034 | * @see #drawableStateChanged |
| 11035 | */ |
| 11036 | public void unscheduleDrawable(Drawable who) { |
| 11037 | if (mAttachInfo != null) { |
| 11038 | mAttachInfo.mHandler.removeCallbacksAndMessages(who); |
| 11039 | } |
| 11040 | } |
| 11041 | |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 11042 | /** |
| 11043 | * Return the layout direction of a given Drawable. |
| 11044 | * |
| 11045 | * @param who the Drawable to query |
| 11046 | * |
| 11047 | * @hide |
| 11048 | */ |
| 11049 | public int getResolvedLayoutDirection(Drawable who) { |
| 11050 | return (who == mBGDrawable) ? getResolvedLayoutDirection() : LAYOUT_DIRECTION_DEFAULT; |
Fabrice Di Meglio | 6a03640 | 2011-05-23 14:43:23 -0700 | [diff] [blame] | 11051 | } |
| 11052 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11053 | /** |
| 11054 | * If your view subclass is displaying its own Drawable objects, it should |
| 11055 | * override this function and return true for any Drawable it is |
| 11056 | * displaying. This allows animations for those drawables to be |
| 11057 | * scheduled. |
| 11058 | * |
| 11059 | * <p>Be sure to call through to the super class when overriding this |
| 11060 | * function. |
| 11061 | * |
| 11062 | * @param who The Drawable to verify. Return true if it is one you are |
| 11063 | * displaying, else return the result of calling through to the |
| 11064 | * super class. |
| 11065 | * |
| 11066 | * @return boolean If true than the Drawable is being displayed in the |
| 11067 | * view; else false and it is not allowed to animate. |
| 11068 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11069 | * @see #unscheduleDrawable(android.graphics.drawable.Drawable) |
| 11070 | * @see #drawableStateChanged() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11071 | */ |
| 11072 | protected boolean verifyDrawable(Drawable who) { |
| 11073 | return who == mBGDrawable; |
| 11074 | } |
| 11075 | |
| 11076 | /** |
| 11077 | * This function is called whenever the state of the view changes in such |
| 11078 | * a way that it impacts the state of drawables being shown. |
| 11079 | * |
| 11080 | * <p>Be sure to call through to the superclass when overriding this |
| 11081 | * function. |
| 11082 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11083 | * @see Drawable#setState(int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11084 | */ |
| 11085 | protected void drawableStateChanged() { |
| 11086 | Drawable d = mBGDrawable; |
| 11087 | if (d != null && d.isStateful()) { |
| 11088 | d.setState(getDrawableState()); |
| 11089 | } |
| 11090 | } |
| 11091 | |
| 11092 | /** |
| 11093 | * Call this to force a view to update its drawable state. This will cause |
| 11094 | * drawableStateChanged to be called on this view. Views that are interested |
| 11095 | * in the new state should call getDrawableState. |
| 11096 | * |
| 11097 | * @see #drawableStateChanged |
| 11098 | * @see #getDrawableState |
| 11099 | */ |
| 11100 | public void refreshDrawableState() { |
| 11101 | mPrivateFlags |= DRAWABLE_STATE_DIRTY; |
| 11102 | drawableStateChanged(); |
| 11103 | |
| 11104 | ViewParent parent = mParent; |
| 11105 | if (parent != null) { |
| 11106 | parent.childDrawableStateChanged(this); |
| 11107 | } |
| 11108 | } |
| 11109 | |
| 11110 | /** |
| 11111 | * Return an array of resource IDs of the drawable states representing the |
| 11112 | * current state of the view. |
| 11113 | * |
| 11114 | * @return The current drawable state |
| 11115 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11116 | * @see Drawable#setState(int[]) |
| 11117 | * @see #drawableStateChanged() |
| 11118 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11119 | */ |
| 11120 | public final int[] getDrawableState() { |
| 11121 | if ((mDrawableState != null) && ((mPrivateFlags & DRAWABLE_STATE_DIRTY) == 0)) { |
| 11122 | return mDrawableState; |
| 11123 | } else { |
| 11124 | mDrawableState = onCreateDrawableState(0); |
| 11125 | mPrivateFlags &= ~DRAWABLE_STATE_DIRTY; |
| 11126 | return mDrawableState; |
| 11127 | } |
| 11128 | } |
| 11129 | |
| 11130 | /** |
| 11131 | * Generate the new {@link android.graphics.drawable.Drawable} state for |
| 11132 | * this view. This is called by the view |
| 11133 | * system when the cached Drawable state is determined to be invalid. To |
| 11134 | * retrieve the current state, you should use {@link #getDrawableState}. |
| 11135 | * |
| 11136 | * @param extraSpace if non-zero, this is the number of extra entries you |
| 11137 | * would like in the returned array in which you can place your own |
| 11138 | * states. |
| 11139 | * |
| 11140 | * @return Returns an array holding the current {@link Drawable} state of |
| 11141 | * the view. |
| 11142 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11143 | * @see #mergeDrawableStates(int[], int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11144 | */ |
| 11145 | protected int[] onCreateDrawableState(int extraSpace) { |
| 11146 | if ((mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE && |
| 11147 | mParent instanceof View) { |
| 11148 | return ((View) mParent).onCreateDrawableState(extraSpace); |
| 11149 | } |
| 11150 | |
| 11151 | int[] drawableState; |
| 11152 | |
| 11153 | int privateFlags = mPrivateFlags; |
| 11154 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 11155 | int viewStateIndex = 0; |
| 11156 | if ((privateFlags & PRESSED) != 0) viewStateIndex |= VIEW_STATE_PRESSED; |
| 11157 | if ((mViewFlags & ENABLED_MASK) == ENABLED) viewStateIndex |= VIEW_STATE_ENABLED; |
| 11158 | if (isFocused()) viewStateIndex |= VIEW_STATE_FOCUSED; |
Neel Parekh | e537858 | 2010-10-06 11:36:50 -0700 | [diff] [blame] | 11159 | if ((privateFlags & SELECTED) != 0) viewStateIndex |= VIEW_STATE_SELECTED; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 11160 | if (hasWindowFocus()) viewStateIndex |= VIEW_STATE_WINDOW_FOCUSED; |
| 11161 | if ((privateFlags & ACTIVATED) != 0) viewStateIndex |= VIEW_STATE_ACTIVATED; |
Adam Powell | 5a7e94e | 2011-04-25 15:30:43 -0700 | [diff] [blame] | 11162 | if (mAttachInfo != null && mAttachInfo.mHardwareAccelerationRequested && |
| 11163 | HardwareRenderer.isAvailable()) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 11164 | // This is set if HW acceleration is requested, even if the current |
| 11165 | // process doesn't allow it. This is just to allow app preview |
| 11166 | // windows to better match their app. |
| 11167 | viewStateIndex |= VIEW_STATE_ACCELERATED; |
| 11168 | } |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 11169 | if ((privateFlags & HOVERED) != 0) viewStateIndex |= VIEW_STATE_HOVERED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11170 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 11171 | final int privateFlags2 = mPrivateFlags2; |
| 11172 | if ((privateFlags2 & DRAG_CAN_ACCEPT) != 0) viewStateIndex |= VIEW_STATE_DRAG_CAN_ACCEPT; |
| 11173 | if ((privateFlags2 & DRAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_DRAG_HOVERED; |
| 11174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11175 | drawableState = VIEW_STATE_SETS[viewStateIndex]; |
| 11176 | |
| 11177 | //noinspection ConstantIfStatement |
| 11178 | if (false) { |
| 11179 | Log.i("View", "drawableStateIndex=" + viewStateIndex); |
| 11180 | Log.i("View", toString() |
| 11181 | + " pressed=" + ((privateFlags & PRESSED) != 0) |
| 11182 | + " en=" + ((mViewFlags & ENABLED_MASK) == ENABLED) |
| 11183 | + " fo=" + hasFocus() |
| 11184 | + " sl=" + ((privateFlags & SELECTED) != 0) |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 11185 | + " wf=" + hasWindowFocus() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11186 | + ": " + Arrays.toString(drawableState)); |
| 11187 | } |
| 11188 | |
| 11189 | if (extraSpace == 0) { |
| 11190 | return drawableState; |
| 11191 | } |
| 11192 | |
| 11193 | final int[] fullState; |
| 11194 | if (drawableState != null) { |
| 11195 | fullState = new int[drawableState.length + extraSpace]; |
| 11196 | System.arraycopy(drawableState, 0, fullState, 0, drawableState.length); |
| 11197 | } else { |
| 11198 | fullState = new int[extraSpace]; |
| 11199 | } |
| 11200 | |
| 11201 | return fullState; |
| 11202 | } |
| 11203 | |
| 11204 | /** |
| 11205 | * Merge your own state values in <var>additionalState</var> into the base |
| 11206 | * state values <var>baseState</var> that were returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11207 | * {@link #onCreateDrawableState(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11208 | * |
| 11209 | * @param baseState The base state values returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11210 | * {@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] | 11211 | * own additional state values. |
| 11212 | * |
| 11213 | * @param additionalState The additional state values you would like |
| 11214 | * added to <var>baseState</var>; this array is not modified. |
| 11215 | * |
| 11216 | * @return As a convenience, the <var>baseState</var> array you originally |
| 11217 | * passed into the function is returned. |
| 11218 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11219 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11220 | */ |
| 11221 | protected static int[] mergeDrawableStates(int[] baseState, int[] additionalState) { |
| 11222 | final int N = baseState.length; |
| 11223 | int i = N - 1; |
| 11224 | while (i >= 0 && baseState[i] == 0) { |
| 11225 | i--; |
| 11226 | } |
| 11227 | System.arraycopy(additionalState, 0, baseState, i + 1, additionalState.length); |
| 11228 | return baseState; |
| 11229 | } |
| 11230 | |
| 11231 | /** |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 11232 | * Call {@link Drawable#jumpToCurrentState() Drawable.jumpToCurrentState()} |
| 11233 | * on all Drawable objects associated with this view. |
| 11234 | */ |
| 11235 | public void jumpDrawablesToCurrentState() { |
| 11236 | if (mBGDrawable != null) { |
| 11237 | mBGDrawable.jumpToCurrentState(); |
| 11238 | } |
| 11239 | } |
| 11240 | |
| 11241 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11242 | * Sets the background color for this view. |
| 11243 | * @param color the color of the background |
| 11244 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 11245 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11246 | public void setBackgroundColor(int color) { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 11247 | if (mBGDrawable instanceof ColorDrawable) { |
| 11248 | ((ColorDrawable) mBGDrawable).setColor(color); |
| 11249 | } else { |
| 11250 | setBackgroundDrawable(new ColorDrawable(color)); |
| 11251 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11252 | } |
| 11253 | |
| 11254 | /** |
| 11255 | * Set the background to a given resource. The resource should refer to |
Wink Saville | 7cd88e1 | 2009-08-04 14:45:10 -0700 | [diff] [blame] | 11256 | * a Drawable object or 0 to remove the background. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11257 | * @param resid The identifier of the resource. |
| 11258 | * @attr ref android.R.styleable#View_background |
| 11259 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 11260 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11261 | public void setBackgroundResource(int resid) { |
| 11262 | if (resid != 0 && resid == mBackgroundResource) { |
| 11263 | return; |
| 11264 | } |
| 11265 | |
| 11266 | Drawable d= null; |
| 11267 | if (resid != 0) { |
| 11268 | d = mResources.getDrawable(resid); |
| 11269 | } |
| 11270 | setBackgroundDrawable(d); |
| 11271 | |
| 11272 | mBackgroundResource = resid; |
| 11273 | } |
| 11274 | |
| 11275 | /** |
| 11276 | * Set the background to a given Drawable, or remove the background. If the |
| 11277 | * background has padding, this View's padding is set to the background's |
| 11278 | * padding. However, when a background is removed, this View's padding isn't |
| 11279 | * touched. If setting the padding is desired, please use |
| 11280 | * {@link #setPadding(int, int, int, int)}. |
| 11281 | * |
| 11282 | * @param d The Drawable to use as the background, or null to remove the |
| 11283 | * background |
| 11284 | */ |
| 11285 | public void setBackgroundDrawable(Drawable d) { |
Adam Powell | 4d36ec1 | 2011-07-17 16:44:16 -0700 | [diff] [blame] | 11286 | if (d == mBGDrawable) { |
| 11287 | return; |
| 11288 | } |
| 11289 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11290 | boolean requestLayout = false; |
| 11291 | |
| 11292 | mBackgroundResource = 0; |
| 11293 | |
| 11294 | /* |
| 11295 | * Regardless of whether we're setting a new background or not, we want |
| 11296 | * to clear the previous drawable. |
| 11297 | */ |
| 11298 | if (mBGDrawable != null) { |
| 11299 | mBGDrawable.setCallback(null); |
| 11300 | unscheduleDrawable(mBGDrawable); |
| 11301 | } |
| 11302 | |
| 11303 | if (d != null) { |
| 11304 | Rect padding = sThreadLocal.get(); |
| 11305 | if (padding == null) { |
| 11306 | padding = new Rect(); |
| 11307 | sThreadLocal.set(padding); |
| 11308 | } |
| 11309 | if (d.getPadding(padding)) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11310 | switch (d.getResolvedLayoutDirectionSelf()) { |
| 11311 | case LAYOUT_DIRECTION_RTL: |
| 11312 | setPadding(padding.right, padding.top, padding.left, padding.bottom); |
| 11313 | break; |
| 11314 | case LAYOUT_DIRECTION_LTR: |
| 11315 | default: |
| 11316 | setPadding(padding.left, padding.top, padding.right, padding.bottom); |
| 11317 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11318 | } |
| 11319 | |
| 11320 | // Compare the minimum sizes of the old Drawable and the new. If there isn't an old or |
| 11321 | // if it has a different minimum size, we should layout again |
| 11322 | if (mBGDrawable == null || mBGDrawable.getMinimumHeight() != d.getMinimumHeight() || |
| 11323 | mBGDrawable.getMinimumWidth() != d.getMinimumWidth()) { |
| 11324 | requestLayout = true; |
| 11325 | } |
| 11326 | |
| 11327 | d.setCallback(this); |
| 11328 | if (d.isStateful()) { |
| 11329 | d.setState(getDrawableState()); |
| 11330 | } |
| 11331 | d.setVisible(getVisibility() == VISIBLE, false); |
| 11332 | mBGDrawable = d; |
| 11333 | |
| 11334 | if ((mPrivateFlags & SKIP_DRAW) != 0) { |
| 11335 | mPrivateFlags &= ~SKIP_DRAW; |
| 11336 | mPrivateFlags |= ONLY_DRAWS_BACKGROUND; |
| 11337 | requestLayout = true; |
| 11338 | } |
| 11339 | } else { |
| 11340 | /* Remove the background */ |
| 11341 | mBGDrawable = null; |
| 11342 | |
| 11343 | if ((mPrivateFlags & ONLY_DRAWS_BACKGROUND) != 0) { |
| 11344 | /* |
| 11345 | * This view ONLY drew the background before and we're removing |
| 11346 | * the background, so now it won't draw anything |
| 11347 | * (hence we SKIP_DRAW) |
| 11348 | */ |
| 11349 | mPrivateFlags &= ~ONLY_DRAWS_BACKGROUND; |
| 11350 | mPrivateFlags |= SKIP_DRAW; |
| 11351 | } |
| 11352 | |
| 11353 | /* |
| 11354 | * When the background is set, we try to apply its padding to this |
| 11355 | * View. When the background is removed, we don't touch this View's |
| 11356 | * padding. This is noted in the Javadocs. Hence, we don't need to |
| 11357 | * requestLayout(), the invalidate() below is sufficient. |
| 11358 | */ |
| 11359 | |
| 11360 | // The old background's minimum size could have affected this |
| 11361 | // View's layout, so let's requestLayout |
| 11362 | requestLayout = true; |
| 11363 | } |
| 11364 | |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 11365 | computeOpaqueFlags(); |
| 11366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11367 | if (requestLayout) { |
| 11368 | requestLayout(); |
| 11369 | } |
| 11370 | |
| 11371 | mBackgroundSizeChanged = true; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 11372 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11373 | } |
| 11374 | |
| 11375 | /** |
| 11376 | * Gets the background drawable |
| 11377 | * @return The drawable used as the background for this view, if any. |
| 11378 | */ |
| 11379 | public Drawable getBackground() { |
| 11380 | return mBGDrawable; |
| 11381 | } |
| 11382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11383 | /** |
| 11384 | * Sets the padding. The view may add on the space required to display |
| 11385 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 11386 | * So the values returned from {@link #getPaddingLeft}, {@link #getPaddingTop}, |
| 11387 | * {@link #getPaddingRight} and {@link #getPaddingBottom} may be different |
| 11388 | * from the values set in this call. |
| 11389 | * |
| 11390 | * @attr ref android.R.styleable#View_padding |
| 11391 | * @attr ref android.R.styleable#View_paddingBottom |
| 11392 | * @attr ref android.R.styleable#View_paddingLeft |
| 11393 | * @attr ref android.R.styleable#View_paddingRight |
| 11394 | * @attr ref android.R.styleable#View_paddingTop |
| 11395 | * @param left the left padding in pixels |
| 11396 | * @param top the top padding in pixels |
| 11397 | * @param right the right padding in pixels |
| 11398 | * @param bottom the bottom padding in pixels |
| 11399 | */ |
| 11400 | public void setPadding(int left, int top, int right, int bottom) { |
| 11401 | boolean changed = false; |
| 11402 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11403 | mUserPaddingRelative = false; |
| 11404 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11405 | mUserPaddingLeft = left; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11406 | mUserPaddingRight = right; |
| 11407 | mUserPaddingBottom = bottom; |
| 11408 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11409 | final int viewFlags = mViewFlags; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11410 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11411 | // Common case is there are no scroll bars. |
| 11412 | if ((viewFlags & (SCROLLBARS_VERTICAL|SCROLLBARS_HORIZONTAL)) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11413 | if ((viewFlags & SCROLLBARS_VERTICAL) != 0) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11414 | final int offset = (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11415 | ? 0 : getVerticalScrollbarWidth(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11416 | switch (mVerticalScrollbarPosition) { |
| 11417 | case SCROLLBAR_POSITION_DEFAULT: |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11418 | if (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
| 11419 | left += offset; |
| 11420 | } else { |
| 11421 | right += offset; |
| 11422 | } |
| 11423 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11424 | case SCROLLBAR_POSITION_RIGHT: |
| 11425 | right += offset; |
| 11426 | break; |
| 11427 | case SCROLLBAR_POSITION_LEFT: |
| 11428 | left += offset; |
| 11429 | break; |
| 11430 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11431 | } |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11432 | if ((viewFlags & SCROLLBARS_HORIZONTAL) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11433 | bottom += (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
| 11434 | ? 0 : getHorizontalScrollbarHeight(); |
| 11435 | } |
| 11436 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11437 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11438 | if (mPaddingLeft != left) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11439 | changed = true; |
| 11440 | mPaddingLeft = left; |
| 11441 | } |
| 11442 | if (mPaddingTop != top) { |
| 11443 | changed = true; |
| 11444 | mPaddingTop = top; |
| 11445 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11446 | if (mPaddingRight != right) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11447 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11448 | mPaddingRight = right; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11449 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11450 | if (mPaddingBottom != bottom) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11451 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11452 | mPaddingBottom = bottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11453 | } |
| 11454 | |
| 11455 | if (changed) { |
| 11456 | requestLayout(); |
| 11457 | } |
| 11458 | } |
| 11459 | |
| 11460 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11461 | * Sets the relative padding. The view may add on the space required to display |
| 11462 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 11463 | * So the values returned from {@link #getPaddingStart}, {@link #getPaddingTop}, |
| 11464 | * {@link #getPaddingEnd} and {@link #getPaddingBottom} may be different |
| 11465 | * from the values set in this call. |
| 11466 | * |
| 11467 | * @attr ref android.R.styleable#View_padding |
| 11468 | * @attr ref android.R.styleable#View_paddingBottom |
| 11469 | * @attr ref android.R.styleable#View_paddingStart |
| 11470 | * @attr ref android.R.styleable#View_paddingEnd |
| 11471 | * @attr ref android.R.styleable#View_paddingTop |
| 11472 | * @param start the start padding in pixels |
| 11473 | * @param top the top padding in pixels |
| 11474 | * @param end the end padding in pixels |
| 11475 | * @param bottom the bottom padding in pixels |
| 11476 | * |
| 11477 | * @hide |
| 11478 | */ |
| 11479 | public void setPaddingRelative(int start, int top, int end, int bottom) { |
| 11480 | mUserPaddingRelative = true; |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 11481 | |
| 11482 | mUserPaddingStart = start; |
| 11483 | mUserPaddingEnd = end; |
| 11484 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11485 | switch(getResolvedLayoutDirection()) { |
| 11486 | case LAYOUT_DIRECTION_RTL: |
| 11487 | setPadding(end, top, start, bottom); |
| 11488 | break; |
| 11489 | case LAYOUT_DIRECTION_LTR: |
| 11490 | default: |
| 11491 | setPadding(start, top, end, bottom); |
| 11492 | } |
| 11493 | } |
| 11494 | |
| 11495 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11496 | * Returns the top padding of this view. |
| 11497 | * |
| 11498 | * @return the top padding in pixels |
| 11499 | */ |
| 11500 | public int getPaddingTop() { |
| 11501 | return mPaddingTop; |
| 11502 | } |
| 11503 | |
| 11504 | /** |
| 11505 | * Returns the bottom padding of this view. If there are inset and enabled |
| 11506 | * scrollbars, this value may include the space required to display the |
| 11507 | * scrollbars as well. |
| 11508 | * |
| 11509 | * @return the bottom padding in pixels |
| 11510 | */ |
| 11511 | public int getPaddingBottom() { |
| 11512 | return mPaddingBottom; |
| 11513 | } |
| 11514 | |
| 11515 | /** |
| 11516 | * Returns the left padding of this view. If there are inset and enabled |
| 11517 | * scrollbars, this value may include the space required to display the |
| 11518 | * scrollbars as well. |
| 11519 | * |
| 11520 | * @return the left padding in pixels |
| 11521 | */ |
| 11522 | public int getPaddingLeft() { |
| 11523 | return mPaddingLeft; |
| 11524 | } |
| 11525 | |
| 11526 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11527 | * Returns the start padding of this view. If there are inset and enabled |
| 11528 | * scrollbars, this value may include the space required to display the |
| 11529 | * scrollbars as well. |
| 11530 | * |
| 11531 | * @return the start padding in pixels |
| 11532 | * |
| 11533 | * @hide |
| 11534 | */ |
| 11535 | public int getPaddingStart() { |
| 11536 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
| 11537 | mPaddingRight : mPaddingLeft; |
| 11538 | } |
| 11539 | |
| 11540 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11541 | * Returns the right padding of this view. If there are inset and enabled |
| 11542 | * scrollbars, this value may include the space required to display the |
| 11543 | * scrollbars as well. |
| 11544 | * |
| 11545 | * @return the right padding in pixels |
| 11546 | */ |
| 11547 | public int getPaddingRight() { |
| 11548 | return mPaddingRight; |
| 11549 | } |
| 11550 | |
| 11551 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11552 | * Returns the end padding of this view. If there are inset and enabled |
| 11553 | * scrollbars, this value may include the space required to display the |
| 11554 | * scrollbars as well. |
| 11555 | * |
| 11556 | * @return the end padding in pixels |
| 11557 | * |
| 11558 | * @hide |
| 11559 | */ |
| 11560 | public int getPaddingEnd() { |
| 11561 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
| 11562 | mPaddingLeft : mPaddingRight; |
| 11563 | } |
| 11564 | |
| 11565 | /** |
| 11566 | * Return if the padding as been set thru relative values |
| 11567 | * {@link #setPaddingRelative(int, int, int, int)} or thru |
| 11568 | * @attr ref android.R.styleable#View_paddingStart or |
| 11569 | * @attr ref android.R.styleable#View_paddingEnd |
| 11570 | * |
| 11571 | * @return true if the padding is relative or false if it is not. |
| 11572 | * |
| 11573 | * @hide |
| 11574 | */ |
| 11575 | public boolean isPaddingRelative() { |
| 11576 | return mUserPaddingRelative; |
| 11577 | } |
| 11578 | |
| 11579 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11580 | * Changes the selection state of this view. A view can be selected or not. |
| 11581 | * Note that selection is not the same as focus. Views are typically |
| 11582 | * selected in the context of an AdapterView like ListView or GridView; |
| 11583 | * the selected view is the view that is highlighted. |
| 11584 | * |
| 11585 | * @param selected true if the view must be selected, false otherwise |
| 11586 | */ |
| 11587 | public void setSelected(boolean selected) { |
| 11588 | if (((mPrivateFlags & SELECTED) != 0) != selected) { |
| 11589 | mPrivateFlags = (mPrivateFlags & ~SELECTED) | (selected ? SELECTED : 0); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 11590 | if (!selected) resetPressedState(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 11591 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11592 | refreshDrawableState(); |
| 11593 | dispatchSetSelected(selected); |
| 11594 | } |
| 11595 | } |
| 11596 | |
| 11597 | /** |
| 11598 | * Dispatch setSelected to all of this View's children. |
| 11599 | * |
| 11600 | * @see #setSelected(boolean) |
| 11601 | * |
| 11602 | * @param selected The new selected state |
| 11603 | */ |
| 11604 | protected void dispatchSetSelected(boolean selected) { |
| 11605 | } |
| 11606 | |
| 11607 | /** |
| 11608 | * Indicates the selection state of this view. |
| 11609 | * |
| 11610 | * @return true if the view is selected, false otherwise |
| 11611 | */ |
| 11612 | @ViewDebug.ExportedProperty |
| 11613 | public boolean isSelected() { |
| 11614 | return (mPrivateFlags & SELECTED) != 0; |
| 11615 | } |
| 11616 | |
| 11617 | /** |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 11618 | * Changes the activated state of this view. A view can be activated or not. |
| 11619 | * Note that activation is not the same as selection. Selection is |
| 11620 | * a transient property, representing the view (hierarchy) the user is |
| 11621 | * currently interacting with. Activation is a longer-term state that the |
| 11622 | * user can move views in and out of. For example, in a list view with |
| 11623 | * single or multiple selection enabled, the views in the current selection |
| 11624 | * set are activated. (Um, yeah, we are deeply sorry about the terminology |
| 11625 | * here.) The activated state is propagated down to children of the view it |
| 11626 | * is set on. |
| 11627 | * |
| 11628 | * @param activated true if the view must be activated, false otherwise |
| 11629 | */ |
| 11630 | public void setActivated(boolean activated) { |
| 11631 | if (((mPrivateFlags & ACTIVATED) != 0) != activated) { |
| 11632 | mPrivateFlags = (mPrivateFlags & ~ACTIVATED) | (activated ? ACTIVATED : 0); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 11633 | invalidate(true); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 11634 | refreshDrawableState(); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 11635 | dispatchSetActivated(activated); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 11636 | } |
| 11637 | } |
| 11638 | |
| 11639 | /** |
| 11640 | * Dispatch setActivated to all of this View's children. |
| 11641 | * |
| 11642 | * @see #setActivated(boolean) |
| 11643 | * |
| 11644 | * @param activated The new activated state |
| 11645 | */ |
| 11646 | protected void dispatchSetActivated(boolean activated) { |
| 11647 | } |
| 11648 | |
| 11649 | /** |
| 11650 | * Indicates the activation state of this view. |
| 11651 | * |
| 11652 | * @return true if the view is activated, false otherwise |
| 11653 | */ |
| 11654 | @ViewDebug.ExportedProperty |
| 11655 | public boolean isActivated() { |
| 11656 | return (mPrivateFlags & ACTIVATED) != 0; |
| 11657 | } |
| 11658 | |
| 11659 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11660 | * Returns the ViewTreeObserver for this view's hierarchy. The view tree |
| 11661 | * observer can be used to get notifications when global events, like |
| 11662 | * layout, happen. |
| 11663 | * |
| 11664 | * The returned ViewTreeObserver observer is not guaranteed to remain |
| 11665 | * valid for the lifetime of this View. If the caller of this method keeps |
| 11666 | * a long-lived reference to ViewTreeObserver, it should always check for |
| 11667 | * the return value of {@link ViewTreeObserver#isAlive()}. |
| 11668 | * |
| 11669 | * @return The ViewTreeObserver for this view's hierarchy. |
| 11670 | */ |
| 11671 | public ViewTreeObserver getViewTreeObserver() { |
| 11672 | if (mAttachInfo != null) { |
| 11673 | return mAttachInfo.mTreeObserver; |
| 11674 | } |
| 11675 | if (mFloatingTreeObserver == null) { |
| 11676 | mFloatingTreeObserver = new ViewTreeObserver(); |
| 11677 | } |
| 11678 | return mFloatingTreeObserver; |
| 11679 | } |
| 11680 | |
| 11681 | /** |
| 11682 | * <p>Finds the topmost view in the current view hierarchy.</p> |
| 11683 | * |
| 11684 | * @return the topmost view containing this view |
| 11685 | */ |
| 11686 | public View getRootView() { |
| 11687 | if (mAttachInfo != null) { |
| 11688 | final View v = mAttachInfo.mRootView; |
| 11689 | if (v != null) { |
| 11690 | return v; |
| 11691 | } |
| 11692 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11693 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11694 | View parent = this; |
| 11695 | |
| 11696 | while (parent.mParent != null && parent.mParent instanceof View) { |
| 11697 | parent = (View) parent.mParent; |
| 11698 | } |
| 11699 | |
| 11700 | return parent; |
| 11701 | } |
| 11702 | |
| 11703 | /** |
| 11704 | * <p>Computes the coordinates of this view on the screen. The argument |
| 11705 | * must be an array of two integers. After the method returns, the array |
| 11706 | * contains the x and y location in that order.</p> |
| 11707 | * |
| 11708 | * @param location an array of two integers in which to hold the coordinates |
| 11709 | */ |
| 11710 | public void getLocationOnScreen(int[] location) { |
| 11711 | getLocationInWindow(location); |
| 11712 | |
| 11713 | final AttachInfo info = mAttachInfo; |
Romain Guy | 779398e | 2009-06-16 13:17:50 -0700 | [diff] [blame] | 11714 | if (info != null) { |
| 11715 | location[0] += info.mWindowLeft; |
| 11716 | location[1] += info.mWindowTop; |
| 11717 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11718 | } |
| 11719 | |
| 11720 | /** |
| 11721 | * <p>Computes the coordinates of this view in its window. The argument |
| 11722 | * must be an array of two integers. After the method returns, the array |
| 11723 | * contains the x and y location in that order.</p> |
| 11724 | * |
| 11725 | * @param location an array of two integers in which to hold the coordinates |
| 11726 | */ |
| 11727 | public void getLocationInWindow(int[] location) { |
| 11728 | if (location == null || location.length < 2) { |
| 11729 | throw new IllegalArgumentException("location must be an array of " |
| 11730 | + "two integers"); |
| 11731 | } |
| 11732 | |
Michael Jurka | 4d2bd4c | 2010-11-30 18:15:11 -0800 | [diff] [blame] | 11733 | location[0] = mLeft + (int) (mTranslationX + 0.5f); |
| 11734 | location[1] = mTop + (int) (mTranslationY + 0.5f); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11735 | |
| 11736 | ViewParent viewParent = mParent; |
| 11737 | while (viewParent instanceof View) { |
| 11738 | final View view = (View)viewParent; |
Michael Jurka | 4d2bd4c | 2010-11-30 18:15:11 -0800 | [diff] [blame] | 11739 | location[0] += view.mLeft + (int) (view.mTranslationX + 0.5f) - view.mScrollX; |
| 11740 | location[1] += view.mTop + (int) (view.mTranslationY + 0.5f) - view.mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11741 | viewParent = view.mParent; |
| 11742 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11743 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 11744 | if (viewParent instanceof ViewRootImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11745 | // *cough* |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 11746 | final ViewRootImpl vr = (ViewRootImpl)viewParent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11747 | location[1] -= vr.mCurScrollY; |
| 11748 | } |
| 11749 | } |
| 11750 | |
| 11751 | /** |
| 11752 | * {@hide} |
| 11753 | * @param id the id of the view to be found |
| 11754 | * @return the view of the specified id, null if cannot be found |
| 11755 | */ |
| 11756 | protected View findViewTraversal(int id) { |
| 11757 | if (id == mID) { |
| 11758 | return this; |
| 11759 | } |
| 11760 | return null; |
| 11761 | } |
| 11762 | |
| 11763 | /** |
| 11764 | * {@hide} |
| 11765 | * @param tag the tag of the view to be found |
| 11766 | * @return the view of specified tag, null if cannot be found |
| 11767 | */ |
| 11768 | protected View findViewWithTagTraversal(Object tag) { |
| 11769 | if (tag != null && tag.equals(mTag)) { |
| 11770 | return this; |
| 11771 | } |
| 11772 | return null; |
| 11773 | } |
| 11774 | |
| 11775 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 11776 | * {@hide} |
| 11777 | * @param predicate The predicate to evaluate. |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 11778 | * @param childToSkip If not null, ignores this child during the recursive traversal. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 11779 | * @return The first view that matches the predicate or null. |
| 11780 | */ |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 11781 | protected View findViewByPredicateTraversal(Predicate<View> predicate, View childToSkip) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 11782 | if (predicate.apply(this)) { |
| 11783 | return this; |
| 11784 | } |
| 11785 | return null; |
| 11786 | } |
| 11787 | |
| 11788 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11789 | * Look for a child view with the given id. If this view has the given |
| 11790 | * id, return this view. |
| 11791 | * |
| 11792 | * @param id The id to search for. |
| 11793 | * @return The view that has the given id in the hierarchy or null |
| 11794 | */ |
| 11795 | public final View findViewById(int id) { |
| 11796 | if (id < 0) { |
| 11797 | return null; |
| 11798 | } |
| 11799 | return findViewTraversal(id); |
| 11800 | } |
| 11801 | |
| 11802 | /** |
| 11803 | * Look for a child view with the given tag. If this view has the given |
| 11804 | * tag, return this view. |
| 11805 | * |
| 11806 | * @param tag The tag to search for, using "tag.equals(getTag())". |
| 11807 | * @return The View that has the given tag in the hierarchy or null |
| 11808 | */ |
| 11809 | public final View findViewWithTag(Object tag) { |
| 11810 | if (tag == null) { |
| 11811 | return null; |
| 11812 | } |
| 11813 | return findViewWithTagTraversal(tag); |
| 11814 | } |
| 11815 | |
| 11816 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 11817 | * {@hide} |
| 11818 | * Look for a child view that matches the specified predicate. |
| 11819 | * If this view matches the predicate, return this view. |
| 11820 | * |
| 11821 | * @param predicate The predicate to evaluate. |
| 11822 | * @return The first view that matches the predicate or null. |
| 11823 | */ |
| 11824 | public final View findViewByPredicate(Predicate<View> predicate) { |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 11825 | return findViewByPredicateTraversal(predicate, null); |
| 11826 | } |
| 11827 | |
| 11828 | /** |
| 11829 | * {@hide} |
| 11830 | * Look for a child view that matches the specified predicate, |
| 11831 | * starting with the specified view and its descendents and then |
| 11832 | * recusively searching the ancestors and siblings of that view |
| 11833 | * until this view is reached. |
| 11834 | * |
| 11835 | * This method is useful in cases where the predicate does not match |
| 11836 | * a single unique view (perhaps multiple views use the same id) |
| 11837 | * and we are trying to find the view that is "closest" in scope to the |
| 11838 | * starting view. |
| 11839 | * |
| 11840 | * @param start The view to start from. |
| 11841 | * @param predicate The predicate to evaluate. |
| 11842 | * @return The first view that matches the predicate or null. |
| 11843 | */ |
| 11844 | public final View findViewByPredicateInsideOut(View start, Predicate<View> predicate) { |
| 11845 | View childToSkip = null; |
| 11846 | for (;;) { |
| 11847 | View view = start.findViewByPredicateTraversal(predicate, childToSkip); |
| 11848 | if (view != null || start == this) { |
| 11849 | return view; |
| 11850 | } |
| 11851 | |
| 11852 | ViewParent parent = start.getParent(); |
| 11853 | if (parent == null || !(parent instanceof View)) { |
| 11854 | return null; |
| 11855 | } |
| 11856 | |
| 11857 | childToSkip = start; |
| 11858 | start = (View) parent; |
| 11859 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 11860 | } |
| 11861 | |
| 11862 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11863 | * Sets the identifier for this view. The identifier does not have to be |
| 11864 | * unique in this view's hierarchy. The identifier should be a positive |
| 11865 | * number. |
| 11866 | * |
| 11867 | * @see #NO_ID |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11868 | * @see #getId() |
| 11869 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11870 | * |
| 11871 | * @param id a number used to identify the view |
| 11872 | * |
| 11873 | * @attr ref android.R.styleable#View_id |
| 11874 | */ |
| 11875 | public void setId(int id) { |
| 11876 | mID = id; |
| 11877 | } |
| 11878 | |
| 11879 | /** |
| 11880 | * {@hide} |
| 11881 | * |
| 11882 | * @param isRoot true if the view belongs to the root namespace, false |
| 11883 | * otherwise |
| 11884 | */ |
| 11885 | public void setIsRootNamespace(boolean isRoot) { |
| 11886 | if (isRoot) { |
| 11887 | mPrivateFlags |= IS_ROOT_NAMESPACE; |
| 11888 | } else { |
| 11889 | mPrivateFlags &= ~IS_ROOT_NAMESPACE; |
| 11890 | } |
| 11891 | } |
| 11892 | |
| 11893 | /** |
| 11894 | * {@hide} |
| 11895 | * |
| 11896 | * @return true if the view belongs to the root namespace, false otherwise |
| 11897 | */ |
| 11898 | public boolean isRootNamespace() { |
| 11899 | return (mPrivateFlags&IS_ROOT_NAMESPACE) != 0; |
| 11900 | } |
| 11901 | |
| 11902 | /** |
| 11903 | * Returns this view's identifier. |
| 11904 | * |
| 11905 | * @return a positive integer used to identify the view or {@link #NO_ID} |
| 11906 | * if the view has no ID |
| 11907 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11908 | * @see #setId(int) |
| 11909 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11910 | * @attr ref android.R.styleable#View_id |
| 11911 | */ |
| 11912 | @ViewDebug.CapturedViewProperty |
| 11913 | public int getId() { |
| 11914 | return mID; |
| 11915 | } |
| 11916 | |
| 11917 | /** |
| 11918 | * Returns this view's tag. |
| 11919 | * |
| 11920 | * @return the Object stored in this view as a tag |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 11921 | * |
| 11922 | * @see #setTag(Object) |
| 11923 | * @see #getTag(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11924 | */ |
| 11925 | @ViewDebug.ExportedProperty |
| 11926 | public Object getTag() { |
| 11927 | return mTag; |
| 11928 | } |
| 11929 | |
| 11930 | /** |
| 11931 | * Sets the tag associated with this view. A tag can be used to mark |
| 11932 | * a view in its hierarchy and does not have to be unique within the |
| 11933 | * hierarchy. Tags can also be used to store data within a view without |
| 11934 | * resorting to another data structure. |
| 11935 | * |
| 11936 | * @param tag an Object to tag the view with |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 11937 | * |
| 11938 | * @see #getTag() |
| 11939 | * @see #setTag(int, Object) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11940 | */ |
| 11941 | public void setTag(final Object tag) { |
| 11942 | mTag = tag; |
| 11943 | } |
| 11944 | |
| 11945 | /** |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 11946 | * Returns the tag associated with this view and the specified key. |
| 11947 | * |
| 11948 | * @param key The key identifying the tag |
| 11949 | * |
| 11950 | * @return the Object stored in this view as a tag |
| 11951 | * |
| 11952 | * @see #setTag(int, Object) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11953 | * @see #getTag() |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 11954 | */ |
| 11955 | public Object getTag(int key) { |
| 11956 | SparseArray<Object> tags = null; |
| 11957 | synchronized (sTagsLock) { |
| 11958 | if (sTags != null) { |
| 11959 | tags = sTags.get(this); |
| 11960 | } |
| 11961 | } |
| 11962 | |
| 11963 | if (tags != null) return tags.get(key); |
| 11964 | return null; |
| 11965 | } |
| 11966 | |
| 11967 | /** |
| 11968 | * Sets a tag associated with this view and a key. A tag can be used |
| 11969 | * to mark a view in its hierarchy and does not have to be unique within |
| 11970 | * the hierarchy. Tags can also be used to store data within a view |
| 11971 | * without resorting to another data structure. |
| 11972 | * |
| 11973 | * 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] | 11974 | * application to ensure it is unique (see the <a |
| 11975 | * href={@docRoot}guide/topics/resources/more-resources.html#Id">ID resource type</a>). |
| 11976 | * Keys identified as belonging to |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 11977 | * the Android framework or not associated with any package will cause |
| 11978 | * an {@link IllegalArgumentException} to be thrown. |
| 11979 | * |
| 11980 | * @param key The key identifying the tag |
| 11981 | * @param tag An Object to tag the view with |
| 11982 | * |
| 11983 | * @throws IllegalArgumentException If they specified key is not valid |
| 11984 | * |
| 11985 | * @see #setTag(Object) |
| 11986 | * @see #getTag(int) |
| 11987 | */ |
| 11988 | public void setTag(int key, final Object tag) { |
| 11989 | // If the package id is 0x00 or 0x01, it's either an undefined package |
| 11990 | // or a framework id |
| 11991 | if ((key >>> 24) < 2) { |
| 11992 | throw new IllegalArgumentException("The key must be an application-specific " |
| 11993 | + "resource id."); |
| 11994 | } |
| 11995 | |
| 11996 | setTagInternal(this, key, tag); |
| 11997 | } |
| 11998 | |
| 11999 | /** |
| 12000 | * Variation of {@link #setTag(int, Object)} that enforces the key to be a |
| 12001 | * framework id. |
| 12002 | * |
| 12003 | * @hide |
| 12004 | */ |
| 12005 | public void setTagInternal(int key, Object tag) { |
| 12006 | if ((key >>> 24) != 0x1) { |
| 12007 | throw new IllegalArgumentException("The key must be a framework-specific " |
| 12008 | + "resource id."); |
| 12009 | } |
| 12010 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12011 | setTagInternal(this, key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12012 | } |
| 12013 | |
| 12014 | private static void setTagInternal(View view, int key, Object tag) { |
| 12015 | SparseArray<Object> tags = null; |
| 12016 | synchronized (sTagsLock) { |
| 12017 | if (sTags == null) { |
| 12018 | sTags = new WeakHashMap<View, SparseArray<Object>>(); |
| 12019 | } else { |
| 12020 | tags = sTags.get(view); |
| 12021 | } |
| 12022 | } |
| 12023 | |
| 12024 | if (tags == null) { |
| 12025 | tags = new SparseArray<Object>(2); |
| 12026 | synchronized (sTagsLock) { |
| 12027 | sTags.put(view, tags); |
| 12028 | } |
| 12029 | } |
| 12030 | |
| 12031 | tags.put(key, tag); |
| 12032 | } |
| 12033 | |
| 12034 | /** |
Romain Guy | 13922e0 | 2009-05-12 17:56:14 -0700 | [diff] [blame] | 12035 | * @param consistency The type of consistency. See ViewDebug for more information. |
| 12036 | * |
| 12037 | * @hide |
| 12038 | */ |
| 12039 | protected boolean dispatchConsistencyCheck(int consistency) { |
| 12040 | return onConsistencyCheck(consistency); |
| 12041 | } |
| 12042 | |
| 12043 | /** |
| 12044 | * Method that subclasses should implement to check their consistency. The type of |
| 12045 | * consistency check is indicated by the bit field passed as a parameter. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12046 | * |
Romain Guy | 13922e0 | 2009-05-12 17:56:14 -0700 | [diff] [blame] | 12047 | * @param consistency The type of consistency. See ViewDebug for more information. |
| 12048 | * |
| 12049 | * @throws IllegalStateException if the view is in an inconsistent state. |
| 12050 | * |
| 12051 | * @hide |
| 12052 | */ |
| 12053 | protected boolean onConsistencyCheck(int consistency) { |
| 12054 | boolean result = true; |
| 12055 | |
| 12056 | final boolean checkLayout = (consistency & ViewDebug.CONSISTENCY_LAYOUT) != 0; |
| 12057 | final boolean checkDrawing = (consistency & ViewDebug.CONSISTENCY_DRAWING) != 0; |
| 12058 | |
| 12059 | if (checkLayout) { |
| 12060 | if (getParent() == null) { |
| 12061 | result = false; |
| 12062 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 12063 | "View " + this + " does not have a parent."); |
| 12064 | } |
| 12065 | |
| 12066 | if (mAttachInfo == null) { |
| 12067 | result = false; |
| 12068 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 12069 | "View " + this + " is not attached to a window."); |
| 12070 | } |
| 12071 | } |
| 12072 | |
| 12073 | if (checkDrawing) { |
| 12074 | // Do not check the DIRTY/DRAWN flags because views can call invalidate() |
| 12075 | // from their draw() method |
| 12076 | |
| 12077 | if ((mPrivateFlags & DRAWN) != DRAWN && |
| 12078 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) { |
| 12079 | result = false; |
| 12080 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 12081 | "View " + this + " was invalidated but its drawing cache is valid."); |
| 12082 | } |
| 12083 | } |
| 12084 | |
| 12085 | return result; |
| 12086 | } |
| 12087 | |
| 12088 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12089 | * Prints information about this view in the log output, with the tag |
| 12090 | * {@link #VIEW_LOG_TAG}. |
| 12091 | * |
| 12092 | * @hide |
| 12093 | */ |
| 12094 | public void debug() { |
| 12095 | debug(0); |
| 12096 | } |
| 12097 | |
| 12098 | /** |
| 12099 | * Prints information about this view in the log output, with the tag |
| 12100 | * {@link #VIEW_LOG_TAG}. Each line in the output is preceded with an |
| 12101 | * indentation defined by the <code>depth</code>. |
| 12102 | * |
| 12103 | * @param depth the indentation level |
| 12104 | * |
| 12105 | * @hide |
| 12106 | */ |
| 12107 | protected void debug(int depth) { |
| 12108 | String output = debugIndent(depth - 1); |
| 12109 | |
| 12110 | output += "+ " + this; |
| 12111 | int id = getId(); |
| 12112 | if (id != -1) { |
| 12113 | output += " (id=" + id + ")"; |
| 12114 | } |
| 12115 | Object tag = getTag(); |
| 12116 | if (tag != null) { |
| 12117 | output += " (tag=" + tag + ")"; |
| 12118 | } |
| 12119 | Log.d(VIEW_LOG_TAG, output); |
| 12120 | |
| 12121 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 12122 | output = debugIndent(depth) + " FOCUSED"; |
| 12123 | Log.d(VIEW_LOG_TAG, output); |
| 12124 | } |
| 12125 | |
| 12126 | output = debugIndent(depth); |
| 12127 | output += "frame={" + mLeft + ", " + mTop + ", " + mRight |
| 12128 | + ", " + mBottom + "} scroll={" + mScrollX + ", " + mScrollY |
| 12129 | + "} "; |
| 12130 | Log.d(VIEW_LOG_TAG, output); |
| 12131 | |
| 12132 | if (mPaddingLeft != 0 || mPaddingTop != 0 || mPaddingRight != 0 |
| 12133 | || mPaddingBottom != 0) { |
| 12134 | output = debugIndent(depth); |
| 12135 | output += "padding={" + mPaddingLeft + ", " + mPaddingTop |
| 12136 | + ", " + mPaddingRight + ", " + mPaddingBottom + "}"; |
| 12137 | Log.d(VIEW_LOG_TAG, output); |
| 12138 | } |
| 12139 | |
| 12140 | output = debugIndent(depth); |
| 12141 | output += "mMeasureWidth=" + mMeasuredWidth + |
| 12142 | " mMeasureHeight=" + mMeasuredHeight; |
| 12143 | Log.d(VIEW_LOG_TAG, output); |
| 12144 | |
| 12145 | output = debugIndent(depth); |
| 12146 | if (mLayoutParams == null) { |
| 12147 | output += "BAD! no layout params"; |
| 12148 | } else { |
| 12149 | output = mLayoutParams.debug(output); |
| 12150 | } |
| 12151 | Log.d(VIEW_LOG_TAG, output); |
| 12152 | |
| 12153 | output = debugIndent(depth); |
| 12154 | output += "flags={"; |
| 12155 | output += View.printFlags(mViewFlags); |
| 12156 | output += "}"; |
| 12157 | Log.d(VIEW_LOG_TAG, output); |
| 12158 | |
| 12159 | output = debugIndent(depth); |
| 12160 | output += "privateFlags={"; |
| 12161 | output += View.printPrivateFlags(mPrivateFlags); |
| 12162 | output += "}"; |
| 12163 | Log.d(VIEW_LOG_TAG, output); |
| 12164 | } |
| 12165 | |
| 12166 | /** |
| 12167 | * Creates an string of whitespaces used for indentation. |
| 12168 | * |
| 12169 | * @param depth the indentation level |
| 12170 | * @return a String containing (depth * 2 + 3) * 2 white spaces |
| 12171 | * |
| 12172 | * @hide |
| 12173 | */ |
| 12174 | protected static String debugIndent(int depth) { |
| 12175 | StringBuilder spaces = new StringBuilder((depth * 2 + 3) * 2); |
| 12176 | for (int i = 0; i < (depth * 2) + 3; i++) { |
| 12177 | spaces.append(' ').append(' '); |
| 12178 | } |
| 12179 | return spaces.toString(); |
| 12180 | } |
| 12181 | |
| 12182 | /** |
| 12183 | * <p>Return the offset of the widget's text baseline from the widget's top |
| 12184 | * boundary. If this widget does not support baseline alignment, this |
| 12185 | * method returns -1. </p> |
| 12186 | * |
| 12187 | * @return the offset of the baseline within the widget's bounds or -1 |
| 12188 | * if baseline alignment is not supported |
| 12189 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 12190 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12191 | public int getBaseline() { |
| 12192 | return -1; |
| 12193 | } |
| 12194 | |
| 12195 | /** |
| 12196 | * Call this when something has changed which has invalidated the |
| 12197 | * layout of this view. This will schedule a layout pass of the view |
| 12198 | * tree. |
| 12199 | */ |
| 12200 | public void requestLayout() { |
| 12201 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12202 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.REQUEST_LAYOUT); |
| 12203 | } |
| 12204 | |
| 12205 | mPrivateFlags |= FORCE_LAYOUT; |
Chet Haase | 5af048c | 2011-01-24 17:00:32 -0800 | [diff] [blame] | 12206 | mPrivateFlags |= INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12207 | |
Fabrice Di Meglio | d794aca | 2011-07-22 18:19:36 -0700 | [diff] [blame] | 12208 | if (mParent != null) { |
| 12209 | if (mLayoutParams != null) { |
| 12210 | mLayoutParams.resolveWithDirection(getResolvedLayoutDirection()); |
| 12211 | } |
| 12212 | if (!mParent.isLayoutRequested()) { |
| 12213 | mParent.requestLayout(); |
| 12214 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12215 | } |
| 12216 | } |
| 12217 | |
| 12218 | /** |
| 12219 | * Forces this view to be laid out during the next layout pass. |
| 12220 | * This method does not call requestLayout() or forceLayout() |
| 12221 | * on the parent. |
| 12222 | */ |
| 12223 | public void forceLayout() { |
| 12224 | mPrivateFlags |= FORCE_LAYOUT; |
Chet Haase | 5af048c | 2011-01-24 17:00:32 -0800 | [diff] [blame] | 12225 | mPrivateFlags |= INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12226 | } |
| 12227 | |
| 12228 | /** |
| 12229 | * <p> |
| 12230 | * This is called to find out how big a view should be. The parent |
| 12231 | * supplies constraint information in the width and height parameters. |
| 12232 | * </p> |
| 12233 | * |
| 12234 | * <p> |
| 12235 | * The actual mesurement work of a view is performed in |
| 12236 | * {@link #onMeasure(int, int)}, called by this method. Therefore, only |
| 12237 | * {@link #onMeasure(int, int)} can and must be overriden by subclasses. |
| 12238 | * </p> |
| 12239 | * |
| 12240 | * |
| 12241 | * @param widthMeasureSpec Horizontal space requirements as imposed by the |
| 12242 | * parent |
| 12243 | * @param heightMeasureSpec Vertical space requirements as imposed by the |
| 12244 | * parent |
| 12245 | * |
| 12246 | * @see #onMeasure(int, int) |
| 12247 | */ |
| 12248 | public final void measure(int widthMeasureSpec, int heightMeasureSpec) { |
| 12249 | if ((mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT || |
| 12250 | widthMeasureSpec != mOldWidthMeasureSpec || |
| 12251 | heightMeasureSpec != mOldHeightMeasureSpec) { |
| 12252 | |
| 12253 | // first clears the measured dimension flag |
| 12254 | mPrivateFlags &= ~MEASURED_DIMENSION_SET; |
| 12255 | |
| 12256 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12257 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_MEASURE); |
| 12258 | } |
| 12259 | |
| 12260 | // measure ourselves, this should set the measured dimension flag back |
| 12261 | onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 12262 | |
| 12263 | // flag not set, setMeasuredDimension() was not invoked, we raise |
| 12264 | // an exception to warn the developer |
| 12265 | if ((mPrivateFlags & MEASURED_DIMENSION_SET) != MEASURED_DIMENSION_SET) { |
| 12266 | throw new IllegalStateException("onMeasure() did not set the" |
| 12267 | + " measured dimension by calling" |
| 12268 | + " setMeasuredDimension()"); |
| 12269 | } |
| 12270 | |
| 12271 | mPrivateFlags |= LAYOUT_REQUIRED; |
| 12272 | } |
| 12273 | |
| 12274 | mOldWidthMeasureSpec = widthMeasureSpec; |
| 12275 | mOldHeightMeasureSpec = heightMeasureSpec; |
| 12276 | } |
| 12277 | |
| 12278 | /** |
| 12279 | * <p> |
| 12280 | * Measure the view and its content to determine the measured width and the |
| 12281 | * measured height. This method is invoked by {@link #measure(int, int)} and |
| 12282 | * should be overriden by subclasses to provide accurate and efficient |
| 12283 | * measurement of their contents. |
| 12284 | * </p> |
| 12285 | * |
| 12286 | * <p> |
| 12287 | * <strong>CONTRACT:</strong> When overriding this method, you |
| 12288 | * <em>must</em> call {@link #setMeasuredDimension(int, int)} to store the |
| 12289 | * measured width and height of this view. Failure to do so will trigger an |
| 12290 | * <code>IllegalStateException</code>, thrown by |
| 12291 | * {@link #measure(int, int)}. Calling the superclass' |
| 12292 | * {@link #onMeasure(int, int)} is a valid use. |
| 12293 | * </p> |
| 12294 | * |
| 12295 | * <p> |
| 12296 | * The base class implementation of measure defaults to the background size, |
| 12297 | * unless a larger size is allowed by the MeasureSpec. Subclasses should |
| 12298 | * override {@link #onMeasure(int, int)} to provide better measurements of |
| 12299 | * their content. |
| 12300 | * </p> |
| 12301 | * |
| 12302 | * <p> |
| 12303 | * If this method is overridden, it is the subclass's responsibility to make |
| 12304 | * sure the measured height and width are at least the view's minimum height |
| 12305 | * and width ({@link #getSuggestedMinimumHeight()} and |
| 12306 | * {@link #getSuggestedMinimumWidth()}). |
| 12307 | * </p> |
| 12308 | * |
| 12309 | * @param widthMeasureSpec horizontal space requirements as imposed by the parent. |
| 12310 | * The requirements are encoded with |
| 12311 | * {@link android.view.View.MeasureSpec}. |
| 12312 | * @param heightMeasureSpec vertical space requirements as imposed by the parent. |
| 12313 | * The requirements are encoded with |
| 12314 | * {@link android.view.View.MeasureSpec}. |
| 12315 | * |
| 12316 | * @see #getMeasuredWidth() |
| 12317 | * @see #getMeasuredHeight() |
| 12318 | * @see #setMeasuredDimension(int, int) |
| 12319 | * @see #getSuggestedMinimumHeight() |
| 12320 | * @see #getSuggestedMinimumWidth() |
| 12321 | * @see android.view.View.MeasureSpec#getMode(int) |
| 12322 | * @see android.view.View.MeasureSpec#getSize(int) |
| 12323 | */ |
| 12324 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 12325 | setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), |
| 12326 | getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec)); |
| 12327 | } |
| 12328 | |
| 12329 | /** |
| 12330 | * <p>This mehod must be called by {@link #onMeasure(int, int)} to store the |
| 12331 | * measured width and measured height. Failing to do so will trigger an |
| 12332 | * exception at measurement time.</p> |
| 12333 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12334 | * @param measuredWidth The measured width of this view. May be a complex |
| 12335 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 12336 | * {@link #MEASURED_STATE_TOO_SMALL}. |
| 12337 | * @param measuredHeight The measured height of this view. May be a complex |
| 12338 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 12339 | * {@link #MEASURED_STATE_TOO_SMALL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12340 | */ |
| 12341 | protected final void setMeasuredDimension(int measuredWidth, int measuredHeight) { |
| 12342 | mMeasuredWidth = measuredWidth; |
| 12343 | mMeasuredHeight = measuredHeight; |
| 12344 | |
| 12345 | mPrivateFlags |= MEASURED_DIMENSION_SET; |
| 12346 | } |
| 12347 | |
| 12348 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12349 | * Merge two states as returned by {@link #getMeasuredState()}. |
| 12350 | * @param curState The current state as returned from a view or the result |
| 12351 | * of combining multiple views. |
| 12352 | * @param newState The new view state to combine. |
| 12353 | * @return Returns a new integer reflecting the combination of the two |
| 12354 | * states. |
| 12355 | */ |
| 12356 | public static int combineMeasuredStates(int curState, int newState) { |
| 12357 | return curState | newState; |
| 12358 | } |
| 12359 | |
| 12360 | /** |
| 12361 | * Version of {@link #resolveSizeAndState(int, int, int)} |
| 12362 | * returning only the {@link #MEASURED_SIZE_MASK} bits of the result. |
| 12363 | */ |
| 12364 | public static int resolveSize(int size, int measureSpec) { |
| 12365 | return resolveSizeAndState(size, measureSpec, 0) & MEASURED_SIZE_MASK; |
| 12366 | } |
| 12367 | |
| 12368 | /** |
| 12369 | * Utility to reconcile a desired size and state, with constraints imposed |
| 12370 | * by a MeasureSpec. Will take the desired size, unless a different size |
| 12371 | * is imposed by the constraints. The returned value is a compound integer, |
| 12372 | * with the resolved size in the {@link #MEASURED_SIZE_MASK} bits and |
| 12373 | * optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the resulting |
| 12374 | * 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] | 12375 | * |
| 12376 | * @param size How big the view wants to be |
| 12377 | * @param measureSpec Constraints imposed by the parent |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12378 | * @return Size information bit mask as defined by |
| 12379 | * {@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] | 12380 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12381 | 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] | 12382 | int result = size; |
| 12383 | int specMode = MeasureSpec.getMode(measureSpec); |
| 12384 | int specSize = MeasureSpec.getSize(measureSpec); |
| 12385 | switch (specMode) { |
| 12386 | case MeasureSpec.UNSPECIFIED: |
| 12387 | result = size; |
| 12388 | break; |
| 12389 | case MeasureSpec.AT_MOST: |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12390 | if (specSize < size) { |
| 12391 | result = specSize | MEASURED_STATE_TOO_SMALL; |
| 12392 | } else { |
| 12393 | result = size; |
| 12394 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12395 | break; |
| 12396 | case MeasureSpec.EXACTLY: |
| 12397 | result = specSize; |
| 12398 | break; |
| 12399 | } |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12400 | return result | (childMeasuredState&MEASURED_STATE_MASK); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12401 | } |
| 12402 | |
| 12403 | /** |
| 12404 | * Utility to return a default size. Uses the supplied size if the |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 12405 | * MeasureSpec imposed no constraints. Will get larger if allowed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12406 | * by the MeasureSpec. |
| 12407 | * |
| 12408 | * @param size Default size for this view |
| 12409 | * @param measureSpec Constraints imposed by the parent |
| 12410 | * @return The size this view should be. |
| 12411 | */ |
| 12412 | public static int getDefaultSize(int size, int measureSpec) { |
| 12413 | int result = size; |
| 12414 | int specMode = MeasureSpec.getMode(measureSpec); |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 12415 | int specSize = MeasureSpec.getSize(measureSpec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12416 | |
| 12417 | switch (specMode) { |
| 12418 | case MeasureSpec.UNSPECIFIED: |
| 12419 | result = size; |
| 12420 | break; |
| 12421 | case MeasureSpec.AT_MOST: |
| 12422 | case MeasureSpec.EXACTLY: |
| 12423 | result = specSize; |
| 12424 | break; |
| 12425 | } |
| 12426 | return result; |
| 12427 | } |
| 12428 | |
| 12429 | /** |
| 12430 | * Returns the suggested minimum height that the view should use. This |
| 12431 | * returns the maximum of the view's minimum height |
| 12432 | * and the background's minimum height |
| 12433 | * ({@link android.graphics.drawable.Drawable#getMinimumHeight()}). |
| 12434 | * <p> |
| 12435 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 12436 | * ensure the returned height is within the requirements of the parent. |
| 12437 | * |
| 12438 | * @return The suggested minimum height of the view. |
| 12439 | */ |
| 12440 | protected int getSuggestedMinimumHeight() { |
| 12441 | int suggestedMinHeight = mMinHeight; |
| 12442 | |
| 12443 | if (mBGDrawable != null) { |
| 12444 | final int bgMinHeight = mBGDrawable.getMinimumHeight(); |
| 12445 | if (suggestedMinHeight < bgMinHeight) { |
| 12446 | suggestedMinHeight = bgMinHeight; |
| 12447 | } |
| 12448 | } |
| 12449 | |
| 12450 | return suggestedMinHeight; |
| 12451 | } |
| 12452 | |
| 12453 | /** |
| 12454 | * Returns the suggested minimum width that the view should use. This |
| 12455 | * returns the maximum of the view's minimum width) |
| 12456 | * and the background's minimum width |
| 12457 | * ({@link android.graphics.drawable.Drawable#getMinimumWidth()}). |
| 12458 | * <p> |
| 12459 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 12460 | * ensure the returned width is within the requirements of the parent. |
| 12461 | * |
| 12462 | * @return The suggested minimum width of the view. |
| 12463 | */ |
| 12464 | protected int getSuggestedMinimumWidth() { |
| 12465 | int suggestedMinWidth = mMinWidth; |
| 12466 | |
| 12467 | if (mBGDrawable != null) { |
| 12468 | final int bgMinWidth = mBGDrawable.getMinimumWidth(); |
| 12469 | if (suggestedMinWidth < bgMinWidth) { |
| 12470 | suggestedMinWidth = bgMinWidth; |
| 12471 | } |
| 12472 | } |
| 12473 | |
| 12474 | return suggestedMinWidth; |
| 12475 | } |
| 12476 | |
| 12477 | /** |
| 12478 | * Sets the minimum height of the view. It is not guaranteed the view will |
| 12479 | * be able to achieve this minimum height (for example, if its parent layout |
| 12480 | * constrains it with less available height). |
| 12481 | * |
| 12482 | * @param minHeight The minimum height the view will try to be. |
| 12483 | */ |
| 12484 | public void setMinimumHeight(int minHeight) { |
| 12485 | mMinHeight = minHeight; |
| 12486 | } |
| 12487 | |
| 12488 | /** |
| 12489 | * Sets the minimum width of the view. It is not guaranteed the view will |
| 12490 | * be able to achieve this minimum width (for example, if its parent layout |
| 12491 | * constrains it with less available width). |
| 12492 | * |
| 12493 | * @param minWidth The minimum width the view will try to be. |
| 12494 | */ |
| 12495 | public void setMinimumWidth(int minWidth) { |
| 12496 | mMinWidth = minWidth; |
| 12497 | } |
| 12498 | |
| 12499 | /** |
| 12500 | * Get the animation currently associated with this view. |
| 12501 | * |
| 12502 | * @return The animation that is currently playing or |
| 12503 | * scheduled to play for this view. |
| 12504 | */ |
| 12505 | public Animation getAnimation() { |
| 12506 | return mCurrentAnimation; |
| 12507 | } |
| 12508 | |
| 12509 | /** |
| 12510 | * Start the specified animation now. |
| 12511 | * |
| 12512 | * @param animation the animation to start now |
| 12513 | */ |
| 12514 | public void startAnimation(Animation animation) { |
| 12515 | animation.setStartTime(Animation.START_ON_FIRST_FRAME); |
| 12516 | setAnimation(animation); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 12517 | invalidateParentCaches(); |
| 12518 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12519 | } |
| 12520 | |
| 12521 | /** |
| 12522 | * Cancels any animations for this view. |
| 12523 | */ |
| 12524 | public void clearAnimation() { |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 12525 | if (mCurrentAnimation != null) { |
Romain Guy | b4a107d | 2010-02-09 18:50:08 -0800 | [diff] [blame] | 12526 | mCurrentAnimation.detach(); |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 12527 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12528 | mCurrentAnimation = null; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 12529 | invalidateParentIfNeeded(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12530 | } |
| 12531 | |
| 12532 | /** |
| 12533 | * Sets the next animation to play for this view. |
| 12534 | * If you want the animation to play immediately, use |
| 12535 | * startAnimation. This method provides allows fine-grained |
| 12536 | * control over the start time and invalidation, but you |
| 12537 | * must make sure that 1) the animation has a start time set, and |
| 12538 | * 2) the view will be invalidated when the animation is supposed to |
| 12539 | * start. |
| 12540 | * |
| 12541 | * @param animation The next animation, or null. |
| 12542 | */ |
| 12543 | public void setAnimation(Animation animation) { |
| 12544 | mCurrentAnimation = animation; |
| 12545 | if (animation != null) { |
| 12546 | animation.reset(); |
| 12547 | } |
| 12548 | } |
| 12549 | |
| 12550 | /** |
| 12551 | * Invoked by a parent ViewGroup to notify the start of the animation |
| 12552 | * currently associated with this view. If you override this method, |
| 12553 | * always call super.onAnimationStart(); |
| 12554 | * |
| 12555 | * @see #setAnimation(android.view.animation.Animation) |
| 12556 | * @see #getAnimation() |
| 12557 | */ |
| 12558 | protected void onAnimationStart() { |
| 12559 | mPrivateFlags |= ANIMATION_STARTED; |
| 12560 | } |
| 12561 | |
| 12562 | /** |
| 12563 | * Invoked by a parent ViewGroup to notify the end of the animation |
| 12564 | * currently associated with this view. If you override this method, |
| 12565 | * always call super.onAnimationEnd(); |
| 12566 | * |
| 12567 | * @see #setAnimation(android.view.animation.Animation) |
| 12568 | * @see #getAnimation() |
| 12569 | */ |
| 12570 | protected void onAnimationEnd() { |
| 12571 | mPrivateFlags &= ~ANIMATION_STARTED; |
| 12572 | } |
| 12573 | |
| 12574 | /** |
| 12575 | * Invoked if there is a Transform that involves alpha. Subclass that can |
| 12576 | * draw themselves with the specified alpha should return true, and then |
| 12577 | * respect that alpha when their onDraw() is called. If this returns false |
| 12578 | * then the view may be redirected to draw into an offscreen buffer to |
| 12579 | * fulfill the request, which will look fine, but may be slower than if the |
| 12580 | * subclass handles it internally. The default implementation returns false. |
| 12581 | * |
| 12582 | * @param alpha The alpha (0..255) to apply to the view's drawing |
| 12583 | * @return true if the view can draw with the specified alpha. |
| 12584 | */ |
| 12585 | protected boolean onSetAlpha(int alpha) { |
| 12586 | return false; |
| 12587 | } |
| 12588 | |
| 12589 | /** |
| 12590 | * This is used by the RootView to perform an optimization when |
| 12591 | * the view hierarchy contains one or several SurfaceView. |
| 12592 | * SurfaceView is always considered transparent, but its children are not, |
| 12593 | * therefore all View objects remove themselves from the global transparent |
| 12594 | * region (passed as a parameter to this function). |
| 12595 | * |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 12596 | * @param region The transparent region for this ViewAncestor (window). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12597 | * |
| 12598 | * @return Returns true if the effective visibility of the view at this |
| 12599 | * point is opaque, regardless of the transparent region; returns false |
| 12600 | * if it is possible for underlying windows to be seen behind the view. |
| 12601 | * |
| 12602 | * {@hide} |
| 12603 | */ |
| 12604 | public boolean gatherTransparentRegion(Region region) { |
| 12605 | final AttachInfo attachInfo = mAttachInfo; |
| 12606 | if (region != null && attachInfo != null) { |
| 12607 | final int pflags = mPrivateFlags; |
| 12608 | if ((pflags & SKIP_DRAW) == 0) { |
| 12609 | // The SKIP_DRAW flag IS NOT set, so this view draws. We need to |
| 12610 | // remove it from the transparent region. |
| 12611 | final int[] location = attachInfo.mTransparentLocation; |
| 12612 | getLocationInWindow(location); |
| 12613 | region.op(location[0], location[1], location[0] + mRight - mLeft, |
| 12614 | location[1] + mBottom - mTop, Region.Op.DIFFERENCE); |
| 12615 | } else if ((pflags & ONLY_DRAWS_BACKGROUND) != 0 && mBGDrawable != null) { |
| 12616 | // The ONLY_DRAWS_BACKGROUND flag IS set and the background drawable |
| 12617 | // exists, so we remove the background drawable's non-transparent |
| 12618 | // parts from this transparent region. |
| 12619 | applyDrawableToTransparentRegion(mBGDrawable, region); |
| 12620 | } |
| 12621 | } |
| 12622 | return true; |
| 12623 | } |
| 12624 | |
| 12625 | /** |
| 12626 | * Play a sound effect for this view. |
| 12627 | * |
| 12628 | * <p>The framework will play sound effects for some built in actions, such as |
| 12629 | * clicking, but you may wish to play these effects in your widget, |
| 12630 | * for instance, for internal navigation. |
| 12631 | * |
| 12632 | * <p>The sound effect will only be played if sound effects are enabled by the user, and |
| 12633 | * {@link #isSoundEffectsEnabled()} is true. |
| 12634 | * |
| 12635 | * @param soundConstant One of the constants defined in {@link SoundEffectConstants} |
| 12636 | */ |
| 12637 | public void playSoundEffect(int soundConstant) { |
| 12638 | if (mAttachInfo == null || mAttachInfo.mRootCallbacks == null || !isSoundEffectsEnabled()) { |
| 12639 | return; |
| 12640 | } |
| 12641 | mAttachInfo.mRootCallbacks.playSoundEffect(soundConstant); |
| 12642 | } |
| 12643 | |
| 12644 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 12645 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12646 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 12647 | * <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] | 12648 | * |
| 12649 | * <p>The framework will provide haptic feedback for some built in actions, |
| 12650 | * such as long presses, but you may wish to provide feedback for your |
| 12651 | * own widget. |
| 12652 | * |
| 12653 | * <p>The feedback will only be performed if |
| 12654 | * {@link #isHapticFeedbackEnabled()} is true. |
| 12655 | * |
| 12656 | * @param feedbackConstant One of the constants defined in |
| 12657 | * {@link HapticFeedbackConstants} |
| 12658 | */ |
| 12659 | public boolean performHapticFeedback(int feedbackConstant) { |
| 12660 | return performHapticFeedback(feedbackConstant, 0); |
| 12661 | } |
| 12662 | |
| 12663 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 12664 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12665 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 12666 | * <p>Like {@link #performHapticFeedback(int)}, with additional options. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12667 | * |
| 12668 | * @param feedbackConstant One of the constants defined in |
| 12669 | * {@link HapticFeedbackConstants} |
| 12670 | * @param flags Additional flags as per {@link HapticFeedbackConstants}. |
| 12671 | */ |
| 12672 | public boolean performHapticFeedback(int feedbackConstant, int flags) { |
| 12673 | if (mAttachInfo == null) { |
| 12674 | return false; |
| 12675 | } |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 12676 | //noinspection SimplifiableIfStatement |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 12677 | if ((flags & HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING) == 0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12678 | && !isHapticFeedbackEnabled()) { |
| 12679 | return false; |
| 12680 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 12681 | return mAttachInfo.mRootCallbacks.performHapticFeedback(feedbackConstant, |
| 12682 | (flags & HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12683 | } |
| 12684 | |
| 12685 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 12686 | * Request that the visibility of the status bar be changed. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 12687 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or |
| 12688 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. |
Daniel Sandler | fad9555 | 2011-08-17 14:06:16 -0400 | [diff] [blame] | 12689 | * |
| 12690 | * This value will be re-applied immediately, even if the flags have not changed, so a view may |
| 12691 | * easily reassert a particular SystemUiVisibility condition even if the system UI itself has |
| 12692 | * since countermanded the original request. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 12693 | */ |
| 12694 | public void setSystemUiVisibility(int visibility) { |
Daniel Sandler | fad9555 | 2011-08-17 14:06:16 -0400 | [diff] [blame] | 12695 | mSystemUiVisibility = visibility; |
| 12696 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 12697 | mParent.recomputeViewAttributes(this); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 12698 | } |
| 12699 | } |
| 12700 | |
| 12701 | /** |
| 12702 | * Returns the status bar visibility that this view has requested. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 12703 | * @return Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or |
| 12704 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 12705 | */ |
Joe Onorato | e595cad | 2011-01-24 09:22:12 -0800 | [diff] [blame] | 12706 | public int getSystemUiVisibility() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 12707 | return mSystemUiVisibility; |
| 12708 | } |
| 12709 | |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 12710 | /** |
| 12711 | * Set a listener to receive callbacks when the visibility of the system bar changes. |
| 12712 | * @param l The {@link OnSystemUiVisibilityChangeListener} to receive callbacks. |
| 12713 | */ |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 12714 | public void setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener l) { |
| 12715 | mOnSystemUiVisibilityChangeListener = l; |
| 12716 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 12717 | mParent.recomputeViewAttributes(this); |
| 12718 | } |
| 12719 | } |
| 12720 | |
| 12721 | /** |
| 12722 | */ |
| 12723 | public void dispatchSystemUiVisibilityChanged(int visibility) { |
| 12724 | if (mOnSystemUiVisibilityChangeListener != null) { |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 12725 | mOnSystemUiVisibilityChangeListener.onSystemUiVisibilityChange( |
Joe Onorato | 6ab77bd | 2011-01-31 11:21:10 -0800 | [diff] [blame] | 12726 | visibility & PUBLIC_STATUS_BAR_VISIBILITY_MASK); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 12727 | } |
| 12728 | } |
| 12729 | |
| 12730 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12731 | * Creates an image that the system displays during the drag and drop |
| 12732 | * operation. This is called a "drag shadow". The default implementation |
| 12733 | * for a DragShadowBuilder based on a View returns an image that has exactly the same |
| 12734 | * appearance as the given View. The default also positions the center of the drag shadow |
| 12735 | * directly under the touch point. If no View is provided (the constructor with no parameters |
| 12736 | * is used), and {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} and |
| 12737 | * {@link #onDrawShadow(Canvas) onDrawShadow()} are not overriden, then the |
| 12738 | * default is an invisible drag shadow. |
| 12739 | * <p> |
| 12740 | * You are not required to use the View you provide to the constructor as the basis of the |
| 12741 | * drag shadow. The {@link #onDrawShadow(Canvas) onDrawShadow()} method allows you to draw |
| 12742 | * anything you want as the drag shadow. |
| 12743 | * </p> |
| 12744 | * <p> |
| 12745 | * You pass a DragShadowBuilder object to the system when you start the drag. The system |
| 12746 | * calls {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} to get the |
| 12747 | * size and position of the drag shadow. It uses this data to construct a |
| 12748 | * {@link android.graphics.Canvas} object, then it calls {@link #onDrawShadow(Canvas) onDrawShadow()} |
| 12749 | * so that your application can draw the shadow image in the Canvas. |
| 12750 | * </p> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 12751 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 12752 | public static class DragShadowBuilder { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 12753 | private final WeakReference<View> mView; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 12754 | |
| 12755 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12756 | * Constructs a shadow image builder based on a View. By default, the resulting drag |
| 12757 | * shadow will have the same appearance and dimensions as the View, with the touch point |
| 12758 | * over the center of the View. |
| 12759 | * @param view A View. Any View in scope can be used. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 12760 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 12761 | public DragShadowBuilder(View view) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 12762 | mView = new WeakReference<View>(view); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 12763 | } |
| 12764 | |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 12765 | /** |
| 12766 | * Construct a shadow builder object with no associated View. This |
| 12767 | * constructor variant is only useful when the {@link #onProvideShadowMetrics(Point, Point)} |
| 12768 | * and {@link #onDrawShadow(Canvas)} methods are also overridden in order |
| 12769 | * to supply the drag shadow's dimensions and appearance without |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12770 | * reference to any View object. If they are not overridden, then the result is an |
| 12771 | * invisible drag shadow. |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 12772 | */ |
| 12773 | public DragShadowBuilder() { |
| 12774 | mView = new WeakReference<View>(null); |
| 12775 | } |
| 12776 | |
| 12777 | /** |
| 12778 | * Returns the View object that had been passed to the |
| 12779 | * {@link #View.DragShadowBuilder(View)} |
| 12780 | * constructor. If that View parameter was {@code null} or if the |
| 12781 | * {@link #View.DragShadowBuilder()} |
| 12782 | * constructor was used to instantiate the builder object, this method will return |
| 12783 | * null. |
| 12784 | * |
| 12785 | * @return The View object associate with this builder object. |
| 12786 | */ |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12787 | @SuppressWarnings({"JavadocReference"}) |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 12788 | final public View getView() { |
| 12789 | return mView.get(); |
| 12790 | } |
| 12791 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 12792 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12793 | * Provides the metrics for the shadow image. These include the dimensions of |
| 12794 | * the shadow image, and the point within that shadow that should |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 12795 | * be centered under the touch location while dragging. |
| 12796 | * <p> |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 12797 | * The default implementation sets the dimensions of the shadow to be the |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12798 | * same as the dimensions of the View itself and centers the shadow under |
| 12799 | * the touch point. |
| 12800 | * </p> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 12801 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12802 | * @param shadowSize A {@link android.graphics.Point} containing the width and height |
| 12803 | * of the shadow image. Your application must set {@link android.graphics.Point#x} to the |
| 12804 | * desired width and must set {@link android.graphics.Point#y} to the desired height of the |
| 12805 | * image. |
| 12806 | * |
| 12807 | * @param shadowTouchPoint A {@link android.graphics.Point} for the position within the |
| 12808 | * shadow image that should be underneath the touch point during the drag and drop |
| 12809 | * operation. Your application must set {@link android.graphics.Point#x} to the |
| 12810 | * 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] | 12811 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 12812 | public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 12813 | final View view = mView.get(); |
| 12814 | if (view != null) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 12815 | shadowSize.set(view.getWidth(), view.getHeight()); |
| 12816 | shadowTouchPoint.set(shadowSize.x / 2, shadowSize.y / 2); |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 12817 | } else { |
| 12818 | Log.e(View.VIEW_LOG_TAG, "Asked for drag thumb metrics but no view"); |
| 12819 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 12820 | } |
| 12821 | |
| 12822 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12823 | * Draws the shadow image. The system creates the {@link android.graphics.Canvas} object |
| 12824 | * based on the dimensions it received from the |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 12825 | * {@link #onProvideShadowMetrics(Point, Point)} callback. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 12826 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12827 | * @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] | 12828 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 12829 | public void onDrawShadow(Canvas canvas) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 12830 | final View view = mView.get(); |
| 12831 | if (view != null) { |
| 12832 | view.draw(canvas); |
| 12833 | } else { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 12834 | 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] | 12835 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 12836 | } |
| 12837 | } |
| 12838 | |
| 12839 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12840 | * Starts a drag and drop operation. When your application calls this method, it passes a |
| 12841 | * {@link android.view.View.DragShadowBuilder} object to the system. The |
| 12842 | * system calls this object's {@link DragShadowBuilder#onProvideShadowMetrics(Point, Point)} |
| 12843 | * to get metrics for the drag shadow, and then calls the object's |
| 12844 | * {@link DragShadowBuilder#onDrawShadow(Canvas)} to draw the drag shadow itself. |
| 12845 | * <p> |
| 12846 | * Once the system has the drag shadow, it begins the drag and drop operation by sending |
| 12847 | * drag events to all the View objects in your application that are currently visible. It does |
| 12848 | * this either by calling the View object's drag listener (an implementation of |
| 12849 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent) onDrag()} or by calling the |
| 12850 | * View object's {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} method. |
| 12851 | * Both are passed a {@link android.view.DragEvent} object that has a |
| 12852 | * {@link android.view.DragEvent#getAction()} value of |
| 12853 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED}. |
| 12854 | * </p> |
| 12855 | * <p> |
| 12856 | * Your application can invoke startDrag() on any attached View object. The View object does not |
| 12857 | * need to be the one used in {@link android.view.View.DragShadowBuilder}, nor does it need to |
| 12858 | * be related to the View the user selected for dragging. |
| 12859 | * </p> |
| 12860 | * @param data A {@link android.content.ClipData} object pointing to the data to be |
| 12861 | * transferred by the drag and drop operation. |
| 12862 | * @param shadowBuilder A {@link android.view.View.DragShadowBuilder} object for building the |
| 12863 | * drag shadow. |
| 12864 | * @param myLocalState An {@link java.lang.Object} containing local data about the drag and |
| 12865 | * drop operation. This Object is put into every DragEvent object sent by the system during the |
| 12866 | * current drag. |
| 12867 | * <p> |
| 12868 | * myLocalState is a lightweight mechanism for the sending information from the dragged View |
| 12869 | * to the target Views. For example, it can contain flags that differentiate between a |
| 12870 | * a copy operation and a move operation. |
| 12871 | * </p> |
| 12872 | * @param flags Flags that control the drag and drop operation. No flags are currently defined, |
| 12873 | * so the parameter should be set to 0. |
| 12874 | * @return {@code true} if the method completes successfully, or |
| 12875 | * {@code false} if it fails anywhere. Returning {@code false} means the system was unable to |
| 12876 | * do a drag, and so no drag operation is in progress. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 12877 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 12878 | public final boolean startDrag(ClipData data, DragShadowBuilder shadowBuilder, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 12879 | Object myLocalState, int flags) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 12880 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 12881 | Log.d(VIEW_LOG_TAG, "startDrag: data=" + data + " flags=" + flags); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 12882 | } |
| 12883 | boolean okay = false; |
| 12884 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 12885 | Point shadowSize = new Point(); |
| 12886 | Point shadowTouchPoint = new Point(); |
| 12887 | shadowBuilder.onProvideShadowMetrics(shadowSize, shadowTouchPoint); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 12888 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 12889 | if ((shadowSize.x < 0) || (shadowSize.y < 0) || |
| 12890 | (shadowTouchPoint.x < 0) || (shadowTouchPoint.y < 0)) { |
| 12891 | throw new IllegalStateException("Drag shadow dimensions must not be negative"); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 12892 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 12893 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 12894 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 12895 | Log.d(VIEW_LOG_TAG, "drag shadow: width=" + shadowSize.x + " height=" + shadowSize.y |
| 12896 | + " shadowX=" + shadowTouchPoint.x + " shadowY=" + shadowTouchPoint.y); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 12897 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 12898 | Surface surface = new Surface(); |
| 12899 | try { |
| 12900 | IBinder token = mAttachInfo.mSession.prepareDrag(mAttachInfo.mWindow, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 12901 | flags, shadowSize.x, shadowSize.y, surface); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 12902 | 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] | 12903 | + " surface=" + surface); |
| 12904 | if (token != null) { |
| 12905 | Canvas canvas = surface.lockCanvas(null); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 12906 | try { |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 12907 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 12908 | shadowBuilder.onDrawShadow(canvas); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 12909 | } finally { |
| 12910 | surface.unlockCanvasAndPost(canvas); |
| 12911 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 12912 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 12913 | final ViewRootImpl root = getViewRootImpl(); |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 12914 | |
| 12915 | // Cache the local state object for delivery with DragEvents |
| 12916 | root.setLocalDragState(myLocalState); |
| 12917 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 12918 | // repurpose 'shadowSize' for the last touch point |
| 12919 | root.getLastTouchPoint(shadowSize); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 12920 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 12921 | okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, token, |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 12922 | shadowSize.x, shadowSize.y, |
| 12923 | shadowTouchPoint.x, shadowTouchPoint.y, data); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 12924 | if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "performDrag returned " + okay); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 12925 | } |
| 12926 | } catch (Exception e) { |
| 12927 | Log.e(VIEW_LOG_TAG, "Unable to initiate drag", e); |
| 12928 | surface.destroy(); |
| 12929 | } |
| 12930 | |
| 12931 | return okay; |
| 12932 | } |
| 12933 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 12934 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12935 | * Handles drag events sent by the system following a call to |
| 12936 | * {@link android.view.View#startDrag(ClipData,DragShadowBuilder,Object,int) startDrag()}. |
| 12937 | *<p> |
| 12938 | * When the system calls this method, it passes a |
| 12939 | * {@link android.view.DragEvent} object. A call to |
| 12940 | * {@link android.view.DragEvent#getAction()} returns one of the action type constants defined |
| 12941 | * in DragEvent. The method uses these to determine what is happening in the drag and drop |
| 12942 | * operation. |
| 12943 | * @param event The {@link android.view.DragEvent} sent by the system. |
| 12944 | * The {@link android.view.DragEvent#getAction()} method returns an action type constant defined |
| 12945 | * in DragEvent, indicating the type of drag event represented by this object. |
| 12946 | * @return {@code true} if the method was successful, otherwise {@code false}. |
| 12947 | * <p> |
| 12948 | * The method should return {@code true} in response to an action type of |
| 12949 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED} to receive drag events for the current |
| 12950 | * operation. |
| 12951 | * </p> |
| 12952 | * <p> |
| 12953 | * The method should also return {@code true} in response to an action type of |
| 12954 | * {@link android.view.DragEvent#ACTION_DROP} if it consumed the drop, or |
| 12955 | * {@code false} if it didn't. |
| 12956 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 12957 | */ |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 12958 | public boolean onDragEvent(DragEvent event) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 12959 | return false; |
| 12960 | } |
| 12961 | |
| 12962 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12963 | * Detects if this View is enabled and has a drag event listener. |
| 12964 | * If both are true, then it calls the drag event listener with the |
| 12965 | * {@link android.view.DragEvent} it received. If the drag event listener returns |
| 12966 | * {@code true}, then dispatchDragEvent() returns {@code true}. |
| 12967 | * <p> |
| 12968 | * For all other cases, the method calls the |
| 12969 | * {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} drag event handler |
| 12970 | * method and returns its result. |
| 12971 | * </p> |
| 12972 | * <p> |
| 12973 | * This ensures that a drag event is always consumed, even if the View does not have a drag |
| 12974 | * event listener. However, if the View has a listener and the listener returns true, then |
| 12975 | * onDragEvent() is not called. |
| 12976 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 12977 | */ |
| 12978 | public boolean dispatchDragEvent(DragEvent event) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12979 | //noinspection SimplifiableIfStatement |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 12980 | if (mOnDragListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 12981 | && mOnDragListener.onDrag(this, event)) { |
| 12982 | return true; |
| 12983 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 12984 | return onDragEvent(event); |
| 12985 | } |
| 12986 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 12987 | boolean canAcceptDrag() { |
| 12988 | return (mPrivateFlags2 & DRAG_CAN_ACCEPT) != 0; |
| 12989 | } |
| 12990 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 12991 | /** |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 12992 | * This needs to be a better API (NOT ON VIEW) before it is exposed. If |
| 12993 | * it is ever exposed at all. |
Dianne Hackborn | 29e4a3c | 2009-09-30 22:35:40 -0700 | [diff] [blame] | 12994 | * @hide |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 12995 | */ |
| 12996 | public void onCloseSystemDialogs(String reason) { |
| 12997 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12998 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 12999 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13000 | * 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] | 13001 | * update a Region being computed for |
| 13002 | * {@link #gatherTransparentRegion(android.graphics.Region)} so |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13003 | * that any non-transparent parts of the Drawable are removed from the |
| 13004 | * given transparent region. |
| 13005 | * |
| 13006 | * @param dr The Drawable whose transparency is to be applied to the region. |
| 13007 | * @param region A Region holding the current transparency information, |
| 13008 | * where any parts of the region that are set are considered to be |
| 13009 | * transparent. On return, this region will be modified to have the |
| 13010 | * transparency information reduced by the corresponding parts of the |
| 13011 | * Drawable that are not transparent. |
| 13012 | * {@hide} |
| 13013 | */ |
| 13014 | public void applyDrawableToTransparentRegion(Drawable dr, Region region) { |
| 13015 | if (DBG) { |
| 13016 | Log.i("View", "Getting transparent region for: " + this); |
| 13017 | } |
| 13018 | final Region r = dr.getTransparentRegion(); |
| 13019 | final Rect db = dr.getBounds(); |
| 13020 | final AttachInfo attachInfo = mAttachInfo; |
| 13021 | if (r != null && attachInfo != null) { |
| 13022 | final int w = getRight()-getLeft(); |
| 13023 | final int h = getBottom()-getTop(); |
| 13024 | if (db.left > 0) { |
| 13025 | //Log.i("VIEW", "Drawable left " + db.left + " > view 0"); |
| 13026 | r.op(0, 0, db.left, h, Region.Op.UNION); |
| 13027 | } |
| 13028 | if (db.right < w) { |
| 13029 | //Log.i("VIEW", "Drawable right " + db.right + " < view " + w); |
| 13030 | r.op(db.right, 0, w, h, Region.Op.UNION); |
| 13031 | } |
| 13032 | if (db.top > 0) { |
| 13033 | //Log.i("VIEW", "Drawable top " + db.top + " > view 0"); |
| 13034 | r.op(0, 0, w, db.top, Region.Op.UNION); |
| 13035 | } |
| 13036 | if (db.bottom < h) { |
| 13037 | //Log.i("VIEW", "Drawable bottom " + db.bottom + " < view " + h); |
| 13038 | r.op(0, db.bottom, w, h, Region.Op.UNION); |
| 13039 | } |
| 13040 | final int[] location = attachInfo.mTransparentLocation; |
| 13041 | getLocationInWindow(location); |
| 13042 | r.translate(location[0], location[1]); |
| 13043 | region.op(r, Region.Op.INTERSECT); |
| 13044 | } else { |
| 13045 | region.op(db, Region.Op.DIFFERENCE); |
| 13046 | } |
| 13047 | } |
| 13048 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 13049 | private void checkForLongClick(int delayOffset) { |
| 13050 | if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) { |
| 13051 | mHasPerformedLongPress = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13052 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 13053 | if (mPendingCheckForLongPress == null) { |
| 13054 | mPendingCheckForLongPress = new CheckForLongPress(); |
| 13055 | } |
| 13056 | mPendingCheckForLongPress.rememberWindowAttachCount(); |
| 13057 | postDelayed(mPendingCheckForLongPress, |
| 13058 | ViewConfiguration.getLongPressTimeout() - delayOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13059 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13060 | } |
| 13061 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13062 | /** |
| 13063 | * Inflate a view from an XML resource. This convenience method wraps the {@link |
| 13064 | * LayoutInflater} class, which provides a full range of options for view inflation. |
| 13065 | * |
| 13066 | * @param context The Context object for your activity or application. |
| 13067 | * @param resource The resource ID to inflate |
| 13068 | * @param root A view group that will be the parent. Used to properly inflate the |
| 13069 | * layout_* parameters. |
| 13070 | * @see LayoutInflater |
| 13071 | */ |
| 13072 | public static View inflate(Context context, int resource, ViewGroup root) { |
| 13073 | LayoutInflater factory = LayoutInflater.from(context); |
| 13074 | return factory.inflate(resource, root); |
| 13075 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 13076 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13077 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 13078 | * Scroll the view with standard behavior for scrolling beyond the normal |
| 13079 | * content boundaries. Views that call this method should override |
| 13080 | * {@link #onOverScrolled(int, int, boolean, boolean)} to respond to the |
| 13081 | * results of an over-scroll operation. |
| 13082 | * |
| 13083 | * Views can use this method to handle any touch or fling-based scrolling. |
| 13084 | * |
| 13085 | * @param deltaX Change in X in pixels |
| 13086 | * @param deltaY Change in Y in pixels |
| 13087 | * @param scrollX Current X scroll value in pixels before applying deltaX |
| 13088 | * @param scrollY Current Y scroll value in pixels before applying deltaY |
| 13089 | * @param scrollRangeX Maximum content scroll range along the X axis |
| 13090 | * @param scrollRangeY Maximum content scroll range along the Y axis |
| 13091 | * @param maxOverScrollX Number of pixels to overscroll by in either direction |
| 13092 | * along the X axis. |
| 13093 | * @param maxOverScrollY Number of pixels to overscroll by in either direction |
| 13094 | * along the Y axis. |
| 13095 | * @param isTouchEvent true if this scroll operation is the result of a touch event. |
| 13096 | * @return true if scrolling was clamped to an over-scroll boundary along either |
| 13097 | * axis, false otherwise. |
| 13098 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13099 | @SuppressWarnings({"UnusedParameters"}) |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 13100 | protected boolean overScrollBy(int deltaX, int deltaY, |
| 13101 | int scrollX, int scrollY, |
| 13102 | int scrollRangeX, int scrollRangeY, |
| 13103 | int maxOverScrollX, int maxOverScrollY, |
| 13104 | boolean isTouchEvent) { |
| 13105 | final int overScrollMode = mOverScrollMode; |
| 13106 | final boolean canScrollHorizontal = |
| 13107 | computeHorizontalScrollRange() > computeHorizontalScrollExtent(); |
| 13108 | final boolean canScrollVertical = |
| 13109 | computeVerticalScrollRange() > computeVerticalScrollExtent(); |
| 13110 | final boolean overScrollHorizontal = overScrollMode == OVER_SCROLL_ALWAYS || |
| 13111 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollHorizontal); |
| 13112 | final boolean overScrollVertical = overScrollMode == OVER_SCROLL_ALWAYS || |
| 13113 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollVertical); |
| 13114 | |
| 13115 | int newScrollX = scrollX + deltaX; |
| 13116 | if (!overScrollHorizontal) { |
| 13117 | maxOverScrollX = 0; |
| 13118 | } |
| 13119 | |
| 13120 | int newScrollY = scrollY + deltaY; |
| 13121 | if (!overScrollVertical) { |
| 13122 | maxOverScrollY = 0; |
| 13123 | } |
| 13124 | |
| 13125 | // Clamp values if at the limits and record |
| 13126 | final int left = -maxOverScrollX; |
| 13127 | final int right = maxOverScrollX + scrollRangeX; |
| 13128 | final int top = -maxOverScrollY; |
| 13129 | final int bottom = maxOverScrollY + scrollRangeY; |
| 13130 | |
| 13131 | boolean clampedX = false; |
| 13132 | if (newScrollX > right) { |
| 13133 | newScrollX = right; |
| 13134 | clampedX = true; |
| 13135 | } else if (newScrollX < left) { |
| 13136 | newScrollX = left; |
| 13137 | clampedX = true; |
| 13138 | } |
| 13139 | |
| 13140 | boolean clampedY = false; |
| 13141 | if (newScrollY > bottom) { |
| 13142 | newScrollY = bottom; |
| 13143 | clampedY = true; |
| 13144 | } else if (newScrollY < top) { |
| 13145 | newScrollY = top; |
| 13146 | clampedY = true; |
| 13147 | } |
| 13148 | |
| 13149 | onOverScrolled(newScrollX, newScrollY, clampedX, clampedY); |
| 13150 | |
| 13151 | return clampedX || clampedY; |
| 13152 | } |
| 13153 | |
| 13154 | /** |
| 13155 | * Called by {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)} to |
| 13156 | * respond to the results of an over-scroll operation. |
| 13157 | * |
| 13158 | * @param scrollX New X scroll value in pixels |
| 13159 | * @param scrollY New Y scroll value in pixels |
| 13160 | * @param clampedX True if scrollX was clamped to an over-scroll boundary |
| 13161 | * @param clampedY True if scrollY was clamped to an over-scroll boundary |
| 13162 | */ |
| 13163 | protected void onOverScrolled(int scrollX, int scrollY, |
| 13164 | boolean clampedX, boolean clampedY) { |
| 13165 | // Intentionally empty. |
| 13166 | } |
| 13167 | |
| 13168 | /** |
| 13169 | * Returns the over-scroll mode for this view. The result will be |
| 13170 | * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 13171 | * (allow over-scrolling only if the view content is larger than the container), |
| 13172 | * or {@link #OVER_SCROLL_NEVER}. |
| 13173 | * |
| 13174 | * @return This view's over-scroll mode. |
| 13175 | */ |
| 13176 | public int getOverScrollMode() { |
| 13177 | return mOverScrollMode; |
| 13178 | } |
| 13179 | |
| 13180 | /** |
| 13181 | * Set the over-scroll mode for this view. Valid over-scroll modes are |
| 13182 | * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 13183 | * (allow over-scrolling only if the view content is larger than the container), |
| 13184 | * or {@link #OVER_SCROLL_NEVER}. |
| 13185 | * |
| 13186 | * Setting the over-scroll mode of a view will have an effect only if the |
| 13187 | * view is capable of scrolling. |
| 13188 | * |
| 13189 | * @param overScrollMode The new over-scroll mode for this view. |
| 13190 | */ |
| 13191 | public void setOverScrollMode(int overScrollMode) { |
| 13192 | if (overScrollMode != OVER_SCROLL_ALWAYS && |
| 13193 | overScrollMode != OVER_SCROLL_IF_CONTENT_SCROLLS && |
| 13194 | overScrollMode != OVER_SCROLL_NEVER) { |
| 13195 | throw new IllegalArgumentException("Invalid overscroll mode " + overScrollMode); |
| 13196 | } |
| 13197 | mOverScrollMode = overScrollMode; |
| 13198 | } |
| 13199 | |
| 13200 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 13201 | * Gets a scale factor that determines the distance the view should scroll |
| 13202 | * vertically in response to {@link MotionEvent#ACTION_SCROLL}. |
| 13203 | * @return The vertical scroll scale factor. |
| 13204 | * @hide |
| 13205 | */ |
| 13206 | protected float getVerticalScrollFactor() { |
| 13207 | if (mVerticalScrollFactor == 0) { |
| 13208 | TypedValue outValue = new TypedValue(); |
| 13209 | if (!mContext.getTheme().resolveAttribute( |
| 13210 | com.android.internal.R.attr.listPreferredItemHeight, outValue, true)) { |
| 13211 | throw new IllegalStateException( |
| 13212 | "Expected theme to define listPreferredItemHeight."); |
| 13213 | } |
| 13214 | mVerticalScrollFactor = outValue.getDimension( |
| 13215 | mContext.getResources().getDisplayMetrics()); |
| 13216 | } |
| 13217 | return mVerticalScrollFactor; |
| 13218 | } |
| 13219 | |
| 13220 | /** |
| 13221 | * Gets a scale factor that determines the distance the view should scroll |
| 13222 | * horizontally in response to {@link MotionEvent#ACTION_SCROLL}. |
| 13223 | * @return The horizontal scroll scale factor. |
| 13224 | * @hide |
| 13225 | */ |
| 13226 | protected float getHorizontalScrollFactor() { |
| 13227 | // TODO: Should use something else. |
| 13228 | return getVerticalScrollFactor(); |
| 13229 | } |
| 13230 | |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13231 | /** |
| 13232 | * Return the value specifying the text direction or policy that was set with |
| 13233 | * {@link #setTextDirection(int)}. |
| 13234 | * |
| 13235 | * @return the defined text direction. It can be one of: |
| 13236 | * |
| 13237 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 13238 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 13239 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
Fabrice Di Meglio | 8f50265 | 2011-06-29 20:40:43 -0700 | [diff] [blame] | 13240 | * {@link #TEXT_DIRECTION_CHAR_COUNT}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13241 | * {@link #TEXT_DIRECTION_LTR}, |
| 13242 | * {@link #TEXT_DIRECTION_RTL}, |
| 13243 | * |
| 13244 | * @hide |
| 13245 | */ |
| 13246 | public int getTextDirection() { |
| 13247 | return mTextDirection; |
| 13248 | } |
| 13249 | |
| 13250 | /** |
| 13251 | * Set the text direction. |
| 13252 | * |
| 13253 | * @param textDirection the direction to set. Should be one of: |
| 13254 | * |
| 13255 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 13256 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 13257 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
Fabrice Di Meglio | 8f50265 | 2011-06-29 20:40:43 -0700 | [diff] [blame] | 13258 | * {@link #TEXT_DIRECTION_CHAR_COUNT}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13259 | * {@link #TEXT_DIRECTION_LTR}, |
| 13260 | * {@link #TEXT_DIRECTION_RTL}, |
| 13261 | * |
| 13262 | * @hide |
| 13263 | */ |
| 13264 | public void setTextDirection(int textDirection) { |
| 13265 | if (textDirection != mTextDirection) { |
| 13266 | mTextDirection = textDirection; |
| 13267 | resetResolvedTextDirection(); |
| 13268 | requestLayout(); |
| 13269 | } |
| 13270 | } |
| 13271 | |
| 13272 | /** |
| 13273 | * Return the resolved text direction. |
| 13274 | * |
| 13275 | * @return the resolved text direction. Return one of: |
| 13276 | * |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13277 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 13278 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 13279 | * {@link #TEXT_DIRECTION_CHAR_COUNT}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13280 | * {@link #TEXT_DIRECTION_LTR}, |
| 13281 | * {@link #TEXT_DIRECTION_RTL}, |
| 13282 | * |
| 13283 | * @hide |
| 13284 | */ |
| 13285 | public int getResolvedTextDirection() { |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13286 | if (mResolvedTextDirection == TEXT_DIRECTION_INHERIT) { |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13287 | resolveTextDirection(); |
| 13288 | } |
| 13289 | return mResolvedTextDirection; |
| 13290 | } |
| 13291 | |
| 13292 | /** |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13293 | * Resolve the text direction. |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13294 | */ |
| 13295 | protected void resolveTextDirection() { |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13296 | if (mTextDirection != TEXT_DIRECTION_INHERIT) { |
| 13297 | mResolvedTextDirection = mTextDirection; |
| 13298 | return; |
| 13299 | } |
| 13300 | if (mParent != null && mParent instanceof ViewGroup) { |
| 13301 | mResolvedTextDirection = ((ViewGroup) mParent).getResolvedTextDirection(); |
| 13302 | return; |
| 13303 | } |
| 13304 | mResolvedTextDirection = TEXT_DIRECTION_FIRST_STRONG; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13305 | } |
| 13306 | |
| 13307 | /** |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13308 | * Reset resolved text direction. Will be resolved during a call to getResolvedTextDirection(). |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13309 | */ |
| 13310 | protected void resetResolvedTextDirection() { |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13311 | mResolvedTextDirection = TEXT_DIRECTION_INHERIT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13312 | } |
| 13313 | |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13314 | // |
| 13315 | // Properties |
| 13316 | // |
| 13317 | /** |
| 13318 | * A Property wrapper around the <code>alpha</code> functionality handled by the |
| 13319 | * {@link View#setAlpha(float)} and {@link View#getAlpha()} methods. |
| 13320 | */ |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 13321 | public static Property<View, Float> ALPHA = new FloatProperty<View>("alpha") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13322 | @Override |
| 13323 | public void setValue(View object, float value) { |
| 13324 | object.setAlpha(value); |
| 13325 | } |
| 13326 | |
| 13327 | @Override |
| 13328 | public Float get(View object) { |
| 13329 | return object.getAlpha(); |
| 13330 | } |
| 13331 | }; |
| 13332 | |
| 13333 | /** |
| 13334 | * A Property wrapper around the <code>translationX</code> functionality handled by the |
| 13335 | * {@link View#setTranslationX(float)} and {@link View#getTranslationX()} methods. |
| 13336 | */ |
| 13337 | public static Property<View, Float> TRANSLATION_X = new FloatProperty<View>("translationX") { |
| 13338 | @Override |
| 13339 | public void setValue(View object, float value) { |
| 13340 | object.setTranslationX(value); |
| 13341 | } |
| 13342 | |
| 13343 | @Override |
| 13344 | public Float get(View object) { |
| 13345 | return object.getTranslationX(); |
| 13346 | } |
| 13347 | }; |
| 13348 | |
| 13349 | /** |
| 13350 | * A Property wrapper around the <code>translationY</code> functionality handled by the |
| 13351 | * {@link View#setTranslationY(float)} and {@link View#getTranslationY()} methods. |
| 13352 | */ |
| 13353 | public static Property<View, Float> TRANSLATION_Y = new FloatProperty<View>("translationY") { |
| 13354 | @Override |
| 13355 | public void setValue(View object, float value) { |
| 13356 | object.setTranslationY(value); |
| 13357 | } |
| 13358 | |
| 13359 | @Override |
| 13360 | public Float get(View object) { |
| 13361 | return object.getTranslationY(); |
| 13362 | } |
| 13363 | }; |
| 13364 | |
| 13365 | /** |
| 13366 | * A Property wrapper around the <code>x</code> functionality handled by the |
| 13367 | * {@link View#setX(float)} and {@link View#getX()} methods. |
| 13368 | */ |
| 13369 | public static Property<View, Float> X = new FloatProperty<View>("x") { |
| 13370 | @Override |
| 13371 | public void setValue(View object, float value) { |
| 13372 | object.setX(value); |
| 13373 | } |
| 13374 | |
| 13375 | @Override |
| 13376 | public Float get(View object) { |
| 13377 | return object.getX(); |
| 13378 | } |
| 13379 | }; |
| 13380 | |
| 13381 | /** |
| 13382 | * A Property wrapper around the <code>y</code> functionality handled by the |
| 13383 | * {@link View#setY(float)} and {@link View#getY()} methods. |
| 13384 | */ |
| 13385 | public static Property<View, Float> Y = new FloatProperty<View>("y") { |
| 13386 | @Override |
| 13387 | public void setValue(View object, float value) { |
| 13388 | object.setY(value); |
| 13389 | } |
| 13390 | |
| 13391 | @Override |
| 13392 | public Float get(View object) { |
| 13393 | return object.getY(); |
| 13394 | } |
| 13395 | }; |
| 13396 | |
| 13397 | /** |
| 13398 | * A Property wrapper around the <code>rotation</code> functionality handled by the |
| 13399 | * {@link View#setRotation(float)} and {@link View#getRotation()} methods. |
| 13400 | */ |
| 13401 | public static Property<View, Float> ROTATION = new FloatProperty<View>("rotation") { |
| 13402 | @Override |
| 13403 | public void setValue(View object, float value) { |
| 13404 | object.setRotation(value); |
| 13405 | } |
| 13406 | |
| 13407 | @Override |
| 13408 | public Float get(View object) { |
| 13409 | return object.getRotation(); |
| 13410 | } |
| 13411 | }; |
| 13412 | |
| 13413 | /** |
| 13414 | * A Property wrapper around the <code>rotationX</code> functionality handled by the |
| 13415 | * {@link View#setRotationX(float)} and {@link View#getRotationX()} methods. |
| 13416 | */ |
| 13417 | public static Property<View, Float> ROTATION_X = new FloatProperty<View>("rotationX") { |
| 13418 | @Override |
| 13419 | public void setValue(View object, float value) { |
| 13420 | object.setRotationX(value); |
| 13421 | } |
| 13422 | |
| 13423 | @Override |
| 13424 | public Float get(View object) { |
| 13425 | return object.getRotationX(); |
| 13426 | } |
| 13427 | }; |
| 13428 | |
| 13429 | /** |
| 13430 | * A Property wrapper around the <code>rotationY</code> functionality handled by the |
| 13431 | * {@link View#setRotationY(float)} and {@link View#getRotationY()} methods. |
| 13432 | */ |
| 13433 | public static Property<View, Float> ROTATION_Y = new FloatProperty<View>("rotationY") { |
| 13434 | @Override |
| 13435 | public void setValue(View object, float value) { |
| 13436 | object.setRotationY(value); |
| 13437 | } |
| 13438 | |
| 13439 | @Override |
| 13440 | public Float get(View object) { |
| 13441 | return object.getRotationY(); |
| 13442 | } |
| 13443 | }; |
| 13444 | |
| 13445 | /** |
| 13446 | * A Property wrapper around the <code>scaleX</code> functionality handled by the |
| 13447 | * {@link View#setScaleX(float)} and {@link View#getScaleX()} methods. |
| 13448 | */ |
| 13449 | public static Property<View, Float> SCALE_X = new FloatProperty<View>("scaleX") { |
| 13450 | @Override |
| 13451 | public void setValue(View object, float value) { |
| 13452 | object.setScaleX(value); |
| 13453 | } |
| 13454 | |
| 13455 | @Override |
| 13456 | public Float get(View object) { |
| 13457 | return object.getScaleX(); |
| 13458 | } |
| 13459 | }; |
| 13460 | |
| 13461 | /** |
| 13462 | * A Property wrapper around the <code>scaleY</code> functionality handled by the |
| 13463 | * {@link View#setScaleY(float)} and {@link View#getScaleY()} methods. |
| 13464 | */ |
| 13465 | public static Property<View, Float> SCALE_Y = new FloatProperty<View>("scaleY") { |
| 13466 | @Override |
| 13467 | public void setValue(View object, float value) { |
| 13468 | object.setScaleY(value); |
| 13469 | } |
| 13470 | |
| 13471 | @Override |
| 13472 | public Float get(View object) { |
| 13473 | return object.getScaleY(); |
| 13474 | } |
| 13475 | }; |
| 13476 | |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 13477 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13478 | * A MeasureSpec encapsulates the layout requirements passed from parent to child. |
| 13479 | * Each MeasureSpec represents a requirement for either the width or the height. |
| 13480 | * A MeasureSpec is comprised of a size and a mode. There are three possible |
| 13481 | * modes: |
| 13482 | * <dl> |
| 13483 | * <dt>UNSPECIFIED</dt> |
| 13484 | * <dd> |
| 13485 | * The parent has not imposed any constraint on the child. It can be whatever size |
| 13486 | * it wants. |
| 13487 | * </dd> |
| 13488 | * |
| 13489 | * <dt>EXACTLY</dt> |
| 13490 | * <dd> |
| 13491 | * The parent has determined an exact size for the child. The child is going to be |
| 13492 | * given those bounds regardless of how big it wants to be. |
| 13493 | * </dd> |
| 13494 | * |
| 13495 | * <dt>AT_MOST</dt> |
| 13496 | * <dd> |
| 13497 | * The child can be as large as it wants up to the specified size. |
| 13498 | * </dd> |
| 13499 | * </dl> |
| 13500 | * |
| 13501 | * MeasureSpecs are implemented as ints to reduce object allocation. This class |
| 13502 | * is provided to pack and unpack the <size, mode> tuple into the int. |
| 13503 | */ |
| 13504 | public static class MeasureSpec { |
| 13505 | private static final int MODE_SHIFT = 30; |
| 13506 | private static final int MODE_MASK = 0x3 << MODE_SHIFT; |
| 13507 | |
| 13508 | /** |
| 13509 | * Measure specification mode: The parent has not imposed any constraint |
| 13510 | * on the child. It can be whatever size it wants. |
| 13511 | */ |
| 13512 | public static final int UNSPECIFIED = 0 << MODE_SHIFT; |
| 13513 | |
| 13514 | /** |
| 13515 | * Measure specification mode: The parent has determined an exact size |
| 13516 | * for the child. The child is going to be given those bounds regardless |
| 13517 | * of how big it wants to be. |
| 13518 | */ |
| 13519 | public static final int EXACTLY = 1 << MODE_SHIFT; |
| 13520 | |
| 13521 | /** |
| 13522 | * Measure specification mode: The child can be as large as it wants up |
| 13523 | * to the specified size. |
| 13524 | */ |
| 13525 | public static final int AT_MOST = 2 << MODE_SHIFT; |
| 13526 | |
| 13527 | /** |
| 13528 | * Creates a measure specification based on the supplied size and mode. |
| 13529 | * |
| 13530 | * The mode must always be one of the following: |
| 13531 | * <ul> |
| 13532 | * <li>{@link android.view.View.MeasureSpec#UNSPECIFIED}</li> |
| 13533 | * <li>{@link android.view.View.MeasureSpec#EXACTLY}</li> |
| 13534 | * <li>{@link android.view.View.MeasureSpec#AT_MOST}</li> |
| 13535 | * </ul> |
| 13536 | * |
| 13537 | * @param size the size of the measure specification |
| 13538 | * @param mode the mode of the measure specification |
| 13539 | * @return the measure specification based on size and mode |
| 13540 | */ |
| 13541 | public static int makeMeasureSpec(int size, int mode) { |
| 13542 | return size + mode; |
| 13543 | } |
| 13544 | |
| 13545 | /** |
| 13546 | * Extracts the mode from the supplied measure specification. |
| 13547 | * |
| 13548 | * @param measureSpec the measure specification to extract the mode from |
| 13549 | * @return {@link android.view.View.MeasureSpec#UNSPECIFIED}, |
| 13550 | * {@link android.view.View.MeasureSpec#AT_MOST} or |
| 13551 | * {@link android.view.View.MeasureSpec#EXACTLY} |
| 13552 | */ |
| 13553 | public static int getMode(int measureSpec) { |
| 13554 | return (measureSpec & MODE_MASK); |
| 13555 | } |
| 13556 | |
| 13557 | /** |
| 13558 | * Extracts the size from the supplied measure specification. |
| 13559 | * |
| 13560 | * @param measureSpec the measure specification to extract the size from |
| 13561 | * @return the size in pixels defined in the supplied measure specification |
| 13562 | */ |
| 13563 | public static int getSize(int measureSpec) { |
| 13564 | return (measureSpec & ~MODE_MASK); |
| 13565 | } |
| 13566 | |
| 13567 | /** |
| 13568 | * Returns a String representation of the specified measure |
| 13569 | * specification. |
| 13570 | * |
| 13571 | * @param measureSpec the measure specification to convert to a String |
| 13572 | * @return a String with the following format: "MeasureSpec: MODE SIZE" |
| 13573 | */ |
| 13574 | public static String toString(int measureSpec) { |
| 13575 | int mode = getMode(measureSpec); |
| 13576 | int size = getSize(measureSpec); |
| 13577 | |
| 13578 | StringBuilder sb = new StringBuilder("MeasureSpec: "); |
| 13579 | |
| 13580 | if (mode == UNSPECIFIED) |
| 13581 | sb.append("UNSPECIFIED "); |
| 13582 | else if (mode == EXACTLY) |
| 13583 | sb.append("EXACTLY "); |
| 13584 | else if (mode == AT_MOST) |
| 13585 | sb.append("AT_MOST "); |
| 13586 | else |
| 13587 | sb.append(mode).append(" "); |
| 13588 | |
| 13589 | sb.append(size); |
| 13590 | return sb.toString(); |
| 13591 | } |
| 13592 | } |
| 13593 | |
| 13594 | class CheckForLongPress implements Runnable { |
| 13595 | |
| 13596 | private int mOriginalWindowAttachCount; |
| 13597 | |
| 13598 | public void run() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 13599 | if (isPressed() && (mParent != null) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13600 | && mOriginalWindowAttachCount == mWindowAttachCount) { |
| 13601 | if (performLongClick()) { |
| 13602 | mHasPerformedLongPress = true; |
| 13603 | } |
| 13604 | } |
| 13605 | } |
| 13606 | |
| 13607 | public void rememberWindowAttachCount() { |
| 13608 | mOriginalWindowAttachCount = mWindowAttachCount; |
| 13609 | } |
| 13610 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13611 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 13612 | private final class CheckForTap implements Runnable { |
| 13613 | public void run() { |
| 13614 | mPrivateFlags &= ~PREPRESSED; |
| 13615 | mPrivateFlags |= PRESSED; |
| 13616 | refreshDrawableState(); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 13617 | checkForLongClick(ViewConfiguration.getTapTimeout()); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 13618 | } |
| 13619 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13620 | |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 13621 | private final class PerformClick implements Runnable { |
| 13622 | public void run() { |
| 13623 | performClick(); |
| 13624 | } |
| 13625 | } |
| 13626 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 13627 | /** @hide */ |
| 13628 | public void hackTurnOffWindowResizeAnim(boolean off) { |
| 13629 | mAttachInfo.mTurnOffWindowResizeAnim = off; |
| 13630 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13631 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13632 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 13633 | * This method returns a ViewPropertyAnimator object, which can be used to animate |
| 13634 | * specific properties on this View. |
| 13635 | * |
| 13636 | * @return ViewPropertyAnimator The ViewPropertyAnimator associated with this View. |
| 13637 | */ |
| 13638 | public ViewPropertyAnimator animate() { |
| 13639 | if (mAnimator == null) { |
| 13640 | mAnimator = new ViewPropertyAnimator(this); |
| 13641 | } |
| 13642 | return mAnimator; |
| 13643 | } |
| 13644 | |
| 13645 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13646 | * Interface definition for a callback to be invoked when a key event is |
| 13647 | * dispatched to this view. The callback will be invoked before the key |
| 13648 | * event is given to the view. |
| 13649 | */ |
| 13650 | public interface OnKeyListener { |
| 13651 | /** |
| 13652 | * Called when a key is dispatched to a view. This allows listeners to |
| 13653 | * get a chance to respond before the target view. |
| 13654 | * |
| 13655 | * @param v The view the key has been dispatched to. |
| 13656 | * @param keyCode The code for the physical key that was pressed |
| 13657 | * @param event The KeyEvent object containing full information about |
| 13658 | * the event. |
| 13659 | * @return True if the listener has consumed the event, false otherwise. |
| 13660 | */ |
| 13661 | boolean onKey(View v, int keyCode, KeyEvent event); |
| 13662 | } |
| 13663 | |
| 13664 | /** |
| 13665 | * Interface definition for a callback to be invoked when a touch event is |
| 13666 | * dispatched to this view. The callback will be invoked before the touch |
| 13667 | * event is given to the view. |
| 13668 | */ |
| 13669 | public interface OnTouchListener { |
| 13670 | /** |
| 13671 | * Called when a touch event is dispatched to a view. This allows listeners to |
| 13672 | * get a chance to respond before the target view. |
| 13673 | * |
| 13674 | * @param v The view the touch event has been dispatched to. |
| 13675 | * @param event The MotionEvent object containing full information about |
| 13676 | * the event. |
| 13677 | * @return True if the listener has consumed the event, false otherwise. |
| 13678 | */ |
| 13679 | boolean onTouch(View v, MotionEvent event); |
| 13680 | } |
| 13681 | |
| 13682 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 13683 | * Interface definition for a callback to be invoked when a hover event is |
| 13684 | * dispatched to this view. The callback will be invoked before the hover |
| 13685 | * event is given to the view. |
| 13686 | */ |
| 13687 | public interface OnHoverListener { |
| 13688 | /** |
| 13689 | * Called when a hover event is dispatched to a view. This allows listeners to |
| 13690 | * get a chance to respond before the target view. |
| 13691 | * |
| 13692 | * @param v The view the hover event has been dispatched to. |
| 13693 | * @param event The MotionEvent object containing full information about |
| 13694 | * the event. |
| 13695 | * @return True if the listener has consumed the event, false otherwise. |
| 13696 | */ |
| 13697 | boolean onHover(View v, MotionEvent event); |
| 13698 | } |
| 13699 | |
| 13700 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 13701 | * Interface definition for a callback to be invoked when a generic motion event is |
| 13702 | * dispatched to this view. The callback will be invoked before the generic motion |
| 13703 | * event is given to the view. |
| 13704 | */ |
| 13705 | public interface OnGenericMotionListener { |
| 13706 | /** |
| 13707 | * Called when a generic motion event is dispatched to a view. This allows listeners to |
| 13708 | * get a chance to respond before the target view. |
| 13709 | * |
| 13710 | * @param v The view the generic motion event has been dispatched to. |
| 13711 | * @param event The MotionEvent object containing full information about |
| 13712 | * the event. |
| 13713 | * @return True if the listener has consumed the event, false otherwise. |
| 13714 | */ |
| 13715 | boolean onGenericMotion(View v, MotionEvent event); |
| 13716 | } |
| 13717 | |
| 13718 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13719 | * Interface definition for a callback to be invoked when a view has been clicked and held. |
| 13720 | */ |
| 13721 | public interface OnLongClickListener { |
| 13722 | /** |
| 13723 | * Called when a view has been clicked and held. |
| 13724 | * |
| 13725 | * @param v The view that was clicked and held. |
| 13726 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 13727 | * @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] | 13728 | */ |
| 13729 | boolean onLongClick(View v); |
| 13730 | } |
| 13731 | |
| 13732 | /** |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 13733 | * Interface definition for a callback to be invoked when a drag is being dispatched |
| 13734 | * to this view. The callback will be invoked before the hosting view's own |
| 13735 | * onDrag(event) method. If the listener wants to fall back to the hosting view's |
| 13736 | * onDrag(event) behavior, it should return 'false' from this callback. |
| 13737 | */ |
| 13738 | public interface OnDragListener { |
| 13739 | /** |
| 13740 | * Called when a drag event is dispatched to a view. This allows listeners |
| 13741 | * to get a chance to override base View behavior. |
| 13742 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13743 | * @param v The View that received the drag event. |
| 13744 | * @param event The {@link android.view.DragEvent} object for the drag event. |
| 13745 | * @return {@code true} if the drag event was handled successfully, or {@code false} |
| 13746 | * if the drag event was not handled. Note that {@code false} will trigger the View |
| 13747 | * to call its {@link #onDragEvent(DragEvent) onDragEvent()} handler. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 13748 | */ |
| 13749 | boolean onDrag(View v, DragEvent event); |
| 13750 | } |
| 13751 | |
| 13752 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13753 | * Interface definition for a callback to be invoked when the focus state of |
| 13754 | * a view changed. |
| 13755 | */ |
| 13756 | public interface OnFocusChangeListener { |
| 13757 | /** |
| 13758 | * Called when the focus state of a view has changed. |
| 13759 | * |
| 13760 | * @param v The view whose state has changed. |
| 13761 | * @param hasFocus The new focus state of v. |
| 13762 | */ |
| 13763 | void onFocusChange(View v, boolean hasFocus); |
| 13764 | } |
| 13765 | |
| 13766 | /** |
| 13767 | * Interface definition for a callback to be invoked when a view is clicked. |
| 13768 | */ |
| 13769 | public interface OnClickListener { |
| 13770 | /** |
| 13771 | * Called when a view has been clicked. |
| 13772 | * |
| 13773 | * @param v The view that was clicked. |
| 13774 | */ |
| 13775 | void onClick(View v); |
| 13776 | } |
| 13777 | |
| 13778 | /** |
| 13779 | * Interface definition for a callback to be invoked when the context menu |
| 13780 | * for this view is being built. |
| 13781 | */ |
| 13782 | public interface OnCreateContextMenuListener { |
| 13783 | /** |
| 13784 | * Called when the context menu for this view is being built. It is not |
| 13785 | * safe to hold onto the menu after this method returns. |
| 13786 | * |
| 13787 | * @param menu The context menu that is being built |
| 13788 | * @param v The view for which the context menu is being built |
| 13789 | * @param menuInfo Extra information about the item for which the |
| 13790 | * context menu should be shown. This information will vary |
| 13791 | * depending on the class of v. |
| 13792 | */ |
| 13793 | void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo); |
| 13794 | } |
| 13795 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13796 | /** |
| 13797 | * Interface definition for a callback to be invoked when the status bar changes |
| 13798 | * visibility. |
| 13799 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 13800 | * @see View#setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13801 | */ |
| 13802 | public interface OnSystemUiVisibilityChangeListener { |
| 13803 | /** |
| 13804 | * Called when the status bar changes visibility because of a call to |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 13805 | * {@link View#setSystemUiVisibility(int)}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13806 | * |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 13807 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or |
| 13808 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13809 | */ |
| 13810 | public void onSystemUiVisibilityChange(int visibility); |
| 13811 | } |
| 13812 | |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 13813 | /** |
| 13814 | * Interface definition for a callback to be invoked when this view is attached |
| 13815 | * or detached from its window. |
| 13816 | */ |
| 13817 | public interface OnAttachStateChangeListener { |
| 13818 | /** |
| 13819 | * Called when the view is attached to a window. |
| 13820 | * @param v The view that was attached |
| 13821 | */ |
| 13822 | public void onViewAttachedToWindow(View v); |
| 13823 | /** |
| 13824 | * Called when the view is detached from a window. |
| 13825 | * @param v The view that was detached |
| 13826 | */ |
| 13827 | public void onViewDetachedFromWindow(View v); |
| 13828 | } |
| 13829 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13830 | private final class UnsetPressedState implements Runnable { |
| 13831 | public void run() { |
| 13832 | setPressed(false); |
| 13833 | } |
| 13834 | } |
| 13835 | |
| 13836 | /** |
| 13837 | * Base class for derived classes that want to save and restore their own |
| 13838 | * state in {@link android.view.View#onSaveInstanceState()}. |
| 13839 | */ |
| 13840 | public static class BaseSavedState extends AbsSavedState { |
| 13841 | /** |
| 13842 | * Constructor used when reading from a parcel. Reads the state of the superclass. |
| 13843 | * |
| 13844 | * @param source |
| 13845 | */ |
| 13846 | public BaseSavedState(Parcel source) { |
| 13847 | super(source); |
| 13848 | } |
| 13849 | |
| 13850 | /** |
| 13851 | * Constructor called by derived classes when creating their SavedState objects |
| 13852 | * |
| 13853 | * @param superState The state of the superclass of this view |
| 13854 | */ |
| 13855 | public BaseSavedState(Parcelable superState) { |
| 13856 | super(superState); |
| 13857 | } |
| 13858 | |
| 13859 | public static final Parcelable.Creator<BaseSavedState> CREATOR = |
| 13860 | new Parcelable.Creator<BaseSavedState>() { |
| 13861 | public BaseSavedState createFromParcel(Parcel in) { |
| 13862 | return new BaseSavedState(in); |
| 13863 | } |
| 13864 | |
| 13865 | public BaseSavedState[] newArray(int size) { |
| 13866 | return new BaseSavedState[size]; |
| 13867 | } |
| 13868 | }; |
| 13869 | } |
| 13870 | |
| 13871 | /** |
| 13872 | * A set of information given to a view when it is attached to its parent |
| 13873 | * window. |
| 13874 | */ |
| 13875 | static class AttachInfo { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13876 | interface Callbacks { |
| 13877 | void playSoundEffect(int effectId); |
| 13878 | boolean performHapticFeedback(int effectId, boolean always); |
| 13879 | } |
| 13880 | |
| 13881 | /** |
| 13882 | * InvalidateInfo is used to post invalidate(int, int, int, int) messages |
| 13883 | * to a Handler. This class contains the target (View) to invalidate and |
| 13884 | * the coordinates of the dirty rectangle. |
| 13885 | * |
| 13886 | * For performance purposes, this class also implements a pool of up to |
| 13887 | * POOL_LIMIT objects that get reused. This reduces memory allocations |
| 13888 | * whenever possible. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13889 | */ |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 13890 | static class InvalidateInfo implements Poolable<InvalidateInfo> { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13891 | private static final int POOL_LIMIT = 10; |
Romain Guy | 2e9bbce | 2009-04-01 10:40:10 -0700 | [diff] [blame] | 13892 | private static final Pool<InvalidateInfo> sPool = Pools.synchronizedPool( |
| 13893 | Pools.finitePool(new PoolableManager<InvalidateInfo>() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 13894 | public InvalidateInfo newInstance() { |
| 13895 | return new InvalidateInfo(); |
| 13896 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13897 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 13898 | public void onAcquired(InvalidateInfo element) { |
| 13899 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13900 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 13901 | public void onReleased(InvalidateInfo element) { |
Romain Guy | 40c18f5 | 2011-09-01 17:01:18 -0700 | [diff] [blame] | 13902 | element.target = null; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 13903 | } |
| 13904 | }, POOL_LIMIT) |
| 13905 | ); |
| 13906 | |
| 13907 | private InvalidateInfo mNext; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 13908 | private boolean mIsPooled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13909 | |
| 13910 | View target; |
| 13911 | |
| 13912 | int left; |
| 13913 | int top; |
| 13914 | int right; |
| 13915 | int bottom; |
| 13916 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 13917 | public void setNextPoolable(InvalidateInfo element) { |
| 13918 | mNext = element; |
| 13919 | } |
| 13920 | |
| 13921 | public InvalidateInfo getNextPoolable() { |
| 13922 | return mNext; |
| 13923 | } |
| 13924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13925 | static InvalidateInfo acquire() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 13926 | return sPool.acquire(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13927 | } |
| 13928 | |
| 13929 | void release() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 13930 | sPool.release(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13931 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 13932 | |
| 13933 | public boolean isPooled() { |
| 13934 | return mIsPooled; |
| 13935 | } |
| 13936 | |
| 13937 | public void setPooled(boolean isPooled) { |
| 13938 | mIsPooled = isPooled; |
| 13939 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13940 | } |
| 13941 | |
| 13942 | final IWindowSession mSession; |
| 13943 | |
| 13944 | final IWindow mWindow; |
| 13945 | |
| 13946 | final IBinder mWindowToken; |
| 13947 | |
| 13948 | final Callbacks mRootCallbacks; |
| 13949 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 13950 | HardwareCanvas mHardwareCanvas; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 13951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13952 | /** |
| 13953 | * The top view of the hierarchy. |
| 13954 | */ |
| 13955 | View mRootView; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13956 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13957 | IBinder mPanelParentWindowToken; |
| 13958 | Surface mSurface; |
| 13959 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 13960 | boolean mHardwareAccelerated; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 13961 | boolean mHardwareAccelerationRequested; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 13962 | HardwareRenderer mHardwareRenderer; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13963 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13964 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13965 | * Scale factor used by the compatibility mode |
| 13966 | */ |
| 13967 | float mApplicationScale; |
| 13968 | |
| 13969 | /** |
| 13970 | * Indicates whether the application is in compatibility mode |
| 13971 | */ |
| 13972 | boolean mScalingRequired; |
| 13973 | |
| 13974 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 13975 | * 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] | 13976 | */ |
| 13977 | boolean mTurnOffWindowResizeAnim; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13978 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 13979 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13980 | * Left position of this view's window |
| 13981 | */ |
| 13982 | int mWindowLeft; |
| 13983 | |
| 13984 | /** |
| 13985 | * Top position of this view's window |
| 13986 | */ |
| 13987 | int mWindowTop; |
| 13988 | |
| 13989 | /** |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 13990 | * Indicates whether views need to use 32-bit drawing caches |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 13991 | */ |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 13992 | boolean mUse32BitDrawingCache; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 13993 | |
| 13994 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13995 | * For windows that are full-screen but using insets to layout inside |
| 13996 | * of the screen decorations, these are the current insets for the |
| 13997 | * content of the window. |
| 13998 | */ |
| 13999 | final Rect mContentInsets = new Rect(); |
| 14000 | |
| 14001 | /** |
| 14002 | * For windows that are full-screen but using insets to layout inside |
| 14003 | * of the screen decorations, these are the current insets for the |
| 14004 | * actual visible parts of the window. |
| 14005 | */ |
| 14006 | final Rect mVisibleInsets = new Rect(); |
| 14007 | |
| 14008 | /** |
| 14009 | * The internal insets given by this window. This value is |
| 14010 | * supplied by the client (through |
| 14011 | * {@link ViewTreeObserver.OnComputeInternalInsetsListener}) and will |
| 14012 | * be given to the window manager when changed to be used in laying |
| 14013 | * out windows behind it. |
| 14014 | */ |
| 14015 | final ViewTreeObserver.InternalInsetsInfo mGivenInternalInsets |
| 14016 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 14017 | |
| 14018 | /** |
| 14019 | * All views in the window's hierarchy that serve as scroll containers, |
| 14020 | * used to determine if the window can be resized or must be panned |
| 14021 | * to adjust for a soft input area. |
| 14022 | */ |
| 14023 | final ArrayList<View> mScrollContainers = new ArrayList<View>(); |
| 14024 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 14025 | final KeyEvent.DispatcherState mKeyDispatchState |
| 14026 | = new KeyEvent.DispatcherState(); |
| 14027 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14028 | /** |
| 14029 | * Indicates whether the view's window currently has the focus. |
| 14030 | */ |
| 14031 | boolean mHasWindowFocus; |
| 14032 | |
| 14033 | /** |
| 14034 | * The current visibility of the window. |
| 14035 | */ |
| 14036 | int mWindowVisibility; |
| 14037 | |
| 14038 | /** |
| 14039 | * Indicates the time at which drawing started to occur. |
| 14040 | */ |
| 14041 | long mDrawingTime; |
| 14042 | |
| 14043 | /** |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 14044 | * Indicates whether or not ignoring the DIRTY_MASK flags. |
| 14045 | */ |
| 14046 | boolean mIgnoreDirtyState; |
| 14047 | |
| 14048 | /** |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 14049 | * This flag tracks when the mIgnoreDirtyState flag is set during draw(), |
| 14050 | * to avoid clearing that flag prematurely. |
| 14051 | */ |
| 14052 | boolean mSetIgnoreDirtyState = false; |
| 14053 | |
| 14054 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14055 | * Indicates whether the view's window is currently in touch mode. |
| 14056 | */ |
| 14057 | boolean mInTouchMode; |
| 14058 | |
| 14059 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 14060 | * Indicates that ViewAncestor should trigger a global layout change |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14061 | * the next time it performs a traversal |
| 14062 | */ |
| 14063 | boolean mRecomputeGlobalAttributes; |
| 14064 | |
| 14065 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14066 | * Set during a traveral if any views want to keep the screen on. |
| 14067 | */ |
| 14068 | boolean mKeepScreenOn; |
| 14069 | |
| 14070 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14071 | * Bitwise-or of all of the values that views have passed to setSystemUiVisibility(). |
| 14072 | */ |
| 14073 | int mSystemUiVisibility; |
| 14074 | |
| 14075 | /** |
| 14076 | * True if a view in this hierarchy has an OnSystemUiVisibilityChangeListener |
| 14077 | * attached. |
| 14078 | */ |
| 14079 | boolean mHasSystemUiListeners; |
| 14080 | |
| 14081 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14082 | * Set if the visibility of any views has changed. |
| 14083 | */ |
| 14084 | boolean mViewVisibilityChanged; |
| 14085 | |
| 14086 | /** |
| 14087 | * Set to true if a view has been scrolled. |
| 14088 | */ |
| 14089 | boolean mViewScrollChanged; |
| 14090 | |
| 14091 | /** |
| 14092 | * Global to the view hierarchy used as a temporary for dealing with |
| 14093 | * x/y points in the transparent region computations. |
| 14094 | */ |
| 14095 | final int[] mTransparentLocation = new int[2]; |
| 14096 | |
| 14097 | /** |
| 14098 | * Global to the view hierarchy used as a temporary for dealing with |
| 14099 | * x/y points in the ViewGroup.invalidateChild implementation. |
| 14100 | */ |
| 14101 | final int[] mInvalidateChildLocation = new int[2]; |
| 14102 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 14103 | |
| 14104 | /** |
| 14105 | * Global to the view hierarchy used as a temporary for dealing with |
| 14106 | * x/y location when view is transformed. |
| 14107 | */ |
| 14108 | final float[] mTmpTransformLocation = new float[2]; |
| 14109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14110 | /** |
| 14111 | * The view tree observer used to dispatch global events like |
| 14112 | * layout, pre-draw, touch mode change, etc. |
| 14113 | */ |
| 14114 | final ViewTreeObserver mTreeObserver = new ViewTreeObserver(); |
| 14115 | |
| 14116 | /** |
| 14117 | * A Canvas used by the view hierarchy to perform bitmap caching. |
| 14118 | */ |
| 14119 | Canvas mCanvas; |
| 14120 | |
| 14121 | /** |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 14122 | * 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] | 14123 | * handler can be used to pump events in the UI events queue. |
| 14124 | */ |
| 14125 | final Handler mHandler; |
| 14126 | |
| 14127 | /** |
| 14128 | * Identifier for messages requesting the view to be invalidated. |
| 14129 | * Such messages should be sent to {@link #mHandler}. |
| 14130 | */ |
| 14131 | static final int INVALIDATE_MSG = 0x1; |
| 14132 | |
| 14133 | /** |
| 14134 | * Identifier for messages requesting the view to invalidate a region. |
| 14135 | * Such messages should be sent to {@link #mHandler}. |
| 14136 | */ |
| 14137 | static final int INVALIDATE_RECT_MSG = 0x2; |
| 14138 | |
| 14139 | /** |
| 14140 | * Temporary for use in computing invalidate rectangles while |
| 14141 | * calling up the hierarchy. |
| 14142 | */ |
| 14143 | final Rect mTmpInvalRect = new Rect(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 14144 | |
| 14145 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 14146 | * Temporary for use in computing hit areas with transformed views |
| 14147 | */ |
| 14148 | final RectF mTmpTransformRect = new RectF(); |
| 14149 | |
| 14150 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 14151 | * Temporary list for use in collecting focusable descendents of a view. |
| 14152 | */ |
| 14153 | final ArrayList<View> mFocusablesTempList = new ArrayList<View>(24); |
| 14154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14155 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 14156 | * The id of the window for accessibility purposes. |
| 14157 | */ |
| 14158 | int mAccessibilityWindowId = View.NO_ID; |
| 14159 | |
| 14160 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14161 | * Creates a new set of attachment information with the specified |
| 14162 | * events handler and thread. |
| 14163 | * |
| 14164 | * @param handler the events handler the view must use |
| 14165 | */ |
| 14166 | AttachInfo(IWindowSession session, IWindow window, |
| 14167 | Handler handler, Callbacks effectPlayer) { |
| 14168 | mSession = session; |
| 14169 | mWindow = window; |
| 14170 | mWindowToken = window.asBinder(); |
| 14171 | mHandler = handler; |
| 14172 | mRootCallbacks = effectPlayer; |
| 14173 | } |
| 14174 | } |
| 14175 | |
| 14176 | /** |
| 14177 | * <p>ScrollabilityCache holds various fields used by a View when scrolling |
| 14178 | * is supported. This avoids keeping too many unused fields in most |
| 14179 | * instances of View.</p> |
| 14180 | */ |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14181 | private static class ScrollabilityCache implements Runnable { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14182 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14183 | /** |
| 14184 | * Scrollbars are not visible |
| 14185 | */ |
| 14186 | public static final int OFF = 0; |
| 14187 | |
| 14188 | /** |
| 14189 | * Scrollbars are visible |
| 14190 | */ |
| 14191 | public static final int ON = 1; |
| 14192 | |
| 14193 | /** |
| 14194 | * Scrollbars are fading away |
| 14195 | */ |
| 14196 | public static final int FADING = 2; |
| 14197 | |
| 14198 | public boolean fadeScrollBars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14200 | public int fadingEdgeLength; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14201 | public int scrollBarDefaultDelayBeforeFade; |
| 14202 | public int scrollBarFadeDuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14203 | |
| 14204 | public int scrollBarSize; |
| 14205 | public ScrollBarDrawable scrollBar; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14206 | public float[] interpolatorValues; |
| 14207 | public View host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14208 | |
| 14209 | public final Paint paint; |
| 14210 | public final Matrix matrix; |
| 14211 | public Shader shader; |
| 14212 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14213 | public final Interpolator scrollBarInterpolator = new Interpolator(1, 2); |
| 14214 | |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 14215 | private static final float[] OPAQUE = { 255 }; |
| 14216 | private static final float[] TRANSPARENT = { 0.0f }; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14217 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14218 | /** |
| 14219 | * When fading should start. This time moves into the future every time |
| 14220 | * a new scroll happens. Measured based on SystemClock.uptimeMillis() |
| 14221 | */ |
| 14222 | public long fadeStartTime; |
| 14223 | |
| 14224 | |
| 14225 | /** |
| 14226 | * The current state of the scrollbars: ON, OFF, or FADING |
| 14227 | */ |
| 14228 | public int state = OFF; |
| 14229 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14230 | private int mLastColor; |
| 14231 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14232 | public ScrollabilityCache(ViewConfiguration configuration, View host) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14233 | fadingEdgeLength = configuration.getScaledFadingEdgeLength(); |
| 14234 | scrollBarSize = configuration.getScaledScrollBarSize(); |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 14235 | scrollBarDefaultDelayBeforeFade = ViewConfiguration.getScrollDefaultDelay(); |
| 14236 | scrollBarFadeDuration = ViewConfiguration.getScrollBarFadeDuration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14237 | |
| 14238 | paint = new Paint(); |
| 14239 | matrix = new Matrix(); |
| 14240 | // use use a height of 1, and then wack the matrix each time we |
| 14241 | // actually use it. |
| 14242 | shader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14243 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14244 | paint.setShader(shader); |
| 14245 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14246 | this.host = host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14247 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14248 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14249 | public void setFadeColor(int color) { |
| 14250 | if (color != 0 && color != mLastColor) { |
| 14251 | mLastColor = color; |
| 14252 | color |= 0xFF000000; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14253 | |
Romain Guy | e55e1a7 | 2009-08-27 10:42:26 -0700 | [diff] [blame] | 14254 | shader = new LinearGradient(0, 0, 0, 1, color | 0xFF000000, |
| 14255 | color & 0x00FFFFFF, Shader.TileMode.CLAMP); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14256 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14257 | paint.setShader(shader); |
| 14258 | // Restore the default transfer mode (src_over) |
| 14259 | paint.setXfermode(null); |
| 14260 | } |
| 14261 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14262 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14263 | public void run() { |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 14264 | long now = AnimationUtils.currentAnimationTimeMillis(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14265 | if (now >= fadeStartTime) { |
| 14266 | |
| 14267 | // the animation fades the scrollbars out by changing |
| 14268 | // the opacity (alpha) from fully opaque to fully |
| 14269 | // transparent |
| 14270 | int nextFrame = (int) now; |
| 14271 | int framesCount = 0; |
| 14272 | |
| 14273 | Interpolator interpolator = scrollBarInterpolator; |
| 14274 | |
| 14275 | // Start opaque |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 14276 | interpolator.setKeyFrame(framesCount++, nextFrame, OPAQUE); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14277 | |
| 14278 | // End transparent |
| 14279 | nextFrame += scrollBarFadeDuration; |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 14280 | interpolator.setKeyFrame(framesCount, nextFrame, TRANSPARENT); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14281 | |
| 14282 | state = FADING; |
| 14283 | |
| 14284 | // Kick off the fade animation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14285 | host.invalidate(true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14286 | } |
| 14287 | } |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 14288 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14289 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 14290 | /** |
| 14291 | * Resuable callback for sending |
| 14292 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 14293 | */ |
| 14294 | private class SendViewScrolledAccessibilityEvent implements Runnable { |
| 14295 | public volatile boolean mIsPending; |
| 14296 | |
| 14297 | public void run() { |
| 14298 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED); |
| 14299 | mIsPending = false; |
| 14300 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14301 | } |
| 14302 | } |