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; |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 48 | import android.text.TextUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.util.AttributeSet; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 50 | import android.util.FloatProperty; |
| 51 | import android.util.LocaleUtil; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.util.Log; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 53 | import android.util.Pool; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 54 | import android.util.Poolable; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 55 | import android.util.PoolableManager; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 56 | import android.util.Pools; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 57 | import android.util.Property; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 58 | import android.util.SparseArray; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 59 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.view.ContextMenu.ContextMenuInfo; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 61 | import android.view.accessibility.AccessibilityEvent; |
| 62 | import android.view.accessibility.AccessibilityEventSource; |
| 63 | import android.view.accessibility.AccessibilityManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 64 | import android.view.accessibility.AccessibilityNodeInfo; |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 65 | import android.view.accessibility.AccessibilityNodeProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.view.animation.Animation; |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 67 | import android.view.animation.AnimationUtils; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 68 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.view.inputmethod.InputConnection; |
| 70 | import android.view.inputmethod.InputMethodManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.widget.ScrollBarDrawable; |
| 72 | |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 73 | import static android.os.Build.VERSION_CODES.*; |
| 74 | |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 75 | import com.android.internal.R; |
| 76 | import com.android.internal.util.Predicate; |
| 77 | import com.android.internal.view.menu.MenuBuilder; |
| 78 | |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 79 | import java.lang.ref.WeakReference; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 80 | import java.lang.reflect.InvocationTargetException; |
| 81 | import java.lang.reflect.Method; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import java.util.ArrayList; |
| 83 | import java.util.Arrays; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 84 | import java.util.Locale; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 85 | import java.util.concurrent.CopyOnWriteArrayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * <p> |
| 89 | * This class represents the basic building block for user interface components. A View |
| 90 | * occupies a rectangular area on the screen and is responsible for drawing and |
| 91 | * event handling. View is the base class for <em>widgets</em>, which are |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 92 | * used to create interactive UI components (buttons, text fields, etc.). The |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | * {@link android.view.ViewGroup} subclass is the base class for <em>layouts</em>, which |
| 94 | * are invisible containers that hold other Views (or other ViewGroups) and define |
| 95 | * their layout properties. |
| 96 | * </p> |
| 97 | * |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 98 | * <div class="special reference"> |
| 99 | * <h3>Developer Guides</h3> |
| 100 | * <p>For information about using this class to develop your application's user interface, |
| 101 | * read the <a href="{@docRoot}guide/topics/ui/index.html">User Interface</a> developer guide. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | * </div> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 103 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | * <a name="Using"></a> |
| 105 | * <h3>Using Views</h3> |
| 106 | * <p> |
| 107 | * All of the views in a window are arranged in a single tree. You can add views |
| 108 | * either from code or by specifying a tree of views in one or more XML layout |
| 109 | * files. There are many specialized subclasses of views that act as controls or |
| 110 | * are capable of displaying text, images, or other content. |
| 111 | * </p> |
| 112 | * <p> |
| 113 | * Once you have created a tree of views, there are typically a few types of |
| 114 | * common operations you may wish to perform: |
| 115 | * <ul> |
| 116 | * <li><strong>Set properties:</strong> for example setting the text of a |
| 117 | * {@link android.widget.TextView}. The available properties and the methods |
| 118 | * that set them will vary among the different subclasses of views. Note that |
| 119 | * properties that are known at build time can be set in the XML layout |
| 120 | * files.</li> |
| 121 | * <li><strong>Set focus:</strong> The framework will handled moving focus in |
| 122 | * response to user input. To force focus to a specific view, call |
| 123 | * {@link #requestFocus}.</li> |
| 124 | * <li><strong>Set up listeners:</strong> Views allow clients to set listeners |
| 125 | * that will be notified when something interesting happens to the view. For |
| 126 | * example, all views will let you set a listener to be notified when the view |
| 127 | * gains or loses focus. You can register such a listener using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 128 | * {@link #setOnFocusChangeListener(android.view.View.OnFocusChangeListener)}. |
| 129 | * Other view subclasses offer more specialized listeners. For example, a Button |
| 130 | * exposes a listener to notify clients when the button is clicked.</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | * <li><strong>Set visibility:</strong> You can hide or show views using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 132 | * {@link #setVisibility(int)}.</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | * </ul> |
| 134 | * </p> |
| 135 | * <p><em> |
| 136 | * Note: The Android framework is responsible for measuring, laying out and |
| 137 | * drawing views. You should not call methods that perform these actions on |
| 138 | * views yourself unless you are actually implementing a |
| 139 | * {@link android.view.ViewGroup}. |
| 140 | * </em></p> |
| 141 | * |
| 142 | * <a name="Lifecycle"></a> |
| 143 | * <h3>Implementing a Custom View</h3> |
| 144 | * |
| 145 | * <p> |
| 146 | * To implement a custom view, you will usually begin by providing overrides for |
| 147 | * some of the standard methods that the framework calls on all views. You do |
| 148 | * not need to override all of these methods. In fact, you can start by just |
| 149 | * overriding {@link #onDraw(android.graphics.Canvas)}. |
| 150 | * <table border="2" width="85%" align="center" cellpadding="5"> |
| 151 | * <thead> |
| 152 | * <tr><th>Category</th> <th>Methods</th> <th>Description</th></tr> |
| 153 | * </thead> |
| 154 | * |
| 155 | * <tbody> |
| 156 | * <tr> |
| 157 | * <td rowspan="2">Creation</td> |
| 158 | * <td>Constructors</td> |
| 159 | * <td>There is a form of the constructor that are called when the view |
| 160 | * is created from code and a form that is called when the view is |
| 161 | * inflated from a layout file. The second form should parse and apply |
| 162 | * any attributes defined in the layout file. |
| 163 | * </td> |
| 164 | * </tr> |
| 165 | * <tr> |
| 166 | * <td><code>{@link #onFinishInflate()}</code></td> |
| 167 | * <td>Called after a view and all of its children has been inflated |
| 168 | * from XML.</td> |
| 169 | * </tr> |
| 170 | * |
| 171 | * <tr> |
| 172 | * <td rowspan="3">Layout</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 173 | * <td><code>{@link #onMeasure(int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | * <td>Called to determine the size requirements for this view and all |
| 175 | * of its children. |
| 176 | * </td> |
| 177 | * </tr> |
| 178 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 179 | * <td><code>{@link #onLayout(boolean, int, int, int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | * <td>Called when this view should assign a size and position to all |
| 181 | * of its children. |
| 182 | * </td> |
| 183 | * </tr> |
| 184 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 185 | * <td><code>{@link #onSizeChanged(int, int, int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | * <td>Called when the size of this view has changed. |
| 187 | * </td> |
| 188 | * </tr> |
| 189 | * |
| 190 | * <tr> |
| 191 | * <td>Drawing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 192 | * <td><code>{@link #onDraw(android.graphics.Canvas)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | * <td>Called when the view should render its content. |
| 194 | * </td> |
| 195 | * </tr> |
| 196 | * |
| 197 | * <tr> |
| 198 | * <td rowspan="4">Event processing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 199 | * <td><code>{@link #onKeyDown(int, KeyEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | * <td>Called when a new key event occurs. |
| 201 | * </td> |
| 202 | * </tr> |
| 203 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 204 | * <td><code>{@link #onKeyUp(int, KeyEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | * <td>Called when a key up event occurs. |
| 206 | * </td> |
| 207 | * </tr> |
| 208 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 209 | * <td><code>{@link #onTrackballEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | * <td>Called when a trackball motion event occurs. |
| 211 | * </td> |
| 212 | * </tr> |
| 213 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 214 | * <td><code>{@link #onTouchEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | * <td>Called when a touch screen motion event occurs. |
| 216 | * </td> |
| 217 | * </tr> |
| 218 | * |
| 219 | * <tr> |
| 220 | * <td rowspan="2">Focus</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 221 | * <td><code>{@link #onFocusChanged(boolean, int, android.graphics.Rect)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | * <td>Called when the view gains or loses focus. |
| 223 | * </td> |
| 224 | * </tr> |
| 225 | * |
| 226 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 227 | * <td><code>{@link #onWindowFocusChanged(boolean)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | * <td>Called when the window containing the view gains or loses focus. |
| 229 | * </td> |
| 230 | * </tr> |
| 231 | * |
| 232 | * <tr> |
| 233 | * <td rowspan="3">Attaching</td> |
| 234 | * <td><code>{@link #onAttachedToWindow()}</code></td> |
| 235 | * <td>Called when the view is attached to a window. |
| 236 | * </td> |
| 237 | * </tr> |
| 238 | * |
| 239 | * <tr> |
| 240 | * <td><code>{@link #onDetachedFromWindow}</code></td> |
| 241 | * <td>Called when the view is detached from its window. |
| 242 | * </td> |
| 243 | * </tr> |
| 244 | * |
| 245 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 246 | * <td><code>{@link #onWindowVisibilityChanged(int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | * <td>Called when the visibility of the window containing the view |
| 248 | * has changed. |
| 249 | * </td> |
| 250 | * </tr> |
| 251 | * </tbody> |
| 252 | * |
| 253 | * </table> |
| 254 | * </p> |
| 255 | * |
| 256 | * <a name="IDs"></a> |
| 257 | * <h3>IDs</h3> |
| 258 | * Views may have an integer id associated with them. These ids are typically |
| 259 | * assigned in the layout XML files, and are used to find specific views within |
| 260 | * the view tree. A common pattern is to: |
| 261 | * <ul> |
| 262 | * <li>Define a Button in the layout file and assign it a unique ID. |
| 263 | * <pre> |
Gilles Debunne | 0243caf | 2010-08-24 23:06:35 -0700 | [diff] [blame] | 264 | * <Button |
| 265 | * android:id="@+id/my_button" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | * android:layout_width="wrap_content" |
| 267 | * android:layout_height="wrap_content" |
| 268 | * android:text="@string/my_button_text"/> |
| 269 | * </pre></li> |
| 270 | * <li>From the onCreate method of an Activity, find the Button |
| 271 | * <pre class="prettyprint"> |
| 272 | * Button myButton = (Button) findViewById(R.id.my_button); |
| 273 | * </pre></li> |
| 274 | * </ul> |
| 275 | * <p> |
| 276 | * View IDs need not be unique throughout the tree, but it is good practice to |
| 277 | * ensure that they are at least unique within the part of the tree you are |
| 278 | * searching. |
| 279 | * </p> |
| 280 | * |
| 281 | * <a name="Position"></a> |
| 282 | * <h3>Position</h3> |
| 283 | * <p> |
| 284 | * The geometry of a view is that of a rectangle. A view has a location, |
| 285 | * expressed as a pair of <em>left</em> and <em>top</em> coordinates, and |
| 286 | * two dimensions, expressed as a width and a height. The unit for location |
| 287 | * and dimensions is the pixel. |
| 288 | * </p> |
| 289 | * |
| 290 | * <p> |
| 291 | * It is possible to retrieve the location of a view by invoking the methods |
| 292 | * {@link #getLeft()} and {@link #getTop()}. The former returns the left, or X, |
| 293 | * coordinate of the rectangle representing the view. The latter returns the |
| 294 | * top, or Y, coordinate of the rectangle representing the view. These methods |
| 295 | * both return the location of the view relative to its parent. For instance, |
| 296 | * when getLeft() returns 20, that means the view is located 20 pixels to the |
| 297 | * right of the left edge of its direct parent. |
| 298 | * </p> |
| 299 | * |
| 300 | * <p> |
| 301 | * In addition, several convenience methods are offered to avoid unnecessary |
| 302 | * computations, namely {@link #getRight()} and {@link #getBottom()}. |
| 303 | * These methods return the coordinates of the right and bottom edges of the |
| 304 | * rectangle representing the view. For instance, calling {@link #getRight()} |
| 305 | * is similar to the following computation: <code>getLeft() + getWidth()</code> |
| 306 | * (see <a href="#SizePaddingMargins">Size</a> for more information about the width.) |
| 307 | * </p> |
| 308 | * |
| 309 | * <a name="SizePaddingMargins"></a> |
| 310 | * <h3>Size, padding and margins</h3> |
| 311 | * <p> |
| 312 | * The size of a view is expressed with a width and a height. A view actually |
| 313 | * possess two pairs of width and height values. |
| 314 | * </p> |
| 315 | * |
| 316 | * <p> |
| 317 | * The first pair is known as <em>measured width</em> and |
| 318 | * <em>measured height</em>. These dimensions define how big a view wants to be |
| 319 | * within its parent (see <a href="#Layout">Layout</a> for more details.) The |
| 320 | * measured dimensions can be obtained by calling {@link #getMeasuredWidth()} |
| 321 | * and {@link #getMeasuredHeight()}. |
| 322 | * </p> |
| 323 | * |
| 324 | * <p> |
| 325 | * The second pair is simply known as <em>width</em> and <em>height</em>, or |
| 326 | * sometimes <em>drawing width</em> and <em>drawing height</em>. These |
| 327 | * dimensions define the actual size of the view on screen, at drawing time and |
| 328 | * after layout. These values may, but do not have to, be different from the |
| 329 | * measured width and height. The width and height can be obtained by calling |
| 330 | * {@link #getWidth()} and {@link #getHeight()}. |
| 331 | * </p> |
| 332 | * |
| 333 | * <p> |
| 334 | * To measure its dimensions, a view takes into account its padding. The padding |
| 335 | * is expressed in pixels for the left, top, right and bottom parts of the view. |
| 336 | * Padding can be used to offset the content of the view by a specific amount of |
| 337 | * pixels. For instance, a left padding of 2 will push the view's content by |
| 338 | * 2 pixels to the right of the left edge. Padding can be set using the |
| 339 | * {@link #setPadding(int, int, int, int)} method and queried by calling |
| 340 | * {@link #getPaddingLeft()}, {@link #getPaddingTop()}, |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 341 | * {@link #getPaddingRight()}, {@link #getPaddingBottom()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | * </p> |
| 343 | * |
| 344 | * <p> |
| 345 | * Even though a view can define a padding, it does not provide any support for |
| 346 | * margins. However, view groups provide such a support. Refer to |
| 347 | * {@link android.view.ViewGroup} and |
| 348 | * {@link android.view.ViewGroup.MarginLayoutParams} for further information. |
| 349 | * </p> |
| 350 | * |
| 351 | * <a name="Layout"></a> |
| 352 | * <h3>Layout</h3> |
| 353 | * <p> |
| 354 | * Layout is a two pass process: a measure pass and a layout pass. The measuring |
| 355 | * pass is implemented in {@link #measure(int, int)} and is a top-down traversal |
| 356 | * of the view tree. Each view pushes dimension specifications down the tree |
| 357 | * during the recursion. At the end of the measure pass, every view has stored |
| 358 | * its measurements. The second pass happens in |
| 359 | * {@link #layout(int,int,int,int)} and is also top-down. During |
| 360 | * this pass each parent is responsible for positioning all of its children |
| 361 | * using the sizes computed in the measure pass. |
| 362 | * </p> |
| 363 | * |
| 364 | * <p> |
| 365 | * When a view's measure() method returns, its {@link #getMeasuredWidth()} and |
| 366 | * {@link #getMeasuredHeight()} values must be set, along with those for all of |
| 367 | * that view's descendants. A view's measured width and measured height values |
| 368 | * must respect the constraints imposed by the view's parents. This guarantees |
| 369 | * that at the end of the measure pass, all parents accept all of their |
| 370 | * children's measurements. A parent view may call measure() more than once on |
| 371 | * its children. For example, the parent may measure each child once with |
| 372 | * unspecified dimensions to find out how big they want to be, then call |
| 373 | * measure() on them again with actual numbers if the sum of all the children's |
| 374 | * unconstrained sizes is too big or too small. |
| 375 | * </p> |
| 376 | * |
| 377 | * <p> |
| 378 | * The measure pass uses two classes to communicate dimensions. The |
| 379 | * {@link MeasureSpec} class is used by views to tell their parents how they |
| 380 | * want to be measured and positioned. The base LayoutParams class just |
| 381 | * describes how big the view wants to be for both width and height. For each |
| 382 | * dimension, it can specify one of: |
| 383 | * <ul> |
| 384 | * <li> an exact number |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 385 | * <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] | 386 | * (minus padding) |
| 387 | * <li> WRAP_CONTENT, which means that the view wants to be just big enough to |
| 388 | * enclose its content (plus padding). |
| 389 | * </ul> |
| 390 | * There are subclasses of LayoutParams for different subclasses of ViewGroup. |
| 391 | * For example, AbsoluteLayout has its own subclass of LayoutParams which adds |
| 392 | * an X and Y value. |
| 393 | * </p> |
| 394 | * |
| 395 | * <p> |
| 396 | * MeasureSpecs are used to push requirements down the tree from parent to |
| 397 | * child. A MeasureSpec can be in one of three modes: |
| 398 | * <ul> |
| 399 | * <li>UNSPECIFIED: This is used by a parent to determine the desired dimension |
| 400 | * of a child view. For example, a LinearLayout may call measure() on its child |
| 401 | * with the height set to UNSPECIFIED and a width of EXACTLY 240 to find out how |
| 402 | * tall the child view wants to be given a width of 240 pixels. |
| 403 | * <li>EXACTLY: This is used by the parent to impose an exact size on the |
| 404 | * child. The child must use this size, and guarantee that all of its |
| 405 | * descendants will fit within this size. |
| 406 | * <li>AT_MOST: This is used by the parent to impose a maximum size on the |
| 407 | * child. The child must gurantee that it and all of its descendants will fit |
| 408 | * within this size. |
| 409 | * </ul> |
| 410 | * </p> |
| 411 | * |
| 412 | * <p> |
| 413 | * To intiate a layout, call {@link #requestLayout}. This method is typically |
| 414 | * called by a view on itself when it believes that is can no longer fit within |
| 415 | * its current bounds. |
| 416 | * </p> |
| 417 | * |
| 418 | * <a name="Drawing"></a> |
| 419 | * <h3>Drawing</h3> |
| 420 | * <p> |
| 421 | * Drawing is handled by walking the tree and rendering each view that |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 422 | * intersects the invalid region. Because the tree is traversed in-order, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | * this means that parents will draw before (i.e., behind) their children, with |
| 424 | * siblings drawn in the order they appear in the tree. |
| 425 | * If you set a background drawable for a View, then the View will draw it for you |
| 426 | * before calling back to its <code>onDraw()</code> method. |
| 427 | * </p> |
| 428 | * |
| 429 | * <p> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 430 | * 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] | 431 | * </p> |
| 432 | * |
| 433 | * <p> |
| 434 | * To force a view to draw, call {@link #invalidate()}. |
| 435 | * </p> |
| 436 | * |
| 437 | * <a name="EventHandlingThreading"></a> |
| 438 | * <h3>Event Handling and Threading</h3> |
| 439 | * <p> |
| 440 | * The basic cycle of a view is as follows: |
| 441 | * <ol> |
| 442 | * <li>An event comes in and is dispatched to the appropriate view. The view |
| 443 | * handles the event and notifies any listeners.</li> |
| 444 | * <li>If in the course of processing the event, the view's bounds may need |
| 445 | * to be changed, the view will call {@link #requestLayout()}.</li> |
| 446 | * <li>Similarly, if in the course of processing the event the view's appearance |
| 447 | * may need to be changed, the view will call {@link #invalidate()}.</li> |
| 448 | * <li>If either {@link #requestLayout()} or {@link #invalidate()} were called, |
| 449 | * the framework will take care of measuring, laying out, and drawing the tree |
| 450 | * as appropriate.</li> |
| 451 | * </ol> |
| 452 | * </p> |
| 453 | * |
| 454 | * <p><em>Note: The entire view tree is single threaded. You must always be on |
| 455 | * the UI thread when calling any method on any view.</em> |
| 456 | * If you are doing work on other threads and want to update the state of a view |
| 457 | * from that thread, you should use a {@link Handler}. |
| 458 | * </p> |
| 459 | * |
| 460 | * <a name="FocusHandling"></a> |
| 461 | * <h3>Focus Handling</h3> |
| 462 | * <p> |
| 463 | * The framework will handle routine focus movement in response to user input. |
| 464 | * This includes changing the focus as views are removed or hidden, or as new |
| 465 | * views become available. Views indicate their willingness to take focus |
| 466 | * through the {@link #isFocusable} method. To change whether a view can take |
| 467 | * focus, call {@link #setFocusable(boolean)}. When in touch mode (see notes below) |
| 468 | * views indicate whether they still would like focus via {@link #isFocusableInTouchMode} |
| 469 | * and can change this via {@link #setFocusableInTouchMode(boolean)}. |
| 470 | * </p> |
| 471 | * <p> |
| 472 | * Focus movement is based on an algorithm which finds the nearest neighbor in a |
| 473 | * given direction. In rare cases, the default algorithm may not match the |
| 474 | * intended behavior of the developer. In these situations, you can provide |
| 475 | * explicit overrides by using these XML attributes in the layout file: |
| 476 | * <pre> |
| 477 | * nextFocusDown |
| 478 | * nextFocusLeft |
| 479 | * nextFocusRight |
| 480 | * nextFocusUp |
| 481 | * </pre> |
| 482 | * </p> |
| 483 | * |
| 484 | * |
| 485 | * <p> |
| 486 | * To get a particular view to take focus, call {@link #requestFocus()}. |
| 487 | * </p> |
| 488 | * |
| 489 | * <a name="TouchMode"></a> |
| 490 | * <h3>Touch Mode</h3> |
| 491 | * <p> |
| 492 | * When a user is navigating a user interface via directional keys such as a D-pad, it is |
| 493 | * necessary to give focus to actionable items such as buttons so the user can see |
| 494 | * what will take input. If the device has touch capabilities, however, and the user |
| 495 | * begins interacting with the interface by touching it, it is no longer necessary to |
| 496 | * always highlight, or give focus to, a particular view. This motivates a mode |
| 497 | * for interaction named 'touch mode'. |
| 498 | * </p> |
| 499 | * <p> |
| 500 | * For a touch capable device, once the user touches the screen, the device |
| 501 | * will enter touch mode. From this point onward, only views for which |
| 502 | * {@link #isFocusableInTouchMode} is true will be focusable, such as text editing widgets. |
| 503 | * Other views that are touchable, like buttons, will not take focus when touched; they will |
| 504 | * only fire the on click listeners. |
| 505 | * </p> |
| 506 | * <p> |
| 507 | * Any time a user hits a directional key, such as a D-pad direction, the view device will |
| 508 | * exit touch mode, and find a view to take focus, so that the user may resume interacting |
| 509 | * with the user interface without touching the screen again. |
| 510 | * </p> |
| 511 | * <p> |
| 512 | * The touch mode state is maintained across {@link android.app.Activity}s. Call |
| 513 | * {@link #isInTouchMode} to see whether the device is currently in touch mode. |
| 514 | * </p> |
| 515 | * |
| 516 | * <a name="Scrolling"></a> |
| 517 | * <h3>Scrolling</h3> |
| 518 | * <p> |
| 519 | * The framework provides basic support for views that wish to internally |
| 520 | * scroll their content. This includes keeping track of the X and Y scroll |
| 521 | * offset as well as mechanisms for drawing scrollbars. See |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 522 | * {@link #scrollBy(int, int)}, {@link #scrollTo(int, int)}, and |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 523 | * {@link #awakenScrollBars()} for more details. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | * </p> |
| 525 | * |
| 526 | * <a name="Tags"></a> |
| 527 | * <h3>Tags</h3> |
| 528 | * <p> |
| 529 | * Unlike IDs, tags are not used to identify views. Tags are essentially an |
| 530 | * extra piece of information that can be associated with a view. They are most |
| 531 | * often used as a convenience to store data related to views in the views |
| 532 | * themselves rather than by putting them in a separate structure. |
| 533 | * </p> |
| 534 | * |
| 535 | * <a name="Animation"></a> |
| 536 | * <h3>Animation</h3> |
| 537 | * <p> |
| 538 | * You can attach an {@link Animation} object to a view using |
| 539 | * {@link #setAnimation(Animation)} or |
| 540 | * {@link #startAnimation(Animation)}. The animation can alter the scale, |
| 541 | * rotation, translation and alpha of a view over time. If the animation is |
| 542 | * attached to a view that has children, the animation will affect the entire |
| 543 | * subtree rooted by that node. When an animation is started, the framework will |
| 544 | * take care of redrawing the appropriate views until the animation completes. |
| 545 | * </p> |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 546 | * <p> |
| 547 | * Starting with Android 3.0, the preferred way of animating views is to use the |
| 548 | * {@link android.animation} package APIs. |
| 549 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 551 | * <a name="Security"></a> |
| 552 | * <h3>Security</h3> |
| 553 | * <p> |
| 554 | * Sometimes it is essential that an application be able to verify that an action |
| 555 | * is being performed with the full knowledge and consent of the user, such as |
| 556 | * granting a permission request, making a purchase or clicking on an advertisement. |
| 557 | * Unfortunately, a malicious application could try to spoof the user into |
| 558 | * performing these actions, unaware, by concealing the intended purpose of the view. |
| 559 | * As a remedy, the framework offers a touch filtering mechanism that can be used to |
| 560 | * improve the security of views that provide access to sensitive functionality. |
| 561 | * </p><p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 562 | * To enable touch filtering, call {@link #setFilterTouchesWhenObscured(boolean)} or set the |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 563 | * android:filterTouchesWhenObscured layout attribute to true. When enabled, the framework |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 564 | * will discard touches that are received whenever the view's window is obscured by |
| 565 | * another visible window. As a result, the view will not receive touches whenever a |
| 566 | * toast, dialog or other window appears above the view's window. |
| 567 | * </p><p> |
| 568 | * For more fine-grained control over security, consider overriding the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 569 | * {@link #onFilterTouchEventForSecurity(MotionEvent)} method to implement your own |
| 570 | * security policy. See also {@link MotionEvent#FLAG_WINDOW_IS_OBSCURED}. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 571 | * </p> |
| 572 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 573 | * @attr ref android.R.styleable#View_alpha |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 574 | * @attr ref android.R.styleable#View_background |
| 575 | * @attr ref android.R.styleable#View_clickable |
| 576 | * @attr ref android.R.styleable#View_contentDescription |
| 577 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 578 | * @attr ref android.R.styleable#View_duplicateParentState |
| 579 | * @attr ref android.R.styleable#View_id |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 580 | * @attr ref android.R.styleable#View_requiresFadingEdge |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 581 | * @attr ref android.R.styleable#View_fadingEdgeLength |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 582 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 584 | * @attr ref android.R.styleable#View_isScrollContainer |
| 585 | * @attr ref android.R.styleable#View_focusable |
| 586 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 587 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 588 | * @attr ref android.R.styleable#View_keepScreenOn |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 589 | * @attr ref android.R.styleable#View_layerType |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 590 | * @attr ref android.R.styleable#View_longClickable |
| 591 | * @attr ref android.R.styleable#View_minHeight |
| 592 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 593 | * @attr ref android.R.styleable#View_nextFocusDown |
| 594 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 595 | * @attr ref android.R.styleable#View_nextFocusRight |
| 596 | * @attr ref android.R.styleable#View_nextFocusUp |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 597 | * @attr ref android.R.styleable#View_onClick |
| 598 | * @attr ref android.R.styleable#View_padding |
| 599 | * @attr ref android.R.styleable#View_paddingBottom |
| 600 | * @attr ref android.R.styleable#View_paddingLeft |
| 601 | * @attr ref android.R.styleable#View_paddingRight |
| 602 | * @attr ref android.R.styleable#View_paddingTop |
| 603 | * @attr ref android.R.styleable#View_saveEnabled |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 604 | * @attr ref android.R.styleable#View_rotation |
| 605 | * @attr ref android.R.styleable#View_rotationX |
| 606 | * @attr ref android.R.styleable#View_rotationY |
| 607 | * @attr ref android.R.styleable#View_scaleX |
| 608 | * @attr ref android.R.styleable#View_scaleY |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | * @attr ref android.R.styleable#View_scrollX |
| 610 | * @attr ref android.R.styleable#View_scrollY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 611 | * @attr ref android.R.styleable#View_scrollbarSize |
| 612 | * @attr ref android.R.styleable#View_scrollbarStyle |
| 613 | * @attr ref android.R.styleable#View_scrollbars |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 614 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 615 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | * @attr ref android.R.styleable#View_scrollbarTrackHorizontal |
| 617 | * @attr ref android.R.styleable#View_scrollbarThumbHorizontal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | * @attr ref android.R.styleable#View_scrollbarThumbVertical |
| 619 | * @attr ref android.R.styleable#View_scrollbarTrackVertical |
| 620 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawHorizontalTrack |
| 621 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawVerticalTrack |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 622 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 623 | * @attr ref android.R.styleable#View_tag |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 624 | * @attr ref android.R.styleable#View_transformPivotX |
| 625 | * @attr ref android.R.styleable#View_transformPivotY |
| 626 | * @attr ref android.R.styleable#View_translationX |
| 627 | * @attr ref android.R.styleable#View_translationY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 628 | * @attr ref android.R.styleable#View_visibility |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | * |
| 630 | * @see android.view.ViewGroup |
| 631 | */ |
Adam Powell | 8fc54f9 | 2011-09-07 16:40:45 -0700 | [diff] [blame] | 632 | public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Callback, |
| 633 | AccessibilityEventSource { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | private static final boolean DBG = false; |
| 635 | |
| 636 | /** |
| 637 | * The logging tag used by this class with android.util.Log. |
| 638 | */ |
| 639 | protected static final String VIEW_LOG_TAG = "View"; |
| 640 | |
| 641 | /** |
| 642 | * Used to mark a View that has no ID. |
| 643 | */ |
| 644 | public static final int NO_ID = -1; |
| 645 | |
| 646 | /** |
| 647 | * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when |
| 648 | * calling setFlags. |
| 649 | */ |
| 650 | private static final int NOT_FOCUSABLE = 0x00000000; |
| 651 | |
| 652 | /** |
| 653 | * This view wants keystrokes. Use with TAKES_FOCUS_MASK when calling |
| 654 | * setFlags. |
| 655 | */ |
| 656 | private static final int FOCUSABLE = 0x00000001; |
| 657 | |
| 658 | /** |
| 659 | * Mask for use with setFlags indicating bits used for focus. |
| 660 | */ |
| 661 | private static final int FOCUSABLE_MASK = 0x00000001; |
| 662 | |
| 663 | /** |
| 664 | * This view will adjust its padding to fit sytem windows (e.g. status bar) |
| 665 | */ |
| 666 | private static final int FITS_SYSTEM_WINDOWS = 0x00000002; |
| 667 | |
| 668 | /** |
Scott Main | 812634c2 | 2011-07-27 13:22:35 -0700 | [diff] [blame] | 669 | * This view is visible. |
| 670 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 671 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 672 | */ |
| 673 | public static final int VISIBLE = 0x00000000; |
| 674 | |
| 675 | /** |
| 676 | * 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] | 677 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 678 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 679 | */ |
| 680 | public static final int INVISIBLE = 0x00000004; |
| 681 | |
| 682 | /** |
| 683 | * 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] | 684 | * purposes. Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 685 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 686 | */ |
| 687 | public static final int GONE = 0x00000008; |
| 688 | |
| 689 | /** |
| 690 | * Mask for use with setFlags indicating bits used for visibility. |
| 691 | * {@hide} |
| 692 | */ |
| 693 | static final int VISIBILITY_MASK = 0x0000000C; |
| 694 | |
| 695 | private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE}; |
| 696 | |
| 697 | /** |
| 698 | * This view is enabled. Intrepretation varies by subclass. |
| 699 | * Use with ENABLED_MASK when calling setFlags. |
| 700 | * {@hide} |
| 701 | */ |
| 702 | static final int ENABLED = 0x00000000; |
| 703 | |
| 704 | /** |
| 705 | * This view is disabled. Intrepretation varies by subclass. |
| 706 | * Use with ENABLED_MASK when calling setFlags. |
| 707 | * {@hide} |
| 708 | */ |
| 709 | static final int DISABLED = 0x00000020; |
| 710 | |
| 711 | /** |
| 712 | * Mask for use with setFlags indicating bits used for indicating whether |
| 713 | * this view is enabled |
| 714 | * {@hide} |
| 715 | */ |
| 716 | static final int ENABLED_MASK = 0x00000020; |
| 717 | |
| 718 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 719 | * This view won't draw. {@link #onDraw(android.graphics.Canvas)} won't be |
| 720 | * called and further optimizations will be performed. It is okay to have |
| 721 | * 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] | 722 | * {@hide} |
| 723 | */ |
| 724 | static final int WILL_NOT_DRAW = 0x00000080; |
| 725 | |
| 726 | /** |
| 727 | * Mask for use with setFlags indicating bits used for indicating whether |
| 728 | * this view is will draw |
| 729 | * {@hide} |
| 730 | */ |
| 731 | static final int DRAW_MASK = 0x00000080; |
| 732 | |
| 733 | /** |
| 734 | * <p>This view doesn't show scrollbars.</p> |
| 735 | * {@hide} |
| 736 | */ |
| 737 | static final int SCROLLBARS_NONE = 0x00000000; |
| 738 | |
| 739 | /** |
| 740 | * <p>This view shows horizontal scrollbars.</p> |
| 741 | * {@hide} |
| 742 | */ |
| 743 | static final int SCROLLBARS_HORIZONTAL = 0x00000100; |
| 744 | |
| 745 | /** |
| 746 | * <p>This view shows vertical scrollbars.</p> |
| 747 | * {@hide} |
| 748 | */ |
| 749 | static final int SCROLLBARS_VERTICAL = 0x00000200; |
| 750 | |
| 751 | /** |
| 752 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 753 | * scrollbars are enabled.</p> |
| 754 | * {@hide} |
| 755 | */ |
| 756 | static final int SCROLLBARS_MASK = 0x00000300; |
| 757 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 758 | /** |
| 759 | * Indicates that the view should filter touches when its window is obscured. |
| 760 | * Refer to the class comments for more information about this security feature. |
| 761 | * {@hide} |
| 762 | */ |
| 763 | static final int FILTER_TOUCHES_WHEN_OBSCURED = 0x00000400; |
| 764 | |
| 765 | // 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] | 766 | |
| 767 | /** |
| 768 | * <p>This view doesn't show fading edges.</p> |
| 769 | * {@hide} |
| 770 | */ |
| 771 | static final int FADING_EDGE_NONE = 0x00000000; |
| 772 | |
| 773 | /** |
| 774 | * <p>This view shows horizontal fading edges.</p> |
| 775 | * {@hide} |
| 776 | */ |
| 777 | static final int FADING_EDGE_HORIZONTAL = 0x00001000; |
| 778 | |
| 779 | /** |
| 780 | * <p>This view shows vertical fading edges.</p> |
| 781 | * {@hide} |
| 782 | */ |
| 783 | static final int FADING_EDGE_VERTICAL = 0x00002000; |
| 784 | |
| 785 | /** |
| 786 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 787 | * fading edges are enabled.</p> |
| 788 | * {@hide} |
| 789 | */ |
| 790 | static final int FADING_EDGE_MASK = 0x00003000; |
| 791 | |
| 792 | /** |
| 793 | * <p>Indicates this view can be clicked. When clickable, a View reacts |
| 794 | * to clicks by notifying the OnClickListener.<p> |
| 795 | * {@hide} |
| 796 | */ |
| 797 | static final int CLICKABLE = 0x00004000; |
| 798 | |
| 799 | /** |
| 800 | * <p>Indicates this view is caching its drawing into a bitmap.</p> |
| 801 | * {@hide} |
| 802 | */ |
| 803 | static final int DRAWING_CACHE_ENABLED = 0x00008000; |
| 804 | |
| 805 | /** |
| 806 | * <p>Indicates that no icicle should be saved for this view.<p> |
| 807 | * {@hide} |
| 808 | */ |
| 809 | static final int SAVE_DISABLED = 0x000010000; |
| 810 | |
| 811 | /** |
| 812 | * <p>Mask for use with setFlags indicating bits used for the saveEnabled |
| 813 | * property.</p> |
| 814 | * {@hide} |
| 815 | */ |
| 816 | static final int SAVE_DISABLED_MASK = 0x000010000; |
| 817 | |
| 818 | /** |
| 819 | * <p>Indicates that no drawing cache should ever be created for this view.<p> |
| 820 | * {@hide} |
| 821 | */ |
| 822 | static final int WILL_NOT_CACHE_DRAWING = 0x000020000; |
| 823 | |
| 824 | /** |
| 825 | * <p>Indicates this view can take / keep focus when int touch mode.</p> |
| 826 | * {@hide} |
| 827 | */ |
| 828 | static final int FOCUSABLE_IN_TOUCH_MODE = 0x00040000; |
| 829 | |
| 830 | /** |
| 831 | * <p>Enables low quality mode for the drawing cache.</p> |
| 832 | */ |
| 833 | public static final int DRAWING_CACHE_QUALITY_LOW = 0x00080000; |
| 834 | |
| 835 | /** |
| 836 | * <p>Enables high quality mode for the drawing cache.</p> |
| 837 | */ |
| 838 | public static final int DRAWING_CACHE_QUALITY_HIGH = 0x00100000; |
| 839 | |
| 840 | /** |
| 841 | * <p>Enables automatic quality mode for the drawing cache.</p> |
| 842 | */ |
| 843 | public static final int DRAWING_CACHE_QUALITY_AUTO = 0x00000000; |
| 844 | |
| 845 | private static final int[] DRAWING_CACHE_QUALITY_FLAGS = { |
| 846 | DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_LOW, DRAWING_CACHE_QUALITY_HIGH |
| 847 | }; |
| 848 | |
| 849 | /** |
| 850 | * <p>Mask for use with setFlags indicating bits used for the cache |
| 851 | * quality property.</p> |
| 852 | * {@hide} |
| 853 | */ |
| 854 | static final int DRAWING_CACHE_QUALITY_MASK = 0x00180000; |
| 855 | |
| 856 | /** |
| 857 | * <p> |
| 858 | * Indicates this view can be long clicked. When long clickable, a View |
| 859 | * reacts to long clicks by notifying the OnLongClickListener or showing a |
| 860 | * context menu. |
| 861 | * </p> |
| 862 | * {@hide} |
| 863 | */ |
| 864 | static final int LONG_CLICKABLE = 0x00200000; |
| 865 | |
| 866 | /** |
| 867 | * <p>Indicates that this view gets its drawable states from its direct parent |
| 868 | * and ignores its original internal states.</p> |
| 869 | * |
| 870 | * @hide |
| 871 | */ |
| 872 | static final int DUPLICATE_PARENT_STATE = 0x00400000; |
| 873 | |
| 874 | /** |
| 875 | * The scrollbar style to display the scrollbars inside the content area, |
| 876 | * without increasing the padding. The scrollbars will be overlaid with |
| 877 | * translucency on the view's content. |
| 878 | */ |
| 879 | public static final int SCROLLBARS_INSIDE_OVERLAY = 0; |
| 880 | |
| 881 | /** |
| 882 | * The scrollbar style to display the scrollbars inside the padded area, |
| 883 | * increasing the padding of the view. The scrollbars will not overlap the |
| 884 | * content area of the view. |
| 885 | */ |
| 886 | public static final int SCROLLBARS_INSIDE_INSET = 0x01000000; |
| 887 | |
| 888 | /** |
| 889 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 890 | * without increasing the padding. The scrollbars will be overlaid with |
| 891 | * translucency. |
| 892 | */ |
| 893 | public static final int SCROLLBARS_OUTSIDE_OVERLAY = 0x02000000; |
| 894 | |
| 895 | /** |
| 896 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 897 | * increasing the padding of the view. The scrollbars will only overlap the |
| 898 | * background, if any. |
| 899 | */ |
| 900 | public static final int SCROLLBARS_OUTSIDE_INSET = 0x03000000; |
| 901 | |
| 902 | /** |
| 903 | * Mask to check if the scrollbar style is overlay or inset. |
| 904 | * {@hide} |
| 905 | */ |
| 906 | static final int SCROLLBARS_INSET_MASK = 0x01000000; |
| 907 | |
| 908 | /** |
| 909 | * Mask to check if the scrollbar style is inside or outside. |
| 910 | * {@hide} |
| 911 | */ |
| 912 | static final int SCROLLBARS_OUTSIDE_MASK = 0x02000000; |
| 913 | |
| 914 | /** |
| 915 | * Mask for scrollbar style. |
| 916 | * {@hide} |
| 917 | */ |
| 918 | static final int SCROLLBARS_STYLE_MASK = 0x03000000; |
| 919 | |
| 920 | /** |
| 921 | * View flag indicating that the screen should remain on while the |
| 922 | * window containing this view is visible to the user. This effectively |
| 923 | * takes care of automatically setting the WindowManager's |
| 924 | * {@link WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON}. |
| 925 | */ |
| 926 | public static final int KEEP_SCREEN_ON = 0x04000000; |
| 927 | |
| 928 | /** |
| 929 | * View flag indicating whether this view should have sound effects enabled |
| 930 | * for events such as clicking and touching. |
| 931 | */ |
| 932 | public static final int SOUND_EFFECTS_ENABLED = 0x08000000; |
| 933 | |
| 934 | /** |
| 935 | * View flag indicating whether this view should have haptic feedback |
| 936 | * enabled for events such as long presses. |
| 937 | */ |
| 938 | public static final int HAPTIC_FEEDBACK_ENABLED = 0x10000000; |
| 939 | |
| 940 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 941 | * <p>Indicates that the view hierarchy should stop saving state when |
| 942 | * it reaches this view. If state saving is initiated immediately at |
| 943 | * the view, it will be allowed. |
| 944 | * {@hide} |
| 945 | */ |
| 946 | static final int PARENT_SAVE_DISABLED = 0x20000000; |
| 947 | |
| 948 | /** |
| 949 | * <p>Mask for use with setFlags indicating bits used for PARENT_SAVE_DISABLED.</p> |
| 950 | * {@hide} |
| 951 | */ |
| 952 | static final int PARENT_SAVE_DISABLED_MASK = 0x20000000; |
| 953 | |
| 954 | /** |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 955 | * Horizontal direction of this view is from Left to Right. |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 956 | * Use with {@link #setLayoutDirection}. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 957 | * {@hide} |
| 958 | */ |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 959 | public static final int LAYOUT_DIRECTION_LTR = 0x00000000; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 960 | |
| 961 | /** |
| 962 | * Horizontal direction of this view is from Right to Left. |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 963 | * Use with {@link #setLayoutDirection}. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 964 | * {@hide} |
| 965 | */ |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 966 | public static final int LAYOUT_DIRECTION_RTL = 0x40000000; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 967 | |
| 968 | /** |
| 969 | * Horizontal direction of this view is inherited from its parent. |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 970 | * Use with {@link #setLayoutDirection}. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 971 | * {@hide} |
| 972 | */ |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 973 | public static final int LAYOUT_DIRECTION_INHERIT = 0x80000000; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 974 | |
| 975 | /** |
| 976 | * 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] | 977 | * script for the locale. Use with {@link #setLayoutDirection}. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 978 | * {@hide} |
| 979 | */ |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 980 | public static final int LAYOUT_DIRECTION_LOCALE = 0xC0000000; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 981 | |
| 982 | /** |
| 983 | * Mask for use with setFlags indicating bits used for horizontalDirection. |
| 984 | * {@hide} |
| 985 | */ |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 986 | static final int LAYOUT_DIRECTION_MASK = 0xC0000000; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 987 | |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 988 | /* |
| 989 | * Array of horizontal direction flags for mapping attribute "horizontalDirection" to correct |
| 990 | * flag value. |
| 991 | * {@hide} |
| 992 | */ |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 993 | private static final int[] LAYOUT_DIRECTION_FLAGS = {LAYOUT_DIRECTION_LTR, |
| 994 | LAYOUT_DIRECTION_RTL, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE}; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 995 | |
| 996 | /** |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 997 | * Default horizontalDirection. |
| 998 | * {@hide} |
| 999 | */ |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 1000 | private static final int LAYOUT_DIRECTION_DEFAULT = LAYOUT_DIRECTION_INHERIT; |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 1001 | |
| 1002 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1003 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 1004 | * should add all focusable Views regardless if they are focusable in touch mode. |
| 1005 | */ |
| 1006 | public static final int FOCUSABLES_ALL = 0x00000000; |
| 1007 | |
| 1008 | /** |
| 1009 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 1010 | * should add only Views focusable in touch mode. |
| 1011 | */ |
| 1012 | public static final int FOCUSABLES_TOUCH_MODE = 0x00000001; |
| 1013 | |
| 1014 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1015 | * 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] | 1016 | * item. |
| 1017 | */ |
| 1018 | public static final int FOCUS_BACKWARD = 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 next 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_FORWARD = 0x00000002; |
| 1025 | |
| 1026 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1027 | * 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] | 1028 | */ |
| 1029 | public static final int FOCUS_LEFT = 0x00000011; |
| 1030 | |
| 1031 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1032 | * Use with {@link #focusSearch(int)}. Move focus up. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1033 | */ |
| 1034 | public static final int FOCUS_UP = 0x00000021; |
| 1035 | |
| 1036 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1037 | * 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] | 1038 | */ |
| 1039 | public static final int FOCUS_RIGHT = 0x00000042; |
| 1040 | |
| 1041 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1042 | * Use with {@link #focusSearch(int)}. Move focus down. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1043 | */ |
| 1044 | public static final int FOCUS_DOWN = 0x00000082; |
| 1045 | |
| 1046 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1047 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1048 | * {@link #getMeasuredWidthAndState()} that provide the actual measured size. |
| 1049 | */ |
| 1050 | public static final int MEASURED_SIZE_MASK = 0x00ffffff; |
| 1051 | |
| 1052 | /** |
| 1053 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1054 | * {@link #getMeasuredWidthAndState()} that provide the additional state bits. |
| 1055 | */ |
| 1056 | public static final int MEASURED_STATE_MASK = 0xff000000; |
| 1057 | |
| 1058 | /** |
| 1059 | * Bit shift of {@link #MEASURED_STATE_MASK} to get to the height bits |
| 1060 | * for functions that combine both width and height into a single int, |
| 1061 | * such as {@link #getMeasuredState()} and the childState argument of |
| 1062 | * {@link #resolveSizeAndState(int, int, int)}. |
| 1063 | */ |
| 1064 | public static final int MEASURED_HEIGHT_STATE_SHIFT = 16; |
| 1065 | |
| 1066 | /** |
| 1067 | * Bit of {@link #getMeasuredWidthAndState()} and |
| 1068 | * {@link #getMeasuredWidthAndState()} that indicates the measured size |
| 1069 | * is smaller that the space the view would like to have. |
| 1070 | */ |
| 1071 | public static final int MEASURED_STATE_TOO_SMALL = 0x01000000; |
| 1072 | |
| 1073 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1074 | * Base View state sets |
| 1075 | */ |
| 1076 | // Singles |
| 1077 | /** |
| 1078 | * Indicates the view has no states set. States are used with |
| 1079 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1080 | * view depending on its state. |
| 1081 | * |
| 1082 | * @see android.graphics.drawable.Drawable |
| 1083 | * @see #getDrawableState() |
| 1084 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1085 | protected static final int[] EMPTY_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1086 | /** |
| 1087 | * Indicates the view is enabled. States are used with |
| 1088 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1089 | * view depending on its state. |
| 1090 | * |
| 1091 | * @see android.graphics.drawable.Drawable |
| 1092 | * @see #getDrawableState() |
| 1093 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1094 | protected static final int[] ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | /** |
| 1096 | * Indicates the view is focused. States are used with |
| 1097 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1098 | * view depending on its state. |
| 1099 | * |
| 1100 | * @see android.graphics.drawable.Drawable |
| 1101 | * @see #getDrawableState() |
| 1102 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1103 | protected static final int[] FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1104 | /** |
| 1105 | * Indicates the view is selected. States are used with |
| 1106 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1107 | * view depending on its state. |
| 1108 | * |
| 1109 | * @see android.graphics.drawable.Drawable |
| 1110 | * @see #getDrawableState() |
| 1111 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1112 | protected static final int[] SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1113 | /** |
| 1114 | * Indicates the view is pressed. States are used with |
| 1115 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1116 | * view depending on its state. |
| 1117 | * |
| 1118 | * @see android.graphics.drawable.Drawable |
| 1119 | * @see #getDrawableState() |
| 1120 | * @hide |
| 1121 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1122 | protected static final int[] PRESSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1123 | /** |
| 1124 | * Indicates the view's window has focus. States are used with |
| 1125 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1126 | * view depending on its state. |
| 1127 | * |
| 1128 | * @see android.graphics.drawable.Drawable |
| 1129 | * @see #getDrawableState() |
| 1130 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1131 | protected static final int[] WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1132 | // Doubles |
| 1133 | /** |
| 1134 | * Indicates the view is enabled and has the focus. |
| 1135 | * |
| 1136 | * @see #ENABLED_STATE_SET |
| 1137 | * @see #FOCUSED_STATE_SET |
| 1138 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1139 | protected static final int[] ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1140 | /** |
| 1141 | * Indicates the view is enabled and selected. |
| 1142 | * |
| 1143 | * @see #ENABLED_STATE_SET |
| 1144 | * @see #SELECTED_STATE_SET |
| 1145 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1146 | protected static final int[] ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | /** |
| 1148 | * Indicates the view is enabled and that its window has focus. |
| 1149 | * |
| 1150 | * @see #ENABLED_STATE_SET |
| 1151 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1152 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1153 | protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | /** |
| 1155 | * Indicates the view is focused and selected. |
| 1156 | * |
| 1157 | * @see #FOCUSED_STATE_SET |
| 1158 | * @see #SELECTED_STATE_SET |
| 1159 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1160 | protected static final int[] FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1161 | /** |
| 1162 | * Indicates the view has the focus and that its window has the focus. |
| 1163 | * |
| 1164 | * @see #FOCUSED_STATE_SET |
| 1165 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1166 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1167 | protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1168 | /** |
| 1169 | * Indicates the view is selected and that its window has the focus. |
| 1170 | * |
| 1171 | * @see #SELECTED_STATE_SET |
| 1172 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1173 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1174 | protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1175 | // Triples |
| 1176 | /** |
| 1177 | * Indicates the view is enabled, focused and selected. |
| 1178 | * |
| 1179 | * @see #ENABLED_STATE_SET |
| 1180 | * @see #FOCUSED_STATE_SET |
| 1181 | * @see #SELECTED_STATE_SET |
| 1182 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1183 | protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1184 | /** |
| 1185 | * Indicates the view is enabled, focused and its window has the focus. |
| 1186 | * |
| 1187 | * @see #ENABLED_STATE_SET |
| 1188 | * @see #FOCUSED_STATE_SET |
| 1189 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1190 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1191 | 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] | 1192 | /** |
| 1193 | * Indicates the view is enabled, selected and its window has the focus. |
| 1194 | * |
| 1195 | * @see #ENABLED_STATE_SET |
| 1196 | * @see #SELECTED_STATE_SET |
| 1197 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1198 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1199 | protected static final int[] ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1200 | /** |
| 1201 | * Indicates the view is focused, selected and its window has the focus. |
| 1202 | * |
| 1203 | * @see #FOCUSED_STATE_SET |
| 1204 | * @see #SELECTED_STATE_SET |
| 1205 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1206 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1207 | 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] | 1208 | /** |
| 1209 | * Indicates the view is enabled, focused, selected and its window |
| 1210 | * has the focus. |
| 1211 | * |
| 1212 | * @see #ENABLED_STATE_SET |
| 1213 | * @see #FOCUSED_STATE_SET |
| 1214 | * @see #SELECTED_STATE_SET |
| 1215 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1216 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1217 | protected static final int[] ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1218 | /** |
| 1219 | * Indicates the view is pressed and its window has the focus. |
| 1220 | * |
| 1221 | * @see #PRESSED_STATE_SET |
| 1222 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1223 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1224 | protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1225 | /** |
| 1226 | * Indicates the view is pressed and selected. |
| 1227 | * |
| 1228 | * @see #PRESSED_STATE_SET |
| 1229 | * @see #SELECTED_STATE_SET |
| 1230 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1231 | protected static final int[] PRESSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | /** |
| 1233 | * Indicates the view is pressed, selected and its window has the focus. |
| 1234 | * |
| 1235 | * @see #PRESSED_STATE_SET |
| 1236 | * @see #SELECTED_STATE_SET |
| 1237 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1238 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1239 | 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] | 1240 | /** |
| 1241 | * Indicates the view is pressed and focused. |
| 1242 | * |
| 1243 | * @see #PRESSED_STATE_SET |
| 1244 | * @see #FOCUSED_STATE_SET |
| 1245 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1246 | protected static final int[] PRESSED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1247 | /** |
| 1248 | * Indicates the view is pressed, focused and its window has the focus. |
| 1249 | * |
| 1250 | * @see #PRESSED_STATE_SET |
| 1251 | * @see #FOCUSED_STATE_SET |
| 1252 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1253 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1254 | 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] | 1255 | /** |
| 1256 | * Indicates the view is pressed, focused and selected. |
| 1257 | * |
| 1258 | * @see #PRESSED_STATE_SET |
| 1259 | * @see #SELECTED_STATE_SET |
| 1260 | * @see #FOCUSED_STATE_SET |
| 1261 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1262 | protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1263 | /** |
| 1264 | * Indicates the view is pressed, focused, selected and its window has the focus. |
| 1265 | * |
| 1266 | * @see #PRESSED_STATE_SET |
| 1267 | * @see #FOCUSED_STATE_SET |
| 1268 | * @see #SELECTED_STATE_SET |
| 1269 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1270 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1271 | 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] | 1272 | /** |
| 1273 | * Indicates the view is pressed and enabled. |
| 1274 | * |
| 1275 | * @see #PRESSED_STATE_SET |
| 1276 | * @see #ENABLED_STATE_SET |
| 1277 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1278 | protected static final int[] PRESSED_ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1279 | /** |
| 1280 | * Indicates the view is pressed, enabled and its window has the focus. |
| 1281 | * |
| 1282 | * @see #PRESSED_STATE_SET |
| 1283 | * @see #ENABLED_STATE_SET |
| 1284 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1285 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1286 | 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] | 1287 | /** |
| 1288 | * Indicates the view is pressed, enabled and selected. |
| 1289 | * |
| 1290 | * @see #PRESSED_STATE_SET |
| 1291 | * @see #ENABLED_STATE_SET |
| 1292 | * @see #SELECTED_STATE_SET |
| 1293 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1294 | protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1295 | /** |
| 1296 | * Indicates the view is pressed, enabled, selected and its window has the |
| 1297 | * focus. |
| 1298 | * |
| 1299 | * @see #PRESSED_STATE_SET |
| 1300 | * @see #ENABLED_STATE_SET |
| 1301 | * @see #SELECTED_STATE_SET |
| 1302 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1303 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1304 | 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] | 1305 | /** |
| 1306 | * Indicates the view is pressed, enabled and focused. |
| 1307 | * |
| 1308 | * @see #PRESSED_STATE_SET |
| 1309 | * @see #ENABLED_STATE_SET |
| 1310 | * @see #FOCUSED_STATE_SET |
| 1311 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1312 | protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1313 | /** |
| 1314 | * Indicates the view is pressed, enabled, focused and its window has the |
| 1315 | * focus. |
| 1316 | * |
| 1317 | * @see #PRESSED_STATE_SET |
| 1318 | * @see #ENABLED_STATE_SET |
| 1319 | * @see #FOCUSED_STATE_SET |
| 1320 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1321 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1322 | 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] | 1323 | /** |
| 1324 | * Indicates the view is pressed, enabled, focused and selected. |
| 1325 | * |
| 1326 | * @see #PRESSED_STATE_SET |
| 1327 | * @see #ENABLED_STATE_SET |
| 1328 | * @see #SELECTED_STATE_SET |
| 1329 | * @see #FOCUSED_STATE_SET |
| 1330 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1331 | 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] | 1332 | /** |
| 1333 | * Indicates the view is pressed, enabled, focused, selected and its window |
| 1334 | * has the focus. |
| 1335 | * |
| 1336 | * @see #PRESSED_STATE_SET |
| 1337 | * @see #ENABLED_STATE_SET |
| 1338 | * @see #SELECTED_STATE_SET |
| 1339 | * @see #FOCUSED_STATE_SET |
| 1340 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1341 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1342 | protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1343 | |
| 1344 | /** |
| 1345 | * The order here is very important to {@link #getDrawableState()} |
| 1346 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1347 | private static final int[][] VIEW_STATE_SETS; |
| 1348 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1349 | static final int VIEW_STATE_WINDOW_FOCUSED = 1; |
| 1350 | static final int VIEW_STATE_SELECTED = 1 << 1; |
| 1351 | static final int VIEW_STATE_FOCUSED = 1 << 2; |
| 1352 | static final int VIEW_STATE_ENABLED = 1 << 3; |
| 1353 | static final int VIEW_STATE_PRESSED = 1 << 4; |
| 1354 | static final int VIEW_STATE_ACTIVATED = 1 << 5; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1355 | static final int VIEW_STATE_ACCELERATED = 1 << 6; |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1356 | static final int VIEW_STATE_HOVERED = 1 << 7; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1357 | static final int VIEW_STATE_DRAG_CAN_ACCEPT = 1 << 8; |
| 1358 | static final int VIEW_STATE_DRAG_HOVERED = 1 << 9; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1359 | |
| 1360 | static final int[] VIEW_STATE_IDS = new int[] { |
| 1361 | R.attr.state_window_focused, VIEW_STATE_WINDOW_FOCUSED, |
| 1362 | R.attr.state_selected, VIEW_STATE_SELECTED, |
| 1363 | R.attr.state_focused, VIEW_STATE_FOCUSED, |
| 1364 | R.attr.state_enabled, VIEW_STATE_ENABLED, |
| 1365 | R.attr.state_pressed, VIEW_STATE_PRESSED, |
| 1366 | R.attr.state_activated, VIEW_STATE_ACTIVATED, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1367 | R.attr.state_accelerated, VIEW_STATE_ACCELERATED, |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1368 | R.attr.state_hovered, VIEW_STATE_HOVERED, |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1369 | R.attr.state_drag_can_accept, VIEW_STATE_DRAG_CAN_ACCEPT, |
| 1370 | R.attr.state_drag_hovered, VIEW_STATE_DRAG_HOVERED, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1371 | }; |
| 1372 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1373 | static { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1374 | if ((VIEW_STATE_IDS.length/2) != R.styleable.ViewDrawableStates.length) { |
| 1375 | throw new IllegalStateException( |
| 1376 | "VIEW_STATE_IDs array length does not match ViewDrawableStates style array"); |
| 1377 | } |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1378 | int[] orderedIds = new int[VIEW_STATE_IDS.length]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1379 | for (int i = 0; i < R.styleable.ViewDrawableStates.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1380 | int viewState = R.styleable.ViewDrawableStates[i]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1381 | for (int j = 0; j<VIEW_STATE_IDS.length; j += 2) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1382 | if (VIEW_STATE_IDS[j] == viewState) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1383 | orderedIds[i * 2] = viewState; |
| 1384 | orderedIds[i * 2 + 1] = VIEW_STATE_IDS[j + 1]; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1385 | } |
| 1386 | } |
| 1387 | } |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1388 | final int NUM_BITS = VIEW_STATE_IDS.length / 2; |
| 1389 | VIEW_STATE_SETS = new int[1 << NUM_BITS][]; |
| 1390 | for (int i = 0; i < VIEW_STATE_SETS.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1391 | int numBits = Integer.bitCount(i); |
| 1392 | int[] set = new int[numBits]; |
| 1393 | int pos = 0; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1394 | for (int j = 0; j < orderedIds.length; j += 2) { |
| 1395 | if ((i & orderedIds[j+1]) != 0) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1396 | set[pos++] = orderedIds[j]; |
| 1397 | } |
| 1398 | } |
| 1399 | VIEW_STATE_SETS[i] = set; |
| 1400 | } |
| 1401 | |
| 1402 | EMPTY_STATE_SET = VIEW_STATE_SETS[0]; |
| 1403 | WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_WINDOW_FOCUSED]; |
| 1404 | SELECTED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_SELECTED]; |
| 1405 | SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1406 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED]; |
| 1407 | FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_FOCUSED]; |
| 1408 | FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1409 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED]; |
| 1410 | FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1411 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED]; |
| 1412 | FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1413 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1414 | | VIEW_STATE_FOCUSED]; |
| 1415 | ENABLED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_ENABLED]; |
| 1416 | ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1417 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED]; |
| 1418 | ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1419 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED]; |
| 1420 | ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1421 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1422 | | VIEW_STATE_ENABLED]; |
| 1423 | ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1424 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED]; |
| 1425 | ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1426 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1427 | | VIEW_STATE_ENABLED]; |
| 1428 | ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1429 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1430 | | VIEW_STATE_ENABLED]; |
| 1431 | ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1432 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1433 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED]; |
| 1434 | |
| 1435 | PRESSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_PRESSED]; |
| 1436 | PRESSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1437 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_PRESSED]; |
| 1438 | PRESSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1439 | VIEW_STATE_SELECTED | VIEW_STATE_PRESSED]; |
| 1440 | PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1441 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1442 | | VIEW_STATE_PRESSED]; |
| 1443 | PRESSED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1444 | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1445 | PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1446 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1447 | | VIEW_STATE_PRESSED]; |
| 1448 | PRESSED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1449 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1450 | | VIEW_STATE_PRESSED]; |
| 1451 | PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1452 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1453 | | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1454 | PRESSED_ENABLED_STATE_SET = VIEW_STATE_SETS[ |
| 1455 | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1456 | PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1457 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED |
| 1458 | | VIEW_STATE_PRESSED]; |
| 1459 | PRESSED_ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1460 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED |
| 1461 | | VIEW_STATE_PRESSED]; |
| 1462 | PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1463 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1464 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1465 | PRESSED_ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1466 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED |
| 1467 | | VIEW_STATE_PRESSED]; |
| 1468 | PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1469 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1470 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1471 | PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1472 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1473 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1474 | PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1475 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1476 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED |
| 1477 | | VIEW_STATE_PRESSED]; |
| 1478 | } |
| 1479 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1480 | /** |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1481 | * Accessibility event types that are dispatched for text population. |
| 1482 | */ |
| 1483 | private static final int POPULATING_ACCESSIBILITY_EVENT_TYPES = |
| 1484 | AccessibilityEvent.TYPE_VIEW_CLICKED |
| 1485 | | AccessibilityEvent.TYPE_VIEW_LONG_CLICKED |
| 1486 | | AccessibilityEvent.TYPE_VIEW_SELECTED |
| 1487 | | AccessibilityEvent.TYPE_VIEW_FOCUSED |
| 1488 | | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED |
| 1489 | | AccessibilityEvent.TYPE_VIEW_HOVER_ENTER |
Svetoslav Ganov | 9920f4f | 2011-10-07 18:39:11 -0700 | [diff] [blame] | 1490 | | AccessibilityEvent.TYPE_VIEW_HOVER_EXIT |
Svetoslav Ganov | 84dd52e | 2011-11-18 10:24:00 -0800 | [diff] [blame] | 1491 | | AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED |
| 1492 | | AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED; |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1493 | |
| 1494 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | * Temporary Rect currently for use in setBackground(). This will probably |
| 1496 | * be extended in the future to hold our own class with more than just |
| 1497 | * a Rect. :) |
| 1498 | */ |
| 1499 | static final ThreadLocal<Rect> sThreadLocal = new ThreadLocal<Rect>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1500 | |
| 1501 | /** |
| 1502 | * Map used to store views' tags. |
| 1503 | */ |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 1504 | private SparseArray<Object> mKeyedTags; |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1505 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1507 | * The next available accessiiblity id. |
| 1508 | */ |
| 1509 | private static int sNextAccessibilityViewId; |
| 1510 | |
| 1511 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1512 | * The animation currently associated with this view. |
| 1513 | * @hide |
| 1514 | */ |
| 1515 | protected Animation mCurrentAnimation = null; |
| 1516 | |
| 1517 | /** |
| 1518 | * Width as measured during measure pass. |
| 1519 | * {@hide} |
| 1520 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1521 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1522 | int mMeasuredWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1523 | |
| 1524 | /** |
| 1525 | * Height as measured during measure pass. |
| 1526 | * {@hide} |
| 1527 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1528 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1529 | int mMeasuredHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1530 | |
| 1531 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1532 | * Flag to indicate that this view was marked INVALIDATED, or had its display list |
| 1533 | * invalidated, prior to the current drawing iteration. If true, the view must re-draw |
| 1534 | * its display list. This flag, used only when hw accelerated, allows us to clear the |
| 1535 | * flag while retaining this information until it's needed (at getDisplayList() time and |
| 1536 | * in drawChild(), when we decide to draw a view's children's display lists into our own). |
| 1537 | * |
| 1538 | * {@hide} |
| 1539 | */ |
| 1540 | boolean mRecreateDisplayList = false; |
| 1541 | |
| 1542 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1543 | * The view's identifier. |
| 1544 | * {@hide} |
| 1545 | * |
| 1546 | * @see #setId(int) |
| 1547 | * @see #getId() |
| 1548 | */ |
| 1549 | @ViewDebug.ExportedProperty(resolveId = true) |
| 1550 | int mID = NO_ID; |
| 1551 | |
| 1552 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 1553 | * The stable ID of this view for accessibility purposes. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1554 | */ |
| 1555 | int mAccessibilityViewId = NO_ID; |
| 1556 | |
| 1557 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1558 | * The view's tag. |
| 1559 | * {@hide} |
| 1560 | * |
| 1561 | * @see #setTag(Object) |
| 1562 | * @see #getTag() |
| 1563 | */ |
| 1564 | protected Object mTag; |
| 1565 | |
| 1566 | // for mPrivateFlags: |
| 1567 | /** {@hide} */ |
| 1568 | static final int WANTS_FOCUS = 0x00000001; |
| 1569 | /** {@hide} */ |
| 1570 | static final int FOCUSED = 0x00000002; |
| 1571 | /** {@hide} */ |
| 1572 | static final int SELECTED = 0x00000004; |
| 1573 | /** {@hide} */ |
| 1574 | static final int IS_ROOT_NAMESPACE = 0x00000008; |
| 1575 | /** {@hide} */ |
| 1576 | static final int HAS_BOUNDS = 0x00000010; |
| 1577 | /** {@hide} */ |
| 1578 | static final int DRAWN = 0x00000020; |
| 1579 | /** |
| 1580 | * When this flag is set, this view is running an animation on behalf of its |
| 1581 | * children and should therefore not cancel invalidate requests, even if they |
| 1582 | * lie outside of this view's bounds. |
| 1583 | * |
| 1584 | * {@hide} |
| 1585 | */ |
| 1586 | static final int DRAW_ANIMATION = 0x00000040; |
| 1587 | /** {@hide} */ |
| 1588 | static final int SKIP_DRAW = 0x00000080; |
| 1589 | /** {@hide} */ |
| 1590 | static final int ONLY_DRAWS_BACKGROUND = 0x00000100; |
| 1591 | /** {@hide} */ |
| 1592 | static final int REQUEST_TRANSPARENT_REGIONS = 0x00000200; |
| 1593 | /** {@hide} */ |
| 1594 | static final int DRAWABLE_STATE_DIRTY = 0x00000400; |
| 1595 | /** {@hide} */ |
| 1596 | static final int MEASURED_DIMENSION_SET = 0x00000800; |
| 1597 | /** {@hide} */ |
| 1598 | static final int FORCE_LAYOUT = 0x00001000; |
Konstantin Lopyrev | c6dc457 | 2010-08-06 15:01:52 -0700 | [diff] [blame] | 1599 | /** {@hide} */ |
| 1600 | static final int LAYOUT_REQUIRED = 0x00002000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1601 | |
| 1602 | private static final int PRESSED = 0x00004000; |
| 1603 | |
| 1604 | /** {@hide} */ |
| 1605 | static final int DRAWING_CACHE_VALID = 0x00008000; |
| 1606 | /** |
| 1607 | * Flag used to indicate that this view should be drawn once more (and only once |
| 1608 | * more) after its animation has completed. |
| 1609 | * {@hide} |
| 1610 | */ |
| 1611 | static final int ANIMATION_STARTED = 0x00010000; |
| 1612 | |
| 1613 | private static final int SAVE_STATE_CALLED = 0x00020000; |
| 1614 | |
| 1615 | /** |
| 1616 | * Indicates that the View returned true when onSetAlpha() was called and that |
| 1617 | * the alpha must be restored. |
| 1618 | * {@hide} |
| 1619 | */ |
| 1620 | static final int ALPHA_SET = 0x00040000; |
| 1621 | |
| 1622 | /** |
| 1623 | * Set by {@link #setScrollContainer(boolean)}. |
| 1624 | */ |
| 1625 | static final int SCROLL_CONTAINER = 0x00080000; |
| 1626 | |
| 1627 | /** |
| 1628 | * Set by {@link #setScrollContainer(boolean)}. |
| 1629 | */ |
| 1630 | static final int SCROLL_CONTAINER_ADDED = 0x00100000; |
| 1631 | |
| 1632 | /** |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1633 | * View flag indicating whether this view was invalidated (fully or partially.) |
| 1634 | * |
| 1635 | * @hide |
| 1636 | */ |
| 1637 | static final int DIRTY = 0x00200000; |
| 1638 | |
| 1639 | /** |
| 1640 | * View flag indicating whether this view was invalidated by an opaque |
| 1641 | * invalidate request. |
| 1642 | * |
| 1643 | * @hide |
| 1644 | */ |
| 1645 | static final int DIRTY_OPAQUE = 0x00400000; |
| 1646 | |
| 1647 | /** |
| 1648 | * Mask for {@link #DIRTY} and {@link #DIRTY_OPAQUE}. |
| 1649 | * |
| 1650 | * @hide |
| 1651 | */ |
| 1652 | static final int DIRTY_MASK = 0x00600000; |
| 1653 | |
| 1654 | /** |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1655 | * Indicates whether the background is opaque. |
| 1656 | * |
| 1657 | * @hide |
| 1658 | */ |
| 1659 | static final int OPAQUE_BACKGROUND = 0x00800000; |
| 1660 | |
| 1661 | /** |
| 1662 | * Indicates whether the scrollbars are opaque. |
| 1663 | * |
| 1664 | * @hide |
| 1665 | */ |
| 1666 | static final int OPAQUE_SCROLLBARS = 0x01000000; |
| 1667 | |
| 1668 | /** |
| 1669 | * Indicates whether the view is opaque. |
| 1670 | * |
| 1671 | * @hide |
| 1672 | */ |
| 1673 | static final int OPAQUE_MASK = 0x01800000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1674 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1675 | /** |
| 1676 | * Indicates a prepressed state; |
| 1677 | * the short time between ACTION_DOWN and recognizing |
| 1678 | * a 'real' press. Prepressed is used to recognize quick taps |
| 1679 | * even when they are shorter than ViewConfiguration.getTapTimeout(). |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1680 | * |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1681 | * @hide |
| 1682 | */ |
| 1683 | private static final int PREPRESSED = 0x02000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1684 | |
Adam Powell | c9fbaab | 2010-02-16 17:16:19 -0800 | [diff] [blame] | 1685 | /** |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 1686 | * Indicates whether the view is temporarily detached. |
| 1687 | * |
| 1688 | * @hide |
| 1689 | */ |
| 1690 | static final int CANCEL_NEXT_UP_EVENT = 0x04000000; |
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 | /** |
| 1693 | * Indicates that we should awaken scroll bars once attached |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1694 | * |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1695 | * @hide |
| 1696 | */ |
| 1697 | private static final int AWAKEN_SCROLL_BARS_ON_ATTACH = 0x08000000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1698 | |
| 1699 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1700 | * Indicates that the view has received HOVER_ENTER. Cleared on HOVER_EXIT. |
| 1701 | * @hide |
| 1702 | */ |
| 1703 | private static final int HOVERED = 0x10000000; |
| 1704 | |
| 1705 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1706 | * Indicates that pivotX or pivotY were explicitly set and we should not assume the center |
| 1707 | * for transform operations |
| 1708 | * |
| 1709 | * @hide |
| 1710 | */ |
Adam Powell | f37df07 | 2010-09-17 16:22:49 -0700 | [diff] [blame] | 1711 | private static final int PIVOT_EXPLICITLY_SET = 0x20000000; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1712 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1713 | /** {@hide} */ |
Adam Powell | f37df07 | 2010-09-17 16:22:49 -0700 | [diff] [blame] | 1714 | static final int ACTIVATED = 0x40000000; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1715 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1716 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1717 | * Indicates that this view was specifically invalidated, not just dirtied because some |
| 1718 | * child view was invalidated. The flag is used to determine when we need to recreate |
| 1719 | * a view's display list (as opposed to just returning a reference to its existing |
| 1720 | * display list). |
| 1721 | * |
| 1722 | * @hide |
| 1723 | */ |
| 1724 | static final int INVALIDATED = 0x80000000; |
| 1725 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1726 | /* Masks for mPrivateFlags2 */ |
| 1727 | |
| 1728 | /** |
| 1729 | * Indicates that this view has reported that it can accept the current drag's content. |
| 1730 | * Cleared when the drag operation concludes. |
| 1731 | * @hide |
| 1732 | */ |
| 1733 | static final int DRAG_CAN_ACCEPT = 0x00000001; |
| 1734 | |
| 1735 | /** |
| 1736 | * Indicates that this view is currently directly under the drag location in a |
| 1737 | * drag-and-drop operation involving content that it can accept. Cleared when |
| 1738 | * the drag exits the view, or when the drag operation concludes. |
| 1739 | * @hide |
| 1740 | */ |
| 1741 | static final int DRAG_HOVERED = 0x00000002; |
| 1742 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1743 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1744 | * Indicates whether the view layout direction has been resolved and drawn to the |
| 1745 | * right-to-left direction. |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1746 | * |
| 1747 | * @hide |
| 1748 | */ |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1749 | static final int LAYOUT_DIRECTION_RESOLVED_RTL = 0x00000004; |
| 1750 | |
| 1751 | /** |
| 1752 | * Indicates whether the view layout direction has been resolved. |
| 1753 | * |
| 1754 | * @hide |
| 1755 | */ |
| 1756 | static final int LAYOUT_DIRECTION_RESOLVED = 0x00000008; |
| 1757 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1758 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1759 | /* End of masks for mPrivateFlags2 */ |
| 1760 | |
| 1761 | static final int DRAG_MASK = DRAG_CAN_ACCEPT | DRAG_HOVERED; |
| 1762 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1763 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 1764 | * Always allow a user to over-scroll this view, provided it is a |
| 1765 | * view that can scroll. |
| 1766 | * |
| 1767 | * @see #getOverScrollMode() |
| 1768 | * @see #setOverScrollMode(int) |
| 1769 | */ |
| 1770 | public static final int OVER_SCROLL_ALWAYS = 0; |
| 1771 | |
| 1772 | /** |
| 1773 | * Allow a user to over-scroll this view only if the content is large |
| 1774 | * enough to meaningfully scroll, provided it is a view that can scroll. |
| 1775 | * |
| 1776 | * @see #getOverScrollMode() |
| 1777 | * @see #setOverScrollMode(int) |
| 1778 | */ |
| 1779 | public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1; |
| 1780 | |
| 1781 | /** |
| 1782 | * Never allow a user to over-scroll this view. |
| 1783 | * |
| 1784 | * @see #getOverScrollMode() |
| 1785 | * @see #setOverScrollMode(int) |
| 1786 | */ |
| 1787 | public static final int OVER_SCROLL_NEVER = 2; |
| 1788 | |
| 1789 | /** |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1790 | * 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] | 1791 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1792 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1793 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1794 | public static final int SYSTEM_UI_FLAG_VISIBLE = 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1795 | |
| 1796 | /** |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1797 | * View has requested the system UI to enter an unobtrusive "low profile" mode. |
| 1798 | * |
| 1799 | * This is for use in games, book readers, video players, or any other "immersive" application |
| 1800 | * where the usual system chrome is deemed too distracting. |
| 1801 | * |
| 1802 | * 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] | 1803 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1804 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1805 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1806 | public static final int SYSTEM_UI_FLAG_LOW_PROFILE = 0x00000001; |
| 1807 | |
| 1808 | /** |
| 1809 | * View has requested that the system navigation be temporarily hidden. |
| 1810 | * |
| 1811 | * This is an even less obtrusive state than that called for by |
| 1812 | * {@link #SYSTEM_UI_FLAG_LOW_PROFILE}; on devices that draw essential navigation controls |
| 1813 | * (Home, Back, and the like) on screen, <code>SYSTEM_UI_FLAG_HIDE_NAVIGATION</code> will cause |
| 1814 | * those to disappear. This is useful (in conjunction with the |
| 1815 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN FLAG_FULLSCREEN} and |
| 1816 | * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN FLAG_LAYOUT_IN_SCREEN} |
| 1817 | * window flags) for displaying content using every last pixel on the display. |
| 1818 | * |
| 1819 | * There is a limitation: because navigation controls are so important, the least user |
| 1820 | * interaction will cause them to reappear immediately. |
| 1821 | * |
| 1822 | * @see #setSystemUiVisibility(int) |
| 1823 | */ |
| 1824 | public static final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 0x00000002; |
| 1825 | |
| 1826 | /** |
| 1827 | * @deprecated Use {@link #SYSTEM_UI_FLAG_LOW_PROFILE} instead. |
| 1828 | */ |
| 1829 | public static final int STATUS_BAR_HIDDEN = SYSTEM_UI_FLAG_LOW_PROFILE; |
| 1830 | |
| 1831 | /** |
| 1832 | * @deprecated Use {@link #SYSTEM_UI_FLAG_VISIBLE} instead. |
| 1833 | */ |
| 1834 | public static final int STATUS_BAR_VISIBLE = SYSTEM_UI_FLAG_VISIBLE; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1835 | |
| 1836 | /** |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 1837 | * @hide |
| 1838 | * |
| 1839 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1840 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1841 | * |
| 1842 | * Flag to make the status bar not expandable. Unless you also |
| 1843 | * set {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show. |
| 1844 | */ |
| 1845 | public static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000; |
| 1846 | |
| 1847 | /** |
| 1848 | * @hide |
| 1849 | * |
| 1850 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1851 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1852 | * |
| 1853 | * Flag to hide notification icons and scrolling ticker text. |
| 1854 | */ |
| 1855 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ICONS = 0x00020000; |
| 1856 | |
| 1857 | /** |
| 1858 | * @hide |
| 1859 | * |
| 1860 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1861 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1862 | * |
| 1863 | * Flag to disable incoming notification alerts. This will not block |
| 1864 | * icons, but it will block sound, vibrating and other visual or aural notifications. |
| 1865 | */ |
| 1866 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ALERTS = 0x00040000; |
| 1867 | |
| 1868 | /** |
| 1869 | * @hide |
| 1870 | * |
| 1871 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1872 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1873 | * |
| 1874 | * Flag to hide only the scrolling ticker. Note that |
| 1875 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS} implies |
| 1876 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_TICKER}. |
| 1877 | */ |
| 1878 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_TICKER = 0x00080000; |
| 1879 | |
| 1880 | /** |
| 1881 | * @hide |
| 1882 | * |
| 1883 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1884 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1885 | * |
| 1886 | * Flag to hide the center system info area. |
| 1887 | */ |
| 1888 | public static final int STATUS_BAR_DISABLE_SYSTEM_INFO = 0x00100000; |
| 1889 | |
| 1890 | /** |
| 1891 | * @hide |
| 1892 | * |
| 1893 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1894 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1895 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 1896 | * Flag to hide only the home button. Don't use this |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 1897 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 1898 | */ |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 1899 | public static final int STATUS_BAR_DISABLE_HOME = 0x00200000; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 1900 | |
| 1901 | /** |
| 1902 | * @hide |
| 1903 | * |
| 1904 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1905 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1906 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 1907 | * Flag to hide only the back button. Don't use this |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 1908 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 1909 | */ |
| 1910 | public static final int STATUS_BAR_DISABLE_BACK = 0x00400000; |
| 1911 | |
| 1912 | /** |
| 1913 | * @hide |
| 1914 | * |
| 1915 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1916 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1917 | * |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 1918 | * Flag to hide only the clock. You might use this if your activity has |
| 1919 | * its own clock making the status bar's clock redundant. |
| 1920 | */ |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 1921 | public static final int STATUS_BAR_DISABLE_CLOCK = 0x00800000; |
| 1922 | |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 1923 | /** |
| 1924 | * @hide |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 1925 | * |
| 1926 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 1927 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 1928 | * |
| 1929 | * Flag to hide only the recent apps button. Don't use this |
| 1930 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 1931 | */ |
| 1932 | public static final int STATUS_BAR_DISABLE_RECENT = 0x01000000; |
| 1933 | |
| 1934 | /** |
| 1935 | * @hide |
| 1936 | * |
| 1937 | * NOTE: This flag may only be used in subtreeSystemUiVisibility, etc. etc. |
| 1938 | * |
| 1939 | * This hides HOME and RECENT and is provided for compatibility with interim implementations. |
| 1940 | */ |
| 1941 | @Deprecated |
| 1942 | public static final int STATUS_BAR_DISABLE_NAVIGATION = |
| 1943 | STATUS_BAR_DISABLE_HOME | STATUS_BAR_DISABLE_RECENT; |
| 1944 | |
| 1945 | /** |
| 1946 | * @hide |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 1947 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 1948 | public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK = 0x0000FFFF; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 1949 | |
| 1950 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1951 | * These are the system UI flags that can be cleared by events outside |
| 1952 | * of an application. Currently this is just the ability to tap on the |
| 1953 | * screen while hiding the navigation bar to have it return. |
| 1954 | * @hide |
| 1955 | */ |
| 1956 | public static final int SYSTEM_UI_CLEARABLE_FLAGS = |
| 1957 | SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 1958 | |
| 1959 | /** |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 1960 | * Find views that render the specified text. |
| 1961 | * |
| 1962 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 1963 | */ |
| 1964 | public static final int FIND_VIEWS_WITH_TEXT = 0x00000001; |
| 1965 | |
| 1966 | /** |
| 1967 | * Find find views that contain the specified content description. |
| 1968 | * |
| 1969 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 1970 | */ |
| 1971 | public static final int FIND_VIEWS_WITH_CONTENT_DESCRIPTION = 0x00000002; |
| 1972 | |
| 1973 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 1974 | * Find views that contain {@link AccessibilityNodeProvider}. Such |
| 1975 | * a View is a root of virtual view hierarchy and may contain the searched |
| 1976 | * text. If this flag is set Views with providers are automatically |
| 1977 | * added and it is a responsibility of the client to call the APIs of |
| 1978 | * the provider to determine whether the virtual tree rooted at this View |
| 1979 | * contains the text, i.e. getting the list of {@link AccessibilityNodeInfo}s |
| 1980 | * represeting the virtual views with this text. |
| 1981 | * |
| 1982 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 1983 | * |
| 1984 | * @hide |
| 1985 | */ |
| 1986 | public static final int FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS = 0x00000004; |
| 1987 | |
| 1988 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 1989 | * Controls the over-scroll mode for this view. |
| 1990 | * See {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)}, |
| 1991 | * {@link #OVER_SCROLL_ALWAYS}, {@link #OVER_SCROLL_IF_CONTENT_SCROLLS}, |
| 1992 | * and {@link #OVER_SCROLL_NEVER}. |
| 1993 | */ |
| 1994 | private int mOverScrollMode; |
| 1995 | |
| 1996 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1997 | * The parent this view is attached to. |
| 1998 | * {@hide} |
| 1999 | * |
| 2000 | * @see #getParent() |
| 2001 | */ |
| 2002 | protected ViewParent mParent; |
| 2003 | |
| 2004 | /** |
| 2005 | * {@hide} |
| 2006 | */ |
| 2007 | AttachInfo mAttachInfo; |
| 2008 | |
| 2009 | /** |
| 2010 | * {@hide} |
| 2011 | */ |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2012 | @ViewDebug.ExportedProperty(flagMapping = { |
| 2013 | @ViewDebug.FlagToString(mask = FORCE_LAYOUT, equals = FORCE_LAYOUT, |
| 2014 | name = "FORCE_LAYOUT"), |
| 2015 | @ViewDebug.FlagToString(mask = LAYOUT_REQUIRED, equals = LAYOUT_REQUIRED, |
| 2016 | name = "LAYOUT_REQUIRED"), |
| 2017 | @ViewDebug.FlagToString(mask = DRAWING_CACHE_VALID, equals = DRAWING_CACHE_VALID, |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 2018 | name = "DRAWING_CACHE_INVALID", outputIf = false), |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2019 | @ViewDebug.FlagToString(mask = DRAWN, equals = DRAWN, name = "DRAWN", outputIf = true), |
| 2020 | @ViewDebug.FlagToString(mask = DRAWN, equals = DRAWN, name = "NOT_DRAWN", outputIf = false), |
| 2021 | @ViewDebug.FlagToString(mask = DIRTY_MASK, equals = DIRTY_OPAQUE, name = "DIRTY_OPAQUE"), |
| 2022 | @ViewDebug.FlagToString(mask = DIRTY_MASK, equals = DIRTY, name = "DIRTY") |
| 2023 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2024 | int mPrivateFlags; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2025 | int mPrivateFlags2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2026 | |
| 2027 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2028 | * This view's request for the visibility of the status bar. |
| 2029 | * @hide |
| 2030 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2031 | @ViewDebug.ExportedProperty(flagMapping = { |
| 2032 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2033 | equals = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2034 | name = "SYSTEM_UI_FLAG_LOW_PROFILE", outputIf = true), |
| 2035 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2036 | equals = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2037 | name = "SYSTEM_UI_FLAG_HIDE_NAVIGATION", outputIf = true), |
| 2038 | @ViewDebug.FlagToString(mask = PUBLIC_STATUS_BAR_VISIBILITY_MASK, |
| 2039 | equals = SYSTEM_UI_FLAG_VISIBLE, |
| 2040 | name = "SYSTEM_UI_FLAG_VISIBLE", outputIf = true) |
| 2041 | }) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2042 | int mSystemUiVisibility; |
| 2043 | |
| 2044 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2045 | * Count of how many windows this view has been attached to. |
| 2046 | */ |
| 2047 | int mWindowAttachCount; |
| 2048 | |
| 2049 | /** |
| 2050 | * The layout parameters associated with this view and used by the parent |
| 2051 | * {@link android.view.ViewGroup} to determine how this view should be |
| 2052 | * laid out. |
| 2053 | * {@hide} |
| 2054 | */ |
| 2055 | protected ViewGroup.LayoutParams mLayoutParams; |
| 2056 | |
| 2057 | /** |
| 2058 | * The view flags hold various views states. |
| 2059 | * {@hide} |
| 2060 | */ |
| 2061 | @ViewDebug.ExportedProperty |
| 2062 | int mViewFlags; |
| 2063 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2064 | static class TransformationInfo { |
| 2065 | /** |
| 2066 | * The transform matrix for the View. This transform is calculated internally |
| 2067 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2068 | * is used by default. Do *not* use this variable directly; instead call |
| 2069 | * getMatrix(), which will automatically recalculate the matrix if necessary |
| 2070 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2071 | */ |
| 2072 | private final Matrix mMatrix = new Matrix(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2073 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2074 | /** |
| 2075 | * The transform matrix for the View. This transform is calculated internally |
| 2076 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2077 | * is used by default. Do *not* use this variable directly; instead call |
| 2078 | * getInverseMatrix(), which will automatically recalculate the matrix if necessary |
| 2079 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2080 | */ |
| 2081 | private Matrix mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2082 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2083 | /** |
| 2084 | * An internal variable that tracks whether we need to recalculate the |
| 2085 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2086 | * have changed since the matrix was last calculated. |
| 2087 | */ |
| 2088 | boolean mMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2089 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2090 | /** |
| 2091 | * An internal variable that tracks whether we need to recalculate the |
| 2092 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2093 | * have changed since the matrix was last calculated. |
| 2094 | */ |
| 2095 | private boolean mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2096 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2097 | /** |
| 2098 | * A variable that tracks whether we need to recalculate the |
| 2099 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2100 | * have changed since the matrix was last calculated. This variable |
| 2101 | * is only valid after a call to updateMatrix() or to a function that |
| 2102 | * calls it such as getMatrix(), hasIdentityMatrix() and getInverseMatrix(). |
| 2103 | */ |
| 2104 | private boolean mMatrixIsIdentity = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2105 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2106 | /** |
| 2107 | * The Camera object is used to compute a 3D matrix when rotationX or rotationY are set. |
| 2108 | */ |
| 2109 | private Camera mCamera = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2110 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2111 | /** |
| 2112 | * This matrix is used when computing the matrix for 3D rotations. |
| 2113 | */ |
| 2114 | private Matrix matrix3D = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2115 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2116 | /** |
| 2117 | * These prev values are used to recalculate a centered pivot point when necessary. The |
| 2118 | * pivot point is only used in matrix operations (when rotation, scale, or translation are |
| 2119 | * set), so thes values are only used then as well. |
| 2120 | */ |
| 2121 | private int mPrevWidth = -1; |
| 2122 | private int mPrevHeight = -1; |
| 2123 | |
| 2124 | /** |
| 2125 | * The degrees rotation around the vertical axis through the pivot point. |
| 2126 | */ |
| 2127 | @ViewDebug.ExportedProperty |
| 2128 | float mRotationY = 0f; |
| 2129 | |
| 2130 | /** |
| 2131 | * The degrees rotation around the horizontal axis through the pivot point. |
| 2132 | */ |
| 2133 | @ViewDebug.ExportedProperty |
| 2134 | float mRotationX = 0f; |
| 2135 | |
| 2136 | /** |
| 2137 | * The degrees rotation around the pivot point. |
| 2138 | */ |
| 2139 | @ViewDebug.ExportedProperty |
| 2140 | float mRotation = 0f; |
| 2141 | |
| 2142 | /** |
| 2143 | * The amount of translation of the object away from its left property (post-layout). |
| 2144 | */ |
| 2145 | @ViewDebug.ExportedProperty |
| 2146 | float mTranslationX = 0f; |
| 2147 | |
| 2148 | /** |
| 2149 | * The amount of translation of the object away from its top property (post-layout). |
| 2150 | */ |
| 2151 | @ViewDebug.ExportedProperty |
| 2152 | float mTranslationY = 0f; |
| 2153 | |
| 2154 | /** |
| 2155 | * The amount of scale in the x direction around the pivot point. A |
| 2156 | * value of 1 means no scaling is applied. |
| 2157 | */ |
| 2158 | @ViewDebug.ExportedProperty |
| 2159 | float mScaleX = 1f; |
| 2160 | |
| 2161 | /** |
| 2162 | * The amount of scale in the y direction around the pivot point. A |
| 2163 | * value of 1 means no scaling is applied. |
| 2164 | */ |
| 2165 | @ViewDebug.ExportedProperty |
| 2166 | float mScaleY = 1f; |
| 2167 | |
| 2168 | /** |
| 2169 | * The amount of scale in the x direction around the pivot point. A |
| 2170 | * value of 1 means no scaling is applied. |
| 2171 | */ |
| 2172 | @ViewDebug.ExportedProperty |
| 2173 | float mPivotX = 0f; |
| 2174 | |
| 2175 | /** |
| 2176 | * The amount of scale in the y direction around the pivot point. A |
| 2177 | * value of 1 means no scaling is applied. |
| 2178 | */ |
| 2179 | @ViewDebug.ExportedProperty |
| 2180 | float mPivotY = 0f; |
| 2181 | |
| 2182 | /** |
| 2183 | * The opacity of the View. This is a value from 0 to 1, where 0 means |
| 2184 | * completely transparent and 1 means completely opaque. |
| 2185 | */ |
| 2186 | @ViewDebug.ExportedProperty |
| 2187 | float mAlpha = 1f; |
| 2188 | } |
| 2189 | |
| 2190 | TransformationInfo mTransformationInfo; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2191 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2192 | private boolean mLastIsOpaque; |
| 2193 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2194 | /** |
| 2195 | * Convenience value to check for float values that are close enough to zero to be considered |
| 2196 | * zero. |
| 2197 | */ |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame] | 2198 | private static final float NONZERO_EPSILON = .001f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2199 | |
| 2200 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2201 | * The distance in pixels from the left edge of this view's parent |
| 2202 | * to the left edge of this view. |
| 2203 | * {@hide} |
| 2204 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2205 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2206 | protected int mLeft; |
| 2207 | /** |
| 2208 | * The distance in pixels from the left edge of this view's parent |
| 2209 | * to the right edge of this view. |
| 2210 | * {@hide} |
| 2211 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2212 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2213 | protected int mRight; |
| 2214 | /** |
| 2215 | * The distance in pixels from the top edge of this view's parent |
| 2216 | * to the top edge of this view. |
| 2217 | * {@hide} |
| 2218 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2219 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2220 | protected int mTop; |
| 2221 | /** |
| 2222 | * The distance in pixels from the top edge of this view's parent |
| 2223 | * to the bottom edge of this view. |
| 2224 | * {@hide} |
| 2225 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2226 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2227 | protected int mBottom; |
| 2228 | |
| 2229 | /** |
| 2230 | * The offset, in pixels, by which the content of this view is scrolled |
| 2231 | * horizontally. |
| 2232 | * {@hide} |
| 2233 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2234 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2235 | protected int mScrollX; |
| 2236 | /** |
| 2237 | * The offset, in pixels, by which the content of this view is scrolled |
| 2238 | * vertically. |
| 2239 | * {@hide} |
| 2240 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2241 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2242 | protected int mScrollY; |
| 2243 | |
| 2244 | /** |
| 2245 | * The left padding in pixels, that is the distance in pixels between the |
| 2246 | * left edge of this view and the left edge of its content. |
| 2247 | * {@hide} |
| 2248 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2249 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2250 | protected int mPaddingLeft; |
| 2251 | /** |
| 2252 | * The right padding in pixels, that is the distance in pixels between the |
| 2253 | * right edge of this view and the right edge of its content. |
| 2254 | * {@hide} |
| 2255 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2256 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2257 | protected int mPaddingRight; |
| 2258 | /** |
| 2259 | * The top padding in pixels, that is the distance in pixels between the |
| 2260 | * top edge of this view and the top edge of its content. |
| 2261 | * {@hide} |
| 2262 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2263 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2264 | protected int mPaddingTop; |
| 2265 | /** |
| 2266 | * The bottom padding in pixels, that is the distance in pixels between the |
| 2267 | * bottom edge of this view and the bottom edge of its content. |
| 2268 | * {@hide} |
| 2269 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2270 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2271 | protected int mPaddingBottom; |
| 2272 | |
| 2273 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2274 | * Briefly describes the view and is primarily used for accessibility support. |
| 2275 | */ |
| 2276 | private CharSequence mContentDescription; |
| 2277 | |
| 2278 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2279 | * 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] | 2280 | * |
| 2281 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2282 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2283 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2284 | protected int mUserPaddingRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2285 | |
| 2286 | /** |
| 2287 | * 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] | 2288 | * |
| 2289 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2290 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2291 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2292 | protected int mUserPaddingBottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2293 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2294 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2295 | * 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] | 2296 | * |
| 2297 | * @hide |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2298 | */ |
| 2299 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2300 | protected int mUserPaddingLeft; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2301 | |
| 2302 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 2303 | * Cache if the user padding is relative. |
| 2304 | * |
| 2305 | */ |
| 2306 | @ViewDebug.ExportedProperty(category = "padding") |
| 2307 | boolean mUserPaddingRelative; |
| 2308 | |
| 2309 | /** |
| 2310 | * Cache the paddingStart set by the user to append to the scrollbar's size. |
| 2311 | * |
| 2312 | */ |
| 2313 | @ViewDebug.ExportedProperty(category = "padding") |
| 2314 | int mUserPaddingStart; |
| 2315 | |
| 2316 | /** |
| 2317 | * Cache the paddingEnd set by the user to append to the scrollbar's size. |
| 2318 | * |
| 2319 | */ |
| 2320 | @ViewDebug.ExportedProperty(category = "padding") |
| 2321 | int mUserPaddingEnd; |
| 2322 | |
| 2323 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2324 | * @hide |
| 2325 | */ |
| 2326 | int mOldWidthMeasureSpec = Integer.MIN_VALUE; |
| 2327 | /** |
| 2328 | * @hide |
| 2329 | */ |
| 2330 | int mOldHeightMeasureSpec = Integer.MIN_VALUE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2332 | private Drawable mBGDrawable; |
| 2333 | |
| 2334 | private int mBackgroundResource; |
| 2335 | private boolean mBackgroundSizeChanged; |
| 2336 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2337 | static class ListenerInfo { |
| 2338 | /** |
| 2339 | * Listener used to dispatch focus change events. |
| 2340 | * This field should be made private, so it is hidden from the SDK. |
| 2341 | * {@hide} |
| 2342 | */ |
| 2343 | protected OnFocusChangeListener mOnFocusChangeListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2344 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2345 | /** |
| 2346 | * Listeners for layout change events. |
| 2347 | */ |
| 2348 | private ArrayList<OnLayoutChangeListener> mOnLayoutChangeListeners; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 2349 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2350 | /** |
| 2351 | * Listeners for attach events. |
| 2352 | */ |
| 2353 | private CopyOnWriteArrayList<OnAttachStateChangeListener> mOnAttachStateChangeListeners; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 2354 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2355 | /** |
| 2356 | * Listener used to dispatch click events. |
| 2357 | * This field should be made private, so it is hidden from the SDK. |
| 2358 | * {@hide} |
| 2359 | */ |
| 2360 | public OnClickListener mOnClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2361 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2362 | /** |
| 2363 | * Listener used to dispatch long click events. |
| 2364 | * This field should be made private, so it is hidden from the SDK. |
| 2365 | * {@hide} |
| 2366 | */ |
| 2367 | protected OnLongClickListener mOnLongClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2368 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2369 | /** |
| 2370 | * Listener used to build the context menu. |
| 2371 | * This field should be made private, so it is hidden from the SDK. |
| 2372 | * {@hide} |
| 2373 | */ |
| 2374 | protected OnCreateContextMenuListener mOnCreateContextMenuListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2375 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2376 | private OnKeyListener mOnKeyListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2377 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2378 | private OnTouchListener mOnTouchListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2379 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2380 | private OnHoverListener mOnHoverListener; |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2381 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2382 | private OnGenericMotionListener mOnGenericMotionListener; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2383 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2384 | private OnDragListener mOnDragListener; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 2385 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2386 | private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener; |
| 2387 | } |
| 2388 | |
| 2389 | ListenerInfo mListenerInfo; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2390 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2391 | /** |
| 2392 | * The application environment this view lives in. |
| 2393 | * This field should be made private, so it is hidden from the SDK. |
| 2394 | * {@hide} |
| 2395 | */ |
| 2396 | protected Context mContext; |
| 2397 | |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 2398 | private final Resources mResources; |
| 2399 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2400 | private ScrollabilityCache mScrollCache; |
| 2401 | |
| 2402 | private int[] mDrawableState = null; |
| 2403 | |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2404 | /** |
| 2405 | * Set to true when drawing cache is enabled and cannot be created. |
| 2406 | * |
| 2407 | * @hide |
| 2408 | */ |
| 2409 | public boolean mCachingFailed; |
| 2410 | |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 2411 | private Bitmap mDrawingCache; |
| 2412 | private Bitmap mUnscaledDrawingCache; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 2413 | private HardwareLayer mHardwareLayer; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2414 | DisplayList mDisplayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2415 | |
| 2416 | /** |
| 2417 | * When this view has focus and the next focus is {@link #FOCUS_LEFT}, |
| 2418 | * the user may specify which view to go to next. |
| 2419 | */ |
| 2420 | private int mNextFocusLeftId = View.NO_ID; |
| 2421 | |
| 2422 | /** |
| 2423 | * When this view has focus and the next focus is {@link #FOCUS_RIGHT}, |
| 2424 | * the user may specify which view to go to next. |
| 2425 | */ |
| 2426 | private int mNextFocusRightId = View.NO_ID; |
| 2427 | |
| 2428 | /** |
| 2429 | * When this view has focus and the next focus is {@link #FOCUS_UP}, |
| 2430 | * the user may specify which view to go to next. |
| 2431 | */ |
| 2432 | private int mNextFocusUpId = View.NO_ID; |
| 2433 | |
| 2434 | /** |
| 2435 | * When this view has focus and the next focus is {@link #FOCUS_DOWN}, |
| 2436 | * the user may specify which view to go to next. |
| 2437 | */ |
| 2438 | private int mNextFocusDownId = View.NO_ID; |
| 2439 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 2440 | /** |
| 2441 | * When this view has focus and the next focus is {@link #FOCUS_FORWARD}, |
| 2442 | * the user may specify which view to go to next. |
| 2443 | */ |
| 2444 | int mNextFocusForwardId = View.NO_ID; |
| 2445 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2446 | private CheckForLongPress mPendingCheckForLongPress; |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2447 | private CheckForTap mPendingCheckForTap = null; |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 2448 | private PerformClick mPerformClick; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 2449 | private SendViewScrolledAccessibilityEvent mSendViewScrolledAccessibilityEvent; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | private UnsetPressedState mUnsetPressedState; |
| 2452 | |
| 2453 | /** |
| 2454 | * Whether the long press's action has been invoked. The tap's action is invoked on the |
| 2455 | * up event while a long press is invoked as soon as the long press duration is reached, so |
| 2456 | * a long press could be performed before the tap is checked, in which case the tap's action |
| 2457 | * should not be invoked. |
| 2458 | */ |
| 2459 | private boolean mHasPerformedLongPress; |
| 2460 | |
| 2461 | /** |
| 2462 | * The minimum height of the view. We'll try our best to have the height |
| 2463 | * of this view to at least this amount. |
| 2464 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2465 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2466 | private int mMinHeight; |
| 2467 | |
| 2468 | /** |
| 2469 | * The minimum width of the view. We'll try our best to have the width |
| 2470 | * of this view to at least this amount. |
| 2471 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2472 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2473 | private int mMinWidth; |
| 2474 | |
| 2475 | /** |
| 2476 | * The delegate to handle touch events that are physically in this view |
| 2477 | * but should be handled by another view. |
| 2478 | */ |
| 2479 | private TouchDelegate mTouchDelegate = null; |
| 2480 | |
| 2481 | /** |
| 2482 | * Solid color to use as a background when creating the drawing cache. Enables |
| 2483 | * the cache to use 16 bit bitmaps instead of 32 bit. |
| 2484 | */ |
| 2485 | private int mDrawingCacheBackgroundColor = 0; |
| 2486 | |
| 2487 | /** |
| 2488 | * Special tree observer used when mAttachInfo is null. |
| 2489 | */ |
| 2490 | private ViewTreeObserver mFloatingTreeObserver; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2491 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2492 | /** |
| 2493 | * Cache the touch slop from the context that created the view. |
| 2494 | */ |
| 2495 | private int mTouchSlop; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2496 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2497 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2498 | * Object that handles automatic animation of view properties. |
| 2499 | */ |
| 2500 | private ViewPropertyAnimator mAnimator = null; |
| 2501 | |
| 2502 | /** |
Christopher Tate | 251602f | 2011-01-28 17:54:12 -0800 | [diff] [blame] | 2503 | * Flag indicating that a drag can cross window boundaries. When |
| 2504 | * {@link #startDrag(ClipData, DragShadowBuilder, Object, int)} is called |
| 2505 | * with this flag set, all visible applications will be able to participate |
| 2506 | * in the drag operation and receive the dragged content. |
Christopher Tate | 7f9ff9d | 2011-02-14 17:31:13 -0800 | [diff] [blame] | 2507 | * |
| 2508 | * @hide |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 2509 | */ |
| 2510 | public static final int DRAG_FLAG_GLOBAL = 1; |
| 2511 | |
| 2512 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2513 | * Vertical scroll factor cached by {@link #getVerticalScrollFactor}. |
| 2514 | */ |
| 2515 | private float mVerticalScrollFactor; |
| 2516 | |
| 2517 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2518 | * Position of the vertical scroll bar. |
| 2519 | */ |
| 2520 | private int mVerticalScrollbarPosition; |
| 2521 | |
| 2522 | /** |
| 2523 | * Position the scroll bar at the default position as determined by the system. |
| 2524 | */ |
| 2525 | public static final int SCROLLBAR_POSITION_DEFAULT = 0; |
| 2526 | |
| 2527 | /** |
| 2528 | * Position the scroll bar along the left edge. |
| 2529 | */ |
| 2530 | public static final int SCROLLBAR_POSITION_LEFT = 1; |
| 2531 | |
| 2532 | /** |
| 2533 | * Position the scroll bar along the right edge. |
| 2534 | */ |
| 2535 | public static final int SCROLLBAR_POSITION_RIGHT = 2; |
| 2536 | |
| 2537 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2538 | * Indicates that the view does not have a layer. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2539 | * |
| 2540 | * @see #getLayerType() |
| 2541 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2542 | * @see #LAYER_TYPE_SOFTWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2543 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2544 | */ |
| 2545 | public static final int LAYER_TYPE_NONE = 0; |
| 2546 | |
| 2547 | /** |
| 2548 | * <p>Indicates that the view has a software layer. A software layer is backed |
| 2549 | * by a bitmap and causes the view to be rendered using Android's software |
| 2550 | * rendering pipeline, even if hardware acceleration is enabled.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2551 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2552 | * <p>Software layers have various usages:</p> |
| 2553 | * <p>When the application is not using hardware acceleration, a software layer |
| 2554 | * is useful to apply a specific color filter and/or blending mode and/or |
| 2555 | * translucency to a view and all its children.</p> |
| 2556 | * <p>When the application is using hardware acceleration, a software layer |
| 2557 | * is useful to render drawing primitives not supported by the hardware |
| 2558 | * accelerated pipeline. It can also be used to cache a complex view tree |
| 2559 | * into a texture and reduce the complexity of drawing operations. For instance, |
| 2560 | * when animating a complex view tree with a translation, a software layer can |
| 2561 | * be used to render the view tree only once.</p> |
| 2562 | * <p>Software layers should be avoided when the affected view tree updates |
| 2563 | * often. Every update will require to re-render the software layer, which can |
| 2564 | * potentially be slow (particularly when hardware acceleration is turned on |
| 2565 | * since the layer will have to be uploaded into a hardware texture after every |
| 2566 | * update.)</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2567 | * |
| 2568 | * @see #getLayerType() |
| 2569 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2570 | * @see #LAYER_TYPE_NONE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2571 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2572 | */ |
| 2573 | public static final int LAYER_TYPE_SOFTWARE = 1; |
| 2574 | |
| 2575 | /** |
| 2576 | * <p>Indicates that the view has a hardware layer. A hardware layer is backed |
| 2577 | * by a hardware specific texture (generally Frame Buffer Objects or FBO on |
| 2578 | * OpenGL hardware) and causes the view to be rendered using Android's hardware |
| 2579 | * rendering pipeline, but only if hardware acceleration is turned on for the |
| 2580 | * view hierarchy. When hardware acceleration is turned off, hardware layers |
| 2581 | * behave exactly as {@link #LAYER_TYPE_SOFTWARE software layers}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2582 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2583 | * <p>A hardware layer is useful to apply a specific color filter and/or |
| 2584 | * 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] | 2585 | * <p>A hardware layer can be used to cache a complex view tree into a |
| 2586 | * texture and reduce the complexity of drawing operations. For instance, |
| 2587 | * when animating a complex view tree with a translation, a hardware layer can |
| 2588 | * be used to render the view tree only once.</p> |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2589 | * <p>A hardware layer can also be used to increase the rendering quality when |
| 2590 | * rotation transformations are applied on a view. It can also be used to |
| 2591 | * prevent potential clipping issues when applying 3D transforms on a view.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2592 | * |
| 2593 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2594 | * @see #setLayerType(int, android.graphics.Paint) |
| 2595 | * @see #LAYER_TYPE_NONE |
| 2596 | * @see #LAYER_TYPE_SOFTWARE |
| 2597 | */ |
| 2598 | public static final int LAYER_TYPE_HARDWARE = 2; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2599 | |
Romain Guy | 3aaff3a | 2011-01-12 14:18:47 -0800 | [diff] [blame] | 2600 | @ViewDebug.ExportedProperty(category = "drawing", mapping = { |
| 2601 | @ViewDebug.IntToString(from = LAYER_TYPE_NONE, to = "NONE"), |
| 2602 | @ViewDebug.IntToString(from = LAYER_TYPE_SOFTWARE, to = "SOFTWARE"), |
| 2603 | @ViewDebug.IntToString(from = LAYER_TYPE_HARDWARE, to = "HARDWARE") |
| 2604 | }) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2605 | int mLayerType = LAYER_TYPE_NONE; |
| 2606 | Paint mLayerPaint; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 2607 | Rect mLocalDirtyRect; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 2608 | |
| 2609 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 2610 | * Set to true when the view is sending hover accessibility events because it |
| 2611 | * is the innermost hovered view. |
| 2612 | */ |
| 2613 | private boolean mSendingHoverAccessibilityEvents; |
| 2614 | |
| 2615 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 2616 | * Delegate for injecting accessiblity functionality. |
| 2617 | */ |
| 2618 | AccessibilityDelegate mAccessibilityDelegate; |
| 2619 | |
| 2620 | /** |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2621 | * Text direction is inherited thru {@link ViewGroup} |
| 2622 | * @hide |
| 2623 | */ |
| 2624 | public static final int TEXT_DIRECTION_INHERIT = 0; |
| 2625 | |
| 2626 | /** |
| 2627 | * Text direction is using "first strong algorithm". The first strong directional character |
| 2628 | * determines the paragraph direction. If there is no strong directional character, the |
Fabrice Di Meglio | 4c1e00a | 2012-01-05 19:05:55 -0800 | [diff] [blame] | 2629 | * paragraph direction is the view's resolved layout direction. |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2630 | * |
| 2631 | * @hide |
| 2632 | */ |
| 2633 | public static final int TEXT_DIRECTION_FIRST_STRONG = 1; |
| 2634 | |
| 2635 | /** |
| 2636 | * Text direction is using "any-RTL" algorithm. The paragraph direction is RTL if it contains |
| 2637 | * 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] | 2638 | * 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] | 2639 | * |
| 2640 | * @hide |
| 2641 | */ |
| 2642 | public static final int TEXT_DIRECTION_ANY_RTL = 2; |
| 2643 | |
| 2644 | /** |
| 2645 | * Text direction is forced to LTR. |
| 2646 | * |
| 2647 | * @hide |
| 2648 | */ |
Fabrice Di Meglio | e3bf88d | 2011-09-06 11:08:45 -0700 | [diff] [blame] | 2649 | public static final int TEXT_DIRECTION_LTR = 3; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2650 | |
| 2651 | /** |
| 2652 | * Text direction is forced to RTL. |
| 2653 | * |
| 2654 | * @hide |
| 2655 | */ |
Fabrice Di Meglio | e3bf88d | 2011-09-06 11:08:45 -0700 | [diff] [blame] | 2656 | public static final int TEXT_DIRECTION_RTL = 4; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2657 | |
| 2658 | /** |
Fabrice Di Meglio | 4c1e00a | 2012-01-05 19:05:55 -0800 | [diff] [blame] | 2659 | * Text direction is coming from the system Locale. |
| 2660 | * |
| 2661 | * @hide |
| 2662 | */ |
| 2663 | public static final int TEXT_DIRECTION_LOCALE = 5; |
| 2664 | |
| 2665 | /** |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2666 | * Default text direction is inherited |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 2667 | * |
| 2668 | * @hide |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2669 | */ |
| 2670 | protected static int DEFAULT_TEXT_DIRECTION = TEXT_DIRECTION_INHERIT; |
| 2671 | |
| 2672 | /** |
| 2673 | * The text direction that has been defined by {@link #setTextDirection(int)}. |
| 2674 | * |
| 2675 | * {@hide} |
| 2676 | */ |
| 2677 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2678 | @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), |
| 2679 | @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), |
| 2680 | @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), |
| 2681 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), |
Fabrice Di Meglio | 4c1e00a | 2012-01-05 19:05:55 -0800 | [diff] [blame] | 2682 | @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"), |
| 2683 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE") |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2684 | }) |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 2685 | private int mTextDirection = DEFAULT_TEXT_DIRECTION; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2686 | |
| 2687 | /** |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 2688 | * The resolved text direction. This needs resolution if the value is |
Fabrice Di Meglio | 4c1e00a | 2012-01-05 19:05:55 -0800 | [diff] [blame] | 2689 | * TEXT_DIRECTION_INHERIT. The resolution matches mTextDirection if it is |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 2690 | * not TEXT_DIRECTION_INHERIT, otherwise resolution proceeds up the parent |
| 2691 | * chain of the view. |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2692 | * |
| 2693 | * {@hide} |
| 2694 | */ |
| 2695 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 2696 | @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), |
| 2697 | @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), |
| 2698 | @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2699 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), |
Fabrice Di Meglio | 4c1e00a | 2012-01-05 19:05:55 -0800 | [diff] [blame] | 2700 | @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"), |
| 2701 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE") |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2702 | }) |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 2703 | private int mResolvedTextDirection = TEXT_DIRECTION_INHERIT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 2704 | |
| 2705 | /** |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 2706 | * Consistency verifier for debugging purposes. |
| 2707 | * @hide |
| 2708 | */ |
| 2709 | protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = |
| 2710 | InputEventConsistencyVerifier.isInstrumentationEnabled() ? |
| 2711 | new InputEventConsistencyVerifier(this, 0) : null; |
| 2712 | |
| 2713 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2714 | * Simple constructor to use when creating a view from code. |
| 2715 | * |
| 2716 | * @param context The Context the view is running in, through which it can |
| 2717 | * access the current theme, resources, etc. |
| 2718 | */ |
| 2719 | public View(Context context) { |
| 2720 | mContext = context; |
| 2721 | mResources = context != null ? context.getResources() : null; |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 2722 | mViewFlags = SOUND_EFFECTS_ENABLED | HAPTIC_FEEDBACK_ENABLED | LAYOUT_DIRECTION_INHERIT; |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2723 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2724 | setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS); |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 2725 | mUserPaddingStart = -1; |
| 2726 | mUserPaddingEnd = -1; |
| 2727 | mUserPaddingRelative = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2728 | } |
| 2729 | |
| 2730 | /** |
| 2731 | * Constructor that is called when inflating a view from XML. This is called |
| 2732 | * when a view is being constructed from an XML file, supplying attributes |
| 2733 | * that were specified in the XML file. This version uses a default style of |
| 2734 | * 0, so the only attribute values applied are those in the Context's Theme |
| 2735 | * and the given AttributeSet. |
| 2736 | * |
| 2737 | * <p> |
| 2738 | * The method onFinishInflate() will be called after all children have been |
| 2739 | * added. |
| 2740 | * |
| 2741 | * @param context The Context the view is running in, through which it can |
| 2742 | * access the current theme, resources, etc. |
| 2743 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 2744 | * @see #View(Context, AttributeSet, int) |
| 2745 | */ |
| 2746 | public View(Context context, AttributeSet attrs) { |
| 2747 | this(context, attrs, 0); |
| 2748 | } |
| 2749 | |
| 2750 | /** |
| 2751 | * Perform inflation from XML and apply a class-specific base style. This |
| 2752 | * constructor of View allows subclasses to use their own base style when |
| 2753 | * they are inflating. For example, a Button class's constructor would call |
| 2754 | * this version of the super class constructor and supply |
| 2755 | * <code>R.attr.buttonStyle</code> for <var>defStyle</var>; this allows |
| 2756 | * the theme's button style to modify all of the base view attributes (in |
| 2757 | * particular its background) as well as the Button class's attributes. |
| 2758 | * |
| 2759 | * @param context The Context the view is running in, through which it can |
| 2760 | * access the current theme, resources, etc. |
| 2761 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 2762 | * @param defStyle The default style to apply to this view. If 0, no style |
| 2763 | * will be applied (beyond what is included in the theme). This may |
| 2764 | * either be an attribute resource, whose value will be retrieved |
| 2765 | * from the current theme, or an explicit style resource. |
| 2766 | * @see #View(Context, AttributeSet) |
| 2767 | */ |
| 2768 | public View(Context context, AttributeSet attrs, int defStyle) { |
| 2769 | this(context); |
| 2770 | |
| 2771 | TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View, |
| 2772 | defStyle, 0); |
| 2773 | |
| 2774 | Drawable background = null; |
| 2775 | |
| 2776 | int leftPadding = -1; |
| 2777 | int topPadding = -1; |
| 2778 | int rightPadding = -1; |
| 2779 | int bottomPadding = -1; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 2780 | int startPadding = -1; |
| 2781 | int endPadding = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2782 | |
| 2783 | int padding = -1; |
| 2784 | |
| 2785 | int viewFlagValues = 0; |
| 2786 | int viewFlagMasks = 0; |
| 2787 | |
| 2788 | boolean setScrollContainer = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2790 | int x = 0; |
| 2791 | int y = 0; |
| 2792 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 2793 | float tx = 0; |
| 2794 | float ty = 0; |
| 2795 | float rotation = 0; |
| 2796 | float rotationX = 0; |
| 2797 | float rotationY = 0; |
| 2798 | float sx = 1f; |
| 2799 | float sy = 1f; |
| 2800 | boolean transformSet = false; |
| 2801 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2802 | int scrollbarStyle = SCROLLBARS_INSIDE_OVERLAY; |
| 2803 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2804 | int overScrollMode = mOverScrollMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2805 | final int N = a.getIndexCount(); |
| 2806 | for (int i = 0; i < N; i++) { |
| 2807 | int attr = a.getIndex(i); |
| 2808 | switch (attr) { |
| 2809 | case com.android.internal.R.styleable.View_background: |
| 2810 | background = a.getDrawable(attr); |
| 2811 | break; |
| 2812 | case com.android.internal.R.styleable.View_padding: |
| 2813 | padding = a.getDimensionPixelSize(attr, -1); |
| 2814 | break; |
| 2815 | case com.android.internal.R.styleable.View_paddingLeft: |
| 2816 | leftPadding = a.getDimensionPixelSize(attr, -1); |
| 2817 | break; |
| 2818 | case com.android.internal.R.styleable.View_paddingTop: |
| 2819 | topPadding = a.getDimensionPixelSize(attr, -1); |
| 2820 | break; |
| 2821 | case com.android.internal.R.styleable.View_paddingRight: |
| 2822 | rightPadding = a.getDimensionPixelSize(attr, -1); |
| 2823 | break; |
| 2824 | case com.android.internal.R.styleable.View_paddingBottom: |
| 2825 | bottomPadding = a.getDimensionPixelSize(attr, -1); |
| 2826 | break; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 2827 | case com.android.internal.R.styleable.View_paddingStart: |
| 2828 | startPadding = a.getDimensionPixelSize(attr, -1); |
| 2829 | break; |
| 2830 | case com.android.internal.R.styleable.View_paddingEnd: |
| 2831 | endPadding = a.getDimensionPixelSize(attr, -1); |
| 2832 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2833 | case com.android.internal.R.styleable.View_scrollX: |
| 2834 | x = a.getDimensionPixelOffset(attr, 0); |
| 2835 | break; |
| 2836 | case com.android.internal.R.styleable.View_scrollY: |
| 2837 | y = a.getDimensionPixelOffset(attr, 0); |
| 2838 | break; |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 2839 | case com.android.internal.R.styleable.View_alpha: |
| 2840 | setAlpha(a.getFloat(attr, 1f)); |
| 2841 | break; |
| 2842 | case com.android.internal.R.styleable.View_transformPivotX: |
| 2843 | setPivotX(a.getDimensionPixelOffset(attr, 0)); |
| 2844 | break; |
| 2845 | case com.android.internal.R.styleable.View_transformPivotY: |
| 2846 | setPivotY(a.getDimensionPixelOffset(attr, 0)); |
| 2847 | break; |
| 2848 | case com.android.internal.R.styleable.View_translationX: |
| 2849 | tx = a.getDimensionPixelOffset(attr, 0); |
| 2850 | transformSet = true; |
| 2851 | break; |
| 2852 | case com.android.internal.R.styleable.View_translationY: |
| 2853 | ty = a.getDimensionPixelOffset(attr, 0); |
| 2854 | transformSet = true; |
| 2855 | break; |
| 2856 | case com.android.internal.R.styleable.View_rotation: |
| 2857 | rotation = a.getFloat(attr, 0); |
| 2858 | transformSet = true; |
| 2859 | break; |
| 2860 | case com.android.internal.R.styleable.View_rotationX: |
| 2861 | rotationX = a.getFloat(attr, 0); |
| 2862 | transformSet = true; |
| 2863 | break; |
| 2864 | case com.android.internal.R.styleable.View_rotationY: |
| 2865 | rotationY = a.getFloat(attr, 0); |
| 2866 | transformSet = true; |
| 2867 | break; |
| 2868 | case com.android.internal.R.styleable.View_scaleX: |
| 2869 | sx = a.getFloat(attr, 1f); |
| 2870 | transformSet = true; |
| 2871 | break; |
| 2872 | case com.android.internal.R.styleable.View_scaleY: |
| 2873 | sy = a.getFloat(attr, 1f); |
| 2874 | transformSet = true; |
| 2875 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2876 | case com.android.internal.R.styleable.View_id: |
| 2877 | mID = a.getResourceId(attr, NO_ID); |
| 2878 | break; |
| 2879 | case com.android.internal.R.styleable.View_tag: |
| 2880 | mTag = a.getText(attr); |
| 2881 | break; |
| 2882 | case com.android.internal.R.styleable.View_fitsSystemWindows: |
| 2883 | if (a.getBoolean(attr, false)) { |
| 2884 | viewFlagValues |= FITS_SYSTEM_WINDOWS; |
| 2885 | viewFlagMasks |= FITS_SYSTEM_WINDOWS; |
| 2886 | } |
| 2887 | break; |
| 2888 | case com.android.internal.R.styleable.View_focusable: |
| 2889 | if (a.getBoolean(attr, false)) { |
| 2890 | viewFlagValues |= FOCUSABLE; |
| 2891 | viewFlagMasks |= FOCUSABLE_MASK; |
| 2892 | } |
| 2893 | break; |
| 2894 | case com.android.internal.R.styleable.View_focusableInTouchMode: |
| 2895 | if (a.getBoolean(attr, false)) { |
| 2896 | viewFlagValues |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE; |
| 2897 | viewFlagMasks |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE_MASK; |
| 2898 | } |
| 2899 | break; |
| 2900 | case com.android.internal.R.styleable.View_clickable: |
| 2901 | if (a.getBoolean(attr, false)) { |
| 2902 | viewFlagValues |= CLICKABLE; |
| 2903 | viewFlagMasks |= CLICKABLE; |
| 2904 | } |
| 2905 | break; |
| 2906 | case com.android.internal.R.styleable.View_longClickable: |
| 2907 | if (a.getBoolean(attr, false)) { |
| 2908 | viewFlagValues |= LONG_CLICKABLE; |
| 2909 | viewFlagMasks |= LONG_CLICKABLE; |
| 2910 | } |
| 2911 | break; |
| 2912 | case com.android.internal.R.styleable.View_saveEnabled: |
| 2913 | if (!a.getBoolean(attr, true)) { |
| 2914 | viewFlagValues |= SAVE_DISABLED; |
| 2915 | viewFlagMasks |= SAVE_DISABLED_MASK; |
| 2916 | } |
| 2917 | break; |
| 2918 | case com.android.internal.R.styleable.View_duplicateParentState: |
| 2919 | if (a.getBoolean(attr, false)) { |
| 2920 | viewFlagValues |= DUPLICATE_PARENT_STATE; |
| 2921 | viewFlagMasks |= DUPLICATE_PARENT_STATE; |
| 2922 | } |
| 2923 | break; |
| 2924 | case com.android.internal.R.styleable.View_visibility: |
| 2925 | final int visibility = a.getInt(attr, 0); |
| 2926 | if (visibility != 0) { |
| 2927 | viewFlagValues |= VISIBILITY_FLAGS[visibility]; |
| 2928 | viewFlagMasks |= VISIBILITY_MASK; |
| 2929 | } |
| 2930 | break; |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 2931 | case com.android.internal.R.styleable.View_layoutDirection: |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 2932 | // Clear any HORIZONTAL_DIRECTION flag already set |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 2933 | viewFlagValues &= ~LAYOUT_DIRECTION_MASK; |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 2934 | // 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] | 2935 | final int layoutDirection = a.getInt(attr, -1); |
| 2936 | if (layoutDirection != -1) { |
| 2937 | viewFlagValues |= LAYOUT_DIRECTION_FLAGS[layoutDirection]; |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 2938 | } else { |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 2939 | // Set to default (LAYOUT_DIRECTION_INHERIT) |
| 2940 | viewFlagValues |= LAYOUT_DIRECTION_DEFAULT; |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 2941 | } |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 2942 | viewFlagMasks |= LAYOUT_DIRECTION_MASK; |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 2943 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2944 | case com.android.internal.R.styleable.View_drawingCacheQuality: |
| 2945 | final int cacheQuality = a.getInt(attr, 0); |
| 2946 | if (cacheQuality != 0) { |
| 2947 | viewFlagValues |= DRAWING_CACHE_QUALITY_FLAGS[cacheQuality]; |
| 2948 | viewFlagMasks |= DRAWING_CACHE_QUALITY_MASK; |
| 2949 | } |
| 2950 | break; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2951 | case com.android.internal.R.styleable.View_contentDescription: |
| 2952 | mContentDescription = a.getString(attr); |
| 2953 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2954 | case com.android.internal.R.styleable.View_soundEffectsEnabled: |
| 2955 | if (!a.getBoolean(attr, true)) { |
| 2956 | viewFlagValues &= ~SOUND_EFFECTS_ENABLED; |
| 2957 | viewFlagMasks |= SOUND_EFFECTS_ENABLED; |
| 2958 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 2959 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2960 | case com.android.internal.R.styleable.View_hapticFeedbackEnabled: |
| 2961 | if (!a.getBoolean(attr, true)) { |
| 2962 | viewFlagValues &= ~HAPTIC_FEEDBACK_ENABLED; |
| 2963 | viewFlagMasks |= HAPTIC_FEEDBACK_ENABLED; |
| 2964 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 2965 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2966 | case R.styleable.View_scrollbars: |
| 2967 | final int scrollbars = a.getInt(attr, SCROLLBARS_NONE); |
| 2968 | if (scrollbars != SCROLLBARS_NONE) { |
| 2969 | viewFlagValues |= scrollbars; |
| 2970 | viewFlagMasks |= SCROLLBARS_MASK; |
| 2971 | initializeScrollbars(a); |
| 2972 | } |
| 2973 | break; |
Romain Guy | 2a9fa89 | 2011-09-28 16:50:02 -0700 | [diff] [blame] | 2974 | //noinspection deprecation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2975 | case R.styleable.View_fadingEdge: |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 2976 | if (context.getApplicationInfo().targetSdkVersion >= ICE_CREAM_SANDWICH) { |
| 2977 | // Ignore the attribute starting with ICS |
| 2978 | break; |
| 2979 | } |
| 2980 | // With builds < ICS, fall through and apply fading edges |
| 2981 | case R.styleable.View_requiresFadingEdge: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2982 | final int fadingEdge = a.getInt(attr, FADING_EDGE_NONE); |
| 2983 | if (fadingEdge != FADING_EDGE_NONE) { |
| 2984 | viewFlagValues |= fadingEdge; |
| 2985 | viewFlagMasks |= FADING_EDGE_MASK; |
| 2986 | initializeFadingEdge(a); |
| 2987 | } |
| 2988 | break; |
| 2989 | case R.styleable.View_scrollbarStyle: |
| 2990 | scrollbarStyle = a.getInt(attr, SCROLLBARS_INSIDE_OVERLAY); |
| 2991 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 2992 | viewFlagValues |= scrollbarStyle & SCROLLBARS_STYLE_MASK; |
| 2993 | viewFlagMasks |= SCROLLBARS_STYLE_MASK; |
| 2994 | } |
| 2995 | break; |
| 2996 | case R.styleable.View_isScrollContainer: |
| 2997 | setScrollContainer = true; |
| 2998 | if (a.getBoolean(attr, false)) { |
| 2999 | setScrollContainer(true); |
| 3000 | } |
| 3001 | break; |
| 3002 | case com.android.internal.R.styleable.View_keepScreenOn: |
| 3003 | if (a.getBoolean(attr, false)) { |
| 3004 | viewFlagValues |= KEEP_SCREEN_ON; |
| 3005 | viewFlagMasks |= KEEP_SCREEN_ON; |
| 3006 | } |
| 3007 | break; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 3008 | case R.styleable.View_filterTouchesWhenObscured: |
| 3009 | if (a.getBoolean(attr, false)) { |
| 3010 | viewFlagValues |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3011 | viewFlagMasks |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3012 | } |
| 3013 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3014 | case R.styleable.View_nextFocusLeft: |
| 3015 | mNextFocusLeftId = a.getResourceId(attr, View.NO_ID); |
| 3016 | break; |
| 3017 | case R.styleable.View_nextFocusRight: |
| 3018 | mNextFocusRightId = a.getResourceId(attr, View.NO_ID); |
| 3019 | break; |
| 3020 | case R.styleable.View_nextFocusUp: |
| 3021 | mNextFocusUpId = a.getResourceId(attr, View.NO_ID); |
| 3022 | break; |
| 3023 | case R.styleable.View_nextFocusDown: |
| 3024 | mNextFocusDownId = a.getResourceId(attr, View.NO_ID); |
| 3025 | break; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 3026 | case R.styleable.View_nextFocusForward: |
| 3027 | mNextFocusForwardId = a.getResourceId(attr, View.NO_ID); |
| 3028 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3029 | case R.styleable.View_minWidth: |
| 3030 | mMinWidth = a.getDimensionPixelSize(attr, 0); |
| 3031 | break; |
| 3032 | case R.styleable.View_minHeight: |
| 3033 | mMinHeight = a.getDimensionPixelSize(attr, 0); |
| 3034 | break; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3035 | case R.styleable.View_onClick: |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3036 | if (context.isRestricted()) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3037 | throw new IllegalStateException("The android:onClick attribute cannot " |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3038 | + "be used within a restricted context"); |
| 3039 | } |
| 3040 | |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3041 | final String handlerName = a.getString(attr); |
| 3042 | if (handlerName != null) { |
| 3043 | setOnClickListener(new OnClickListener() { |
| 3044 | private Method mHandler; |
| 3045 | |
| 3046 | public void onClick(View v) { |
| 3047 | if (mHandler == null) { |
| 3048 | try { |
| 3049 | mHandler = getContext().getClass().getMethod(handlerName, |
| 3050 | View.class); |
| 3051 | } catch (NoSuchMethodException e) { |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3052 | int id = getId(); |
| 3053 | String idText = id == NO_ID ? "" : " with id '" |
| 3054 | + getContext().getResources().getResourceEntryName( |
| 3055 | id) + "'"; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3056 | throw new IllegalStateException("Could not find a method " + |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3057 | handlerName + "(View) in the activity " |
| 3058 | + getContext().getClass() + " for onClick handler" |
| 3059 | + " on view " + View.this.getClass() + idText, e); |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3060 | } |
| 3061 | } |
| 3062 | |
| 3063 | try { |
| 3064 | mHandler.invoke(getContext(), View.this); |
| 3065 | } catch (IllegalAccessException e) { |
| 3066 | throw new IllegalStateException("Could not execute non " |
| 3067 | + "public method of the activity", e); |
| 3068 | } catch (InvocationTargetException e) { |
| 3069 | throw new IllegalStateException("Could not execute " |
| 3070 | + "method of the activity", e); |
| 3071 | } |
| 3072 | } |
| 3073 | }); |
| 3074 | } |
| 3075 | break; |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3076 | case R.styleable.View_overScrollMode: |
| 3077 | overScrollMode = a.getInt(attr, OVER_SCROLL_IF_CONTENT_SCROLLS); |
| 3078 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3079 | case R.styleable.View_verticalScrollbarPosition: |
| 3080 | mVerticalScrollbarPosition = a.getInt(attr, SCROLLBAR_POSITION_DEFAULT); |
| 3081 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3082 | case R.styleable.View_layerType: |
| 3083 | setLayerType(a.getInt(attr, LAYER_TYPE_NONE), null); |
| 3084 | break; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3085 | case R.styleable.View_textDirection: |
| 3086 | mTextDirection = a.getInt(attr, DEFAULT_TEXT_DIRECTION); |
| 3087 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3088 | } |
| 3089 | } |
| 3090 | |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 3091 | a.recycle(); |
| 3092 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3093 | setOverScrollMode(overScrollMode); |
| 3094 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3095 | if (background != null) { |
| 3096 | setBackgroundDrawable(background); |
| 3097 | } |
| 3098 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3099 | mUserPaddingRelative = (startPadding >= 0 || endPadding >= 0); |
| 3100 | |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 3101 | // Cache user padding as we cannot fully resolve padding here (we dont have yet the resolved |
| 3102 | // layout direction). Those cached values will be used later during padding resolution. |
| 3103 | mUserPaddingStart = startPadding; |
| 3104 | mUserPaddingEnd = endPadding; |
| 3105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3106 | if (padding >= 0) { |
| 3107 | leftPadding = padding; |
| 3108 | topPadding = padding; |
| 3109 | rightPadding = padding; |
| 3110 | bottomPadding = padding; |
| 3111 | } |
| 3112 | |
| 3113 | // If the user specified the padding (either with android:padding or |
| 3114 | // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise |
| 3115 | // use the default padding or the padding from the background drawable |
| 3116 | // (stored at this point in mPadding*) |
| 3117 | setPadding(leftPadding >= 0 ? leftPadding : mPaddingLeft, |
| 3118 | topPadding >= 0 ? topPadding : mPaddingTop, |
| 3119 | rightPadding >= 0 ? rightPadding : mPaddingRight, |
| 3120 | bottomPadding >= 0 ? bottomPadding : mPaddingBottom); |
| 3121 | |
| 3122 | if (viewFlagMasks != 0) { |
| 3123 | setFlags(viewFlagValues, viewFlagMasks); |
| 3124 | } |
| 3125 | |
| 3126 | // Needs to be called after mViewFlags is set |
| 3127 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3128 | recomputePadding(); |
| 3129 | } |
| 3130 | |
| 3131 | if (x != 0 || y != 0) { |
| 3132 | scrollTo(x, y); |
| 3133 | } |
| 3134 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3135 | if (transformSet) { |
| 3136 | setTranslationX(tx); |
| 3137 | setTranslationY(ty); |
| 3138 | setRotation(rotation); |
| 3139 | setRotationX(rotationX); |
| 3140 | setRotationY(rotationY); |
| 3141 | setScaleX(sx); |
| 3142 | setScaleY(sy); |
| 3143 | } |
| 3144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3145 | if (!setScrollContainer && (viewFlagValues&SCROLLBARS_VERTICAL) != 0) { |
| 3146 | setScrollContainer(true); |
| 3147 | } |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 3148 | |
| 3149 | computeOpaqueFlags(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | /** |
| 3153 | * Non-public constructor for use in testing |
| 3154 | */ |
| 3155 | View() { |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 3156 | mResources = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3157 | } |
| 3158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3159 | /** |
| 3160 | * <p> |
| 3161 | * Initializes the fading edges from a given set of styled attributes. This |
| 3162 | * method should be called by subclasses that need fading edges and when an |
| 3163 | * instance of these subclasses is created programmatically rather than |
| 3164 | * being inflated from XML. This method is automatically called when the XML |
| 3165 | * is inflated. |
| 3166 | * </p> |
| 3167 | * |
| 3168 | * @param a the styled attributes set to initialize the fading edges from |
| 3169 | */ |
| 3170 | protected void initializeFadingEdge(TypedArray a) { |
| 3171 | initScrollCache(); |
| 3172 | |
| 3173 | mScrollCache.fadingEdgeLength = a.getDimensionPixelSize( |
| 3174 | R.styleable.View_fadingEdgeLength, |
| 3175 | ViewConfiguration.get(mContext).getScaledFadingEdgeLength()); |
| 3176 | } |
| 3177 | |
| 3178 | /** |
| 3179 | * Returns the size of the vertical faded edges used to indicate that more |
| 3180 | * content in this view is visible. |
| 3181 | * |
| 3182 | * @return The size in pixels of the vertical faded edge or 0 if vertical |
| 3183 | * faded edges are not enabled for this view. |
| 3184 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3185 | */ |
| 3186 | public int getVerticalFadingEdgeLength() { |
| 3187 | if (isVerticalFadingEdgeEnabled()) { |
| 3188 | ScrollabilityCache cache = mScrollCache; |
| 3189 | if (cache != null) { |
| 3190 | return cache.fadingEdgeLength; |
| 3191 | } |
| 3192 | } |
| 3193 | return 0; |
| 3194 | } |
| 3195 | |
| 3196 | /** |
| 3197 | * Set the size of the faded edge used to indicate that more content in this |
| 3198 | * 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] | 3199 | * {@link #setVerticalFadingEdgeEnabled(boolean)} or |
| 3200 | * {@link #setHorizontalFadingEdgeEnabled(boolean)} to enable the fading edge |
| 3201 | * for the vertical or horizontal fading edges. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3202 | * |
| 3203 | * @param length The size in pixels of the faded edge used to indicate that more |
| 3204 | * content in this view is visible. |
| 3205 | */ |
| 3206 | public void setFadingEdgeLength(int length) { |
| 3207 | initScrollCache(); |
| 3208 | mScrollCache.fadingEdgeLength = length; |
| 3209 | } |
| 3210 | |
| 3211 | /** |
| 3212 | * Returns the size of the horizontal faded edges used to indicate that more |
| 3213 | * content in this view is visible. |
| 3214 | * |
| 3215 | * @return The size in pixels of the horizontal faded edge or 0 if horizontal |
| 3216 | * faded edges are not enabled for this view. |
| 3217 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3218 | */ |
| 3219 | public int getHorizontalFadingEdgeLength() { |
| 3220 | if (isHorizontalFadingEdgeEnabled()) { |
| 3221 | ScrollabilityCache cache = mScrollCache; |
| 3222 | if (cache != null) { |
| 3223 | return cache.fadingEdgeLength; |
| 3224 | } |
| 3225 | } |
| 3226 | return 0; |
| 3227 | } |
| 3228 | |
| 3229 | /** |
| 3230 | * Returns the width of the vertical scrollbar. |
| 3231 | * |
| 3232 | * @return The width in pixels of the vertical scrollbar or 0 if there |
| 3233 | * is no vertical scrollbar. |
| 3234 | */ |
| 3235 | public int getVerticalScrollbarWidth() { |
| 3236 | ScrollabilityCache cache = mScrollCache; |
| 3237 | if (cache != null) { |
| 3238 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3239 | if (scrollBar != null) { |
| 3240 | int size = scrollBar.getSize(true); |
| 3241 | if (size <= 0) { |
| 3242 | size = cache.scrollBarSize; |
| 3243 | } |
| 3244 | return size; |
| 3245 | } |
| 3246 | return 0; |
| 3247 | } |
| 3248 | return 0; |
| 3249 | } |
| 3250 | |
| 3251 | /** |
| 3252 | * Returns the height of the horizontal scrollbar. |
| 3253 | * |
| 3254 | * @return The height in pixels of the horizontal scrollbar or 0 if |
| 3255 | * there is no horizontal scrollbar. |
| 3256 | */ |
| 3257 | protected int getHorizontalScrollbarHeight() { |
| 3258 | ScrollabilityCache cache = mScrollCache; |
| 3259 | if (cache != null) { |
| 3260 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3261 | if (scrollBar != null) { |
| 3262 | int size = scrollBar.getSize(false); |
| 3263 | if (size <= 0) { |
| 3264 | size = cache.scrollBarSize; |
| 3265 | } |
| 3266 | return size; |
| 3267 | } |
| 3268 | return 0; |
| 3269 | } |
| 3270 | return 0; |
| 3271 | } |
| 3272 | |
| 3273 | /** |
| 3274 | * <p> |
| 3275 | * Initializes the scrollbars from a given set of styled attributes. This |
| 3276 | * method should be called by subclasses that need scrollbars and when an |
| 3277 | * instance of these subclasses is created programmatically rather than |
| 3278 | * being inflated from XML. This method is automatically called when the XML |
| 3279 | * is inflated. |
| 3280 | * </p> |
| 3281 | * |
| 3282 | * @param a the styled attributes set to initialize the scrollbars from |
| 3283 | */ |
| 3284 | protected void initializeScrollbars(TypedArray a) { |
| 3285 | initScrollCache(); |
| 3286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3287 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3288 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3289 | if (scrollabilityCache.scrollBar == null) { |
| 3290 | scrollabilityCache.scrollBar = new ScrollBarDrawable(); |
| 3291 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3292 | |
Romain Guy | 8bda248 | 2010-03-02 11:42:11 -0800 | [diff] [blame] | 3293 | 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] | 3294 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3295 | if (!fadeScrollbars) { |
| 3296 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 3297 | } |
| 3298 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3299 | |
| 3300 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3301 | scrollabilityCache.scrollBarFadeDuration = a.getInt( |
| 3302 | R.styleable.View_scrollbarFadeDuration, ViewConfiguration |
| 3303 | .getScrollBarFadeDuration()); |
| 3304 | scrollabilityCache.scrollBarDefaultDelayBeforeFade = a.getInt( |
| 3305 | R.styleable.View_scrollbarDefaultDelayBeforeFade, |
| 3306 | ViewConfiguration.getScrollDefaultDelay()); |
| 3307 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3308 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3309 | scrollabilityCache.scrollBarSize = a.getDimensionPixelSize( |
| 3310 | com.android.internal.R.styleable.View_scrollbarSize, |
| 3311 | ViewConfiguration.get(mContext).getScaledScrollBarSize()); |
| 3312 | |
| 3313 | Drawable track = a.getDrawable(R.styleable.View_scrollbarTrackHorizontal); |
| 3314 | scrollabilityCache.scrollBar.setHorizontalTrackDrawable(track); |
| 3315 | |
| 3316 | Drawable thumb = a.getDrawable(R.styleable.View_scrollbarThumbHorizontal); |
| 3317 | if (thumb != null) { |
| 3318 | scrollabilityCache.scrollBar.setHorizontalThumbDrawable(thumb); |
| 3319 | } |
| 3320 | |
| 3321 | boolean alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawHorizontalTrack, |
| 3322 | false); |
| 3323 | if (alwaysDraw) { |
| 3324 | scrollabilityCache.scrollBar.setAlwaysDrawHorizontalTrack(true); |
| 3325 | } |
| 3326 | |
| 3327 | track = a.getDrawable(R.styleable.View_scrollbarTrackVertical); |
| 3328 | scrollabilityCache.scrollBar.setVerticalTrackDrawable(track); |
| 3329 | |
| 3330 | thumb = a.getDrawable(R.styleable.View_scrollbarThumbVertical); |
| 3331 | if (thumb != null) { |
| 3332 | scrollabilityCache.scrollBar.setVerticalThumbDrawable(thumb); |
| 3333 | } |
| 3334 | |
| 3335 | alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawVerticalTrack, |
| 3336 | false); |
| 3337 | if (alwaysDraw) { |
| 3338 | scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true); |
| 3339 | } |
| 3340 | |
| 3341 | // Re-apply user/background padding so that scrollbar(s) get added |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3342 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | } |
| 3344 | |
| 3345 | /** |
| 3346 | * <p> |
| 3347 | * Initalizes the scrollability cache if necessary. |
| 3348 | * </p> |
| 3349 | */ |
| 3350 | private void initScrollCache() { |
| 3351 | if (mScrollCache == null) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3352 | mScrollCache = new ScrollabilityCache(ViewConfiguration.get(mContext), this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3353 | } |
| 3354 | } |
| 3355 | |
| 3356 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3357 | * Set the position of the vertical scroll bar. Should be one of |
| 3358 | * {@link #SCROLLBAR_POSITION_DEFAULT}, {@link #SCROLLBAR_POSITION_LEFT} or |
| 3359 | * {@link #SCROLLBAR_POSITION_RIGHT}. |
| 3360 | * |
| 3361 | * @param position Where the vertical scroll bar should be positioned. |
| 3362 | */ |
| 3363 | public void setVerticalScrollbarPosition(int position) { |
| 3364 | if (mVerticalScrollbarPosition != position) { |
| 3365 | mVerticalScrollbarPosition = position; |
| 3366 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3367 | resolvePadding(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3368 | } |
| 3369 | } |
| 3370 | |
| 3371 | /** |
| 3372 | * @return The position where the vertical scroll bar will show, if applicable. |
| 3373 | * @see #setVerticalScrollbarPosition(int) |
| 3374 | */ |
| 3375 | public int getVerticalScrollbarPosition() { |
| 3376 | return mVerticalScrollbarPosition; |
| 3377 | } |
| 3378 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3379 | ListenerInfo getListenerInfo() { |
| 3380 | if (mListenerInfo != null) { |
| 3381 | return mListenerInfo; |
| 3382 | } |
| 3383 | mListenerInfo = new ListenerInfo(); |
| 3384 | return mListenerInfo; |
| 3385 | } |
| 3386 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3387 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3388 | * Register a callback to be invoked when focus of this view changed. |
| 3389 | * |
| 3390 | * @param l The callback that will run. |
| 3391 | */ |
| 3392 | public void setOnFocusChangeListener(OnFocusChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3393 | getListenerInfo().mOnFocusChangeListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3394 | } |
| 3395 | |
| 3396 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3397 | * Add a listener that will be called when the bounds of the view change due to |
| 3398 | * layout processing. |
| 3399 | * |
| 3400 | * @param listener The listener that will be called when layout bounds change. |
| 3401 | */ |
| 3402 | public void addOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3403 | ListenerInfo li = getListenerInfo(); |
| 3404 | if (li.mOnLayoutChangeListeners == null) { |
| 3405 | li.mOnLayoutChangeListeners = new ArrayList<OnLayoutChangeListener>(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3406 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3407 | if (!li.mOnLayoutChangeListeners.contains(listener)) { |
| 3408 | li.mOnLayoutChangeListeners.add(listener); |
Chet Haase | 1a76dcd | 2011-10-06 11:16:40 -0700 | [diff] [blame] | 3409 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | /** |
| 3413 | * Remove a listener for layout changes. |
| 3414 | * |
| 3415 | * @param listener The listener for layout bounds change. |
| 3416 | */ |
| 3417 | public void removeOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3418 | ListenerInfo li = mListenerInfo; |
| 3419 | if (li == null || li.mOnLayoutChangeListeners == null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3420 | return; |
| 3421 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3422 | li.mOnLayoutChangeListeners.remove(listener); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3423 | } |
| 3424 | |
| 3425 | /** |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3426 | * Add a listener for attach state changes. |
| 3427 | * |
| 3428 | * This listener will be called whenever this view is attached or detached |
| 3429 | * from a window. Remove the listener using |
| 3430 | * {@link #removeOnAttachStateChangeListener(OnAttachStateChangeListener)}. |
| 3431 | * |
| 3432 | * @param listener Listener to attach |
| 3433 | * @see #removeOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 3434 | */ |
| 3435 | public void addOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3436 | ListenerInfo li = getListenerInfo(); |
| 3437 | if (li.mOnAttachStateChangeListeners == null) { |
| 3438 | li.mOnAttachStateChangeListeners |
| 3439 | = new CopyOnWriteArrayList<OnAttachStateChangeListener>(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3440 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3441 | li.mOnAttachStateChangeListeners.add(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3442 | } |
| 3443 | |
| 3444 | /** |
| 3445 | * Remove a listener for attach state changes. The listener will receive no further |
| 3446 | * notification of window attach/detach events. |
| 3447 | * |
| 3448 | * @param listener Listener to remove |
| 3449 | * @see #addOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 3450 | */ |
| 3451 | public void removeOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3452 | ListenerInfo li = mListenerInfo; |
| 3453 | if (li == null || li.mOnAttachStateChangeListeners == null) { |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3454 | return; |
| 3455 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3456 | li.mOnAttachStateChangeListeners.remove(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3460 | * Returns the focus-change callback registered for this view. |
| 3461 | * |
| 3462 | * @return The callback, or null if one is not registered. |
| 3463 | */ |
| 3464 | public OnFocusChangeListener getOnFocusChangeListener() { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3465 | ListenerInfo li = mListenerInfo; |
| 3466 | return li != null ? li.mOnFocusChangeListener : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | /** |
| 3470 | * Register a callback to be invoked when this view is clicked. If this view is not |
| 3471 | * clickable, it becomes clickable. |
| 3472 | * |
| 3473 | * @param l The callback that will run |
| 3474 | * |
| 3475 | * @see #setClickable(boolean) |
| 3476 | */ |
| 3477 | public void setOnClickListener(OnClickListener l) { |
| 3478 | if (!isClickable()) { |
| 3479 | setClickable(true); |
| 3480 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3481 | getListenerInfo().mOnClickListener = l; |
| 3482 | } |
| 3483 | |
| 3484 | /** |
| 3485 | * Return whether this view has an attached OnClickListener. Returns |
| 3486 | * true if there is a listener, false if there is none. |
| 3487 | */ |
| 3488 | public boolean hasOnClickListeners() { |
| 3489 | ListenerInfo li = mListenerInfo; |
| 3490 | return (li != null && li.mOnClickListener != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3491 | } |
| 3492 | |
| 3493 | /** |
| 3494 | * Register a callback to be invoked when this view is clicked and held. If this view is not |
| 3495 | * long clickable, it becomes long clickable. |
| 3496 | * |
| 3497 | * @param l The callback that will run |
| 3498 | * |
| 3499 | * @see #setLongClickable(boolean) |
| 3500 | */ |
| 3501 | public void setOnLongClickListener(OnLongClickListener l) { |
| 3502 | if (!isLongClickable()) { |
| 3503 | setLongClickable(true); |
| 3504 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3505 | getListenerInfo().mOnLongClickListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | /** |
| 3509 | * Register a callback to be invoked when the context menu for this view is |
| 3510 | * being built. If this view is not long clickable, it becomes long clickable. |
| 3511 | * |
| 3512 | * @param l The callback that will run |
| 3513 | * |
| 3514 | */ |
| 3515 | public void setOnCreateContextMenuListener(OnCreateContextMenuListener l) { |
| 3516 | if (!isLongClickable()) { |
| 3517 | setLongClickable(true); |
| 3518 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3519 | getListenerInfo().mOnCreateContextMenuListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3523 | * Call this view's OnClickListener, if it is defined. Performs all normal |
| 3524 | * actions associated with clicking: reporting accessibility event, playing |
| 3525 | * a sound, etc. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3526 | * |
| 3527 | * @return True there was an assigned OnClickListener that was called, false |
| 3528 | * otherwise is returned. |
| 3529 | */ |
| 3530 | public boolean performClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3531 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); |
| 3532 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3533 | ListenerInfo li = mListenerInfo; |
| 3534 | if (li != null && li.mOnClickListener != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3535 | playSoundEffect(SoundEffectConstants.CLICK); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3536 | li.mOnClickListener.onClick(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3537 | return true; |
| 3538 | } |
| 3539 | |
| 3540 | return false; |
| 3541 | } |
| 3542 | |
| 3543 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3544 | * Directly call any attached OnClickListener. Unlike {@link #performClick()}, |
| 3545 | * this only calls the listener, and does not do any associated clicking |
| 3546 | * actions like reporting an accessibility event. |
| 3547 | * |
| 3548 | * @return True there was an assigned OnClickListener that was called, false |
| 3549 | * otherwise is returned. |
| 3550 | */ |
| 3551 | public boolean callOnClick() { |
| 3552 | ListenerInfo li = mListenerInfo; |
| 3553 | if (li != null && li.mOnClickListener != null) { |
| 3554 | li.mOnClickListener.onClick(this); |
| 3555 | return true; |
| 3556 | } |
| 3557 | return false; |
| 3558 | } |
| 3559 | |
| 3560 | /** |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 3561 | * Call this view's OnLongClickListener, if it is defined. Invokes the context menu if the |
| 3562 | * OnLongClickListener did not consume the event. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3563 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 3564 | * @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] | 3565 | */ |
| 3566 | public boolean performLongClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3567 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); |
| 3568 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3569 | boolean handled = false; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3570 | ListenerInfo li = mListenerInfo; |
| 3571 | if (li != null && li.mOnLongClickListener != null) { |
| 3572 | handled = li.mOnLongClickListener.onLongClick(View.this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3573 | } |
| 3574 | if (!handled) { |
| 3575 | handled = showContextMenu(); |
| 3576 | } |
| 3577 | if (handled) { |
| 3578 | performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); |
| 3579 | } |
| 3580 | return handled; |
| 3581 | } |
| 3582 | |
| 3583 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3584 | * Performs button-related actions during a touch down event. |
| 3585 | * |
| 3586 | * @param event The event. |
| 3587 | * @return True if the down was consumed. |
| 3588 | * |
| 3589 | * @hide |
| 3590 | */ |
| 3591 | protected boolean performButtonActionOnTouchDown(MotionEvent event) { |
| 3592 | if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) { |
| 3593 | if (showContextMenu(event.getX(), event.getY(), event.getMetaState())) { |
| 3594 | return true; |
| 3595 | } |
| 3596 | } |
| 3597 | return false; |
| 3598 | } |
| 3599 | |
| 3600 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3601 | * Bring up the context menu for this view. |
| 3602 | * |
| 3603 | * @return Whether a context menu was displayed. |
| 3604 | */ |
| 3605 | public boolean showContextMenu() { |
| 3606 | return getParent().showContextMenuForChild(this); |
| 3607 | } |
| 3608 | |
| 3609 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3610 | * Bring up the context menu for this view, referring to the item under the specified point. |
| 3611 | * |
| 3612 | * @param x The referenced x coordinate. |
| 3613 | * @param y The referenced y coordinate. |
| 3614 | * @param metaState The keyboard modifiers that were pressed. |
| 3615 | * @return Whether a context menu was displayed. |
| 3616 | * |
| 3617 | * @hide |
| 3618 | */ |
| 3619 | public boolean showContextMenu(float x, float y, int metaState) { |
| 3620 | return showContextMenu(); |
| 3621 | } |
| 3622 | |
| 3623 | /** |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 3624 | * Start an action mode. |
| 3625 | * |
| 3626 | * @param callback Callback that will control the lifecycle of the action mode |
| 3627 | * @return The new action mode if it is started, null otherwise |
| 3628 | * |
| 3629 | * @see ActionMode |
| 3630 | */ |
| 3631 | public ActionMode startActionMode(ActionMode.Callback callback) { |
| 3632 | return getParent().startActionModeForChild(this, callback); |
| 3633 | } |
| 3634 | |
| 3635 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3636 | * Register a callback to be invoked when a key is pressed in this view. |
| 3637 | * @param l the key listener to attach to this view |
| 3638 | */ |
| 3639 | public void setOnKeyListener(OnKeyListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3640 | getListenerInfo().mOnKeyListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | /** |
| 3644 | * Register a callback to be invoked when a touch event is sent to this view. |
| 3645 | * @param l the touch listener to attach to this view |
| 3646 | */ |
| 3647 | public void setOnTouchListener(OnTouchListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3648 | getListenerInfo().mOnTouchListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3649 | } |
| 3650 | |
| 3651 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3652 | * Register a callback to be invoked when a generic motion event is sent to this view. |
| 3653 | * @param l the generic motion listener to attach to this view |
| 3654 | */ |
| 3655 | public void setOnGenericMotionListener(OnGenericMotionListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3656 | getListenerInfo().mOnGenericMotionListener = l; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | /** |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 3660 | * Register a callback to be invoked when a hover event is sent to this view. |
| 3661 | * @param l the hover listener to attach to this view |
| 3662 | */ |
| 3663 | public void setOnHoverListener(OnHoverListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3664 | getListenerInfo().mOnHoverListener = l; |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3668 | * Register a drag event listener callback object for this View. The parameter is |
| 3669 | * an implementation of {@link android.view.View.OnDragListener}. To send a drag event to a |
| 3670 | * View, the system calls the |
| 3671 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent)} method. |
| 3672 | * @param l An implementation of {@link android.view.View.OnDragListener}. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 3673 | */ |
| 3674 | public void setOnDragListener(OnDragListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3675 | getListenerInfo().mOnDragListener = l; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 3676 | } |
| 3677 | |
| 3678 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 3679 | * Give this view focus. This will cause |
| 3680 | * {@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] | 3681 | * |
| 3682 | * Note: this does not check whether this {@link View} should get focus, it just |
| 3683 | * gives it focus no matter what. It should only be called internally by framework |
| 3684 | * code that knows what it is doing, namely {@link #requestFocus(int, Rect)}. |
| 3685 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 3686 | * @param direction values are {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN}, |
| 3687 | * {@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] | 3688 | * focus moved when requestFocus() is called. It may not always |
| 3689 | * apply, in which case use the default View.FOCUS_DOWN. |
| 3690 | * @param previouslyFocusedRect The rectangle of the view that had focus |
| 3691 | * prior in this View's coordinate system. |
| 3692 | */ |
| 3693 | void handleFocusGainInternal(int direction, Rect previouslyFocusedRect) { |
| 3694 | if (DBG) { |
| 3695 | System.out.println(this + " requestFocus()"); |
| 3696 | } |
| 3697 | |
| 3698 | if ((mPrivateFlags & FOCUSED) == 0) { |
| 3699 | mPrivateFlags |= FOCUSED; |
| 3700 | |
| 3701 | if (mParent != null) { |
| 3702 | mParent.requestChildFocus(this, this); |
| 3703 | } |
| 3704 | |
| 3705 | onFocusChanged(true, direction, previouslyFocusedRect); |
| 3706 | refreshDrawableState(); |
| 3707 | } |
| 3708 | } |
| 3709 | |
| 3710 | /** |
| 3711 | * Request that a rectangle of this view be visible on the screen, |
| 3712 | * scrolling if necessary just enough. |
| 3713 | * |
| 3714 | * <p>A View should call this if it maintains some notion of which part |
| 3715 | * of its content is interesting. For example, a text editing view |
| 3716 | * should call this when its cursor moves. |
| 3717 | * |
| 3718 | * @param rectangle The rectangle. |
| 3719 | * @return Whether any parent scrolled. |
| 3720 | */ |
| 3721 | public boolean requestRectangleOnScreen(Rect rectangle) { |
| 3722 | return requestRectangleOnScreen(rectangle, false); |
| 3723 | } |
| 3724 | |
| 3725 | /** |
| 3726 | * Request that a rectangle of this view be visible on the screen, |
| 3727 | * scrolling if necessary just enough. |
| 3728 | * |
| 3729 | * <p>A View should call this if it maintains some notion of which part |
| 3730 | * of its content is interesting. For example, a text editing view |
| 3731 | * should call this when its cursor moves. |
| 3732 | * |
| 3733 | * <p>When <code>immediate</code> is set to true, scrolling will not be |
| 3734 | * animated. |
| 3735 | * |
| 3736 | * @param rectangle The rectangle. |
| 3737 | * @param immediate True to forbid animated scrolling, false otherwise |
| 3738 | * @return Whether any parent scrolled. |
| 3739 | */ |
| 3740 | public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) { |
| 3741 | View child = this; |
| 3742 | ViewParent parent = mParent; |
| 3743 | boolean scrolled = false; |
| 3744 | while (parent != null) { |
| 3745 | scrolled |= parent.requestChildRectangleOnScreen(child, |
| 3746 | rectangle, immediate); |
| 3747 | |
| 3748 | // offset rect so next call has the rectangle in the |
| 3749 | // coordinate system of its direct child. |
| 3750 | rectangle.offset(child.getLeft(), child.getTop()); |
| 3751 | rectangle.offset(-child.getScrollX(), -child.getScrollY()); |
| 3752 | |
| 3753 | if (!(parent instanceof View)) { |
| 3754 | break; |
| 3755 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3756 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3757 | child = (View) parent; |
| 3758 | parent = child.getParent(); |
| 3759 | } |
| 3760 | return scrolled; |
| 3761 | } |
| 3762 | |
| 3763 | /** |
| 3764 | * Called when this view wants to give up focus. This will cause |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 3765 | * {@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] | 3766 | */ |
| 3767 | public void clearFocus() { |
| 3768 | if (DBG) { |
| 3769 | System.out.println(this + " clearFocus()"); |
| 3770 | } |
| 3771 | |
| 3772 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 3773 | mPrivateFlags &= ~FOCUSED; |
| 3774 | |
| 3775 | if (mParent != null) { |
| 3776 | mParent.clearChildFocus(this); |
| 3777 | } |
| 3778 | |
| 3779 | onFocusChanged(false, 0, null); |
| 3780 | refreshDrawableState(); |
| 3781 | } |
| 3782 | } |
| 3783 | |
| 3784 | /** |
| 3785 | * Called to clear the focus of a view that is about to be removed. |
| 3786 | * Doesn't call clearChildFocus, which prevents this view from taking |
| 3787 | * focus again before it has been removed from the parent |
| 3788 | */ |
| 3789 | void clearFocusForRemoval() { |
| 3790 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 3791 | mPrivateFlags &= ~FOCUSED; |
| 3792 | |
| 3793 | onFocusChanged(false, 0, null); |
| 3794 | refreshDrawableState(); |
| 3795 | } |
| 3796 | } |
| 3797 | |
| 3798 | /** |
| 3799 | * Called internally by the view system when a new view is getting focus. |
| 3800 | * This is what clears the old focus. |
| 3801 | */ |
| 3802 | void unFocus() { |
| 3803 | if (DBG) { |
| 3804 | System.out.println(this + " unFocus()"); |
| 3805 | } |
| 3806 | |
| 3807 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 3808 | mPrivateFlags &= ~FOCUSED; |
| 3809 | |
| 3810 | onFocusChanged(false, 0, null); |
| 3811 | refreshDrawableState(); |
| 3812 | } |
| 3813 | } |
| 3814 | |
| 3815 | /** |
| 3816 | * Returns true if this view has focus iteself, or is the ancestor of the |
| 3817 | * view that has focus. |
| 3818 | * |
| 3819 | * @return True if this view has or contains focus, false otherwise. |
| 3820 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 3821 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3822 | public boolean hasFocus() { |
| 3823 | return (mPrivateFlags & FOCUSED) != 0; |
| 3824 | } |
| 3825 | |
| 3826 | /** |
| 3827 | * Returns true if this view is focusable or if it contains a reachable View |
| 3828 | * for which {@link #hasFocusable()} returns true. A "reachable hasFocusable()" |
| 3829 | * is a View whose parents do not block descendants focus. |
| 3830 | * |
| 3831 | * Only {@link #VISIBLE} views are considered focusable. |
| 3832 | * |
| 3833 | * @return True if the view is focusable or if the view contains a focusable |
| 3834 | * View, false otherwise. |
| 3835 | * |
| 3836 | * @see ViewGroup#FOCUS_BLOCK_DESCENDANTS |
| 3837 | */ |
| 3838 | public boolean hasFocusable() { |
| 3839 | return (mViewFlags & VISIBILITY_MASK) == VISIBLE && isFocusable(); |
| 3840 | } |
| 3841 | |
| 3842 | /** |
| 3843 | * Called by the view system when the focus state of this view changes. |
| 3844 | * When the focus change event is caused by directional navigation, direction |
| 3845 | * and previouslyFocusedRect provide insight into where the focus is coming from. |
| 3846 | * When overriding, be sure to call up through to the super class so that |
| 3847 | * the standard focus handling will occur. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3848 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3849 | * @param gainFocus True if the View has focus; false otherwise. |
| 3850 | * @param direction The direction focus has moved when requestFocus() |
| 3851 | * is called to give this view focus. Values are |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 3852 | * {@link #FOCUS_UP}, {@link #FOCUS_DOWN}, {@link #FOCUS_LEFT}, |
| 3853 | * {@link #FOCUS_RIGHT}, {@link #FOCUS_FORWARD}, or {@link #FOCUS_BACKWARD}. |
| 3854 | * 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] | 3855 | * @param previouslyFocusedRect The rectangle, in this view's coordinate |
| 3856 | * system, of the previously focused view. If applicable, this will be |
| 3857 | * passed in as finer grained information about where the focus is coming |
| 3858 | * from (in addition to direction). Will be <code>null</code> otherwise. |
| 3859 | */ |
| 3860 | protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3861 | if (gainFocus) { |
| 3862 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 3863 | } |
| 3864 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3865 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 3866 | if (!gainFocus) { |
| 3867 | if (isPressed()) { |
| 3868 | setPressed(false); |
| 3869 | } |
| 3870 | if (imm != null && mAttachInfo != null |
| 3871 | && mAttachInfo.mHasWindowFocus) { |
| 3872 | imm.focusOut(this); |
| 3873 | } |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 3874 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3875 | } else if (imm != null && mAttachInfo != null |
| 3876 | && mAttachInfo.mHasWindowFocus) { |
| 3877 | imm.focusIn(this); |
| 3878 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3879 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 3880 | invalidate(true); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3881 | ListenerInfo li = mListenerInfo; |
| 3882 | if (li != null && li.mOnFocusChangeListener != null) { |
| 3883 | li.mOnFocusChangeListener.onFocusChange(this, gainFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3884 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3885 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3886 | if (mAttachInfo != null) { |
| 3887 | mAttachInfo.mKeyDispatchState.reset(this); |
| 3888 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3889 | } |
| 3890 | |
| 3891 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3892 | * Sends an accessibility event of the given type. If accessiiblity is |
| 3893 | * not enabled this method has no effect. The default implementation calls |
| 3894 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)} first |
| 3895 | * to populate information about the event source (this View), then calls |
| 3896 | * {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} to |
| 3897 | * populate the text content of the event source including its descendants, |
| 3898 | * and last calls |
| 3899 | * {@link ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)} |
| 3900 | * on its parent to resuest sending of the event to interested parties. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 3901 | * <p> |
| 3902 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 3903 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 3904 | * {@link AccessibilityDelegate#sendAccessibilityEvent(View, int)} is |
| 3905 | * responsible for handling this call. |
| 3906 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3907 | * |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 3908 | * @param eventType The type of the event to send, as defined by several types from |
| 3909 | * {@link android.view.accessibility.AccessibilityEvent}, such as |
| 3910 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_CLICKED} or |
| 3911 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_ENTER}. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3912 | * |
| 3913 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 3914 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 3915 | * @see ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent) |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 3916 | * @see AccessibilityDelegate |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3917 | */ |
| 3918 | public void sendAccessibilityEvent(int eventType) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 3919 | if (mAccessibilityDelegate != null) { |
| 3920 | mAccessibilityDelegate.sendAccessibilityEvent(this, eventType); |
| 3921 | } else { |
| 3922 | sendAccessibilityEventInternal(eventType); |
| 3923 | } |
| 3924 | } |
| 3925 | |
| 3926 | /** |
| 3927 | * @see #sendAccessibilityEvent(int) |
| 3928 | * |
| 3929 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 3930 | */ |
| 3931 | void sendAccessibilityEventInternal(int eventType) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3932 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 3933 | sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType)); |
| 3934 | } |
| 3935 | } |
| 3936 | |
| 3937 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3938 | * This method behaves exactly as {@link #sendAccessibilityEvent(int)} but |
| 3939 | * takes as an argument an empty {@link AccessibilityEvent} and does not |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 3940 | * perform a check whether accessibility is enabled. |
| 3941 | * <p> |
| 3942 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 3943 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 3944 | * {@link AccessibilityDelegate#sendAccessibilityEventUnchecked(View, AccessibilityEvent)} |
| 3945 | * is responsible for handling this call. |
| 3946 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3947 | * |
| 3948 | * @param event The event to send. |
| 3949 | * |
| 3950 | * @see #sendAccessibilityEvent(int) |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3951 | */ |
| 3952 | public void sendAccessibilityEventUnchecked(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 3953 | if (mAccessibilityDelegate != null) { |
| 3954 | mAccessibilityDelegate.sendAccessibilityEventUnchecked(this, event); |
| 3955 | } else { |
| 3956 | sendAccessibilityEventUncheckedInternal(event); |
| 3957 | } |
| 3958 | } |
| 3959 | |
| 3960 | /** |
| 3961 | * @see #sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 3962 | * |
| 3963 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 3964 | */ |
| 3965 | void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 9cd1eca | 2011-01-13 14:24:02 -0800 | [diff] [blame] | 3966 | if (!isShown()) { |
| 3967 | return; |
| 3968 | } |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3969 | onInitializeAccessibilityEvent(event); |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 3970 | // Only a subset of accessibility events populates text content. |
| 3971 | if ((event.getEventType() & POPULATING_ACCESSIBILITY_EVENT_TYPES) != 0) { |
| 3972 | dispatchPopulateAccessibilityEvent(event); |
| 3973 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 3974 | // In the beginning we called #isShown(), so we know that getParent() is not null. |
| 3975 | getParent().requestSendAccessibilityEvent(this, event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3976 | } |
| 3977 | |
| 3978 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3979 | * Dispatches an {@link AccessibilityEvent} to the {@link View} first and then |
| 3980 | * to its children for adding their text content to the event. Note that the |
| 3981 | * event text is populated in a separate dispatch path since we add to the |
| 3982 | * event not only the text of the source but also the text of all its descendants. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3983 | * A typical implementation will call |
| 3984 | * {@link #onPopulateAccessibilityEvent(AccessibilityEvent)} on the this view |
| 3985 | * and then call the {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
| 3986 | * on each child. Override this method if custom population of the event text |
| 3987 | * content is required. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 3988 | * <p> |
| 3989 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 3990 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 3991 | * {@link AccessibilityDelegate#dispatchPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 3992 | * is responsible for handling this call. |
| 3993 | * </p> |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 3994 | * <p> |
| 3995 | * <em>Note:</em> Accessibility events of certain types are not dispatched for |
| 3996 | * populating the event text via this method. For details refer to {@link AccessibilityEvent}. |
| 3997 | * </p> |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3998 | * |
| 3999 | * @param event The event. |
| 4000 | * |
| 4001 | * @return True if the event population was completed. |
| 4002 | */ |
| 4003 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4004 | if (mAccessibilityDelegate != null) { |
| 4005 | return mAccessibilityDelegate.dispatchPopulateAccessibilityEvent(this, event); |
| 4006 | } else { |
| 4007 | return dispatchPopulateAccessibilityEventInternal(event); |
| 4008 | } |
| 4009 | } |
| 4010 | |
| 4011 | /** |
| 4012 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4013 | * |
| 4014 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4015 | */ |
| 4016 | boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4017 | onPopulateAccessibilityEvent(event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4018 | return false; |
| 4019 | } |
| 4020 | |
| 4021 | /** |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4022 | * Called from {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4023 | * giving a chance to this View to populate the accessibility event with its |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4024 | * text content. While this method is free to modify event |
| 4025 | * attributes other than text content, doing so should normally be performed in |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4026 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)}. |
| 4027 | * <p> |
| 4028 | * Example: Adding formatted date string to an accessibility event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4029 | * to the text added by the super implementation: |
| 4030 | * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4031 | * super.onPopulateAccessibilityEvent(event); |
| 4032 | * final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; |
| 4033 | * String selectedDateUtterance = DateUtils.formatDateTime(mContext, |
| 4034 | * mCurrentDate.getTimeInMillis(), flags); |
| 4035 | * event.getText().add(selectedDateUtterance); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4036 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4037 | * <p> |
| 4038 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4039 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4040 | * {@link AccessibilityDelegate#onPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4041 | * is responsible for handling this call. |
| 4042 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4043 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4044 | * information to the event, in case the default implementation has basic information to add. |
| 4045 | * </p> |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4046 | * |
| 4047 | * @param event The accessibility event which to populate. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4048 | * |
| 4049 | * @see #sendAccessibilityEvent(int) |
| 4050 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4051 | */ |
| 4052 | public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4053 | if (mAccessibilityDelegate != null) { |
| 4054 | mAccessibilityDelegate.onPopulateAccessibilityEvent(this, event); |
| 4055 | } else { |
| 4056 | onPopulateAccessibilityEventInternal(event); |
| 4057 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4058 | } |
| 4059 | |
| 4060 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4061 | * @see #onPopulateAccessibilityEvent(AccessibilityEvent) |
| 4062 | * |
| 4063 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4064 | */ |
| 4065 | void onPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
| 4066 | |
| 4067 | } |
| 4068 | |
| 4069 | /** |
| 4070 | * Initializes an {@link AccessibilityEvent} with information about |
| 4071 | * this View which is the event source. In other words, the source of |
| 4072 | * an accessibility event is the view whose state change triggered firing |
| 4073 | * the event. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4074 | * <p> |
| 4075 | * Example: Setting the password property of an event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4076 | * to properties set by the super implementation: |
| 4077 | * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 4078 | * super.onInitializeAccessibilityEvent(event); |
| 4079 | * event.setPassword(true); |
| 4080 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4081 | * <p> |
| 4082 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4083 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4084 | * {@link AccessibilityDelegate#onInitializeAccessibilityEvent(View, AccessibilityEvent)} |
| 4085 | * is responsible for handling this call. |
| 4086 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4087 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4088 | * information to the event, in case the default implementation has basic information to add. |
| 4089 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4090 | * @param event The event to initialize. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4091 | * |
| 4092 | * @see #sendAccessibilityEvent(int) |
| 4093 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4094 | */ |
| 4095 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4096 | if (mAccessibilityDelegate != null) { |
| 4097 | mAccessibilityDelegate.onInitializeAccessibilityEvent(this, event); |
| 4098 | } else { |
| 4099 | onInitializeAccessibilityEventInternal(event); |
| 4100 | } |
| 4101 | } |
| 4102 | |
| 4103 | /** |
| 4104 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4105 | * |
| 4106 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4107 | */ |
| 4108 | void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4109 | event.setSource(this); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4110 | event.setClassName(getClass().getName()); |
| 4111 | event.setPackageName(getContext().getPackageName()); |
| 4112 | event.setEnabled(isEnabled()); |
| 4113 | event.setContentDescription(mContentDescription); |
| 4114 | |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 4115 | if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && mAttachInfo != null) { |
| 4116 | ArrayList<View> focusablesTempList = mAttachInfo.mFocusablesTempList; |
| 4117 | getRootView().addFocusables(focusablesTempList, View.FOCUS_FORWARD, |
| 4118 | FOCUSABLES_ALL); |
| 4119 | event.setItemCount(focusablesTempList.size()); |
| 4120 | event.setCurrentItemIndex(focusablesTempList.indexOf(this)); |
| 4121 | focusablesTempList.clear(); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4122 | } |
| 4123 | } |
| 4124 | |
| 4125 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4126 | * Returns an {@link AccessibilityNodeInfo} representing this view from the |
| 4127 | * point of view of an {@link android.accessibilityservice.AccessibilityService}. |
| 4128 | * This method is responsible for obtaining an accessibility node info from a |
| 4129 | * pool of reusable instances and calling |
| 4130 | * {@link #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} on this view to |
| 4131 | * initialize the former. |
| 4132 | * <p> |
| 4133 | * Note: The client is responsible for recycling the obtained instance by calling |
| 4134 | * {@link AccessibilityNodeInfo#recycle()} to minimize object creation. |
| 4135 | * </p> |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4136 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4137 | * @return A populated {@link AccessibilityNodeInfo}. |
| 4138 | * |
| 4139 | * @see AccessibilityNodeInfo |
| 4140 | */ |
| 4141 | public AccessibilityNodeInfo createAccessibilityNodeInfo() { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4142 | AccessibilityNodeProvider provider = getAccessibilityNodeProvider(); |
| 4143 | if (provider != null) { |
| 4144 | return provider.createAccessibilityNodeInfo(View.NO_ID); |
| 4145 | } else { |
| 4146 | AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(this); |
| 4147 | onInitializeAccessibilityNodeInfo(info); |
| 4148 | return info; |
| 4149 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4150 | } |
| 4151 | |
| 4152 | /** |
| 4153 | * Initializes an {@link AccessibilityNodeInfo} with information about this view. |
| 4154 | * The base implementation sets: |
| 4155 | * <ul> |
| 4156 | * <li>{@link AccessibilityNodeInfo#setParent(View)},</li> |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4157 | * <li>{@link AccessibilityNodeInfo#setBoundsInParent(Rect)},</li> |
| 4158 | * <li>{@link AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li> |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4159 | * <li>{@link AccessibilityNodeInfo#setPackageName(CharSequence)},</li> |
| 4160 | * <li>{@link AccessibilityNodeInfo#setClassName(CharSequence)},</li> |
| 4161 | * <li>{@link AccessibilityNodeInfo#setContentDescription(CharSequence)},</li> |
| 4162 | * <li>{@link AccessibilityNodeInfo#setEnabled(boolean)},</li> |
| 4163 | * <li>{@link AccessibilityNodeInfo#setClickable(boolean)},</li> |
| 4164 | * <li>{@link AccessibilityNodeInfo#setFocusable(boolean)},</li> |
| 4165 | * <li>{@link AccessibilityNodeInfo#setFocused(boolean)},</li> |
| 4166 | * <li>{@link AccessibilityNodeInfo#setLongClickable(boolean)},</li> |
| 4167 | * <li>{@link AccessibilityNodeInfo#setSelected(boolean)},</li> |
| 4168 | * </ul> |
| 4169 | * <p> |
| 4170 | * Subclasses should override this method, call the super implementation, |
| 4171 | * and set additional attributes. |
| 4172 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4173 | * <p> |
| 4174 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4175 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4176 | * {@link AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)} |
| 4177 | * is responsible for handling this call. |
| 4178 | * </p> |
| 4179 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4180 | * @param info The instance to initialize. |
| 4181 | */ |
| 4182 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4183 | if (mAccessibilityDelegate != null) { |
| 4184 | mAccessibilityDelegate.onInitializeAccessibilityNodeInfo(this, info); |
| 4185 | } else { |
| 4186 | onInitializeAccessibilityNodeInfoInternal(info); |
| 4187 | } |
| 4188 | } |
| 4189 | |
| 4190 | /** |
| 4191 | * @see #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 4192 | * |
| 4193 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4194 | */ |
| 4195 | void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4196 | Rect bounds = mAttachInfo.mTmpInvalRect; |
| 4197 | getDrawingRect(bounds); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4198 | info.setBoundsInParent(bounds); |
| 4199 | |
| 4200 | int[] locationOnScreen = mAttachInfo.mInvalidateChildLocation; |
| 4201 | getLocationOnScreen(locationOnScreen); |
Alan Viverette | 326804f | 2011-07-22 16:20:41 -0700 | [diff] [blame] | 4202 | bounds.offsetTo(0, 0); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4203 | bounds.offset(locationOnScreen[0], locationOnScreen[1]); |
| 4204 | info.setBoundsInScreen(bounds); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4205 | |
Svetoslav Ganov | 57f3b566db | 2011-10-31 17:59:14 -0700 | [diff] [blame] | 4206 | if ((mPrivateFlags & IS_ROOT_NAMESPACE) == 0) { |
| 4207 | ViewParent parent = getParent(); |
| 4208 | if (parent instanceof View) { |
| 4209 | View parentView = (View) parent; |
| 4210 | info.setParent(parentView); |
| 4211 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4212 | } |
| 4213 | |
| 4214 | info.setPackageName(mContext.getPackageName()); |
| 4215 | info.setClassName(getClass().getName()); |
| 4216 | info.setContentDescription(getContentDescription()); |
| 4217 | |
| 4218 | info.setEnabled(isEnabled()); |
| 4219 | info.setClickable(isClickable()); |
| 4220 | info.setFocusable(isFocusable()); |
| 4221 | info.setFocused(isFocused()); |
| 4222 | info.setSelected(isSelected()); |
| 4223 | info.setLongClickable(isLongClickable()); |
| 4224 | |
| 4225 | // TODO: These make sense only if we are in an AdapterView but all |
| 4226 | // views can be selected. Maybe from accessiiblity perspective |
| 4227 | // we should report as selectable view in an AdapterView. |
| 4228 | info.addAction(AccessibilityNodeInfo.ACTION_SELECT); |
| 4229 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_SELECTION); |
| 4230 | |
| 4231 | if (isFocusable()) { |
| 4232 | if (isFocused()) { |
| 4233 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS); |
| 4234 | } else { |
| 4235 | info.addAction(AccessibilityNodeInfo.ACTION_FOCUS); |
| 4236 | } |
| 4237 | } |
| 4238 | } |
| 4239 | |
| 4240 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4241 | * Sets a delegate for implementing accessibility support via compositon as |
| 4242 | * opposed to inheritance. The delegate's primary use is for implementing |
| 4243 | * backwards compatible widgets. For more details see {@link AccessibilityDelegate}. |
| 4244 | * |
| 4245 | * @param delegate The delegate instance. |
| 4246 | * |
| 4247 | * @see AccessibilityDelegate |
| 4248 | */ |
| 4249 | public void setAccessibilityDelegate(AccessibilityDelegate delegate) { |
| 4250 | mAccessibilityDelegate = delegate; |
| 4251 | } |
| 4252 | |
| 4253 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4254 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 4255 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 4256 | * that explore the window content. |
| 4257 | * <p> |
| 4258 | * If this method returns an instance, this instance is responsible for managing |
| 4259 | * {@link AccessibilityNodeInfo}s describing the virtual sub-tree rooted at this |
| 4260 | * View including the one representing the View itself. Similarly the returned |
| 4261 | * instance is responsible for performing accessibility actions on any virtual |
| 4262 | * view or the root view itself. |
| 4263 | * </p> |
| 4264 | * <p> |
| 4265 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4266 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4267 | * {@link AccessibilityDelegate#getAccessibilityNodeProvider(View)} |
| 4268 | * is responsible for handling this call. |
| 4269 | * </p> |
| 4270 | * |
| 4271 | * @return The provider. |
| 4272 | * |
| 4273 | * @see AccessibilityNodeProvider |
| 4274 | */ |
| 4275 | public AccessibilityNodeProvider getAccessibilityNodeProvider() { |
| 4276 | if (mAccessibilityDelegate != null) { |
| 4277 | return mAccessibilityDelegate.getAccessibilityNodeProvider(this); |
| 4278 | } else { |
| 4279 | return null; |
| 4280 | } |
| 4281 | } |
| 4282 | |
| 4283 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4284 | * Gets the unique identifier of this view on the screen for accessibility purposes. |
| 4285 | * If this {@link View} is not attached to any window, {@value #NO_ID} is returned. |
| 4286 | * |
| 4287 | * @return The view accessibility id. |
| 4288 | * |
| 4289 | * @hide |
| 4290 | */ |
| 4291 | public int getAccessibilityViewId() { |
| 4292 | if (mAccessibilityViewId == NO_ID) { |
| 4293 | mAccessibilityViewId = sNextAccessibilityViewId++; |
| 4294 | } |
| 4295 | return mAccessibilityViewId; |
| 4296 | } |
| 4297 | |
| 4298 | /** |
| 4299 | * Gets the unique identifier of the window in which this View reseides. |
| 4300 | * |
| 4301 | * @return The window accessibility id. |
| 4302 | * |
| 4303 | * @hide |
| 4304 | */ |
| 4305 | public int getAccessibilityWindowId() { |
| 4306 | return mAttachInfo != null ? mAttachInfo.mAccessibilityWindowId : NO_ID; |
| 4307 | } |
| 4308 | |
| 4309 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4310 | * Gets the {@link View} description. It briefly describes the view and is |
| 4311 | * primarily used for accessibility support. Set this property to enable |
| 4312 | * better accessibility support for your application. This is especially |
| 4313 | * true for views that do not have textual representation (For example, |
| 4314 | * ImageButton). |
| 4315 | * |
| 4316 | * @return The content descriptiopn. |
| 4317 | * |
| 4318 | * @attr ref android.R.styleable#View_contentDescription |
| 4319 | */ |
| 4320 | public CharSequence getContentDescription() { |
| 4321 | return mContentDescription; |
| 4322 | } |
| 4323 | |
| 4324 | /** |
| 4325 | * Sets the {@link View} description. It briefly describes the view and is |
| 4326 | * primarily used for accessibility support. Set this property to enable |
| 4327 | * better accessibility support for your application. This is especially |
| 4328 | * true for views that do not have textual representation (For example, |
| 4329 | * ImageButton). |
| 4330 | * |
| 4331 | * @param contentDescription The content description. |
| 4332 | * |
| 4333 | * @attr ref android.R.styleable#View_contentDescription |
| 4334 | */ |
Svetoslav Ganov | e261e28 | 2011-10-18 17:47:04 -0700 | [diff] [blame] | 4335 | @RemotableViewMethod |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4336 | public void setContentDescription(CharSequence contentDescription) { |
| 4337 | mContentDescription = contentDescription; |
| 4338 | } |
| 4339 | |
| 4340 | /** |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4341 | * Invoked whenever this view loses focus, either by losing window focus or by losing |
| 4342 | * focus within its window. This method can be used to clear any state tied to the |
| 4343 | * focus. For instance, if a button is held pressed with the trackball and the window |
| 4344 | * loses focus, this method can be used to cancel the press. |
| 4345 | * |
| 4346 | * Subclasses of View overriding this method should always call super.onFocusLost(). |
| 4347 | * |
| 4348 | * @see #onFocusChanged(boolean, int, android.graphics.Rect) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4349 | * @see #onWindowFocusChanged(boolean) |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4350 | * |
| 4351 | * @hide pending API council approval |
| 4352 | */ |
| 4353 | protected void onFocusLost() { |
| 4354 | resetPressedState(); |
| 4355 | } |
| 4356 | |
| 4357 | private void resetPressedState() { |
| 4358 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 4359 | return; |
| 4360 | } |
| 4361 | |
| 4362 | if (isPressed()) { |
| 4363 | setPressed(false); |
| 4364 | |
| 4365 | if (!mHasPerformedLongPress) { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 4366 | removeLongPressCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4367 | } |
| 4368 | } |
| 4369 | } |
| 4370 | |
| 4371 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4372 | * Returns true if this view has focus |
| 4373 | * |
| 4374 | * @return True if this view has focus, false otherwise. |
| 4375 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4376 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4377 | public boolean isFocused() { |
| 4378 | return (mPrivateFlags & FOCUSED) != 0; |
| 4379 | } |
| 4380 | |
| 4381 | /** |
| 4382 | * Find the view in the hierarchy rooted at this view that currently has |
| 4383 | * focus. |
| 4384 | * |
| 4385 | * @return The view that currently has focus, or null if no focused view can |
| 4386 | * be found. |
| 4387 | */ |
| 4388 | public View findFocus() { |
| 4389 | return (mPrivateFlags & FOCUSED) != 0 ? this : null; |
| 4390 | } |
| 4391 | |
| 4392 | /** |
| 4393 | * Change whether this view is one of the set of scrollable containers in |
| 4394 | * its window. This will be used to determine whether the window can |
| 4395 | * resize or must pan when a soft input area is open -- scrollable |
| 4396 | * containers allow the window to use resize mode since the container |
| 4397 | * will appropriately shrink. |
| 4398 | */ |
| 4399 | public void setScrollContainer(boolean isScrollContainer) { |
| 4400 | if (isScrollContainer) { |
| 4401 | if (mAttachInfo != null && (mPrivateFlags&SCROLL_CONTAINER_ADDED) == 0) { |
| 4402 | mAttachInfo.mScrollContainers.add(this); |
| 4403 | mPrivateFlags |= SCROLL_CONTAINER_ADDED; |
| 4404 | } |
| 4405 | mPrivateFlags |= SCROLL_CONTAINER; |
| 4406 | } else { |
| 4407 | if ((mPrivateFlags&SCROLL_CONTAINER_ADDED) != 0) { |
| 4408 | mAttachInfo.mScrollContainers.remove(this); |
| 4409 | } |
| 4410 | mPrivateFlags &= ~(SCROLL_CONTAINER|SCROLL_CONTAINER_ADDED); |
| 4411 | } |
| 4412 | } |
| 4413 | |
| 4414 | /** |
| 4415 | * Returns the quality of the drawing cache. |
| 4416 | * |
| 4417 | * @return One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 4418 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 4419 | * |
| 4420 | * @see #setDrawingCacheQuality(int) |
| 4421 | * @see #setDrawingCacheEnabled(boolean) |
| 4422 | * @see #isDrawingCacheEnabled() |
| 4423 | * |
| 4424 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 4425 | */ |
| 4426 | public int getDrawingCacheQuality() { |
| 4427 | return mViewFlags & DRAWING_CACHE_QUALITY_MASK; |
| 4428 | } |
| 4429 | |
| 4430 | /** |
| 4431 | * Set the drawing cache quality of this view. This value is used only when the |
| 4432 | * drawing cache is enabled |
| 4433 | * |
| 4434 | * @param quality One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 4435 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 4436 | * |
| 4437 | * @see #getDrawingCacheQuality() |
| 4438 | * @see #setDrawingCacheEnabled(boolean) |
| 4439 | * @see #isDrawingCacheEnabled() |
| 4440 | * |
| 4441 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 4442 | */ |
| 4443 | public void setDrawingCacheQuality(int quality) { |
| 4444 | setFlags(quality, DRAWING_CACHE_QUALITY_MASK); |
| 4445 | } |
| 4446 | |
| 4447 | /** |
| 4448 | * Returns whether the screen should remain on, corresponding to the current |
| 4449 | * value of {@link #KEEP_SCREEN_ON}. |
| 4450 | * |
| 4451 | * @return Returns true if {@link #KEEP_SCREEN_ON} is set. |
| 4452 | * |
| 4453 | * @see #setKeepScreenOn(boolean) |
| 4454 | * |
| 4455 | * @attr ref android.R.styleable#View_keepScreenOn |
| 4456 | */ |
| 4457 | public boolean getKeepScreenOn() { |
| 4458 | return (mViewFlags & KEEP_SCREEN_ON) != 0; |
| 4459 | } |
| 4460 | |
| 4461 | /** |
| 4462 | * Controls whether the screen should remain on, modifying the |
| 4463 | * value of {@link #KEEP_SCREEN_ON}. |
| 4464 | * |
| 4465 | * @param keepScreenOn Supply true to set {@link #KEEP_SCREEN_ON}. |
| 4466 | * |
| 4467 | * @see #getKeepScreenOn() |
| 4468 | * |
| 4469 | * @attr ref android.R.styleable#View_keepScreenOn |
| 4470 | */ |
| 4471 | public void setKeepScreenOn(boolean keepScreenOn) { |
| 4472 | setFlags(keepScreenOn ? KEEP_SCREEN_ON : 0, KEEP_SCREEN_ON); |
| 4473 | } |
| 4474 | |
| 4475 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4476 | * Gets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 4477 | * @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] | 4478 | * |
| 4479 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 4480 | */ |
| 4481 | public int getNextFocusLeftId() { |
| 4482 | return mNextFocusLeftId; |
| 4483 | } |
| 4484 | |
| 4485 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4486 | * Sets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 4487 | * @param nextFocusLeftId The next focus ID, or {@link #NO_ID} if the framework should |
| 4488 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4489 | * |
| 4490 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 4491 | */ |
| 4492 | public void setNextFocusLeftId(int nextFocusLeftId) { |
| 4493 | mNextFocusLeftId = nextFocusLeftId; |
| 4494 | } |
| 4495 | |
| 4496 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4497 | * Gets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 4498 | * @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] | 4499 | * |
| 4500 | * @attr ref android.R.styleable#View_nextFocusRight |
| 4501 | */ |
| 4502 | public int getNextFocusRightId() { |
| 4503 | return mNextFocusRightId; |
| 4504 | } |
| 4505 | |
| 4506 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4507 | * Sets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 4508 | * @param nextFocusRightId The next focus ID, or {@link #NO_ID} if the framework should |
| 4509 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4510 | * |
| 4511 | * @attr ref android.R.styleable#View_nextFocusRight |
| 4512 | */ |
| 4513 | public void setNextFocusRightId(int nextFocusRightId) { |
| 4514 | mNextFocusRightId = nextFocusRightId; |
| 4515 | } |
| 4516 | |
| 4517 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4518 | * Gets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 4519 | * @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] | 4520 | * |
| 4521 | * @attr ref android.R.styleable#View_nextFocusUp |
| 4522 | */ |
| 4523 | public int getNextFocusUpId() { |
| 4524 | return mNextFocusUpId; |
| 4525 | } |
| 4526 | |
| 4527 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4528 | * Sets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 4529 | * @param nextFocusUpId The next focus ID, or {@link #NO_ID} if the framework should |
| 4530 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4531 | * |
| 4532 | * @attr ref android.R.styleable#View_nextFocusUp |
| 4533 | */ |
| 4534 | public void setNextFocusUpId(int nextFocusUpId) { |
| 4535 | mNextFocusUpId = nextFocusUpId; |
| 4536 | } |
| 4537 | |
| 4538 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4539 | * Gets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 4540 | * @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] | 4541 | * |
| 4542 | * @attr ref android.R.styleable#View_nextFocusDown |
| 4543 | */ |
| 4544 | public int getNextFocusDownId() { |
| 4545 | return mNextFocusDownId; |
| 4546 | } |
| 4547 | |
| 4548 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4549 | * Sets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 4550 | * @param nextFocusDownId The next focus ID, or {@link #NO_ID} if the framework should |
| 4551 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4552 | * |
| 4553 | * @attr ref android.R.styleable#View_nextFocusDown |
| 4554 | */ |
| 4555 | public void setNextFocusDownId(int nextFocusDownId) { |
| 4556 | mNextFocusDownId = nextFocusDownId; |
| 4557 | } |
| 4558 | |
| 4559 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4560 | * Gets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 4561 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
| 4562 | * |
| 4563 | * @attr ref android.R.styleable#View_nextFocusForward |
| 4564 | */ |
| 4565 | public int getNextFocusForwardId() { |
| 4566 | return mNextFocusForwardId; |
| 4567 | } |
| 4568 | |
| 4569 | /** |
| 4570 | * Sets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 4571 | * @param nextFocusForwardId The next focus ID, or {@link #NO_ID} if the framework should |
| 4572 | * decide automatically. |
| 4573 | * |
| 4574 | * @attr ref android.R.styleable#View_nextFocusForward |
| 4575 | */ |
| 4576 | public void setNextFocusForwardId(int nextFocusForwardId) { |
| 4577 | mNextFocusForwardId = nextFocusForwardId; |
| 4578 | } |
| 4579 | |
| 4580 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4581 | * Returns the visibility of this view and all of its ancestors |
| 4582 | * |
| 4583 | * @return True if this view and all of its ancestors are {@link #VISIBLE} |
| 4584 | */ |
| 4585 | public boolean isShown() { |
| 4586 | View current = this; |
| 4587 | //noinspection ConstantConditions |
| 4588 | do { |
| 4589 | if ((current.mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 4590 | return false; |
| 4591 | } |
| 4592 | ViewParent parent = current.mParent; |
| 4593 | if (parent == null) { |
| 4594 | return false; // We are not attached to the view root |
| 4595 | } |
| 4596 | if (!(parent instanceof View)) { |
| 4597 | return true; |
| 4598 | } |
| 4599 | current = (View) parent; |
| 4600 | } while (current != null); |
| 4601 | |
| 4602 | return false; |
| 4603 | } |
| 4604 | |
| 4605 | /** |
| 4606 | * Apply the insets for system windows to this view, if the FITS_SYSTEM_WINDOWS flag |
| 4607 | * is set |
| 4608 | * |
| 4609 | * @param insets Insets for system windows |
| 4610 | * |
| 4611 | * @return True if this view applied the insets, false otherwise |
| 4612 | */ |
| 4613 | protected boolean fitSystemWindows(Rect insets) { |
| 4614 | if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) { |
| 4615 | mPaddingLeft = insets.left; |
| 4616 | mPaddingTop = insets.top; |
| 4617 | mPaddingRight = insets.right; |
| 4618 | mPaddingBottom = insets.bottom; |
| 4619 | requestLayout(); |
| 4620 | return true; |
| 4621 | } |
| 4622 | return false; |
| 4623 | } |
| 4624 | |
| 4625 | /** |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 4626 | * Set whether or not this view should account for system screen decorations |
| 4627 | * such as the status bar and inset its content. This allows this view to be |
| 4628 | * positioned in absolute screen coordinates and remain visible to the user. |
| 4629 | * |
| 4630 | * <p>This should only be used by top-level window decor views. |
| 4631 | * |
| 4632 | * @param fitSystemWindows true to inset content for system screen decorations, false for |
| 4633 | * default behavior. |
| 4634 | * |
| 4635 | * @attr ref android.R.styleable#View_fitsSystemWindows |
| 4636 | */ |
| 4637 | public void setFitsSystemWindows(boolean fitSystemWindows) { |
| 4638 | setFlags(fitSystemWindows ? FITS_SYSTEM_WINDOWS : 0, FITS_SYSTEM_WINDOWS); |
| 4639 | } |
| 4640 | |
| 4641 | /** |
| 4642 | * Check for the FITS_SYSTEM_WINDOWS flag. If this method returns true, this view |
| 4643 | * will account for system screen decorations such as the status bar and inset its |
| 4644 | * content. This allows the view to be positioned in absolute screen coordinates |
| 4645 | * and remain visible to the user. |
| 4646 | * |
| 4647 | * @return true if this view will adjust its content bounds for system screen decorations. |
| 4648 | * |
| 4649 | * @attr ref android.R.styleable#View_fitsSystemWindows |
| 4650 | */ |
| 4651 | public boolean fitsSystemWindows() { |
| 4652 | return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS; |
| 4653 | } |
| 4654 | |
| 4655 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4656 | * Returns the visibility status for this view. |
| 4657 | * |
| 4658 | * @return One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 4659 | * @attr ref android.R.styleable#View_visibility |
| 4660 | */ |
| 4661 | @ViewDebug.ExportedProperty(mapping = { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 4662 | @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), |
| 4663 | @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), |
| 4664 | @ViewDebug.IntToString(from = GONE, to = "GONE") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4665 | }) |
| 4666 | public int getVisibility() { |
| 4667 | return mViewFlags & VISIBILITY_MASK; |
| 4668 | } |
| 4669 | |
| 4670 | /** |
| 4671 | * Set the enabled state of this view. |
| 4672 | * |
| 4673 | * @param visibility One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 4674 | * @attr ref android.R.styleable#View_visibility |
| 4675 | */ |
| 4676 | @RemotableViewMethod |
| 4677 | public void setVisibility(int visibility) { |
| 4678 | setFlags(visibility, VISIBILITY_MASK); |
| 4679 | if (mBGDrawable != null) mBGDrawable.setVisible(visibility == VISIBLE, false); |
| 4680 | } |
| 4681 | |
| 4682 | /** |
| 4683 | * Returns the enabled status for this view. The interpretation of the |
| 4684 | * enabled state varies by subclass. |
| 4685 | * |
| 4686 | * @return True if this view is enabled, false otherwise. |
| 4687 | */ |
| 4688 | @ViewDebug.ExportedProperty |
| 4689 | public boolean isEnabled() { |
| 4690 | return (mViewFlags & ENABLED_MASK) == ENABLED; |
| 4691 | } |
| 4692 | |
| 4693 | /** |
| 4694 | * Set the enabled state of this view. The interpretation of the enabled |
| 4695 | * state varies by subclass. |
| 4696 | * |
| 4697 | * @param enabled True if this view is enabled, false otherwise. |
| 4698 | */ |
Jeff Sharkey | 2b95c24 | 2010-02-08 17:40:30 -0800 | [diff] [blame] | 4699 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4700 | public void setEnabled(boolean enabled) { |
Amith Yamasani | a2ef00b | 2009-07-30 16:14:34 -0700 | [diff] [blame] | 4701 | if (enabled == isEnabled()) return; |
| 4702 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4703 | setFlags(enabled ? ENABLED : DISABLED, ENABLED_MASK); |
| 4704 | |
| 4705 | /* |
| 4706 | * The View most likely has to change its appearance, so refresh |
| 4707 | * the drawable state. |
| 4708 | */ |
| 4709 | refreshDrawableState(); |
| 4710 | |
| 4711 | // Invalidate too, since the default behavior for views is to be |
| 4712 | // be drawn at 50% alpha rather than to change the drawable. |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 4713 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4714 | } |
| 4715 | |
| 4716 | /** |
| 4717 | * Set whether this view can receive the focus. |
| 4718 | * |
| 4719 | * Setting this to false will also ensure that this view is not focusable |
| 4720 | * in touch mode. |
| 4721 | * |
| 4722 | * @param focusable If true, this view can receive the focus. |
| 4723 | * |
| 4724 | * @see #setFocusableInTouchMode(boolean) |
| 4725 | * @attr ref android.R.styleable#View_focusable |
| 4726 | */ |
| 4727 | public void setFocusable(boolean focusable) { |
| 4728 | if (!focusable) { |
| 4729 | setFlags(0, FOCUSABLE_IN_TOUCH_MODE); |
| 4730 | } |
| 4731 | setFlags(focusable ? FOCUSABLE : NOT_FOCUSABLE, FOCUSABLE_MASK); |
| 4732 | } |
| 4733 | |
| 4734 | /** |
| 4735 | * Set whether this view can receive focus while in touch mode. |
| 4736 | * |
| 4737 | * Setting this to true will also ensure that this view is focusable. |
| 4738 | * |
| 4739 | * @param focusableInTouchMode If true, this view can receive the focus while |
| 4740 | * in touch mode. |
| 4741 | * |
| 4742 | * @see #setFocusable(boolean) |
| 4743 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 4744 | */ |
| 4745 | public void setFocusableInTouchMode(boolean focusableInTouchMode) { |
| 4746 | // Focusable in touch mode should always be set before the focusable flag |
| 4747 | // otherwise, setting the focusable flag will trigger a focusableViewAvailable() |
| 4748 | // which, in touch mode, will not successfully request focus on this view |
| 4749 | // because the focusable in touch mode flag is not set |
| 4750 | setFlags(focusableInTouchMode ? FOCUSABLE_IN_TOUCH_MODE : 0, FOCUSABLE_IN_TOUCH_MODE); |
| 4751 | if (focusableInTouchMode) { |
| 4752 | setFlags(FOCUSABLE, FOCUSABLE_MASK); |
| 4753 | } |
| 4754 | } |
| 4755 | |
| 4756 | /** |
| 4757 | * Set whether this view should have sound effects enabled for events such as |
| 4758 | * clicking and touching. |
| 4759 | * |
| 4760 | * <p>You may wish to disable sound effects for a view if you already play sounds, |
| 4761 | * for instance, a dial key that plays dtmf tones. |
| 4762 | * |
| 4763 | * @param soundEffectsEnabled whether sound effects are enabled for this view. |
| 4764 | * @see #isSoundEffectsEnabled() |
| 4765 | * @see #playSoundEffect(int) |
| 4766 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 4767 | */ |
| 4768 | public void setSoundEffectsEnabled(boolean soundEffectsEnabled) { |
| 4769 | setFlags(soundEffectsEnabled ? SOUND_EFFECTS_ENABLED: 0, SOUND_EFFECTS_ENABLED); |
| 4770 | } |
| 4771 | |
| 4772 | /** |
| 4773 | * @return whether this view should have sound effects enabled for events such as |
| 4774 | * clicking and touching. |
| 4775 | * |
| 4776 | * @see #setSoundEffectsEnabled(boolean) |
| 4777 | * @see #playSoundEffect(int) |
| 4778 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 4779 | */ |
| 4780 | @ViewDebug.ExportedProperty |
| 4781 | public boolean isSoundEffectsEnabled() { |
| 4782 | return SOUND_EFFECTS_ENABLED == (mViewFlags & SOUND_EFFECTS_ENABLED); |
| 4783 | } |
| 4784 | |
| 4785 | /** |
| 4786 | * Set whether this view should have haptic feedback for events such as |
| 4787 | * long presses. |
| 4788 | * |
| 4789 | * <p>You may wish to disable haptic feedback if your view already controls |
| 4790 | * its own haptic feedback. |
| 4791 | * |
| 4792 | * @param hapticFeedbackEnabled whether haptic feedback enabled for this view. |
| 4793 | * @see #isHapticFeedbackEnabled() |
| 4794 | * @see #performHapticFeedback(int) |
| 4795 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 4796 | */ |
| 4797 | public void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled) { |
| 4798 | setFlags(hapticFeedbackEnabled ? HAPTIC_FEEDBACK_ENABLED: 0, HAPTIC_FEEDBACK_ENABLED); |
| 4799 | } |
| 4800 | |
| 4801 | /** |
| 4802 | * @return whether this view should have haptic feedback enabled for events |
| 4803 | * long presses. |
| 4804 | * |
| 4805 | * @see #setHapticFeedbackEnabled(boolean) |
| 4806 | * @see #performHapticFeedback(int) |
| 4807 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 4808 | */ |
| 4809 | @ViewDebug.ExportedProperty |
| 4810 | public boolean isHapticFeedbackEnabled() { |
| 4811 | return HAPTIC_FEEDBACK_ENABLED == (mViewFlags & HAPTIC_FEEDBACK_ENABLED); |
| 4812 | } |
| 4813 | |
| 4814 | /** |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4815 | * Returns the layout direction for this view. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4816 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4817 | * @return One of {@link #LAYOUT_DIRECTION_LTR}, |
| 4818 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 4819 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 4820 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
| 4821 | * @attr ref android.R.styleable#View_layoutDirection |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 4822 | * |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4823 | * @hide |
| 4824 | */ |
Fabrice Di Meglio | bce84d2 | 2011-06-02 15:57:01 -0700 | [diff] [blame] | 4825 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4826 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "LTR"), |
| 4827 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RTL"), |
| 4828 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"), |
| 4829 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE, to = "LOCALE") |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4830 | }) |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4831 | public int getLayoutDirection() { |
| 4832 | return mViewFlags & LAYOUT_DIRECTION_MASK; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4833 | } |
| 4834 | |
| 4835 | /** |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 4836 | * Set the layout direction for this view. This will propagate a reset of layout direction |
| 4837 | * 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] | 4838 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4839 | * @param layoutDirection One of {@link #LAYOUT_DIRECTION_LTR}, |
| 4840 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 4841 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 4842 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 4843 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4844 | * @attr ref android.R.styleable#View_layoutDirection |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 4845 | * |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4846 | * @hide |
| 4847 | */ |
| 4848 | @RemotableViewMethod |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4849 | public void setLayoutDirection(int layoutDirection) { |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 4850 | if (getLayoutDirection() != layoutDirection) { |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 4851 | resetResolvedLayoutDirection(); |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 4852 | // Setting the flag will also request a layout. |
| 4853 | setFlags(layoutDirection, LAYOUT_DIRECTION_MASK); |
| 4854 | } |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4855 | } |
| 4856 | |
| 4857 | /** |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 4858 | * Returns the resolved layout direction for this view. |
| 4859 | * |
| 4860 | * @return {@link #LAYOUT_DIRECTION_RTL} if the layout direction is RTL or returns |
| 4861 | * {@link #LAYOUT_DIRECTION_LTR} id the layout direction is not RTL. |
| 4862 | * |
| 4863 | * @hide |
| 4864 | */ |
| 4865 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
| 4866 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"), |
| 4867 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL") |
| 4868 | }) |
| 4869 | public int getResolvedLayoutDirection() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 4870 | resolveLayoutDirectionIfNeeded(); |
| 4871 | return ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED_RTL) == LAYOUT_DIRECTION_RESOLVED_RTL) ? |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 4872 | LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR; |
| 4873 | } |
| 4874 | |
| 4875 | /** |
| 4876 | * <p>Indicates whether or not this view's layout is right-to-left. This is resolved from |
| 4877 | * layout attribute and/or the inherited value from the parent.</p> |
| 4878 | * |
| 4879 | * @return true if the layout is right-to-left. |
| 4880 | * |
| 4881 | * @hide |
| 4882 | */ |
| 4883 | @ViewDebug.ExportedProperty(category = "layout") |
| 4884 | public boolean isLayoutRtl() { |
| 4885 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL); |
| 4886 | } |
| 4887 | |
| 4888 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4889 | * If this view doesn't do any drawing on its own, set this flag to |
| 4890 | * allow further optimizations. By default, this flag is not set on |
| 4891 | * View, but could be set on some View subclasses such as ViewGroup. |
| 4892 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 4893 | * Typically, if you override {@link #onDraw(android.graphics.Canvas)} |
| 4894 | * you should clear this flag. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4895 | * |
| 4896 | * @param willNotDraw whether or not this View draw on its own |
| 4897 | */ |
| 4898 | public void setWillNotDraw(boolean willNotDraw) { |
| 4899 | setFlags(willNotDraw ? WILL_NOT_DRAW : 0, DRAW_MASK); |
| 4900 | } |
| 4901 | |
| 4902 | /** |
| 4903 | * Returns whether or not this View draws on its own. |
| 4904 | * |
| 4905 | * @return true if this view has nothing to draw, false otherwise |
| 4906 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4907 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4908 | public boolean willNotDraw() { |
| 4909 | return (mViewFlags & DRAW_MASK) == WILL_NOT_DRAW; |
| 4910 | } |
| 4911 | |
| 4912 | /** |
| 4913 | * When a View's drawing cache is enabled, drawing is redirected to an |
| 4914 | * offscreen bitmap. Some views, like an ImageView, must be able to |
| 4915 | * bypass this mechanism if they already draw a single bitmap, to avoid |
| 4916 | * unnecessary usage of the memory. |
| 4917 | * |
| 4918 | * @param willNotCacheDrawing true if this view does not cache its |
| 4919 | * drawing, false otherwise |
| 4920 | */ |
| 4921 | public void setWillNotCacheDrawing(boolean willNotCacheDrawing) { |
| 4922 | setFlags(willNotCacheDrawing ? WILL_NOT_CACHE_DRAWING : 0, WILL_NOT_CACHE_DRAWING); |
| 4923 | } |
| 4924 | |
| 4925 | /** |
| 4926 | * Returns whether or not this View can cache its drawing or not. |
| 4927 | * |
| 4928 | * @return true if this view does not cache its drawing, false otherwise |
| 4929 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4930 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4931 | public boolean willNotCacheDrawing() { |
| 4932 | return (mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING; |
| 4933 | } |
| 4934 | |
| 4935 | /** |
| 4936 | * Indicates whether this view reacts to click events or not. |
| 4937 | * |
| 4938 | * @return true if the view is clickable, false otherwise |
| 4939 | * |
| 4940 | * @see #setClickable(boolean) |
| 4941 | * @attr ref android.R.styleable#View_clickable |
| 4942 | */ |
| 4943 | @ViewDebug.ExportedProperty |
| 4944 | public boolean isClickable() { |
| 4945 | return (mViewFlags & CLICKABLE) == CLICKABLE; |
| 4946 | } |
| 4947 | |
| 4948 | /** |
| 4949 | * Enables or disables click events for this view. When a view |
| 4950 | * is clickable it will change its state to "pressed" on every click. |
| 4951 | * Subclasses should set the view clickable to visually react to |
| 4952 | * user's clicks. |
| 4953 | * |
| 4954 | * @param clickable true to make the view clickable, false otherwise |
| 4955 | * |
| 4956 | * @see #isClickable() |
| 4957 | * @attr ref android.R.styleable#View_clickable |
| 4958 | */ |
| 4959 | public void setClickable(boolean clickable) { |
| 4960 | setFlags(clickable ? CLICKABLE : 0, CLICKABLE); |
| 4961 | } |
| 4962 | |
| 4963 | /** |
| 4964 | * Indicates whether this view reacts to long click events or not. |
| 4965 | * |
| 4966 | * @return true if the view is long clickable, false otherwise |
| 4967 | * |
| 4968 | * @see #setLongClickable(boolean) |
| 4969 | * @attr ref android.R.styleable#View_longClickable |
| 4970 | */ |
| 4971 | public boolean isLongClickable() { |
| 4972 | return (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 4973 | } |
| 4974 | |
| 4975 | /** |
| 4976 | * Enables or disables long click events for this view. When a view is long |
| 4977 | * clickable it reacts to the user holding down the button for a longer |
| 4978 | * duration than a tap. This event can either launch the listener or a |
| 4979 | * context menu. |
| 4980 | * |
| 4981 | * @param longClickable true to make the view long clickable, false otherwise |
| 4982 | * @see #isLongClickable() |
| 4983 | * @attr ref android.R.styleable#View_longClickable |
| 4984 | */ |
| 4985 | public void setLongClickable(boolean longClickable) { |
| 4986 | setFlags(longClickable ? LONG_CLICKABLE : 0, LONG_CLICKABLE); |
| 4987 | } |
| 4988 | |
| 4989 | /** |
Chet Haase | 49afa5b | 2010-08-23 11:39:53 -0700 | [diff] [blame] | 4990 | * Sets the pressed state for this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4991 | * |
| 4992 | * @see #isClickable() |
| 4993 | * @see #setClickable(boolean) |
| 4994 | * |
| 4995 | * @param pressed Pass true to set the View's internal state to "pressed", or false to reverts |
| 4996 | * the View's internal state from a previously set "pressed" state. |
| 4997 | */ |
| 4998 | public void setPressed(boolean pressed) { |
| 4999 | if (pressed) { |
| 5000 | mPrivateFlags |= PRESSED; |
| 5001 | } else { |
| 5002 | mPrivateFlags &= ~PRESSED; |
| 5003 | } |
| 5004 | refreshDrawableState(); |
| 5005 | dispatchSetPressed(pressed); |
| 5006 | } |
| 5007 | |
| 5008 | /** |
| 5009 | * Dispatch setPressed to all of this View's children. |
| 5010 | * |
| 5011 | * @see #setPressed(boolean) |
| 5012 | * |
| 5013 | * @param pressed The new pressed state |
| 5014 | */ |
| 5015 | protected void dispatchSetPressed(boolean pressed) { |
| 5016 | } |
| 5017 | |
| 5018 | /** |
| 5019 | * Indicates whether the view is currently in pressed state. Unless |
| 5020 | * {@link #setPressed(boolean)} is explicitly called, only clickable views can enter |
| 5021 | * the pressed state. |
| 5022 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5023 | * @see #setPressed(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5024 | * @see #isClickable() |
| 5025 | * @see #setClickable(boolean) |
| 5026 | * |
| 5027 | * @return true if the view is currently pressed, false otherwise |
| 5028 | */ |
| 5029 | public boolean isPressed() { |
| 5030 | return (mPrivateFlags & PRESSED) == PRESSED; |
| 5031 | } |
| 5032 | |
| 5033 | /** |
| 5034 | * Indicates whether this view will save its state (that is, |
| 5035 | * whether its {@link #onSaveInstanceState} method will be called). |
| 5036 | * |
| 5037 | * @return Returns true if the view state saving is enabled, else false. |
| 5038 | * |
| 5039 | * @see #setSaveEnabled(boolean) |
| 5040 | * @attr ref android.R.styleable#View_saveEnabled |
| 5041 | */ |
| 5042 | public boolean isSaveEnabled() { |
| 5043 | return (mViewFlags & SAVE_DISABLED_MASK) != SAVE_DISABLED; |
| 5044 | } |
| 5045 | |
| 5046 | /** |
| 5047 | * Controls whether the saving of this view's state is |
| 5048 | * enabled (that is, whether its {@link #onSaveInstanceState} method |
| 5049 | * will be called). Note that even if freezing is enabled, the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5050 | * 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] | 5051 | * for its state to be saved. This flag can only disable the |
| 5052 | * saving of this view; any child views may still have their state saved. |
| 5053 | * |
| 5054 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 5055 | * (the default) to allow it. |
| 5056 | * |
| 5057 | * @see #isSaveEnabled() |
| 5058 | * @see #setId(int) |
| 5059 | * @see #onSaveInstanceState() |
| 5060 | * @attr ref android.R.styleable#View_saveEnabled |
| 5061 | */ |
| 5062 | public void setSaveEnabled(boolean enabled) { |
| 5063 | setFlags(enabled ? 0 : SAVE_DISABLED, SAVE_DISABLED_MASK); |
| 5064 | } |
| 5065 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5066 | /** |
| 5067 | * Gets whether the framework should discard touches when the view's |
| 5068 | * window is obscured by another visible window. |
| 5069 | * Refer to the {@link View} security documentation for more details. |
| 5070 | * |
| 5071 | * @return True if touch filtering is enabled. |
| 5072 | * |
| 5073 | * @see #setFilterTouchesWhenObscured(boolean) |
| 5074 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 5075 | */ |
| 5076 | @ViewDebug.ExportedProperty |
| 5077 | public boolean getFilterTouchesWhenObscured() { |
| 5078 | return (mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0; |
| 5079 | } |
| 5080 | |
| 5081 | /** |
| 5082 | * Sets whether the framework should discard touches when the view's |
| 5083 | * window is obscured by another visible window. |
| 5084 | * Refer to the {@link View} security documentation for more details. |
| 5085 | * |
| 5086 | * @param enabled True if touch filtering should be enabled. |
| 5087 | * |
| 5088 | * @see #getFilterTouchesWhenObscured |
| 5089 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 5090 | */ |
| 5091 | public void setFilterTouchesWhenObscured(boolean enabled) { |
| 5092 | setFlags(enabled ? 0 : FILTER_TOUCHES_WHEN_OBSCURED, |
| 5093 | FILTER_TOUCHES_WHEN_OBSCURED); |
| 5094 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5095 | |
| 5096 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 5097 | * Indicates whether the entire hierarchy under this view will save its |
| 5098 | * state when a state saving traversal occurs from its parent. The default |
| 5099 | * is true; if false, these views will not be saved unless |
| 5100 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 5101 | * |
| 5102 | * @return Returns true if the view state saving from parent is enabled, else false. |
| 5103 | * |
| 5104 | * @see #setSaveFromParentEnabled(boolean) |
| 5105 | */ |
| 5106 | public boolean isSaveFromParentEnabled() { |
| 5107 | return (mViewFlags & PARENT_SAVE_DISABLED_MASK) != PARENT_SAVE_DISABLED; |
| 5108 | } |
| 5109 | |
| 5110 | /** |
| 5111 | * Controls whether the entire hierarchy under this view will save its |
| 5112 | * state when a state saving traversal occurs from its parent. The default |
| 5113 | * is true; if false, these views will not be saved unless |
| 5114 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 5115 | * |
| 5116 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 5117 | * (the default) to allow it. |
| 5118 | * |
| 5119 | * @see #isSaveFromParentEnabled() |
| 5120 | * @see #setId(int) |
| 5121 | * @see #onSaveInstanceState() |
| 5122 | */ |
| 5123 | public void setSaveFromParentEnabled(boolean enabled) { |
| 5124 | setFlags(enabled ? 0 : PARENT_SAVE_DISABLED, PARENT_SAVE_DISABLED_MASK); |
| 5125 | } |
| 5126 | |
| 5127 | |
| 5128 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5129 | * Returns whether this View is able to take focus. |
| 5130 | * |
| 5131 | * @return True if this view can take focus, or false otherwise. |
| 5132 | * @attr ref android.R.styleable#View_focusable |
| 5133 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5134 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5135 | public final boolean isFocusable() { |
| 5136 | return FOCUSABLE == (mViewFlags & FOCUSABLE_MASK); |
| 5137 | } |
| 5138 | |
| 5139 | /** |
| 5140 | * When a view is focusable, it may not want to take focus when in touch mode. |
| 5141 | * For example, a button would like focus when the user is navigating via a D-pad |
| 5142 | * so that the user can click on it, but once the user starts touching the screen, |
| 5143 | * the button shouldn't take focus |
| 5144 | * @return Whether the view is focusable in touch mode. |
| 5145 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 5146 | */ |
| 5147 | @ViewDebug.ExportedProperty |
| 5148 | public final boolean isFocusableInTouchMode() { |
| 5149 | return FOCUSABLE_IN_TOUCH_MODE == (mViewFlags & FOCUSABLE_IN_TOUCH_MODE); |
| 5150 | } |
| 5151 | |
| 5152 | /** |
| 5153 | * Find the nearest view in the specified direction that can take focus. |
| 5154 | * This does not actually give focus to that view. |
| 5155 | * |
| 5156 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 5157 | * |
| 5158 | * @return The nearest focusable in the specified direction, or null if none |
| 5159 | * can be found. |
| 5160 | */ |
| 5161 | public View focusSearch(int direction) { |
| 5162 | if (mParent != null) { |
| 5163 | return mParent.focusSearch(this, direction); |
| 5164 | } else { |
| 5165 | return null; |
| 5166 | } |
| 5167 | } |
| 5168 | |
| 5169 | /** |
| 5170 | * This method is the last chance for the focused view and its ancestors to |
| 5171 | * respond to an arrow key. This is called when the focused view did not |
| 5172 | * consume the key internally, nor could the view system find a new view in |
| 5173 | * the requested direction to give focus to. |
| 5174 | * |
| 5175 | * @param focused The currently focused view. |
| 5176 | * @param direction The direction focus wants to move. One of FOCUS_UP, |
| 5177 | * FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT. |
| 5178 | * @return True if the this view consumed this unhandled move. |
| 5179 | */ |
| 5180 | public boolean dispatchUnhandledMove(View focused, int direction) { |
| 5181 | return false; |
| 5182 | } |
| 5183 | |
| 5184 | /** |
| 5185 | * 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] | 5186 | * use the root to look up the view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5187 | * @param root The root view of the hierarchy containing this view. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5188 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, |
| 5189 | * or FOCUS_BACKWARD. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5190 | * @return The user specified next view, or null if there is none. |
| 5191 | */ |
| 5192 | View findUserSetNextFocus(View root, int direction) { |
| 5193 | switch (direction) { |
| 5194 | case FOCUS_LEFT: |
| 5195 | if (mNextFocusLeftId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5196 | return findViewInsideOutShouldExist(root, mNextFocusLeftId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5197 | case FOCUS_RIGHT: |
| 5198 | if (mNextFocusRightId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5199 | return findViewInsideOutShouldExist(root, mNextFocusRightId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5200 | case FOCUS_UP: |
| 5201 | if (mNextFocusUpId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5202 | return findViewInsideOutShouldExist(root, mNextFocusUpId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5203 | case FOCUS_DOWN: |
| 5204 | if (mNextFocusDownId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5205 | return findViewInsideOutShouldExist(root, mNextFocusDownId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5206 | case FOCUS_FORWARD: |
| 5207 | if (mNextFocusForwardId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5208 | return findViewInsideOutShouldExist(root, mNextFocusForwardId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5209 | case FOCUS_BACKWARD: { |
| 5210 | final int id = mID; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5211 | return root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5212 | @Override |
| 5213 | public boolean apply(View t) { |
| 5214 | return t.mNextFocusForwardId == id; |
| 5215 | } |
| 5216 | }); |
| 5217 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5218 | } |
| 5219 | return null; |
| 5220 | } |
| 5221 | |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5222 | private View findViewInsideOutShouldExist(View root, final int childViewId) { |
| 5223 | View result = root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
| 5224 | @Override |
| 5225 | public boolean apply(View t) { |
| 5226 | return t.mID == childViewId; |
| 5227 | } |
| 5228 | }); |
| 5229 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5230 | if (result == null) { |
| 5231 | Log.w(VIEW_LOG_TAG, "couldn't find next focus view specified " |
| 5232 | + "by user for id " + childViewId); |
| 5233 | } |
| 5234 | return result; |
| 5235 | } |
| 5236 | |
| 5237 | /** |
| 5238 | * Find and return all focusable views that are descendants of this view, |
| 5239 | * possibly including this view if it is focusable itself. |
| 5240 | * |
| 5241 | * @param direction The direction of the focus |
| 5242 | * @return A list of focusable views |
| 5243 | */ |
| 5244 | public ArrayList<View> getFocusables(int direction) { |
| 5245 | ArrayList<View> result = new ArrayList<View>(24); |
| 5246 | addFocusables(result, direction); |
| 5247 | return result; |
| 5248 | } |
| 5249 | |
| 5250 | /** |
| 5251 | * Add any focusable views that are descendants of this view (possibly |
| 5252 | * including this view if it is focusable itself) to views. If we are in touch mode, |
| 5253 | * only add views that are also focusable in touch mode. |
| 5254 | * |
| 5255 | * @param views Focusable views found so far |
| 5256 | * @param direction The direction of the focus |
| 5257 | */ |
| 5258 | public void addFocusables(ArrayList<View> views, int direction) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5259 | addFocusables(views, direction, FOCUSABLES_TOUCH_MODE); |
| 5260 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5261 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5262 | /** |
| 5263 | * Adds any focusable views that are descendants of this view (possibly |
| 5264 | * including this view if it is focusable itself) to views. This method |
| 5265 | * adds all focusable views regardless if we are in touch mode or |
| 5266 | * only views focusable in touch mode if we are in touch mode depending on |
| 5267 | * the focusable mode paramater. |
| 5268 | * |
| 5269 | * @param views Focusable views found so far or null if all we are interested is |
| 5270 | * the number of focusables. |
| 5271 | * @param direction The direction of the focus. |
| 5272 | * @param focusableMode The type of focusables to be added. |
| 5273 | * |
| 5274 | * @see #FOCUSABLES_ALL |
| 5275 | * @see #FOCUSABLES_TOUCH_MODE |
| 5276 | */ |
| 5277 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
| 5278 | if (!isFocusable()) { |
| 5279 | return; |
| 5280 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5281 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5282 | if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && |
| 5283 | isInTouchMode() && !isFocusableInTouchMode()) { |
| 5284 | return; |
| 5285 | } |
| 5286 | |
| 5287 | if (views != null) { |
| 5288 | views.add(this); |
| 5289 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5293 | * Finds the Views that contain given text. The containment is case insensitive. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5294 | * The search is performed by either the text that the View renders or the content |
| 5295 | * description that describes the view for accessibility purposes and the view does |
| 5296 | * not render or both. Clients can specify how the search is to be performed via |
| 5297 | * passing the {@link #FIND_VIEWS_WITH_TEXT} and |
| 5298 | * {@link #FIND_VIEWS_WITH_CONTENT_DESCRIPTION} flags. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5299 | * |
| 5300 | * @param outViews The output list of matching Views. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5301 | * @param searched The text to match against. |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 5302 | * |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5303 | * @see #FIND_VIEWS_WITH_TEXT |
| 5304 | * @see #FIND_VIEWS_WITH_CONTENT_DESCRIPTION |
| 5305 | * @see #setContentDescription(CharSequence) |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5306 | */ |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5307 | public void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 5308 | if (getAccessibilityNodeProvider() != null) { |
| 5309 | if ((flags & FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS) != 0) { |
| 5310 | outViews.add(this); |
| 5311 | } |
| 5312 | } else if ((flags & FIND_VIEWS_WITH_CONTENT_DESCRIPTION) != 0 |
| 5313 | && !TextUtils.isEmpty(searched) && !TextUtils.isEmpty(mContentDescription)) { |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5314 | String searchedLowerCase = searched.toString().toLowerCase(); |
| 5315 | String contentDescriptionLowerCase = mContentDescription.toString().toLowerCase(); |
| 5316 | if (contentDescriptionLowerCase.contains(searchedLowerCase)) { |
| 5317 | outViews.add(this); |
| 5318 | } |
| 5319 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5320 | } |
| 5321 | |
| 5322 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5323 | * Find and return all touchable views that are descendants of this view, |
| 5324 | * possibly including this view if it is touchable itself. |
| 5325 | * |
| 5326 | * @return A list of touchable views |
| 5327 | */ |
| 5328 | public ArrayList<View> getTouchables() { |
| 5329 | ArrayList<View> result = new ArrayList<View>(); |
| 5330 | addTouchables(result); |
| 5331 | return result; |
| 5332 | } |
| 5333 | |
| 5334 | /** |
| 5335 | * Add any touchable views that are descendants of this view (possibly |
| 5336 | * including this view if it is touchable itself) to views. |
| 5337 | * |
| 5338 | * @param views Touchable views found so far |
| 5339 | */ |
| 5340 | public void addTouchables(ArrayList<View> views) { |
| 5341 | final int viewFlags = mViewFlags; |
| 5342 | |
| 5343 | if (((viewFlags & CLICKABLE) == CLICKABLE || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) |
| 5344 | && (viewFlags & ENABLED_MASK) == ENABLED) { |
| 5345 | views.add(this); |
| 5346 | } |
| 5347 | } |
| 5348 | |
| 5349 | /** |
| 5350 | * Call this to try to give focus to a specific view or to one of its |
| 5351 | * descendants. |
| 5352 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5353 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 5354 | * false), or if it is focusable and it is not focusable in touch mode |
| 5355 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5356 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5357 | * 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] | 5358 | * have focus, and you want your parent to look for the next one. |
| 5359 | * |
| 5360 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with arguments |
| 5361 | * {@link #FOCUS_DOWN} and <code>null</code>. |
| 5362 | * |
| 5363 | * @return Whether this view or one of its descendants actually took focus. |
| 5364 | */ |
| 5365 | public final boolean requestFocus() { |
| 5366 | return requestFocus(View.FOCUS_DOWN); |
| 5367 | } |
| 5368 | |
| 5369 | |
| 5370 | /** |
| 5371 | * Call this to try to give focus to a specific view or to one of its |
| 5372 | * descendants and give it a hint about what direction focus is heading. |
| 5373 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5374 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 5375 | * false), or if it is focusable and it is not focusable in touch mode |
| 5376 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5377 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5378 | * 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] | 5379 | * have focus, and you want your parent to look for the next one. |
| 5380 | * |
| 5381 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with |
| 5382 | * <code>null</code> set for the previously focused rectangle. |
| 5383 | * |
| 5384 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 5385 | * @return Whether this view or one of its descendants actually took focus. |
| 5386 | */ |
| 5387 | public final boolean requestFocus(int direction) { |
| 5388 | return requestFocus(direction, null); |
| 5389 | } |
| 5390 | |
| 5391 | /** |
| 5392 | * Call this to try to give focus to a specific view or to one of its descendants |
| 5393 | * and give it hints about the direction and a specific rectangle that the focus |
| 5394 | * is coming from. The rectangle can help give larger views a finer grained hint |
| 5395 | * about where focus is coming from, and therefore, where to show selection, or |
| 5396 | * forward focus change internally. |
| 5397 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5398 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 5399 | * false), or if it is focusable and it is not focusable in touch mode |
| 5400 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5401 | * |
| 5402 | * A View will not take focus if it is not visible. |
| 5403 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5404 | * A View will not take focus if one of its parents has |
| 5405 | * {@link android.view.ViewGroup#getDescendantFocusability()} equal to |
| 5406 | * {@link ViewGroup#FOCUS_BLOCK_DESCENDANTS}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5407 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5408 | * 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] | 5409 | * have focus, and you want your parent to look for the next one. |
| 5410 | * |
| 5411 | * You may wish to override this method if your custom {@link View} has an internal |
| 5412 | * {@link View} that it wishes to forward the request to. |
| 5413 | * |
| 5414 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 5415 | * @param previouslyFocusedRect The rectangle (in this View's coordinate system) |
| 5416 | * to give a finer grained hint about where focus is coming from. May be null |
| 5417 | * if there is no hint. |
| 5418 | * @return Whether this view or one of its descendants actually took focus. |
| 5419 | */ |
| 5420 | public boolean requestFocus(int direction, Rect previouslyFocusedRect) { |
| 5421 | // need to be focusable |
| 5422 | if ((mViewFlags & FOCUSABLE_MASK) != FOCUSABLE || |
| 5423 | (mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 5424 | return false; |
| 5425 | } |
| 5426 | |
| 5427 | // need to be focusable in touch mode if in touch mode |
| 5428 | if (isInTouchMode() && |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5429 | (FOCUSABLE_IN_TOUCH_MODE != (mViewFlags & FOCUSABLE_IN_TOUCH_MODE))) { |
| 5430 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | // need to not have any parents blocking us |
| 5434 | if (hasAncestorThatBlocksDescendantFocus()) { |
| 5435 | return false; |
| 5436 | } |
| 5437 | |
| 5438 | handleFocusGainInternal(direction, previouslyFocusedRect); |
| 5439 | return true; |
| 5440 | } |
| 5441 | |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 5442 | /** Gets the ViewAncestor, or null if not attached. */ |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 5443 | /*package*/ ViewRootImpl getViewRootImpl() { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5444 | View root = getRootView(); |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 5445 | return root != null ? (ViewRootImpl)root.getParent() : null; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5446 | } |
| 5447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5448 | /** |
| 5449 | * Call this to try to give focus to a specific view or to one of its descendants. This is a |
| 5450 | * special variant of {@link #requestFocus() } that will allow views that are not focuable in |
| 5451 | * touch mode to request focus when they are touched. |
| 5452 | * |
| 5453 | * @return Whether this view or one of its descendants actually took focus. |
| 5454 | * |
| 5455 | * @see #isInTouchMode() |
| 5456 | * |
| 5457 | */ |
| 5458 | public final boolean requestFocusFromTouch() { |
| 5459 | // Leave touch mode if we need to |
| 5460 | if (isInTouchMode()) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 5461 | ViewRootImpl viewRoot = getViewRootImpl(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5462 | if (viewRoot != null) { |
| 5463 | viewRoot.ensureTouchMode(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5464 | } |
| 5465 | } |
| 5466 | return requestFocus(View.FOCUS_DOWN); |
| 5467 | } |
| 5468 | |
| 5469 | /** |
| 5470 | * @return Whether any ancestor of this view blocks descendant focus. |
| 5471 | */ |
| 5472 | private boolean hasAncestorThatBlocksDescendantFocus() { |
| 5473 | ViewParent ancestor = mParent; |
| 5474 | while (ancestor instanceof ViewGroup) { |
| 5475 | final ViewGroup vgAncestor = (ViewGroup) ancestor; |
| 5476 | if (vgAncestor.getDescendantFocusability() == ViewGroup.FOCUS_BLOCK_DESCENDANTS) { |
| 5477 | return true; |
| 5478 | } else { |
| 5479 | ancestor = vgAncestor.getParent(); |
| 5480 | } |
| 5481 | } |
| 5482 | return false; |
| 5483 | } |
| 5484 | |
| 5485 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5486 | * @hide |
| 5487 | */ |
| 5488 | public void dispatchStartTemporaryDetach() { |
| 5489 | onStartTemporaryDetach(); |
| 5490 | } |
| 5491 | |
| 5492 | /** |
| 5493 | * 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] | 5494 | * {@link ViewGroup#detachViewFromParent(View) ViewGroup.detachViewFromParent}. |
| 5495 | * It will either be followed by {@link #onFinishTemporaryDetach()} or |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5496 | * {@link #onDetachedFromWindow()} when the container is done. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5497 | */ |
| 5498 | public void onStartTemporaryDetach() { |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5499 | removeUnsetPressCallback(); |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 5500 | mPrivateFlags |= CANCEL_NEXT_UP_EVENT; |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5501 | } |
| 5502 | |
| 5503 | /** |
| 5504 | * @hide |
| 5505 | */ |
| 5506 | public void dispatchFinishTemporaryDetach() { |
| 5507 | onFinishTemporaryDetach(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5508 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5510 | /** |
| 5511 | * Called after {@link #onStartTemporaryDetach} when the container is done |
| 5512 | * changing the view. |
| 5513 | */ |
| 5514 | public void onFinishTemporaryDetach() { |
| 5515 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5516 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5517 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5518 | * Return the global {@link KeyEvent.DispatcherState KeyEvent.DispatcherState} |
| 5519 | * for this view's window. Returns null if the view is not currently attached |
| 5520 | * 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] | 5521 | * just use the standard high-level event callbacks like |
| 5522 | * {@link #onKeyDown(int, KeyEvent)}. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5523 | */ |
| 5524 | public KeyEvent.DispatcherState getKeyDispatcherState() { |
| 5525 | return mAttachInfo != null ? mAttachInfo.mKeyDispatchState : null; |
| 5526 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 5527 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5528 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5529 | * Dispatch a key event before it is processed by any input method |
| 5530 | * associated with the view hierarchy. This can be used to intercept |
| 5531 | * key events in special situations before the IME consumes them; a |
| 5532 | * typical example would be handling the BACK key to update the application's |
| 5533 | * UI instead of allowing the IME to see it and close itself. |
| 5534 | * |
| 5535 | * @param event The key event to be dispatched. |
| 5536 | * @return True if the event was handled, false otherwise. |
| 5537 | */ |
| 5538 | public boolean dispatchKeyEventPreIme(KeyEvent event) { |
| 5539 | return onKeyPreIme(event.getKeyCode(), event); |
| 5540 | } |
| 5541 | |
| 5542 | /** |
| 5543 | * Dispatch a key event to the next view on the focus path. This path runs |
| 5544 | * from the top of the view tree down to the currently focused view. If this |
| 5545 | * view has focus, it will dispatch to itself. Otherwise it will dispatch |
| 5546 | * the next node down the focus path. This method also fires any key |
| 5547 | * listeners. |
| 5548 | * |
| 5549 | * @param event The key event to be dispatched. |
| 5550 | * @return True if the event was handled, false otherwise. |
| 5551 | */ |
| 5552 | public boolean dispatchKeyEvent(KeyEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5553 | if (mInputEventConsistencyVerifier != null) { |
| 5554 | mInputEventConsistencyVerifier.onKeyEvent(event, 0); |
| 5555 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5556 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5557 | // Give any attached key listener a first crack at the event. |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 5558 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 5559 | ListenerInfo li = mListenerInfo; |
| 5560 | if (li != null && li.mOnKeyListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5561 | && li.mOnKeyListener.onKey(this, event.getKeyCode(), event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5562 | return true; |
| 5563 | } |
| 5564 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5565 | if (event.dispatch(this, mAttachInfo != null |
| 5566 | ? mAttachInfo.mKeyDispatchState : null, this)) { |
| 5567 | return true; |
| 5568 | } |
| 5569 | |
| 5570 | if (mInputEventConsistencyVerifier != null) { |
| 5571 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 5572 | } |
| 5573 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5574 | } |
| 5575 | |
| 5576 | /** |
| 5577 | * Dispatches a key shortcut event. |
| 5578 | * |
| 5579 | * @param event The key event to be dispatched. |
| 5580 | * @return True if the event was handled by the view, false otherwise. |
| 5581 | */ |
| 5582 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 5583 | return onKeyShortcut(event.getKeyCode(), event); |
| 5584 | } |
| 5585 | |
| 5586 | /** |
| 5587 | * Pass the touch screen motion event down to the target view, or this |
| 5588 | * view if it is the target. |
| 5589 | * |
| 5590 | * @param event The motion event to be dispatched. |
| 5591 | * @return True if the event was handled by the view, false otherwise. |
| 5592 | */ |
| 5593 | public boolean dispatchTouchEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5594 | if (mInputEventConsistencyVerifier != null) { |
| 5595 | mInputEventConsistencyVerifier.onTouchEvent(event, 0); |
| 5596 | } |
| 5597 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5598 | if (onFilterTouchEventForSecurity(event)) { |
| 5599 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 5600 | ListenerInfo li = mListenerInfo; |
| 5601 | if (li != null && li.mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5602 | && li.mOnTouchListener.onTouch(this, event)) { |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5603 | return true; |
| 5604 | } |
| 5605 | |
| 5606 | if (onTouchEvent(event)) { |
| 5607 | return true; |
| 5608 | } |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5609 | } |
| 5610 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5611 | if (mInputEventConsistencyVerifier != null) { |
| 5612 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5613 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5614 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5615 | } |
| 5616 | |
| 5617 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5618 | * Filter the touch event to apply security policies. |
| 5619 | * |
| 5620 | * @param event The motion event to be filtered. |
| 5621 | * @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] | 5622 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5623 | * @see #getFilterTouchesWhenObscured |
| 5624 | */ |
| 5625 | public boolean onFilterTouchEventForSecurity(MotionEvent event) { |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 5626 | //noinspection RedundantIfStatement |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5627 | if ((mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0 |
| 5628 | && (event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) { |
| 5629 | // Window is obscured, drop this touch. |
| 5630 | return false; |
| 5631 | } |
| 5632 | return true; |
| 5633 | } |
| 5634 | |
| 5635 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5636 | * Pass a trackball motion event down to the focused view. |
| 5637 | * |
| 5638 | * @param event The motion event to be dispatched. |
| 5639 | * @return True if the event was handled by the view, false otherwise. |
| 5640 | */ |
| 5641 | public boolean dispatchTrackballEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5642 | if (mInputEventConsistencyVerifier != null) { |
| 5643 | mInputEventConsistencyVerifier.onTrackballEvent(event, 0); |
| 5644 | } |
| 5645 | |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 5646 | return onTrackballEvent(event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5647 | } |
| 5648 | |
| 5649 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5650 | * Dispatch a generic motion event. |
| 5651 | * <p> |
| 5652 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 5653 | * 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] | 5654 | * 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] | 5655 | * to {@link #onHoverEvent(MotionEvent)}. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5656 | * </p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5657 | * |
| 5658 | * @param event The motion event to be dispatched. |
| 5659 | * @return True if the event was handled by the view, false otherwise. |
| 5660 | */ |
| 5661 | public boolean dispatchGenericMotionEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5662 | if (mInputEventConsistencyVerifier != null) { |
| 5663 | mInputEventConsistencyVerifier.onGenericMotionEvent(event, 0); |
| 5664 | } |
| 5665 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5666 | final int source = event.getSource(); |
| 5667 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 5668 | final int action = event.getAction(); |
| 5669 | if (action == MotionEvent.ACTION_HOVER_ENTER |
| 5670 | || action == MotionEvent.ACTION_HOVER_MOVE |
| 5671 | || action == MotionEvent.ACTION_HOVER_EXIT) { |
| 5672 | if (dispatchHoverEvent(event)) { |
| 5673 | return true; |
| 5674 | } |
| 5675 | } else if (dispatchGenericPointerEvent(event)) { |
| 5676 | return true; |
| 5677 | } |
| 5678 | } else if (dispatchGenericFocusedEvent(event)) { |
| 5679 | return true; |
| 5680 | } |
| 5681 | |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 5682 | if (dispatchGenericMotionEventInternal(event)) { |
| 5683 | return true; |
| 5684 | } |
| 5685 | |
| 5686 | if (mInputEventConsistencyVerifier != null) { |
| 5687 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 5688 | } |
| 5689 | return false; |
| 5690 | } |
| 5691 | |
| 5692 | private boolean dispatchGenericMotionEventInternal(MotionEvent event) { |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 5693 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 5694 | ListenerInfo li = mListenerInfo; |
| 5695 | if (li != null && li.mOnGenericMotionListener != null |
| 5696 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5697 | && li.mOnGenericMotionListener.onGenericMotion(this, event)) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5698 | return true; |
| 5699 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5700 | |
| 5701 | if (onGenericMotionEvent(event)) { |
| 5702 | return true; |
| 5703 | } |
| 5704 | |
| 5705 | if (mInputEventConsistencyVerifier != null) { |
| 5706 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 5707 | } |
| 5708 | return false; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5709 | } |
| 5710 | |
| 5711 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5712 | * Dispatch a hover event. |
| 5713 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5714 | * Do not call this method directly. |
| 5715 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5716 | * </p> |
| 5717 | * |
| 5718 | * @param event The motion event to be dispatched. |
| 5719 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5720 | */ |
| 5721 | protected boolean dispatchHoverEvent(MotionEvent event) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 5722 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 5723 | ListenerInfo li = mListenerInfo; |
| 5724 | if (li != null && li.mOnHoverListener != null |
| 5725 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5726 | && li.mOnHoverListener.onHover(this, event)) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 5727 | return true; |
| 5728 | } |
| 5729 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5730 | return onHoverEvent(event); |
| 5731 | } |
| 5732 | |
| 5733 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 5734 | * Returns true if the view has a child to which it has recently sent |
| 5735 | * {@link MotionEvent#ACTION_HOVER_ENTER}. If this view is hovered and |
| 5736 | * it does not have a hovered child, then it must be the innermost hovered view. |
| 5737 | * @hide |
| 5738 | */ |
| 5739 | protected boolean hasHoveredChild() { |
| 5740 | return false; |
| 5741 | } |
| 5742 | |
| 5743 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5744 | * Dispatch a generic motion event to the view under the first pointer. |
| 5745 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5746 | * Do not call this method directly. |
| 5747 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5748 | * </p> |
| 5749 | * |
| 5750 | * @param event The motion event to be dispatched. |
| 5751 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5752 | */ |
| 5753 | protected boolean dispatchGenericPointerEvent(MotionEvent event) { |
| 5754 | return false; |
| 5755 | } |
| 5756 | |
| 5757 | /** |
| 5758 | * Dispatch a generic motion event to the currently focused view. |
| 5759 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5760 | * Do not call this method directly. |
| 5761 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5762 | * </p> |
| 5763 | * |
| 5764 | * @param event The motion event to be dispatched. |
| 5765 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5766 | */ |
| 5767 | protected boolean dispatchGenericFocusedEvent(MotionEvent event) { |
| 5768 | return false; |
| 5769 | } |
| 5770 | |
| 5771 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5772 | * Dispatch a pointer event. |
| 5773 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5774 | * Dispatches touch related pointer events to {@link #onTouchEvent(MotionEvent)} and all |
| 5775 | * other events to {@link #onGenericMotionEvent(MotionEvent)}. This separation of concerns |
| 5776 | * reinforces the invariant that {@link #onTouchEvent(MotionEvent)} is really about touches |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5777 | * and should not be expected to handle other pointing device features. |
| 5778 | * </p> |
| 5779 | * |
| 5780 | * @param event The motion event to be dispatched. |
| 5781 | * @return True if the event was handled by the view, false otherwise. |
| 5782 | * @hide |
| 5783 | */ |
| 5784 | public final boolean dispatchPointerEvent(MotionEvent event) { |
| 5785 | if (event.isTouchEvent()) { |
| 5786 | return dispatchTouchEvent(event); |
| 5787 | } else { |
| 5788 | return dispatchGenericMotionEvent(event); |
| 5789 | } |
| 5790 | } |
| 5791 | |
| 5792 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5793 | * Called when the window containing this view gains or loses window focus. |
| 5794 | * ViewGroups should override to route to their children. |
| 5795 | * |
| 5796 | * @param hasFocus True if the window containing this view now has focus, |
| 5797 | * false otherwise. |
| 5798 | */ |
| 5799 | public void dispatchWindowFocusChanged(boolean hasFocus) { |
| 5800 | onWindowFocusChanged(hasFocus); |
| 5801 | } |
| 5802 | |
| 5803 | /** |
| 5804 | * Called when the window containing this view gains or loses focus. Note |
| 5805 | * that this is separate from view focus: to receive key events, both |
| 5806 | * your view and its window must have focus. If a window is displayed |
| 5807 | * on top of yours that takes input focus, then your own window will lose |
| 5808 | * focus but the view focus will remain unchanged. |
| 5809 | * |
| 5810 | * @param hasWindowFocus True if the window containing this view now has |
| 5811 | * focus, false otherwise. |
| 5812 | */ |
| 5813 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 5814 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 5815 | if (!hasWindowFocus) { |
| 5816 | if (isPressed()) { |
| 5817 | setPressed(false); |
| 5818 | } |
| 5819 | if (imm != null && (mPrivateFlags & FOCUSED) != 0) { |
| 5820 | imm.focusOut(this); |
| 5821 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 5822 | removeLongPressCallback(); |
Tony Wu | 26edf20 | 2010-09-13 19:54:00 +0800 | [diff] [blame] | 5823 | removeTapCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 5824 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5825 | } else if (imm != null && (mPrivateFlags & FOCUSED) != 0) { |
| 5826 | imm.focusIn(this); |
| 5827 | } |
| 5828 | refreshDrawableState(); |
| 5829 | } |
| 5830 | |
| 5831 | /** |
| 5832 | * Returns true if this view is in a window that currently has window focus. |
| 5833 | * Note that this is not the same as the view itself having focus. |
| 5834 | * |
| 5835 | * @return True if this view is in a window that currently has window focus. |
| 5836 | */ |
| 5837 | public boolean hasWindowFocus() { |
| 5838 | return mAttachInfo != null && mAttachInfo.mHasWindowFocus; |
| 5839 | } |
| 5840 | |
| 5841 | /** |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 5842 | * Dispatch a view visibility change down the view hierarchy. |
| 5843 | * ViewGroups should override to route to their children. |
| 5844 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 5845 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 5846 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 5847 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 5848 | */ |
| 5849 | protected void dispatchVisibilityChanged(View changedView, int visibility) { |
| 5850 | onVisibilityChanged(changedView, visibility); |
| 5851 | } |
| 5852 | |
| 5853 | /** |
| 5854 | * Called when the visibility of the view or an ancestor of the view is changed. |
| 5855 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 5856 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 5857 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 5858 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 5859 | */ |
| 5860 | protected void onVisibilityChanged(View changedView, int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 5861 | if (visibility == VISIBLE) { |
| 5862 | if (mAttachInfo != null) { |
| 5863 | initialAwakenScrollBars(); |
| 5864 | } else { |
| 5865 | mPrivateFlags |= AWAKEN_SCROLL_BARS_ON_ATTACH; |
| 5866 | } |
| 5867 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 5868 | } |
| 5869 | |
| 5870 | /** |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 5871 | * Dispatch a hint about whether this view is displayed. For instance, when |
| 5872 | * a View moves out of the screen, it might receives a display hint indicating |
| 5873 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 5874 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 5875 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 5876 | * @param hint A hint about whether or not this view is displayed: |
| 5877 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 5878 | */ |
| 5879 | public void dispatchDisplayHint(int hint) { |
| 5880 | onDisplayHint(hint); |
| 5881 | } |
| 5882 | |
| 5883 | /** |
| 5884 | * Gives this view a hint about whether is displayed or not. For instance, when |
| 5885 | * a View moves out of the screen, it might receives a display hint indicating |
| 5886 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 5887 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 5888 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 5889 | * @param hint A hint about whether or not this view is displayed: |
| 5890 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 5891 | */ |
| 5892 | protected void onDisplayHint(int hint) { |
| 5893 | } |
| 5894 | |
| 5895 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5896 | * Dispatch a window visibility change down the view hierarchy. |
| 5897 | * ViewGroups should override to route to their children. |
| 5898 | * |
| 5899 | * @param visibility The new visibility of the window. |
| 5900 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5901 | * @see #onWindowVisibilityChanged(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5902 | */ |
| 5903 | public void dispatchWindowVisibilityChanged(int visibility) { |
| 5904 | onWindowVisibilityChanged(visibility); |
| 5905 | } |
| 5906 | |
| 5907 | /** |
| 5908 | * Called when the window containing has change its visibility |
| 5909 | * (between {@link #GONE}, {@link #INVISIBLE}, and {@link #VISIBLE}). Note |
| 5910 | * that this tells you whether or not your window is being made visible |
| 5911 | * to the window manager; this does <em>not</em> tell you whether or not |
| 5912 | * your window is obscured by other windows on the screen, even if it |
| 5913 | * is itself visible. |
| 5914 | * |
| 5915 | * @param visibility The new visibility of the window. |
| 5916 | */ |
| 5917 | protected void onWindowVisibilityChanged(int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 5918 | if (visibility == VISIBLE) { |
| 5919 | initialAwakenScrollBars(); |
| 5920 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5921 | } |
| 5922 | |
| 5923 | /** |
| 5924 | * Returns the current visibility of the window this view is attached to |
| 5925 | * (either {@link #GONE}, {@link #INVISIBLE}, or {@link #VISIBLE}). |
| 5926 | * |
| 5927 | * @return Returns the current visibility of the view's window. |
| 5928 | */ |
| 5929 | public int getWindowVisibility() { |
| 5930 | return mAttachInfo != null ? mAttachInfo.mWindowVisibility : GONE; |
| 5931 | } |
| 5932 | |
| 5933 | /** |
| 5934 | * Retrieve the overall visible display size in which the window this view is |
| 5935 | * attached to has been positioned in. This takes into account screen |
| 5936 | * decorations above the window, for both cases where the window itself |
| 5937 | * is being position inside of them or the window is being placed under |
| 5938 | * then and covered insets are used for the window to position its content |
| 5939 | * inside. In effect, this tells you the available area where content can |
| 5940 | * be placed and remain visible to users. |
| 5941 | * |
| 5942 | * <p>This function requires an IPC back to the window manager to retrieve |
| 5943 | * the requested information, so should not be used in performance critical |
| 5944 | * code like drawing. |
| 5945 | * |
| 5946 | * @param outRect Filled in with the visible display frame. If the view |
| 5947 | * is not attached to a window, this is simply the raw display size. |
| 5948 | */ |
| 5949 | public void getWindowVisibleDisplayFrame(Rect outRect) { |
| 5950 | if (mAttachInfo != null) { |
| 5951 | try { |
| 5952 | mAttachInfo.mSession.getDisplayFrame(mAttachInfo.mWindow, outRect); |
| 5953 | } catch (RemoteException e) { |
| 5954 | return; |
| 5955 | } |
| 5956 | // XXX This is really broken, and probably all needs to be done |
| 5957 | // in the window manager, and we need to know more about whether |
| 5958 | // we want the area behind or in front of the IME. |
| 5959 | final Rect insets = mAttachInfo.mVisibleInsets; |
| 5960 | outRect.left += insets.left; |
| 5961 | outRect.top += insets.top; |
| 5962 | outRect.right -= insets.right; |
| 5963 | outRect.bottom -= insets.bottom; |
| 5964 | return; |
| 5965 | } |
| 5966 | Display d = WindowManagerImpl.getDefault().getDefaultDisplay(); |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 5967 | d.getRectSize(outRect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5968 | } |
| 5969 | |
| 5970 | /** |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5971 | * Dispatch a notification about a resource configuration change down |
| 5972 | * the view hierarchy. |
| 5973 | * ViewGroups should override to route to their children. |
| 5974 | * |
| 5975 | * @param newConfig The new resource configuration. |
| 5976 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5977 | * @see #onConfigurationChanged(android.content.res.Configuration) |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5978 | */ |
| 5979 | public void dispatchConfigurationChanged(Configuration newConfig) { |
| 5980 | onConfigurationChanged(newConfig); |
| 5981 | } |
| 5982 | |
| 5983 | /** |
| 5984 | * Called when the current configuration of the resources being used |
| 5985 | * by the application have changed. You can use this to decide when |
| 5986 | * to reload resources that can changed based on orientation and other |
| 5987 | * configuration characterstics. You only need to use this if you are |
| 5988 | * not relying on the normal {@link android.app.Activity} mechanism of |
| 5989 | * recreating the activity instance upon a configuration change. |
| 5990 | * |
| 5991 | * @param newConfig The new resource configuration. |
| 5992 | */ |
| 5993 | protected void onConfigurationChanged(Configuration newConfig) { |
| 5994 | } |
| 5995 | |
| 5996 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5997 | * Private function to aggregate all per-view attributes in to the view |
| 5998 | * root. |
| 5999 | */ |
| 6000 | void dispatchCollectViewAttributes(int visibility) { |
| 6001 | performCollectViewAttributes(visibility); |
| 6002 | } |
| 6003 | |
| 6004 | void performCollectViewAttributes(int visibility) { |
Romain Guy | d30b36d | 2011-01-26 10:54:43 -0800 | [diff] [blame] | 6005 | if ((visibility & VISIBILITY_MASK) == VISIBLE && mAttachInfo != null) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6006 | if ((mViewFlags & KEEP_SCREEN_ON) == KEEP_SCREEN_ON) { |
| 6007 | mAttachInfo.mKeepScreenOn = true; |
| 6008 | } |
| 6009 | mAttachInfo.mSystemUiVisibility |= mSystemUiVisibility; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6010 | ListenerInfo li = mListenerInfo; |
| 6011 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6012 | mAttachInfo.mHasSystemUiListeners = true; |
| 6013 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6014 | } |
| 6015 | } |
| 6016 | |
| 6017 | void needGlobalAttributesUpdate(boolean force) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6018 | final AttachInfo ai = mAttachInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6019 | if (ai != null) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6020 | if (force || ai.mKeepScreenOn || (ai.mSystemUiVisibility != 0) |
| 6021 | || ai.mHasSystemUiListeners) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6022 | ai.mRecomputeGlobalAttributes = true; |
| 6023 | } |
| 6024 | } |
| 6025 | } |
| 6026 | |
| 6027 | /** |
| 6028 | * Returns whether the device is currently in touch mode. Touch mode is entered |
| 6029 | * once the user begins interacting with the device by touch, and affects various |
| 6030 | * things like whether focus is always visible to the user. |
| 6031 | * |
| 6032 | * @return Whether the device is in touch mode. |
| 6033 | */ |
| 6034 | @ViewDebug.ExportedProperty |
| 6035 | public boolean isInTouchMode() { |
| 6036 | if (mAttachInfo != null) { |
| 6037 | return mAttachInfo.mInTouchMode; |
| 6038 | } else { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6039 | return ViewRootImpl.isInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6040 | } |
| 6041 | } |
| 6042 | |
| 6043 | /** |
| 6044 | * Returns the context the view is running in, through which it can |
| 6045 | * access the current theme, resources, etc. |
| 6046 | * |
| 6047 | * @return The view's Context. |
| 6048 | */ |
| 6049 | @ViewDebug.CapturedViewProperty |
| 6050 | public final Context getContext() { |
| 6051 | return mContext; |
| 6052 | } |
| 6053 | |
| 6054 | /** |
| 6055 | * Handle a key event before it is processed by any input method |
| 6056 | * associated with the view hierarchy. This can be used to intercept |
| 6057 | * key events in special situations before the IME consumes them; a |
| 6058 | * typical example would be handling the BACK key to update the application's |
| 6059 | * UI instead of allowing the IME to see it and close itself. |
| 6060 | * |
| 6061 | * @param keyCode The value in event.getKeyCode(). |
| 6062 | * @param event Description of the key event. |
| 6063 | * @return If you handled the event, return true. If you want to allow the |
| 6064 | * event to be handled by the next receiver, return false. |
| 6065 | */ |
| 6066 | public boolean onKeyPreIme(int keyCode, KeyEvent event) { |
| 6067 | return false; |
| 6068 | } |
| 6069 | |
| 6070 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 6071 | * Default implementation of {@link KeyEvent.Callback#onKeyDown(int, KeyEvent) |
| 6072 | * KeyEvent.Callback.onKeyDown()}: perform press of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6073 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or {@link KeyEvent#KEYCODE_ENTER} |
| 6074 | * is released, if the view is enabled and clickable. |
| 6075 | * |
| 6076 | * @param keyCode A key code that represents the button pressed, from |
| 6077 | * {@link android.view.KeyEvent}. |
| 6078 | * @param event The KeyEvent object that defines the button action. |
| 6079 | */ |
| 6080 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 6081 | boolean result = false; |
| 6082 | |
| 6083 | switch (keyCode) { |
| 6084 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 6085 | case KeyEvent.KEYCODE_ENTER: { |
| 6086 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 6087 | return true; |
| 6088 | } |
| 6089 | // Long clickable items don't necessarily have to be clickable |
| 6090 | if (((mViewFlags & CLICKABLE) == CLICKABLE || |
| 6091 | (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) && |
| 6092 | (event.getRepeatCount() == 0)) { |
| 6093 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6094 | checkForLongClick(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6095 | return true; |
| 6096 | } |
| 6097 | break; |
| 6098 | } |
| 6099 | } |
| 6100 | return result; |
| 6101 | } |
| 6102 | |
| 6103 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6104 | * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
| 6105 | * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle |
| 6106 | * the event). |
| 6107 | */ |
| 6108 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 6109 | return false; |
| 6110 | } |
| 6111 | |
| 6112 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 6113 | * Default implementation of {@link KeyEvent.Callback#onKeyUp(int, KeyEvent) |
| 6114 | * KeyEvent.Callback.onKeyUp()}: perform clicking of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6115 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or |
| 6116 | * {@link KeyEvent#KEYCODE_ENTER} is released. |
| 6117 | * |
| 6118 | * @param keyCode A key code that represents the button pressed, from |
| 6119 | * {@link android.view.KeyEvent}. |
| 6120 | * @param event The KeyEvent object that defines the button action. |
| 6121 | */ |
| 6122 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 6123 | boolean result = false; |
| 6124 | |
| 6125 | switch (keyCode) { |
| 6126 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 6127 | case KeyEvent.KEYCODE_ENTER: { |
| 6128 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 6129 | return true; |
| 6130 | } |
| 6131 | if ((mViewFlags & CLICKABLE) == CLICKABLE && isPressed()) { |
| 6132 | setPressed(false); |
| 6133 | |
| 6134 | if (!mHasPerformedLongPress) { |
| 6135 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6136 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6137 | |
| 6138 | result = performClick(); |
| 6139 | } |
| 6140 | } |
| 6141 | break; |
| 6142 | } |
| 6143 | } |
| 6144 | return result; |
| 6145 | } |
| 6146 | |
| 6147 | /** |
| 6148 | * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) |
| 6149 | * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle |
| 6150 | * the event). |
| 6151 | * |
| 6152 | * @param keyCode A key code that represents the button pressed, from |
| 6153 | * {@link android.view.KeyEvent}. |
| 6154 | * @param repeatCount The number of times the action was made. |
| 6155 | * @param event The KeyEvent object that defines the button action. |
| 6156 | */ |
| 6157 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 6158 | return false; |
| 6159 | } |
| 6160 | |
| 6161 | /** |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 6162 | * Called on the focused view when a key shortcut event is not handled. |
| 6163 | * Override this method to implement local key shortcuts for the View. |
| 6164 | * Key shortcuts can also be implemented by setting the |
| 6165 | * {@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] | 6166 | * |
| 6167 | * @param keyCode The value in event.getKeyCode(). |
| 6168 | * @param event Description of the key event. |
| 6169 | * @return If you handled the event, return true. If you want to allow the |
| 6170 | * event to be handled by the next receiver, return false. |
| 6171 | */ |
| 6172 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
| 6173 | return false; |
| 6174 | } |
| 6175 | |
| 6176 | /** |
| 6177 | * Check whether the called view is a text editor, in which case it |
| 6178 | * would make sense to automatically display a soft input window for |
| 6179 | * it. Subclasses should override this if they implement |
| 6180 | * {@link #onCreateInputConnection(EditorInfo)} to return true if |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 6181 | * a call on that method would return a non-null InputConnection, and |
| 6182 | * they are really a first-class editor that the user would normally |
| 6183 | * start typing on when the go into a window containing your view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6184 | * |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 6185 | * <p>The default implementation always returns false. This does |
| 6186 | * <em>not</em> mean that its {@link #onCreateInputConnection(EditorInfo)} |
| 6187 | * will not be called or the user can not otherwise perform edits on your |
| 6188 | * view; it is just a hint to the system that this is not the primary |
| 6189 | * purpose of this view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6190 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6191 | * @return Returns true if this view is a text editor, else false. |
| 6192 | */ |
| 6193 | public boolean onCheckIsTextEditor() { |
| 6194 | return false; |
| 6195 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6196 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6197 | /** |
| 6198 | * Create a new InputConnection for an InputMethod to interact |
| 6199 | * with the view. The default implementation returns null, since it doesn't |
| 6200 | * support input methods. You can override this to implement such support. |
| 6201 | * This is only needed for views that take focus and text input. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6202 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6203 | * <p>When implementing this, you probably also want to implement |
| 6204 | * {@link #onCheckIsTextEditor()} to indicate you will return a |
| 6205 | * non-null InputConnection. |
| 6206 | * |
| 6207 | * @param outAttrs Fill in with attribute information about the connection. |
| 6208 | */ |
| 6209 | public InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
| 6210 | return null; |
| 6211 | } |
| 6212 | |
| 6213 | /** |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 6214 | * Called by the {@link android.view.inputmethod.InputMethodManager} |
| 6215 | * when a view who is not the current |
| 6216 | * input connection target is trying to make a call on the manager. The |
| 6217 | * default implementation returns false; you can override this to return |
| 6218 | * true for certain views if you are performing InputConnection proxying |
| 6219 | * to them. |
| 6220 | * @param view The View that is making the InputMethodManager call. |
| 6221 | * @return Return true to allow the call, false to reject. |
| 6222 | */ |
| 6223 | public boolean checkInputConnectionProxy(View view) { |
| 6224 | return false; |
| 6225 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6226 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 6227 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6228 | * Show the context menu for this view. It is not safe to hold on to the |
| 6229 | * menu after returning from this method. |
| 6230 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 6231 | * You should normally not overload this method. Overload |
| 6232 | * {@link #onCreateContextMenu(ContextMenu)} or define an |
| 6233 | * {@link OnCreateContextMenuListener} to add items to the context menu. |
| 6234 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6235 | * @param menu The context menu to populate |
| 6236 | */ |
| 6237 | public void createContextMenu(ContextMenu menu) { |
| 6238 | ContextMenuInfo menuInfo = getContextMenuInfo(); |
| 6239 | |
| 6240 | // Sets the current menu info so all items added to menu will have |
| 6241 | // my extra info set. |
| 6242 | ((MenuBuilder)menu).setCurrentMenuInfo(menuInfo); |
| 6243 | |
| 6244 | onCreateContextMenu(menu); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6245 | ListenerInfo li = mListenerInfo; |
| 6246 | if (li != null && li.mOnCreateContextMenuListener != null) { |
| 6247 | li.mOnCreateContextMenuListener.onCreateContextMenu(menu, this, menuInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6248 | } |
| 6249 | |
| 6250 | // Clear the extra information so subsequent items that aren't mine don't |
| 6251 | // have my extra info. |
| 6252 | ((MenuBuilder)menu).setCurrentMenuInfo(null); |
| 6253 | |
| 6254 | if (mParent != null) { |
| 6255 | mParent.createContextMenu(menu); |
| 6256 | } |
| 6257 | } |
| 6258 | |
| 6259 | /** |
| 6260 | * Views should implement this if they have extra information to associate |
| 6261 | * with the context menu. The return result is supplied as a parameter to |
| 6262 | * the {@link OnCreateContextMenuListener#onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} |
| 6263 | * callback. |
| 6264 | * |
| 6265 | * @return Extra information about the item for which the context menu |
| 6266 | * should be shown. This information will vary across different |
| 6267 | * subclasses of View. |
| 6268 | */ |
| 6269 | protected ContextMenuInfo getContextMenuInfo() { |
| 6270 | return null; |
| 6271 | } |
| 6272 | |
| 6273 | /** |
| 6274 | * Views should implement this if the view itself is going to add items to |
| 6275 | * the context menu. |
| 6276 | * |
| 6277 | * @param menu the context menu to populate |
| 6278 | */ |
| 6279 | protected void onCreateContextMenu(ContextMenu menu) { |
| 6280 | } |
| 6281 | |
| 6282 | /** |
| 6283 | * Implement this method to handle trackball motion events. The |
| 6284 | * <em>relative</em> movement of the trackball since the last event |
| 6285 | * can be retrieve with {@link MotionEvent#getX MotionEvent.getX()} and |
| 6286 | * {@link MotionEvent#getY MotionEvent.getY()}. These are normalized so |
| 6287 | * that a movement of 1 corresponds to the user pressing one DPAD key (so |
| 6288 | * they will often be fractional values, representing the more fine-grained |
| 6289 | * movement information available from a trackball). |
| 6290 | * |
| 6291 | * @param event The motion event. |
| 6292 | * @return True if the event was handled, false otherwise. |
| 6293 | */ |
| 6294 | public boolean onTrackballEvent(MotionEvent event) { |
| 6295 | return false; |
| 6296 | } |
| 6297 | |
| 6298 | /** |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6299 | * Implement this method to handle generic motion events. |
| 6300 | * <p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6301 | * Generic motion events describe joystick movements, mouse hovers, track pad |
| 6302 | * touches, scroll wheel movements and other input events. The |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6303 | * {@link MotionEvent#getSource() source} of the motion event specifies |
| 6304 | * the class of input that was received. Implementations of this method |
| 6305 | * must examine the bits in the source before processing the event. |
| 6306 | * The following code example shows how this is done. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6307 | * </p><p> |
| 6308 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 6309 | * are delivered to the view under the pointer. All other generic motion events are |
| 6310 | * delivered to the focused view. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6311 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 6312 | * <pre> public boolean onGenericMotionEvent(MotionEvent event) { |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6313 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6314 | * if (event.getAction() == MotionEvent.ACTION_MOVE) { |
| 6315 | * // process the joystick movement... |
| 6316 | * return true; |
| 6317 | * } |
| 6318 | * } |
| 6319 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 6320 | * switch (event.getAction()) { |
| 6321 | * case MotionEvent.ACTION_HOVER_MOVE: |
| 6322 | * // process the mouse hover movement... |
| 6323 | * return true; |
| 6324 | * case MotionEvent.ACTION_SCROLL: |
| 6325 | * // process the scroll wheel movement... |
| 6326 | * return true; |
| 6327 | * } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6328 | * } |
| 6329 | * return super.onGenericMotionEvent(event); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 6330 | * }</pre> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6331 | * |
| 6332 | * @param event The generic motion event being processed. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6333 | * @return True if the event was handled, false otherwise. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6334 | */ |
| 6335 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 6336 | return false; |
| 6337 | } |
| 6338 | |
| 6339 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6340 | * Implement this method to handle hover events. |
| 6341 | * <p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6342 | * This method is called whenever a pointer is hovering into, over, or out of the |
| 6343 | * bounds of a view and the view is not currently being touched. |
| 6344 | * Hover events are represented as pointer events with action |
| 6345 | * {@link MotionEvent#ACTION_HOVER_ENTER}, {@link MotionEvent#ACTION_HOVER_MOVE}, |
| 6346 | * or {@link MotionEvent#ACTION_HOVER_EXIT}. |
| 6347 | * </p> |
| 6348 | * <ul> |
| 6349 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_ENTER} |
| 6350 | * when the pointer enters the bounds of the view.</li> |
| 6351 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_MOVE} |
| 6352 | * when the pointer has already entered the bounds of the view and has moved.</li> |
| 6353 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_EXIT} |
| 6354 | * when the pointer has exited the bounds of the view or when the pointer is |
| 6355 | * about to go down due to a button click, tap, or similar user action that |
| 6356 | * causes the view to be touched.</li> |
| 6357 | * </ul> |
| 6358 | * <p> |
| 6359 | * The view should implement this method to return true to indicate that it is |
| 6360 | * handling the hover event, such as by changing its drawable state. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6361 | * </p><p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6362 | * The default implementation calls {@link #setHovered} to update the hovered state |
| 6363 | * 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] | 6364 | * is enabled and is clickable. The default implementation also sends hover |
| 6365 | * accessibility events. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6366 | * </p> |
| 6367 | * |
| 6368 | * @param event The motion event that describes the hover. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6369 | * @return True if the view handled the hover event. |
| 6370 | * |
| 6371 | * @see #isHovered |
| 6372 | * @see #setHovered |
| 6373 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6374 | */ |
| 6375 | public boolean onHoverEvent(MotionEvent event) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 6376 | // The root view may receive hover (or touch) events that are outside the bounds of |
| 6377 | // the window. This code ensures that we only send accessibility events for |
| 6378 | // hovers that are actually within the bounds of the root view. |
| 6379 | final int action = event.getAction(); |
| 6380 | if (!mSendingHoverAccessibilityEvents) { |
| 6381 | if ((action == MotionEvent.ACTION_HOVER_ENTER |
| 6382 | || action == MotionEvent.ACTION_HOVER_MOVE) |
| 6383 | && !hasHoveredChild() |
| 6384 | && pointInView(event.getX(), event.getY())) { |
| 6385 | mSendingHoverAccessibilityEvents = true; |
| 6386 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER); |
| 6387 | } |
| 6388 | } else { |
| 6389 | if (action == MotionEvent.ACTION_HOVER_EXIT |
| 6390 | || (action == MotionEvent.ACTION_HOVER_MOVE |
| 6391 | && !pointInView(event.getX(), event.getY()))) { |
| 6392 | mSendingHoverAccessibilityEvents = false; |
| 6393 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT); |
| 6394 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 6395 | } |
| 6396 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6397 | if (isHoverable()) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 6398 | switch (action) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6399 | case MotionEvent.ACTION_HOVER_ENTER: |
| 6400 | setHovered(true); |
| 6401 | break; |
| 6402 | case MotionEvent.ACTION_HOVER_EXIT: |
| 6403 | setHovered(false); |
| 6404 | break; |
| 6405 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 6406 | |
| 6407 | // Dispatch the event to onGenericMotionEvent before returning true. |
| 6408 | // This is to provide compatibility with existing applications that |
| 6409 | // handled HOVER_MOVE events in onGenericMotionEvent and that would |
| 6410 | // break because of the new default handling for hoverable views |
| 6411 | // in onHoverEvent. |
| 6412 | // Note that onGenericMotionEvent will be called by default when |
| 6413 | // onHoverEvent returns false (refer to dispatchGenericMotionEvent). |
| 6414 | dispatchGenericMotionEventInternal(event); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6415 | return true; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6416 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6417 | return false; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6418 | } |
| 6419 | |
| 6420 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6421 | * Returns true if the view should handle {@link #onHoverEvent} |
| 6422 | * by calling {@link #setHovered} to change its hovered state. |
| 6423 | * |
| 6424 | * @return True if the view is hoverable. |
| 6425 | */ |
| 6426 | private boolean isHoverable() { |
| 6427 | final int viewFlags = mViewFlags; |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 6428 | //noinspection SimplifiableIfStatement |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6429 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
| 6430 | return false; |
| 6431 | } |
| 6432 | |
| 6433 | return (viewFlags & CLICKABLE) == CLICKABLE |
| 6434 | || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 6435 | } |
| 6436 | |
| 6437 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6438 | * Returns true if the view is currently hovered. |
| 6439 | * |
| 6440 | * @return True if the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6441 | * |
| 6442 | * @see #setHovered |
| 6443 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6444 | */ |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6445 | @ViewDebug.ExportedProperty |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6446 | public boolean isHovered() { |
| 6447 | return (mPrivateFlags & HOVERED) != 0; |
| 6448 | } |
| 6449 | |
| 6450 | /** |
| 6451 | * Sets whether the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6452 | * <p> |
| 6453 | * Calling this method also changes the drawable state of the view. This |
| 6454 | * enables the view to react to hover by using different drawable resources |
| 6455 | * to change its appearance. |
| 6456 | * </p><p> |
| 6457 | * The {@link #onHoverChanged} method is called when the hovered state changes. |
| 6458 | * </p> |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6459 | * |
| 6460 | * @param hovered True if the view is hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6461 | * |
| 6462 | * @see #isHovered |
| 6463 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6464 | */ |
| 6465 | public void setHovered(boolean hovered) { |
| 6466 | if (hovered) { |
| 6467 | if ((mPrivateFlags & HOVERED) == 0) { |
| 6468 | mPrivateFlags |= HOVERED; |
| 6469 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6470 | onHoverChanged(true); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6471 | } |
| 6472 | } else { |
| 6473 | if ((mPrivateFlags & HOVERED) != 0) { |
| 6474 | mPrivateFlags &= ~HOVERED; |
| 6475 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6476 | onHoverChanged(false); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6477 | } |
| 6478 | } |
| 6479 | } |
| 6480 | |
| 6481 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6482 | * Implement this method to handle hover state changes. |
| 6483 | * <p> |
| 6484 | * This method is called whenever the hover state changes as a result of a |
| 6485 | * call to {@link #setHovered}. |
| 6486 | * </p> |
| 6487 | * |
| 6488 | * @param hovered The current hover state, as returned by {@link #isHovered}. |
| 6489 | * |
| 6490 | * @see #isHovered |
| 6491 | * @see #setHovered |
| 6492 | */ |
| 6493 | public void onHoverChanged(boolean hovered) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6494 | } |
| 6495 | |
| 6496 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6497 | * Implement this method to handle touch screen motion events. |
| 6498 | * |
| 6499 | * @param event The motion event. |
| 6500 | * @return True if the event was handled, false otherwise. |
| 6501 | */ |
| 6502 | public boolean onTouchEvent(MotionEvent event) { |
| 6503 | final int viewFlags = mViewFlags; |
| 6504 | |
| 6505 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
Svetoslav Ganov | 77b80c0 | 2011-03-15 20:52:58 -0700 | [diff] [blame] | 6506 | if (event.getAction() == MotionEvent.ACTION_UP && (mPrivateFlags & PRESSED) != 0) { |
| 6507 | mPrivateFlags &= ~PRESSED; |
| 6508 | refreshDrawableState(); |
| 6509 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6510 | // A disabled view that is clickable still consumes the touch |
| 6511 | // events, it just doesn't respond to them. |
| 6512 | return (((viewFlags & CLICKABLE) == CLICKABLE || |
| 6513 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)); |
| 6514 | } |
| 6515 | |
| 6516 | if (mTouchDelegate != null) { |
| 6517 | if (mTouchDelegate.onTouchEvent(event)) { |
| 6518 | return true; |
| 6519 | } |
| 6520 | } |
| 6521 | |
| 6522 | if (((viewFlags & CLICKABLE) == CLICKABLE || |
| 6523 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)) { |
| 6524 | switch (event.getAction()) { |
| 6525 | case MotionEvent.ACTION_UP: |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6526 | boolean prepressed = (mPrivateFlags & PREPRESSED) != 0; |
| 6527 | if ((mPrivateFlags & PRESSED) != 0 || prepressed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6528 | // take focus if we don't have it already and we should in |
| 6529 | // touch mode. |
| 6530 | boolean focusTaken = false; |
| 6531 | if (isFocusable() && isFocusableInTouchMode() && !isFocused()) { |
| 6532 | focusTaken = requestFocus(); |
| 6533 | } |
| 6534 | |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 6535 | if (prepressed) { |
| 6536 | // The button is being released before we actually |
| 6537 | // showed it as pressed. Make it show the pressed |
| 6538 | // state now (before scheduling the click) to ensure |
| 6539 | // the user sees it. |
| 6540 | mPrivateFlags |= PRESSED; |
| 6541 | refreshDrawableState(); |
| 6542 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6543 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6544 | if (!mHasPerformedLongPress) { |
| 6545 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6546 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6547 | |
| 6548 | // Only perform take click actions if we were in the pressed state |
| 6549 | if (!focusTaken) { |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 6550 | // Use a Runnable and post this rather than calling |
| 6551 | // performClick directly. This lets other visual state |
| 6552 | // of the view update before click actions start. |
| 6553 | if (mPerformClick == null) { |
| 6554 | mPerformClick = new PerformClick(); |
| 6555 | } |
| 6556 | if (!post(mPerformClick)) { |
| 6557 | performClick(); |
| 6558 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6559 | } |
| 6560 | } |
| 6561 | |
| 6562 | if (mUnsetPressedState == null) { |
| 6563 | mUnsetPressedState = new UnsetPressedState(); |
| 6564 | } |
| 6565 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6566 | if (prepressed) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6567 | postDelayed(mUnsetPressedState, |
| 6568 | ViewConfiguration.getPressedStateDuration()); |
| 6569 | } else if (!post(mUnsetPressedState)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6570 | // If the post failed, unpress right now |
| 6571 | mUnsetPressedState.run(); |
| 6572 | } |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6573 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6574 | } |
| 6575 | break; |
| 6576 | |
| 6577 | case MotionEvent.ACTION_DOWN: |
Adam Powell | 3b02339 | 2010-03-11 16:30:28 -0800 | [diff] [blame] | 6578 | mHasPerformedLongPress = false; |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6579 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 6580 | if (performButtonActionOnTouchDown(event)) { |
| 6581 | break; |
| 6582 | } |
| 6583 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6584 | // 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] | 6585 | boolean isInScrollingContainer = isInScrollingContainer(); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6586 | |
| 6587 | // For views inside a scrolling container, delay the pressed feedback for |
| 6588 | // a short period in case this is a scroll. |
| 6589 | if (isInScrollingContainer) { |
| 6590 | mPrivateFlags |= PREPRESSED; |
| 6591 | if (mPendingCheckForTap == null) { |
| 6592 | mPendingCheckForTap = new CheckForTap(); |
| 6593 | } |
| 6594 | postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); |
| 6595 | } else { |
| 6596 | // Not inside a scrolling container, so show the feedback right away |
| 6597 | mPrivateFlags |= PRESSED; |
| 6598 | refreshDrawableState(); |
| 6599 | checkForLongClick(0); |
| 6600 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6601 | break; |
| 6602 | |
| 6603 | case MotionEvent.ACTION_CANCEL: |
| 6604 | mPrivateFlags &= ~PRESSED; |
| 6605 | refreshDrawableState(); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6606 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6607 | break; |
| 6608 | |
| 6609 | case MotionEvent.ACTION_MOVE: |
| 6610 | final int x = (int) event.getX(); |
| 6611 | final int y = (int) event.getY(); |
| 6612 | |
| 6613 | // Be lenient about moving outside of buttons |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6614 | if (!pointInView(x, y, mTouchSlop)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6615 | // Outside button |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6616 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6617 | if ((mPrivateFlags & PRESSED) != 0) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6618 | // Remove any future long press/tap checks |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6619 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6620 | |
| 6621 | // Need to switch from pressed to not pressed |
| 6622 | mPrivateFlags &= ~PRESSED; |
| 6623 | refreshDrawableState(); |
| 6624 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6625 | } |
| 6626 | break; |
| 6627 | } |
| 6628 | return true; |
| 6629 | } |
| 6630 | |
| 6631 | return false; |
| 6632 | } |
| 6633 | |
| 6634 | /** |
Adam Powell | 1029866 | 2011-08-14 18:26:30 -0700 | [diff] [blame] | 6635 | * @hide |
| 6636 | */ |
| 6637 | public boolean isInScrollingContainer() { |
| 6638 | ViewParent p = getParent(); |
| 6639 | while (p != null && p instanceof ViewGroup) { |
| 6640 | if (((ViewGroup) p).shouldDelayChildPressedState()) { |
| 6641 | return true; |
| 6642 | } |
| 6643 | p = p.getParent(); |
| 6644 | } |
| 6645 | return false; |
| 6646 | } |
| 6647 | |
| 6648 | /** |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6649 | * Remove the longpress detection timer. |
| 6650 | */ |
| 6651 | private void removeLongPressCallback() { |
| 6652 | if (mPendingCheckForLongPress != null) { |
| 6653 | removeCallbacks(mPendingCheckForLongPress); |
| 6654 | } |
| 6655 | } |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 6656 | |
| 6657 | /** |
| 6658 | * Remove the pending click action |
| 6659 | */ |
| 6660 | private void removePerformClickCallback() { |
| 6661 | if (mPerformClick != null) { |
| 6662 | removeCallbacks(mPerformClick); |
| 6663 | } |
| 6664 | } |
| 6665 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6666 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6667 | * Remove the prepress detection timer. |
| 6668 | */ |
| 6669 | private void removeUnsetPressCallback() { |
| 6670 | if ((mPrivateFlags & PRESSED) != 0 && mUnsetPressedState != null) { |
| 6671 | setPressed(false); |
| 6672 | removeCallbacks(mUnsetPressedState); |
| 6673 | } |
| 6674 | } |
| 6675 | |
| 6676 | /** |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6677 | * Remove the tap detection timer. |
| 6678 | */ |
| 6679 | private void removeTapCallback() { |
| 6680 | if (mPendingCheckForTap != null) { |
| 6681 | mPrivateFlags &= ~PREPRESSED; |
| 6682 | removeCallbacks(mPendingCheckForTap); |
| 6683 | } |
| 6684 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6685 | |
| 6686 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6687 | * Cancels a pending long press. Your subclass can use this if you |
| 6688 | * want the context menu to come up if the user presses and holds |
| 6689 | * at the same place, but you don't want it to come up if they press |
| 6690 | * and then move around enough to cause scrolling. |
| 6691 | */ |
| 6692 | public void cancelLongPress() { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6693 | removeLongPressCallback(); |
Adam Powell | 732ebb1 | 2010-02-02 15:28:14 -0800 | [diff] [blame] | 6694 | |
| 6695 | /* |
| 6696 | * The prepressed state handled by the tap callback is a display |
| 6697 | * construct, but the tap callback will post a long press callback |
| 6698 | * less its own timeout. Remove it here. |
| 6699 | */ |
| 6700 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6701 | } |
| 6702 | |
| 6703 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6704 | * Remove the pending callback for sending a |
| 6705 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 6706 | */ |
| 6707 | private void removeSendViewScrolledAccessibilityEventCallback() { |
| 6708 | if (mSendViewScrolledAccessibilityEvent != null) { |
| 6709 | removeCallbacks(mSendViewScrolledAccessibilityEvent); |
| 6710 | } |
| 6711 | } |
| 6712 | |
| 6713 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6714 | * Sets the TouchDelegate for this View. |
| 6715 | */ |
| 6716 | public void setTouchDelegate(TouchDelegate delegate) { |
| 6717 | mTouchDelegate = delegate; |
| 6718 | } |
| 6719 | |
| 6720 | /** |
| 6721 | * Gets the TouchDelegate for this View. |
| 6722 | */ |
| 6723 | public TouchDelegate getTouchDelegate() { |
| 6724 | return mTouchDelegate; |
| 6725 | } |
| 6726 | |
| 6727 | /** |
| 6728 | * Set flags controlling behavior of this view. |
| 6729 | * |
| 6730 | * @param flags Constant indicating the value which should be set |
| 6731 | * @param mask Constant indicating the bit range that should be changed |
| 6732 | */ |
| 6733 | void setFlags(int flags, int mask) { |
| 6734 | int old = mViewFlags; |
| 6735 | mViewFlags = (mViewFlags & ~mask) | (flags & mask); |
| 6736 | |
| 6737 | int changed = mViewFlags ^ old; |
| 6738 | if (changed == 0) { |
| 6739 | return; |
| 6740 | } |
| 6741 | int privateFlags = mPrivateFlags; |
| 6742 | |
| 6743 | /* Check if the FOCUSABLE bit has changed */ |
| 6744 | if (((changed & FOCUSABLE_MASK) != 0) && |
| 6745 | ((privateFlags & HAS_BOUNDS) !=0)) { |
| 6746 | if (((old & FOCUSABLE_MASK) == FOCUSABLE) |
| 6747 | && ((privateFlags & FOCUSED) != 0)) { |
| 6748 | /* Give up focus if we are no longer focusable */ |
| 6749 | clearFocus(); |
| 6750 | } else if (((old & FOCUSABLE_MASK) == NOT_FOCUSABLE) |
| 6751 | && ((privateFlags & FOCUSED) == 0)) { |
| 6752 | /* |
| 6753 | * Tell the view system that we are now available to take focus |
| 6754 | * if no one else already has it. |
| 6755 | */ |
| 6756 | if (mParent != null) mParent.focusableViewAvailable(this); |
| 6757 | } |
| 6758 | } |
| 6759 | |
| 6760 | if ((flags & VISIBILITY_MASK) == VISIBLE) { |
| 6761 | if ((changed & VISIBILITY_MASK) != 0) { |
| 6762 | /* |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 6763 | * 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] | 6764 | * it was not visible. Marking it drawn ensures that the invalidation will |
| 6765 | * go through. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6766 | */ |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 6767 | mPrivateFlags |= DRAWN; |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 6768 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6769 | |
| 6770 | needGlobalAttributesUpdate(true); |
| 6771 | |
| 6772 | // a view becoming visible is worth notifying the parent |
| 6773 | // about in case nothing has focus. even if this specific view |
| 6774 | // isn't focusable, it may contain something that is, so let |
| 6775 | // the root view try to give this focus if nothing else does. |
| 6776 | if ((mParent != null) && (mBottom > mTop) && (mRight > mLeft)) { |
| 6777 | mParent.focusableViewAvailable(this); |
| 6778 | } |
| 6779 | } |
| 6780 | } |
| 6781 | |
| 6782 | /* Check if the GONE bit has changed */ |
| 6783 | if ((changed & GONE) != 0) { |
| 6784 | needGlobalAttributesUpdate(false); |
| 6785 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6786 | |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 6787 | if (((mViewFlags & VISIBILITY_MASK) == GONE)) { |
| 6788 | if (hasFocus()) clearFocus(); |
| 6789 | destroyDrawingCache(); |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 6790 | if (mParent instanceof View) { |
| 6791 | // GONE views noop invalidation, so invalidate the parent |
| 6792 | ((View) mParent).invalidate(true); |
| 6793 | } |
| 6794 | // Mark the view drawn to ensure that it gets invalidated properly the next |
| 6795 | // time it is visible and gets invalidated |
| 6796 | mPrivateFlags |= DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6797 | } |
| 6798 | if (mAttachInfo != null) { |
| 6799 | mAttachInfo.mViewVisibilityChanged = true; |
| 6800 | } |
| 6801 | } |
| 6802 | |
| 6803 | /* Check if the VISIBLE bit has changed */ |
| 6804 | if ((changed & INVISIBLE) != 0) { |
| 6805 | needGlobalAttributesUpdate(false); |
Chet Haase | c8a9a70 | 2011-06-17 12:13:42 -0700 | [diff] [blame] | 6806 | /* |
| 6807 | * If this view is becoming invisible, set the DRAWN flag so that |
| 6808 | * the next invalidate() will not be skipped. |
| 6809 | */ |
| 6810 | mPrivateFlags |= DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6811 | |
| 6812 | if (((mViewFlags & VISIBILITY_MASK) == INVISIBLE) && hasFocus()) { |
| 6813 | // root view becoming invisible shouldn't clear focus |
| 6814 | if (getRootView() != this) { |
| 6815 | clearFocus(); |
| 6816 | } |
| 6817 | } |
| 6818 | if (mAttachInfo != null) { |
| 6819 | mAttachInfo.mViewVisibilityChanged = true; |
| 6820 | } |
| 6821 | } |
| 6822 | |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6823 | if ((changed & VISIBILITY_MASK) != 0) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 6824 | if (mParent instanceof ViewGroup) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 6825 | ((ViewGroup) mParent).onChildVisibilityChanged(this, (flags & VISIBILITY_MASK)); |
| 6826 | ((View) mParent).invalidate(true); |
Chet Haase | e4e6e20 | 2011-08-29 14:34:30 -0700 | [diff] [blame] | 6827 | } else if (mParent != null) { |
| 6828 | mParent.invalidateChild(this, null); |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 6829 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6830 | dispatchVisibilityChanged(this, (flags & VISIBILITY_MASK)); |
| 6831 | } |
| 6832 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6833 | if ((changed & WILL_NOT_CACHE_DRAWING) != 0) { |
| 6834 | destroyDrawingCache(); |
| 6835 | } |
| 6836 | |
| 6837 | if ((changed & DRAWING_CACHE_ENABLED) != 0) { |
| 6838 | destroyDrawingCache(); |
| 6839 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 6840 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6841 | } |
| 6842 | |
| 6843 | if ((changed & DRAWING_CACHE_QUALITY_MASK) != 0) { |
| 6844 | destroyDrawingCache(); |
| 6845 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 6846 | } |
| 6847 | |
| 6848 | if ((changed & DRAW_MASK) != 0) { |
| 6849 | if ((mViewFlags & WILL_NOT_DRAW) != 0) { |
| 6850 | if (mBGDrawable != null) { |
| 6851 | mPrivateFlags &= ~SKIP_DRAW; |
| 6852 | mPrivateFlags |= ONLY_DRAWS_BACKGROUND; |
| 6853 | } else { |
| 6854 | mPrivateFlags |= SKIP_DRAW; |
| 6855 | } |
| 6856 | } else { |
| 6857 | mPrivateFlags &= ~SKIP_DRAW; |
| 6858 | } |
| 6859 | requestLayout(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 6860 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6861 | } |
| 6862 | |
| 6863 | if ((changed & KEEP_SCREEN_ON) != 0) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6864 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6865 | mParent.recomputeViewAttributes(this); |
| 6866 | } |
| 6867 | } |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 6868 | |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 6869 | if ((changed & LAYOUT_DIRECTION_MASK) != 0) { |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 6870 | requestLayout(); |
| 6871 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6872 | } |
| 6873 | |
| 6874 | /** |
| 6875 | * Change the view's z order in the tree, so it's on top of other sibling |
| 6876 | * views |
| 6877 | */ |
| 6878 | public void bringToFront() { |
| 6879 | if (mParent != null) { |
| 6880 | mParent.bringChildToFront(this); |
| 6881 | } |
| 6882 | } |
| 6883 | |
| 6884 | /** |
| 6885 | * This is called in response to an internal scroll in this view (i.e., the |
| 6886 | * view scrolled its own contents). This is typically as a result of |
| 6887 | * {@link #scrollBy(int, int)} or {@link #scrollTo(int, int)} having been |
| 6888 | * called. |
| 6889 | * |
| 6890 | * @param l Current horizontal scroll origin. |
| 6891 | * @param t Current vertical scroll origin. |
| 6892 | * @param oldl Previous horizontal scroll origin. |
| 6893 | * @param oldt Previous vertical scroll origin. |
| 6894 | */ |
| 6895 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6896 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 6897 | postSendViewScrolledAccessibilityEventCallback(); |
| 6898 | } |
| 6899 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6900 | mBackgroundSizeChanged = true; |
| 6901 | |
| 6902 | final AttachInfo ai = mAttachInfo; |
| 6903 | if (ai != null) { |
| 6904 | ai.mViewScrollChanged = true; |
| 6905 | } |
| 6906 | } |
| 6907 | |
| 6908 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 6909 | * Interface definition for a callback to be invoked when the layout bounds of a view |
| 6910 | * changes due to layout processing. |
| 6911 | */ |
| 6912 | public interface OnLayoutChangeListener { |
| 6913 | /** |
| 6914 | * Called when the focus state of a view has changed. |
| 6915 | * |
| 6916 | * @param v The view whose state has changed. |
| 6917 | * @param left The new value of the view's left property. |
| 6918 | * @param top The new value of the view's top property. |
| 6919 | * @param right The new value of the view's right property. |
| 6920 | * @param bottom The new value of the view's bottom property. |
| 6921 | * @param oldLeft The previous value of the view's left property. |
| 6922 | * @param oldTop The previous value of the view's top property. |
| 6923 | * @param oldRight The previous value of the view's right property. |
| 6924 | * @param oldBottom The previous value of the view's bottom property. |
| 6925 | */ |
| 6926 | void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 6927 | int oldLeft, int oldTop, int oldRight, int oldBottom); |
| 6928 | } |
| 6929 | |
| 6930 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6931 | * This is called during layout when the size of this view has changed. If |
| 6932 | * you were just added to the view hierarchy, you're called with the old |
| 6933 | * values of 0. |
| 6934 | * |
| 6935 | * @param w Current width of this view. |
| 6936 | * @param h Current height of this view. |
| 6937 | * @param oldw Old width of this view. |
| 6938 | * @param oldh Old height of this view. |
| 6939 | */ |
| 6940 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 6941 | } |
| 6942 | |
| 6943 | /** |
| 6944 | * Called by draw to draw the child views. This may be overridden |
| 6945 | * by derived classes to gain control just before its children are drawn |
| 6946 | * (but after its own view has been drawn). |
| 6947 | * @param canvas the canvas on which to draw the view |
| 6948 | */ |
| 6949 | protected void dispatchDraw(Canvas canvas) { |
| 6950 | } |
| 6951 | |
| 6952 | /** |
| 6953 | * Gets the parent of this view. Note that the parent is a |
| 6954 | * ViewParent and not necessarily a View. |
| 6955 | * |
| 6956 | * @return Parent of this view. |
| 6957 | */ |
| 6958 | public final ViewParent getParent() { |
| 6959 | return mParent; |
| 6960 | } |
| 6961 | |
| 6962 | /** |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 6963 | * Set the horizontal scrolled position of your view. This will cause a call to |
| 6964 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 6965 | * invalidated. |
| 6966 | * @param value the x position to scroll to |
| 6967 | */ |
| 6968 | public void setScrollX(int value) { |
| 6969 | scrollTo(value, mScrollY); |
| 6970 | } |
| 6971 | |
| 6972 | /** |
| 6973 | * Set the vertical scrolled position of your view. This will cause a call to |
| 6974 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 6975 | * invalidated. |
| 6976 | * @param value the y position to scroll to |
| 6977 | */ |
| 6978 | public void setScrollY(int value) { |
| 6979 | scrollTo(mScrollX, value); |
| 6980 | } |
| 6981 | |
| 6982 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6983 | * Return the scrolled left position of this view. This is the left edge of |
| 6984 | * the displayed part of your view. You do not need to draw any pixels |
| 6985 | * farther left, since those are outside of the frame of your view on |
| 6986 | * screen. |
| 6987 | * |
| 6988 | * @return The left edge of the displayed part of your view, in pixels. |
| 6989 | */ |
| 6990 | public final int getScrollX() { |
| 6991 | return mScrollX; |
| 6992 | } |
| 6993 | |
| 6994 | /** |
| 6995 | * Return the scrolled top position of this view. This is the top edge of |
| 6996 | * the displayed part of your view. You do not need to draw any pixels above |
| 6997 | * it, since those are outside of the frame of your view on screen. |
| 6998 | * |
| 6999 | * @return The top edge of the displayed part of your view, in pixels. |
| 7000 | */ |
| 7001 | public final int getScrollY() { |
| 7002 | return mScrollY; |
| 7003 | } |
| 7004 | |
| 7005 | /** |
| 7006 | * Return the width of the your view. |
| 7007 | * |
| 7008 | * @return The width of your view, in pixels. |
| 7009 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 7010 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7011 | public final int getWidth() { |
| 7012 | return mRight - mLeft; |
| 7013 | } |
| 7014 | |
| 7015 | /** |
| 7016 | * Return the height of your view. |
| 7017 | * |
| 7018 | * @return The height of your view, in pixels. |
| 7019 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 7020 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7021 | public final int getHeight() { |
| 7022 | return mBottom - mTop; |
| 7023 | } |
| 7024 | |
| 7025 | /** |
| 7026 | * Return the visible drawing bounds of your view. Fills in the output |
| 7027 | * rectangle with the values from getScrollX(), getScrollY(), |
| 7028 | * getWidth(), and getHeight(). |
| 7029 | * |
| 7030 | * @param outRect The (scrolled) drawing bounds of the view. |
| 7031 | */ |
| 7032 | public void getDrawingRect(Rect outRect) { |
| 7033 | outRect.left = mScrollX; |
| 7034 | outRect.top = mScrollY; |
| 7035 | outRect.right = mScrollX + (mRight - mLeft); |
| 7036 | outRect.bottom = mScrollY + (mBottom - mTop); |
| 7037 | } |
| 7038 | |
| 7039 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7040 | * Like {@link #getMeasuredWidthAndState()}, but only returns the |
| 7041 | * raw width component (that is the result is masked by |
| 7042 | * {@link #MEASURED_SIZE_MASK}). |
| 7043 | * |
| 7044 | * @return The raw measured width of this view. |
| 7045 | */ |
| 7046 | public final int getMeasuredWidth() { |
| 7047 | return mMeasuredWidth & MEASURED_SIZE_MASK; |
| 7048 | } |
| 7049 | |
| 7050 | /** |
| 7051 | * Return the full width measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7052 | * 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] | 7053 | * 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] | 7054 | * This should be used during measurement and layout calculations only. Use |
| 7055 | * {@link #getWidth()} to see how wide a view is after layout. |
| 7056 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7057 | * @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] | 7058 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7059 | public final int getMeasuredWidthAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7060 | return mMeasuredWidth; |
| 7061 | } |
| 7062 | |
| 7063 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7064 | * Like {@link #getMeasuredHeightAndState()}, but only returns the |
| 7065 | * raw width component (that is the result is masked by |
| 7066 | * {@link #MEASURED_SIZE_MASK}). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7067 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7068 | * @return The raw measured height of this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7069 | */ |
| 7070 | public final int getMeasuredHeight() { |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7071 | return mMeasuredHeight & MEASURED_SIZE_MASK; |
| 7072 | } |
| 7073 | |
| 7074 | /** |
| 7075 | * Return the full height measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7076 | * 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] | 7077 | * as defined by {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. |
| 7078 | * This should be used during measurement and layout calculations only. Use |
| 7079 | * {@link #getHeight()} to see how wide a view is after layout. |
| 7080 | * |
| 7081 | * @return The measured width of this view as a bit mask. |
| 7082 | */ |
| 7083 | public final int getMeasuredHeightAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7084 | return mMeasuredHeight; |
| 7085 | } |
| 7086 | |
| 7087 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7088 | * Return only the state bits of {@link #getMeasuredWidthAndState()} |
| 7089 | * and {@link #getMeasuredHeightAndState()}, combined into one integer. |
| 7090 | * The width component is in the regular bits {@link #MEASURED_STATE_MASK} |
| 7091 | * and the height component is at the shifted bits |
| 7092 | * {@link #MEASURED_HEIGHT_STATE_SHIFT}>>{@link #MEASURED_STATE_MASK}. |
| 7093 | */ |
| 7094 | public final int getMeasuredState() { |
| 7095 | return (mMeasuredWidth&MEASURED_STATE_MASK) |
| 7096 | | ((mMeasuredHeight>>MEASURED_HEIGHT_STATE_SHIFT) |
| 7097 | & (MEASURED_STATE_MASK>>MEASURED_HEIGHT_STATE_SHIFT)); |
| 7098 | } |
| 7099 | |
| 7100 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7101 | * The transform matrix of this view, which is calculated based on the current |
| 7102 | * roation, scale, and pivot properties. |
| 7103 | * |
| 7104 | * @see #getRotation() |
| 7105 | * @see #getScaleX() |
| 7106 | * @see #getScaleY() |
| 7107 | * @see #getPivotX() |
| 7108 | * @see #getPivotY() |
| 7109 | * @return The current transform matrix for the view |
| 7110 | */ |
| 7111 | public Matrix getMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7112 | if (mTransformationInfo != null) { |
| 7113 | updateMatrix(); |
| 7114 | return mTransformationInfo.mMatrix; |
| 7115 | } |
| 7116 | return Matrix.IDENTITY_MATRIX; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7117 | } |
| 7118 | |
| 7119 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7120 | * Utility function to determine if the value is far enough away from zero to be |
| 7121 | * considered non-zero. |
| 7122 | * @param value A floating point value to check for zero-ness |
| 7123 | * @return whether the passed-in value is far enough away from zero to be considered non-zero |
| 7124 | */ |
| 7125 | private static boolean nonzero(float value) { |
| 7126 | return (value < -NONZERO_EPSILON || value > NONZERO_EPSILON); |
| 7127 | } |
| 7128 | |
| 7129 | /** |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7130 | * Returns true if the transform matrix is the identity matrix. |
| 7131 | * Recomputes the matrix if necessary. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7132 | * |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7133 | * @return True if the transform matrix is the identity matrix, false otherwise. |
| 7134 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7135 | final boolean hasIdentityMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7136 | if (mTransformationInfo != null) { |
| 7137 | updateMatrix(); |
| 7138 | return mTransformationInfo.mMatrixIsIdentity; |
| 7139 | } |
| 7140 | return true; |
| 7141 | } |
| 7142 | |
| 7143 | void ensureTransformationInfo() { |
| 7144 | if (mTransformationInfo == null) { |
| 7145 | mTransformationInfo = new TransformationInfo(); |
| 7146 | } |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7147 | } |
| 7148 | |
| 7149 | /** |
| 7150 | * Recomputes the transform matrix if necessary. |
| 7151 | */ |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 7152 | private void updateMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7153 | final TransformationInfo info = mTransformationInfo; |
| 7154 | if (info == null) { |
| 7155 | return; |
| 7156 | } |
| 7157 | if (info.mMatrixDirty) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7158 | // transform-related properties have changed since the last time someone |
| 7159 | // asked for the matrix; recalculate it with the current values |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7160 | |
| 7161 | // Figure out if we need to update the pivot point |
| 7162 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7163 | if ((mRight - mLeft) != info.mPrevWidth || (mBottom - mTop) != info.mPrevHeight) { |
| 7164 | info.mPrevWidth = mRight - mLeft; |
| 7165 | info.mPrevHeight = mBottom - mTop; |
| 7166 | info.mPivotX = info.mPrevWidth / 2f; |
| 7167 | info.mPivotY = info.mPrevHeight / 2f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7168 | } |
| 7169 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7170 | info.mMatrix.reset(); |
| 7171 | if (!nonzero(info.mRotationX) && !nonzero(info.mRotationY)) { |
| 7172 | info.mMatrix.setTranslate(info.mTranslationX, info.mTranslationY); |
| 7173 | info.mMatrix.preRotate(info.mRotation, info.mPivotX, info.mPivotY); |
| 7174 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7175 | } else { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7176 | if (info.mCamera == null) { |
| 7177 | info.mCamera = new Camera(); |
| 7178 | info.matrix3D = new Matrix(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7179 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7180 | info.mCamera.save(); |
| 7181 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
| 7182 | info.mCamera.rotate(info.mRotationX, info.mRotationY, -info.mRotation); |
| 7183 | info.mCamera.getMatrix(info.matrix3D); |
| 7184 | info.matrix3D.preTranslate(-info.mPivotX, -info.mPivotY); |
| 7185 | info.matrix3D.postTranslate(info.mPivotX + info.mTranslationX, |
| 7186 | info.mPivotY + info.mTranslationY); |
| 7187 | info.mMatrix.postConcat(info.matrix3D); |
| 7188 | info.mCamera.restore(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7189 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7190 | info.mMatrixDirty = false; |
| 7191 | info.mMatrixIsIdentity = info.mMatrix.isIdentity(); |
| 7192 | info.mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7193 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7194 | } |
| 7195 | |
| 7196 | /** |
| 7197 | * Utility method to retrieve the inverse of the current mMatrix property. |
| 7198 | * We cache the matrix to avoid recalculating it when transform properties |
| 7199 | * have not changed. |
| 7200 | * |
| 7201 | * @return The inverse of the current matrix of this view. |
| 7202 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7203 | final Matrix getInverseMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7204 | final TransformationInfo info = mTransformationInfo; |
| 7205 | if (info != null) { |
| 7206 | updateMatrix(); |
| 7207 | if (info.mInverseMatrixDirty) { |
| 7208 | if (info.mInverseMatrix == null) { |
| 7209 | info.mInverseMatrix = new Matrix(); |
| 7210 | } |
| 7211 | info.mMatrix.invert(info.mInverseMatrix); |
| 7212 | info.mInverseMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7213 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7214 | return info.mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7215 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7216 | return Matrix.IDENTITY_MATRIX; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7217 | } |
| 7218 | |
| 7219 | /** |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7220 | * <p>Sets the distance along the Z axis (orthogonal to the X/Y plane on which |
| 7221 | * views are drawn) from the camera to this view. The camera's distance |
| 7222 | * affects 3D transformations, for instance rotations around the X and Y |
| 7223 | * axis. If the rotationX or rotationY properties are changed and this view is |
| 7224 | * large (more than half the size of the screen), it is recommended to always |
| 7225 | * use a camera distance that's greater than the height (X axis rotation) or |
| 7226 | * the width (Y axis rotation) of this view.</p> |
| 7227 | * |
| 7228 | * <p>The distance of the camera from the view plane can have an affect on the |
| 7229 | * perspective distortion of the view when it is rotated around the x or y axis. |
| 7230 | * For example, a large distance will result in a large viewing angle, and there |
| 7231 | * will not be much perspective distortion of the view as it rotates. A short |
| 7232 | * distance may cause much more perspective distortion upon rotation, and can |
| 7233 | * also result in some drawing artifacts if the rotated view ends up partially |
| 7234 | * behind the camera (which is why the recommendation is to use a distance at |
| 7235 | * least as far as the size of the view, if the view is to be rotated.)</p> |
| 7236 | * |
| 7237 | * <p>The distance is expressed in "depth pixels." The default distance depends |
| 7238 | * on the screen density. For instance, on a medium density display, the |
| 7239 | * default distance is 1280. On a high density display, the default distance |
| 7240 | * is 1920.</p> |
| 7241 | * |
| 7242 | * <p>If you want to specify a distance that leads to visually consistent |
| 7243 | * results across various densities, use the following formula:</p> |
| 7244 | * <pre> |
| 7245 | * float scale = context.getResources().getDisplayMetrics().density; |
| 7246 | * view.setCameraDistance(distance * scale); |
| 7247 | * </pre> |
| 7248 | * |
| 7249 | * <p>The density scale factor of a high density display is 1.5, |
| 7250 | * and 1920 = 1280 * 1.5.</p> |
| 7251 | * |
| 7252 | * @param distance The distance in "depth pixels", if negative the opposite |
| 7253 | * value is used |
| 7254 | * |
| 7255 | * @see #setRotationX(float) |
| 7256 | * @see #setRotationY(float) |
| 7257 | */ |
| 7258 | public void setCameraDistance(float distance) { |
| 7259 | invalidateParentCaches(); |
| 7260 | invalidate(false); |
| 7261 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7262 | ensureTransformationInfo(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7263 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7264 | final TransformationInfo info = mTransformationInfo; |
| 7265 | if (info.mCamera == null) { |
| 7266 | info.mCamera = new Camera(); |
| 7267 | info.matrix3D = new Matrix(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7268 | } |
| 7269 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7270 | info.mCamera.setLocation(0.0f, 0.0f, -Math.abs(distance) / dpi); |
| 7271 | info.mMatrixDirty = true; |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7272 | |
| 7273 | invalidate(false); |
| 7274 | } |
| 7275 | |
| 7276 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7277 | * The degrees that the view is rotated around the pivot point. |
| 7278 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7279 | * @see #setRotation(float) |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7280 | * @see #getPivotX() |
| 7281 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7282 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7283 | * @return The degrees of rotation. |
| 7284 | */ |
| 7285 | public float getRotation() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7286 | return mTransformationInfo != null ? mTransformationInfo.mRotation : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7287 | } |
| 7288 | |
| 7289 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7290 | * Sets the degrees that the view is rotated around the pivot point. Increasing values |
| 7291 | * result in clockwise rotation. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7292 | * |
| 7293 | * @param rotation The degrees of rotation. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7294 | * |
| 7295 | * @see #getRotation() |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7296 | * @see #getPivotX() |
| 7297 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7298 | * @see #setRotationX(float) |
| 7299 | * @see #setRotationY(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7300 | * |
| 7301 | * @attr ref android.R.styleable#View_rotation |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7302 | */ |
| 7303 | public void setRotation(float rotation) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7304 | ensureTransformationInfo(); |
| 7305 | final TransformationInfo info = mTransformationInfo; |
| 7306 | if (info.mRotation != rotation) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7307 | invalidateParentCaches(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7308 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7309 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7310 | info.mRotation = rotation; |
| 7311 | info.mMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7312 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7313 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7314 | } |
| 7315 | } |
| 7316 | |
| 7317 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7318 | * The degrees that the view is rotated around the vertical axis through the pivot point. |
| 7319 | * |
| 7320 | * @see #getPivotX() |
| 7321 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7322 | * @see #setRotationY(float) |
| 7323 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7324 | * @return The degrees of Y rotation. |
| 7325 | */ |
| 7326 | public float getRotationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7327 | return mTransformationInfo != null ? mTransformationInfo.mRotationY : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7328 | } |
| 7329 | |
| 7330 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7331 | * Sets the degrees that the view is rotated around the vertical axis through the pivot point. |
| 7332 | * Increasing values result in counter-clockwise rotation from the viewpoint of looking |
| 7333 | * down the y axis. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7334 | * |
| 7335 | * When rotating large views, it is recommended to adjust the camera distance |
| 7336 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7337 | * |
| 7338 | * @param rotationY The degrees of Y rotation. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7339 | * |
| 7340 | * @see #getRotationY() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7341 | * @see #getPivotX() |
| 7342 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7343 | * @see #setRotation(float) |
| 7344 | * @see #setRotationX(float) |
| 7345 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7346 | * |
| 7347 | * @attr ref android.R.styleable#View_rotationY |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7348 | */ |
| 7349 | public void setRotationY(float rotationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7350 | ensureTransformationInfo(); |
| 7351 | final TransformationInfo info = mTransformationInfo; |
| 7352 | if (info.mRotationY != rotationY) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7353 | invalidateParentCaches(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7354 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7355 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7356 | info.mRotationY = rotationY; |
| 7357 | info.mMatrixDirty = true; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7358 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7359 | invalidate(false); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7360 | } |
| 7361 | } |
| 7362 | |
| 7363 | /** |
| 7364 | * The degrees that the view is rotated around the horizontal axis through the pivot point. |
| 7365 | * |
| 7366 | * @see #getPivotX() |
| 7367 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7368 | * @see #setRotationX(float) |
| 7369 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7370 | * @return The degrees of X rotation. |
| 7371 | */ |
| 7372 | public float getRotationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7373 | return mTransformationInfo != null ? mTransformationInfo.mRotationX : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7374 | } |
| 7375 | |
| 7376 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7377 | * Sets the degrees that the view is rotated around the horizontal axis through the pivot point. |
| 7378 | * Increasing values result in clockwise rotation from the viewpoint of looking down the |
| 7379 | * x axis. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7380 | * |
| 7381 | * When rotating large views, it is recommended to adjust the camera distance |
| 7382 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7383 | * |
| 7384 | * @param rotationX The degrees of X rotation. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7385 | * |
| 7386 | * @see #getRotationX() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7387 | * @see #getPivotX() |
| 7388 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7389 | * @see #setRotation(float) |
| 7390 | * @see #setRotationY(float) |
| 7391 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7392 | * |
| 7393 | * @attr ref android.R.styleable#View_rotationX |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7394 | */ |
| 7395 | public void setRotationX(float rotationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7396 | ensureTransformationInfo(); |
| 7397 | final TransformationInfo info = mTransformationInfo; |
| 7398 | if (info.mRotationX != rotationX) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7399 | invalidateParentCaches(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7400 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7401 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7402 | info.mRotationX = rotationX; |
| 7403 | info.mMatrixDirty = true; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7404 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7405 | invalidate(false); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7406 | } |
| 7407 | } |
| 7408 | |
| 7409 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7410 | * The amount that the view is scaled in x around the pivot point, as a proportion of |
| 7411 | * the view's unscaled width. A value of 1, the default, means that no scaling is applied. |
| 7412 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 7413 | * <p>By default, this is 1.0f. |
| 7414 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7415 | * @see #getPivotX() |
| 7416 | * @see #getPivotY() |
| 7417 | * @return The scaling factor. |
| 7418 | */ |
| 7419 | public float getScaleX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7420 | return mTransformationInfo != null ? mTransformationInfo.mScaleX : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7421 | } |
| 7422 | |
| 7423 | /** |
| 7424 | * Sets the amount that the view is scaled in x around the pivot point, as a proportion of |
| 7425 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 7426 | * |
| 7427 | * @param scaleX The scaling factor. |
| 7428 | * @see #getPivotX() |
| 7429 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7430 | * |
| 7431 | * @attr ref android.R.styleable#View_scaleX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7432 | */ |
| 7433 | public void setScaleX(float scaleX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7434 | ensureTransformationInfo(); |
| 7435 | final TransformationInfo info = mTransformationInfo; |
| 7436 | if (info.mScaleX != scaleX) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7437 | invalidateParentCaches(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7438 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7439 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7440 | info.mScaleX = scaleX; |
| 7441 | info.mMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7442 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7443 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7444 | } |
| 7445 | } |
| 7446 | |
| 7447 | /** |
| 7448 | * The amount that the view is scaled in y around the pivot point, as a proportion of |
| 7449 | * the view's unscaled height. A value of 1, the default, means that no scaling is applied. |
| 7450 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 7451 | * <p>By default, this is 1.0f. |
| 7452 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7453 | * @see #getPivotX() |
| 7454 | * @see #getPivotY() |
| 7455 | * @return The scaling factor. |
| 7456 | */ |
| 7457 | public float getScaleY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7458 | return mTransformationInfo != null ? mTransformationInfo.mScaleY : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7459 | } |
| 7460 | |
| 7461 | /** |
| 7462 | * Sets the amount that the view is scaled in Y around the pivot point, as a proportion of |
| 7463 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 7464 | * |
| 7465 | * @param scaleY The scaling factor. |
| 7466 | * @see #getPivotX() |
| 7467 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7468 | * |
| 7469 | * @attr ref android.R.styleable#View_scaleY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7470 | */ |
| 7471 | public void setScaleY(float scaleY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7472 | ensureTransformationInfo(); |
| 7473 | final TransformationInfo info = mTransformationInfo; |
| 7474 | if (info.mScaleY != scaleY) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7475 | invalidateParentCaches(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7476 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7477 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7478 | info.mScaleY = scaleY; |
| 7479 | info.mMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7480 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7481 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7482 | } |
| 7483 | } |
| 7484 | |
| 7485 | /** |
| 7486 | * The x location of the point around which the view is {@link #setRotation(float) rotated} |
| 7487 | * and {@link #setScaleX(float) scaled}. |
| 7488 | * |
| 7489 | * @see #getRotation() |
| 7490 | * @see #getScaleX() |
| 7491 | * @see #getScaleY() |
| 7492 | * @see #getPivotY() |
| 7493 | * @return The x location of the pivot point. |
| 7494 | */ |
| 7495 | public float getPivotX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7496 | return mTransformationInfo != null ? mTransformationInfo.mPivotX : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7497 | } |
| 7498 | |
| 7499 | /** |
| 7500 | * Sets the x location of the point around which the view is |
| 7501 | * {@link #setRotation(float) rotated} and {@link #setScaleX(float) scaled}. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7502 | * By default, the pivot point is centered on the object. |
| 7503 | * Setting this property disables this behavior and causes the view to use only the |
| 7504 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7505 | * |
| 7506 | * @param pivotX The x location of the pivot point. |
| 7507 | * @see #getRotation() |
| 7508 | * @see #getScaleX() |
| 7509 | * @see #getScaleY() |
| 7510 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7511 | * |
| 7512 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7513 | */ |
| 7514 | public void setPivotX(float pivotX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7515 | ensureTransformationInfo(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7516 | mPrivateFlags |= PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7517 | final TransformationInfo info = mTransformationInfo; |
| 7518 | if (info.mPivotX != pivotX) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7519 | invalidateParentCaches(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7520 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7521 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7522 | info.mPivotX = pivotX; |
| 7523 | info.mMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7524 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7525 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7526 | } |
| 7527 | } |
| 7528 | |
| 7529 | /** |
| 7530 | * The y location of the point around which the view is {@link #setRotation(float) rotated} |
| 7531 | * and {@link #setScaleY(float) scaled}. |
| 7532 | * |
| 7533 | * @see #getRotation() |
| 7534 | * @see #getScaleX() |
| 7535 | * @see #getScaleY() |
| 7536 | * @see #getPivotY() |
| 7537 | * @return The y location of the pivot point. |
| 7538 | */ |
| 7539 | public float getPivotY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7540 | return mTransformationInfo != null ? mTransformationInfo.mPivotY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7541 | } |
| 7542 | |
| 7543 | /** |
| 7544 | * 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] | 7545 | * and {@link #setScaleY(float) scaled}. By default, the pivot point is centered on the object. |
| 7546 | * Setting this property disables this behavior and causes the view to use only the |
| 7547 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7548 | * |
| 7549 | * @param pivotY The y location of the pivot point. |
| 7550 | * @see #getRotation() |
| 7551 | * @see #getScaleX() |
| 7552 | * @see #getScaleY() |
| 7553 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7554 | * |
| 7555 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7556 | */ |
| 7557 | public void setPivotY(float pivotY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7558 | ensureTransformationInfo(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7559 | mPrivateFlags |= PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7560 | final TransformationInfo info = mTransformationInfo; |
| 7561 | if (info.mPivotY != pivotY) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7562 | invalidateParentCaches(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7563 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7564 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7565 | info.mPivotY = pivotY; |
| 7566 | info.mMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7567 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7568 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7569 | } |
| 7570 | } |
| 7571 | |
| 7572 | /** |
| 7573 | * The opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 7574 | * completely transparent and 1 means the view is completely opaque. |
| 7575 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 7576 | * <p>By default this is 1.0f. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7577 | * @return The opacity of the view. |
| 7578 | */ |
| 7579 | public float getAlpha() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7580 | return mTransformationInfo != null ? mTransformationInfo.mAlpha : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7581 | } |
| 7582 | |
| 7583 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 7584 | * <p>Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 7585 | * completely transparent and 1 means the view is completely opaque.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7586 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 7587 | * <p>If this view overrides {@link #onSetAlpha(int)} to return true, then this view is |
| 7588 | * responsible for applying the opacity itself. Otherwise, calling this method is |
| 7589 | * equivalent to calling {@link #setLayerType(int, android.graphics.Paint)} and |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7590 | * setting a hardware layer.</p> |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7591 | * |
| 7592 | * @param alpha The opacity of the view. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7593 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7594 | * @see #setLayerType(int, android.graphics.Paint) |
| 7595 | * |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7596 | * @attr ref android.R.styleable#View_alpha |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7597 | */ |
| 7598 | public void setAlpha(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7599 | ensureTransformationInfo(); |
| 7600 | mTransformationInfo.mAlpha = alpha; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7601 | invalidateParentCaches(); |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7602 | if (onSetAlpha((int) (alpha * 255))) { |
Romain Guy | a3496a9 | 2010-10-12 11:53:24 -0700 | [diff] [blame] | 7603 | mPrivateFlags |= ALPHA_SET; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7604 | // subclass is handling alpha - don't optimize rendering cache invalidation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7605 | invalidate(true); |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7606 | } else { |
Romain Guy | a3496a9 | 2010-10-12 11:53:24 -0700 | [diff] [blame] | 7607 | mPrivateFlags &= ~ALPHA_SET; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7608 | invalidate(false); |
| 7609 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7610 | } |
| 7611 | |
| 7612 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 7613 | * Faster version of setAlpha() which performs the same steps except there are |
| 7614 | * no calls to invalidate(). The caller of this function should perform proper invalidation |
| 7615 | * on the parent and this object. The return value indicates whether the subclass handles |
| 7616 | * alpha (the return value for onSetAlpha()). |
| 7617 | * |
| 7618 | * @param alpha The new value for the alpha property |
| 7619 | * @return true if the View subclass handles alpha (the return value for onSetAlpha()) |
| 7620 | */ |
| 7621 | boolean setAlphaNoInvalidation(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7622 | ensureTransformationInfo(); |
| 7623 | mTransformationInfo.mAlpha = alpha; |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 7624 | boolean subclassHandlesAlpha = onSetAlpha((int) (alpha * 255)); |
| 7625 | if (subclassHandlesAlpha) { |
| 7626 | mPrivateFlags |= ALPHA_SET; |
| 7627 | } else { |
| 7628 | mPrivateFlags &= ~ALPHA_SET; |
| 7629 | } |
| 7630 | return subclassHandlesAlpha; |
| 7631 | } |
| 7632 | |
| 7633 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7634 | * Top position of this view relative to its parent. |
| 7635 | * |
| 7636 | * @return The top of this view, in pixels. |
| 7637 | */ |
| 7638 | @ViewDebug.CapturedViewProperty |
| 7639 | public final int getTop() { |
| 7640 | return mTop; |
| 7641 | } |
| 7642 | |
| 7643 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7644 | * Sets the top position of this view relative to its parent. This method is meant to be called |
| 7645 | * by the layout system and should not generally be called otherwise, because the property |
| 7646 | * may be changed at any time by the layout. |
| 7647 | * |
| 7648 | * @param top The top of this view, in pixels. |
| 7649 | */ |
| 7650 | public final void setTop(int top) { |
| 7651 | if (top != mTop) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7652 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7653 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 7654 | || mTransformationInfo.mMatrixIsIdentity; |
| 7655 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7656 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7657 | int minTop; |
| 7658 | int yLoc; |
| 7659 | if (top < mTop) { |
| 7660 | minTop = top; |
| 7661 | yLoc = top - mTop; |
| 7662 | } else { |
| 7663 | minTop = mTop; |
| 7664 | yLoc = 0; |
| 7665 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7666 | invalidate(0, yLoc, mRight - mLeft, mBottom - minTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7667 | } |
| 7668 | } else { |
| 7669 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7670 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7671 | } |
| 7672 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7673 | int width = mRight - mLeft; |
| 7674 | int oldHeight = mBottom - mTop; |
| 7675 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7676 | mTop = top; |
| 7677 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7678 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 7679 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7680 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7681 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 7682 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7683 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7684 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7685 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7686 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7687 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 7688 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 7689 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7690 | } |
| 7691 | } |
| 7692 | |
| 7693 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7694 | * Bottom position of this view relative to its parent. |
| 7695 | * |
| 7696 | * @return The bottom of this view, in pixels. |
| 7697 | */ |
| 7698 | @ViewDebug.CapturedViewProperty |
| 7699 | public final int getBottom() { |
| 7700 | return mBottom; |
| 7701 | } |
| 7702 | |
| 7703 | /** |
Michael Jurka | dab559a | 2011-01-04 20:31:51 -0800 | [diff] [blame] | 7704 | * True if this view has changed since the last time being drawn. |
| 7705 | * |
| 7706 | * @return The dirty state of this view. |
| 7707 | */ |
| 7708 | public boolean isDirty() { |
| 7709 | return (mPrivateFlags & DIRTY_MASK) != 0; |
| 7710 | } |
| 7711 | |
| 7712 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7713 | * Sets the bottom position of this view relative to its parent. This method is meant to be |
| 7714 | * called by the layout system and should not generally be called otherwise, because the |
| 7715 | * property may be changed at any time by the layout. |
| 7716 | * |
| 7717 | * @param bottom The bottom of this view, in pixels. |
| 7718 | */ |
| 7719 | public final void setBottom(int bottom) { |
| 7720 | if (bottom != mBottom) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7721 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7722 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 7723 | || mTransformationInfo.mMatrixIsIdentity; |
| 7724 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7725 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7726 | int maxBottom; |
| 7727 | if (bottom < mBottom) { |
| 7728 | maxBottom = mBottom; |
| 7729 | } else { |
| 7730 | maxBottom = bottom; |
| 7731 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7732 | invalidate(0, 0, mRight - mLeft, maxBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7733 | } |
| 7734 | } else { |
| 7735 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7736 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7737 | } |
| 7738 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7739 | int width = mRight - mLeft; |
| 7740 | int oldHeight = mBottom - mTop; |
| 7741 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7742 | mBottom = bottom; |
| 7743 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7744 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 7745 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7746 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7747 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 7748 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7749 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7750 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7751 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7752 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7753 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 7754 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 7755 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7756 | } |
| 7757 | } |
| 7758 | |
| 7759 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7760 | * Left position of this view relative to its parent. |
| 7761 | * |
| 7762 | * @return The left edge of this view, in pixels. |
| 7763 | */ |
| 7764 | @ViewDebug.CapturedViewProperty |
| 7765 | public final int getLeft() { |
| 7766 | return mLeft; |
| 7767 | } |
| 7768 | |
| 7769 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7770 | * Sets the left position of this view relative to its parent. This method is meant to be called |
| 7771 | * by the layout system and should not generally be called otherwise, because the property |
| 7772 | * may be changed at any time by the layout. |
| 7773 | * |
| 7774 | * @param left The bottom of this view, in pixels. |
| 7775 | */ |
| 7776 | public final void setLeft(int left) { |
| 7777 | if (left != mLeft) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7778 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7779 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 7780 | || mTransformationInfo.mMatrixIsIdentity; |
| 7781 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7782 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7783 | int minLeft; |
| 7784 | int xLoc; |
| 7785 | if (left < mLeft) { |
| 7786 | minLeft = left; |
| 7787 | xLoc = left - mLeft; |
| 7788 | } else { |
| 7789 | minLeft = mLeft; |
| 7790 | xLoc = 0; |
| 7791 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7792 | invalidate(xLoc, 0, mRight - minLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7793 | } |
| 7794 | } else { |
| 7795 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7796 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7797 | } |
| 7798 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7799 | int oldWidth = mRight - mLeft; |
| 7800 | int height = mBottom - mTop; |
| 7801 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7802 | mLeft = left; |
| 7803 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7804 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 7805 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7806 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7807 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 7808 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7809 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7810 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7811 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7812 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7813 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 7814 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 7815 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7816 | } |
| 7817 | } |
| 7818 | |
| 7819 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7820 | * Right position of this view relative to its parent. |
| 7821 | * |
| 7822 | * @return The right edge of this view, in pixels. |
| 7823 | */ |
| 7824 | @ViewDebug.CapturedViewProperty |
| 7825 | public final int getRight() { |
| 7826 | return mRight; |
| 7827 | } |
| 7828 | |
| 7829 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7830 | * Sets the right position of this view relative to its parent. This method is meant to be called |
| 7831 | * by the layout system and should not generally be called otherwise, because the property |
| 7832 | * may be changed at any time by the layout. |
| 7833 | * |
| 7834 | * @param right The bottom of this view, in pixels. |
| 7835 | */ |
| 7836 | public final void setRight(int right) { |
| 7837 | if (right != mRight) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7838 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7839 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 7840 | || mTransformationInfo.mMatrixIsIdentity; |
| 7841 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7842 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7843 | int maxRight; |
| 7844 | if (right < mRight) { |
| 7845 | maxRight = mRight; |
| 7846 | } else { |
| 7847 | maxRight = right; |
| 7848 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7849 | invalidate(0, 0, maxRight - mLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7850 | } |
| 7851 | } else { |
| 7852 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7853 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7854 | } |
| 7855 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7856 | int oldWidth = mRight - mLeft; |
| 7857 | int height = mBottom - mTop; |
| 7858 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7859 | mRight = right; |
| 7860 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7861 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 7862 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7863 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7864 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 7865 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7866 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7867 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7868 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7869 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7870 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 7871 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 7872 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7873 | } |
| 7874 | } |
| 7875 | |
| 7876 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7877 | * The visual x position of this view, in pixels. This is equivalent to the |
| 7878 | * {@link #setTranslationX(float) translationX} property plus the current |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7879 | * {@link #getLeft() left} property. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7880 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7881 | * @return The visual x position of this view, in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7882 | */ |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7883 | public float getX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7884 | return mLeft + (mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7885 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7886 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7887 | /** |
| 7888 | * Sets the visual x position of this view, in pixels. This is equivalent to setting the |
| 7889 | * {@link #setTranslationX(float) translationX} property to be the difference between |
| 7890 | * the x value passed in and the current {@link #getLeft() left} property. |
| 7891 | * |
| 7892 | * @param x The visual x position of this view, in pixels. |
| 7893 | */ |
| 7894 | public void setX(float x) { |
| 7895 | setTranslationX(x - mLeft); |
| 7896 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7897 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7898 | /** |
| 7899 | * The visual y position of this view, in pixels. This is equivalent to the |
| 7900 | * {@link #setTranslationY(float) translationY} property plus the current |
| 7901 | * {@link #getTop() top} property. |
| 7902 | * |
| 7903 | * @return The visual y position of this view, in pixels. |
| 7904 | */ |
| 7905 | public float getY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7906 | return mTop + (mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7907 | } |
| 7908 | |
| 7909 | /** |
| 7910 | * Sets the visual y position of this view, in pixels. This is equivalent to setting the |
| 7911 | * {@link #setTranslationY(float) translationY} property to be the difference between |
| 7912 | * the y value passed in and the current {@link #getTop() top} property. |
| 7913 | * |
| 7914 | * @param y The visual y position of this view, in pixels. |
| 7915 | */ |
| 7916 | public void setY(float y) { |
| 7917 | setTranslationY(y - mTop); |
| 7918 | } |
| 7919 | |
| 7920 | |
| 7921 | /** |
| 7922 | * The horizontal location of this view relative to its {@link #getLeft() left} position. |
| 7923 | * This position is post-layout, in addition to wherever the object's |
| 7924 | * layout placed it. |
| 7925 | * |
| 7926 | * @return The horizontal position of this view relative to its left position, in pixels. |
| 7927 | */ |
| 7928 | public float getTranslationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7929 | return mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0; |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7930 | } |
| 7931 | |
| 7932 | /** |
| 7933 | * Sets the horizontal location of this view relative to its {@link #getLeft() left} position. |
| 7934 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 7935 | * layout placed it. |
| 7936 | * |
| 7937 | * @param translationX The horizontal position of this view relative to its left position, |
| 7938 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7939 | * |
| 7940 | * @attr ref android.R.styleable#View_translationX |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7941 | */ |
| 7942 | public void setTranslationX(float translationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7943 | ensureTransformationInfo(); |
| 7944 | final TransformationInfo info = mTransformationInfo; |
| 7945 | if (info.mTranslationX != translationX) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7946 | invalidateParentCaches(); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7947 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7948 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7949 | info.mTranslationX = translationX; |
| 7950 | info.mMatrixDirty = true; |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7951 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7952 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7953 | } |
| 7954 | } |
| 7955 | |
| 7956 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7957 | * The horizontal location of this view relative to its {@link #getTop() top} position. |
| 7958 | * This position is post-layout, in addition to wherever the object's |
| 7959 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7960 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7961 | * @return The vertical position of this view relative to its top position, |
| 7962 | * in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7963 | */ |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7964 | public float getTranslationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7965 | return mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7966 | } |
| 7967 | |
| 7968 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7969 | * Sets the vertical location of this view relative to its {@link #getTop() top} position. |
| 7970 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 7971 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7972 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7973 | * @param translationY The vertical position of this view relative to its top position, |
| 7974 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7975 | * |
| 7976 | * @attr ref android.R.styleable#View_translationY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7977 | */ |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7978 | public void setTranslationY(float translationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7979 | ensureTransformationInfo(); |
| 7980 | final TransformationInfo info = mTransformationInfo; |
| 7981 | if (info.mTranslationY != translationY) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7982 | invalidateParentCaches(); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7983 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7984 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7985 | info.mTranslationY = translationY; |
| 7986 | info.mMatrixDirty = true; |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7987 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7988 | invalidate(false); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7989 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7990 | } |
| 7991 | |
| 7992 | /** |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 7993 | * @hide |
| 7994 | */ |
Michael Jurka | dece29f | 2011-02-03 01:41:49 -0800 | [diff] [blame] | 7995 | public void setFastTranslationX(float x) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7996 | ensureTransformationInfo(); |
| 7997 | final TransformationInfo info = mTransformationInfo; |
| 7998 | info.mTranslationX = x; |
| 7999 | info.mMatrixDirty = true; |
Michael Jurka | dece29f | 2011-02-03 01:41:49 -0800 | [diff] [blame] | 8000 | } |
| 8001 | |
| 8002 | /** |
| 8003 | * @hide |
| 8004 | */ |
| 8005 | public void setFastTranslationY(float y) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8006 | ensureTransformationInfo(); |
| 8007 | final TransformationInfo info = mTransformationInfo; |
| 8008 | info.mTranslationY = y; |
| 8009 | info.mMatrixDirty = true; |
Michael Jurka | dece29f | 2011-02-03 01:41:49 -0800 | [diff] [blame] | 8010 | } |
| 8011 | |
| 8012 | /** |
| 8013 | * @hide |
| 8014 | */ |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8015 | public void setFastX(float x) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8016 | ensureTransformationInfo(); |
| 8017 | final TransformationInfo info = mTransformationInfo; |
| 8018 | info.mTranslationX = x - mLeft; |
| 8019 | info.mMatrixDirty = true; |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8020 | } |
| 8021 | |
| 8022 | /** |
| 8023 | * @hide |
| 8024 | */ |
| 8025 | public void setFastY(float y) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8026 | ensureTransformationInfo(); |
| 8027 | final TransformationInfo info = mTransformationInfo; |
| 8028 | info.mTranslationY = y - mTop; |
| 8029 | info.mMatrixDirty = true; |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8030 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 8031 | |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8032 | /** |
| 8033 | * @hide |
| 8034 | */ |
| 8035 | public void setFastScaleX(float x) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8036 | ensureTransformationInfo(); |
| 8037 | final TransformationInfo info = mTransformationInfo; |
| 8038 | info.mScaleX = x; |
| 8039 | info.mMatrixDirty = true; |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8040 | } |
| 8041 | |
| 8042 | /** |
| 8043 | * @hide |
| 8044 | */ |
| 8045 | public void setFastScaleY(float y) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8046 | ensureTransformationInfo(); |
| 8047 | final TransformationInfo info = mTransformationInfo; |
| 8048 | info.mScaleY = y; |
| 8049 | info.mMatrixDirty = true; |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8050 | } |
| 8051 | |
| 8052 | /** |
| 8053 | * @hide |
| 8054 | */ |
| 8055 | public void setFastAlpha(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8056 | ensureTransformationInfo(); |
| 8057 | mTransformationInfo.mAlpha = alpha; |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8058 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 8059 | |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8060 | /** |
| 8061 | * @hide |
| 8062 | */ |
| 8063 | public void setFastRotationY(float y) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8064 | ensureTransformationInfo(); |
| 8065 | final TransformationInfo info = mTransformationInfo; |
| 8066 | info.mRotationY = y; |
| 8067 | info.mMatrixDirty = true; |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8068 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 8069 | |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8070 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8071 | * Hit rectangle in parent's coordinates |
| 8072 | * |
| 8073 | * @param outRect The hit rectangle of the view. |
| 8074 | */ |
| 8075 | public void getHitRect(Rect outRect) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8076 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8077 | final TransformationInfo info = mTransformationInfo; |
| 8078 | if (info == null || info.mMatrixIsIdentity || mAttachInfo == null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8079 | outRect.set(mLeft, mTop, mRight, mBottom); |
| 8080 | } else { |
| 8081 | final RectF tmpRect = mAttachInfo.mTmpTransformRect; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8082 | tmpRect.set(-info.mPivotX, -info.mPivotY, |
| 8083 | getWidth() - info.mPivotX, getHeight() - info.mPivotY); |
| 8084 | info.mMatrix.mapRect(tmpRect); |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8085 | outRect.set((int) tmpRect.left + mLeft, (int) tmpRect.top + mTop, |
| 8086 | (int) tmpRect.right + mLeft, (int) tmpRect.bottom + mTop); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8087 | } |
| 8088 | } |
| 8089 | |
| 8090 | /** |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8091 | * Determines whether the given point, in local coordinates is inside the view. |
| 8092 | */ |
| 8093 | /*package*/ final boolean pointInView(float localX, float localY) { |
| 8094 | return localX >= 0 && localX < (mRight - mLeft) |
| 8095 | && localY >= 0 && localY < (mBottom - mTop); |
| 8096 | } |
| 8097 | |
| 8098 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8099 | * Utility method to determine whether the given point, in local coordinates, |
| 8100 | * is inside the view, where the area of the view is expanded by the slop factor. |
| 8101 | * This method is called while processing touch-move events to determine if the event |
| 8102 | * is still within the view. |
| 8103 | */ |
| 8104 | private boolean pointInView(float localX, float localY, float slop) { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8105 | return localX >= -slop && localY >= -slop && localX < ((mRight - mLeft) + slop) && |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8106 | localY < ((mBottom - mTop) + slop); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8107 | } |
| 8108 | |
| 8109 | /** |
| 8110 | * When a view has focus and the user navigates away from it, the next view is searched for |
| 8111 | * starting from the rectangle filled in by this method. |
| 8112 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8113 | * By default, the rectange is the {@link #getDrawingRect(android.graphics.Rect)}) |
| 8114 | * of the view. However, if your view maintains some idea of internal selection, |
| 8115 | * such as a cursor, or a selected row or column, you should override this method and |
| 8116 | * fill in a more specific rectangle. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8117 | * |
| 8118 | * @param r The rectangle to fill in, in this view's coordinates. |
| 8119 | */ |
| 8120 | public void getFocusedRect(Rect r) { |
| 8121 | getDrawingRect(r); |
| 8122 | } |
| 8123 | |
| 8124 | /** |
| 8125 | * If some part of this view is not clipped by any of its parents, then |
| 8126 | * return that area in r in global (root) coordinates. To convert r to local |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 8127 | * coordinates (without taking possible View rotations into account), offset |
| 8128 | * it by -globalOffset (e.g. r.offset(-globalOffset.x, -globalOffset.y)). |
| 8129 | * If the view is completely clipped or translated out, return false. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8130 | * |
| 8131 | * @param r If true is returned, r holds the global coordinates of the |
| 8132 | * visible portion of this view. |
| 8133 | * @param globalOffset If true is returned, globalOffset holds the dx,dy |
| 8134 | * between this view and its root. globalOffet may be null. |
| 8135 | * @return true if r is non-empty (i.e. part of the view is visible at the |
| 8136 | * root level. |
| 8137 | */ |
| 8138 | public boolean getGlobalVisibleRect(Rect r, Point globalOffset) { |
| 8139 | int width = mRight - mLeft; |
| 8140 | int height = mBottom - mTop; |
| 8141 | if (width > 0 && height > 0) { |
| 8142 | r.set(0, 0, width, height); |
| 8143 | if (globalOffset != null) { |
| 8144 | globalOffset.set(-mScrollX, -mScrollY); |
| 8145 | } |
| 8146 | return mParent == null || mParent.getChildVisibleRect(this, r, globalOffset); |
| 8147 | } |
| 8148 | return false; |
| 8149 | } |
| 8150 | |
| 8151 | public final boolean getGlobalVisibleRect(Rect r) { |
| 8152 | return getGlobalVisibleRect(r, null); |
| 8153 | } |
| 8154 | |
| 8155 | public final boolean getLocalVisibleRect(Rect r) { |
| 8156 | Point offset = new Point(); |
| 8157 | if (getGlobalVisibleRect(r, offset)) { |
| 8158 | r.offset(-offset.x, -offset.y); // make r local |
| 8159 | return true; |
| 8160 | } |
| 8161 | return false; |
| 8162 | } |
| 8163 | |
| 8164 | /** |
| 8165 | * Offset this view's vertical location by the specified number of pixels. |
| 8166 | * |
| 8167 | * @param offset the number of pixels to offset the view by |
| 8168 | */ |
| 8169 | public void offsetTopAndBottom(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8170 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8171 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8172 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8173 | || mTransformationInfo.mMatrixIsIdentity; |
| 8174 | if (matrixIsIdentity) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8175 | final ViewParent p = mParent; |
| 8176 | if (p != null && mAttachInfo != null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8177 | final Rect r = mAttachInfo.mTmpInvalRect; |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 8178 | int minTop; |
| 8179 | int maxBottom; |
| 8180 | int yLoc; |
| 8181 | if (offset < 0) { |
| 8182 | minTop = mTop + offset; |
| 8183 | maxBottom = mBottom; |
| 8184 | yLoc = offset; |
| 8185 | } else { |
| 8186 | minTop = mTop; |
| 8187 | maxBottom = mBottom + offset; |
| 8188 | yLoc = 0; |
| 8189 | } |
| 8190 | r.set(0, yLoc, mRight - mLeft, maxBottom - minTop); |
| 8191 | p.invalidateChild(this, r); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8192 | } |
| 8193 | } else { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8194 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8195 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8196 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8197 | mTop += offset; |
| 8198 | mBottom += offset; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8199 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8200 | if (!matrixIsIdentity) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8201 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8202 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8203 | } |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8204 | invalidateParentIfNeeded(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8205 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8206 | } |
| 8207 | |
| 8208 | /** |
| 8209 | * Offset this view's horizontal location by the specified amount of pixels. |
| 8210 | * |
| 8211 | * @param offset the numer of pixels to offset the view by |
| 8212 | */ |
| 8213 | public void offsetLeftAndRight(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8214 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8215 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8216 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8217 | || mTransformationInfo.mMatrixIsIdentity; |
| 8218 | if (matrixIsIdentity) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8219 | final ViewParent p = mParent; |
| 8220 | if (p != null && mAttachInfo != null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8221 | final Rect r = mAttachInfo.mTmpInvalRect; |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 8222 | int minLeft; |
| 8223 | int maxRight; |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 8224 | if (offset < 0) { |
| 8225 | minLeft = mLeft + offset; |
| 8226 | maxRight = mRight; |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 8227 | } else { |
| 8228 | minLeft = mLeft; |
| 8229 | maxRight = mRight + offset; |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 8230 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8231 | r.set(0, 0, maxRight - minLeft, mBottom - mTop); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 8232 | p.invalidateChild(this, r); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8233 | } |
| 8234 | } else { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8235 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8236 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8237 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8238 | mLeft += offset; |
| 8239 | mRight += offset; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8240 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8241 | if (!matrixIsIdentity) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8242 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8243 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8244 | } |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8245 | invalidateParentIfNeeded(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8246 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8247 | } |
| 8248 | |
| 8249 | /** |
| 8250 | * Get the LayoutParams associated with this view. All views should have |
| 8251 | * layout parameters. These supply parameters to the <i>parent</i> of this |
| 8252 | * view specifying how it should be arranged. There are many subclasses of |
| 8253 | * ViewGroup.LayoutParams, and these correspond to the different subclasses |
| 8254 | * of ViewGroup that are responsible for arranging their children. |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 8255 | * |
| 8256 | * This method may return null if this View is not attached to a parent |
| 8257 | * ViewGroup or {@link #setLayoutParams(android.view.ViewGroup.LayoutParams)} |
| 8258 | * was not invoked successfully. When a View is attached to a parent |
| 8259 | * ViewGroup, this method must not return null. |
| 8260 | * |
| 8261 | * @return The LayoutParams associated with this view, or null if no |
| 8262 | * parameters have been set yet |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8263 | */ |
Konstantin Lopyrev | 91a7f5f | 2010-08-10 18:54:54 -0700 | [diff] [blame] | 8264 | @ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8265 | public ViewGroup.LayoutParams getLayoutParams() { |
| 8266 | return mLayoutParams; |
| 8267 | } |
| 8268 | |
| 8269 | /** |
| 8270 | * Set the layout parameters associated with this view. These supply |
| 8271 | * parameters to the <i>parent</i> of this view specifying how it should be |
| 8272 | * arranged. There are many subclasses of ViewGroup.LayoutParams, and these |
| 8273 | * correspond to the different subclasses of ViewGroup that are responsible |
| 8274 | * for arranging their children. |
| 8275 | * |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 8276 | * @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] | 8277 | */ |
| 8278 | public void setLayoutParams(ViewGroup.LayoutParams params) { |
| 8279 | if (params == null) { |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 8280 | throw new NullPointerException("Layout parameters cannot be null"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8281 | } |
| 8282 | mLayoutParams = params; |
| 8283 | requestLayout(); |
| 8284 | } |
| 8285 | |
| 8286 | /** |
| 8287 | * Set the scrolled position of your view. This will cause a call to |
| 8288 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8289 | * invalidated. |
| 8290 | * @param x the x position to scroll to |
| 8291 | * @param y the y position to scroll to |
| 8292 | */ |
| 8293 | public void scrollTo(int x, int y) { |
| 8294 | if (mScrollX != x || mScrollY != y) { |
| 8295 | int oldX = mScrollX; |
| 8296 | int oldY = mScrollY; |
| 8297 | mScrollX = x; |
| 8298 | mScrollY = y; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8299 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8300 | onScrollChanged(mScrollX, mScrollY, oldX, oldY); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8301 | if (!awakenScrollBars()) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8302 | invalidate(true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8303 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8304 | } |
| 8305 | } |
| 8306 | |
| 8307 | /** |
| 8308 | * Move the scrolled position of your view. This will cause a call to |
| 8309 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8310 | * invalidated. |
| 8311 | * @param x the amount of pixels to scroll by horizontally |
| 8312 | * @param y the amount of pixels to scroll by vertically |
| 8313 | */ |
| 8314 | public void scrollBy(int x, int y) { |
| 8315 | scrollTo(mScrollX + x, mScrollY + y); |
| 8316 | } |
| 8317 | |
| 8318 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8319 | * <p>Trigger the scrollbars to draw. When invoked this method starts an |
| 8320 | * animation to fade the scrollbars out after a default delay. If a subclass |
| 8321 | * provides animated scrolling, the start delay should equal the duration |
| 8322 | * of the scrolling animation.</p> |
| 8323 | * |
| 8324 | * <p>The animation starts only if at least one of the scrollbars is |
| 8325 | * enabled, as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 8326 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 8327 | * this method returns true, and false otherwise. If the animation is |
| 8328 | * started, this method calls {@link #invalidate()}; in that case the |
| 8329 | * caller should not call {@link #invalidate()}.</p> |
| 8330 | * |
| 8331 | * <p>This method should be invoked every time a subclass directly updates |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 8332 | * the scroll parameters.</p> |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8333 | * |
| 8334 | * <p>This method is automatically invoked by {@link #scrollBy(int, int)} |
| 8335 | * and {@link #scrollTo(int, int)}.</p> |
| 8336 | * |
| 8337 | * @return true if the animation is played, false otherwise |
| 8338 | * |
| 8339 | * @see #awakenScrollBars(int) |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8340 | * @see #scrollBy(int, int) |
| 8341 | * @see #scrollTo(int, int) |
| 8342 | * @see #isHorizontalScrollBarEnabled() |
| 8343 | * @see #isVerticalScrollBarEnabled() |
| 8344 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 8345 | * @see #setVerticalScrollBarEnabled(boolean) |
| 8346 | */ |
| 8347 | protected boolean awakenScrollBars() { |
| 8348 | return mScrollCache != null && |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8349 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade, true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8350 | } |
| 8351 | |
| 8352 | /** |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 8353 | * Trigger the scrollbars to draw. |
| 8354 | * This method differs from awakenScrollBars() only in its default duration. |
| 8355 | * initialAwakenScrollBars() will show the scroll bars for longer than |
| 8356 | * usual to give the user more of a chance to notice them. |
| 8357 | * |
| 8358 | * @return true if the animation is played, false otherwise. |
| 8359 | */ |
| 8360 | private boolean initialAwakenScrollBars() { |
| 8361 | return mScrollCache != null && |
| 8362 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade * 4, true); |
| 8363 | } |
| 8364 | |
| 8365 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8366 | * <p> |
| 8367 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 8368 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 8369 | * provides animated scrolling, the start delay should equal the duration of |
| 8370 | * the scrolling animation. |
| 8371 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8372 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8373 | * <p> |
| 8374 | * The animation starts only if at least one of the scrollbars is enabled, |
| 8375 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 8376 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 8377 | * this method returns true, and false otherwise. If the animation is |
| 8378 | * started, this method calls {@link #invalidate()}; in that case the caller |
| 8379 | * should not call {@link #invalidate()}. |
| 8380 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8381 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8382 | * <p> |
| 8383 | * This method should be invoked everytime a subclass directly updates the |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 8384 | * scroll parameters. |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8385 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8386 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8387 | * @param startDelay the delay, in milliseconds, after which the animation |
| 8388 | * should start; when the delay is 0, the animation starts |
| 8389 | * immediately |
| 8390 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8391 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8392 | * @see #scrollBy(int, int) |
| 8393 | * @see #scrollTo(int, int) |
| 8394 | * @see #isHorizontalScrollBarEnabled() |
| 8395 | * @see #isVerticalScrollBarEnabled() |
| 8396 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 8397 | * @see #setVerticalScrollBarEnabled(boolean) |
| 8398 | */ |
| 8399 | protected boolean awakenScrollBars(int startDelay) { |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8400 | return awakenScrollBars(startDelay, true); |
| 8401 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8402 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8403 | /** |
| 8404 | * <p> |
| 8405 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 8406 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 8407 | * provides animated scrolling, the start delay should equal the duration of |
| 8408 | * the scrolling animation. |
| 8409 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8410 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8411 | * <p> |
| 8412 | * The animation starts only if at least one of the scrollbars is enabled, |
| 8413 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 8414 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 8415 | * this method returns true, and false otherwise. If the animation is |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8416 | * started, this method calls {@link #invalidate()} if the invalidate parameter |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8417 | * is set to true; in that case the caller |
| 8418 | * should not call {@link #invalidate()}. |
| 8419 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8420 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8421 | * <p> |
| 8422 | * This method should be invoked everytime a subclass directly updates the |
| 8423 | * scroll parameters. |
| 8424 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8425 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8426 | * @param startDelay the delay, in milliseconds, after which the animation |
| 8427 | * should start; when the delay is 0, the animation starts |
| 8428 | * immediately |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8429 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8430 | * @param invalidate Wheter this method should call invalidate |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8431 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8432 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8433 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8434 | * @see #scrollBy(int, int) |
| 8435 | * @see #scrollTo(int, int) |
| 8436 | * @see #isHorizontalScrollBarEnabled() |
| 8437 | * @see #isVerticalScrollBarEnabled() |
| 8438 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 8439 | * @see #setVerticalScrollBarEnabled(boolean) |
| 8440 | */ |
| 8441 | protected boolean awakenScrollBars(int startDelay, boolean invalidate) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8442 | final ScrollabilityCache scrollCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8443 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8444 | if (scrollCache == null || !scrollCache.fadeScrollBars) { |
| 8445 | return false; |
| 8446 | } |
| 8447 | |
| 8448 | if (scrollCache.scrollBar == null) { |
| 8449 | scrollCache.scrollBar = new ScrollBarDrawable(); |
| 8450 | } |
| 8451 | |
| 8452 | if (isHorizontalScrollBarEnabled() || isVerticalScrollBarEnabled()) { |
| 8453 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8454 | if (invalidate) { |
| 8455 | // Invalidate to show the scrollbars |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8456 | invalidate(true); |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8457 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8458 | |
| 8459 | if (scrollCache.state == ScrollabilityCache.OFF) { |
| 8460 | // FIXME: this is copied from WindowManagerService. |
| 8461 | // We should get this value from the system when it |
| 8462 | // is possible to do so. |
| 8463 | final int KEY_REPEAT_FIRST_DELAY = 750; |
| 8464 | startDelay = Math.max(KEY_REPEAT_FIRST_DELAY, startDelay); |
| 8465 | } |
| 8466 | |
| 8467 | // Tell mScrollCache when we should start fading. This may |
| 8468 | // extend the fade start time if one was already scheduled |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 8469 | long fadeStartTime = AnimationUtils.currentAnimationTimeMillis() + startDelay; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8470 | scrollCache.fadeStartTime = fadeStartTime; |
| 8471 | scrollCache.state = ScrollabilityCache.ON; |
| 8472 | |
| 8473 | // Schedule our fader to run, unscheduling any old ones first |
| 8474 | if (mAttachInfo != null) { |
| 8475 | mAttachInfo.mHandler.removeCallbacks(scrollCache); |
| 8476 | mAttachInfo.mHandler.postAtTime(scrollCache, fadeStartTime); |
| 8477 | } |
| 8478 | |
| 8479 | return true; |
| 8480 | } |
| 8481 | |
| 8482 | return false; |
| 8483 | } |
| 8484 | |
| 8485 | /** |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8486 | * Do not invalidate views which are not visible and which are not running an animation. They |
| 8487 | * will not get drawn and they should not set dirty flags as if they will be drawn |
| 8488 | */ |
| 8489 | private boolean skipInvalidate() { |
| 8490 | return (mViewFlags & VISIBILITY_MASK) != VISIBLE && mCurrentAnimation == null && |
| 8491 | (!(mParent instanceof ViewGroup) || |
| 8492 | !((ViewGroup) mParent).isViewTransitioning(this)); |
| 8493 | } |
| 8494 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 8495 | * Mark the area defined by dirty as needing to be drawn. If the view is |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8496 | * visible, {@link #onDraw(android.graphics.Canvas)} will be called at some point |
| 8497 | * in the future. This must be called from a UI thread. To call from a non-UI |
| 8498 | * thread, call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8499 | * |
| 8500 | * WARNING: This method is destructive to dirty. |
| 8501 | * @param dirty the rectangle representing the bounds of the dirty region |
| 8502 | */ |
| 8503 | public void invalidate(Rect dirty) { |
| 8504 | if (ViewDebug.TRACE_HIERARCHY) { |
| 8505 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 8506 | } |
| 8507 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8508 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 8509 | return; |
| 8510 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8511 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8512 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || |
| 8513 | (mPrivateFlags & INVALIDATED) != INVALIDATED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8514 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8515 | mPrivateFlags |= INVALIDATED; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 8516 | mPrivateFlags |= DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8517 | final ViewParent p = mParent; |
| 8518 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8519 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 8520 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 8521 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 8522 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 8523 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8524 | p.invalidateChild(this, null); |
| 8525 | return; |
| 8526 | } |
Romain Guy | af636eb | 2010-12-09 17:47:21 -0800 | [diff] [blame] | 8527 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8528 | if (p != null && ai != null) { |
| 8529 | final int scrollX = mScrollX; |
| 8530 | final int scrollY = mScrollY; |
| 8531 | final Rect r = ai.mTmpInvalRect; |
| 8532 | r.set(dirty.left - scrollX, dirty.top - scrollY, |
| 8533 | dirty.right - scrollX, dirty.bottom - scrollY); |
| 8534 | mParent.invalidateChild(this, r); |
| 8535 | } |
| 8536 | } |
| 8537 | } |
| 8538 | |
| 8539 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 8540 | * Mark the area defined by the rect (l,t,r,b) as needing to be drawn. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8541 | * The coordinates of the dirty rect are relative to the view. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8542 | * If the view is visible, {@link #onDraw(android.graphics.Canvas)} |
| 8543 | * will be called at some point in the future. This must be called from |
| 8544 | * 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] | 8545 | * @param l the left position of the dirty region |
| 8546 | * @param t the top position of the dirty region |
| 8547 | * @param r the right position of the dirty region |
| 8548 | * @param b the bottom position of the dirty region |
| 8549 | */ |
| 8550 | public void invalidate(int l, int t, int r, int b) { |
| 8551 | if (ViewDebug.TRACE_HIERARCHY) { |
| 8552 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 8553 | } |
| 8554 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8555 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 8556 | return; |
| 8557 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8558 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8559 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || |
| 8560 | (mPrivateFlags & INVALIDATED) != INVALIDATED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8561 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8562 | mPrivateFlags |= INVALIDATED; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 8563 | mPrivateFlags |= DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8564 | final ViewParent p = mParent; |
| 8565 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8566 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 8567 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 8568 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 8569 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 8570 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8571 | p.invalidateChild(this, null); |
| 8572 | return; |
| 8573 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 8574 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8575 | if (p != null && ai != null && l < r && t < b) { |
| 8576 | final int scrollX = mScrollX; |
| 8577 | final int scrollY = mScrollY; |
| 8578 | final Rect tmpr = ai.mTmpInvalRect; |
| 8579 | tmpr.set(l - scrollX, t - scrollY, r - scrollX, b - scrollY); |
| 8580 | p.invalidateChild(this, tmpr); |
| 8581 | } |
| 8582 | } |
| 8583 | } |
| 8584 | |
| 8585 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8586 | * Invalidate the whole view. If the view is visible, |
| 8587 | * {@link #onDraw(android.graphics.Canvas)} will be called at some point in |
| 8588 | * the future. This must be called from a UI thread. To call from a non-UI thread, |
| 8589 | * call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8590 | */ |
| 8591 | public void invalidate() { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8592 | invalidate(true); |
| 8593 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8594 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8595 | /** |
| 8596 | * This is where the invalidate() work actually happens. A full invalidate() |
| 8597 | * causes the drawing cache to be invalidated, but this function can be called with |
| 8598 | * invalidateCache set to false to skip that invalidation step for cases that do not |
| 8599 | * need it (for example, a component that remains at the same dimensions with the same |
| 8600 | * content). |
| 8601 | * |
| 8602 | * @param invalidateCache Whether the drawing cache for this view should be invalidated as |
| 8603 | * well. This is usually true for a full invalidate, but may be set to false if the |
| 8604 | * View's contents or dimensions have not changed. |
| 8605 | */ |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 8606 | void invalidate(boolean invalidateCache) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8607 | if (ViewDebug.TRACE_HIERARCHY) { |
| 8608 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 8609 | } |
| 8610 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8611 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 8612 | return; |
| 8613 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8614 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Romain Guy | c5d5586 | 2011-01-21 19:01:46 -0800 | [diff] [blame] | 8615 | (invalidateCache && (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) || |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8616 | (mPrivateFlags & INVALIDATED) != INVALIDATED || isOpaque() != mLastIsOpaque) { |
| 8617 | mLastIsOpaque = isOpaque(); |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8618 | mPrivateFlags &= ~DRAWN; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 8619 | mPrivateFlags |= DIRTY; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8620 | if (invalidateCache) { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8621 | mPrivateFlags |= INVALIDATED; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8622 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 8623 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8624 | final AttachInfo ai = mAttachInfo; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 8625 | final ViewParent p = mParent; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8626 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 8627 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 8628 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 8629 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 8630 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8631 | p.invalidateChild(this, null); |
| 8632 | return; |
| 8633 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 8634 | } |
Michael Jurka | ebefea4 | 2010-11-15 16:04:01 -0800 | [diff] [blame] | 8635 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8636 | if (p != null && ai != null) { |
| 8637 | final Rect r = ai.mTmpInvalRect; |
| 8638 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 8639 | // Don't call invalidate -- we don't want to internally scroll |
| 8640 | // our own bounds |
| 8641 | p.invalidateChild(this, r); |
| 8642 | } |
| 8643 | } |
| 8644 | } |
| 8645 | |
| 8646 | /** |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8647 | * @hide |
| 8648 | */ |
| 8649 | public void fastInvalidate() { |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8650 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 8651 | return; |
| 8652 | } |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8653 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
| 8654 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || |
| 8655 | (mPrivateFlags & INVALIDATED) != INVALIDATED) { |
| 8656 | if (mParent instanceof View) { |
| 8657 | ((View) mParent).mPrivateFlags |= INVALIDATED; |
| 8658 | } |
| 8659 | mPrivateFlags &= ~DRAWN; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 8660 | mPrivateFlags |= DIRTY; |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8661 | mPrivateFlags |= INVALIDATED; |
| 8662 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Michael Jurka | d0872bd | 2011-03-24 15:44:19 -0700 | [diff] [blame] | 8663 | if (mParent != null && mAttachInfo != null) { |
| 8664 | if (mAttachInfo.mHardwareAccelerated) { |
| 8665 | mParent.invalidateChild(this, null); |
| 8666 | } else { |
| 8667 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 8668 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 8669 | // Don't call invalidate -- we don't want to internally scroll |
| 8670 | // our own bounds |
| 8671 | mParent.invalidateChild(this, r); |
| 8672 | } |
Romain Guy | da48979 | 2011-02-03 01:05:15 -0800 | [diff] [blame] | 8673 | } |
| 8674 | } |
| 8675 | } |
| 8676 | |
| 8677 | /** |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8678 | * 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] | 8679 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 8680 | * 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] | 8681 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method only |
| 8682 | * clears the parent caches and does not causes an invalidate event. |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8683 | * |
| 8684 | * @hide |
| 8685 | */ |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8686 | protected void invalidateParentCaches() { |
| 8687 | if (mParent instanceof View) { |
| 8688 | ((View) mParent).mPrivateFlags |= INVALIDATED; |
| 8689 | } |
| 8690 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8691 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8692 | /** |
| 8693 | * Used to indicate that the parent of this view should be invalidated. This functionality |
| 8694 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 8695 | * which is necessary when various parent-managed properties of the view change, such as |
| 8696 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method will propagate |
| 8697 | * an invalidation event to the parent. |
| 8698 | * |
| 8699 | * @hide |
| 8700 | */ |
| 8701 | protected void invalidateParentIfNeeded() { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8702 | if (isHardwareAccelerated() && mParent instanceof View) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8703 | ((View) mParent).invalidate(true); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8704 | } |
| 8705 | } |
| 8706 | |
| 8707 | /** |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 8708 | * Indicates whether this View is opaque. An opaque View guarantees that it will |
| 8709 | * draw all the pixels overlapping its bounds using a fully opaque color. |
| 8710 | * |
| 8711 | * Subclasses of View should override this method whenever possible to indicate |
| 8712 | * whether an instance is opaque. Opaque Views are treated in a special way by |
| 8713 | * the View hierarchy, possibly allowing it to perform optimizations during |
| 8714 | * invalidate/draw passes. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 8715 | * |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 8716 | * @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] | 8717 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 8718 | @ViewDebug.ExportedProperty(category = "drawing") |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 8719 | public boolean isOpaque() { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 8720 | return (mPrivateFlags & OPAQUE_MASK) == OPAQUE_MASK && |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8721 | ((mTransformationInfo != null ? mTransformationInfo.mAlpha : 1) |
| 8722 | >= 1.0f - ViewConfiguration.ALPHA_THRESHOLD); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 8723 | } |
| 8724 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 8725 | /** |
| 8726 | * @hide |
| 8727 | */ |
| 8728 | protected void computeOpaqueFlags() { |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 8729 | // Opaque if: |
| 8730 | // - Has a background |
| 8731 | // - Background is opaque |
| 8732 | // - Doesn't have scrollbars or scrollbars are inside overlay |
| 8733 | |
| 8734 | if (mBGDrawable != null && mBGDrawable.getOpacity() == PixelFormat.OPAQUE) { |
| 8735 | mPrivateFlags |= OPAQUE_BACKGROUND; |
| 8736 | } else { |
| 8737 | mPrivateFlags &= ~OPAQUE_BACKGROUND; |
| 8738 | } |
| 8739 | |
| 8740 | final int flags = mViewFlags; |
| 8741 | if (((flags & SCROLLBARS_VERTICAL) == 0 && (flags & SCROLLBARS_HORIZONTAL) == 0) || |
| 8742 | (flags & SCROLLBARS_STYLE_MASK) == SCROLLBARS_INSIDE_OVERLAY) { |
| 8743 | mPrivateFlags |= OPAQUE_SCROLLBARS; |
| 8744 | } else { |
| 8745 | mPrivateFlags &= ~OPAQUE_SCROLLBARS; |
| 8746 | } |
| 8747 | } |
| 8748 | |
| 8749 | /** |
| 8750 | * @hide |
| 8751 | */ |
| 8752 | protected boolean hasOpaqueScrollbars() { |
| 8753 | return (mPrivateFlags & OPAQUE_SCROLLBARS) == OPAQUE_SCROLLBARS; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 8754 | } |
| 8755 | |
| 8756 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8757 | * @return A handler associated with the thread running the View. This |
| 8758 | * handler can be used to pump events in the UI events queue. |
| 8759 | */ |
| 8760 | public Handler getHandler() { |
| 8761 | if (mAttachInfo != null) { |
| 8762 | return mAttachInfo.mHandler; |
| 8763 | } |
| 8764 | return null; |
| 8765 | } |
| 8766 | |
| 8767 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8768 | * <p>Causes the Runnable to be added to the message queue. |
| 8769 | * The runnable will be run on the user interface thread.</p> |
| 8770 | * |
| 8771 | * <p>This method can be invoked from outside of the UI thread |
| 8772 | * 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] | 8773 | * |
| 8774 | * @param action The Runnable that will be executed. |
| 8775 | * |
| 8776 | * @return Returns true if the Runnable was successfully placed in to the |
| 8777 | * message queue. Returns false on failure, usually because the |
| 8778 | * looper processing the message queue is exiting. |
| 8779 | */ |
| 8780 | public boolean post(Runnable action) { |
| 8781 | Handler handler; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8782 | AttachInfo attachInfo = mAttachInfo; |
| 8783 | if (attachInfo != null) { |
| 8784 | handler = attachInfo.mHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8785 | } else { |
| 8786 | // Assume that post will succeed later |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8787 | ViewRootImpl.getRunQueue().post(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8788 | return true; |
| 8789 | } |
| 8790 | |
| 8791 | return handler.post(action); |
| 8792 | } |
| 8793 | |
| 8794 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8795 | * <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] | 8796 | * after the specified amount of time elapses. |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8797 | * The runnable will be run on the user interface thread.</p> |
| 8798 | * |
| 8799 | * <p>This method can be invoked from outside of the UI thread |
| 8800 | * 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] | 8801 | * |
| 8802 | * @param action The Runnable that will be executed. |
| 8803 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 8804 | * will be executed. |
| 8805 | * |
| 8806 | * @return true if the Runnable was successfully placed in to the |
| 8807 | * message queue. Returns false on failure, usually because the |
| 8808 | * looper processing the message queue is exiting. Note that a |
| 8809 | * result of true does not mean the Runnable will be processed -- |
| 8810 | * if the looper is quit before the delivery time of the message |
| 8811 | * occurs then the message will be dropped. |
| 8812 | */ |
| 8813 | public boolean postDelayed(Runnable action, long delayMillis) { |
| 8814 | Handler handler; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8815 | AttachInfo attachInfo = mAttachInfo; |
| 8816 | if (attachInfo != null) { |
| 8817 | handler = attachInfo.mHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8818 | } else { |
| 8819 | // Assume that post will succeed later |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8820 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8821 | return true; |
| 8822 | } |
| 8823 | |
| 8824 | return handler.postDelayed(action, delayMillis); |
| 8825 | } |
| 8826 | |
| 8827 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8828 | * <p>Removes the specified Runnable from the message queue.</p> |
| 8829 | * |
| 8830 | * <p>This method can be invoked from outside of the UI thread |
| 8831 | * 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] | 8832 | * |
| 8833 | * @param action The Runnable to remove from the message handling queue |
| 8834 | * |
| 8835 | * @return true if this view could ask the Handler to remove the Runnable, |
| 8836 | * false otherwise. When the returned value is true, the Runnable |
| 8837 | * may or may not have been actually removed from the message queue |
| 8838 | * (for instance, if the Runnable was not in the queue already.) |
| 8839 | */ |
| 8840 | public boolean removeCallbacks(Runnable action) { |
| 8841 | Handler handler; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8842 | AttachInfo attachInfo = mAttachInfo; |
| 8843 | if (attachInfo != null) { |
| 8844 | handler = attachInfo.mHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8845 | } else { |
| 8846 | // Assume that post will succeed later |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8847 | ViewRootImpl.getRunQueue().removeCallbacks(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8848 | return true; |
| 8849 | } |
| 8850 | |
| 8851 | handler.removeCallbacks(action); |
| 8852 | return true; |
| 8853 | } |
| 8854 | |
| 8855 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8856 | * <p>Cause an invalidate to happen on a subsequent cycle through the event loop. |
| 8857 | * 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] | 8858 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8859 | * <p>This method can be invoked from outside of the UI thread |
| 8860 | * only when this View is attached to a window.</p> |
| 8861 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8862 | * @see #invalidate() |
| 8863 | */ |
| 8864 | public void postInvalidate() { |
| 8865 | postInvalidateDelayed(0); |
| 8866 | } |
| 8867 | |
| 8868 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8869 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 8870 | * through the event loop. Use this to invalidate the View from a non-UI thread.</p> |
| 8871 | * |
| 8872 | * <p>This method can be invoked from outside of the UI thread |
| 8873 | * 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] | 8874 | * |
| 8875 | * @param left The left coordinate of the rectangle to invalidate. |
| 8876 | * @param top The top coordinate of the rectangle to invalidate. |
| 8877 | * @param right The right coordinate of the rectangle to invalidate. |
| 8878 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 8879 | * |
| 8880 | * @see #invalidate(int, int, int, int) |
| 8881 | * @see #invalidate(Rect) |
| 8882 | */ |
| 8883 | public void postInvalidate(int left, int top, int right, int bottom) { |
| 8884 | postInvalidateDelayed(0, left, top, right, bottom); |
| 8885 | } |
| 8886 | |
| 8887 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8888 | * <p>Cause an invalidate to happen on a subsequent cycle through the event |
| 8889 | * loop. Waits for the specified amount of time.</p> |
| 8890 | * |
| 8891 | * <p>This method can be invoked from outside of the UI thread |
| 8892 | * 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] | 8893 | * |
| 8894 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 8895 | * invalidation by |
| 8896 | */ |
| 8897 | public void postInvalidateDelayed(long delayMilliseconds) { |
| 8898 | // We try only with the AttachInfo because there's no point in invalidating |
| 8899 | // if we are not attached to our window |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8900 | AttachInfo attachInfo = mAttachInfo; |
| 8901 | if (attachInfo != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8902 | Message msg = Message.obtain(); |
| 8903 | msg.what = AttachInfo.INVALIDATE_MSG; |
| 8904 | msg.obj = this; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8905 | attachInfo.mHandler.sendMessageDelayed(msg, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8906 | } |
| 8907 | } |
| 8908 | |
| 8909 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8910 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 8911 | * through the event loop. Waits for the specified amount of time.</p> |
| 8912 | * |
| 8913 | * <p>This method can be invoked from outside of the UI thread |
| 8914 | * 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] | 8915 | * |
| 8916 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 8917 | * invalidation by |
| 8918 | * @param left The left coordinate of the rectangle to invalidate. |
| 8919 | * @param top The top coordinate of the rectangle to invalidate. |
| 8920 | * @param right The right coordinate of the rectangle to invalidate. |
| 8921 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 8922 | */ |
| 8923 | public void postInvalidateDelayed(long delayMilliseconds, int left, int top, |
| 8924 | int right, int bottom) { |
| 8925 | |
| 8926 | // We try only with the AttachInfo because there's no point in invalidating |
| 8927 | // if we are not attached to our window |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8928 | AttachInfo attachInfo = mAttachInfo; |
| 8929 | if (attachInfo != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8930 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire(); |
| 8931 | info.target = this; |
| 8932 | info.left = left; |
| 8933 | info.top = top; |
| 8934 | info.right = right; |
| 8935 | info.bottom = bottom; |
| 8936 | |
| 8937 | final Message msg = Message.obtain(); |
| 8938 | msg.what = AttachInfo.INVALIDATE_RECT_MSG; |
| 8939 | msg.obj = info; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8940 | attachInfo.mHandler.sendMessageDelayed(msg, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8941 | } |
| 8942 | } |
| 8943 | |
| 8944 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 8945 | * Post a callback to send a {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} event. |
| 8946 | * This event is sent at most once every |
| 8947 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
| 8948 | */ |
| 8949 | private void postSendViewScrolledAccessibilityEventCallback() { |
| 8950 | if (mSendViewScrolledAccessibilityEvent == null) { |
| 8951 | mSendViewScrolledAccessibilityEvent = new SendViewScrolledAccessibilityEvent(); |
| 8952 | } |
| 8953 | if (!mSendViewScrolledAccessibilityEvent.mIsPending) { |
| 8954 | mSendViewScrolledAccessibilityEvent.mIsPending = true; |
| 8955 | postDelayed(mSendViewScrolledAccessibilityEvent, |
| 8956 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval()); |
| 8957 | } |
| 8958 | } |
| 8959 | |
| 8960 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8961 | * Called by a parent to request that a child update its values for mScrollX |
| 8962 | * and mScrollY if necessary. This will typically be done if the child is |
| 8963 | * animating a scroll using a {@link android.widget.Scroller Scroller} |
| 8964 | * object. |
| 8965 | */ |
| 8966 | public void computeScroll() { |
| 8967 | } |
| 8968 | |
| 8969 | /** |
| 8970 | * <p>Indicate whether the horizontal edges are faded when the view is |
| 8971 | * scrolled horizontally.</p> |
| 8972 | * |
| 8973 | * @return true if the horizontal edges should are faded on scroll, false |
| 8974 | * otherwise |
| 8975 | * |
| 8976 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 8977 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8978 | */ |
| 8979 | public boolean isHorizontalFadingEdgeEnabled() { |
| 8980 | return (mViewFlags & FADING_EDGE_HORIZONTAL) == FADING_EDGE_HORIZONTAL; |
| 8981 | } |
| 8982 | |
| 8983 | /** |
| 8984 | * <p>Define whether the horizontal edges should be faded when this view |
| 8985 | * is scrolled horizontally.</p> |
| 8986 | * |
| 8987 | * @param horizontalFadingEdgeEnabled true if the horizontal edges should |
| 8988 | * be faded when the view is scrolled |
| 8989 | * horizontally |
| 8990 | * |
| 8991 | * @see #isHorizontalFadingEdgeEnabled() |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 8992 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8993 | */ |
| 8994 | public void setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled) { |
| 8995 | if (isHorizontalFadingEdgeEnabled() != horizontalFadingEdgeEnabled) { |
| 8996 | if (horizontalFadingEdgeEnabled) { |
| 8997 | initScrollCache(); |
| 8998 | } |
| 8999 | |
| 9000 | mViewFlags ^= FADING_EDGE_HORIZONTAL; |
| 9001 | } |
| 9002 | } |
| 9003 | |
| 9004 | /** |
| 9005 | * <p>Indicate whether the vertical edges are faded when the view is |
| 9006 | * scrolled horizontally.</p> |
| 9007 | * |
| 9008 | * @return true if the vertical edges should are faded on scroll, false |
| 9009 | * otherwise |
| 9010 | * |
| 9011 | * @see #setVerticalFadingEdgeEnabled(boolean) |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 9012 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9013 | */ |
| 9014 | public boolean isVerticalFadingEdgeEnabled() { |
| 9015 | return (mViewFlags & FADING_EDGE_VERTICAL) == FADING_EDGE_VERTICAL; |
| 9016 | } |
| 9017 | |
| 9018 | /** |
| 9019 | * <p>Define whether the vertical edges should be faded when this view |
| 9020 | * is scrolled vertically.</p> |
| 9021 | * |
| 9022 | * @param verticalFadingEdgeEnabled true if the vertical edges should |
| 9023 | * be faded when the view is scrolled |
| 9024 | * vertically |
| 9025 | * |
| 9026 | * @see #isVerticalFadingEdgeEnabled() |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 9027 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9028 | */ |
| 9029 | public void setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled) { |
| 9030 | if (isVerticalFadingEdgeEnabled() != verticalFadingEdgeEnabled) { |
| 9031 | if (verticalFadingEdgeEnabled) { |
| 9032 | initScrollCache(); |
| 9033 | } |
| 9034 | |
| 9035 | mViewFlags ^= FADING_EDGE_VERTICAL; |
| 9036 | } |
| 9037 | } |
| 9038 | |
| 9039 | /** |
| 9040 | * Returns the strength, or intensity, of the top faded edge. The strength is |
| 9041 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 9042 | * returns 0.0 or 1.0 but no value in between. |
| 9043 | * |
| 9044 | * Subclasses should override this method to provide a smoother fade transition |
| 9045 | * when scrolling occurs. |
| 9046 | * |
| 9047 | * @return the intensity of the top fade as a float between 0.0f and 1.0f |
| 9048 | */ |
| 9049 | protected float getTopFadingEdgeStrength() { |
| 9050 | return computeVerticalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 9051 | } |
| 9052 | |
| 9053 | /** |
| 9054 | * Returns the strength, or intensity, of the bottom faded edge. The strength is |
| 9055 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 9056 | * returns 0.0 or 1.0 but no value in between. |
| 9057 | * |
| 9058 | * Subclasses should override this method to provide a smoother fade transition |
| 9059 | * when scrolling occurs. |
| 9060 | * |
| 9061 | * @return the intensity of the bottom fade as a float between 0.0f and 1.0f |
| 9062 | */ |
| 9063 | protected float getBottomFadingEdgeStrength() { |
| 9064 | return computeVerticalScrollOffset() + computeVerticalScrollExtent() < |
| 9065 | computeVerticalScrollRange() ? 1.0f : 0.0f; |
| 9066 | } |
| 9067 | |
| 9068 | /** |
| 9069 | * Returns the strength, or intensity, of the left faded edge. The strength is |
| 9070 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 9071 | * returns 0.0 or 1.0 but no value in between. |
| 9072 | * |
| 9073 | * Subclasses should override this method to provide a smoother fade transition |
| 9074 | * when scrolling occurs. |
| 9075 | * |
| 9076 | * @return the intensity of the left fade as a float between 0.0f and 1.0f |
| 9077 | */ |
| 9078 | protected float getLeftFadingEdgeStrength() { |
| 9079 | return computeHorizontalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 9080 | } |
| 9081 | |
| 9082 | /** |
| 9083 | * Returns the strength, or intensity, of the right faded edge. The strength is |
| 9084 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 9085 | * returns 0.0 or 1.0 but no value in between. |
| 9086 | * |
| 9087 | * Subclasses should override this method to provide a smoother fade transition |
| 9088 | * when scrolling occurs. |
| 9089 | * |
| 9090 | * @return the intensity of the right fade as a float between 0.0f and 1.0f |
| 9091 | */ |
| 9092 | protected float getRightFadingEdgeStrength() { |
| 9093 | return computeHorizontalScrollOffset() + computeHorizontalScrollExtent() < |
| 9094 | computeHorizontalScrollRange() ? 1.0f : 0.0f; |
| 9095 | } |
| 9096 | |
| 9097 | /** |
| 9098 | * <p>Indicate whether the horizontal scrollbar should be drawn or not. The |
| 9099 | * scrollbar is not drawn by default.</p> |
| 9100 | * |
| 9101 | * @return true if the horizontal scrollbar should be painted, false |
| 9102 | * otherwise |
| 9103 | * |
| 9104 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 9105 | */ |
| 9106 | public boolean isHorizontalScrollBarEnabled() { |
| 9107 | return (mViewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 9108 | } |
| 9109 | |
| 9110 | /** |
| 9111 | * <p>Define whether the horizontal scrollbar should be drawn or not. The |
| 9112 | * scrollbar is not drawn by default.</p> |
| 9113 | * |
| 9114 | * @param horizontalScrollBarEnabled true if the horizontal scrollbar should |
| 9115 | * be painted |
| 9116 | * |
| 9117 | * @see #isHorizontalScrollBarEnabled() |
| 9118 | */ |
| 9119 | public void setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled) { |
| 9120 | if (isHorizontalScrollBarEnabled() != horizontalScrollBarEnabled) { |
| 9121 | mViewFlags ^= SCROLLBARS_HORIZONTAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9122 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9123 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9124 | } |
| 9125 | } |
| 9126 | |
| 9127 | /** |
| 9128 | * <p>Indicate whether the vertical scrollbar should be drawn or not. The |
| 9129 | * scrollbar is not drawn by default.</p> |
| 9130 | * |
| 9131 | * @return true if the vertical scrollbar should be painted, false |
| 9132 | * otherwise |
| 9133 | * |
| 9134 | * @see #setVerticalScrollBarEnabled(boolean) |
| 9135 | */ |
| 9136 | public boolean isVerticalScrollBarEnabled() { |
| 9137 | return (mViewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL; |
| 9138 | } |
| 9139 | |
| 9140 | /** |
| 9141 | * <p>Define whether the vertical scrollbar should be drawn or not. The |
| 9142 | * scrollbar is not drawn by default.</p> |
| 9143 | * |
| 9144 | * @param verticalScrollBarEnabled true if the vertical scrollbar should |
| 9145 | * be painted |
| 9146 | * |
| 9147 | * @see #isVerticalScrollBarEnabled() |
| 9148 | */ |
| 9149 | public void setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled) { |
| 9150 | if (isVerticalScrollBarEnabled() != verticalScrollBarEnabled) { |
| 9151 | mViewFlags ^= SCROLLBARS_VERTICAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9152 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9153 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9154 | } |
| 9155 | } |
| 9156 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 9157 | /** |
| 9158 | * @hide |
| 9159 | */ |
| 9160 | protected void recomputePadding() { |
| 9161 | setPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, mUserPaddingBottom); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9162 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9163 | |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9164 | /** |
| 9165 | * Define whether scrollbars will fade when the view is not scrolling. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9166 | * |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9167 | * @param fadeScrollbars wheter to enable fading |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9168 | * |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9169 | */ |
| 9170 | public void setScrollbarFadingEnabled(boolean fadeScrollbars) { |
| 9171 | initScrollCache(); |
| 9172 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
| 9173 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9174 | if (fadeScrollbars) { |
| 9175 | scrollabilityCache.state = ScrollabilityCache.OFF; |
| 9176 | } else { |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9177 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 9178 | } |
| 9179 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9180 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9181 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9182 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9183 | * Returns true if scrollbars will fade when this view is not scrolling |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9184 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9185 | * @return true if scrollbar fading is enabled |
| 9186 | */ |
| 9187 | public boolean isScrollbarFadingEnabled() { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9188 | return mScrollCache != null && mScrollCache.fadeScrollBars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9189 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9190 | |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9191 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9192 | * <p>Specify the style of the scrollbars. The scrollbars can be overlaid or |
| 9193 | * inset. When inset, they add to the padding of the view. And the scrollbars |
| 9194 | * can be drawn inside the padding area or on the edge of the view. For example, |
| 9195 | * if a view has a background drawable and you want to draw the scrollbars |
| 9196 | * inside the padding specified by the drawable, you can use |
| 9197 | * SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to |
| 9198 | * appear at the edge of the view, ignoring the padding, then you can use |
| 9199 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.</p> |
| 9200 | * @param style the style of the scrollbars. Should be one of |
| 9201 | * SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, |
| 9202 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET. |
| 9203 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 9204 | * @see #SCROLLBARS_INSIDE_INSET |
| 9205 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 9206 | * @see #SCROLLBARS_OUTSIDE_INSET |
| 9207 | */ |
| 9208 | public void setScrollBarStyle(int style) { |
| 9209 | if (style != (mViewFlags & SCROLLBARS_STYLE_MASK)) { |
| 9210 | mViewFlags = (mViewFlags & ~SCROLLBARS_STYLE_MASK) | (style & SCROLLBARS_STYLE_MASK); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9211 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9212 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9213 | } |
| 9214 | } |
| 9215 | |
| 9216 | /** |
| 9217 | * <p>Returns the current scrollbar style.</p> |
| 9218 | * @return the current scrollbar style |
| 9219 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 9220 | * @see #SCROLLBARS_INSIDE_INSET |
| 9221 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 9222 | * @see #SCROLLBARS_OUTSIDE_INSET |
| 9223 | */ |
Jeff Sharkey | 010d7e5 | 2011-08-08 21:05:02 -0700 | [diff] [blame] | 9224 | @ViewDebug.ExportedProperty(mapping = { |
| 9225 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_OVERLAY, to = "INSIDE_OVERLAY"), |
| 9226 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_INSET, to = "INSIDE_INSET"), |
| 9227 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_OVERLAY, to = "OUTSIDE_OVERLAY"), |
| 9228 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_INSET, to = "OUTSIDE_INSET") |
| 9229 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9230 | public int getScrollBarStyle() { |
| 9231 | return mViewFlags & SCROLLBARS_STYLE_MASK; |
| 9232 | } |
| 9233 | |
| 9234 | /** |
| 9235 | * <p>Compute the horizontal range that the horizontal scrollbar |
| 9236 | * represents.</p> |
| 9237 | * |
| 9238 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9239 | * units used by {@link #computeHorizontalScrollExtent()} and |
| 9240 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 9241 | * |
| 9242 | * <p>The default range is the drawing width of this view.</p> |
| 9243 | * |
| 9244 | * @return the total horizontal range represented by the horizontal |
| 9245 | * scrollbar |
| 9246 | * |
| 9247 | * @see #computeHorizontalScrollExtent() |
| 9248 | * @see #computeHorizontalScrollOffset() |
| 9249 | * @see android.widget.ScrollBarDrawable |
| 9250 | */ |
| 9251 | protected int computeHorizontalScrollRange() { |
| 9252 | return getWidth(); |
| 9253 | } |
| 9254 | |
| 9255 | /** |
| 9256 | * <p>Compute the horizontal offset of the horizontal scrollbar's thumb |
| 9257 | * within the horizontal range. This value is used to compute the position |
| 9258 | * of the thumb within the scrollbar's track.</p> |
| 9259 | * |
| 9260 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9261 | * units used by {@link #computeHorizontalScrollRange()} and |
| 9262 | * {@link #computeHorizontalScrollExtent()}.</p> |
| 9263 | * |
| 9264 | * <p>The default offset is the scroll offset of this view.</p> |
| 9265 | * |
| 9266 | * @return the horizontal offset of the scrollbar's thumb |
| 9267 | * |
| 9268 | * @see #computeHorizontalScrollRange() |
| 9269 | * @see #computeHorizontalScrollExtent() |
| 9270 | * @see android.widget.ScrollBarDrawable |
| 9271 | */ |
| 9272 | protected int computeHorizontalScrollOffset() { |
| 9273 | return mScrollX; |
| 9274 | } |
| 9275 | |
| 9276 | /** |
| 9277 | * <p>Compute the horizontal extent of the horizontal scrollbar's thumb |
| 9278 | * within the horizontal range. This value is used to compute the length |
| 9279 | * of the thumb within the scrollbar's track.</p> |
| 9280 | * |
| 9281 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9282 | * units used by {@link #computeHorizontalScrollRange()} and |
| 9283 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 9284 | * |
| 9285 | * <p>The default extent is the drawing width of this view.</p> |
| 9286 | * |
| 9287 | * @return the horizontal extent of the scrollbar's thumb |
| 9288 | * |
| 9289 | * @see #computeHorizontalScrollRange() |
| 9290 | * @see #computeHorizontalScrollOffset() |
| 9291 | * @see android.widget.ScrollBarDrawable |
| 9292 | */ |
| 9293 | protected int computeHorizontalScrollExtent() { |
| 9294 | return getWidth(); |
| 9295 | } |
| 9296 | |
| 9297 | /** |
| 9298 | * <p>Compute the vertical range that the vertical scrollbar represents.</p> |
| 9299 | * |
| 9300 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9301 | * units used by {@link #computeVerticalScrollExtent()} and |
| 9302 | * {@link #computeVerticalScrollOffset()}.</p> |
| 9303 | * |
| 9304 | * @return the total vertical range represented by the vertical scrollbar |
| 9305 | * |
| 9306 | * <p>The default range is the drawing height of this view.</p> |
| 9307 | * |
| 9308 | * @see #computeVerticalScrollExtent() |
| 9309 | * @see #computeVerticalScrollOffset() |
| 9310 | * @see android.widget.ScrollBarDrawable |
| 9311 | */ |
| 9312 | protected int computeVerticalScrollRange() { |
| 9313 | return getHeight(); |
| 9314 | } |
| 9315 | |
| 9316 | /** |
| 9317 | * <p>Compute the vertical offset of the vertical scrollbar's thumb |
| 9318 | * within the horizontal range. This value is used to compute the position |
| 9319 | * of the thumb within the scrollbar's track.</p> |
| 9320 | * |
| 9321 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9322 | * units used by {@link #computeVerticalScrollRange()} and |
| 9323 | * {@link #computeVerticalScrollExtent()}.</p> |
| 9324 | * |
| 9325 | * <p>The default offset is the scroll offset of this view.</p> |
| 9326 | * |
| 9327 | * @return the vertical offset of the scrollbar's thumb |
| 9328 | * |
| 9329 | * @see #computeVerticalScrollRange() |
| 9330 | * @see #computeVerticalScrollExtent() |
| 9331 | * @see android.widget.ScrollBarDrawable |
| 9332 | */ |
| 9333 | protected int computeVerticalScrollOffset() { |
| 9334 | return mScrollY; |
| 9335 | } |
| 9336 | |
| 9337 | /** |
| 9338 | * <p>Compute the vertical extent of the horizontal scrollbar's thumb |
| 9339 | * within the vertical range. This value is used to compute the length |
| 9340 | * of the thumb within the scrollbar's track.</p> |
| 9341 | * |
| 9342 | * <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] | 9343 | * units used by {@link #computeVerticalScrollRange()} and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9344 | * {@link #computeVerticalScrollOffset()}.</p> |
| 9345 | * |
| 9346 | * <p>The default extent is the drawing height of this view.</p> |
| 9347 | * |
| 9348 | * @return the vertical extent of the scrollbar's thumb |
| 9349 | * |
| 9350 | * @see #computeVerticalScrollRange() |
| 9351 | * @see #computeVerticalScrollOffset() |
| 9352 | * @see android.widget.ScrollBarDrawable |
| 9353 | */ |
| 9354 | protected int computeVerticalScrollExtent() { |
| 9355 | return getHeight(); |
| 9356 | } |
| 9357 | |
| 9358 | /** |
Adam Powell | 6915944 | 2011-06-13 17:53:06 -0700 | [diff] [blame] | 9359 | * Check if this view can be scrolled horizontally in a certain direction. |
| 9360 | * |
| 9361 | * @param direction Negative to check scrolling left, positive to check scrolling right. |
| 9362 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 9363 | */ |
| 9364 | public boolean canScrollHorizontally(int direction) { |
| 9365 | final int offset = computeHorizontalScrollOffset(); |
| 9366 | final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent(); |
| 9367 | if (range == 0) return false; |
| 9368 | if (direction < 0) { |
| 9369 | return offset > 0; |
| 9370 | } else { |
| 9371 | return offset < range - 1; |
| 9372 | } |
| 9373 | } |
| 9374 | |
| 9375 | /** |
| 9376 | * Check if this view can be scrolled vertically in a certain direction. |
| 9377 | * |
| 9378 | * @param direction Negative to check scrolling up, positive to check scrolling down. |
| 9379 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 9380 | */ |
| 9381 | public boolean canScrollVertically(int direction) { |
| 9382 | final int offset = computeVerticalScrollOffset(); |
| 9383 | final int range = computeVerticalScrollRange() - computeVerticalScrollExtent(); |
| 9384 | if (range == 0) return false; |
| 9385 | if (direction < 0) { |
| 9386 | return offset > 0; |
| 9387 | } else { |
| 9388 | return offset < range - 1; |
| 9389 | } |
| 9390 | } |
| 9391 | |
| 9392 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9393 | * <p>Request the drawing of the horizontal and the vertical scrollbar. The |
| 9394 | * scrollbars are painted only if they have been awakened first.</p> |
| 9395 | * |
| 9396 | * @param canvas the canvas on which to draw the scrollbars |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9397 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9398 | * @see #awakenScrollBars(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9399 | */ |
Romain Guy | 1d5b3a6 | 2009-11-05 18:44:12 -0800 | [diff] [blame] | 9400 | protected final void onDrawScrollBars(Canvas canvas) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9401 | // scrollbars are drawn only when the animation is running |
| 9402 | final ScrollabilityCache cache = mScrollCache; |
| 9403 | if (cache != null) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9404 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9405 | int state = cache.state; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9406 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9407 | if (state == ScrollabilityCache.OFF) { |
| 9408 | return; |
| 9409 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9410 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9411 | boolean invalidate = false; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9412 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9413 | if (state == ScrollabilityCache.FADING) { |
| 9414 | // We're fading -- get our fade interpolation |
| 9415 | if (cache.interpolatorValues == null) { |
| 9416 | cache.interpolatorValues = new float[1]; |
| 9417 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9418 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9419 | float[] values = cache.interpolatorValues; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9420 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9421 | // Stops the animation if we're done |
| 9422 | if (cache.scrollBarInterpolator.timeToValues(values) == |
| 9423 | Interpolator.Result.FREEZE_END) { |
| 9424 | cache.state = ScrollabilityCache.OFF; |
| 9425 | } else { |
| 9426 | cache.scrollBar.setAlpha(Math.round(values[0])); |
| 9427 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9428 | |
| 9429 | // This will make the scroll bars inval themselves after |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9430 | // drawing. We only want this when we're fading so that |
| 9431 | // we prevent excessive redraws |
| 9432 | invalidate = true; |
| 9433 | } else { |
| 9434 | // We're just on -- but we may have been fading before so |
| 9435 | // reset alpha |
| 9436 | cache.scrollBar.setAlpha(255); |
| 9437 | } |
| 9438 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9439 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9440 | final int viewFlags = mViewFlags; |
| 9441 | |
| 9442 | final boolean drawHorizontalScrollBar = |
| 9443 | (viewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 9444 | final boolean drawVerticalScrollBar = |
| 9445 | (viewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL |
| 9446 | && !isVerticalScrollBarHidden(); |
| 9447 | |
| 9448 | if (drawVerticalScrollBar || drawHorizontalScrollBar) { |
| 9449 | final int width = mRight - mLeft; |
| 9450 | final int height = mBottom - mTop; |
| 9451 | |
| 9452 | final ScrollBarDrawable scrollBar = cache.scrollBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9453 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9454 | final int scrollX = mScrollX; |
| 9455 | final int scrollY = mScrollY; |
| 9456 | final int inside = (viewFlags & SCROLLBARS_OUTSIDE_MASK) == 0 ? ~0 : 0; |
| 9457 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9458 | int left, top, right, bottom; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9460 | if (drawHorizontalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 9461 | int size = scrollBar.getSize(false); |
| 9462 | if (size <= 0) { |
| 9463 | size = cache.scrollBarSize; |
| 9464 | } |
| 9465 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9466 | scrollBar.setParameters(computeHorizontalScrollRange(), |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9467 | computeHorizontalScrollOffset(), |
| 9468 | computeHorizontalScrollExtent(), false); |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9469 | final int verticalScrollBarGap = drawVerticalScrollBar ? |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9470 | getVerticalScrollbarWidth() : 0; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9471 | top = scrollY + height - size - (mUserPaddingBottom & inside); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9472 | left = scrollX + (mPaddingLeft & inside); |
| 9473 | right = scrollX + width - (mUserPaddingRight & inside) - verticalScrollBarGap; |
| 9474 | bottom = top + size; |
| 9475 | onDrawHorizontalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 9476 | if (invalidate) { |
| 9477 | invalidate(left, top, right, bottom); |
| 9478 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9479 | } |
| 9480 | |
| 9481 | if (drawVerticalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 9482 | int size = scrollBar.getSize(true); |
| 9483 | if (size <= 0) { |
| 9484 | size = cache.scrollBarSize; |
| 9485 | } |
| 9486 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9487 | scrollBar.setParameters(computeVerticalScrollRange(), |
| 9488 | computeVerticalScrollOffset(), |
| 9489 | computeVerticalScrollExtent(), true); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 9490 | switch (mVerticalScrollbarPosition) { |
| 9491 | default: |
| 9492 | case SCROLLBAR_POSITION_DEFAULT: |
| 9493 | case SCROLLBAR_POSITION_RIGHT: |
| 9494 | left = scrollX + width - size - (mUserPaddingRight & inside); |
| 9495 | break; |
| 9496 | case SCROLLBAR_POSITION_LEFT: |
| 9497 | left = scrollX + (mUserPaddingLeft & inside); |
| 9498 | break; |
| 9499 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9500 | top = scrollY + (mPaddingTop & inside); |
| 9501 | right = left + size; |
| 9502 | bottom = scrollY + height - (mUserPaddingBottom & inside); |
| 9503 | onDrawVerticalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 9504 | if (invalidate) { |
| 9505 | invalidate(left, top, right, bottom); |
| 9506 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9507 | } |
| 9508 | } |
| 9509 | } |
| 9510 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 9511 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9512 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 9513 | * 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] | 9514 | * FastScroller is visible. |
| 9515 | * @return whether to temporarily hide the vertical scrollbar |
| 9516 | * @hide |
| 9517 | */ |
| 9518 | protected boolean isVerticalScrollBarHidden() { |
| 9519 | return false; |
| 9520 | } |
| 9521 | |
| 9522 | /** |
| 9523 | * <p>Draw the horizontal scrollbar if |
| 9524 | * {@link #isHorizontalScrollBarEnabled()} returns true.</p> |
| 9525 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9526 | * @param canvas the canvas on which to draw the scrollbar |
| 9527 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9528 | * |
| 9529 | * @see #isHorizontalScrollBarEnabled() |
| 9530 | * @see #computeHorizontalScrollRange() |
| 9531 | * @see #computeHorizontalScrollExtent() |
| 9532 | * @see #computeHorizontalScrollOffset() |
| 9533 | * @see android.widget.ScrollBarDrawable |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9534 | * @hide |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 9535 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 9536 | protected void onDrawHorizontalScrollBar(Canvas canvas, Drawable scrollBar, |
| 9537 | int l, int t, int r, int b) { |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 9538 | scrollBar.setBounds(l, t, r, b); |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 9539 | scrollBar.draw(canvas); |
| 9540 | } |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9541 | |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 9542 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9543 | * <p>Draw the vertical scrollbar if {@link #isVerticalScrollBarEnabled()} |
| 9544 | * returns true.</p> |
| 9545 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9546 | * @param canvas the canvas on which to draw the scrollbar |
| 9547 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9548 | * |
| 9549 | * @see #isVerticalScrollBarEnabled() |
| 9550 | * @see #computeVerticalScrollRange() |
| 9551 | * @see #computeVerticalScrollExtent() |
| 9552 | * @see #computeVerticalScrollOffset() |
| 9553 | * @see android.widget.ScrollBarDrawable |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9554 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9555 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 9556 | protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, |
| 9557 | int l, int t, int r, int b) { |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9558 | scrollBar.setBounds(l, t, r, b); |
| 9559 | scrollBar.draw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9560 | } |
| 9561 | |
| 9562 | /** |
| 9563 | * Implement this to do your drawing. |
| 9564 | * |
| 9565 | * @param canvas the canvas on which the background will be drawn |
| 9566 | */ |
| 9567 | protected void onDraw(Canvas canvas) { |
| 9568 | } |
| 9569 | |
| 9570 | /* |
| 9571 | * Caller is responsible for calling requestLayout if necessary. |
| 9572 | * (This allows addViewInLayout to not request a new layout.) |
| 9573 | */ |
| 9574 | void assignParent(ViewParent parent) { |
| 9575 | if (mParent == null) { |
| 9576 | mParent = parent; |
| 9577 | } else if (parent == null) { |
| 9578 | mParent = null; |
| 9579 | } else { |
| 9580 | throw new RuntimeException("view " + this + " being added, but" |
| 9581 | + " it already has a parent"); |
| 9582 | } |
| 9583 | } |
| 9584 | |
| 9585 | /** |
| 9586 | * This is called when the view is attached to a window. At this point it |
| 9587 | * has a Surface and will start drawing. Note that this function is |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9588 | * guaranteed to be called before {@link #onDraw(android.graphics.Canvas)}, |
| 9589 | * however it may be called any time before the first onDraw -- including |
| 9590 | * before or after {@link #onMeasure(int, int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9591 | * |
| 9592 | * @see #onDetachedFromWindow() |
| 9593 | */ |
| 9594 | protected void onAttachedToWindow() { |
| 9595 | if ((mPrivateFlags & REQUEST_TRANSPARENT_REGIONS) != 0) { |
| 9596 | mParent.requestTransparentRegion(this); |
| 9597 | } |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 9598 | if ((mPrivateFlags & AWAKEN_SCROLL_BARS_ON_ATTACH) != 0) { |
| 9599 | initialAwakenScrollBars(); |
| 9600 | mPrivateFlags &= ~AWAKEN_SCROLL_BARS_ON_ATTACH; |
| 9601 | } |
Chet Haase | a9b61ac | 2010-12-20 07:40:25 -0800 | [diff] [blame] | 9602 | jumpDrawablesToCurrentState(); |
Fabrice Di Meglio | a646145 | 2011-08-19 15:42:04 -0700 | [diff] [blame] | 9603 | // Order is important here: LayoutDirection MUST be resolved before Padding |
| 9604 | // and TextDirection |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9605 | resolveLayoutDirectionIfNeeded(); |
| 9606 | resolvePadding(); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 9607 | resolveTextDirection(); |
Amith Yamasani | 4503c8d | 2011-06-17 12:36:14 -0700 | [diff] [blame] | 9608 | if (isFocused()) { |
| 9609 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 9610 | imm.focusIn(this); |
| 9611 | } |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 9612 | } |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 9613 | |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 9614 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9615 | * Resolve and cache the layout direction. LTR is set initially. This is implicitly supposing |
| 9616 | * 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] | 9617 | */ |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9618 | private void resolveLayoutDirectionIfNeeded() { |
| 9619 | // Do not resolve if it is not needed |
| 9620 | if ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED) == LAYOUT_DIRECTION_RESOLVED) return; |
| 9621 | |
| 9622 | // Clear any previous layout direction resolution |
| 9623 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_RTL; |
| 9624 | |
Fabrice Di Meglio | 4b60c30 | 2011-08-17 16:56:55 -0700 | [diff] [blame] | 9625 | // Reset also TextDirection as a change into LayoutDirection may impact the selected |
| 9626 | // TextDirectionHeuristic |
| 9627 | resetResolvedTextDirection(); |
| 9628 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9629 | // Set resolved depending on layout direction |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 9630 | switch (getLayoutDirection()) { |
| 9631 | case LAYOUT_DIRECTION_INHERIT: |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 9632 | // We cannot do the resolution if there is no parent |
| 9633 | if (mParent == null) return; |
| 9634 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 9635 | // 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] | 9636 | if (mParent instanceof ViewGroup) { |
| 9637 | ViewGroup viewGroup = ((ViewGroup) mParent); |
| 9638 | |
| 9639 | // Check if the parent view group can resolve |
| 9640 | if (! viewGroup.canResolveLayoutDirection()) { |
| 9641 | return; |
| 9642 | } |
| 9643 | if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
| 9644 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
| 9645 | } |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 9646 | } |
| 9647 | break; |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 9648 | case LAYOUT_DIRECTION_RTL: |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9649 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 9650 | break; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 9651 | case LAYOUT_DIRECTION_LOCALE: |
| 9652 | if(isLayoutDirectionRtl(Locale.getDefault())) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9653 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 9654 | } |
| 9655 | break; |
| 9656 | default: |
| 9657 | // Nothing to do, LTR by default |
| 9658 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9659 | |
| 9660 | // Set to resolved |
| 9661 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED; |
| 9662 | } |
| 9663 | |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 9664 | /** |
| 9665 | * @hide |
| 9666 | */ |
| 9667 | protected void resolvePadding() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9668 | // If the user specified the absolute padding (either with android:padding or |
| 9669 | // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise |
| 9670 | // use the default padding or the padding from the background drawable |
| 9671 | // (stored at this point in mPadding*) |
| 9672 | switch (getResolvedLayoutDirection()) { |
| 9673 | case LAYOUT_DIRECTION_RTL: |
| 9674 | // Start user padding override Right user padding. Otherwise, if Right user |
| 9675 | // padding is not defined, use the default Right padding. If Right user padding |
| 9676 | // is defined, just use it. |
| 9677 | if (mUserPaddingStart >= 0) { |
| 9678 | mUserPaddingRight = mUserPaddingStart; |
| 9679 | } else if (mUserPaddingRight < 0) { |
| 9680 | mUserPaddingRight = mPaddingRight; |
| 9681 | } |
| 9682 | if (mUserPaddingEnd >= 0) { |
| 9683 | mUserPaddingLeft = mUserPaddingEnd; |
| 9684 | } else if (mUserPaddingLeft < 0) { |
| 9685 | mUserPaddingLeft = mPaddingLeft; |
| 9686 | } |
| 9687 | break; |
| 9688 | case LAYOUT_DIRECTION_LTR: |
| 9689 | default: |
| 9690 | // Start user padding override Left user padding. Otherwise, if Left user |
| 9691 | // padding is not defined, use the default left padding. If Left user padding |
| 9692 | // is defined, just use it. |
Fabrice Di Meglio | f3e1a93 | 2011-07-15 17:15:39 -0700 | [diff] [blame] | 9693 | if (mUserPaddingStart >= 0) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9694 | mUserPaddingLeft = mUserPaddingStart; |
| 9695 | } else if (mUserPaddingLeft < 0) { |
| 9696 | mUserPaddingLeft = mPaddingLeft; |
| 9697 | } |
Fabrice Di Meglio | f3e1a93 | 2011-07-15 17:15:39 -0700 | [diff] [blame] | 9698 | if (mUserPaddingEnd >= 0) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9699 | mUserPaddingRight = mUserPaddingEnd; |
| 9700 | } else if (mUserPaddingRight < 0) { |
| 9701 | mUserPaddingRight = mPaddingRight; |
| 9702 | } |
| 9703 | } |
| 9704 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9705 | mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom; |
| 9706 | |
| 9707 | recomputePadding(); |
| 9708 | } |
| 9709 | |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 9710 | /** |
| 9711 | * Return true if layout direction resolution can be done |
| 9712 | * |
| 9713 | * @hide |
| 9714 | */ |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 9715 | protected boolean canResolveLayoutDirection() { |
| 9716 | switch (getLayoutDirection()) { |
| 9717 | case LAYOUT_DIRECTION_INHERIT: |
| 9718 | return (mParent != null); |
| 9719 | default: |
| 9720 | return true; |
| 9721 | } |
| 9722 | } |
| 9723 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9724 | /** |
Doug Felt | c0ccf0c | 2011-06-23 16:13:18 -0700 | [diff] [blame] | 9725 | * Reset the resolved layout direction. |
| 9726 | * |
| 9727 | * Subclasses need to override this method to clear cached information that depends on the |
| 9728 | * resolved layout direction, or to inform child views that inherit their layout direction. |
| 9729 | * Overrides must also call the superclass implementation at the start of their implementation. |
| 9730 | * |
| 9731 | * @hide |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9732 | */ |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 9733 | protected void resetResolvedLayoutDirection() { |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 9734 | // Reset the current View resolution |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9735 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 9736 | } |
| 9737 | |
| 9738 | /** |
| 9739 | * Check if a Locale is corresponding to a RTL script. |
| 9740 | * |
| 9741 | * @param locale Locale to check |
| 9742 | * @return true if a Locale is corresponding to a RTL script. |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 9743 | * |
| 9744 | * @hide |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 9745 | */ |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 9746 | protected static boolean isLayoutDirectionRtl(Locale locale) { |
Fabrice Di Meglio | a47f45e | 2011-06-15 14:22:12 -0700 | [diff] [blame] | 9747 | return (LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE == |
| 9748 | LocaleUtil.getLayoutDirectionFromLocale(locale)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9749 | } |
| 9750 | |
| 9751 | /** |
| 9752 | * This is called when the view is detached from a window. At this point it |
| 9753 | * no longer has a surface for drawing. |
| 9754 | * |
| 9755 | * @see #onAttachedToWindow() |
| 9756 | */ |
| 9757 | protected void onDetachedFromWindow() { |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 9758 | mPrivateFlags &= ~CANCEL_NEXT_UP_EVENT; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9759 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 9760 | removeUnsetPressCallback(); |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 9761 | removeLongPressCallback(); |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 9762 | removePerformClickCallback(); |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 9763 | removeSendViewScrolledAccessibilityEventCallback(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9764 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9765 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9766 | |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 9767 | destroyLayer(); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 9768 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9769 | if (mDisplayList != null) { |
| 9770 | mDisplayList.invalidate(); |
| 9771 | } |
| 9772 | |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 9773 | if (mAttachInfo != null) { |
| 9774 | mAttachInfo.mHandler.removeMessages(AttachInfo.INVALIDATE_MSG, this); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 9775 | } |
| 9776 | |
Patrick Dubroy | ec84c3a | 2011-01-13 17:55:37 -0800 | [diff] [blame] | 9777 | mCurrentAnimation = null; |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 9778 | |
| 9779 | resetResolvedLayoutDirection(); |
| 9780 | resetResolvedTextDirection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9781 | } |
| 9782 | |
| 9783 | /** |
| 9784 | * @return The number of times this view has been attached to a window |
| 9785 | */ |
| 9786 | protected int getWindowAttachCount() { |
| 9787 | return mWindowAttachCount; |
| 9788 | } |
| 9789 | |
| 9790 | /** |
| 9791 | * Retrieve a unique token identifying the window this view is attached to. |
| 9792 | * @return Return the window's token for use in |
| 9793 | * {@link WindowManager.LayoutParams#token WindowManager.LayoutParams.token}. |
| 9794 | */ |
| 9795 | public IBinder getWindowToken() { |
| 9796 | return mAttachInfo != null ? mAttachInfo.mWindowToken : null; |
| 9797 | } |
| 9798 | |
| 9799 | /** |
| 9800 | * Retrieve a unique token identifying the top-level "real" window of |
| 9801 | * the window that this view is attached to. That is, this is like |
| 9802 | * {@link #getWindowToken}, except if the window this view in is a panel |
| 9803 | * window (attached to another containing window), then the token of |
| 9804 | * the containing window is returned instead. |
| 9805 | * |
| 9806 | * @return Returns the associated window token, either |
| 9807 | * {@link #getWindowToken()} or the containing window's token. |
| 9808 | */ |
| 9809 | public IBinder getApplicationWindowToken() { |
| 9810 | AttachInfo ai = mAttachInfo; |
| 9811 | if (ai != null) { |
| 9812 | IBinder appWindowToken = ai.mPanelParentWindowToken; |
| 9813 | if (appWindowToken == null) { |
| 9814 | appWindowToken = ai.mWindowToken; |
| 9815 | } |
| 9816 | return appWindowToken; |
| 9817 | } |
| 9818 | return null; |
| 9819 | } |
| 9820 | |
| 9821 | /** |
| 9822 | * Retrieve private session object this view hierarchy is using to |
| 9823 | * communicate with the window manager. |
| 9824 | * @return the session object to communicate with the window manager |
| 9825 | */ |
| 9826 | /*package*/ IWindowSession getWindowSession() { |
| 9827 | return mAttachInfo != null ? mAttachInfo.mSession : null; |
| 9828 | } |
| 9829 | |
| 9830 | /** |
| 9831 | * @param info the {@link android.view.View.AttachInfo} to associated with |
| 9832 | * this view |
| 9833 | */ |
| 9834 | void dispatchAttachedToWindow(AttachInfo info, int visibility) { |
| 9835 | //System.out.println("Attached! " + this); |
| 9836 | mAttachInfo = info; |
| 9837 | mWindowAttachCount++; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 9838 | // We will need to evaluate the drawable state at least once. |
| 9839 | mPrivateFlags |= DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9840 | if (mFloatingTreeObserver != null) { |
| 9841 | info.mTreeObserver.merge(mFloatingTreeObserver); |
| 9842 | mFloatingTreeObserver = null; |
| 9843 | } |
| 9844 | if ((mPrivateFlags&SCROLL_CONTAINER) != 0) { |
| 9845 | mAttachInfo.mScrollContainers.add(this); |
| 9846 | mPrivateFlags |= SCROLL_CONTAINER_ADDED; |
| 9847 | } |
| 9848 | performCollectViewAttributes(visibility); |
| 9849 | onAttachedToWindow(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 9850 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 9851 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 9852 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 9853 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 9854 | if (listeners != null && listeners.size() > 0) { |
| 9855 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 9856 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 9857 | // could mutate the list by calling the various add/remove methods. This prevents |
| 9858 | // the array from being modified while we iterate it. |
| 9859 | for (OnAttachStateChangeListener listener : listeners) { |
| 9860 | listener.onViewAttachedToWindow(this); |
| 9861 | } |
| 9862 | } |
| 9863 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9864 | int vis = info.mWindowVisibility; |
| 9865 | if (vis != GONE) { |
| 9866 | onWindowVisibilityChanged(vis); |
| 9867 | } |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 9868 | if ((mPrivateFlags&DRAWABLE_STATE_DIRTY) != 0) { |
| 9869 | // If nobody has evaluated the drawable state yet, then do it now. |
| 9870 | refreshDrawableState(); |
| 9871 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9872 | } |
| 9873 | |
| 9874 | void dispatchDetachedFromWindow() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9875 | AttachInfo info = mAttachInfo; |
| 9876 | if (info != null) { |
| 9877 | int vis = info.mWindowVisibility; |
| 9878 | if (vis != GONE) { |
| 9879 | onWindowVisibilityChanged(GONE); |
| 9880 | } |
| 9881 | } |
| 9882 | |
| 9883 | onDetachedFromWindow(); |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 9884 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 9885 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 9886 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 9887 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 9888 | if (listeners != null && listeners.size() > 0) { |
| 9889 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 9890 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 9891 | // could mutate the list by calling the various add/remove methods. This prevents |
| 9892 | // the array from being modified while we iterate it. |
| 9893 | for (OnAttachStateChangeListener listener : listeners) { |
| 9894 | listener.onViewDetachedFromWindow(this); |
| 9895 | } |
| 9896 | } |
| 9897 | |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 9898 | if ((mPrivateFlags & SCROLL_CONTAINER_ADDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9899 | mAttachInfo.mScrollContainers.remove(this); |
| 9900 | mPrivateFlags &= ~SCROLL_CONTAINER_ADDED; |
| 9901 | } |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 9902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9903 | mAttachInfo = null; |
| 9904 | } |
| 9905 | |
| 9906 | /** |
| 9907 | * Store this view hierarchy's frozen state into the given container. |
| 9908 | * |
| 9909 | * @param container The SparseArray in which to save the view's state. |
| 9910 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9911 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 9912 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 9913 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9914 | */ |
| 9915 | public void saveHierarchyState(SparseArray<Parcelable> container) { |
| 9916 | dispatchSaveInstanceState(container); |
| 9917 | } |
| 9918 | |
| 9919 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9920 | * Called by {@link #saveHierarchyState(android.util.SparseArray)} to store the state for |
| 9921 | * this view and its children. May be overridden to modify how freezing happens to a |
| 9922 | * 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] | 9923 | * |
| 9924 | * @param container The SparseArray in which to save the view's state. |
| 9925 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9926 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 9927 | * @see #saveHierarchyState(android.util.SparseArray) |
| 9928 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9929 | */ |
| 9930 | protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { |
| 9931 | if (mID != NO_ID && (mViewFlags & SAVE_DISABLED_MASK) == 0) { |
| 9932 | mPrivateFlags &= ~SAVE_STATE_CALLED; |
| 9933 | Parcelable state = onSaveInstanceState(); |
| 9934 | if ((mPrivateFlags & SAVE_STATE_CALLED) == 0) { |
| 9935 | throw new IllegalStateException( |
| 9936 | "Derived class did not call super.onSaveInstanceState()"); |
| 9937 | } |
| 9938 | if (state != null) { |
| 9939 | // Log.i("View", "Freezing #" + Integer.toHexString(mID) |
| 9940 | // + ": " + state); |
| 9941 | container.put(mID, state); |
| 9942 | } |
| 9943 | } |
| 9944 | } |
| 9945 | |
| 9946 | /** |
| 9947 | * Hook allowing a view to generate a representation of its internal state |
| 9948 | * that can later be used to create a new instance with that same state. |
| 9949 | * This state should only contain information that is not persistent or can |
| 9950 | * not be reconstructed later. For example, you will never store your |
| 9951 | * current position on screen because that will be computed again when a |
| 9952 | * new instance of the view is placed in its view hierarchy. |
| 9953 | * <p> |
| 9954 | * Some examples of things you may store here: the current cursor position |
| 9955 | * in a text view (but usually not the text itself since that is stored in a |
| 9956 | * content provider or other persistent storage), the currently selected |
| 9957 | * item in a list view. |
| 9958 | * |
| 9959 | * @return Returns a Parcelable object containing the view's current dynamic |
| 9960 | * state, or null if there is nothing interesting to save. The |
| 9961 | * default implementation returns null. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9962 | * @see #onRestoreInstanceState(android.os.Parcelable) |
| 9963 | * @see #saveHierarchyState(android.util.SparseArray) |
| 9964 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9965 | * @see #setSaveEnabled(boolean) |
| 9966 | */ |
| 9967 | protected Parcelable onSaveInstanceState() { |
| 9968 | mPrivateFlags |= SAVE_STATE_CALLED; |
| 9969 | return BaseSavedState.EMPTY_STATE; |
| 9970 | } |
| 9971 | |
| 9972 | /** |
| 9973 | * Restore this view hierarchy's frozen state from the given container. |
| 9974 | * |
| 9975 | * @param container The SparseArray which holds previously frozen states. |
| 9976 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9977 | * @see #saveHierarchyState(android.util.SparseArray) |
| 9978 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 9979 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9980 | */ |
| 9981 | public void restoreHierarchyState(SparseArray<Parcelable> container) { |
| 9982 | dispatchRestoreInstanceState(container); |
| 9983 | } |
| 9984 | |
| 9985 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9986 | * Called by {@link #restoreHierarchyState(android.util.SparseArray)} to retrieve the |
| 9987 | * state for this view and its children. May be overridden to modify how restoring |
| 9988 | * happens to a view's children; for example, some views may want to not store state |
| 9989 | * for their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9990 | * |
| 9991 | * @param container The SparseArray which holds previously saved state. |
| 9992 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9993 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 9994 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 9995 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9996 | */ |
| 9997 | protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 9998 | if (mID != NO_ID) { |
| 9999 | Parcelable state = container.get(mID); |
| 10000 | if (state != null) { |
| 10001 | // Log.i("View", "Restoreing #" + Integer.toHexString(mID) |
| 10002 | // + ": " + state); |
| 10003 | mPrivateFlags &= ~SAVE_STATE_CALLED; |
| 10004 | onRestoreInstanceState(state); |
| 10005 | if ((mPrivateFlags & SAVE_STATE_CALLED) == 0) { |
| 10006 | throw new IllegalStateException( |
| 10007 | "Derived class did not call super.onRestoreInstanceState()"); |
| 10008 | } |
| 10009 | } |
| 10010 | } |
| 10011 | } |
| 10012 | |
| 10013 | /** |
| 10014 | * Hook allowing a view to re-apply a representation of its internal state that had previously |
| 10015 | * been generated by {@link #onSaveInstanceState}. This function will never be called with a |
| 10016 | * null state. |
| 10017 | * |
| 10018 | * @param state The frozen state that had previously been returned by |
| 10019 | * {@link #onSaveInstanceState}. |
| 10020 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10021 | * @see #onSaveInstanceState() |
| 10022 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 10023 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10024 | */ |
| 10025 | protected void onRestoreInstanceState(Parcelable state) { |
| 10026 | mPrivateFlags |= SAVE_STATE_CALLED; |
| 10027 | if (state != BaseSavedState.EMPTY_STATE && state != null) { |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 10028 | throw new IllegalArgumentException("Wrong state class, expecting View State but " |
| 10029 | + "received " + state.getClass().toString() + " instead. This usually happens " |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10030 | + "when two views of different type have the same id in the same hierarchy. " |
| 10031 | + "This view's id is " + ViewDebug.resolveId(mContext, getId()) + ". Make sure " |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 10032 | + "other views do not use the same id."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10033 | } |
| 10034 | } |
| 10035 | |
| 10036 | /** |
| 10037 | * <p>Return the time at which the drawing of the view hierarchy started.</p> |
| 10038 | * |
| 10039 | * @return the drawing start time in milliseconds |
| 10040 | */ |
| 10041 | public long getDrawingTime() { |
| 10042 | return mAttachInfo != null ? mAttachInfo.mDrawingTime : 0; |
| 10043 | } |
| 10044 | |
| 10045 | /** |
| 10046 | * <p>Enables or disables the duplication of the parent's state into this view. When |
| 10047 | * duplication is enabled, this view gets its drawable state from its parent rather |
| 10048 | * than from its own internal properties.</p> |
| 10049 | * |
| 10050 | * <p>Note: in the current implementation, setting this property to true after the |
| 10051 | * view was added to a ViewGroup might have no effect at all. This property should |
| 10052 | * always be used from XML or set to true before adding this view to a ViewGroup.</p> |
| 10053 | * |
| 10054 | * <p>Note: if this view's parent addStateFromChildren property is enabled and this |
| 10055 | * property is enabled, an exception will be thrown.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10056 | * |
Gilles Debunne | fb81703 | 2011-01-13 13:52:49 -0800 | [diff] [blame] | 10057 | * <p>Note: if the child view uses and updates additionnal states which are unknown to the |
| 10058 | * 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] | 10059 | * |
| 10060 | * @param enabled True to enable duplication of the parent's drawable state, false |
| 10061 | * to disable it. |
| 10062 | * |
| 10063 | * @see #getDrawableState() |
| 10064 | * @see #isDuplicateParentStateEnabled() |
| 10065 | */ |
| 10066 | public void setDuplicateParentStateEnabled(boolean enabled) { |
| 10067 | setFlags(enabled ? DUPLICATE_PARENT_STATE : 0, DUPLICATE_PARENT_STATE); |
| 10068 | } |
| 10069 | |
| 10070 | /** |
| 10071 | * <p>Indicates whether this duplicates its drawable state from its parent.</p> |
| 10072 | * |
| 10073 | * @return True if this view's drawable state is duplicated from the parent, |
| 10074 | * false otherwise |
| 10075 | * |
| 10076 | * @see #getDrawableState() |
| 10077 | * @see #setDuplicateParentStateEnabled(boolean) |
| 10078 | */ |
| 10079 | public boolean isDuplicateParentStateEnabled() { |
| 10080 | return (mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE; |
| 10081 | } |
| 10082 | |
| 10083 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10084 | * <p>Specifies the type of layer backing this view. The layer can be |
| 10085 | * {@link #LAYER_TYPE_NONE disabled}, {@link #LAYER_TYPE_SOFTWARE software} or |
| 10086 | * {@link #LAYER_TYPE_HARDWARE hardware}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10087 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10088 | * <p>A layer is associated with an optional {@link android.graphics.Paint} |
| 10089 | * instance that controls how the layer is composed on screen. The following |
| 10090 | * properties of the paint are taken into account when composing the layer:</p> |
| 10091 | * <ul> |
| 10092 | * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> |
| 10093 | * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> |
| 10094 | * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> |
| 10095 | * </ul> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10096 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10097 | * <p>If this view has an alpha value set to < 1.0 by calling |
| 10098 | * {@link #setAlpha(float)}, the alpha value of the layer's paint is replaced by |
| 10099 | * this view's alpha value. Calling {@link #setAlpha(float)} is therefore |
| 10100 | * equivalent to setting a hardware layer on this view and providing a paint with |
| 10101 | * the desired alpha value.<p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10102 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10103 | * <p>Refer to the documentation of {@link #LAYER_TYPE_NONE disabled}, |
| 10104 | * {@link #LAYER_TYPE_SOFTWARE software} and {@link #LAYER_TYPE_HARDWARE hardware} |
| 10105 | * for more information on when and how to use layers.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10106 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10107 | * @param layerType The ype of layer to use with this view, must be one of |
| 10108 | * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 10109 | * {@link #LAYER_TYPE_HARDWARE} |
| 10110 | * @param paint The paint used to compose the layer. This argument is optional |
| 10111 | * and can be null. It is ignored when the layer type is |
| 10112 | * {@link #LAYER_TYPE_NONE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10113 | * |
| 10114 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10115 | * @see #LAYER_TYPE_NONE |
| 10116 | * @see #LAYER_TYPE_SOFTWARE |
| 10117 | * @see #LAYER_TYPE_HARDWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10118 | * @see #setAlpha(float) |
| 10119 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10120 | * @attr ref android.R.styleable#View_layerType |
| 10121 | */ |
| 10122 | public void setLayerType(int layerType, Paint paint) { |
| 10123 | if (layerType < LAYER_TYPE_NONE || layerType > LAYER_TYPE_HARDWARE) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10124 | 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] | 10125 | + "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE"); |
| 10126 | } |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10127 | |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 10128 | if (layerType == mLayerType) { |
| 10129 | if (layerType != LAYER_TYPE_NONE && paint != mLayerPaint) { |
| 10130 | mLayerPaint = paint == null ? new Paint() : paint; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10131 | invalidateParentCaches(); |
| 10132 | invalidate(true); |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 10133 | } |
| 10134 | return; |
| 10135 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10136 | |
| 10137 | // Destroy any previous software drawing cache if needed |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10138 | switch (mLayerType) { |
Chet Haase | 6f33e81 | 2011-05-17 12:42:19 -0700 | [diff] [blame] | 10139 | case LAYER_TYPE_HARDWARE: |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10140 | destroyLayer(); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 10141 | // fall through - non-accelerated views may use software layer mechanism instead |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10142 | case LAYER_TYPE_SOFTWARE: |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10143 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10144 | break; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10145 | default: |
| 10146 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10147 | } |
| 10148 | |
| 10149 | mLayerType = layerType; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 10150 | final boolean layerDisabled = mLayerType == LAYER_TYPE_NONE; |
| 10151 | mLayerPaint = layerDisabled ? null : (paint == null ? new Paint() : paint); |
| 10152 | mLocalDirtyRect = layerDisabled ? null : new Rect(); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10153 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10154 | invalidateParentCaches(); |
| 10155 | invalidate(true); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10156 | } |
| 10157 | |
| 10158 | /** |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 10159 | * Indicates whether this view has a static layer. A view with layer type |
| 10160 | * {@link #LAYER_TYPE_NONE} is a static layer. Other types of layers are |
| 10161 | * dynamic. |
| 10162 | */ |
| 10163 | boolean hasStaticLayer() { |
| 10164 | return mLayerType == LAYER_TYPE_NONE; |
| 10165 | } |
| 10166 | |
| 10167 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10168 | * Indicates what type of layer is currently associated with this view. By default |
| 10169 | * a view does not have a layer, and the layer type is {@link #LAYER_TYPE_NONE}. |
| 10170 | * Refer to the documentation of {@link #setLayerType(int, android.graphics.Paint)} |
| 10171 | * for more information on the different types of layers. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10172 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10173 | * @return {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 10174 | * {@link #LAYER_TYPE_HARDWARE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10175 | * |
| 10176 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10177 | * @see #buildLayer() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10178 | * @see #LAYER_TYPE_NONE |
| 10179 | * @see #LAYER_TYPE_SOFTWARE |
| 10180 | * @see #LAYER_TYPE_HARDWARE |
| 10181 | */ |
| 10182 | public int getLayerType() { |
| 10183 | return mLayerType; |
| 10184 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10185 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10186 | /** |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10187 | * Forces this view's layer to be created and this view to be rendered |
| 10188 | * into its layer. If this view's layer type is set to {@link #LAYER_TYPE_NONE}, |
| 10189 | * invoking this method will have no effect. |
| 10190 | * |
| 10191 | * This method can for instance be used to render a view into its layer before |
| 10192 | * starting an animation. If this view is complex, rendering into the layer |
| 10193 | * before starting the animation will avoid skipping frames. |
| 10194 | * |
| 10195 | * @throws IllegalStateException If this view is not attached to a window |
| 10196 | * |
| 10197 | * @see #setLayerType(int, android.graphics.Paint) |
| 10198 | */ |
| 10199 | public void buildLayer() { |
| 10200 | if (mLayerType == LAYER_TYPE_NONE) return; |
| 10201 | |
| 10202 | if (mAttachInfo == null) { |
| 10203 | throw new IllegalStateException("This view must be attached to a window first"); |
| 10204 | } |
| 10205 | |
| 10206 | switch (mLayerType) { |
| 10207 | case LAYER_TYPE_HARDWARE: |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 10208 | if (mAttachInfo.mHardwareRenderer != null && |
| 10209 | mAttachInfo.mHardwareRenderer.isEnabled() && |
| 10210 | mAttachInfo.mHardwareRenderer.validate()) { |
| 10211 | getHardwareLayer(); |
| 10212 | } |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10213 | break; |
| 10214 | case LAYER_TYPE_SOFTWARE: |
| 10215 | buildDrawingCache(true); |
| 10216 | break; |
| 10217 | } |
| 10218 | } |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10219 | |
| 10220 | // Make sure the HardwareRenderer.validate() was invoked before calling this method |
| 10221 | void flushLayer() { |
| 10222 | if (mLayerType == LAYER_TYPE_HARDWARE && mHardwareLayer != null) { |
| 10223 | mHardwareLayer.flush(); |
| 10224 | } |
| 10225 | } |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10226 | |
| 10227 | /** |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10228 | * <p>Returns a hardware layer that can be used to draw this view again |
| 10229 | * without executing its draw method.</p> |
| 10230 | * |
| 10231 | * @return A HardwareLayer ready to render, or null if an error occurred. |
| 10232 | */ |
Romain Guy | 5e7f766 | 2011-01-24 22:35:56 -0800 | [diff] [blame] | 10233 | HardwareLayer getHardwareLayer() { |
Romain Guy | ea83503 | 2011-07-28 19:24:37 -0700 | [diff] [blame] | 10234 | if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null || |
| 10235 | !mAttachInfo.mHardwareRenderer.isEnabled()) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10236 | return null; |
| 10237 | } |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10238 | |
| 10239 | if (!mAttachInfo.mHardwareRenderer.validate()) return null; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10240 | |
| 10241 | final int width = mRight - mLeft; |
| 10242 | final int height = mBottom - mTop; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10243 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10244 | if (width == 0 || height == 0) { |
| 10245 | return null; |
| 10246 | } |
| 10247 | |
| 10248 | if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || mHardwareLayer == null) { |
| 10249 | if (mHardwareLayer == null) { |
| 10250 | mHardwareLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer( |
| 10251 | width, height, isOpaque()); |
Romain Guy | 62687ec | 2011-02-02 15:44:19 -0800 | [diff] [blame] | 10252 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10253 | } else if (mHardwareLayer.getWidth() != width || mHardwareLayer.getHeight() != height) { |
| 10254 | mHardwareLayer.resize(width, height); |
Romain Guy | 62687ec | 2011-02-02 15:44:19 -0800 | [diff] [blame] | 10255 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10256 | } |
| 10257 | |
Romain Guy | 5cd5c3f | 2011-10-17 17:10:02 -0700 | [diff] [blame] | 10258 | // The layer is not valid if the underlying GPU resources cannot be allocated |
| 10259 | if (!mHardwareLayer.isValid()) { |
| 10260 | return null; |
| 10261 | } |
| 10262 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 10263 | HardwareCanvas currentCanvas = mAttachInfo.mHardwareCanvas; |
Romain Guy | 5e7f766 | 2011-01-24 22:35:56 -0800 | [diff] [blame] | 10264 | final HardwareCanvas canvas = mHardwareLayer.start(currentCanvas); |
Romain Guy | 5cd5c3f | 2011-10-17 17:10:02 -0700 | [diff] [blame] | 10265 | |
| 10266 | // Make sure all the GPU resources have been properly allocated |
| 10267 | if (canvas == null) { |
| 10268 | mHardwareLayer.end(currentCanvas); |
| 10269 | return null; |
| 10270 | } |
| 10271 | |
Romain Guy | 5e7f766 | 2011-01-24 22:35:56 -0800 | [diff] [blame] | 10272 | mAttachInfo.mHardwareCanvas = canvas; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10273 | try { |
| 10274 | canvas.setViewport(width, height); |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 10275 | canvas.onPreDraw(mLocalDirtyRect); |
Romain Guy | 62687ec | 2011-02-02 15:44:19 -0800 | [diff] [blame] | 10276 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10277 | |
Chet Haase | 88172fe | 2011-03-07 17:36:33 -0800 | [diff] [blame] | 10278 | final int restoreCount = canvas.save(); |
| 10279 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10280 | computeScroll(); |
| 10281 | canvas.translate(-mScrollX, -mScrollY); |
| 10282 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10283 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10284 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10285 | // Fast path for layouts with no backgrounds |
| 10286 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 10287 | mPrivateFlags &= ~DIRTY_MASK; |
| 10288 | dispatchDraw(canvas); |
| 10289 | } else { |
| 10290 | draw(canvas); |
| 10291 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10292 | |
Chet Haase | 88172fe | 2011-03-07 17:36:33 -0800 | [diff] [blame] | 10293 | canvas.restoreToCount(restoreCount); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10294 | } finally { |
| 10295 | canvas.onPostDraw(); |
Romain Guy | 5e7f766 | 2011-01-24 22:35:56 -0800 | [diff] [blame] | 10296 | mHardwareLayer.end(currentCanvas); |
| 10297 | mAttachInfo.mHardwareCanvas = currentCanvas; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10298 | } |
| 10299 | } |
| 10300 | |
| 10301 | return mHardwareLayer; |
| 10302 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10303 | |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 10304 | /** |
| 10305 | * Destroys this View's hardware layer if possible. |
| 10306 | * |
| 10307 | * @return True if the layer was destroyed, false otherwise. |
| 10308 | * |
| 10309 | * @see #setLayerType(int, android.graphics.Paint) |
| 10310 | * @see #LAYER_TYPE_HARDWARE |
| 10311 | */ |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 10312 | boolean destroyLayer() { |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10313 | if (mHardwareLayer != null) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10314 | AttachInfo info = mAttachInfo; |
| 10315 | if (info != null && info.mHardwareRenderer != null && |
| 10316 | info.mHardwareRenderer.isEnabled() && info.mHardwareRenderer.validate()) { |
| 10317 | mHardwareLayer.destroy(); |
| 10318 | mHardwareLayer = null; |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 10319 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10320 | invalidate(true); |
| 10321 | invalidateParentCaches(); |
| 10322 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 10323 | return true; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10324 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 10325 | return false; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10326 | } |
| 10327 | |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10328 | /** |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 10329 | * Destroys all hardware rendering resources. This method is invoked |
| 10330 | * when the system needs to reclaim resources. Upon execution of this |
| 10331 | * method, you should free any OpenGL resources created by the view. |
| 10332 | * |
| 10333 | * Note: you <strong>must</strong> call |
| 10334 | * <code>super.destroyHardwareResources()</code> when overriding |
| 10335 | * this method. |
| 10336 | * |
| 10337 | * @hide |
| 10338 | */ |
| 10339 | protected void destroyHardwareResources() { |
| 10340 | destroyLayer(); |
| 10341 | } |
| 10342 | |
| 10343 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10344 | * <p>Enables or disables the drawing cache. When the drawing cache is enabled, the next call |
| 10345 | * to {@link #getDrawingCache()} or {@link #buildDrawingCache()} will draw the view in a |
| 10346 | * bitmap. Calling {@link #draw(android.graphics.Canvas)} will not draw from the cache when |
| 10347 | * the cache is enabled. To benefit from the cache, you must request the drawing cache by |
| 10348 | * calling {@link #getDrawingCache()} and draw it on screen if the returned bitmap is not |
| 10349 | * null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10350 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10351 | * <p>Enabling the drawing cache is similar to |
| 10352 | * {@link #setLayerType(int, android.graphics.Paint) setting a layer} when hardware |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10353 | * acceleration is turned off. When hardware acceleration is turned on, enabling the |
| 10354 | * drawing cache has no effect on rendering because the system uses a different mechanism |
| 10355 | * for acceleration which ignores the flag. If you want to use a Bitmap for the view, even |
| 10356 | * when hardware acceleration is enabled, see {@link #setLayerType(int, android.graphics.Paint)} |
| 10357 | * for information on how to enable software and hardware layers.</p> |
| 10358 | * |
| 10359 | * <p>This API can be used to manually generate |
| 10360 | * a bitmap copy of this view, by setting the flag to <code>true</code> and calling |
| 10361 | * {@link #getDrawingCache()}.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10362 | * |
| 10363 | * @param enabled true to enable the drawing cache, false otherwise |
| 10364 | * |
| 10365 | * @see #isDrawingCacheEnabled() |
| 10366 | * @see #getDrawingCache() |
| 10367 | * @see #buildDrawingCache() |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10368 | * @see #setLayerType(int, android.graphics.Paint) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10369 | */ |
| 10370 | public void setDrawingCacheEnabled(boolean enabled) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 10371 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10372 | setFlags(enabled ? DRAWING_CACHE_ENABLED : 0, DRAWING_CACHE_ENABLED); |
| 10373 | } |
| 10374 | |
| 10375 | /** |
| 10376 | * <p>Indicates whether the drawing cache is enabled for this view.</p> |
| 10377 | * |
| 10378 | * @return true if the drawing cache is enabled |
| 10379 | * |
| 10380 | * @see #setDrawingCacheEnabled(boolean) |
| 10381 | * @see #getDrawingCache() |
| 10382 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 10383 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10384 | public boolean isDrawingCacheEnabled() { |
| 10385 | return (mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED; |
| 10386 | } |
| 10387 | |
| 10388 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10389 | * Debugging utility which recursively outputs the dirty state of a view and its |
| 10390 | * descendants. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10391 | * |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10392 | * @hide |
| 10393 | */ |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 10394 | @SuppressWarnings({"UnusedDeclaration"}) |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10395 | public void outputDirtyFlags(String indent, boolean clear, int clearMask) { |
| 10396 | Log.d("View", indent + this + " DIRTY(" + (mPrivateFlags & View.DIRTY_MASK) + |
| 10397 | ") DRAWN(" + (mPrivateFlags & DRAWN) + ")" + " CACHE_VALID(" + |
| 10398 | (mPrivateFlags & View.DRAWING_CACHE_VALID) + |
| 10399 | ") INVALIDATED(" + (mPrivateFlags & INVALIDATED) + ")"); |
| 10400 | if (clear) { |
| 10401 | mPrivateFlags &= clearMask; |
| 10402 | } |
| 10403 | if (this instanceof ViewGroup) { |
| 10404 | ViewGroup parent = (ViewGroup) this; |
| 10405 | final int count = parent.getChildCount(); |
| 10406 | for (int i = 0; i < count; i++) { |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10407 | final View child = parent.getChildAt(i); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10408 | child.outputDirtyFlags(indent + " ", clear, clearMask); |
| 10409 | } |
| 10410 | } |
| 10411 | } |
| 10412 | |
| 10413 | /** |
| 10414 | * This method is used by ViewGroup to cause its children to restore or recreate their |
| 10415 | * display lists. It is called by getDisplayList() when the parent ViewGroup does not need |
| 10416 | * to recreate its own display list, which would happen if it went through the normal |
| 10417 | * draw/dispatchDraw mechanisms. |
| 10418 | * |
| 10419 | * @hide |
| 10420 | */ |
| 10421 | protected void dispatchGetDisplayList() {} |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 10422 | |
| 10423 | /** |
| 10424 | * A view that is not attached or hardware accelerated cannot create a display list. |
| 10425 | * This method checks these conditions and returns the appropriate result. |
| 10426 | * |
| 10427 | * @return true if view has the ability to create a display list, false otherwise. |
| 10428 | * |
| 10429 | * @hide |
| 10430 | */ |
| 10431 | public boolean canHaveDisplayList() { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 10432 | return !(mAttachInfo == null || mAttachInfo.mHardwareRenderer == null); |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 10433 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10434 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10435 | /** |
Gilles Debunne | b35ab7b | 2011-12-05 15:54:00 -0800 | [diff] [blame^] | 10436 | * @return The HardwareRenderer associated with that view or null if hardware rendering |
| 10437 | * is not supported or this this has not been attached to a window. |
| 10438 | * |
| 10439 | * @hide |
| 10440 | */ |
| 10441 | public HardwareRenderer getHardwareRenderer() { |
| 10442 | if (mAttachInfo != null) { |
| 10443 | return mAttachInfo.mHardwareRenderer; |
| 10444 | } |
| 10445 | return null; |
| 10446 | } |
| 10447 | |
| 10448 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10449 | * <p>Returns a display list that can be used to draw this view again |
| 10450 | * without executing its draw method.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10451 | * |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10452 | * @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] | 10453 | * |
| 10454 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10455 | */ |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10456 | public DisplayList getDisplayList() { |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 10457 | if (!canHaveDisplayList()) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10458 | return null; |
| 10459 | } |
| 10460 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10461 | if (((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || |
| 10462 | mDisplayList == null || !mDisplayList.isValid() || |
| 10463 | mRecreateDisplayList)) { |
| 10464 | // Don't need to recreate the display list, just need to tell our |
| 10465 | // children to restore/recreate theirs |
| 10466 | if (mDisplayList != null && mDisplayList.isValid() && |
| 10467 | !mRecreateDisplayList) { |
| 10468 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 10469 | mPrivateFlags &= ~DIRTY_MASK; |
| 10470 | dispatchGetDisplayList(); |
| 10471 | |
| 10472 | return mDisplayList; |
| 10473 | } |
| 10474 | |
| 10475 | // If we got here, we're recreating it. Mark it as such to ensure that |
| 10476 | // we copy in child display lists into ours in drawChild() |
| 10477 | mRecreateDisplayList = true; |
Chet Haase | 9e90a99 | 2011-01-04 16:23:21 -0800 | [diff] [blame] | 10478 | if (mDisplayList == null) { |
Jeff Brown | 162a021 | 2011-07-21 17:02:54 -0700 | [diff] [blame] | 10479 | mDisplayList = mAttachInfo.mHardwareRenderer.createDisplayList(); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10480 | // If we're creating a new display list, make sure our parent gets invalidated |
| 10481 | // since they will need to recreate their display list to account for this |
| 10482 | // new child display list. |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10483 | invalidateParentCaches(); |
Chet Haase | 9e90a99 | 2011-01-04 16:23:21 -0800 | [diff] [blame] | 10484 | } |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10485 | |
| 10486 | final HardwareCanvas canvas = mDisplayList.start(); |
Romain Guy | e080af3 | 2011-09-08 15:03:39 -0700 | [diff] [blame] | 10487 | int restoreCount = 0; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10488 | try { |
| 10489 | int width = mRight - mLeft; |
| 10490 | int height = mBottom - mTop; |
| 10491 | |
| 10492 | canvas.setViewport(width, height); |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10493 | // The dirty rect should always be null for a display list |
| 10494 | canvas.onPreDraw(null); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10495 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10496 | computeScroll(); |
Romain Guy | e080af3 | 2011-09-08 15:03:39 -0700 | [diff] [blame] | 10497 | |
| 10498 | restoreCount = canvas.save(); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10499 | canvas.translate(-mScrollX, -mScrollY); |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 10500 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 10501 | mPrivateFlags &= ~DIRTY_MASK; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10502 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10503 | // Fast path for layouts with no backgrounds |
| 10504 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10505 | dispatchDraw(canvas); |
| 10506 | } else { |
| 10507 | draw(canvas); |
| 10508 | } |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10509 | } finally { |
Romain Guy | e080af3 | 2011-09-08 15:03:39 -0700 | [diff] [blame] | 10510 | canvas.restoreToCount(restoreCount); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10511 | canvas.onPostDraw(); |
| 10512 | |
| 10513 | mDisplayList.end(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10514 | } |
Chet Haase | 77785f9 | 2011-01-25 23:22:09 -0800 | [diff] [blame] | 10515 | } else { |
| 10516 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 10517 | mPrivateFlags &= ~DIRTY_MASK; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10518 | } |
| 10519 | |
| 10520 | return mDisplayList; |
| 10521 | } |
| 10522 | |
| 10523 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10524 | * <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] | 10525 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10526 | * @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] | 10527 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10528 | * @see #getDrawingCache(boolean) |
| 10529 | */ |
| 10530 | public Bitmap getDrawingCache() { |
| 10531 | return getDrawingCache(false); |
| 10532 | } |
| 10533 | |
| 10534 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10535 | * <p>Returns the bitmap in which this view drawing is cached. The returned bitmap |
| 10536 | * is null when caching is disabled. If caching is enabled and the cache is not ready, |
| 10537 | * this method will create it. Calling {@link #draw(android.graphics.Canvas)} will not |
| 10538 | * draw from the cache when the cache is enabled. To benefit from the cache, you must |
| 10539 | * request the drawing cache by calling this method and draw it on screen if the |
| 10540 | * returned bitmap is not null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10541 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10542 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 10543 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 10544 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 10545 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 10546 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 10547 | * size than the view. This implies that your application must be able to handle this |
| 10548 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10549 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10550 | * @param autoScale Indicates whether the generated bitmap should be scaled based on |
| 10551 | * the current density of the screen when the application is in compatibility |
| 10552 | * mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10553 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10554 | * @return A bitmap representing this view or null if cache is disabled. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10555 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10556 | * @see #setDrawingCacheEnabled(boolean) |
| 10557 | * @see #isDrawingCacheEnabled() |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10558 | * @see #buildDrawingCache(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10559 | * @see #destroyDrawingCache() |
| 10560 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10561 | public Bitmap getDrawingCache(boolean autoScale) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10562 | if ((mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING) { |
| 10563 | return null; |
| 10564 | } |
| 10565 | if ((mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10566 | buildDrawingCache(autoScale); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10567 | } |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10568 | return autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10569 | } |
| 10570 | |
| 10571 | /** |
| 10572 | * <p>Frees the resources used by the drawing cache. If you call |
| 10573 | * {@link #buildDrawingCache()} manually without calling |
| 10574 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 10575 | * should cleanup the cache with this method afterwards.</p> |
| 10576 | * |
| 10577 | * @see #setDrawingCacheEnabled(boolean) |
| 10578 | * @see #buildDrawingCache() |
| 10579 | * @see #getDrawingCache() |
| 10580 | */ |
| 10581 | public void destroyDrawingCache() { |
| 10582 | if (mDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10583 | mDrawingCache.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10584 | mDrawingCache = null; |
| 10585 | } |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10586 | if (mUnscaledDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10587 | mUnscaledDrawingCache.recycle(); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10588 | mUnscaledDrawingCache = null; |
| 10589 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10590 | } |
| 10591 | |
| 10592 | /** |
| 10593 | * Setting a solid background color for the drawing cache's bitmaps will improve |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 10594 | * performance and memory usage. Note, though that this should only be used if this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10595 | * view will always be drawn on top of a solid color. |
| 10596 | * |
| 10597 | * @param color The background color to use for the drawing cache's bitmap |
| 10598 | * |
| 10599 | * @see #setDrawingCacheEnabled(boolean) |
| 10600 | * @see #buildDrawingCache() |
| 10601 | * @see #getDrawingCache() |
| 10602 | */ |
| 10603 | public void setDrawingCacheBackgroundColor(int color) { |
Romain Guy | 52e2ef8 | 2010-01-14 12:11:48 -0800 | [diff] [blame] | 10604 | if (color != mDrawingCacheBackgroundColor) { |
| 10605 | mDrawingCacheBackgroundColor = color; |
| 10606 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 10607 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10608 | } |
| 10609 | |
| 10610 | /** |
| 10611 | * @see #setDrawingCacheBackgroundColor(int) |
| 10612 | * |
| 10613 | * @return The background color to used for the drawing cache's bitmap |
| 10614 | */ |
| 10615 | public int getDrawingCacheBackgroundColor() { |
| 10616 | return mDrawingCacheBackgroundColor; |
| 10617 | } |
| 10618 | |
| 10619 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10620 | * <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] | 10621 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10622 | * @see #buildDrawingCache(boolean) |
| 10623 | */ |
| 10624 | public void buildDrawingCache() { |
| 10625 | buildDrawingCache(false); |
| 10626 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 10627 | |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10628 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10629 | * <p>Forces the drawing cache to be built if the drawing cache is invalid.</p> |
| 10630 | * |
| 10631 | * <p>If you call {@link #buildDrawingCache()} manually without calling |
| 10632 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 10633 | * should cleanup the cache by calling {@link #destroyDrawingCache()} afterwards.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10634 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10635 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 10636 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 10637 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 10638 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 10639 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 10640 | * size than the view. This implies that your application must be able to handle this |
| 10641 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10642 | * |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 10643 | * <p>You should avoid calling this method when hardware acceleration is enabled. If |
| 10644 | * 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] | 10645 | * 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] | 10646 | * performance.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10647 | * |
| 10648 | * @see #getDrawingCache() |
| 10649 | * @see #destroyDrawingCache() |
| 10650 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10651 | public void buildDrawingCache(boolean autoScale) { |
| 10652 | if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || (autoScale ? |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10653 | mDrawingCache == null : mUnscaledDrawingCache == null)) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 10654 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10655 | |
| 10656 | if (ViewDebug.TRACE_HIERARCHY) { |
| 10657 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.BUILD_CACHE); |
| 10658 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10659 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10660 | int width = mRight - mLeft; |
| 10661 | int height = mBottom - mTop; |
| 10662 | |
| 10663 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 10664 | final boolean scalingRequired = attachInfo != null && attachInfo.mScalingRequired; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10665 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 10666 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10667 | width = (int) ((width * attachInfo.mApplicationScale) + 0.5f); |
| 10668 | height = (int) ((height * attachInfo.mApplicationScale) + 0.5f); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10669 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10670 | |
| 10671 | final int drawingCacheBackgroundColor = mDrawingCacheBackgroundColor; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 10672 | final boolean opaque = drawingCacheBackgroundColor != 0 || isOpaque(); |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 10673 | final boolean use32BitCache = attachInfo != null && attachInfo.mUse32BitDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10674 | |
| 10675 | if (width <= 0 || height <= 0 || |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 10676 | // Projected bitmap size in bytes |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 10677 | (width * height * (opaque && !use32BitCache ? 2 : 4) > |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10678 | ViewConfiguration.get(mContext).getScaledMaximumDrawingCacheSize())) { |
| 10679 | destroyDrawingCache(); |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 10680 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10681 | return; |
| 10682 | } |
| 10683 | |
| 10684 | boolean clear = true; |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10685 | Bitmap bitmap = autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10686 | |
| 10687 | if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10688 | Bitmap.Config quality; |
| 10689 | if (!opaque) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 10690 | // Never pick ARGB_4444 because it looks awful |
| 10691 | // 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] | 10692 | switch (mViewFlags & DRAWING_CACHE_QUALITY_MASK) { |
| 10693 | case DRAWING_CACHE_QUALITY_AUTO: |
| 10694 | quality = Bitmap.Config.ARGB_8888; |
| 10695 | break; |
| 10696 | case DRAWING_CACHE_QUALITY_LOW: |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 10697 | quality = Bitmap.Config.ARGB_8888; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10698 | break; |
| 10699 | case DRAWING_CACHE_QUALITY_HIGH: |
| 10700 | quality = Bitmap.Config.ARGB_8888; |
| 10701 | break; |
| 10702 | default: |
| 10703 | quality = Bitmap.Config.ARGB_8888; |
| 10704 | break; |
| 10705 | } |
| 10706 | } else { |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 10707 | // Optimization for translucent windows |
| 10708 | // 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] | 10709 | 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] | 10710 | } |
| 10711 | |
| 10712 | // Try to cleanup memory |
| 10713 | if (bitmap != null) bitmap.recycle(); |
| 10714 | |
| 10715 | try { |
| 10716 | bitmap = Bitmap.createBitmap(width, height, quality); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 10717 | bitmap.setDensity(getResources().getDisplayMetrics().densityDpi); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10718 | if (autoScale) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10719 | mDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10720 | } else { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10721 | mUnscaledDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10722 | } |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 10723 | if (opaque && use32BitCache) bitmap.setHasAlpha(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10724 | } catch (OutOfMemoryError e) { |
| 10725 | // If there is not enough memory to create the bitmap cache, just |
| 10726 | // ignore the issue as bitmap caches are not required to draw the |
| 10727 | // view hierarchy |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10728 | if (autoScale) { |
| 10729 | mDrawingCache = null; |
| 10730 | } else { |
| 10731 | mUnscaledDrawingCache = null; |
| 10732 | } |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 10733 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10734 | return; |
| 10735 | } |
| 10736 | |
| 10737 | clear = drawingCacheBackgroundColor != 0; |
| 10738 | } |
| 10739 | |
| 10740 | Canvas canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10741 | if (attachInfo != null) { |
| 10742 | canvas = attachInfo.mCanvas; |
| 10743 | if (canvas == null) { |
| 10744 | canvas = new Canvas(); |
| 10745 | } |
| 10746 | canvas.setBitmap(bitmap); |
| 10747 | // Temporarily clobber the cached Canvas in case one of our children |
| 10748 | // is also using a drawing cache. Without this, the children would |
| 10749 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 10750 | // thing would happen (invisible views, corrupted drawings, etc.) |
| 10751 | attachInfo.mCanvas = null; |
| 10752 | } else { |
| 10753 | // This case should hopefully never or seldom happen |
| 10754 | canvas = new Canvas(bitmap); |
| 10755 | } |
| 10756 | |
| 10757 | if (clear) { |
| 10758 | bitmap.eraseColor(drawingCacheBackgroundColor); |
| 10759 | } |
| 10760 | |
| 10761 | computeScroll(); |
| 10762 | final int restoreCount = canvas.save(); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10763 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 10764 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10765 | final float scale = attachInfo.mApplicationScale; |
| 10766 | canvas.scale(scale, scale); |
| 10767 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10768 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10769 | canvas.translate(-mScrollX, -mScrollY); |
| 10770 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10771 | mPrivateFlags |= DRAWN; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10772 | if (mAttachInfo == null || !mAttachInfo.mHardwareAccelerated || |
| 10773 | mLayerType != LAYER_TYPE_NONE) { |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 10774 | mPrivateFlags |= DRAWING_CACHE_VALID; |
| 10775 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10776 | |
| 10777 | // Fast path for layouts with no backgrounds |
| 10778 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 10779 | if (ViewDebug.TRACE_HIERARCHY) { |
| 10780 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW); |
| 10781 | } |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10782 | mPrivateFlags &= ~DIRTY_MASK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10783 | dispatchDraw(canvas); |
| 10784 | } else { |
| 10785 | draw(canvas); |
| 10786 | } |
| 10787 | |
| 10788 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 10789 | canvas.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10790 | |
| 10791 | if (attachInfo != null) { |
| 10792 | // Restore the cached Canvas for our siblings |
| 10793 | attachInfo.mCanvas = canvas; |
| 10794 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10795 | } |
| 10796 | } |
| 10797 | |
| 10798 | /** |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10799 | * Create a snapshot of the view into a bitmap. We should probably make |
| 10800 | * some form of this public, but should think about the API. |
| 10801 | */ |
Romain Guy | 223ff5c | 2010-03-02 17:07:47 -0800 | [diff] [blame] | 10802 | Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipChildren) { |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 10803 | int width = mRight - mLeft; |
| 10804 | int height = mBottom - mTop; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10805 | |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 10806 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 10807 | final float scale = attachInfo != null ? attachInfo.mApplicationScale : 1.0f; |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 10808 | width = (int) ((width * scale) + 0.5f); |
| 10809 | height = (int) ((height * scale) + 0.5f); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10810 | |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 10811 | 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] | 10812 | if (bitmap == null) { |
| 10813 | throw new OutOfMemoryError(); |
| 10814 | } |
| 10815 | |
Romain Guy | c529d8d | 2011-09-06 15:01:39 -0700 | [diff] [blame] | 10816 | Resources resources = getResources(); |
| 10817 | if (resources != null) { |
| 10818 | bitmap.setDensity(resources.getDisplayMetrics().densityDpi); |
| 10819 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10820 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10821 | Canvas canvas; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10822 | if (attachInfo != null) { |
| 10823 | canvas = attachInfo.mCanvas; |
| 10824 | if (canvas == null) { |
| 10825 | canvas = new Canvas(); |
| 10826 | } |
| 10827 | canvas.setBitmap(bitmap); |
| 10828 | // Temporarily clobber the cached Canvas in case one of our children |
| 10829 | // is also using a drawing cache. Without this, the children would |
| 10830 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 10831 | // things would happen (invisible views, corrupted drawings, etc.) |
| 10832 | attachInfo.mCanvas = null; |
| 10833 | } else { |
| 10834 | // This case should hopefully never or seldom happen |
| 10835 | canvas = new Canvas(bitmap); |
| 10836 | } |
| 10837 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10838 | if ((backgroundColor & 0xff000000) != 0) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10839 | bitmap.eraseColor(backgroundColor); |
| 10840 | } |
| 10841 | |
| 10842 | computeScroll(); |
| 10843 | final int restoreCount = canvas.save(); |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 10844 | canvas.scale(scale, scale); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10845 | canvas.translate(-mScrollX, -mScrollY); |
| 10846 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10847 | // Temporarily remove the dirty mask |
| 10848 | int flags = mPrivateFlags; |
| 10849 | mPrivateFlags &= ~DIRTY_MASK; |
| 10850 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10851 | // Fast path for layouts with no backgrounds |
| 10852 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 10853 | dispatchDraw(canvas); |
| 10854 | } else { |
| 10855 | draw(canvas); |
| 10856 | } |
| 10857 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10858 | mPrivateFlags = flags; |
| 10859 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10860 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 10861 | canvas.setBitmap(null); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10862 | |
| 10863 | if (attachInfo != null) { |
| 10864 | // Restore the cached Canvas for our siblings |
| 10865 | attachInfo.mCanvas = canvas; |
| 10866 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10867 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10868 | return bitmap; |
| 10869 | } |
| 10870 | |
| 10871 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10872 | * Indicates whether this View is currently in edit mode. A View is usually |
| 10873 | * in edit mode when displayed within a developer tool. For instance, if |
| 10874 | * this View is being drawn by a visual user interface builder, this method |
| 10875 | * should return true. |
| 10876 | * |
| 10877 | * Subclasses should check the return value of this method to provide |
| 10878 | * different behaviors if their normal behavior might interfere with the |
| 10879 | * host environment. For instance: the class spawns a thread in its |
| 10880 | * constructor, the drawing code relies on device-specific features, etc. |
| 10881 | * |
| 10882 | * This method is usually checked in the drawing code of custom widgets. |
| 10883 | * |
| 10884 | * @return True if this View is in edit mode, false otherwise. |
| 10885 | */ |
| 10886 | public boolean isInEditMode() { |
| 10887 | return false; |
| 10888 | } |
| 10889 | |
| 10890 | /** |
| 10891 | * If the View draws content inside its padding and enables fading edges, |
| 10892 | * it needs to support padding offsets. Padding offsets are added to the |
| 10893 | * fading edges to extend the length of the fade so that it covers pixels |
| 10894 | * drawn inside the padding. |
| 10895 | * |
| 10896 | * Subclasses of this class should override this method if they need |
| 10897 | * to draw content inside the padding. |
| 10898 | * |
| 10899 | * @return True if padding offset must be applied, false otherwise. |
| 10900 | * |
| 10901 | * @see #getLeftPaddingOffset() |
| 10902 | * @see #getRightPaddingOffset() |
| 10903 | * @see #getTopPaddingOffset() |
| 10904 | * @see #getBottomPaddingOffset() |
| 10905 | * |
| 10906 | * @since CURRENT |
| 10907 | */ |
| 10908 | protected boolean isPaddingOffsetRequired() { |
| 10909 | return false; |
| 10910 | } |
| 10911 | |
| 10912 | /** |
| 10913 | * Amount by which to extend the left fading region. Called only when |
| 10914 | * {@link #isPaddingOffsetRequired()} returns true. |
| 10915 | * |
| 10916 | * @return The left padding offset in pixels. |
| 10917 | * |
| 10918 | * @see #isPaddingOffsetRequired() |
| 10919 | * |
| 10920 | * @since CURRENT |
| 10921 | */ |
| 10922 | protected int getLeftPaddingOffset() { |
| 10923 | return 0; |
| 10924 | } |
| 10925 | |
| 10926 | /** |
| 10927 | * Amount by which to extend the right fading region. Called only when |
| 10928 | * {@link #isPaddingOffsetRequired()} returns true. |
| 10929 | * |
| 10930 | * @return The right padding offset in pixels. |
| 10931 | * |
| 10932 | * @see #isPaddingOffsetRequired() |
| 10933 | * |
| 10934 | * @since CURRENT |
| 10935 | */ |
| 10936 | protected int getRightPaddingOffset() { |
| 10937 | return 0; |
| 10938 | } |
| 10939 | |
| 10940 | /** |
| 10941 | * Amount by which to extend the top fading region. Called only when |
| 10942 | * {@link #isPaddingOffsetRequired()} returns true. |
| 10943 | * |
| 10944 | * @return The top padding offset in pixels. |
| 10945 | * |
| 10946 | * @see #isPaddingOffsetRequired() |
| 10947 | * |
| 10948 | * @since CURRENT |
| 10949 | */ |
| 10950 | protected int getTopPaddingOffset() { |
| 10951 | return 0; |
| 10952 | } |
| 10953 | |
| 10954 | /** |
| 10955 | * Amount by which to extend the bottom fading region. Called only when |
| 10956 | * {@link #isPaddingOffsetRequired()} returns true. |
| 10957 | * |
| 10958 | * @return The bottom padding offset in pixels. |
| 10959 | * |
| 10960 | * @see #isPaddingOffsetRequired() |
| 10961 | * |
| 10962 | * @since CURRENT |
| 10963 | */ |
| 10964 | protected int getBottomPaddingOffset() { |
| 10965 | return 0; |
| 10966 | } |
| 10967 | |
| 10968 | /** |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 10969 | * @hide |
| 10970 | * @param offsetRequired |
| 10971 | */ |
| 10972 | protected int getFadeTop(boolean offsetRequired) { |
| 10973 | int top = mPaddingTop; |
| 10974 | if (offsetRequired) top += getTopPaddingOffset(); |
| 10975 | return top; |
| 10976 | } |
| 10977 | |
| 10978 | /** |
| 10979 | * @hide |
| 10980 | * @param offsetRequired |
| 10981 | */ |
| 10982 | protected int getFadeHeight(boolean offsetRequired) { |
| 10983 | int padding = mPaddingTop; |
| 10984 | if (offsetRequired) padding += getTopPaddingOffset(); |
| 10985 | return mBottom - mTop - mPaddingBottom - padding; |
| 10986 | } |
| 10987 | |
| 10988 | /** |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 10989 | * <p>Indicates whether this view is attached to an hardware accelerated |
| 10990 | * window or not.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10991 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 10992 | * <p>Even if this method returns true, it does not mean that every call |
| 10993 | * to {@link #draw(android.graphics.Canvas)} will be made with an hardware |
| 10994 | * accelerated {@link android.graphics.Canvas}. For instance, if this view |
| 10995 | * is drawn onto an offscren {@link android.graphics.Bitmap} and its |
| 10996 | * window is hardware accelerated, |
| 10997 | * {@link android.graphics.Canvas#isHardwareAccelerated()} will likely |
| 10998 | * return false, and this method will return true.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10999 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 11000 | * @return True if the view is attached to a window and the window is |
| 11001 | * hardware accelerated; false in any other case. |
| 11002 | */ |
| 11003 | public boolean isHardwareAccelerated() { |
| 11004 | return mAttachInfo != null && mAttachInfo.mHardwareAccelerated; |
| 11005 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11006 | |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 11007 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11008 | * Manually render this view (and all of its children) to the given Canvas. |
| 11009 | * 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] | 11010 | * called. When implementing a view, implement |
| 11011 | * {@link #onDraw(android.graphics.Canvas)} instead of overriding this method. |
| 11012 | * 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] | 11013 | * |
| 11014 | * @param canvas The Canvas to which the View is rendered. |
| 11015 | */ |
| 11016 | public void draw(Canvas canvas) { |
| 11017 | if (ViewDebug.TRACE_HIERARCHY) { |
| 11018 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW); |
| 11019 | } |
| 11020 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 11021 | final int privateFlags = mPrivateFlags; |
| 11022 | final boolean dirtyOpaque = (privateFlags & DIRTY_MASK) == DIRTY_OPAQUE && |
| 11023 | (mAttachInfo == null || !mAttachInfo.mIgnoreDirtyState); |
| 11024 | mPrivateFlags = (privateFlags & ~DIRTY_MASK) | DRAWN; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 11025 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11026 | /* |
| 11027 | * Draw traversal performs several drawing steps which must be executed |
| 11028 | * in the appropriate order: |
| 11029 | * |
| 11030 | * 1. Draw the background |
| 11031 | * 2. If necessary, save the canvas' layers to prepare for fading |
| 11032 | * 3. Draw view's content |
| 11033 | * 4. Draw children |
| 11034 | * 5. If necessary, draw the fading edges and restore layers |
| 11035 | * 6. Draw decorations (scrollbars for instance) |
| 11036 | */ |
| 11037 | |
| 11038 | // Step 1, draw the background, if needed |
| 11039 | int saveCount; |
| 11040 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 11041 | if (!dirtyOpaque) { |
| 11042 | final Drawable background = mBGDrawable; |
| 11043 | if (background != null) { |
| 11044 | final int scrollX = mScrollX; |
| 11045 | final int scrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11046 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 11047 | if (mBackgroundSizeChanged) { |
| 11048 | background.setBounds(0, 0, mRight - mLeft, mBottom - mTop); |
| 11049 | mBackgroundSizeChanged = false; |
| 11050 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11051 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 11052 | if ((scrollX | scrollY) == 0) { |
| 11053 | background.draw(canvas); |
| 11054 | } else { |
| 11055 | canvas.translate(scrollX, scrollY); |
| 11056 | background.draw(canvas); |
| 11057 | canvas.translate(-scrollX, -scrollY); |
| 11058 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11059 | } |
| 11060 | } |
| 11061 | |
| 11062 | // skip step 2 & 5 if possible (common case) |
| 11063 | final int viewFlags = mViewFlags; |
| 11064 | boolean horizontalEdges = (viewFlags & FADING_EDGE_HORIZONTAL) != 0; |
| 11065 | boolean verticalEdges = (viewFlags & FADING_EDGE_VERTICAL) != 0; |
| 11066 | if (!verticalEdges && !horizontalEdges) { |
| 11067 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 11068 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11069 | |
| 11070 | // Step 4, draw the children |
| 11071 | dispatchDraw(canvas); |
| 11072 | |
| 11073 | // Step 6, draw decorations (scrollbars) |
| 11074 | onDrawScrollBars(canvas); |
| 11075 | |
| 11076 | // we're done... |
| 11077 | return; |
| 11078 | } |
| 11079 | |
| 11080 | /* |
| 11081 | * Here we do the full fledged routine... |
| 11082 | * (this is an uncommon case where speed matters less, |
| 11083 | * this is why we repeat some of the tests that have been |
| 11084 | * done above) |
| 11085 | */ |
| 11086 | |
| 11087 | boolean drawTop = false; |
| 11088 | boolean drawBottom = false; |
| 11089 | boolean drawLeft = false; |
| 11090 | boolean drawRight = false; |
| 11091 | |
| 11092 | float topFadeStrength = 0.0f; |
| 11093 | float bottomFadeStrength = 0.0f; |
| 11094 | float leftFadeStrength = 0.0f; |
| 11095 | float rightFadeStrength = 0.0f; |
| 11096 | |
| 11097 | // Step 2, save the canvas' layers |
| 11098 | int paddingLeft = mPaddingLeft; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11099 | |
| 11100 | final boolean offsetRequired = isPaddingOffsetRequired(); |
| 11101 | if (offsetRequired) { |
| 11102 | paddingLeft += getLeftPaddingOffset(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11103 | } |
| 11104 | |
| 11105 | int left = mScrollX + paddingLeft; |
| 11106 | int right = left + mRight - mLeft - mPaddingRight - paddingLeft; |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 11107 | int top = mScrollY + getFadeTop(offsetRequired); |
| 11108 | int bottom = top + getFadeHeight(offsetRequired); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11109 | |
| 11110 | if (offsetRequired) { |
| 11111 | right += getRightPaddingOffset(); |
| 11112 | bottom += getBottomPaddingOffset(); |
| 11113 | } |
| 11114 | |
| 11115 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11116 | final float fadeHeight = scrollabilityCache.fadingEdgeLength; |
| 11117 | int length = (int) fadeHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11118 | |
| 11119 | // clip the fade length if top and bottom fades overlap |
| 11120 | // overlapping fades produce odd-looking artifacts |
| 11121 | if (verticalEdges && (top + length > bottom - length)) { |
| 11122 | length = (bottom - top) / 2; |
| 11123 | } |
| 11124 | |
| 11125 | // also clip horizontal fades if necessary |
| 11126 | if (horizontalEdges && (left + length > right - length)) { |
| 11127 | length = (right - left) / 2; |
| 11128 | } |
| 11129 | |
| 11130 | if (verticalEdges) { |
| 11131 | topFadeStrength = Math.max(0.0f, Math.min(1.0f, getTopFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11132 | drawTop = topFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11133 | bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, getBottomFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11134 | drawBottom = bottomFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11135 | } |
| 11136 | |
| 11137 | if (horizontalEdges) { |
| 11138 | leftFadeStrength = Math.max(0.0f, Math.min(1.0f, getLeftFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11139 | drawLeft = leftFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11140 | rightFadeStrength = Math.max(0.0f, Math.min(1.0f, getRightFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11141 | drawRight = rightFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11142 | } |
| 11143 | |
| 11144 | saveCount = canvas.getSaveCount(); |
| 11145 | |
| 11146 | int solidColor = getSolidColor(); |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 11147 | if (solidColor == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11148 | final int flags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
| 11149 | |
| 11150 | if (drawTop) { |
| 11151 | canvas.saveLayer(left, top, right, top + length, null, flags); |
| 11152 | } |
| 11153 | |
| 11154 | if (drawBottom) { |
| 11155 | canvas.saveLayer(left, bottom - length, right, bottom, null, flags); |
| 11156 | } |
| 11157 | |
| 11158 | if (drawLeft) { |
| 11159 | canvas.saveLayer(left, top, left + length, bottom, null, flags); |
| 11160 | } |
| 11161 | |
| 11162 | if (drawRight) { |
| 11163 | canvas.saveLayer(right - length, top, right, bottom, null, flags); |
| 11164 | } |
| 11165 | } else { |
| 11166 | scrollabilityCache.setFadeColor(solidColor); |
| 11167 | } |
| 11168 | |
| 11169 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 11170 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11171 | |
| 11172 | // Step 4, draw the children |
| 11173 | dispatchDraw(canvas); |
| 11174 | |
| 11175 | // Step 5, draw the fade effect and restore layers |
| 11176 | final Paint p = scrollabilityCache.paint; |
| 11177 | final Matrix matrix = scrollabilityCache.matrix; |
| 11178 | final Shader fade = scrollabilityCache.shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11179 | |
| 11180 | if (drawTop) { |
| 11181 | matrix.setScale(1, fadeHeight * topFadeStrength); |
| 11182 | matrix.postTranslate(left, top); |
| 11183 | fade.setLocalMatrix(matrix); |
| 11184 | canvas.drawRect(left, top, right, top + length, p); |
| 11185 | } |
| 11186 | |
| 11187 | if (drawBottom) { |
| 11188 | matrix.setScale(1, fadeHeight * bottomFadeStrength); |
| 11189 | matrix.postRotate(180); |
| 11190 | matrix.postTranslate(left, bottom); |
| 11191 | fade.setLocalMatrix(matrix); |
| 11192 | canvas.drawRect(left, bottom - length, right, bottom, p); |
| 11193 | } |
| 11194 | |
| 11195 | if (drawLeft) { |
| 11196 | matrix.setScale(1, fadeHeight * leftFadeStrength); |
| 11197 | matrix.postRotate(-90); |
| 11198 | matrix.postTranslate(left, top); |
| 11199 | fade.setLocalMatrix(matrix); |
| 11200 | canvas.drawRect(left, top, left + length, bottom, p); |
| 11201 | } |
| 11202 | |
| 11203 | if (drawRight) { |
| 11204 | matrix.setScale(1, fadeHeight * rightFadeStrength); |
| 11205 | matrix.postRotate(90); |
| 11206 | matrix.postTranslate(right, top); |
| 11207 | fade.setLocalMatrix(matrix); |
| 11208 | canvas.drawRect(right - length, top, right, bottom, p); |
| 11209 | } |
| 11210 | |
| 11211 | canvas.restoreToCount(saveCount); |
| 11212 | |
| 11213 | // Step 6, draw decorations (scrollbars) |
| 11214 | onDrawScrollBars(canvas); |
| 11215 | } |
| 11216 | |
| 11217 | /** |
| 11218 | * Override this if your view is known to always be drawn on top of a solid color background, |
| 11219 | * and needs to draw fading edges. Returning a non-zero color enables the view system to |
| 11220 | * optimize the drawing of the fading edges. If you do return a non-zero color, the alpha |
| 11221 | * should be set to 0xFF. |
| 11222 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11223 | * @see #setVerticalFadingEdgeEnabled(boolean) |
| 11224 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11225 | * |
| 11226 | * @return The known solid color background for this view, or 0 if the color may vary |
| 11227 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11228 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11229 | public int getSolidColor() { |
| 11230 | return 0; |
| 11231 | } |
| 11232 | |
| 11233 | /** |
| 11234 | * Build a human readable string representation of the specified view flags. |
| 11235 | * |
| 11236 | * @param flags the view flags to convert to a string |
| 11237 | * @return a String representing the supplied flags |
| 11238 | */ |
| 11239 | private static String printFlags(int flags) { |
| 11240 | String output = ""; |
| 11241 | int numFlags = 0; |
| 11242 | if ((flags & FOCUSABLE_MASK) == FOCUSABLE) { |
| 11243 | output += "TAKES_FOCUS"; |
| 11244 | numFlags++; |
| 11245 | } |
| 11246 | |
| 11247 | switch (flags & VISIBILITY_MASK) { |
| 11248 | case INVISIBLE: |
| 11249 | if (numFlags > 0) { |
| 11250 | output += " "; |
| 11251 | } |
| 11252 | output += "INVISIBLE"; |
| 11253 | // USELESS HERE numFlags++; |
| 11254 | break; |
| 11255 | case GONE: |
| 11256 | if (numFlags > 0) { |
| 11257 | output += " "; |
| 11258 | } |
| 11259 | output += "GONE"; |
| 11260 | // USELESS HERE numFlags++; |
| 11261 | break; |
| 11262 | default: |
| 11263 | break; |
| 11264 | } |
| 11265 | return output; |
| 11266 | } |
| 11267 | |
| 11268 | /** |
| 11269 | * Build a human readable string representation of the specified private |
| 11270 | * view flags. |
| 11271 | * |
| 11272 | * @param privateFlags the private view flags to convert to a string |
| 11273 | * @return a String representing the supplied flags |
| 11274 | */ |
| 11275 | private static String printPrivateFlags(int privateFlags) { |
| 11276 | String output = ""; |
| 11277 | int numFlags = 0; |
| 11278 | |
| 11279 | if ((privateFlags & WANTS_FOCUS) == WANTS_FOCUS) { |
| 11280 | output += "WANTS_FOCUS"; |
| 11281 | numFlags++; |
| 11282 | } |
| 11283 | |
| 11284 | if ((privateFlags & FOCUSED) == FOCUSED) { |
| 11285 | if (numFlags > 0) { |
| 11286 | output += " "; |
| 11287 | } |
| 11288 | output += "FOCUSED"; |
| 11289 | numFlags++; |
| 11290 | } |
| 11291 | |
| 11292 | if ((privateFlags & SELECTED) == SELECTED) { |
| 11293 | if (numFlags > 0) { |
| 11294 | output += " "; |
| 11295 | } |
| 11296 | output += "SELECTED"; |
| 11297 | numFlags++; |
| 11298 | } |
| 11299 | |
| 11300 | if ((privateFlags & IS_ROOT_NAMESPACE) == IS_ROOT_NAMESPACE) { |
| 11301 | if (numFlags > 0) { |
| 11302 | output += " "; |
| 11303 | } |
| 11304 | output += "IS_ROOT_NAMESPACE"; |
| 11305 | numFlags++; |
| 11306 | } |
| 11307 | |
| 11308 | if ((privateFlags & HAS_BOUNDS) == HAS_BOUNDS) { |
| 11309 | if (numFlags > 0) { |
| 11310 | output += " "; |
| 11311 | } |
| 11312 | output += "HAS_BOUNDS"; |
| 11313 | numFlags++; |
| 11314 | } |
| 11315 | |
| 11316 | if ((privateFlags & DRAWN) == DRAWN) { |
| 11317 | if (numFlags > 0) { |
| 11318 | output += " "; |
| 11319 | } |
| 11320 | output += "DRAWN"; |
| 11321 | // USELESS HERE numFlags++; |
| 11322 | } |
| 11323 | return output; |
| 11324 | } |
| 11325 | |
| 11326 | /** |
| 11327 | * <p>Indicates whether or not this view's layout will be requested during |
| 11328 | * the next hierarchy layout pass.</p> |
| 11329 | * |
| 11330 | * @return true if the layout will be forced during next layout pass |
| 11331 | */ |
| 11332 | public boolean isLayoutRequested() { |
| 11333 | return (mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT; |
| 11334 | } |
| 11335 | |
| 11336 | /** |
| 11337 | * Assign a size and position to a view and all of its |
| 11338 | * descendants |
| 11339 | * |
| 11340 | * <p>This is the second phase of the layout mechanism. |
| 11341 | * (The first is measuring). In this phase, each parent calls |
| 11342 | * layout on all of its children to position them. |
| 11343 | * This is typically done using the child measurements |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 11344 | * that were stored in the measure pass().</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11345 | * |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 11346 | * <p>Derived classes should not override this method. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11347 | * Derived classes with children should override |
| 11348 | * onLayout. In that method, they should |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 11349 | * call layout on each of their children.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11350 | * |
| 11351 | * @param l Left position, relative to parent |
| 11352 | * @param t Top position, relative to parent |
| 11353 | * @param r Right position, relative to parent |
| 11354 | * @param b Bottom position, relative to parent |
| 11355 | */ |
Romain Guy | 5429e1d | 2010-09-07 12:38:00 -0700 | [diff] [blame] | 11356 | @SuppressWarnings({"unchecked"}) |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 11357 | public void layout(int l, int t, int r, int b) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 11358 | int oldL = mLeft; |
| 11359 | int oldT = mTop; |
| 11360 | int oldB = mBottom; |
| 11361 | int oldR = mRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11362 | boolean changed = setFrame(l, t, r, b); |
| 11363 | if (changed || (mPrivateFlags & LAYOUT_REQUIRED) == LAYOUT_REQUIRED) { |
| 11364 | if (ViewDebug.TRACE_HIERARCHY) { |
| 11365 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_LAYOUT); |
| 11366 | } |
| 11367 | |
| 11368 | onLayout(changed, l, t, r, b); |
| 11369 | mPrivateFlags &= ~LAYOUT_REQUIRED; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 11370 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11371 | ListenerInfo li = mListenerInfo; |
| 11372 | if (li != null && li.mOnLayoutChangeListeners != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 11373 | ArrayList<OnLayoutChangeListener> listenersCopy = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11374 | (ArrayList<OnLayoutChangeListener>)li.mOnLayoutChangeListeners.clone(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 11375 | int numListeners = listenersCopy.size(); |
| 11376 | for (int i = 0; i < numListeners; ++i) { |
Chet Haase | 7c608f2 | 2010-10-22 17:54:04 -0700 | [diff] [blame] | 11377 | 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] | 11378 | } |
| 11379 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11380 | } |
| 11381 | mPrivateFlags &= ~FORCE_LAYOUT; |
| 11382 | } |
| 11383 | |
| 11384 | /** |
| 11385 | * Called from layout when this view should |
| 11386 | * assign a size and position to each of its children. |
| 11387 | * |
| 11388 | * Derived classes with children should override |
| 11389 | * this method and call layout on each of |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 11390 | * their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11391 | * @param changed This is a new size or position for this view |
| 11392 | * @param left Left position, relative to parent |
| 11393 | * @param top Top position, relative to parent |
| 11394 | * @param right Right position, relative to parent |
| 11395 | * @param bottom Bottom position, relative to parent |
| 11396 | */ |
| 11397 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 11398 | } |
| 11399 | |
| 11400 | /** |
| 11401 | * Assign a size and position to this view. |
| 11402 | * |
| 11403 | * This is called from layout. |
| 11404 | * |
| 11405 | * @param left Left position, relative to parent |
| 11406 | * @param top Top position, relative to parent |
| 11407 | * @param right Right position, relative to parent |
| 11408 | * @param bottom Bottom position, relative to parent |
| 11409 | * @return true if the new size and position are different than the |
| 11410 | * previous ones |
| 11411 | * {@hide} |
| 11412 | */ |
| 11413 | protected boolean setFrame(int left, int top, int right, int bottom) { |
| 11414 | boolean changed = false; |
| 11415 | |
| 11416 | if (DBG) { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 11417 | Log.d("View", this + " View.setFrame(" + left + "," + top + "," |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11418 | + right + "," + bottom + ")"); |
| 11419 | } |
| 11420 | |
| 11421 | if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) { |
| 11422 | changed = true; |
| 11423 | |
| 11424 | // Remember our drawn bit |
| 11425 | int drawn = mPrivateFlags & DRAWN; |
| 11426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11427 | int oldWidth = mRight - mLeft; |
| 11428 | int oldHeight = mBottom - mTop; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 11429 | int newWidth = right - left; |
| 11430 | int newHeight = bottom - top; |
| 11431 | boolean sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight); |
| 11432 | |
| 11433 | // Invalidate our old position |
| 11434 | invalidate(sizeChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11435 | |
| 11436 | mLeft = left; |
| 11437 | mTop = top; |
| 11438 | mRight = right; |
| 11439 | mBottom = bottom; |
| 11440 | |
| 11441 | mPrivateFlags |= HAS_BOUNDS; |
| 11442 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11443 | |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 11444 | if (sizeChanged) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 11445 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 11446 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 11447 | if (mTransformationInfo != null) { |
| 11448 | mTransformationInfo.mMatrixDirty = true; |
| 11449 | } |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 11450 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11451 | onSizeChanged(newWidth, newHeight, oldWidth, oldHeight); |
| 11452 | } |
| 11453 | |
| 11454 | if ((mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 11455 | // If we are visible, force the DRAWN bit to on so that |
| 11456 | // this invalidate will go through (at least to our parent). |
| 11457 | // This is because someone may have invalidated this view |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 11458 | // before this call to setFrame came in, thereby clearing |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11459 | // the DRAWN bit. |
| 11460 | mPrivateFlags |= DRAWN; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 11461 | invalidate(sizeChanged); |
Chet Haase | f28595e | 2011-01-31 18:52:12 -0800 | [diff] [blame] | 11462 | // parent display list may need to be recreated based on a change in the bounds |
| 11463 | // of any child |
| 11464 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11465 | } |
| 11466 | |
| 11467 | // Reset drawn bit to original value (invalidate turns it off) |
| 11468 | mPrivateFlags |= drawn; |
| 11469 | |
| 11470 | mBackgroundSizeChanged = true; |
| 11471 | } |
| 11472 | return changed; |
| 11473 | } |
| 11474 | |
| 11475 | /** |
| 11476 | * Finalize inflating a view from XML. This is called as the last phase |
| 11477 | * of inflation, after all child views have been added. |
| 11478 | * |
| 11479 | * <p>Even if the subclass overrides onFinishInflate, they should always be |
| 11480 | * sure to call the super method, so that we get called. |
| 11481 | */ |
| 11482 | protected void onFinishInflate() { |
| 11483 | } |
| 11484 | |
| 11485 | /** |
| 11486 | * Returns the resources associated with this view. |
| 11487 | * |
| 11488 | * @return Resources object. |
| 11489 | */ |
| 11490 | public Resources getResources() { |
| 11491 | return mResources; |
| 11492 | } |
| 11493 | |
| 11494 | /** |
| 11495 | * Invalidates the specified Drawable. |
| 11496 | * |
| 11497 | * @param drawable the drawable to invalidate |
| 11498 | */ |
| 11499 | public void invalidateDrawable(Drawable drawable) { |
| 11500 | if (verifyDrawable(drawable)) { |
| 11501 | final Rect dirty = drawable.getBounds(); |
| 11502 | final int scrollX = mScrollX; |
| 11503 | final int scrollY = mScrollY; |
| 11504 | |
| 11505 | invalidate(dirty.left + scrollX, dirty.top + scrollY, |
| 11506 | dirty.right + scrollX, dirty.bottom + scrollY); |
| 11507 | } |
| 11508 | } |
| 11509 | |
| 11510 | /** |
| 11511 | * Schedules an action on a drawable to occur at a specified time. |
| 11512 | * |
| 11513 | * @param who the recipient of the action |
| 11514 | * @param what the action to run on the drawable |
| 11515 | * @param when the time at which the action must occur. Uses the |
| 11516 | * {@link SystemClock#uptimeMillis} timebase. |
| 11517 | */ |
| 11518 | public void scheduleDrawable(Drawable who, Runnable what, long when) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 11519 | if (verifyDrawable(who) && what != null) { |
| 11520 | if (mAttachInfo != null) { |
| 11521 | mAttachInfo.mHandler.postAtTime(what, who, when); |
| 11522 | } else { |
| 11523 | ViewRootImpl.getRunQueue().postDelayed(what, when - SystemClock.uptimeMillis()); |
| 11524 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11525 | } |
| 11526 | } |
| 11527 | |
| 11528 | /** |
| 11529 | * Cancels a scheduled action on a drawable. |
| 11530 | * |
| 11531 | * @param who the recipient of the action |
| 11532 | * @param what the action to cancel |
| 11533 | */ |
| 11534 | public void unscheduleDrawable(Drawable who, Runnable what) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 11535 | if (verifyDrawable(who) && what != null) { |
| 11536 | if (mAttachInfo != null) { |
| 11537 | mAttachInfo.mHandler.removeCallbacks(what, who); |
| 11538 | } else { |
| 11539 | ViewRootImpl.getRunQueue().removeCallbacks(what); |
| 11540 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11541 | } |
| 11542 | } |
| 11543 | |
| 11544 | /** |
| 11545 | * Unschedule any events associated with the given Drawable. This can be |
| 11546 | * used when selecting a new Drawable into a view, so that the previous |
| 11547 | * one is completely unscheduled. |
| 11548 | * |
| 11549 | * @param who The Drawable to unschedule. |
| 11550 | * |
| 11551 | * @see #drawableStateChanged |
| 11552 | */ |
| 11553 | public void unscheduleDrawable(Drawable who) { |
| 11554 | if (mAttachInfo != null) { |
| 11555 | mAttachInfo.mHandler.removeCallbacksAndMessages(who); |
| 11556 | } |
| 11557 | } |
| 11558 | |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 11559 | /** |
| 11560 | * Return the layout direction of a given Drawable. |
| 11561 | * |
| 11562 | * @param who the Drawable to query |
| 11563 | * |
| 11564 | * @hide |
| 11565 | */ |
| 11566 | public int getResolvedLayoutDirection(Drawable who) { |
| 11567 | return (who == mBGDrawable) ? getResolvedLayoutDirection() : LAYOUT_DIRECTION_DEFAULT; |
Fabrice Di Meglio | 6a03640 | 2011-05-23 14:43:23 -0700 | [diff] [blame] | 11568 | } |
| 11569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11570 | /** |
| 11571 | * If your view subclass is displaying its own Drawable objects, it should |
| 11572 | * override this function and return true for any Drawable it is |
| 11573 | * displaying. This allows animations for those drawables to be |
| 11574 | * scheduled. |
| 11575 | * |
| 11576 | * <p>Be sure to call through to the super class when overriding this |
| 11577 | * function. |
| 11578 | * |
| 11579 | * @param who The Drawable to verify. Return true if it is one you are |
| 11580 | * displaying, else return the result of calling through to the |
| 11581 | * super class. |
| 11582 | * |
| 11583 | * @return boolean If true than the Drawable is being displayed in the |
| 11584 | * view; else false and it is not allowed to animate. |
| 11585 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11586 | * @see #unscheduleDrawable(android.graphics.drawable.Drawable) |
| 11587 | * @see #drawableStateChanged() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11588 | */ |
| 11589 | protected boolean verifyDrawable(Drawable who) { |
| 11590 | return who == mBGDrawable; |
| 11591 | } |
| 11592 | |
| 11593 | /** |
| 11594 | * This function is called whenever the state of the view changes in such |
| 11595 | * a way that it impacts the state of drawables being shown. |
| 11596 | * |
| 11597 | * <p>Be sure to call through to the superclass when overriding this |
| 11598 | * function. |
| 11599 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11600 | * @see Drawable#setState(int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11601 | */ |
| 11602 | protected void drawableStateChanged() { |
| 11603 | Drawable d = mBGDrawable; |
| 11604 | if (d != null && d.isStateful()) { |
| 11605 | d.setState(getDrawableState()); |
| 11606 | } |
| 11607 | } |
| 11608 | |
| 11609 | /** |
| 11610 | * Call this to force a view to update its drawable state. This will cause |
| 11611 | * drawableStateChanged to be called on this view. Views that are interested |
| 11612 | * in the new state should call getDrawableState. |
| 11613 | * |
| 11614 | * @see #drawableStateChanged |
| 11615 | * @see #getDrawableState |
| 11616 | */ |
| 11617 | public void refreshDrawableState() { |
| 11618 | mPrivateFlags |= DRAWABLE_STATE_DIRTY; |
| 11619 | drawableStateChanged(); |
| 11620 | |
| 11621 | ViewParent parent = mParent; |
| 11622 | if (parent != null) { |
| 11623 | parent.childDrawableStateChanged(this); |
| 11624 | } |
| 11625 | } |
| 11626 | |
| 11627 | /** |
| 11628 | * Return an array of resource IDs of the drawable states representing the |
| 11629 | * current state of the view. |
| 11630 | * |
| 11631 | * @return The current drawable state |
| 11632 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11633 | * @see Drawable#setState(int[]) |
| 11634 | * @see #drawableStateChanged() |
| 11635 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11636 | */ |
| 11637 | public final int[] getDrawableState() { |
| 11638 | if ((mDrawableState != null) && ((mPrivateFlags & DRAWABLE_STATE_DIRTY) == 0)) { |
| 11639 | return mDrawableState; |
| 11640 | } else { |
| 11641 | mDrawableState = onCreateDrawableState(0); |
| 11642 | mPrivateFlags &= ~DRAWABLE_STATE_DIRTY; |
| 11643 | return mDrawableState; |
| 11644 | } |
| 11645 | } |
| 11646 | |
| 11647 | /** |
| 11648 | * Generate the new {@link android.graphics.drawable.Drawable} state for |
| 11649 | * this view. This is called by the view |
| 11650 | * system when the cached Drawable state is determined to be invalid. To |
| 11651 | * retrieve the current state, you should use {@link #getDrawableState}. |
| 11652 | * |
| 11653 | * @param extraSpace if non-zero, this is the number of extra entries you |
| 11654 | * would like in the returned array in which you can place your own |
| 11655 | * states. |
| 11656 | * |
| 11657 | * @return Returns an array holding the current {@link Drawable} state of |
| 11658 | * the view. |
| 11659 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11660 | * @see #mergeDrawableStates(int[], int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11661 | */ |
| 11662 | protected int[] onCreateDrawableState(int extraSpace) { |
| 11663 | if ((mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE && |
| 11664 | mParent instanceof View) { |
| 11665 | return ((View) mParent).onCreateDrawableState(extraSpace); |
| 11666 | } |
| 11667 | |
| 11668 | int[] drawableState; |
| 11669 | |
| 11670 | int privateFlags = mPrivateFlags; |
| 11671 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 11672 | int viewStateIndex = 0; |
| 11673 | if ((privateFlags & PRESSED) != 0) viewStateIndex |= VIEW_STATE_PRESSED; |
| 11674 | if ((mViewFlags & ENABLED_MASK) == ENABLED) viewStateIndex |= VIEW_STATE_ENABLED; |
| 11675 | if (isFocused()) viewStateIndex |= VIEW_STATE_FOCUSED; |
Neel Parekh | e537858 | 2010-10-06 11:36:50 -0700 | [diff] [blame] | 11676 | if ((privateFlags & SELECTED) != 0) viewStateIndex |= VIEW_STATE_SELECTED; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 11677 | if (hasWindowFocus()) viewStateIndex |= VIEW_STATE_WINDOW_FOCUSED; |
| 11678 | if ((privateFlags & ACTIVATED) != 0) viewStateIndex |= VIEW_STATE_ACTIVATED; |
Adam Powell | 5a7e94e | 2011-04-25 15:30:43 -0700 | [diff] [blame] | 11679 | if (mAttachInfo != null && mAttachInfo.mHardwareAccelerationRequested && |
| 11680 | HardwareRenderer.isAvailable()) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 11681 | // This is set if HW acceleration is requested, even if the current |
| 11682 | // process doesn't allow it. This is just to allow app preview |
| 11683 | // windows to better match their app. |
| 11684 | viewStateIndex |= VIEW_STATE_ACCELERATED; |
| 11685 | } |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 11686 | if ((privateFlags & HOVERED) != 0) viewStateIndex |= VIEW_STATE_HOVERED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11687 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 11688 | final int privateFlags2 = mPrivateFlags2; |
| 11689 | if ((privateFlags2 & DRAG_CAN_ACCEPT) != 0) viewStateIndex |= VIEW_STATE_DRAG_CAN_ACCEPT; |
| 11690 | if ((privateFlags2 & DRAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_DRAG_HOVERED; |
| 11691 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11692 | drawableState = VIEW_STATE_SETS[viewStateIndex]; |
| 11693 | |
| 11694 | //noinspection ConstantIfStatement |
| 11695 | if (false) { |
| 11696 | Log.i("View", "drawableStateIndex=" + viewStateIndex); |
| 11697 | Log.i("View", toString() |
| 11698 | + " pressed=" + ((privateFlags & PRESSED) != 0) |
| 11699 | + " en=" + ((mViewFlags & ENABLED_MASK) == ENABLED) |
| 11700 | + " fo=" + hasFocus() |
| 11701 | + " sl=" + ((privateFlags & SELECTED) != 0) |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 11702 | + " wf=" + hasWindowFocus() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11703 | + ": " + Arrays.toString(drawableState)); |
| 11704 | } |
| 11705 | |
| 11706 | if (extraSpace == 0) { |
| 11707 | return drawableState; |
| 11708 | } |
| 11709 | |
| 11710 | final int[] fullState; |
| 11711 | if (drawableState != null) { |
| 11712 | fullState = new int[drawableState.length + extraSpace]; |
| 11713 | System.arraycopy(drawableState, 0, fullState, 0, drawableState.length); |
| 11714 | } else { |
| 11715 | fullState = new int[extraSpace]; |
| 11716 | } |
| 11717 | |
| 11718 | return fullState; |
| 11719 | } |
| 11720 | |
| 11721 | /** |
| 11722 | * Merge your own state values in <var>additionalState</var> into the base |
| 11723 | * state values <var>baseState</var> that were returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11724 | * {@link #onCreateDrawableState(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11725 | * |
| 11726 | * @param baseState The base state values returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11727 | * {@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] | 11728 | * own additional state values. |
| 11729 | * |
| 11730 | * @param additionalState The additional state values you would like |
| 11731 | * added to <var>baseState</var>; this array is not modified. |
| 11732 | * |
| 11733 | * @return As a convenience, the <var>baseState</var> array you originally |
| 11734 | * passed into the function is returned. |
| 11735 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11736 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11737 | */ |
| 11738 | protected static int[] mergeDrawableStates(int[] baseState, int[] additionalState) { |
| 11739 | final int N = baseState.length; |
| 11740 | int i = N - 1; |
| 11741 | while (i >= 0 && baseState[i] == 0) { |
| 11742 | i--; |
| 11743 | } |
| 11744 | System.arraycopy(additionalState, 0, baseState, i + 1, additionalState.length); |
| 11745 | return baseState; |
| 11746 | } |
| 11747 | |
| 11748 | /** |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 11749 | * Call {@link Drawable#jumpToCurrentState() Drawable.jumpToCurrentState()} |
| 11750 | * on all Drawable objects associated with this view. |
| 11751 | */ |
| 11752 | public void jumpDrawablesToCurrentState() { |
| 11753 | if (mBGDrawable != null) { |
| 11754 | mBGDrawable.jumpToCurrentState(); |
| 11755 | } |
| 11756 | } |
| 11757 | |
| 11758 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11759 | * Sets the background color for this view. |
| 11760 | * @param color the color of the background |
| 11761 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 11762 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11763 | public void setBackgroundColor(int color) { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 11764 | if (mBGDrawable instanceof ColorDrawable) { |
| 11765 | ((ColorDrawable) mBGDrawable).setColor(color); |
| 11766 | } else { |
| 11767 | setBackgroundDrawable(new ColorDrawable(color)); |
| 11768 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11769 | } |
| 11770 | |
| 11771 | /** |
| 11772 | * Set the background to a given resource. The resource should refer to |
Wink Saville | 7cd88e1 | 2009-08-04 14:45:10 -0700 | [diff] [blame] | 11773 | * a Drawable object or 0 to remove the background. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11774 | * @param resid The identifier of the resource. |
| 11775 | * @attr ref android.R.styleable#View_background |
| 11776 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 11777 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11778 | public void setBackgroundResource(int resid) { |
| 11779 | if (resid != 0 && resid == mBackgroundResource) { |
| 11780 | return; |
| 11781 | } |
| 11782 | |
| 11783 | Drawable d= null; |
| 11784 | if (resid != 0) { |
| 11785 | d = mResources.getDrawable(resid); |
| 11786 | } |
| 11787 | setBackgroundDrawable(d); |
| 11788 | |
| 11789 | mBackgroundResource = resid; |
| 11790 | } |
| 11791 | |
| 11792 | /** |
| 11793 | * Set the background to a given Drawable, or remove the background. If the |
| 11794 | * background has padding, this View's padding is set to the background's |
| 11795 | * padding. However, when a background is removed, this View's padding isn't |
| 11796 | * touched. If setting the padding is desired, please use |
| 11797 | * {@link #setPadding(int, int, int, int)}. |
| 11798 | * |
| 11799 | * @param d The Drawable to use as the background, or null to remove the |
| 11800 | * background |
| 11801 | */ |
| 11802 | public void setBackgroundDrawable(Drawable d) { |
Adam Powell | 4d36ec1 | 2011-07-17 16:44:16 -0700 | [diff] [blame] | 11803 | if (d == mBGDrawable) { |
| 11804 | return; |
| 11805 | } |
| 11806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11807 | boolean requestLayout = false; |
| 11808 | |
| 11809 | mBackgroundResource = 0; |
| 11810 | |
| 11811 | /* |
| 11812 | * Regardless of whether we're setting a new background or not, we want |
| 11813 | * to clear the previous drawable. |
| 11814 | */ |
| 11815 | if (mBGDrawable != null) { |
| 11816 | mBGDrawable.setCallback(null); |
| 11817 | unscheduleDrawable(mBGDrawable); |
| 11818 | } |
| 11819 | |
| 11820 | if (d != null) { |
| 11821 | Rect padding = sThreadLocal.get(); |
| 11822 | if (padding == null) { |
| 11823 | padding = new Rect(); |
| 11824 | sThreadLocal.set(padding); |
| 11825 | } |
| 11826 | if (d.getPadding(padding)) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11827 | switch (d.getResolvedLayoutDirectionSelf()) { |
| 11828 | case LAYOUT_DIRECTION_RTL: |
| 11829 | setPadding(padding.right, padding.top, padding.left, padding.bottom); |
| 11830 | break; |
| 11831 | case LAYOUT_DIRECTION_LTR: |
| 11832 | default: |
| 11833 | setPadding(padding.left, padding.top, padding.right, padding.bottom); |
| 11834 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11835 | } |
| 11836 | |
| 11837 | // Compare the minimum sizes of the old Drawable and the new. If there isn't an old or |
| 11838 | // if it has a different minimum size, we should layout again |
| 11839 | if (mBGDrawable == null || mBGDrawable.getMinimumHeight() != d.getMinimumHeight() || |
| 11840 | mBGDrawable.getMinimumWidth() != d.getMinimumWidth()) { |
| 11841 | requestLayout = true; |
| 11842 | } |
| 11843 | |
| 11844 | d.setCallback(this); |
| 11845 | if (d.isStateful()) { |
| 11846 | d.setState(getDrawableState()); |
| 11847 | } |
| 11848 | d.setVisible(getVisibility() == VISIBLE, false); |
| 11849 | mBGDrawable = d; |
| 11850 | |
| 11851 | if ((mPrivateFlags & SKIP_DRAW) != 0) { |
| 11852 | mPrivateFlags &= ~SKIP_DRAW; |
| 11853 | mPrivateFlags |= ONLY_DRAWS_BACKGROUND; |
| 11854 | requestLayout = true; |
| 11855 | } |
| 11856 | } else { |
| 11857 | /* Remove the background */ |
| 11858 | mBGDrawable = null; |
| 11859 | |
| 11860 | if ((mPrivateFlags & ONLY_DRAWS_BACKGROUND) != 0) { |
| 11861 | /* |
| 11862 | * This view ONLY drew the background before and we're removing |
| 11863 | * the background, so now it won't draw anything |
| 11864 | * (hence we SKIP_DRAW) |
| 11865 | */ |
| 11866 | mPrivateFlags &= ~ONLY_DRAWS_BACKGROUND; |
| 11867 | mPrivateFlags |= SKIP_DRAW; |
| 11868 | } |
| 11869 | |
| 11870 | /* |
| 11871 | * When the background is set, we try to apply its padding to this |
| 11872 | * View. When the background is removed, we don't touch this View's |
| 11873 | * padding. This is noted in the Javadocs. Hence, we don't need to |
| 11874 | * requestLayout(), the invalidate() below is sufficient. |
| 11875 | */ |
| 11876 | |
| 11877 | // The old background's minimum size could have affected this |
| 11878 | // View's layout, so let's requestLayout |
| 11879 | requestLayout = true; |
| 11880 | } |
| 11881 | |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 11882 | computeOpaqueFlags(); |
| 11883 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11884 | if (requestLayout) { |
| 11885 | requestLayout(); |
| 11886 | } |
| 11887 | |
| 11888 | mBackgroundSizeChanged = true; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 11889 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11890 | } |
| 11891 | |
| 11892 | /** |
| 11893 | * Gets the background drawable |
| 11894 | * @return The drawable used as the background for this view, if any. |
| 11895 | */ |
| 11896 | public Drawable getBackground() { |
| 11897 | return mBGDrawable; |
| 11898 | } |
| 11899 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11900 | /** |
| 11901 | * Sets the padding. The view may add on the space required to display |
| 11902 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 11903 | * So the values returned from {@link #getPaddingLeft}, {@link #getPaddingTop}, |
| 11904 | * {@link #getPaddingRight} and {@link #getPaddingBottom} may be different |
| 11905 | * from the values set in this call. |
| 11906 | * |
| 11907 | * @attr ref android.R.styleable#View_padding |
| 11908 | * @attr ref android.R.styleable#View_paddingBottom |
| 11909 | * @attr ref android.R.styleable#View_paddingLeft |
| 11910 | * @attr ref android.R.styleable#View_paddingRight |
| 11911 | * @attr ref android.R.styleable#View_paddingTop |
| 11912 | * @param left the left padding in pixels |
| 11913 | * @param top the top padding in pixels |
| 11914 | * @param right the right padding in pixels |
| 11915 | * @param bottom the bottom padding in pixels |
| 11916 | */ |
| 11917 | public void setPadding(int left, int top, int right, int bottom) { |
| 11918 | boolean changed = false; |
| 11919 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11920 | mUserPaddingRelative = false; |
| 11921 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11922 | mUserPaddingLeft = left; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11923 | mUserPaddingRight = right; |
| 11924 | mUserPaddingBottom = bottom; |
| 11925 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11926 | final int viewFlags = mViewFlags; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11927 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11928 | // Common case is there are no scroll bars. |
| 11929 | if ((viewFlags & (SCROLLBARS_VERTICAL|SCROLLBARS_HORIZONTAL)) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11930 | if ((viewFlags & SCROLLBARS_VERTICAL) != 0) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11931 | final int offset = (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11932 | ? 0 : getVerticalScrollbarWidth(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11933 | switch (mVerticalScrollbarPosition) { |
| 11934 | case SCROLLBAR_POSITION_DEFAULT: |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11935 | if (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
| 11936 | left += offset; |
| 11937 | } else { |
| 11938 | right += offset; |
| 11939 | } |
| 11940 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11941 | case SCROLLBAR_POSITION_RIGHT: |
| 11942 | right += offset; |
| 11943 | break; |
| 11944 | case SCROLLBAR_POSITION_LEFT: |
| 11945 | left += offset; |
| 11946 | break; |
| 11947 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11948 | } |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11949 | if ((viewFlags & SCROLLBARS_HORIZONTAL) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11950 | bottom += (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
| 11951 | ? 0 : getHorizontalScrollbarHeight(); |
| 11952 | } |
| 11953 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11954 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11955 | if (mPaddingLeft != left) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11956 | changed = true; |
| 11957 | mPaddingLeft = left; |
| 11958 | } |
| 11959 | if (mPaddingTop != top) { |
| 11960 | changed = true; |
| 11961 | mPaddingTop = top; |
| 11962 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11963 | if (mPaddingRight != right) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11964 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11965 | mPaddingRight = right; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11966 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11967 | if (mPaddingBottom != bottom) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11968 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11969 | mPaddingBottom = bottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11970 | } |
| 11971 | |
| 11972 | if (changed) { |
| 11973 | requestLayout(); |
| 11974 | } |
| 11975 | } |
| 11976 | |
| 11977 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11978 | * Sets the relative padding. The view may add on the space required to display |
| 11979 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 11980 | * So the values returned from {@link #getPaddingStart}, {@link #getPaddingTop}, |
| 11981 | * {@link #getPaddingEnd} and {@link #getPaddingBottom} may be different |
| 11982 | * from the values set in this call. |
| 11983 | * |
| 11984 | * @attr ref android.R.styleable#View_padding |
| 11985 | * @attr ref android.R.styleable#View_paddingBottom |
| 11986 | * @attr ref android.R.styleable#View_paddingStart |
| 11987 | * @attr ref android.R.styleable#View_paddingEnd |
| 11988 | * @attr ref android.R.styleable#View_paddingTop |
| 11989 | * @param start the start padding in pixels |
| 11990 | * @param top the top padding in pixels |
| 11991 | * @param end the end padding in pixels |
| 11992 | * @param bottom the bottom padding in pixels |
| 11993 | * |
| 11994 | * @hide |
| 11995 | */ |
| 11996 | public void setPaddingRelative(int start, int top, int end, int bottom) { |
| 11997 | mUserPaddingRelative = true; |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 11998 | |
| 11999 | mUserPaddingStart = start; |
| 12000 | mUserPaddingEnd = end; |
| 12001 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12002 | switch(getResolvedLayoutDirection()) { |
| 12003 | case LAYOUT_DIRECTION_RTL: |
| 12004 | setPadding(end, top, start, bottom); |
| 12005 | break; |
| 12006 | case LAYOUT_DIRECTION_LTR: |
| 12007 | default: |
| 12008 | setPadding(start, top, end, bottom); |
| 12009 | } |
| 12010 | } |
| 12011 | |
| 12012 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12013 | * Returns the top padding of this view. |
| 12014 | * |
| 12015 | * @return the top padding in pixels |
| 12016 | */ |
| 12017 | public int getPaddingTop() { |
| 12018 | return mPaddingTop; |
| 12019 | } |
| 12020 | |
| 12021 | /** |
| 12022 | * Returns the bottom padding of this view. If there are inset and enabled |
| 12023 | * scrollbars, this value may include the space required to display the |
| 12024 | * scrollbars as well. |
| 12025 | * |
| 12026 | * @return the bottom padding in pixels |
| 12027 | */ |
| 12028 | public int getPaddingBottom() { |
| 12029 | return mPaddingBottom; |
| 12030 | } |
| 12031 | |
| 12032 | /** |
| 12033 | * Returns the left padding of this view. If there are inset and enabled |
| 12034 | * scrollbars, this value may include the space required to display the |
| 12035 | * scrollbars as well. |
| 12036 | * |
| 12037 | * @return the left padding in pixels |
| 12038 | */ |
| 12039 | public int getPaddingLeft() { |
| 12040 | return mPaddingLeft; |
| 12041 | } |
| 12042 | |
| 12043 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12044 | * Returns the start padding of this view. If there are inset and enabled |
| 12045 | * scrollbars, this value may include the space required to display the |
| 12046 | * scrollbars as well. |
| 12047 | * |
| 12048 | * @return the start padding in pixels |
| 12049 | * |
| 12050 | * @hide |
| 12051 | */ |
| 12052 | public int getPaddingStart() { |
| 12053 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
| 12054 | mPaddingRight : mPaddingLeft; |
| 12055 | } |
| 12056 | |
| 12057 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12058 | * Returns the right padding of this view. If there are inset and enabled |
| 12059 | * scrollbars, this value may include the space required to display the |
| 12060 | * scrollbars as well. |
| 12061 | * |
| 12062 | * @return the right padding in pixels |
| 12063 | */ |
| 12064 | public int getPaddingRight() { |
| 12065 | return mPaddingRight; |
| 12066 | } |
| 12067 | |
| 12068 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12069 | * Returns the end padding of this view. If there are inset and enabled |
| 12070 | * scrollbars, this value may include the space required to display the |
| 12071 | * scrollbars as well. |
| 12072 | * |
| 12073 | * @return the end padding in pixels |
| 12074 | * |
| 12075 | * @hide |
| 12076 | */ |
| 12077 | public int getPaddingEnd() { |
| 12078 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
| 12079 | mPaddingLeft : mPaddingRight; |
| 12080 | } |
| 12081 | |
| 12082 | /** |
| 12083 | * Return if the padding as been set thru relative values |
| 12084 | * {@link #setPaddingRelative(int, int, int, int)} or thru |
| 12085 | * @attr ref android.R.styleable#View_paddingStart or |
| 12086 | * @attr ref android.R.styleable#View_paddingEnd |
| 12087 | * |
| 12088 | * @return true if the padding is relative or false if it is not. |
| 12089 | * |
| 12090 | * @hide |
| 12091 | */ |
| 12092 | public boolean isPaddingRelative() { |
| 12093 | return mUserPaddingRelative; |
| 12094 | } |
| 12095 | |
| 12096 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12097 | * Changes the selection state of this view. A view can be selected or not. |
| 12098 | * Note that selection is not the same as focus. Views are typically |
| 12099 | * selected in the context of an AdapterView like ListView or GridView; |
| 12100 | * the selected view is the view that is highlighted. |
| 12101 | * |
| 12102 | * @param selected true if the view must be selected, false otherwise |
| 12103 | */ |
| 12104 | public void setSelected(boolean selected) { |
| 12105 | if (((mPrivateFlags & SELECTED) != 0) != selected) { |
| 12106 | mPrivateFlags = (mPrivateFlags & ~SELECTED) | (selected ? SELECTED : 0); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 12107 | if (!selected) resetPressedState(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 12108 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12109 | refreshDrawableState(); |
| 12110 | dispatchSetSelected(selected); |
| 12111 | } |
| 12112 | } |
| 12113 | |
| 12114 | /** |
| 12115 | * Dispatch setSelected to all of this View's children. |
| 12116 | * |
| 12117 | * @see #setSelected(boolean) |
| 12118 | * |
| 12119 | * @param selected The new selected state |
| 12120 | */ |
| 12121 | protected void dispatchSetSelected(boolean selected) { |
| 12122 | } |
| 12123 | |
| 12124 | /** |
| 12125 | * Indicates the selection state of this view. |
| 12126 | * |
| 12127 | * @return true if the view is selected, false otherwise |
| 12128 | */ |
| 12129 | @ViewDebug.ExportedProperty |
| 12130 | public boolean isSelected() { |
| 12131 | return (mPrivateFlags & SELECTED) != 0; |
| 12132 | } |
| 12133 | |
| 12134 | /** |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 12135 | * Changes the activated state of this view. A view can be activated or not. |
| 12136 | * Note that activation is not the same as selection. Selection is |
| 12137 | * a transient property, representing the view (hierarchy) the user is |
| 12138 | * currently interacting with. Activation is a longer-term state that the |
| 12139 | * user can move views in and out of. For example, in a list view with |
| 12140 | * single or multiple selection enabled, the views in the current selection |
| 12141 | * set are activated. (Um, yeah, we are deeply sorry about the terminology |
| 12142 | * here.) The activated state is propagated down to children of the view it |
| 12143 | * is set on. |
| 12144 | * |
| 12145 | * @param activated true if the view must be activated, false otherwise |
| 12146 | */ |
| 12147 | public void setActivated(boolean activated) { |
| 12148 | if (((mPrivateFlags & ACTIVATED) != 0) != activated) { |
| 12149 | mPrivateFlags = (mPrivateFlags & ~ACTIVATED) | (activated ? ACTIVATED : 0); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 12150 | invalidate(true); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 12151 | refreshDrawableState(); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 12152 | dispatchSetActivated(activated); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 12153 | } |
| 12154 | } |
| 12155 | |
| 12156 | /** |
| 12157 | * Dispatch setActivated to all of this View's children. |
| 12158 | * |
| 12159 | * @see #setActivated(boolean) |
| 12160 | * |
| 12161 | * @param activated The new activated state |
| 12162 | */ |
| 12163 | protected void dispatchSetActivated(boolean activated) { |
| 12164 | } |
| 12165 | |
| 12166 | /** |
| 12167 | * Indicates the activation state of this view. |
| 12168 | * |
| 12169 | * @return true if the view is activated, false otherwise |
| 12170 | */ |
| 12171 | @ViewDebug.ExportedProperty |
| 12172 | public boolean isActivated() { |
| 12173 | return (mPrivateFlags & ACTIVATED) != 0; |
| 12174 | } |
| 12175 | |
| 12176 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12177 | * Returns the ViewTreeObserver for this view's hierarchy. The view tree |
| 12178 | * observer can be used to get notifications when global events, like |
| 12179 | * layout, happen. |
| 12180 | * |
| 12181 | * The returned ViewTreeObserver observer is not guaranteed to remain |
| 12182 | * valid for the lifetime of this View. If the caller of this method keeps |
| 12183 | * a long-lived reference to ViewTreeObserver, it should always check for |
| 12184 | * the return value of {@link ViewTreeObserver#isAlive()}. |
| 12185 | * |
| 12186 | * @return The ViewTreeObserver for this view's hierarchy. |
| 12187 | */ |
| 12188 | public ViewTreeObserver getViewTreeObserver() { |
| 12189 | if (mAttachInfo != null) { |
| 12190 | return mAttachInfo.mTreeObserver; |
| 12191 | } |
| 12192 | if (mFloatingTreeObserver == null) { |
| 12193 | mFloatingTreeObserver = new ViewTreeObserver(); |
| 12194 | } |
| 12195 | return mFloatingTreeObserver; |
| 12196 | } |
| 12197 | |
| 12198 | /** |
| 12199 | * <p>Finds the topmost view in the current view hierarchy.</p> |
| 12200 | * |
| 12201 | * @return the topmost view containing this view |
| 12202 | */ |
| 12203 | public View getRootView() { |
| 12204 | if (mAttachInfo != null) { |
| 12205 | final View v = mAttachInfo.mRootView; |
| 12206 | if (v != null) { |
| 12207 | return v; |
| 12208 | } |
| 12209 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12210 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12211 | View parent = this; |
| 12212 | |
| 12213 | while (parent.mParent != null && parent.mParent instanceof View) { |
| 12214 | parent = (View) parent.mParent; |
| 12215 | } |
| 12216 | |
| 12217 | return parent; |
| 12218 | } |
| 12219 | |
| 12220 | /** |
| 12221 | * <p>Computes the coordinates of this view on the screen. The argument |
| 12222 | * must be an array of two integers. After the method returns, the array |
| 12223 | * contains the x and y location in that order.</p> |
| 12224 | * |
| 12225 | * @param location an array of two integers in which to hold the coordinates |
| 12226 | */ |
| 12227 | public void getLocationOnScreen(int[] location) { |
| 12228 | getLocationInWindow(location); |
| 12229 | |
| 12230 | final AttachInfo info = mAttachInfo; |
Romain Guy | 779398e | 2009-06-16 13:17:50 -0700 | [diff] [blame] | 12231 | if (info != null) { |
| 12232 | location[0] += info.mWindowLeft; |
| 12233 | location[1] += info.mWindowTop; |
| 12234 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12235 | } |
| 12236 | |
| 12237 | /** |
| 12238 | * <p>Computes the coordinates of this view in its window. The argument |
| 12239 | * must be an array of two integers. After the method returns, the array |
| 12240 | * contains the x and y location in that order.</p> |
| 12241 | * |
| 12242 | * @param location an array of two integers in which to hold the coordinates |
| 12243 | */ |
| 12244 | public void getLocationInWindow(int[] location) { |
| 12245 | if (location == null || location.length < 2) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 12246 | throw new IllegalArgumentException("location must be an array of two integers"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12247 | } |
| 12248 | |
Gilles Debunne | 6583ce5 | 2011-12-06 18:09:02 -0800 | [diff] [blame] | 12249 | if (mAttachInfo == null) { |
| 12250 | // When the view is not attached to a window, this method does not make sense |
| 12251 | location[0] = location[1] = 0; |
| 12252 | return; |
| 12253 | } |
| 12254 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 12255 | float[] position = mAttachInfo.mTmpTransformLocation; |
| 12256 | position[0] = position[1] = 0.0f; |
| 12257 | |
| 12258 | if (!hasIdentityMatrix()) { |
| 12259 | getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 12260 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12261 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 12262 | position[0] += mLeft; |
| 12263 | position[1] += mTop; |
| 12264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12265 | ViewParent viewParent = mParent; |
| 12266 | while (viewParent instanceof View) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 12267 | final View view = (View) viewParent; |
| 12268 | |
| 12269 | position[0] -= view.mScrollX; |
| 12270 | position[1] -= view.mScrollY; |
| 12271 | |
| 12272 | if (!view.hasIdentityMatrix()) { |
| 12273 | view.getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 12274 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 12275 | |
| 12276 | position[0] += view.mLeft; |
| 12277 | position[1] += view.mTop; |
| 12278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12279 | viewParent = view.mParent; |
| 12280 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12281 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 12282 | if (viewParent instanceof ViewRootImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12283 | // *cough* |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 12284 | final ViewRootImpl vr = (ViewRootImpl) viewParent; |
| 12285 | position[1] -= vr.mCurScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12286 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 12287 | |
| 12288 | location[0] = (int) (position[0] + 0.5f); |
| 12289 | location[1] = (int) (position[1] + 0.5f); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12290 | } |
| 12291 | |
| 12292 | /** |
| 12293 | * {@hide} |
| 12294 | * @param id the id of the view to be found |
| 12295 | * @return the view of the specified id, null if cannot be found |
| 12296 | */ |
| 12297 | protected View findViewTraversal(int id) { |
| 12298 | if (id == mID) { |
| 12299 | return this; |
| 12300 | } |
| 12301 | return null; |
| 12302 | } |
| 12303 | |
| 12304 | /** |
| 12305 | * {@hide} |
| 12306 | * @param tag the tag of the view to be found |
| 12307 | * @return the view of specified tag, null if cannot be found |
| 12308 | */ |
| 12309 | protected View findViewWithTagTraversal(Object tag) { |
| 12310 | if (tag != null && tag.equals(mTag)) { |
| 12311 | return this; |
| 12312 | } |
| 12313 | return null; |
| 12314 | } |
| 12315 | |
| 12316 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 12317 | * {@hide} |
| 12318 | * @param predicate The predicate to evaluate. |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 12319 | * @param childToSkip If not null, ignores this child during the recursive traversal. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 12320 | * @return The first view that matches the predicate or null. |
| 12321 | */ |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 12322 | protected View findViewByPredicateTraversal(Predicate<View> predicate, View childToSkip) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 12323 | if (predicate.apply(this)) { |
| 12324 | return this; |
| 12325 | } |
| 12326 | return null; |
| 12327 | } |
| 12328 | |
| 12329 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12330 | * Look for a child view with the given id. If this view has the given |
| 12331 | * id, return this view. |
| 12332 | * |
| 12333 | * @param id The id to search for. |
| 12334 | * @return The view that has the given id in the hierarchy or null |
| 12335 | */ |
| 12336 | public final View findViewById(int id) { |
| 12337 | if (id < 0) { |
| 12338 | return null; |
| 12339 | } |
| 12340 | return findViewTraversal(id); |
| 12341 | } |
| 12342 | |
| 12343 | /** |
Svetoslav Ganov | 2cdedff | 2011-10-03 14:18:42 -0700 | [diff] [blame] | 12344 | * Finds a view by its unuque and stable accessibility id. |
| 12345 | * |
| 12346 | * @param accessibilityId The searched accessibility id. |
| 12347 | * @return The found view. |
| 12348 | */ |
| 12349 | final View findViewByAccessibilityId(int accessibilityId) { |
| 12350 | if (accessibilityId < 0) { |
| 12351 | return null; |
| 12352 | } |
| 12353 | return findViewByAccessibilityIdTraversal(accessibilityId); |
| 12354 | } |
| 12355 | |
| 12356 | /** |
| 12357 | * Performs the traversal to find a view by its unuque and stable accessibility id. |
| 12358 | * |
| 12359 | * <strong>Note:</strong>This method does not stop at the root namespace |
| 12360 | * boundary since the user can touch the screen at an arbitrary location |
| 12361 | * potentially crossing the root namespace bounday which will send an |
| 12362 | * accessibility event to accessibility services and they should be able |
| 12363 | * to obtain the event source. Also accessibility ids are guaranteed to be |
| 12364 | * unique in the window. |
| 12365 | * |
| 12366 | * @param accessibilityId The accessibility id. |
| 12367 | * @return The found view. |
| 12368 | */ |
| 12369 | View findViewByAccessibilityIdTraversal(int accessibilityId) { |
| 12370 | if (getAccessibilityViewId() == accessibilityId) { |
| 12371 | return this; |
| 12372 | } |
| 12373 | return null; |
| 12374 | } |
| 12375 | |
| 12376 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12377 | * Look for a child view with the given tag. If this view has the given |
| 12378 | * tag, return this view. |
| 12379 | * |
| 12380 | * @param tag The tag to search for, using "tag.equals(getTag())". |
| 12381 | * @return The View that has the given tag in the hierarchy or null |
| 12382 | */ |
| 12383 | public final View findViewWithTag(Object tag) { |
| 12384 | if (tag == null) { |
| 12385 | return null; |
| 12386 | } |
| 12387 | return findViewWithTagTraversal(tag); |
| 12388 | } |
| 12389 | |
| 12390 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 12391 | * {@hide} |
| 12392 | * Look for a child view that matches the specified predicate. |
| 12393 | * If this view matches the predicate, return this view. |
| 12394 | * |
| 12395 | * @param predicate The predicate to evaluate. |
| 12396 | * @return The first view that matches the predicate or null. |
| 12397 | */ |
| 12398 | public final View findViewByPredicate(Predicate<View> predicate) { |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 12399 | return findViewByPredicateTraversal(predicate, null); |
| 12400 | } |
| 12401 | |
| 12402 | /** |
| 12403 | * {@hide} |
| 12404 | * Look for a child view that matches the specified predicate, |
| 12405 | * starting with the specified view and its descendents and then |
| 12406 | * recusively searching the ancestors and siblings of that view |
| 12407 | * until this view is reached. |
| 12408 | * |
| 12409 | * This method is useful in cases where the predicate does not match |
| 12410 | * a single unique view (perhaps multiple views use the same id) |
| 12411 | * and we are trying to find the view that is "closest" in scope to the |
| 12412 | * starting view. |
| 12413 | * |
| 12414 | * @param start The view to start from. |
| 12415 | * @param predicate The predicate to evaluate. |
| 12416 | * @return The first view that matches the predicate or null. |
| 12417 | */ |
| 12418 | public final View findViewByPredicateInsideOut(View start, Predicate<View> predicate) { |
| 12419 | View childToSkip = null; |
| 12420 | for (;;) { |
| 12421 | View view = start.findViewByPredicateTraversal(predicate, childToSkip); |
| 12422 | if (view != null || start == this) { |
| 12423 | return view; |
| 12424 | } |
| 12425 | |
| 12426 | ViewParent parent = start.getParent(); |
| 12427 | if (parent == null || !(parent instanceof View)) { |
| 12428 | return null; |
| 12429 | } |
| 12430 | |
| 12431 | childToSkip = start; |
| 12432 | start = (View) parent; |
| 12433 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 12434 | } |
| 12435 | |
| 12436 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12437 | * Sets the identifier for this view. The identifier does not have to be |
| 12438 | * unique in this view's hierarchy. The identifier should be a positive |
| 12439 | * number. |
| 12440 | * |
| 12441 | * @see #NO_ID |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12442 | * @see #getId() |
| 12443 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12444 | * |
| 12445 | * @param id a number used to identify the view |
| 12446 | * |
| 12447 | * @attr ref android.R.styleable#View_id |
| 12448 | */ |
| 12449 | public void setId(int id) { |
| 12450 | mID = id; |
| 12451 | } |
| 12452 | |
| 12453 | /** |
| 12454 | * {@hide} |
| 12455 | * |
| 12456 | * @param isRoot true if the view belongs to the root namespace, false |
| 12457 | * otherwise |
| 12458 | */ |
| 12459 | public void setIsRootNamespace(boolean isRoot) { |
| 12460 | if (isRoot) { |
| 12461 | mPrivateFlags |= IS_ROOT_NAMESPACE; |
| 12462 | } else { |
| 12463 | mPrivateFlags &= ~IS_ROOT_NAMESPACE; |
| 12464 | } |
| 12465 | } |
| 12466 | |
| 12467 | /** |
| 12468 | * {@hide} |
| 12469 | * |
| 12470 | * @return true if the view belongs to the root namespace, false otherwise |
| 12471 | */ |
| 12472 | public boolean isRootNamespace() { |
| 12473 | return (mPrivateFlags&IS_ROOT_NAMESPACE) != 0; |
| 12474 | } |
| 12475 | |
| 12476 | /** |
| 12477 | * Returns this view's identifier. |
| 12478 | * |
| 12479 | * @return a positive integer used to identify the view or {@link #NO_ID} |
| 12480 | * if the view has no ID |
| 12481 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12482 | * @see #setId(int) |
| 12483 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12484 | * @attr ref android.R.styleable#View_id |
| 12485 | */ |
| 12486 | @ViewDebug.CapturedViewProperty |
| 12487 | public int getId() { |
| 12488 | return mID; |
| 12489 | } |
| 12490 | |
| 12491 | /** |
| 12492 | * Returns this view's tag. |
| 12493 | * |
| 12494 | * @return the Object stored in this view as a tag |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12495 | * |
| 12496 | * @see #setTag(Object) |
| 12497 | * @see #getTag(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12498 | */ |
| 12499 | @ViewDebug.ExportedProperty |
| 12500 | public Object getTag() { |
| 12501 | return mTag; |
| 12502 | } |
| 12503 | |
| 12504 | /** |
| 12505 | * Sets the tag associated with this view. A tag can be used to mark |
| 12506 | * a view in its hierarchy and does not have to be unique within the |
| 12507 | * hierarchy. Tags can also be used to store data within a view without |
| 12508 | * resorting to another data structure. |
| 12509 | * |
| 12510 | * @param tag an Object to tag the view with |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12511 | * |
| 12512 | * @see #getTag() |
| 12513 | * @see #setTag(int, Object) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12514 | */ |
| 12515 | public void setTag(final Object tag) { |
| 12516 | mTag = tag; |
| 12517 | } |
| 12518 | |
| 12519 | /** |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12520 | * Returns the tag associated with this view and the specified key. |
| 12521 | * |
| 12522 | * @param key The key identifying the tag |
| 12523 | * |
| 12524 | * @return the Object stored in this view as a tag |
| 12525 | * |
| 12526 | * @see #setTag(int, Object) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12527 | * @see #getTag() |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12528 | */ |
| 12529 | public Object getTag(int key) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 12530 | if (mKeyedTags != null) return mKeyedTags.get(key); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12531 | return null; |
| 12532 | } |
| 12533 | |
| 12534 | /** |
| 12535 | * Sets a tag associated with this view and a key. A tag can be used |
| 12536 | * to mark a view in its hierarchy and does not have to be unique within |
| 12537 | * the hierarchy. Tags can also be used to store data within a view |
| 12538 | * without resorting to another data structure. |
| 12539 | * |
| 12540 | * 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] | 12541 | * application to ensure it is unique (see the <a |
| 12542 | * href={@docRoot}guide/topics/resources/more-resources.html#Id">ID resource type</a>). |
| 12543 | * Keys identified as belonging to |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12544 | * the Android framework or not associated with any package will cause |
| 12545 | * an {@link IllegalArgumentException} to be thrown. |
| 12546 | * |
| 12547 | * @param key The key identifying the tag |
| 12548 | * @param tag An Object to tag the view with |
| 12549 | * |
| 12550 | * @throws IllegalArgumentException If they specified key is not valid |
| 12551 | * |
| 12552 | * @see #setTag(Object) |
| 12553 | * @see #getTag(int) |
| 12554 | */ |
| 12555 | public void setTag(int key, final Object tag) { |
| 12556 | // If the package id is 0x00 or 0x01, it's either an undefined package |
| 12557 | // or a framework id |
| 12558 | if ((key >>> 24) < 2) { |
| 12559 | throw new IllegalArgumentException("The key must be an application-specific " |
| 12560 | + "resource id."); |
| 12561 | } |
| 12562 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 12563 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12564 | } |
| 12565 | |
| 12566 | /** |
| 12567 | * Variation of {@link #setTag(int, Object)} that enforces the key to be a |
| 12568 | * framework id. |
| 12569 | * |
| 12570 | * @hide |
| 12571 | */ |
| 12572 | public void setTagInternal(int key, Object tag) { |
| 12573 | if ((key >>> 24) != 0x1) { |
| 12574 | throw new IllegalArgumentException("The key must be a framework-specific " |
| 12575 | + "resource id."); |
| 12576 | } |
| 12577 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 12578 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12579 | } |
| 12580 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 12581 | private void setKeyedTag(int key, Object tag) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 12582 | if (mKeyedTags == null) { |
| 12583 | mKeyedTags = new SparseArray<Object>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12584 | } |
| 12585 | |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 12586 | mKeyedTags.put(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12587 | } |
| 12588 | |
| 12589 | /** |
Romain Guy | 13922e0 | 2009-05-12 17:56:14 -0700 | [diff] [blame] | 12590 | * @param consistency The type of consistency. See ViewDebug for more information. |
| 12591 | * |
| 12592 | * @hide |
| 12593 | */ |
| 12594 | protected boolean dispatchConsistencyCheck(int consistency) { |
| 12595 | return onConsistencyCheck(consistency); |
| 12596 | } |
| 12597 | |
| 12598 | /** |
| 12599 | * Method that subclasses should implement to check their consistency. The type of |
| 12600 | * consistency check is indicated by the bit field passed as a parameter. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12601 | * |
Romain Guy | 13922e0 | 2009-05-12 17:56:14 -0700 | [diff] [blame] | 12602 | * @param consistency The type of consistency. See ViewDebug for more information. |
| 12603 | * |
| 12604 | * @throws IllegalStateException if the view is in an inconsistent state. |
| 12605 | * |
| 12606 | * @hide |
| 12607 | */ |
| 12608 | protected boolean onConsistencyCheck(int consistency) { |
| 12609 | boolean result = true; |
| 12610 | |
| 12611 | final boolean checkLayout = (consistency & ViewDebug.CONSISTENCY_LAYOUT) != 0; |
| 12612 | final boolean checkDrawing = (consistency & ViewDebug.CONSISTENCY_DRAWING) != 0; |
| 12613 | |
| 12614 | if (checkLayout) { |
| 12615 | if (getParent() == null) { |
| 12616 | result = false; |
| 12617 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 12618 | "View " + this + " does not have a parent."); |
| 12619 | } |
| 12620 | |
| 12621 | if (mAttachInfo == null) { |
| 12622 | result = false; |
| 12623 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 12624 | "View " + this + " is not attached to a window."); |
| 12625 | } |
| 12626 | } |
| 12627 | |
| 12628 | if (checkDrawing) { |
| 12629 | // Do not check the DIRTY/DRAWN flags because views can call invalidate() |
| 12630 | // from their draw() method |
| 12631 | |
| 12632 | if ((mPrivateFlags & DRAWN) != DRAWN && |
| 12633 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) { |
| 12634 | result = false; |
| 12635 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 12636 | "View " + this + " was invalidated but its drawing cache is valid."); |
| 12637 | } |
| 12638 | } |
| 12639 | |
| 12640 | return result; |
| 12641 | } |
| 12642 | |
| 12643 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12644 | * Prints information about this view in the log output, with the tag |
| 12645 | * {@link #VIEW_LOG_TAG}. |
| 12646 | * |
| 12647 | * @hide |
| 12648 | */ |
| 12649 | public void debug() { |
| 12650 | debug(0); |
| 12651 | } |
| 12652 | |
| 12653 | /** |
| 12654 | * Prints information about this view in the log output, with the tag |
| 12655 | * {@link #VIEW_LOG_TAG}. Each line in the output is preceded with an |
| 12656 | * indentation defined by the <code>depth</code>. |
| 12657 | * |
| 12658 | * @param depth the indentation level |
| 12659 | * |
| 12660 | * @hide |
| 12661 | */ |
| 12662 | protected void debug(int depth) { |
| 12663 | String output = debugIndent(depth - 1); |
| 12664 | |
| 12665 | output += "+ " + this; |
| 12666 | int id = getId(); |
| 12667 | if (id != -1) { |
| 12668 | output += " (id=" + id + ")"; |
| 12669 | } |
| 12670 | Object tag = getTag(); |
| 12671 | if (tag != null) { |
| 12672 | output += " (tag=" + tag + ")"; |
| 12673 | } |
| 12674 | Log.d(VIEW_LOG_TAG, output); |
| 12675 | |
| 12676 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 12677 | output = debugIndent(depth) + " FOCUSED"; |
| 12678 | Log.d(VIEW_LOG_TAG, output); |
| 12679 | } |
| 12680 | |
| 12681 | output = debugIndent(depth); |
| 12682 | output += "frame={" + mLeft + ", " + mTop + ", " + mRight |
| 12683 | + ", " + mBottom + "} scroll={" + mScrollX + ", " + mScrollY |
| 12684 | + "} "; |
| 12685 | Log.d(VIEW_LOG_TAG, output); |
| 12686 | |
| 12687 | if (mPaddingLeft != 0 || mPaddingTop != 0 || mPaddingRight != 0 |
| 12688 | || mPaddingBottom != 0) { |
| 12689 | output = debugIndent(depth); |
| 12690 | output += "padding={" + mPaddingLeft + ", " + mPaddingTop |
| 12691 | + ", " + mPaddingRight + ", " + mPaddingBottom + "}"; |
| 12692 | Log.d(VIEW_LOG_TAG, output); |
| 12693 | } |
| 12694 | |
| 12695 | output = debugIndent(depth); |
| 12696 | output += "mMeasureWidth=" + mMeasuredWidth + |
| 12697 | " mMeasureHeight=" + mMeasuredHeight; |
| 12698 | Log.d(VIEW_LOG_TAG, output); |
| 12699 | |
| 12700 | output = debugIndent(depth); |
| 12701 | if (mLayoutParams == null) { |
| 12702 | output += "BAD! no layout params"; |
| 12703 | } else { |
| 12704 | output = mLayoutParams.debug(output); |
| 12705 | } |
| 12706 | Log.d(VIEW_LOG_TAG, output); |
| 12707 | |
| 12708 | output = debugIndent(depth); |
| 12709 | output += "flags={"; |
| 12710 | output += View.printFlags(mViewFlags); |
| 12711 | output += "}"; |
| 12712 | Log.d(VIEW_LOG_TAG, output); |
| 12713 | |
| 12714 | output = debugIndent(depth); |
| 12715 | output += "privateFlags={"; |
| 12716 | output += View.printPrivateFlags(mPrivateFlags); |
| 12717 | output += "}"; |
| 12718 | Log.d(VIEW_LOG_TAG, output); |
| 12719 | } |
| 12720 | |
| 12721 | /** |
| 12722 | * Creates an string of whitespaces used for indentation. |
| 12723 | * |
| 12724 | * @param depth the indentation level |
| 12725 | * @return a String containing (depth * 2 + 3) * 2 white spaces |
| 12726 | * |
| 12727 | * @hide |
| 12728 | */ |
| 12729 | protected static String debugIndent(int depth) { |
| 12730 | StringBuilder spaces = new StringBuilder((depth * 2 + 3) * 2); |
| 12731 | for (int i = 0; i < (depth * 2) + 3; i++) { |
| 12732 | spaces.append(' ').append(' '); |
| 12733 | } |
| 12734 | return spaces.toString(); |
| 12735 | } |
| 12736 | |
| 12737 | /** |
| 12738 | * <p>Return the offset of the widget's text baseline from the widget's top |
| 12739 | * boundary. If this widget does not support baseline alignment, this |
| 12740 | * method returns -1. </p> |
| 12741 | * |
| 12742 | * @return the offset of the baseline within the widget's bounds or -1 |
| 12743 | * if baseline alignment is not supported |
| 12744 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 12745 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12746 | public int getBaseline() { |
| 12747 | return -1; |
| 12748 | } |
| 12749 | |
| 12750 | /** |
| 12751 | * Call this when something has changed which has invalidated the |
| 12752 | * layout of this view. This will schedule a layout pass of the view |
| 12753 | * tree. |
| 12754 | */ |
| 12755 | public void requestLayout() { |
| 12756 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12757 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.REQUEST_LAYOUT); |
| 12758 | } |
| 12759 | |
| 12760 | mPrivateFlags |= FORCE_LAYOUT; |
Chet Haase | 5af048c | 2011-01-24 17:00:32 -0800 | [diff] [blame] | 12761 | mPrivateFlags |= INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12762 | |
Fabrice Di Meglio | d794aca | 2011-07-22 18:19:36 -0700 | [diff] [blame] | 12763 | if (mParent != null) { |
| 12764 | if (mLayoutParams != null) { |
| 12765 | mLayoutParams.resolveWithDirection(getResolvedLayoutDirection()); |
| 12766 | } |
| 12767 | if (!mParent.isLayoutRequested()) { |
| 12768 | mParent.requestLayout(); |
| 12769 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12770 | } |
| 12771 | } |
| 12772 | |
| 12773 | /** |
| 12774 | * Forces this view to be laid out during the next layout pass. |
| 12775 | * This method does not call requestLayout() or forceLayout() |
| 12776 | * on the parent. |
| 12777 | */ |
| 12778 | public void forceLayout() { |
| 12779 | mPrivateFlags |= FORCE_LAYOUT; |
Chet Haase | 5af048c | 2011-01-24 17:00:32 -0800 | [diff] [blame] | 12780 | mPrivateFlags |= INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12781 | } |
| 12782 | |
| 12783 | /** |
| 12784 | * <p> |
| 12785 | * This is called to find out how big a view should be. The parent |
| 12786 | * supplies constraint information in the width and height parameters. |
| 12787 | * </p> |
| 12788 | * |
| 12789 | * <p> |
| 12790 | * The actual mesurement work of a view is performed in |
| 12791 | * {@link #onMeasure(int, int)}, called by this method. Therefore, only |
| 12792 | * {@link #onMeasure(int, int)} can and must be overriden by subclasses. |
| 12793 | * </p> |
| 12794 | * |
| 12795 | * |
| 12796 | * @param widthMeasureSpec Horizontal space requirements as imposed by the |
| 12797 | * parent |
| 12798 | * @param heightMeasureSpec Vertical space requirements as imposed by the |
| 12799 | * parent |
| 12800 | * |
| 12801 | * @see #onMeasure(int, int) |
| 12802 | */ |
| 12803 | public final void measure(int widthMeasureSpec, int heightMeasureSpec) { |
| 12804 | if ((mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT || |
| 12805 | widthMeasureSpec != mOldWidthMeasureSpec || |
| 12806 | heightMeasureSpec != mOldHeightMeasureSpec) { |
| 12807 | |
| 12808 | // first clears the measured dimension flag |
| 12809 | mPrivateFlags &= ~MEASURED_DIMENSION_SET; |
| 12810 | |
| 12811 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12812 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_MEASURE); |
| 12813 | } |
| 12814 | |
| 12815 | // measure ourselves, this should set the measured dimension flag back |
| 12816 | onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 12817 | |
| 12818 | // flag not set, setMeasuredDimension() was not invoked, we raise |
| 12819 | // an exception to warn the developer |
| 12820 | if ((mPrivateFlags & MEASURED_DIMENSION_SET) != MEASURED_DIMENSION_SET) { |
| 12821 | throw new IllegalStateException("onMeasure() did not set the" |
| 12822 | + " measured dimension by calling" |
| 12823 | + " setMeasuredDimension()"); |
| 12824 | } |
| 12825 | |
| 12826 | mPrivateFlags |= LAYOUT_REQUIRED; |
| 12827 | } |
| 12828 | |
| 12829 | mOldWidthMeasureSpec = widthMeasureSpec; |
| 12830 | mOldHeightMeasureSpec = heightMeasureSpec; |
| 12831 | } |
| 12832 | |
| 12833 | /** |
| 12834 | * <p> |
| 12835 | * Measure the view and its content to determine the measured width and the |
| 12836 | * measured height. This method is invoked by {@link #measure(int, int)} and |
| 12837 | * should be overriden by subclasses to provide accurate and efficient |
| 12838 | * measurement of their contents. |
| 12839 | * </p> |
| 12840 | * |
| 12841 | * <p> |
| 12842 | * <strong>CONTRACT:</strong> When overriding this method, you |
| 12843 | * <em>must</em> call {@link #setMeasuredDimension(int, int)} to store the |
| 12844 | * measured width and height of this view. Failure to do so will trigger an |
| 12845 | * <code>IllegalStateException</code>, thrown by |
| 12846 | * {@link #measure(int, int)}. Calling the superclass' |
| 12847 | * {@link #onMeasure(int, int)} is a valid use. |
| 12848 | * </p> |
| 12849 | * |
| 12850 | * <p> |
| 12851 | * The base class implementation of measure defaults to the background size, |
| 12852 | * unless a larger size is allowed by the MeasureSpec. Subclasses should |
| 12853 | * override {@link #onMeasure(int, int)} to provide better measurements of |
| 12854 | * their content. |
| 12855 | * </p> |
| 12856 | * |
| 12857 | * <p> |
| 12858 | * If this method is overridden, it is the subclass's responsibility to make |
| 12859 | * sure the measured height and width are at least the view's minimum height |
| 12860 | * and width ({@link #getSuggestedMinimumHeight()} and |
| 12861 | * {@link #getSuggestedMinimumWidth()}). |
| 12862 | * </p> |
| 12863 | * |
| 12864 | * @param widthMeasureSpec horizontal space requirements as imposed by the parent. |
| 12865 | * The requirements are encoded with |
| 12866 | * {@link android.view.View.MeasureSpec}. |
| 12867 | * @param heightMeasureSpec vertical space requirements as imposed by the parent. |
| 12868 | * The requirements are encoded with |
| 12869 | * {@link android.view.View.MeasureSpec}. |
| 12870 | * |
| 12871 | * @see #getMeasuredWidth() |
| 12872 | * @see #getMeasuredHeight() |
| 12873 | * @see #setMeasuredDimension(int, int) |
| 12874 | * @see #getSuggestedMinimumHeight() |
| 12875 | * @see #getSuggestedMinimumWidth() |
| 12876 | * @see android.view.View.MeasureSpec#getMode(int) |
| 12877 | * @see android.view.View.MeasureSpec#getSize(int) |
| 12878 | */ |
| 12879 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 12880 | setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), |
| 12881 | getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec)); |
| 12882 | } |
| 12883 | |
| 12884 | /** |
| 12885 | * <p>This mehod must be called by {@link #onMeasure(int, int)} to store the |
| 12886 | * measured width and measured height. Failing to do so will trigger an |
| 12887 | * exception at measurement time.</p> |
| 12888 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12889 | * @param measuredWidth The measured width of this view. May be a complex |
| 12890 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 12891 | * {@link #MEASURED_STATE_TOO_SMALL}. |
| 12892 | * @param measuredHeight The measured height of this view. May be a complex |
| 12893 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 12894 | * {@link #MEASURED_STATE_TOO_SMALL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12895 | */ |
| 12896 | protected final void setMeasuredDimension(int measuredWidth, int measuredHeight) { |
| 12897 | mMeasuredWidth = measuredWidth; |
| 12898 | mMeasuredHeight = measuredHeight; |
| 12899 | |
| 12900 | mPrivateFlags |= MEASURED_DIMENSION_SET; |
| 12901 | } |
| 12902 | |
| 12903 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12904 | * Merge two states as returned by {@link #getMeasuredState()}. |
| 12905 | * @param curState The current state as returned from a view or the result |
| 12906 | * of combining multiple views. |
| 12907 | * @param newState The new view state to combine. |
| 12908 | * @return Returns a new integer reflecting the combination of the two |
| 12909 | * states. |
| 12910 | */ |
| 12911 | public static int combineMeasuredStates(int curState, int newState) { |
| 12912 | return curState | newState; |
| 12913 | } |
| 12914 | |
| 12915 | /** |
| 12916 | * Version of {@link #resolveSizeAndState(int, int, int)} |
| 12917 | * returning only the {@link #MEASURED_SIZE_MASK} bits of the result. |
| 12918 | */ |
| 12919 | public static int resolveSize(int size, int measureSpec) { |
| 12920 | return resolveSizeAndState(size, measureSpec, 0) & MEASURED_SIZE_MASK; |
| 12921 | } |
| 12922 | |
| 12923 | /** |
| 12924 | * Utility to reconcile a desired size and state, with constraints imposed |
| 12925 | * by a MeasureSpec. Will take the desired size, unless a different size |
| 12926 | * is imposed by the constraints. The returned value is a compound integer, |
| 12927 | * with the resolved size in the {@link #MEASURED_SIZE_MASK} bits and |
| 12928 | * optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the resulting |
| 12929 | * 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] | 12930 | * |
| 12931 | * @param size How big the view wants to be |
| 12932 | * @param measureSpec Constraints imposed by the parent |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12933 | * @return Size information bit mask as defined by |
| 12934 | * {@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] | 12935 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12936 | 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] | 12937 | int result = size; |
| 12938 | int specMode = MeasureSpec.getMode(measureSpec); |
| 12939 | int specSize = MeasureSpec.getSize(measureSpec); |
| 12940 | switch (specMode) { |
| 12941 | case MeasureSpec.UNSPECIFIED: |
| 12942 | result = size; |
| 12943 | break; |
| 12944 | case MeasureSpec.AT_MOST: |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12945 | if (specSize < size) { |
| 12946 | result = specSize | MEASURED_STATE_TOO_SMALL; |
| 12947 | } else { |
| 12948 | result = size; |
| 12949 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12950 | break; |
| 12951 | case MeasureSpec.EXACTLY: |
| 12952 | result = specSize; |
| 12953 | break; |
| 12954 | } |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12955 | return result | (childMeasuredState&MEASURED_STATE_MASK); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12956 | } |
| 12957 | |
| 12958 | /** |
| 12959 | * Utility to return a default size. Uses the supplied size if the |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 12960 | * MeasureSpec imposed no constraints. Will get larger if allowed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12961 | * by the MeasureSpec. |
| 12962 | * |
| 12963 | * @param size Default size for this view |
| 12964 | * @param measureSpec Constraints imposed by the parent |
| 12965 | * @return The size this view should be. |
| 12966 | */ |
| 12967 | public static int getDefaultSize(int size, int measureSpec) { |
| 12968 | int result = size; |
| 12969 | int specMode = MeasureSpec.getMode(measureSpec); |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 12970 | int specSize = MeasureSpec.getSize(measureSpec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12971 | |
| 12972 | switch (specMode) { |
| 12973 | case MeasureSpec.UNSPECIFIED: |
| 12974 | result = size; |
| 12975 | break; |
| 12976 | case MeasureSpec.AT_MOST: |
| 12977 | case MeasureSpec.EXACTLY: |
| 12978 | result = specSize; |
| 12979 | break; |
| 12980 | } |
| 12981 | return result; |
| 12982 | } |
| 12983 | |
| 12984 | /** |
| 12985 | * Returns the suggested minimum height that the view should use. This |
| 12986 | * returns the maximum of the view's minimum height |
| 12987 | * and the background's minimum height |
| 12988 | * ({@link android.graphics.drawable.Drawable#getMinimumHeight()}). |
| 12989 | * <p> |
| 12990 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 12991 | * ensure the returned height is within the requirements of the parent. |
| 12992 | * |
| 12993 | * @return The suggested minimum height of the view. |
| 12994 | */ |
| 12995 | protected int getSuggestedMinimumHeight() { |
| 12996 | int suggestedMinHeight = mMinHeight; |
| 12997 | |
| 12998 | if (mBGDrawable != null) { |
| 12999 | final int bgMinHeight = mBGDrawable.getMinimumHeight(); |
| 13000 | if (suggestedMinHeight < bgMinHeight) { |
| 13001 | suggestedMinHeight = bgMinHeight; |
| 13002 | } |
| 13003 | } |
| 13004 | |
| 13005 | return suggestedMinHeight; |
| 13006 | } |
| 13007 | |
| 13008 | /** |
| 13009 | * Returns the suggested minimum width that the view should use. This |
| 13010 | * returns the maximum of the view's minimum width) |
| 13011 | * and the background's minimum width |
| 13012 | * ({@link android.graphics.drawable.Drawable#getMinimumWidth()}). |
| 13013 | * <p> |
| 13014 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 13015 | * ensure the returned width is within the requirements of the parent. |
| 13016 | * |
| 13017 | * @return The suggested minimum width of the view. |
| 13018 | */ |
| 13019 | protected int getSuggestedMinimumWidth() { |
| 13020 | int suggestedMinWidth = mMinWidth; |
| 13021 | |
| 13022 | if (mBGDrawable != null) { |
| 13023 | final int bgMinWidth = mBGDrawable.getMinimumWidth(); |
| 13024 | if (suggestedMinWidth < bgMinWidth) { |
| 13025 | suggestedMinWidth = bgMinWidth; |
| 13026 | } |
| 13027 | } |
| 13028 | |
| 13029 | return suggestedMinWidth; |
| 13030 | } |
| 13031 | |
| 13032 | /** |
| 13033 | * Sets the minimum height of the view. It is not guaranteed the view will |
| 13034 | * be able to achieve this minimum height (for example, if its parent layout |
| 13035 | * constrains it with less available height). |
| 13036 | * |
| 13037 | * @param minHeight The minimum height the view will try to be. |
| 13038 | */ |
| 13039 | public void setMinimumHeight(int minHeight) { |
| 13040 | mMinHeight = minHeight; |
| 13041 | } |
| 13042 | |
| 13043 | /** |
| 13044 | * Sets the minimum width of the view. It is not guaranteed the view will |
| 13045 | * be able to achieve this minimum width (for example, if its parent layout |
| 13046 | * constrains it with less available width). |
| 13047 | * |
| 13048 | * @param minWidth The minimum width the view will try to be. |
| 13049 | */ |
| 13050 | public void setMinimumWidth(int minWidth) { |
| 13051 | mMinWidth = minWidth; |
| 13052 | } |
| 13053 | |
| 13054 | /** |
| 13055 | * Get the animation currently associated with this view. |
| 13056 | * |
| 13057 | * @return The animation that is currently playing or |
| 13058 | * scheduled to play for this view. |
| 13059 | */ |
| 13060 | public Animation getAnimation() { |
| 13061 | return mCurrentAnimation; |
| 13062 | } |
| 13063 | |
| 13064 | /** |
| 13065 | * Start the specified animation now. |
| 13066 | * |
| 13067 | * @param animation the animation to start now |
| 13068 | */ |
| 13069 | public void startAnimation(Animation animation) { |
| 13070 | animation.setStartTime(Animation.START_ON_FIRST_FRAME); |
| 13071 | setAnimation(animation); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 13072 | invalidateParentCaches(); |
| 13073 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13074 | } |
| 13075 | |
| 13076 | /** |
| 13077 | * Cancels any animations for this view. |
| 13078 | */ |
| 13079 | public void clearAnimation() { |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 13080 | if (mCurrentAnimation != null) { |
Romain Guy | b4a107d | 2010-02-09 18:50:08 -0800 | [diff] [blame] | 13081 | mCurrentAnimation.detach(); |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 13082 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13083 | mCurrentAnimation = null; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 13084 | invalidateParentIfNeeded(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13085 | } |
| 13086 | |
| 13087 | /** |
| 13088 | * Sets the next animation to play for this view. |
| 13089 | * If you want the animation to play immediately, use |
| 13090 | * startAnimation. This method provides allows fine-grained |
| 13091 | * control over the start time and invalidation, but you |
| 13092 | * must make sure that 1) the animation has a start time set, and |
| 13093 | * 2) the view will be invalidated when the animation is supposed to |
| 13094 | * start. |
| 13095 | * |
| 13096 | * @param animation The next animation, or null. |
| 13097 | */ |
| 13098 | public void setAnimation(Animation animation) { |
| 13099 | mCurrentAnimation = animation; |
| 13100 | if (animation != null) { |
| 13101 | animation.reset(); |
| 13102 | } |
| 13103 | } |
| 13104 | |
| 13105 | /** |
| 13106 | * Invoked by a parent ViewGroup to notify the start of the animation |
| 13107 | * currently associated with this view. If you override this method, |
| 13108 | * always call super.onAnimationStart(); |
| 13109 | * |
| 13110 | * @see #setAnimation(android.view.animation.Animation) |
| 13111 | * @see #getAnimation() |
| 13112 | */ |
| 13113 | protected void onAnimationStart() { |
| 13114 | mPrivateFlags |= ANIMATION_STARTED; |
| 13115 | } |
| 13116 | |
| 13117 | /** |
| 13118 | * Invoked by a parent ViewGroup to notify the end of the animation |
| 13119 | * currently associated with this view. If you override this method, |
| 13120 | * always call super.onAnimationEnd(); |
| 13121 | * |
| 13122 | * @see #setAnimation(android.view.animation.Animation) |
| 13123 | * @see #getAnimation() |
| 13124 | */ |
| 13125 | protected void onAnimationEnd() { |
| 13126 | mPrivateFlags &= ~ANIMATION_STARTED; |
| 13127 | } |
| 13128 | |
| 13129 | /** |
| 13130 | * Invoked if there is a Transform that involves alpha. Subclass that can |
| 13131 | * draw themselves with the specified alpha should return true, and then |
| 13132 | * respect that alpha when their onDraw() is called. If this returns false |
| 13133 | * then the view may be redirected to draw into an offscreen buffer to |
| 13134 | * fulfill the request, which will look fine, but may be slower than if the |
| 13135 | * subclass handles it internally. The default implementation returns false. |
| 13136 | * |
| 13137 | * @param alpha The alpha (0..255) to apply to the view's drawing |
| 13138 | * @return true if the view can draw with the specified alpha. |
| 13139 | */ |
| 13140 | protected boolean onSetAlpha(int alpha) { |
| 13141 | return false; |
| 13142 | } |
| 13143 | |
| 13144 | /** |
| 13145 | * This is used by the RootView to perform an optimization when |
| 13146 | * the view hierarchy contains one or several SurfaceView. |
| 13147 | * SurfaceView is always considered transparent, but its children are not, |
| 13148 | * therefore all View objects remove themselves from the global transparent |
| 13149 | * region (passed as a parameter to this function). |
| 13150 | * |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 13151 | * @param region The transparent region for this ViewAncestor (window). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13152 | * |
| 13153 | * @return Returns true if the effective visibility of the view at this |
| 13154 | * point is opaque, regardless of the transparent region; returns false |
| 13155 | * if it is possible for underlying windows to be seen behind the view. |
| 13156 | * |
| 13157 | * {@hide} |
| 13158 | */ |
| 13159 | public boolean gatherTransparentRegion(Region region) { |
| 13160 | final AttachInfo attachInfo = mAttachInfo; |
| 13161 | if (region != null && attachInfo != null) { |
| 13162 | final int pflags = mPrivateFlags; |
| 13163 | if ((pflags & SKIP_DRAW) == 0) { |
| 13164 | // The SKIP_DRAW flag IS NOT set, so this view draws. We need to |
| 13165 | // remove it from the transparent region. |
| 13166 | final int[] location = attachInfo.mTransparentLocation; |
| 13167 | getLocationInWindow(location); |
| 13168 | region.op(location[0], location[1], location[0] + mRight - mLeft, |
| 13169 | location[1] + mBottom - mTop, Region.Op.DIFFERENCE); |
| 13170 | } else if ((pflags & ONLY_DRAWS_BACKGROUND) != 0 && mBGDrawable != null) { |
| 13171 | // The ONLY_DRAWS_BACKGROUND flag IS set and the background drawable |
| 13172 | // exists, so we remove the background drawable's non-transparent |
| 13173 | // parts from this transparent region. |
| 13174 | applyDrawableToTransparentRegion(mBGDrawable, region); |
| 13175 | } |
| 13176 | } |
| 13177 | return true; |
| 13178 | } |
| 13179 | |
| 13180 | /** |
| 13181 | * Play a sound effect for this view. |
| 13182 | * |
| 13183 | * <p>The framework will play sound effects for some built in actions, such as |
| 13184 | * clicking, but you may wish to play these effects in your widget, |
| 13185 | * for instance, for internal navigation. |
| 13186 | * |
| 13187 | * <p>The sound effect will only be played if sound effects are enabled by the user, and |
| 13188 | * {@link #isSoundEffectsEnabled()} is true. |
| 13189 | * |
| 13190 | * @param soundConstant One of the constants defined in {@link SoundEffectConstants} |
| 13191 | */ |
| 13192 | public void playSoundEffect(int soundConstant) { |
| 13193 | if (mAttachInfo == null || mAttachInfo.mRootCallbacks == null || !isSoundEffectsEnabled()) { |
| 13194 | return; |
| 13195 | } |
| 13196 | mAttachInfo.mRootCallbacks.playSoundEffect(soundConstant); |
| 13197 | } |
| 13198 | |
| 13199 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 13200 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13201 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 13202 | * <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] | 13203 | * |
| 13204 | * <p>The framework will provide haptic feedback for some built in actions, |
| 13205 | * such as long presses, but you may wish to provide feedback for your |
| 13206 | * own widget. |
| 13207 | * |
| 13208 | * <p>The feedback will only be performed if |
| 13209 | * {@link #isHapticFeedbackEnabled()} is true. |
| 13210 | * |
| 13211 | * @param feedbackConstant One of the constants defined in |
| 13212 | * {@link HapticFeedbackConstants} |
| 13213 | */ |
| 13214 | public boolean performHapticFeedback(int feedbackConstant) { |
| 13215 | return performHapticFeedback(feedbackConstant, 0); |
| 13216 | } |
| 13217 | |
| 13218 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 13219 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13220 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 13221 | * <p>Like {@link #performHapticFeedback(int)}, with additional options. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13222 | * |
| 13223 | * @param feedbackConstant One of the constants defined in |
| 13224 | * {@link HapticFeedbackConstants} |
| 13225 | * @param flags Additional flags as per {@link HapticFeedbackConstants}. |
| 13226 | */ |
| 13227 | public boolean performHapticFeedback(int feedbackConstant, int flags) { |
| 13228 | if (mAttachInfo == null) { |
| 13229 | return false; |
| 13230 | } |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 13231 | //noinspection SimplifiableIfStatement |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 13232 | if ((flags & HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING) == 0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13233 | && !isHapticFeedbackEnabled()) { |
| 13234 | return false; |
| 13235 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 13236 | return mAttachInfo.mRootCallbacks.performHapticFeedback(feedbackConstant, |
| 13237 | (flags & HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13238 | } |
| 13239 | |
| 13240 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13241 | * Request that the visibility of the status bar be changed. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 13242 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or |
| 13243 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13244 | */ |
| 13245 | public void setSystemUiVisibility(int visibility) { |
Daniel Sandler | 7052406 | 2011-09-21 00:30:47 -0400 | [diff] [blame] | 13246 | if (visibility != mSystemUiVisibility) { |
| 13247 | mSystemUiVisibility = visibility; |
| 13248 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 13249 | mParent.recomputeViewAttributes(this); |
| 13250 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13251 | } |
| 13252 | } |
| 13253 | |
| 13254 | /** |
| 13255 | * Returns the status bar visibility that this view has requested. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 13256 | * @return Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or |
| 13257 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13258 | */ |
Joe Onorato | e595cad | 2011-01-24 09:22:12 -0800 | [diff] [blame] | 13259 | public int getSystemUiVisibility() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13260 | return mSystemUiVisibility; |
| 13261 | } |
| 13262 | |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 13263 | /** |
| 13264 | * Set a listener to receive callbacks when the visibility of the system bar changes. |
| 13265 | * @param l The {@link OnSystemUiVisibilityChangeListener} to receive callbacks. |
| 13266 | */ |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13267 | public void setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 13268 | getListenerInfo().mOnSystemUiVisibilityChangeListener = l; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13269 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 13270 | mParent.recomputeViewAttributes(this); |
| 13271 | } |
| 13272 | } |
| 13273 | |
| 13274 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 13275 | * Dispatch callbacks to {@link #setOnSystemUiVisibilityChangeListener} down |
| 13276 | * the view hierarchy. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13277 | */ |
| 13278 | public void dispatchSystemUiVisibilityChanged(int visibility) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 13279 | ListenerInfo li = mListenerInfo; |
| 13280 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
| 13281 | li.mOnSystemUiVisibilityChangeListener.onSystemUiVisibilityChange( |
Joe Onorato | 6ab77bd | 2011-01-31 11:21:10 -0800 | [diff] [blame] | 13282 | visibility & PUBLIC_STATUS_BAR_VISIBILITY_MASK); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13283 | } |
| 13284 | } |
| 13285 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 13286 | void updateLocalSystemUiVisibility(int localValue, int localChanges) { |
| 13287 | int val = (mSystemUiVisibility&~localChanges) | (localValue&localChanges); |
| 13288 | if (val != mSystemUiVisibility) { |
| 13289 | setSystemUiVisibility(val); |
| 13290 | } |
| 13291 | } |
| 13292 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13293 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13294 | * Creates an image that the system displays during the drag and drop |
| 13295 | * operation. This is called a "drag shadow". The default implementation |
| 13296 | * for a DragShadowBuilder based on a View returns an image that has exactly the same |
| 13297 | * appearance as the given View. The default also positions the center of the drag shadow |
| 13298 | * directly under the touch point. If no View is provided (the constructor with no parameters |
| 13299 | * is used), and {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} and |
| 13300 | * {@link #onDrawShadow(Canvas) onDrawShadow()} are not overriden, then the |
| 13301 | * default is an invisible drag shadow. |
| 13302 | * <p> |
| 13303 | * You are not required to use the View you provide to the constructor as the basis of the |
| 13304 | * drag shadow. The {@link #onDrawShadow(Canvas) onDrawShadow()} method allows you to draw |
| 13305 | * anything you want as the drag shadow. |
| 13306 | * </p> |
| 13307 | * <p> |
| 13308 | * You pass a DragShadowBuilder object to the system when you start the drag. The system |
| 13309 | * calls {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} to get the |
| 13310 | * size and position of the drag shadow. It uses this data to construct a |
| 13311 | * {@link android.graphics.Canvas} object, then it calls {@link #onDrawShadow(Canvas) onDrawShadow()} |
| 13312 | * so that your application can draw the shadow image in the Canvas. |
| 13313 | * </p> |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 13314 | * |
| 13315 | * <div class="special reference"> |
| 13316 | * <h3>Developer Guides</h3> |
| 13317 | * <p>For a guide to implementing drag and drop features, read the |
| 13318 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 13319 | * </div> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13320 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13321 | public static class DragShadowBuilder { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 13322 | private final WeakReference<View> mView; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13323 | |
| 13324 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13325 | * Constructs a shadow image builder based on a View. By default, the resulting drag |
| 13326 | * shadow will have the same appearance and dimensions as the View, with the touch point |
| 13327 | * over the center of the View. |
| 13328 | * @param view A View. Any View in scope can be used. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13329 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13330 | public DragShadowBuilder(View view) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 13331 | mView = new WeakReference<View>(view); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13332 | } |
| 13333 | |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 13334 | /** |
| 13335 | * Construct a shadow builder object with no associated View. This |
| 13336 | * constructor variant is only useful when the {@link #onProvideShadowMetrics(Point, Point)} |
| 13337 | * and {@link #onDrawShadow(Canvas)} methods are also overridden in order |
| 13338 | * to supply the drag shadow's dimensions and appearance without |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13339 | * reference to any View object. If they are not overridden, then the result is an |
| 13340 | * invisible drag shadow. |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 13341 | */ |
| 13342 | public DragShadowBuilder() { |
| 13343 | mView = new WeakReference<View>(null); |
| 13344 | } |
| 13345 | |
| 13346 | /** |
| 13347 | * Returns the View object that had been passed to the |
| 13348 | * {@link #View.DragShadowBuilder(View)} |
| 13349 | * constructor. If that View parameter was {@code null} or if the |
| 13350 | * {@link #View.DragShadowBuilder()} |
| 13351 | * constructor was used to instantiate the builder object, this method will return |
| 13352 | * null. |
| 13353 | * |
| 13354 | * @return The View object associate with this builder object. |
| 13355 | */ |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 13356 | @SuppressWarnings({"JavadocReference"}) |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 13357 | final public View getView() { |
| 13358 | return mView.get(); |
| 13359 | } |
| 13360 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13361 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13362 | * Provides the metrics for the shadow image. These include the dimensions of |
| 13363 | * the shadow image, and the point within that shadow that should |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13364 | * be centered under the touch location while dragging. |
| 13365 | * <p> |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13366 | * The default implementation sets the dimensions of the shadow to be the |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13367 | * same as the dimensions of the View itself and centers the shadow under |
| 13368 | * the touch point. |
| 13369 | * </p> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13370 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13371 | * @param shadowSize A {@link android.graphics.Point} containing the width and height |
| 13372 | * of the shadow image. Your application must set {@link android.graphics.Point#x} to the |
| 13373 | * desired width and must set {@link android.graphics.Point#y} to the desired height of the |
| 13374 | * image. |
| 13375 | * |
| 13376 | * @param shadowTouchPoint A {@link android.graphics.Point} for the position within the |
| 13377 | * shadow image that should be underneath the touch point during the drag and drop |
| 13378 | * operation. Your application must set {@link android.graphics.Point#x} to the |
| 13379 | * 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] | 13380 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13381 | public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 13382 | final View view = mView.get(); |
| 13383 | if (view != null) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13384 | shadowSize.set(view.getWidth(), view.getHeight()); |
| 13385 | shadowTouchPoint.set(shadowSize.x / 2, shadowSize.y / 2); |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 13386 | } else { |
| 13387 | Log.e(View.VIEW_LOG_TAG, "Asked for drag thumb metrics but no view"); |
| 13388 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13389 | } |
| 13390 | |
| 13391 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13392 | * Draws the shadow image. The system creates the {@link android.graphics.Canvas} object |
| 13393 | * based on the dimensions it received from the |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13394 | * {@link #onProvideShadowMetrics(Point, Point)} callback. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13395 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13396 | * @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] | 13397 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13398 | public void onDrawShadow(Canvas canvas) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 13399 | final View view = mView.get(); |
| 13400 | if (view != null) { |
| 13401 | view.draw(canvas); |
| 13402 | } else { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13403 | 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] | 13404 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13405 | } |
| 13406 | } |
| 13407 | |
| 13408 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13409 | * Starts a drag and drop operation. When your application calls this method, it passes a |
| 13410 | * {@link android.view.View.DragShadowBuilder} object to the system. The |
| 13411 | * system calls this object's {@link DragShadowBuilder#onProvideShadowMetrics(Point, Point)} |
| 13412 | * to get metrics for the drag shadow, and then calls the object's |
| 13413 | * {@link DragShadowBuilder#onDrawShadow(Canvas)} to draw the drag shadow itself. |
| 13414 | * <p> |
| 13415 | * Once the system has the drag shadow, it begins the drag and drop operation by sending |
| 13416 | * drag events to all the View objects in your application that are currently visible. It does |
| 13417 | * this either by calling the View object's drag listener (an implementation of |
| 13418 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent) onDrag()} or by calling the |
| 13419 | * View object's {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} method. |
| 13420 | * Both are passed a {@link android.view.DragEvent} object that has a |
| 13421 | * {@link android.view.DragEvent#getAction()} value of |
| 13422 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED}. |
| 13423 | * </p> |
| 13424 | * <p> |
| 13425 | * Your application can invoke startDrag() on any attached View object. The View object does not |
| 13426 | * need to be the one used in {@link android.view.View.DragShadowBuilder}, nor does it need to |
| 13427 | * be related to the View the user selected for dragging. |
| 13428 | * </p> |
| 13429 | * @param data A {@link android.content.ClipData} object pointing to the data to be |
| 13430 | * transferred by the drag and drop operation. |
| 13431 | * @param shadowBuilder A {@link android.view.View.DragShadowBuilder} object for building the |
| 13432 | * drag shadow. |
| 13433 | * @param myLocalState An {@link java.lang.Object} containing local data about the drag and |
| 13434 | * drop operation. This Object is put into every DragEvent object sent by the system during the |
| 13435 | * current drag. |
| 13436 | * <p> |
| 13437 | * myLocalState is a lightweight mechanism for the sending information from the dragged View |
| 13438 | * to the target Views. For example, it can contain flags that differentiate between a |
| 13439 | * a copy operation and a move operation. |
| 13440 | * </p> |
| 13441 | * @param flags Flags that control the drag and drop operation. No flags are currently defined, |
| 13442 | * so the parameter should be set to 0. |
| 13443 | * @return {@code true} if the method completes successfully, or |
| 13444 | * {@code false} if it fails anywhere. Returning {@code false} means the system was unable to |
| 13445 | * do a drag, and so no drag operation is in progress. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13446 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13447 | public final boolean startDrag(ClipData data, DragShadowBuilder shadowBuilder, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 13448 | Object myLocalState, int flags) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13449 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 13450 | Log.d(VIEW_LOG_TAG, "startDrag: data=" + data + " flags=" + flags); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13451 | } |
| 13452 | boolean okay = false; |
| 13453 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13454 | Point shadowSize = new Point(); |
| 13455 | Point shadowTouchPoint = new Point(); |
| 13456 | shadowBuilder.onProvideShadowMetrics(shadowSize, shadowTouchPoint); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13457 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13458 | if ((shadowSize.x < 0) || (shadowSize.y < 0) || |
| 13459 | (shadowTouchPoint.x < 0) || (shadowTouchPoint.y < 0)) { |
| 13460 | throw new IllegalStateException("Drag shadow dimensions must not be negative"); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13461 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13462 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 13463 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13464 | Log.d(VIEW_LOG_TAG, "drag shadow: width=" + shadowSize.x + " height=" + shadowSize.y |
| 13465 | + " shadowX=" + shadowTouchPoint.x + " shadowY=" + shadowTouchPoint.y); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 13466 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13467 | Surface surface = new Surface(); |
| 13468 | try { |
| 13469 | IBinder token = mAttachInfo.mSession.prepareDrag(mAttachInfo.mWindow, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 13470 | flags, shadowSize.x, shadowSize.y, surface); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13471 | 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] | 13472 | + " surface=" + surface); |
| 13473 | if (token != null) { |
| 13474 | Canvas canvas = surface.lockCanvas(null); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 13475 | try { |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 13476 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13477 | shadowBuilder.onDrawShadow(canvas); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 13478 | } finally { |
| 13479 | surface.unlockCanvasAndPost(canvas); |
| 13480 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13481 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 13482 | final ViewRootImpl root = getViewRootImpl(); |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 13483 | |
| 13484 | // Cache the local state object for delivery with DragEvents |
| 13485 | root.setLocalDragState(myLocalState); |
| 13486 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13487 | // repurpose 'shadowSize' for the last touch point |
| 13488 | root.getLastTouchPoint(shadowSize); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13489 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13490 | okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, token, |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13491 | shadowSize.x, shadowSize.y, |
| 13492 | shadowTouchPoint.x, shadowTouchPoint.y, data); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13493 | if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "performDrag returned " + okay); |
Christopher Tate | 8f73b5d | 2011-09-12 15:22:12 -0700 | [diff] [blame] | 13494 | |
| 13495 | // Off and running! Release our local surface instance; the drag |
| 13496 | // shadow surface is now managed by the system process. |
| 13497 | surface.release(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13498 | } |
| 13499 | } catch (Exception e) { |
| 13500 | Log.e(VIEW_LOG_TAG, "Unable to initiate drag", e); |
| 13501 | surface.destroy(); |
| 13502 | } |
| 13503 | |
| 13504 | return okay; |
| 13505 | } |
| 13506 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13507 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13508 | * Handles drag events sent by the system following a call to |
| 13509 | * {@link android.view.View#startDrag(ClipData,DragShadowBuilder,Object,int) startDrag()}. |
| 13510 | *<p> |
| 13511 | * When the system calls this method, it passes a |
| 13512 | * {@link android.view.DragEvent} object. A call to |
| 13513 | * {@link android.view.DragEvent#getAction()} returns one of the action type constants defined |
| 13514 | * in DragEvent. The method uses these to determine what is happening in the drag and drop |
| 13515 | * operation. |
| 13516 | * @param event The {@link android.view.DragEvent} sent by the system. |
| 13517 | * The {@link android.view.DragEvent#getAction()} method returns an action type constant defined |
| 13518 | * in DragEvent, indicating the type of drag event represented by this object. |
| 13519 | * @return {@code true} if the method was successful, otherwise {@code false}. |
| 13520 | * <p> |
| 13521 | * The method should return {@code true} in response to an action type of |
| 13522 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED} to receive drag events for the current |
| 13523 | * operation. |
| 13524 | * </p> |
| 13525 | * <p> |
| 13526 | * The method should also return {@code true} in response to an action type of |
| 13527 | * {@link android.view.DragEvent#ACTION_DROP} if it consumed the drop, or |
| 13528 | * {@code false} if it didn't. |
| 13529 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13530 | */ |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 13531 | public boolean onDragEvent(DragEvent event) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13532 | return false; |
| 13533 | } |
| 13534 | |
| 13535 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13536 | * Detects if this View is enabled and has a drag event listener. |
| 13537 | * If both are true, then it calls the drag event listener with the |
| 13538 | * {@link android.view.DragEvent} it received. If the drag event listener returns |
| 13539 | * {@code true}, then dispatchDragEvent() returns {@code true}. |
| 13540 | * <p> |
| 13541 | * For all other cases, the method calls the |
| 13542 | * {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} drag event handler |
| 13543 | * method and returns its result. |
| 13544 | * </p> |
| 13545 | * <p> |
| 13546 | * This ensures that a drag event is always consumed, even if the View does not have a drag |
| 13547 | * event listener. However, if the View has a listener and the listener returns true, then |
| 13548 | * onDragEvent() is not called. |
| 13549 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13550 | */ |
| 13551 | public boolean dispatchDragEvent(DragEvent event) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 13552 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 13553 | ListenerInfo li = mListenerInfo; |
| 13554 | if (li != null && li.mOnDragListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 13555 | && li.mOnDragListener.onDrag(this, event)) { |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 13556 | return true; |
| 13557 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13558 | return onDragEvent(event); |
| 13559 | } |
| 13560 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 13561 | boolean canAcceptDrag() { |
| 13562 | return (mPrivateFlags2 & DRAG_CAN_ACCEPT) != 0; |
| 13563 | } |
| 13564 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13565 | /** |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 13566 | * This needs to be a better API (NOT ON VIEW) before it is exposed. If |
| 13567 | * it is ever exposed at all. |
Dianne Hackborn | 29e4a3c | 2009-09-30 22:35:40 -0700 | [diff] [blame] | 13568 | * @hide |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 13569 | */ |
| 13570 | public void onCloseSystemDialogs(String reason) { |
| 13571 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13572 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 13573 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13574 | * 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] | 13575 | * update a Region being computed for |
| 13576 | * {@link #gatherTransparentRegion(android.graphics.Region)} so |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13577 | * that any non-transparent parts of the Drawable are removed from the |
| 13578 | * given transparent region. |
| 13579 | * |
| 13580 | * @param dr The Drawable whose transparency is to be applied to the region. |
| 13581 | * @param region A Region holding the current transparency information, |
| 13582 | * where any parts of the region that are set are considered to be |
| 13583 | * transparent. On return, this region will be modified to have the |
| 13584 | * transparency information reduced by the corresponding parts of the |
| 13585 | * Drawable that are not transparent. |
| 13586 | * {@hide} |
| 13587 | */ |
| 13588 | public void applyDrawableToTransparentRegion(Drawable dr, Region region) { |
| 13589 | if (DBG) { |
| 13590 | Log.i("View", "Getting transparent region for: " + this); |
| 13591 | } |
| 13592 | final Region r = dr.getTransparentRegion(); |
| 13593 | final Rect db = dr.getBounds(); |
| 13594 | final AttachInfo attachInfo = mAttachInfo; |
| 13595 | if (r != null && attachInfo != null) { |
| 13596 | final int w = getRight()-getLeft(); |
| 13597 | final int h = getBottom()-getTop(); |
| 13598 | if (db.left > 0) { |
| 13599 | //Log.i("VIEW", "Drawable left " + db.left + " > view 0"); |
| 13600 | r.op(0, 0, db.left, h, Region.Op.UNION); |
| 13601 | } |
| 13602 | if (db.right < w) { |
| 13603 | //Log.i("VIEW", "Drawable right " + db.right + " < view " + w); |
| 13604 | r.op(db.right, 0, w, h, Region.Op.UNION); |
| 13605 | } |
| 13606 | if (db.top > 0) { |
| 13607 | //Log.i("VIEW", "Drawable top " + db.top + " > view 0"); |
| 13608 | r.op(0, 0, w, db.top, Region.Op.UNION); |
| 13609 | } |
| 13610 | if (db.bottom < h) { |
| 13611 | //Log.i("VIEW", "Drawable bottom " + db.bottom + " < view " + h); |
| 13612 | r.op(0, db.bottom, w, h, Region.Op.UNION); |
| 13613 | } |
| 13614 | final int[] location = attachInfo.mTransparentLocation; |
| 13615 | getLocationInWindow(location); |
| 13616 | r.translate(location[0], location[1]); |
| 13617 | region.op(r, Region.Op.INTERSECT); |
| 13618 | } else { |
| 13619 | region.op(db, Region.Op.DIFFERENCE); |
| 13620 | } |
| 13621 | } |
| 13622 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 13623 | private void checkForLongClick(int delayOffset) { |
| 13624 | if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) { |
| 13625 | mHasPerformedLongPress = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13626 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 13627 | if (mPendingCheckForLongPress == null) { |
| 13628 | mPendingCheckForLongPress = new CheckForLongPress(); |
| 13629 | } |
| 13630 | mPendingCheckForLongPress.rememberWindowAttachCount(); |
| 13631 | postDelayed(mPendingCheckForLongPress, |
| 13632 | ViewConfiguration.getLongPressTimeout() - delayOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13633 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13634 | } |
| 13635 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13636 | /** |
| 13637 | * Inflate a view from an XML resource. This convenience method wraps the {@link |
| 13638 | * LayoutInflater} class, which provides a full range of options for view inflation. |
| 13639 | * |
| 13640 | * @param context The Context object for your activity or application. |
| 13641 | * @param resource The resource ID to inflate |
| 13642 | * @param root A view group that will be the parent. Used to properly inflate the |
| 13643 | * layout_* parameters. |
| 13644 | * @see LayoutInflater |
| 13645 | */ |
| 13646 | public static View inflate(Context context, int resource, ViewGroup root) { |
| 13647 | LayoutInflater factory = LayoutInflater.from(context); |
| 13648 | return factory.inflate(resource, root); |
| 13649 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 13650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13651 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 13652 | * Scroll the view with standard behavior for scrolling beyond the normal |
| 13653 | * content boundaries. Views that call this method should override |
| 13654 | * {@link #onOverScrolled(int, int, boolean, boolean)} to respond to the |
| 13655 | * results of an over-scroll operation. |
| 13656 | * |
| 13657 | * Views can use this method to handle any touch or fling-based scrolling. |
| 13658 | * |
| 13659 | * @param deltaX Change in X in pixels |
| 13660 | * @param deltaY Change in Y in pixels |
| 13661 | * @param scrollX Current X scroll value in pixels before applying deltaX |
| 13662 | * @param scrollY Current Y scroll value in pixels before applying deltaY |
| 13663 | * @param scrollRangeX Maximum content scroll range along the X axis |
| 13664 | * @param scrollRangeY Maximum content scroll range along the Y axis |
| 13665 | * @param maxOverScrollX Number of pixels to overscroll by in either direction |
| 13666 | * along the X axis. |
| 13667 | * @param maxOverScrollY Number of pixels to overscroll by in either direction |
| 13668 | * along the Y axis. |
| 13669 | * @param isTouchEvent true if this scroll operation is the result of a touch event. |
| 13670 | * @return true if scrolling was clamped to an over-scroll boundary along either |
| 13671 | * axis, false otherwise. |
| 13672 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13673 | @SuppressWarnings({"UnusedParameters"}) |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 13674 | protected boolean overScrollBy(int deltaX, int deltaY, |
| 13675 | int scrollX, int scrollY, |
| 13676 | int scrollRangeX, int scrollRangeY, |
| 13677 | int maxOverScrollX, int maxOverScrollY, |
| 13678 | boolean isTouchEvent) { |
| 13679 | final int overScrollMode = mOverScrollMode; |
| 13680 | final boolean canScrollHorizontal = |
| 13681 | computeHorizontalScrollRange() > computeHorizontalScrollExtent(); |
| 13682 | final boolean canScrollVertical = |
| 13683 | computeVerticalScrollRange() > computeVerticalScrollExtent(); |
| 13684 | final boolean overScrollHorizontal = overScrollMode == OVER_SCROLL_ALWAYS || |
| 13685 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollHorizontal); |
| 13686 | final boolean overScrollVertical = overScrollMode == OVER_SCROLL_ALWAYS || |
| 13687 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollVertical); |
| 13688 | |
| 13689 | int newScrollX = scrollX + deltaX; |
| 13690 | if (!overScrollHorizontal) { |
| 13691 | maxOverScrollX = 0; |
| 13692 | } |
| 13693 | |
| 13694 | int newScrollY = scrollY + deltaY; |
| 13695 | if (!overScrollVertical) { |
| 13696 | maxOverScrollY = 0; |
| 13697 | } |
| 13698 | |
| 13699 | // Clamp values if at the limits and record |
| 13700 | final int left = -maxOverScrollX; |
| 13701 | final int right = maxOverScrollX + scrollRangeX; |
| 13702 | final int top = -maxOverScrollY; |
| 13703 | final int bottom = maxOverScrollY + scrollRangeY; |
| 13704 | |
| 13705 | boolean clampedX = false; |
| 13706 | if (newScrollX > right) { |
| 13707 | newScrollX = right; |
| 13708 | clampedX = true; |
| 13709 | } else if (newScrollX < left) { |
| 13710 | newScrollX = left; |
| 13711 | clampedX = true; |
| 13712 | } |
| 13713 | |
| 13714 | boolean clampedY = false; |
| 13715 | if (newScrollY > bottom) { |
| 13716 | newScrollY = bottom; |
| 13717 | clampedY = true; |
| 13718 | } else if (newScrollY < top) { |
| 13719 | newScrollY = top; |
| 13720 | clampedY = true; |
| 13721 | } |
| 13722 | |
| 13723 | onOverScrolled(newScrollX, newScrollY, clampedX, clampedY); |
| 13724 | |
| 13725 | return clampedX || clampedY; |
| 13726 | } |
| 13727 | |
| 13728 | /** |
| 13729 | * Called by {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)} to |
| 13730 | * respond to the results of an over-scroll operation. |
| 13731 | * |
| 13732 | * @param scrollX New X scroll value in pixels |
| 13733 | * @param scrollY New Y scroll value in pixels |
| 13734 | * @param clampedX True if scrollX was clamped to an over-scroll boundary |
| 13735 | * @param clampedY True if scrollY was clamped to an over-scroll boundary |
| 13736 | */ |
| 13737 | protected void onOverScrolled(int scrollX, int scrollY, |
| 13738 | boolean clampedX, boolean clampedY) { |
| 13739 | // Intentionally empty. |
| 13740 | } |
| 13741 | |
| 13742 | /** |
| 13743 | * Returns the over-scroll mode for this view. The result will be |
| 13744 | * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 13745 | * (allow over-scrolling only if the view content is larger than the container), |
| 13746 | * or {@link #OVER_SCROLL_NEVER}. |
| 13747 | * |
| 13748 | * @return This view's over-scroll mode. |
| 13749 | */ |
| 13750 | public int getOverScrollMode() { |
| 13751 | return mOverScrollMode; |
| 13752 | } |
| 13753 | |
| 13754 | /** |
| 13755 | * Set the over-scroll mode for this view. Valid over-scroll modes are |
| 13756 | * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 13757 | * (allow over-scrolling only if the view content is larger than the container), |
| 13758 | * or {@link #OVER_SCROLL_NEVER}. |
| 13759 | * |
| 13760 | * Setting the over-scroll mode of a view will have an effect only if the |
| 13761 | * view is capable of scrolling. |
| 13762 | * |
| 13763 | * @param overScrollMode The new over-scroll mode for this view. |
| 13764 | */ |
| 13765 | public void setOverScrollMode(int overScrollMode) { |
| 13766 | if (overScrollMode != OVER_SCROLL_ALWAYS && |
| 13767 | overScrollMode != OVER_SCROLL_IF_CONTENT_SCROLLS && |
| 13768 | overScrollMode != OVER_SCROLL_NEVER) { |
| 13769 | throw new IllegalArgumentException("Invalid overscroll mode " + overScrollMode); |
| 13770 | } |
| 13771 | mOverScrollMode = overScrollMode; |
| 13772 | } |
| 13773 | |
| 13774 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 13775 | * Gets a scale factor that determines the distance the view should scroll |
| 13776 | * vertically in response to {@link MotionEvent#ACTION_SCROLL}. |
| 13777 | * @return The vertical scroll scale factor. |
| 13778 | * @hide |
| 13779 | */ |
| 13780 | protected float getVerticalScrollFactor() { |
| 13781 | if (mVerticalScrollFactor == 0) { |
| 13782 | TypedValue outValue = new TypedValue(); |
| 13783 | if (!mContext.getTheme().resolveAttribute( |
| 13784 | com.android.internal.R.attr.listPreferredItemHeight, outValue, true)) { |
| 13785 | throw new IllegalStateException( |
| 13786 | "Expected theme to define listPreferredItemHeight."); |
| 13787 | } |
| 13788 | mVerticalScrollFactor = outValue.getDimension( |
| 13789 | mContext.getResources().getDisplayMetrics()); |
| 13790 | } |
| 13791 | return mVerticalScrollFactor; |
| 13792 | } |
| 13793 | |
| 13794 | /** |
| 13795 | * Gets a scale factor that determines the distance the view should scroll |
| 13796 | * horizontally in response to {@link MotionEvent#ACTION_SCROLL}. |
| 13797 | * @return The horizontal scroll scale factor. |
| 13798 | * @hide |
| 13799 | */ |
| 13800 | protected float getHorizontalScrollFactor() { |
| 13801 | // TODO: Should use something else. |
| 13802 | return getVerticalScrollFactor(); |
| 13803 | } |
| 13804 | |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13805 | /** |
| 13806 | * Return the value specifying the text direction or policy that was set with |
| 13807 | * {@link #setTextDirection(int)}. |
| 13808 | * |
| 13809 | * @return the defined text direction. It can be one of: |
| 13810 | * |
| 13811 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 13812 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 13813 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 13814 | * {@link #TEXT_DIRECTION_LTR}, |
| 13815 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 4c1e00a | 2012-01-05 19:05:55 -0800 | [diff] [blame] | 13816 | * {@link #TEXT_DIRECTION_LOCALE}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13817 | * |
| 13818 | * @hide |
| 13819 | */ |
| 13820 | public int getTextDirection() { |
| 13821 | return mTextDirection; |
| 13822 | } |
| 13823 | |
| 13824 | /** |
| 13825 | * Set the text direction. |
| 13826 | * |
| 13827 | * @param textDirection the direction to set. Should be one of: |
| 13828 | * |
| 13829 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 13830 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 13831 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 13832 | * {@link #TEXT_DIRECTION_LTR}, |
| 13833 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 4c1e00a | 2012-01-05 19:05:55 -0800 | [diff] [blame] | 13834 | * {@link #TEXT_DIRECTION_LOCALE}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13835 | * |
| 13836 | * @hide |
| 13837 | */ |
| 13838 | public void setTextDirection(int textDirection) { |
| 13839 | if (textDirection != mTextDirection) { |
| 13840 | mTextDirection = textDirection; |
| 13841 | resetResolvedTextDirection(); |
| 13842 | requestLayout(); |
| 13843 | } |
| 13844 | } |
| 13845 | |
| 13846 | /** |
| 13847 | * Return the resolved text direction. |
| 13848 | * |
| 13849 | * @return the resolved text direction. Return one of: |
| 13850 | * |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13851 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 13852 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13853 | * {@link #TEXT_DIRECTION_LTR}, |
| 13854 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 4c1e00a | 2012-01-05 19:05:55 -0800 | [diff] [blame] | 13855 | * {@link #TEXT_DIRECTION_LOCALE}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13856 | * |
| 13857 | * @hide |
| 13858 | */ |
| 13859 | public int getResolvedTextDirection() { |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13860 | if (mResolvedTextDirection == TEXT_DIRECTION_INHERIT) { |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13861 | resolveTextDirection(); |
| 13862 | } |
| 13863 | return mResolvedTextDirection; |
| 13864 | } |
| 13865 | |
| 13866 | /** |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13867 | * Resolve the text direction. |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 13868 | * |
| 13869 | * @hide |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13870 | */ |
| 13871 | protected void resolveTextDirection() { |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13872 | if (mTextDirection != TEXT_DIRECTION_INHERIT) { |
| 13873 | mResolvedTextDirection = mTextDirection; |
| 13874 | return; |
| 13875 | } |
| 13876 | if (mParent != null && mParent instanceof ViewGroup) { |
| 13877 | mResolvedTextDirection = ((ViewGroup) mParent).getResolvedTextDirection(); |
| 13878 | return; |
| 13879 | } |
| 13880 | mResolvedTextDirection = TEXT_DIRECTION_FIRST_STRONG; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13881 | } |
| 13882 | |
| 13883 | /** |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13884 | * Reset resolved text direction. Will be resolved during a call to getResolvedTextDirection(). |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 13885 | * |
| 13886 | * @hide |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13887 | */ |
| 13888 | protected void resetResolvedTextDirection() { |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13889 | mResolvedTextDirection = TEXT_DIRECTION_INHERIT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13890 | } |
| 13891 | |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13892 | // |
| 13893 | // Properties |
| 13894 | // |
| 13895 | /** |
| 13896 | * A Property wrapper around the <code>alpha</code> functionality handled by the |
| 13897 | * {@link View#setAlpha(float)} and {@link View#getAlpha()} methods. |
| 13898 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13899 | public static final Property<View, Float> ALPHA = new FloatProperty<View>("alpha") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13900 | @Override |
| 13901 | public void setValue(View object, float value) { |
| 13902 | object.setAlpha(value); |
| 13903 | } |
| 13904 | |
| 13905 | @Override |
| 13906 | public Float get(View object) { |
| 13907 | return object.getAlpha(); |
| 13908 | } |
| 13909 | }; |
| 13910 | |
| 13911 | /** |
| 13912 | * A Property wrapper around the <code>translationX</code> functionality handled by the |
| 13913 | * {@link View#setTranslationX(float)} and {@link View#getTranslationX()} methods. |
| 13914 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13915 | public static final Property<View, Float> TRANSLATION_X = new FloatProperty<View>("translationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13916 | @Override |
| 13917 | public void setValue(View object, float value) { |
| 13918 | object.setTranslationX(value); |
| 13919 | } |
| 13920 | |
| 13921 | @Override |
| 13922 | public Float get(View object) { |
| 13923 | return object.getTranslationX(); |
| 13924 | } |
| 13925 | }; |
| 13926 | |
| 13927 | /** |
| 13928 | * A Property wrapper around the <code>translationY</code> functionality handled by the |
| 13929 | * {@link View#setTranslationY(float)} and {@link View#getTranslationY()} methods. |
| 13930 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13931 | public static final Property<View, Float> TRANSLATION_Y = new FloatProperty<View>("translationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13932 | @Override |
| 13933 | public void setValue(View object, float value) { |
| 13934 | object.setTranslationY(value); |
| 13935 | } |
| 13936 | |
| 13937 | @Override |
| 13938 | public Float get(View object) { |
| 13939 | return object.getTranslationY(); |
| 13940 | } |
| 13941 | }; |
| 13942 | |
| 13943 | /** |
| 13944 | * A Property wrapper around the <code>x</code> functionality handled by the |
| 13945 | * {@link View#setX(float)} and {@link View#getX()} methods. |
| 13946 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13947 | public static final Property<View, Float> X = new FloatProperty<View>("x") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13948 | @Override |
| 13949 | public void setValue(View object, float value) { |
| 13950 | object.setX(value); |
| 13951 | } |
| 13952 | |
| 13953 | @Override |
| 13954 | public Float get(View object) { |
| 13955 | return object.getX(); |
| 13956 | } |
| 13957 | }; |
| 13958 | |
| 13959 | /** |
| 13960 | * A Property wrapper around the <code>y</code> functionality handled by the |
| 13961 | * {@link View#setY(float)} and {@link View#getY()} methods. |
| 13962 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13963 | public static final Property<View, Float> Y = new FloatProperty<View>("y") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13964 | @Override |
| 13965 | public void setValue(View object, float value) { |
| 13966 | object.setY(value); |
| 13967 | } |
| 13968 | |
| 13969 | @Override |
| 13970 | public Float get(View object) { |
| 13971 | return object.getY(); |
| 13972 | } |
| 13973 | }; |
| 13974 | |
| 13975 | /** |
| 13976 | * A Property wrapper around the <code>rotation</code> functionality handled by the |
| 13977 | * {@link View#setRotation(float)} and {@link View#getRotation()} methods. |
| 13978 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13979 | public static final Property<View, Float> ROTATION = new FloatProperty<View>("rotation") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13980 | @Override |
| 13981 | public void setValue(View object, float value) { |
| 13982 | object.setRotation(value); |
| 13983 | } |
| 13984 | |
| 13985 | @Override |
| 13986 | public Float get(View object) { |
| 13987 | return object.getRotation(); |
| 13988 | } |
| 13989 | }; |
| 13990 | |
| 13991 | /** |
| 13992 | * A Property wrapper around the <code>rotationX</code> functionality handled by the |
| 13993 | * {@link View#setRotationX(float)} and {@link View#getRotationX()} methods. |
| 13994 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13995 | public static final Property<View, Float> ROTATION_X = new FloatProperty<View>("rotationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13996 | @Override |
| 13997 | public void setValue(View object, float value) { |
| 13998 | object.setRotationX(value); |
| 13999 | } |
| 14000 | |
| 14001 | @Override |
| 14002 | public Float get(View object) { |
| 14003 | return object.getRotationX(); |
| 14004 | } |
| 14005 | }; |
| 14006 | |
| 14007 | /** |
| 14008 | * A Property wrapper around the <code>rotationY</code> functionality handled by the |
| 14009 | * {@link View#setRotationY(float)} and {@link View#getRotationY()} methods. |
| 14010 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 14011 | public static final Property<View, Float> ROTATION_Y = new FloatProperty<View>("rotationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 14012 | @Override |
| 14013 | public void setValue(View object, float value) { |
| 14014 | object.setRotationY(value); |
| 14015 | } |
| 14016 | |
| 14017 | @Override |
| 14018 | public Float get(View object) { |
| 14019 | return object.getRotationY(); |
| 14020 | } |
| 14021 | }; |
| 14022 | |
| 14023 | /** |
| 14024 | * A Property wrapper around the <code>scaleX</code> functionality handled by the |
| 14025 | * {@link View#setScaleX(float)} and {@link View#getScaleX()} methods. |
| 14026 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 14027 | public static final Property<View, Float> SCALE_X = new FloatProperty<View>("scaleX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 14028 | @Override |
| 14029 | public void setValue(View object, float value) { |
| 14030 | object.setScaleX(value); |
| 14031 | } |
| 14032 | |
| 14033 | @Override |
| 14034 | public Float get(View object) { |
| 14035 | return object.getScaleX(); |
| 14036 | } |
| 14037 | }; |
| 14038 | |
| 14039 | /** |
| 14040 | * A Property wrapper around the <code>scaleY</code> functionality handled by the |
| 14041 | * {@link View#setScaleY(float)} and {@link View#getScaleY()} methods. |
| 14042 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 14043 | public static final Property<View, Float> SCALE_Y = new FloatProperty<View>("scaleY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 14044 | @Override |
| 14045 | public void setValue(View object, float value) { |
| 14046 | object.setScaleY(value); |
| 14047 | } |
| 14048 | |
| 14049 | @Override |
| 14050 | public Float get(View object) { |
| 14051 | return object.getScaleY(); |
| 14052 | } |
| 14053 | }; |
| 14054 | |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 14055 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14056 | * A MeasureSpec encapsulates the layout requirements passed from parent to child. |
| 14057 | * Each MeasureSpec represents a requirement for either the width or the height. |
| 14058 | * A MeasureSpec is comprised of a size and a mode. There are three possible |
| 14059 | * modes: |
| 14060 | * <dl> |
| 14061 | * <dt>UNSPECIFIED</dt> |
| 14062 | * <dd> |
| 14063 | * The parent has not imposed any constraint on the child. It can be whatever size |
| 14064 | * it wants. |
| 14065 | * </dd> |
| 14066 | * |
| 14067 | * <dt>EXACTLY</dt> |
| 14068 | * <dd> |
| 14069 | * The parent has determined an exact size for the child. The child is going to be |
| 14070 | * given those bounds regardless of how big it wants to be. |
| 14071 | * </dd> |
| 14072 | * |
| 14073 | * <dt>AT_MOST</dt> |
| 14074 | * <dd> |
| 14075 | * The child can be as large as it wants up to the specified size. |
| 14076 | * </dd> |
| 14077 | * </dl> |
| 14078 | * |
| 14079 | * MeasureSpecs are implemented as ints to reduce object allocation. This class |
| 14080 | * is provided to pack and unpack the <size, mode> tuple into the int. |
| 14081 | */ |
| 14082 | public static class MeasureSpec { |
| 14083 | private static final int MODE_SHIFT = 30; |
| 14084 | private static final int MODE_MASK = 0x3 << MODE_SHIFT; |
| 14085 | |
| 14086 | /** |
| 14087 | * Measure specification mode: The parent has not imposed any constraint |
| 14088 | * on the child. It can be whatever size it wants. |
| 14089 | */ |
| 14090 | public static final int UNSPECIFIED = 0 << MODE_SHIFT; |
| 14091 | |
| 14092 | /** |
| 14093 | * Measure specification mode: The parent has determined an exact size |
| 14094 | * for the child. The child is going to be given those bounds regardless |
| 14095 | * of how big it wants to be. |
| 14096 | */ |
| 14097 | public static final int EXACTLY = 1 << MODE_SHIFT; |
| 14098 | |
| 14099 | /** |
| 14100 | * Measure specification mode: The child can be as large as it wants up |
| 14101 | * to the specified size. |
| 14102 | */ |
| 14103 | public static final int AT_MOST = 2 << MODE_SHIFT; |
| 14104 | |
| 14105 | /** |
| 14106 | * Creates a measure specification based on the supplied size and mode. |
| 14107 | * |
| 14108 | * The mode must always be one of the following: |
| 14109 | * <ul> |
| 14110 | * <li>{@link android.view.View.MeasureSpec#UNSPECIFIED}</li> |
| 14111 | * <li>{@link android.view.View.MeasureSpec#EXACTLY}</li> |
| 14112 | * <li>{@link android.view.View.MeasureSpec#AT_MOST}</li> |
| 14113 | * </ul> |
| 14114 | * |
| 14115 | * @param size the size of the measure specification |
| 14116 | * @param mode the mode of the measure specification |
| 14117 | * @return the measure specification based on size and mode |
| 14118 | */ |
| 14119 | public static int makeMeasureSpec(int size, int mode) { |
| 14120 | return size + mode; |
| 14121 | } |
| 14122 | |
| 14123 | /** |
| 14124 | * Extracts the mode from the supplied measure specification. |
| 14125 | * |
| 14126 | * @param measureSpec the measure specification to extract the mode from |
| 14127 | * @return {@link android.view.View.MeasureSpec#UNSPECIFIED}, |
| 14128 | * {@link android.view.View.MeasureSpec#AT_MOST} or |
| 14129 | * {@link android.view.View.MeasureSpec#EXACTLY} |
| 14130 | */ |
| 14131 | public static int getMode(int measureSpec) { |
| 14132 | return (measureSpec & MODE_MASK); |
| 14133 | } |
| 14134 | |
| 14135 | /** |
| 14136 | * Extracts the size from the supplied measure specification. |
| 14137 | * |
| 14138 | * @param measureSpec the measure specification to extract the size from |
| 14139 | * @return the size in pixels defined in the supplied measure specification |
| 14140 | */ |
| 14141 | public static int getSize(int measureSpec) { |
| 14142 | return (measureSpec & ~MODE_MASK); |
| 14143 | } |
| 14144 | |
| 14145 | /** |
| 14146 | * Returns a String representation of the specified measure |
| 14147 | * specification. |
| 14148 | * |
| 14149 | * @param measureSpec the measure specification to convert to a String |
| 14150 | * @return a String with the following format: "MeasureSpec: MODE SIZE" |
| 14151 | */ |
| 14152 | public static String toString(int measureSpec) { |
| 14153 | int mode = getMode(measureSpec); |
| 14154 | int size = getSize(measureSpec); |
| 14155 | |
| 14156 | StringBuilder sb = new StringBuilder("MeasureSpec: "); |
| 14157 | |
| 14158 | if (mode == UNSPECIFIED) |
| 14159 | sb.append("UNSPECIFIED "); |
| 14160 | else if (mode == EXACTLY) |
| 14161 | sb.append("EXACTLY "); |
| 14162 | else if (mode == AT_MOST) |
| 14163 | sb.append("AT_MOST "); |
| 14164 | else |
| 14165 | sb.append(mode).append(" "); |
| 14166 | |
| 14167 | sb.append(size); |
| 14168 | return sb.toString(); |
| 14169 | } |
| 14170 | } |
| 14171 | |
| 14172 | class CheckForLongPress implements Runnable { |
| 14173 | |
| 14174 | private int mOriginalWindowAttachCount; |
| 14175 | |
| 14176 | public void run() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 14177 | if (isPressed() && (mParent != null) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14178 | && mOriginalWindowAttachCount == mWindowAttachCount) { |
| 14179 | if (performLongClick()) { |
| 14180 | mHasPerformedLongPress = true; |
| 14181 | } |
| 14182 | } |
| 14183 | } |
| 14184 | |
| 14185 | public void rememberWindowAttachCount() { |
| 14186 | mOriginalWindowAttachCount = mWindowAttachCount; |
| 14187 | } |
| 14188 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14189 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 14190 | private final class CheckForTap implements Runnable { |
| 14191 | public void run() { |
| 14192 | mPrivateFlags &= ~PREPRESSED; |
| 14193 | mPrivateFlags |= PRESSED; |
| 14194 | refreshDrawableState(); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 14195 | checkForLongClick(ViewConfiguration.getTapTimeout()); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 14196 | } |
| 14197 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14198 | |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 14199 | private final class PerformClick implements Runnable { |
| 14200 | public void run() { |
| 14201 | performClick(); |
| 14202 | } |
| 14203 | } |
| 14204 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 14205 | /** @hide */ |
| 14206 | public void hackTurnOffWindowResizeAnim(boolean off) { |
| 14207 | mAttachInfo.mTurnOffWindowResizeAnim = off; |
| 14208 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14209 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14210 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 14211 | * This method returns a ViewPropertyAnimator object, which can be used to animate |
| 14212 | * specific properties on this View. |
| 14213 | * |
| 14214 | * @return ViewPropertyAnimator The ViewPropertyAnimator associated with this View. |
| 14215 | */ |
| 14216 | public ViewPropertyAnimator animate() { |
| 14217 | if (mAnimator == null) { |
| 14218 | mAnimator = new ViewPropertyAnimator(this); |
| 14219 | } |
| 14220 | return mAnimator; |
| 14221 | } |
| 14222 | |
| 14223 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14224 | * Interface definition for a callback to be invoked when a key event is |
| 14225 | * dispatched to this view. The callback will be invoked before the key |
| 14226 | * event is given to the view. |
| 14227 | */ |
| 14228 | public interface OnKeyListener { |
| 14229 | /** |
| 14230 | * Called when a key is dispatched to a view. This allows listeners to |
| 14231 | * get a chance to respond before the target view. |
| 14232 | * |
| 14233 | * @param v The view the key has been dispatched to. |
| 14234 | * @param keyCode The code for the physical key that was pressed |
| 14235 | * @param event The KeyEvent object containing full information about |
| 14236 | * the event. |
| 14237 | * @return True if the listener has consumed the event, false otherwise. |
| 14238 | */ |
| 14239 | boolean onKey(View v, int keyCode, KeyEvent event); |
| 14240 | } |
| 14241 | |
| 14242 | /** |
| 14243 | * Interface definition for a callback to be invoked when a touch event is |
| 14244 | * dispatched to this view. The callback will be invoked before the touch |
| 14245 | * event is given to the view. |
| 14246 | */ |
| 14247 | public interface OnTouchListener { |
| 14248 | /** |
| 14249 | * Called when a touch event is dispatched to a view. This allows listeners to |
| 14250 | * get a chance to respond before the target view. |
| 14251 | * |
| 14252 | * @param v The view the touch event has been dispatched to. |
| 14253 | * @param event The MotionEvent object containing full information about |
| 14254 | * the event. |
| 14255 | * @return True if the listener has consumed the event, false otherwise. |
| 14256 | */ |
| 14257 | boolean onTouch(View v, MotionEvent event); |
| 14258 | } |
| 14259 | |
| 14260 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 14261 | * Interface definition for a callback to be invoked when a hover event is |
| 14262 | * dispatched to this view. The callback will be invoked before the hover |
| 14263 | * event is given to the view. |
| 14264 | */ |
| 14265 | public interface OnHoverListener { |
| 14266 | /** |
| 14267 | * Called when a hover event is dispatched to a view. This allows listeners to |
| 14268 | * get a chance to respond before the target view. |
| 14269 | * |
| 14270 | * @param v The view the hover event has been dispatched to. |
| 14271 | * @param event The MotionEvent object containing full information about |
| 14272 | * the event. |
| 14273 | * @return True if the listener has consumed the event, false otherwise. |
| 14274 | */ |
| 14275 | boolean onHover(View v, MotionEvent event); |
| 14276 | } |
| 14277 | |
| 14278 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 14279 | * Interface definition for a callback to be invoked when a generic motion event is |
| 14280 | * dispatched to this view. The callback will be invoked before the generic motion |
| 14281 | * event is given to the view. |
| 14282 | */ |
| 14283 | public interface OnGenericMotionListener { |
| 14284 | /** |
| 14285 | * Called when a generic motion event is dispatched to a view. This allows listeners to |
| 14286 | * get a chance to respond before the target view. |
| 14287 | * |
| 14288 | * @param v The view the generic motion event has been dispatched to. |
| 14289 | * @param event The MotionEvent object containing full information about |
| 14290 | * the event. |
| 14291 | * @return True if the listener has consumed the event, false otherwise. |
| 14292 | */ |
| 14293 | boolean onGenericMotion(View v, MotionEvent event); |
| 14294 | } |
| 14295 | |
| 14296 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14297 | * Interface definition for a callback to be invoked when a view has been clicked and held. |
| 14298 | */ |
| 14299 | public interface OnLongClickListener { |
| 14300 | /** |
| 14301 | * Called when a view has been clicked and held. |
| 14302 | * |
| 14303 | * @param v The view that was clicked and held. |
| 14304 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 14305 | * @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] | 14306 | */ |
| 14307 | boolean onLongClick(View v); |
| 14308 | } |
| 14309 | |
| 14310 | /** |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 14311 | * Interface definition for a callback to be invoked when a drag is being dispatched |
| 14312 | * to this view. The callback will be invoked before the hosting view's own |
| 14313 | * onDrag(event) method. If the listener wants to fall back to the hosting view's |
| 14314 | * onDrag(event) behavior, it should return 'false' from this callback. |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 14315 | * |
| 14316 | * <div class="special reference"> |
| 14317 | * <h3>Developer Guides</h3> |
| 14318 | * <p>For a guide to implementing drag and drop features, read the |
| 14319 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 14320 | * </div> |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 14321 | */ |
| 14322 | public interface OnDragListener { |
| 14323 | /** |
| 14324 | * Called when a drag event is dispatched to a view. This allows listeners |
| 14325 | * to get a chance to override base View behavior. |
| 14326 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14327 | * @param v The View that received the drag event. |
| 14328 | * @param event The {@link android.view.DragEvent} object for the drag event. |
| 14329 | * @return {@code true} if the drag event was handled successfully, or {@code false} |
| 14330 | * if the drag event was not handled. Note that {@code false} will trigger the View |
| 14331 | * to call its {@link #onDragEvent(DragEvent) onDragEvent()} handler. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 14332 | */ |
| 14333 | boolean onDrag(View v, DragEvent event); |
| 14334 | } |
| 14335 | |
| 14336 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14337 | * Interface definition for a callback to be invoked when the focus state of |
| 14338 | * a view changed. |
| 14339 | */ |
| 14340 | public interface OnFocusChangeListener { |
| 14341 | /** |
| 14342 | * Called when the focus state of a view has changed. |
| 14343 | * |
| 14344 | * @param v The view whose state has changed. |
| 14345 | * @param hasFocus The new focus state of v. |
| 14346 | */ |
| 14347 | void onFocusChange(View v, boolean hasFocus); |
| 14348 | } |
| 14349 | |
| 14350 | /** |
| 14351 | * Interface definition for a callback to be invoked when a view is clicked. |
| 14352 | */ |
| 14353 | public interface OnClickListener { |
| 14354 | /** |
| 14355 | * Called when a view has been clicked. |
| 14356 | * |
| 14357 | * @param v The view that was clicked. |
| 14358 | */ |
| 14359 | void onClick(View v); |
| 14360 | } |
| 14361 | |
| 14362 | /** |
| 14363 | * Interface definition for a callback to be invoked when the context menu |
| 14364 | * for this view is being built. |
| 14365 | */ |
| 14366 | public interface OnCreateContextMenuListener { |
| 14367 | /** |
| 14368 | * Called when the context menu for this view is being built. It is not |
| 14369 | * safe to hold onto the menu after this method returns. |
| 14370 | * |
| 14371 | * @param menu The context menu that is being built |
| 14372 | * @param v The view for which the context menu is being built |
| 14373 | * @param menuInfo Extra information about the item for which the |
| 14374 | * context menu should be shown. This information will vary |
| 14375 | * depending on the class of v. |
| 14376 | */ |
| 14377 | void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo); |
| 14378 | } |
| 14379 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14380 | /** |
| 14381 | * Interface definition for a callback to be invoked when the status bar changes |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 14382 | * visibility. This reports <strong>global</strong> changes to the system UI |
| 14383 | * state, not just what the application is requesting. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14384 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 14385 | * @see View#setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14386 | */ |
| 14387 | public interface OnSystemUiVisibilityChangeListener { |
| 14388 | /** |
| 14389 | * Called when the status bar changes visibility because of a call to |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 14390 | * {@link View#setSystemUiVisibility(int)}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14391 | * |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 14392 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 14393 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. This tells you the |
| 14394 | * <strong>global</strong> state of the UI visibility flags, not what your |
| 14395 | * app is currently applying. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14396 | */ |
| 14397 | public void onSystemUiVisibilityChange(int visibility); |
| 14398 | } |
| 14399 | |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 14400 | /** |
| 14401 | * Interface definition for a callback to be invoked when this view is attached |
| 14402 | * or detached from its window. |
| 14403 | */ |
| 14404 | public interface OnAttachStateChangeListener { |
| 14405 | /** |
| 14406 | * Called when the view is attached to a window. |
| 14407 | * @param v The view that was attached |
| 14408 | */ |
| 14409 | public void onViewAttachedToWindow(View v); |
| 14410 | /** |
| 14411 | * Called when the view is detached from a window. |
| 14412 | * @param v The view that was detached |
| 14413 | */ |
| 14414 | public void onViewDetachedFromWindow(View v); |
| 14415 | } |
| 14416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14417 | private final class UnsetPressedState implements Runnable { |
| 14418 | public void run() { |
| 14419 | setPressed(false); |
| 14420 | } |
| 14421 | } |
| 14422 | |
| 14423 | /** |
| 14424 | * Base class for derived classes that want to save and restore their own |
| 14425 | * state in {@link android.view.View#onSaveInstanceState()}. |
| 14426 | */ |
| 14427 | public static class BaseSavedState extends AbsSavedState { |
| 14428 | /** |
| 14429 | * Constructor used when reading from a parcel. Reads the state of the superclass. |
| 14430 | * |
| 14431 | * @param source |
| 14432 | */ |
| 14433 | public BaseSavedState(Parcel source) { |
| 14434 | super(source); |
| 14435 | } |
| 14436 | |
| 14437 | /** |
| 14438 | * Constructor called by derived classes when creating their SavedState objects |
| 14439 | * |
| 14440 | * @param superState The state of the superclass of this view |
| 14441 | */ |
| 14442 | public BaseSavedState(Parcelable superState) { |
| 14443 | super(superState); |
| 14444 | } |
| 14445 | |
| 14446 | public static final Parcelable.Creator<BaseSavedState> CREATOR = |
| 14447 | new Parcelable.Creator<BaseSavedState>() { |
| 14448 | public BaseSavedState createFromParcel(Parcel in) { |
| 14449 | return new BaseSavedState(in); |
| 14450 | } |
| 14451 | |
| 14452 | public BaseSavedState[] newArray(int size) { |
| 14453 | return new BaseSavedState[size]; |
| 14454 | } |
| 14455 | }; |
| 14456 | } |
| 14457 | |
| 14458 | /** |
| 14459 | * A set of information given to a view when it is attached to its parent |
| 14460 | * window. |
| 14461 | */ |
| 14462 | static class AttachInfo { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14463 | interface Callbacks { |
| 14464 | void playSoundEffect(int effectId); |
| 14465 | boolean performHapticFeedback(int effectId, boolean always); |
| 14466 | } |
| 14467 | |
| 14468 | /** |
| 14469 | * InvalidateInfo is used to post invalidate(int, int, int, int) messages |
| 14470 | * to a Handler. This class contains the target (View) to invalidate and |
| 14471 | * the coordinates of the dirty rectangle. |
| 14472 | * |
| 14473 | * For performance purposes, this class also implements a pool of up to |
| 14474 | * POOL_LIMIT objects that get reused. This reduces memory allocations |
| 14475 | * whenever possible. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14476 | */ |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 14477 | static class InvalidateInfo implements Poolable<InvalidateInfo> { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14478 | private static final int POOL_LIMIT = 10; |
Romain Guy | 2e9bbce | 2009-04-01 10:40:10 -0700 | [diff] [blame] | 14479 | private static final Pool<InvalidateInfo> sPool = Pools.synchronizedPool( |
| 14480 | Pools.finitePool(new PoolableManager<InvalidateInfo>() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 14481 | public InvalidateInfo newInstance() { |
| 14482 | return new InvalidateInfo(); |
| 14483 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14484 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 14485 | public void onAcquired(InvalidateInfo element) { |
| 14486 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14487 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 14488 | public void onReleased(InvalidateInfo element) { |
Romain Guy | 40c18f5 | 2011-09-01 17:01:18 -0700 | [diff] [blame] | 14489 | element.target = null; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 14490 | } |
| 14491 | }, POOL_LIMIT) |
| 14492 | ); |
| 14493 | |
| 14494 | private InvalidateInfo mNext; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 14495 | private boolean mIsPooled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14496 | |
| 14497 | View target; |
| 14498 | |
| 14499 | int left; |
| 14500 | int top; |
| 14501 | int right; |
| 14502 | int bottom; |
| 14503 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 14504 | public void setNextPoolable(InvalidateInfo element) { |
| 14505 | mNext = element; |
| 14506 | } |
| 14507 | |
| 14508 | public InvalidateInfo getNextPoolable() { |
| 14509 | return mNext; |
| 14510 | } |
| 14511 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14512 | static InvalidateInfo acquire() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 14513 | return sPool.acquire(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14514 | } |
| 14515 | |
| 14516 | void release() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 14517 | sPool.release(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14518 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 14519 | |
| 14520 | public boolean isPooled() { |
| 14521 | return mIsPooled; |
| 14522 | } |
| 14523 | |
| 14524 | public void setPooled(boolean isPooled) { |
| 14525 | mIsPooled = isPooled; |
| 14526 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14527 | } |
| 14528 | |
| 14529 | final IWindowSession mSession; |
| 14530 | |
| 14531 | final IWindow mWindow; |
| 14532 | |
| 14533 | final IBinder mWindowToken; |
| 14534 | |
| 14535 | final Callbacks mRootCallbacks; |
| 14536 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 14537 | HardwareCanvas mHardwareCanvas; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 14538 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14539 | /** |
| 14540 | * The top view of the hierarchy. |
| 14541 | */ |
| 14542 | View mRootView; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14543 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14544 | IBinder mPanelParentWindowToken; |
| 14545 | Surface mSurface; |
| 14546 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 14547 | boolean mHardwareAccelerated; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 14548 | boolean mHardwareAccelerationRequested; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 14549 | HardwareRenderer mHardwareRenderer; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14551 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14552 | * Scale factor used by the compatibility mode |
| 14553 | */ |
| 14554 | float mApplicationScale; |
| 14555 | |
| 14556 | /** |
| 14557 | * Indicates whether the application is in compatibility mode |
| 14558 | */ |
| 14559 | boolean mScalingRequired; |
| 14560 | |
| 14561 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 14562 | * 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] | 14563 | */ |
| 14564 | boolean mTurnOffWindowResizeAnim; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14565 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 14566 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14567 | * Left position of this view's window |
| 14568 | */ |
| 14569 | int mWindowLeft; |
| 14570 | |
| 14571 | /** |
| 14572 | * Top position of this view's window |
| 14573 | */ |
| 14574 | int mWindowTop; |
| 14575 | |
| 14576 | /** |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 14577 | * Indicates whether views need to use 32-bit drawing caches |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 14578 | */ |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 14579 | boolean mUse32BitDrawingCache; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 14580 | |
| 14581 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14582 | * For windows that are full-screen but using insets to layout inside |
| 14583 | * of the screen decorations, these are the current insets for the |
| 14584 | * content of the window. |
| 14585 | */ |
| 14586 | final Rect mContentInsets = new Rect(); |
| 14587 | |
| 14588 | /** |
| 14589 | * For windows that are full-screen but using insets to layout inside |
| 14590 | * of the screen decorations, these are the current insets for the |
| 14591 | * actual visible parts of the window. |
| 14592 | */ |
| 14593 | final Rect mVisibleInsets = new Rect(); |
| 14594 | |
| 14595 | /** |
| 14596 | * The internal insets given by this window. This value is |
| 14597 | * supplied by the client (through |
| 14598 | * {@link ViewTreeObserver.OnComputeInternalInsetsListener}) and will |
| 14599 | * be given to the window manager when changed to be used in laying |
| 14600 | * out windows behind it. |
| 14601 | */ |
| 14602 | final ViewTreeObserver.InternalInsetsInfo mGivenInternalInsets |
| 14603 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 14604 | |
| 14605 | /** |
| 14606 | * All views in the window's hierarchy that serve as scroll containers, |
| 14607 | * used to determine if the window can be resized or must be panned |
| 14608 | * to adjust for a soft input area. |
| 14609 | */ |
| 14610 | final ArrayList<View> mScrollContainers = new ArrayList<View>(); |
| 14611 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 14612 | final KeyEvent.DispatcherState mKeyDispatchState |
| 14613 | = new KeyEvent.DispatcherState(); |
| 14614 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14615 | /** |
| 14616 | * Indicates whether the view's window currently has the focus. |
| 14617 | */ |
| 14618 | boolean mHasWindowFocus; |
| 14619 | |
| 14620 | /** |
| 14621 | * The current visibility of the window. |
| 14622 | */ |
| 14623 | int mWindowVisibility; |
| 14624 | |
| 14625 | /** |
| 14626 | * Indicates the time at which drawing started to occur. |
| 14627 | */ |
| 14628 | long mDrawingTime; |
| 14629 | |
| 14630 | /** |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 14631 | * Indicates whether or not ignoring the DIRTY_MASK flags. |
| 14632 | */ |
| 14633 | boolean mIgnoreDirtyState; |
| 14634 | |
| 14635 | /** |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 14636 | * This flag tracks when the mIgnoreDirtyState flag is set during draw(), |
| 14637 | * to avoid clearing that flag prematurely. |
| 14638 | */ |
| 14639 | boolean mSetIgnoreDirtyState = false; |
| 14640 | |
| 14641 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14642 | * Indicates whether the view's window is currently in touch mode. |
| 14643 | */ |
| 14644 | boolean mInTouchMode; |
| 14645 | |
| 14646 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 14647 | * Indicates that ViewAncestor should trigger a global layout change |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14648 | * the next time it performs a traversal |
| 14649 | */ |
| 14650 | boolean mRecomputeGlobalAttributes; |
| 14651 | |
| 14652 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 14653 | * Always report new attributes at next traversal. |
| 14654 | */ |
| 14655 | boolean mForceReportNewAttributes; |
| 14656 | |
| 14657 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14658 | * Set during a traveral if any views want to keep the screen on. |
| 14659 | */ |
| 14660 | boolean mKeepScreenOn; |
| 14661 | |
| 14662 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14663 | * Bitwise-or of all of the values that views have passed to setSystemUiVisibility(). |
| 14664 | */ |
| 14665 | int mSystemUiVisibility; |
| 14666 | |
| 14667 | /** |
| 14668 | * True if a view in this hierarchy has an OnSystemUiVisibilityChangeListener |
| 14669 | * attached. |
| 14670 | */ |
| 14671 | boolean mHasSystemUiListeners; |
| 14672 | |
| 14673 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14674 | * Set if the visibility of any views has changed. |
| 14675 | */ |
| 14676 | boolean mViewVisibilityChanged; |
| 14677 | |
| 14678 | /** |
| 14679 | * Set to true if a view has been scrolled. |
| 14680 | */ |
| 14681 | boolean mViewScrollChanged; |
| 14682 | |
| 14683 | /** |
| 14684 | * Global to the view hierarchy used as a temporary for dealing with |
| 14685 | * x/y points in the transparent region computations. |
| 14686 | */ |
| 14687 | final int[] mTransparentLocation = new int[2]; |
| 14688 | |
| 14689 | /** |
| 14690 | * Global to the view hierarchy used as a temporary for dealing with |
| 14691 | * x/y points in the ViewGroup.invalidateChild implementation. |
| 14692 | */ |
| 14693 | final int[] mInvalidateChildLocation = new int[2]; |
| 14694 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 14695 | |
| 14696 | /** |
| 14697 | * Global to the view hierarchy used as a temporary for dealing with |
| 14698 | * x/y location when view is transformed. |
| 14699 | */ |
| 14700 | final float[] mTmpTransformLocation = new float[2]; |
| 14701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14702 | /** |
| 14703 | * The view tree observer used to dispatch global events like |
| 14704 | * layout, pre-draw, touch mode change, etc. |
| 14705 | */ |
| 14706 | final ViewTreeObserver mTreeObserver = new ViewTreeObserver(); |
| 14707 | |
| 14708 | /** |
| 14709 | * A Canvas used by the view hierarchy to perform bitmap caching. |
| 14710 | */ |
| 14711 | Canvas mCanvas; |
| 14712 | |
| 14713 | /** |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 14714 | * 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] | 14715 | * handler can be used to pump events in the UI events queue. |
| 14716 | */ |
| 14717 | final Handler mHandler; |
| 14718 | |
| 14719 | /** |
| 14720 | * Identifier for messages requesting the view to be invalidated. |
| 14721 | * Such messages should be sent to {@link #mHandler}. |
| 14722 | */ |
| 14723 | static final int INVALIDATE_MSG = 0x1; |
| 14724 | |
| 14725 | /** |
| 14726 | * Identifier for messages requesting the view to invalidate a region. |
| 14727 | * Such messages should be sent to {@link #mHandler}. |
| 14728 | */ |
| 14729 | static final int INVALIDATE_RECT_MSG = 0x2; |
| 14730 | |
| 14731 | /** |
| 14732 | * Temporary for use in computing invalidate rectangles while |
| 14733 | * calling up the hierarchy. |
| 14734 | */ |
| 14735 | final Rect mTmpInvalRect = new Rect(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 14736 | |
| 14737 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 14738 | * Temporary for use in computing hit areas with transformed views |
| 14739 | */ |
| 14740 | final RectF mTmpTransformRect = new RectF(); |
| 14741 | |
| 14742 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 14743 | * Temporary list for use in collecting focusable descendents of a view. |
| 14744 | */ |
| 14745 | final ArrayList<View> mFocusablesTempList = new ArrayList<View>(24); |
| 14746 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14747 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 14748 | * The id of the window for accessibility purposes. |
| 14749 | */ |
| 14750 | int mAccessibilityWindowId = View.NO_ID; |
| 14751 | |
| 14752 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14753 | * Creates a new set of attachment information with the specified |
| 14754 | * events handler and thread. |
| 14755 | * |
| 14756 | * @param handler the events handler the view must use |
| 14757 | */ |
| 14758 | AttachInfo(IWindowSession session, IWindow window, |
| 14759 | Handler handler, Callbacks effectPlayer) { |
| 14760 | mSession = session; |
| 14761 | mWindow = window; |
| 14762 | mWindowToken = window.asBinder(); |
| 14763 | mHandler = handler; |
| 14764 | mRootCallbacks = effectPlayer; |
| 14765 | } |
| 14766 | } |
| 14767 | |
| 14768 | /** |
| 14769 | * <p>ScrollabilityCache holds various fields used by a View when scrolling |
| 14770 | * is supported. This avoids keeping too many unused fields in most |
| 14771 | * instances of View.</p> |
| 14772 | */ |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14773 | private static class ScrollabilityCache implements Runnable { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14774 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14775 | /** |
| 14776 | * Scrollbars are not visible |
| 14777 | */ |
| 14778 | public static final int OFF = 0; |
| 14779 | |
| 14780 | /** |
| 14781 | * Scrollbars are visible |
| 14782 | */ |
| 14783 | public static final int ON = 1; |
| 14784 | |
| 14785 | /** |
| 14786 | * Scrollbars are fading away |
| 14787 | */ |
| 14788 | public static final int FADING = 2; |
| 14789 | |
| 14790 | public boolean fadeScrollBars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14792 | public int fadingEdgeLength; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14793 | public int scrollBarDefaultDelayBeforeFade; |
| 14794 | public int scrollBarFadeDuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14795 | |
| 14796 | public int scrollBarSize; |
| 14797 | public ScrollBarDrawable scrollBar; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14798 | public float[] interpolatorValues; |
| 14799 | public View host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14800 | |
| 14801 | public final Paint paint; |
| 14802 | public final Matrix matrix; |
| 14803 | public Shader shader; |
| 14804 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14805 | public final Interpolator scrollBarInterpolator = new Interpolator(1, 2); |
| 14806 | |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 14807 | private static final float[] OPAQUE = { 255 }; |
| 14808 | private static final float[] TRANSPARENT = { 0.0f }; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14809 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14810 | /** |
| 14811 | * When fading should start. This time moves into the future every time |
| 14812 | * a new scroll happens. Measured based on SystemClock.uptimeMillis() |
| 14813 | */ |
| 14814 | public long fadeStartTime; |
| 14815 | |
| 14816 | |
| 14817 | /** |
| 14818 | * The current state of the scrollbars: ON, OFF, or FADING |
| 14819 | */ |
| 14820 | public int state = OFF; |
| 14821 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14822 | private int mLastColor; |
| 14823 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14824 | public ScrollabilityCache(ViewConfiguration configuration, View host) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14825 | fadingEdgeLength = configuration.getScaledFadingEdgeLength(); |
| 14826 | scrollBarSize = configuration.getScaledScrollBarSize(); |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 14827 | scrollBarDefaultDelayBeforeFade = ViewConfiguration.getScrollDefaultDelay(); |
| 14828 | scrollBarFadeDuration = ViewConfiguration.getScrollBarFadeDuration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14829 | |
| 14830 | paint = new Paint(); |
| 14831 | matrix = new Matrix(); |
| 14832 | // use use a height of 1, and then wack the matrix each time we |
| 14833 | // actually use it. |
| 14834 | shader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14835 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14836 | paint.setShader(shader); |
| 14837 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14838 | this.host = host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14839 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14840 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14841 | public void setFadeColor(int color) { |
| 14842 | if (color != 0 && color != mLastColor) { |
| 14843 | mLastColor = color; |
| 14844 | color |= 0xFF000000; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14845 | |
Romain Guy | e55e1a7 | 2009-08-27 10:42:26 -0700 | [diff] [blame] | 14846 | shader = new LinearGradient(0, 0, 0, 1, color | 0xFF000000, |
| 14847 | color & 0x00FFFFFF, Shader.TileMode.CLAMP); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14848 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14849 | paint.setShader(shader); |
| 14850 | // Restore the default transfer mode (src_over) |
| 14851 | paint.setXfermode(null); |
| 14852 | } |
| 14853 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14854 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14855 | public void run() { |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 14856 | long now = AnimationUtils.currentAnimationTimeMillis(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14857 | if (now >= fadeStartTime) { |
| 14858 | |
| 14859 | // the animation fades the scrollbars out by changing |
| 14860 | // the opacity (alpha) from fully opaque to fully |
| 14861 | // transparent |
| 14862 | int nextFrame = (int) now; |
| 14863 | int framesCount = 0; |
| 14864 | |
| 14865 | Interpolator interpolator = scrollBarInterpolator; |
| 14866 | |
| 14867 | // Start opaque |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 14868 | interpolator.setKeyFrame(framesCount++, nextFrame, OPAQUE); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14869 | |
| 14870 | // End transparent |
| 14871 | nextFrame += scrollBarFadeDuration; |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 14872 | interpolator.setKeyFrame(framesCount, nextFrame, TRANSPARENT); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14873 | |
| 14874 | state = FADING; |
| 14875 | |
| 14876 | // Kick off the fade animation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14877 | host.invalidate(true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14878 | } |
| 14879 | } |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 14880 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14881 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 14882 | /** |
| 14883 | * Resuable callback for sending |
| 14884 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 14885 | */ |
| 14886 | private class SendViewScrolledAccessibilityEvent implements Runnable { |
| 14887 | public volatile boolean mIsPending; |
| 14888 | |
| 14889 | public void run() { |
| 14890 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED); |
| 14891 | mIsPending = false; |
| 14892 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14893 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 14894 | |
| 14895 | /** |
| 14896 | * <p> |
| 14897 | * This class represents a delegate that can be registered in a {@link View} |
| 14898 | * to enhance accessibility support via composition rather via inheritance. |
| 14899 | * It is specifically targeted to widget developers that extend basic View |
| 14900 | * classes i.e. classes in package android.view, that would like their |
| 14901 | * applications to be backwards compatible. |
| 14902 | * </p> |
| 14903 | * <p> |
| 14904 | * A scenario in which a developer would like to use an accessibility delegate |
| 14905 | * is overriding a method introduced in a later API version then the minimal API |
| 14906 | * version supported by the application. For example, the method |
| 14907 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} is not available |
| 14908 | * in API version 4 when the accessibility APIs were first introduced. If a |
| 14909 | * developer would like his application to run on API version 4 devices (assuming |
| 14910 | * all other APIs used by the application are version 4 or lower) and take advantage |
| 14911 | * of this method, instead of overriding the method which would break the application's |
| 14912 | * backwards compatibility, he can override the corresponding method in this |
| 14913 | * delegate and register the delegate in the target View if the API version of |
| 14914 | * the system is high enough i.e. the API version is same or higher to the API |
| 14915 | * version that introduced |
| 14916 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)}. |
| 14917 | * </p> |
| 14918 | * <p> |
| 14919 | * Here is an example implementation: |
| 14920 | * </p> |
| 14921 | * <code><pre><p> |
| 14922 | * if (Build.VERSION.SDK_INT >= 14) { |
| 14923 | * // If the API version is equal of higher than the version in |
| 14924 | * // which onInitializeAccessibilityNodeInfo was introduced we |
| 14925 | * // register a delegate with a customized implementation. |
| 14926 | * View view = findViewById(R.id.view_id); |
| 14927 | * view.setAccessibilityDelegate(new AccessibilityDelegate() { |
| 14928 | * public void onInitializeAccessibilityNodeInfo(View host, |
| 14929 | * AccessibilityNodeInfo info) { |
| 14930 | * // Let the default implementation populate the info. |
| 14931 | * super.onInitializeAccessibilityNodeInfo(host, info); |
| 14932 | * // Set some other information. |
| 14933 | * info.setEnabled(host.isEnabled()); |
| 14934 | * } |
| 14935 | * }); |
| 14936 | * } |
| 14937 | * </code></pre></p> |
| 14938 | * <p> |
| 14939 | * This delegate contains methods that correspond to the accessibility methods |
| 14940 | * in View. If a delegate has been specified the implementation in View hands |
| 14941 | * off handling to the corresponding method in this delegate. The default |
| 14942 | * implementation the delegate methods behaves exactly as the corresponding |
| 14943 | * method in View for the case of no accessibility delegate been set. Hence, |
| 14944 | * to customize the behavior of a View method, clients can override only the |
| 14945 | * corresponding delegate method without altering the behavior of the rest |
| 14946 | * accessibility related methods of the host view. |
| 14947 | * </p> |
| 14948 | */ |
| 14949 | public static class AccessibilityDelegate { |
| 14950 | |
| 14951 | /** |
| 14952 | * Sends an accessibility event of the given type. If accessibility is not |
| 14953 | * enabled this method has no effect. |
| 14954 | * <p> |
| 14955 | * The default implementation behaves as {@link View#sendAccessibilityEvent(int) |
| 14956 | * View#sendAccessibilityEvent(int)} for the case of no accessibility delegate |
| 14957 | * been set. |
| 14958 | * </p> |
| 14959 | * |
| 14960 | * @param host The View hosting the delegate. |
| 14961 | * @param eventType The type of the event to send. |
| 14962 | * |
| 14963 | * @see View#sendAccessibilityEvent(int) View#sendAccessibilityEvent(int) |
| 14964 | */ |
| 14965 | public void sendAccessibilityEvent(View host, int eventType) { |
| 14966 | host.sendAccessibilityEventInternal(eventType); |
| 14967 | } |
| 14968 | |
| 14969 | /** |
| 14970 | * Sends an accessibility event. This method behaves exactly as |
| 14971 | * {@link #sendAccessibilityEvent(View, int)} but takes as an argument an |
| 14972 | * empty {@link AccessibilityEvent} and does not perform a check whether |
| 14973 | * accessibility is enabled. |
| 14974 | * <p> |
| 14975 | * The default implementation behaves as |
| 14976 | * {@link View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 14977 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent)} for |
| 14978 | * the case of no accessibility delegate been set. |
| 14979 | * </p> |
| 14980 | * |
| 14981 | * @param host The View hosting the delegate. |
| 14982 | * @param event The event to send. |
| 14983 | * |
| 14984 | * @see View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 14985 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 14986 | */ |
| 14987 | public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) { |
| 14988 | host.sendAccessibilityEventUncheckedInternal(event); |
| 14989 | } |
| 14990 | |
| 14991 | /** |
| 14992 | * Dispatches an {@link AccessibilityEvent} to the host {@link View} first and then |
| 14993 | * to its children for adding their text content to the event. |
| 14994 | * <p> |
| 14995 | * The default implementation behaves as |
| 14996 | * {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 14997 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 14998 | * the case of no accessibility delegate been set. |
| 14999 | * </p> |
| 15000 | * |
| 15001 | * @param host The View hosting the delegate. |
| 15002 | * @param event The event. |
| 15003 | * @return True if the event population was completed. |
| 15004 | * |
| 15005 | * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 15006 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 15007 | */ |
| 15008 | public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 15009 | return host.dispatchPopulateAccessibilityEventInternal(event); |
| 15010 | } |
| 15011 | |
| 15012 | /** |
| 15013 | * Gives a chance to the host View to populate the accessibility event with its |
| 15014 | * text content. |
| 15015 | * <p> |
| 15016 | * The default implementation behaves as |
| 15017 | * {@link View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 15018 | * View#onPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 15019 | * the case of no accessibility delegate been set. |
| 15020 | * </p> |
| 15021 | * |
| 15022 | * @param host The View hosting the delegate. |
| 15023 | * @param event The accessibility event which to populate. |
| 15024 | * |
| 15025 | * @see View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 15026 | * View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 15027 | */ |
| 15028 | public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 15029 | host.onPopulateAccessibilityEventInternal(event); |
| 15030 | } |
| 15031 | |
| 15032 | /** |
| 15033 | * Initializes an {@link AccessibilityEvent} with information about the |
| 15034 | * the host View which is the event source. |
| 15035 | * <p> |
| 15036 | * The default implementation behaves as |
| 15037 | * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 15038 | * View#onInitializeAccessibilityEvent(AccessibilityEvent)} for |
| 15039 | * the case of no accessibility delegate been set. |
| 15040 | * </p> |
| 15041 | * |
| 15042 | * @param host The View hosting the delegate. |
| 15043 | * @param event The event to initialize. |
| 15044 | * |
| 15045 | * @see View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 15046 | * View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 15047 | */ |
| 15048 | public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { |
| 15049 | host.onInitializeAccessibilityEventInternal(event); |
| 15050 | } |
| 15051 | |
| 15052 | /** |
| 15053 | * Initializes an {@link AccessibilityNodeInfo} with information about the host view. |
| 15054 | * <p> |
| 15055 | * The default implementation behaves as |
| 15056 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 15057 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} for |
| 15058 | * the case of no accessibility delegate been set. |
| 15059 | * </p> |
| 15060 | * |
| 15061 | * @param host The View hosting the delegate. |
| 15062 | * @param info The instance to initialize. |
| 15063 | * |
| 15064 | * @see View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 15065 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 15066 | */ |
| 15067 | public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 15068 | host.onInitializeAccessibilityNodeInfoInternal(info); |
| 15069 | } |
| 15070 | |
| 15071 | /** |
| 15072 | * Called when a child of the host View has requested sending an |
| 15073 | * {@link AccessibilityEvent} and gives an opportunity to the parent (the host) |
| 15074 | * to augment the event. |
| 15075 | * <p> |
| 15076 | * The default implementation behaves as |
| 15077 | * {@link ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 15078 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent)} for |
| 15079 | * the case of no accessibility delegate been set. |
| 15080 | * </p> |
| 15081 | * |
| 15082 | * @param host The View hosting the delegate. |
| 15083 | * @param child The child which requests sending the event. |
| 15084 | * @param event The event to be sent. |
| 15085 | * @return True if the event should be sent |
| 15086 | * |
| 15087 | * @see ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 15088 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 15089 | */ |
| 15090 | public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, |
| 15091 | AccessibilityEvent event) { |
| 15092 | return host.onRequestSendAccessibilityEventInternal(child, event); |
| 15093 | } |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 15094 | |
| 15095 | /** |
| 15096 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 15097 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 15098 | * that explore the window content. |
| 15099 | * <p> |
| 15100 | * The default implementation behaves as |
| 15101 | * {@link View#getAccessibilityNodeProvider() View#getAccessibilityNodeProvider()} for |
| 15102 | * the case of no accessibility delegate been set. |
| 15103 | * </p> |
| 15104 | * |
| 15105 | * @return The provider. |
| 15106 | * |
| 15107 | * @see AccessibilityNodeProvider |
| 15108 | */ |
| 15109 | public AccessibilityNodeProvider getAccessibilityNodeProvider(View host) { |
| 15110 | return null; |
| 15111 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 15112 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15113 | } |