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 | /** |
Svetoslav Ganov | 13fd561 | 2012-02-01 17:01:12 -0800 | [diff] [blame] | 3764 | * Called when this view wants to give up focus. If focus is cleared |
| 3765 | * {@link #onFocusChanged(boolean, int, android.graphics.Rect)} is called. |
| 3766 | * <p> |
| 3767 | * <strong>Note:</strong> When a View clears focus the framework is trying |
| 3768 | * to give focus to the first focusable View from the top. Hence, if this |
| 3769 | * View is the first from the top that can take focus, then its focus will |
| 3770 | * not be cleared nor will the focus change callback be invoked. |
| 3771 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3772 | */ |
| 3773 | public void clearFocus() { |
| 3774 | if (DBG) { |
| 3775 | System.out.println(this + " clearFocus()"); |
| 3776 | } |
| 3777 | |
| 3778 | if ((mPrivateFlags & FOCUSED) != 0) { |
Svetoslav Ganov | c6fd88e | 2012-01-25 23:01:44 -0800 | [diff] [blame] | 3779 | // If this is the first focusable do not clear focus since the we |
| 3780 | // try to give it focus every time a view clears its focus. Hence, |
| 3781 | // the view that would gain focus already has it. |
| 3782 | View firstFocusable = getFirstFocusable(); |
| 3783 | if (firstFocusable == this) { |
| 3784 | return; |
| 3785 | } |
| 3786 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3787 | mPrivateFlags &= ~FOCUSED; |
| 3788 | |
| 3789 | if (mParent != null) { |
| 3790 | mParent.clearChildFocus(this); |
| 3791 | } |
| 3792 | |
| 3793 | onFocusChanged(false, 0, null); |
| 3794 | refreshDrawableState(); |
Svetoslav Ganov | c6fd88e | 2012-01-25 23:01:44 -0800 | [diff] [blame] | 3795 | |
| 3796 | // The view cleared focus and invoked the callbacks, so now is the |
| 3797 | // time to give focus to the the first focusable to ensure that the |
| 3798 | // gain focus is announced after clear focus. |
| 3799 | if (firstFocusable != null) { |
| 3800 | firstFocusable.requestFocus(FOCUS_FORWARD); |
| 3801 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3802 | } |
| 3803 | } |
| 3804 | |
Svetoslav Ganov | c6fd88e | 2012-01-25 23:01:44 -0800 | [diff] [blame] | 3805 | private View getFirstFocusable() { |
| 3806 | ViewRootImpl viewRoot = getViewRootImpl(); |
| 3807 | if (viewRoot != null) { |
| 3808 | return viewRoot.focusSearch(null, FOCUS_FORWARD); |
| 3809 | } |
| 3810 | return null; |
| 3811 | } |
| 3812 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3813 | /** |
| 3814 | * Called to clear the focus of a view that is about to be removed. |
| 3815 | * Doesn't call clearChildFocus, which prevents this view from taking |
| 3816 | * focus again before it has been removed from the parent |
| 3817 | */ |
| 3818 | void clearFocusForRemoval() { |
| 3819 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 3820 | mPrivateFlags &= ~FOCUSED; |
| 3821 | |
| 3822 | onFocusChanged(false, 0, null); |
| 3823 | refreshDrawableState(); |
| 3824 | } |
| 3825 | } |
| 3826 | |
| 3827 | /** |
| 3828 | * Called internally by the view system when a new view is getting focus. |
| 3829 | * This is what clears the old focus. |
| 3830 | */ |
| 3831 | void unFocus() { |
| 3832 | if (DBG) { |
| 3833 | System.out.println(this + " unFocus()"); |
| 3834 | } |
| 3835 | |
| 3836 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 3837 | mPrivateFlags &= ~FOCUSED; |
| 3838 | |
| 3839 | onFocusChanged(false, 0, null); |
| 3840 | refreshDrawableState(); |
| 3841 | } |
| 3842 | } |
| 3843 | |
| 3844 | /** |
| 3845 | * Returns true if this view has focus iteself, or is the ancestor of the |
| 3846 | * view that has focus. |
| 3847 | * |
| 3848 | * @return True if this view has or contains focus, false otherwise. |
| 3849 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 3850 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3851 | public boolean hasFocus() { |
| 3852 | return (mPrivateFlags & FOCUSED) != 0; |
| 3853 | } |
| 3854 | |
| 3855 | /** |
| 3856 | * Returns true if this view is focusable or if it contains a reachable View |
| 3857 | * for which {@link #hasFocusable()} returns true. A "reachable hasFocusable()" |
| 3858 | * is a View whose parents do not block descendants focus. |
| 3859 | * |
| 3860 | * Only {@link #VISIBLE} views are considered focusable. |
| 3861 | * |
| 3862 | * @return True if the view is focusable or if the view contains a focusable |
| 3863 | * View, false otherwise. |
| 3864 | * |
| 3865 | * @see ViewGroup#FOCUS_BLOCK_DESCENDANTS |
| 3866 | */ |
| 3867 | public boolean hasFocusable() { |
| 3868 | return (mViewFlags & VISIBILITY_MASK) == VISIBLE && isFocusable(); |
| 3869 | } |
| 3870 | |
| 3871 | /** |
| 3872 | * Called by the view system when the focus state of this view changes. |
| 3873 | * When the focus change event is caused by directional navigation, direction |
| 3874 | * and previouslyFocusedRect provide insight into where the focus is coming from. |
| 3875 | * When overriding, be sure to call up through to the super class so that |
| 3876 | * the standard focus handling will occur. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3877 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3878 | * @param gainFocus True if the View has focus; false otherwise. |
| 3879 | * @param direction The direction focus has moved when requestFocus() |
| 3880 | * is called to give this view focus. Values are |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 3881 | * {@link #FOCUS_UP}, {@link #FOCUS_DOWN}, {@link #FOCUS_LEFT}, |
| 3882 | * {@link #FOCUS_RIGHT}, {@link #FOCUS_FORWARD}, or {@link #FOCUS_BACKWARD}. |
| 3883 | * 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] | 3884 | * @param previouslyFocusedRect The rectangle, in this view's coordinate |
| 3885 | * system, of the previously focused view. If applicable, this will be |
| 3886 | * passed in as finer grained information about where the focus is coming |
| 3887 | * from (in addition to direction). Will be <code>null</code> otherwise. |
| 3888 | */ |
| 3889 | protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3890 | if (gainFocus) { |
| 3891 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 3892 | } |
| 3893 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3894 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 3895 | if (!gainFocus) { |
| 3896 | if (isPressed()) { |
| 3897 | setPressed(false); |
| 3898 | } |
| 3899 | if (imm != null && mAttachInfo != null |
| 3900 | && mAttachInfo.mHasWindowFocus) { |
| 3901 | imm.focusOut(this); |
| 3902 | } |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 3903 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3904 | } else if (imm != null && mAttachInfo != null |
| 3905 | && mAttachInfo.mHasWindowFocus) { |
| 3906 | imm.focusIn(this); |
| 3907 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3908 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 3909 | invalidate(true); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3910 | ListenerInfo li = mListenerInfo; |
| 3911 | if (li != null && li.mOnFocusChangeListener != null) { |
| 3912 | li.mOnFocusChangeListener.onFocusChange(this, gainFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3913 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3914 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 3915 | if (mAttachInfo != null) { |
| 3916 | mAttachInfo.mKeyDispatchState.reset(this); |
| 3917 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3918 | } |
| 3919 | |
| 3920 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3921 | * Sends an accessibility event of the given type. If accessiiblity is |
| 3922 | * not enabled this method has no effect. The default implementation calls |
| 3923 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)} first |
| 3924 | * to populate information about the event source (this View), then calls |
| 3925 | * {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} to |
| 3926 | * populate the text content of the event source including its descendants, |
| 3927 | * and last calls |
| 3928 | * {@link ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)} |
| 3929 | * on its parent to resuest sending of the event to interested parties. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 3930 | * <p> |
| 3931 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 3932 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 3933 | * {@link AccessibilityDelegate#sendAccessibilityEvent(View, int)} is |
| 3934 | * responsible for handling this call. |
| 3935 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3936 | * |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 3937 | * @param eventType The type of the event to send, as defined by several types from |
| 3938 | * {@link android.view.accessibility.AccessibilityEvent}, such as |
| 3939 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_CLICKED} or |
| 3940 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_ENTER}. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3941 | * |
| 3942 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 3943 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 3944 | * @see ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent) |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 3945 | * @see AccessibilityDelegate |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3946 | */ |
| 3947 | public void sendAccessibilityEvent(int eventType) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 3948 | if (mAccessibilityDelegate != null) { |
| 3949 | mAccessibilityDelegate.sendAccessibilityEvent(this, eventType); |
| 3950 | } else { |
| 3951 | sendAccessibilityEventInternal(eventType); |
| 3952 | } |
| 3953 | } |
| 3954 | |
| 3955 | /** |
| 3956 | * @see #sendAccessibilityEvent(int) |
| 3957 | * |
| 3958 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 3959 | */ |
| 3960 | void sendAccessibilityEventInternal(int eventType) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3961 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 3962 | sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType)); |
| 3963 | } |
| 3964 | } |
| 3965 | |
| 3966 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3967 | * This method behaves exactly as {@link #sendAccessibilityEvent(int)} but |
| 3968 | * takes as an argument an empty {@link AccessibilityEvent} and does not |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 3969 | * perform a check whether accessibility is enabled. |
| 3970 | * <p> |
| 3971 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 3972 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 3973 | * {@link AccessibilityDelegate#sendAccessibilityEventUnchecked(View, AccessibilityEvent)} |
| 3974 | * is responsible for handling this call. |
| 3975 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3976 | * |
| 3977 | * @param event The event to send. |
| 3978 | * |
| 3979 | * @see #sendAccessibilityEvent(int) |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3980 | */ |
| 3981 | public void sendAccessibilityEventUnchecked(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 3982 | if (mAccessibilityDelegate != null) { |
| 3983 | mAccessibilityDelegate.sendAccessibilityEventUnchecked(this, event); |
| 3984 | } else { |
| 3985 | sendAccessibilityEventUncheckedInternal(event); |
| 3986 | } |
| 3987 | } |
| 3988 | |
| 3989 | /** |
| 3990 | * @see #sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 3991 | * |
| 3992 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 3993 | */ |
| 3994 | void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 9cd1eca | 2011-01-13 14:24:02 -0800 | [diff] [blame] | 3995 | if (!isShown()) { |
| 3996 | return; |
| 3997 | } |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 3998 | onInitializeAccessibilityEvent(event); |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 3999 | // Only a subset of accessibility events populates text content. |
| 4000 | if ((event.getEventType() & POPULATING_ACCESSIBILITY_EVENT_TYPES) != 0) { |
| 4001 | dispatchPopulateAccessibilityEvent(event); |
| 4002 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4003 | // In the beginning we called #isShown(), so we know that getParent() is not null. |
| 4004 | getParent().requestSendAccessibilityEvent(this, event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4005 | } |
| 4006 | |
| 4007 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4008 | * Dispatches an {@link AccessibilityEvent} to the {@link View} first and then |
| 4009 | * to its children for adding their text content to the event. Note that the |
| 4010 | * event text is populated in a separate dispatch path since we add to the |
| 4011 | * 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] | 4012 | * A typical implementation will call |
| 4013 | * {@link #onPopulateAccessibilityEvent(AccessibilityEvent)} on the this view |
| 4014 | * and then call the {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
| 4015 | * on each child. Override this method if custom population of the event text |
| 4016 | * content is required. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4017 | * <p> |
| 4018 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4019 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4020 | * {@link AccessibilityDelegate#dispatchPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4021 | * is responsible for handling this call. |
| 4022 | * </p> |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4023 | * <p> |
| 4024 | * <em>Note:</em> Accessibility events of certain types are not dispatched for |
| 4025 | * populating the event text via this method. For details refer to {@link AccessibilityEvent}. |
| 4026 | * </p> |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4027 | * |
| 4028 | * @param event The event. |
| 4029 | * |
| 4030 | * @return True if the event population was completed. |
| 4031 | */ |
| 4032 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4033 | if (mAccessibilityDelegate != null) { |
| 4034 | return mAccessibilityDelegate.dispatchPopulateAccessibilityEvent(this, event); |
| 4035 | } else { |
| 4036 | return dispatchPopulateAccessibilityEventInternal(event); |
| 4037 | } |
| 4038 | } |
| 4039 | |
| 4040 | /** |
| 4041 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4042 | * |
| 4043 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4044 | */ |
| 4045 | boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4046 | onPopulateAccessibilityEvent(event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4047 | return false; |
| 4048 | } |
| 4049 | |
| 4050 | /** |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4051 | * Called from {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4052 | * 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] | 4053 | * text content. While this method is free to modify event |
| 4054 | * attributes other than text content, doing so should normally be performed in |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4055 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)}. |
| 4056 | * <p> |
| 4057 | * Example: Adding formatted date string to an accessibility event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4058 | * to the text added by the super implementation: |
| 4059 | * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4060 | * super.onPopulateAccessibilityEvent(event); |
| 4061 | * final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; |
| 4062 | * String selectedDateUtterance = DateUtils.formatDateTime(mContext, |
| 4063 | * mCurrentDate.getTimeInMillis(), flags); |
| 4064 | * event.getText().add(selectedDateUtterance); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4065 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4066 | * <p> |
| 4067 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4068 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4069 | * {@link AccessibilityDelegate#onPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4070 | * is responsible for handling this call. |
| 4071 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4072 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4073 | * information to the event, in case the default implementation has basic information to add. |
| 4074 | * </p> |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4075 | * |
| 4076 | * @param event The accessibility event which to populate. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4077 | * |
| 4078 | * @see #sendAccessibilityEvent(int) |
| 4079 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4080 | */ |
| 4081 | public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4082 | if (mAccessibilityDelegate != null) { |
| 4083 | mAccessibilityDelegate.onPopulateAccessibilityEvent(this, event); |
| 4084 | } else { |
| 4085 | onPopulateAccessibilityEventInternal(event); |
| 4086 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4087 | } |
| 4088 | |
| 4089 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4090 | * @see #onPopulateAccessibilityEvent(AccessibilityEvent) |
| 4091 | * |
| 4092 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4093 | */ |
| 4094 | void onPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
| 4095 | |
| 4096 | } |
| 4097 | |
| 4098 | /** |
| 4099 | * Initializes an {@link AccessibilityEvent} with information about |
| 4100 | * this View which is the event source. In other words, the source of |
| 4101 | * an accessibility event is the view whose state change triggered firing |
| 4102 | * the event. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4103 | * <p> |
| 4104 | * Example: Setting the password property of an event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4105 | * to properties set by the super implementation: |
| 4106 | * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 4107 | * super.onInitializeAccessibilityEvent(event); |
| 4108 | * event.setPassword(true); |
| 4109 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4110 | * <p> |
| 4111 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4112 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4113 | * {@link AccessibilityDelegate#onInitializeAccessibilityEvent(View, AccessibilityEvent)} |
| 4114 | * is responsible for handling this call. |
| 4115 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4116 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4117 | * information to the event, in case the default implementation has basic information to add. |
| 4118 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4119 | * @param event The event to initialize. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4120 | * |
| 4121 | * @see #sendAccessibilityEvent(int) |
| 4122 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4123 | */ |
| 4124 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4125 | if (mAccessibilityDelegate != null) { |
| 4126 | mAccessibilityDelegate.onInitializeAccessibilityEvent(this, event); |
| 4127 | } else { |
| 4128 | onInitializeAccessibilityEventInternal(event); |
| 4129 | } |
| 4130 | } |
| 4131 | |
| 4132 | /** |
| 4133 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4134 | * |
| 4135 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4136 | */ |
| 4137 | void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4138 | event.setSource(this); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 4139 | event.setClassName(View.class.getName()); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4140 | event.setPackageName(getContext().getPackageName()); |
| 4141 | event.setEnabled(isEnabled()); |
| 4142 | event.setContentDescription(mContentDescription); |
| 4143 | |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 4144 | if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && mAttachInfo != null) { |
| 4145 | ArrayList<View> focusablesTempList = mAttachInfo.mFocusablesTempList; |
| 4146 | getRootView().addFocusables(focusablesTempList, View.FOCUS_FORWARD, |
| 4147 | FOCUSABLES_ALL); |
| 4148 | event.setItemCount(focusablesTempList.size()); |
| 4149 | event.setCurrentItemIndex(focusablesTempList.indexOf(this)); |
| 4150 | focusablesTempList.clear(); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4151 | } |
| 4152 | } |
| 4153 | |
| 4154 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4155 | * Returns an {@link AccessibilityNodeInfo} representing this view from the |
| 4156 | * point of view of an {@link android.accessibilityservice.AccessibilityService}. |
| 4157 | * This method is responsible for obtaining an accessibility node info from a |
| 4158 | * pool of reusable instances and calling |
| 4159 | * {@link #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} on this view to |
| 4160 | * initialize the former. |
| 4161 | * <p> |
| 4162 | * Note: The client is responsible for recycling the obtained instance by calling |
| 4163 | * {@link AccessibilityNodeInfo#recycle()} to minimize object creation. |
| 4164 | * </p> |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4165 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4166 | * @return A populated {@link AccessibilityNodeInfo}. |
| 4167 | * |
| 4168 | * @see AccessibilityNodeInfo |
| 4169 | */ |
| 4170 | public AccessibilityNodeInfo createAccessibilityNodeInfo() { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4171 | AccessibilityNodeProvider provider = getAccessibilityNodeProvider(); |
| 4172 | if (provider != null) { |
| 4173 | return provider.createAccessibilityNodeInfo(View.NO_ID); |
| 4174 | } else { |
| 4175 | AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(this); |
| 4176 | onInitializeAccessibilityNodeInfo(info); |
| 4177 | return info; |
| 4178 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | /** |
| 4182 | * Initializes an {@link AccessibilityNodeInfo} with information about this view. |
| 4183 | * The base implementation sets: |
| 4184 | * <ul> |
| 4185 | * <li>{@link AccessibilityNodeInfo#setParent(View)},</li> |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4186 | * <li>{@link AccessibilityNodeInfo#setBoundsInParent(Rect)},</li> |
| 4187 | * <li>{@link AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li> |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4188 | * <li>{@link AccessibilityNodeInfo#setPackageName(CharSequence)},</li> |
| 4189 | * <li>{@link AccessibilityNodeInfo#setClassName(CharSequence)},</li> |
| 4190 | * <li>{@link AccessibilityNodeInfo#setContentDescription(CharSequence)},</li> |
| 4191 | * <li>{@link AccessibilityNodeInfo#setEnabled(boolean)},</li> |
| 4192 | * <li>{@link AccessibilityNodeInfo#setClickable(boolean)},</li> |
| 4193 | * <li>{@link AccessibilityNodeInfo#setFocusable(boolean)},</li> |
| 4194 | * <li>{@link AccessibilityNodeInfo#setFocused(boolean)},</li> |
| 4195 | * <li>{@link AccessibilityNodeInfo#setLongClickable(boolean)},</li> |
| 4196 | * <li>{@link AccessibilityNodeInfo#setSelected(boolean)},</li> |
| 4197 | * </ul> |
| 4198 | * <p> |
| 4199 | * Subclasses should override this method, call the super implementation, |
| 4200 | * and set additional attributes. |
| 4201 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4202 | * <p> |
| 4203 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4204 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4205 | * {@link AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)} |
| 4206 | * is responsible for handling this call. |
| 4207 | * </p> |
| 4208 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4209 | * @param info The instance to initialize. |
| 4210 | */ |
| 4211 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4212 | if (mAccessibilityDelegate != null) { |
| 4213 | mAccessibilityDelegate.onInitializeAccessibilityNodeInfo(this, info); |
| 4214 | } else { |
| 4215 | onInitializeAccessibilityNodeInfoInternal(info); |
| 4216 | } |
| 4217 | } |
| 4218 | |
| 4219 | /** |
| 4220 | * @see #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 4221 | * |
| 4222 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4223 | */ |
| 4224 | void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4225 | Rect bounds = mAttachInfo.mTmpInvalRect; |
| 4226 | getDrawingRect(bounds); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4227 | info.setBoundsInParent(bounds); |
| 4228 | |
| 4229 | int[] locationOnScreen = mAttachInfo.mInvalidateChildLocation; |
| 4230 | getLocationOnScreen(locationOnScreen); |
Alan Viverette | 326804f | 2011-07-22 16:20:41 -0700 | [diff] [blame] | 4231 | bounds.offsetTo(0, 0); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4232 | bounds.offset(locationOnScreen[0], locationOnScreen[1]); |
| 4233 | info.setBoundsInScreen(bounds); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4234 | |
Svetoslav Ganov | 57f3b566db | 2011-10-31 17:59:14 -0700 | [diff] [blame] | 4235 | if ((mPrivateFlags & IS_ROOT_NAMESPACE) == 0) { |
| 4236 | ViewParent parent = getParent(); |
| 4237 | if (parent instanceof View) { |
| 4238 | View parentView = (View) parent; |
| 4239 | info.setParent(parentView); |
| 4240 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4241 | } |
| 4242 | |
| 4243 | info.setPackageName(mContext.getPackageName()); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 4244 | info.setClassName(View.class.getName()); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4245 | info.setContentDescription(getContentDescription()); |
| 4246 | |
| 4247 | info.setEnabled(isEnabled()); |
| 4248 | info.setClickable(isClickable()); |
| 4249 | info.setFocusable(isFocusable()); |
| 4250 | info.setFocused(isFocused()); |
| 4251 | info.setSelected(isSelected()); |
| 4252 | info.setLongClickable(isLongClickable()); |
| 4253 | |
| 4254 | // TODO: These make sense only if we are in an AdapterView but all |
| 4255 | // views can be selected. Maybe from accessiiblity perspective |
| 4256 | // we should report as selectable view in an AdapterView. |
| 4257 | info.addAction(AccessibilityNodeInfo.ACTION_SELECT); |
| 4258 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_SELECTION); |
| 4259 | |
| 4260 | if (isFocusable()) { |
| 4261 | if (isFocused()) { |
| 4262 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS); |
| 4263 | } else { |
| 4264 | info.addAction(AccessibilityNodeInfo.ACTION_FOCUS); |
| 4265 | } |
| 4266 | } |
| 4267 | } |
| 4268 | |
| 4269 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4270 | * Sets a delegate for implementing accessibility support via compositon as |
| 4271 | * opposed to inheritance. The delegate's primary use is for implementing |
| 4272 | * backwards compatible widgets. For more details see {@link AccessibilityDelegate}. |
| 4273 | * |
| 4274 | * @param delegate The delegate instance. |
| 4275 | * |
| 4276 | * @see AccessibilityDelegate |
| 4277 | */ |
| 4278 | public void setAccessibilityDelegate(AccessibilityDelegate delegate) { |
| 4279 | mAccessibilityDelegate = delegate; |
| 4280 | } |
| 4281 | |
| 4282 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4283 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 4284 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 4285 | * that explore the window content. |
| 4286 | * <p> |
| 4287 | * If this method returns an instance, this instance is responsible for managing |
| 4288 | * {@link AccessibilityNodeInfo}s describing the virtual sub-tree rooted at this |
| 4289 | * View including the one representing the View itself. Similarly the returned |
| 4290 | * instance is responsible for performing accessibility actions on any virtual |
| 4291 | * view or the root view itself. |
| 4292 | * </p> |
| 4293 | * <p> |
| 4294 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4295 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4296 | * {@link AccessibilityDelegate#getAccessibilityNodeProvider(View)} |
| 4297 | * is responsible for handling this call. |
| 4298 | * </p> |
| 4299 | * |
| 4300 | * @return The provider. |
| 4301 | * |
| 4302 | * @see AccessibilityNodeProvider |
| 4303 | */ |
| 4304 | public AccessibilityNodeProvider getAccessibilityNodeProvider() { |
| 4305 | if (mAccessibilityDelegate != null) { |
| 4306 | return mAccessibilityDelegate.getAccessibilityNodeProvider(this); |
| 4307 | } else { |
| 4308 | return null; |
| 4309 | } |
| 4310 | } |
| 4311 | |
| 4312 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4313 | * Gets the unique identifier of this view on the screen for accessibility purposes. |
| 4314 | * If this {@link View} is not attached to any window, {@value #NO_ID} is returned. |
| 4315 | * |
| 4316 | * @return The view accessibility id. |
| 4317 | * |
| 4318 | * @hide |
| 4319 | */ |
| 4320 | public int getAccessibilityViewId() { |
| 4321 | if (mAccessibilityViewId == NO_ID) { |
| 4322 | mAccessibilityViewId = sNextAccessibilityViewId++; |
| 4323 | } |
| 4324 | return mAccessibilityViewId; |
| 4325 | } |
| 4326 | |
| 4327 | /** |
| 4328 | * Gets the unique identifier of the window in which this View reseides. |
| 4329 | * |
| 4330 | * @return The window accessibility id. |
| 4331 | * |
| 4332 | * @hide |
| 4333 | */ |
| 4334 | public int getAccessibilityWindowId() { |
| 4335 | return mAttachInfo != null ? mAttachInfo.mAccessibilityWindowId : NO_ID; |
| 4336 | } |
| 4337 | |
| 4338 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4339 | * Gets the {@link View} description. It briefly describes the view and is |
| 4340 | * primarily used for accessibility support. Set this property to enable |
| 4341 | * better accessibility support for your application. This is especially |
| 4342 | * true for views that do not have textual representation (For example, |
| 4343 | * ImageButton). |
| 4344 | * |
| 4345 | * @return The content descriptiopn. |
| 4346 | * |
| 4347 | * @attr ref android.R.styleable#View_contentDescription |
| 4348 | */ |
| 4349 | public CharSequence getContentDescription() { |
| 4350 | return mContentDescription; |
| 4351 | } |
| 4352 | |
| 4353 | /** |
| 4354 | * Sets the {@link View} description. It briefly describes the view and is |
| 4355 | * primarily used for accessibility support. Set this property to enable |
| 4356 | * better accessibility support for your application. This is especially |
| 4357 | * true for views that do not have textual representation (For example, |
| 4358 | * ImageButton). |
| 4359 | * |
| 4360 | * @param contentDescription The content description. |
| 4361 | * |
| 4362 | * @attr ref android.R.styleable#View_contentDescription |
| 4363 | */ |
Svetoslav Ganov | e261e28 | 2011-10-18 17:47:04 -0700 | [diff] [blame] | 4364 | @RemotableViewMethod |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4365 | public void setContentDescription(CharSequence contentDescription) { |
| 4366 | mContentDescription = contentDescription; |
| 4367 | } |
| 4368 | |
| 4369 | /** |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4370 | * Invoked whenever this view loses focus, either by losing window focus or by losing |
| 4371 | * focus within its window. This method can be used to clear any state tied to the |
| 4372 | * focus. For instance, if a button is held pressed with the trackball and the window |
| 4373 | * loses focus, this method can be used to cancel the press. |
| 4374 | * |
| 4375 | * Subclasses of View overriding this method should always call super.onFocusLost(). |
| 4376 | * |
| 4377 | * @see #onFocusChanged(boolean, int, android.graphics.Rect) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4378 | * @see #onWindowFocusChanged(boolean) |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4379 | * |
| 4380 | * @hide pending API council approval |
| 4381 | */ |
| 4382 | protected void onFocusLost() { |
| 4383 | resetPressedState(); |
| 4384 | } |
| 4385 | |
| 4386 | private void resetPressedState() { |
| 4387 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 4388 | return; |
| 4389 | } |
| 4390 | |
| 4391 | if (isPressed()) { |
| 4392 | setPressed(false); |
| 4393 | |
| 4394 | if (!mHasPerformedLongPress) { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 4395 | removeLongPressCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4396 | } |
| 4397 | } |
| 4398 | } |
| 4399 | |
| 4400 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4401 | * Returns true if this view has focus |
| 4402 | * |
| 4403 | * @return True if this view has focus, false otherwise. |
| 4404 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4405 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4406 | public boolean isFocused() { |
| 4407 | return (mPrivateFlags & FOCUSED) != 0; |
| 4408 | } |
| 4409 | |
| 4410 | /** |
| 4411 | * Find the view in the hierarchy rooted at this view that currently has |
| 4412 | * focus. |
| 4413 | * |
| 4414 | * @return The view that currently has focus, or null if no focused view can |
| 4415 | * be found. |
| 4416 | */ |
| 4417 | public View findFocus() { |
| 4418 | return (mPrivateFlags & FOCUSED) != 0 ? this : null; |
| 4419 | } |
| 4420 | |
| 4421 | /** |
| 4422 | * Change whether this view is one of the set of scrollable containers in |
| 4423 | * its window. This will be used to determine whether the window can |
| 4424 | * resize or must pan when a soft input area is open -- scrollable |
| 4425 | * containers allow the window to use resize mode since the container |
| 4426 | * will appropriately shrink. |
| 4427 | */ |
| 4428 | public void setScrollContainer(boolean isScrollContainer) { |
| 4429 | if (isScrollContainer) { |
| 4430 | if (mAttachInfo != null && (mPrivateFlags&SCROLL_CONTAINER_ADDED) == 0) { |
| 4431 | mAttachInfo.mScrollContainers.add(this); |
| 4432 | mPrivateFlags |= SCROLL_CONTAINER_ADDED; |
| 4433 | } |
| 4434 | mPrivateFlags |= SCROLL_CONTAINER; |
| 4435 | } else { |
| 4436 | if ((mPrivateFlags&SCROLL_CONTAINER_ADDED) != 0) { |
| 4437 | mAttachInfo.mScrollContainers.remove(this); |
| 4438 | } |
| 4439 | mPrivateFlags &= ~(SCROLL_CONTAINER|SCROLL_CONTAINER_ADDED); |
| 4440 | } |
| 4441 | } |
| 4442 | |
| 4443 | /** |
| 4444 | * Returns the quality of the drawing cache. |
| 4445 | * |
| 4446 | * @return One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 4447 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 4448 | * |
| 4449 | * @see #setDrawingCacheQuality(int) |
| 4450 | * @see #setDrawingCacheEnabled(boolean) |
| 4451 | * @see #isDrawingCacheEnabled() |
| 4452 | * |
| 4453 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 4454 | */ |
| 4455 | public int getDrawingCacheQuality() { |
| 4456 | return mViewFlags & DRAWING_CACHE_QUALITY_MASK; |
| 4457 | } |
| 4458 | |
| 4459 | /** |
| 4460 | * Set the drawing cache quality of this view. This value is used only when the |
| 4461 | * drawing cache is enabled |
| 4462 | * |
| 4463 | * @param quality One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 4464 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 4465 | * |
| 4466 | * @see #getDrawingCacheQuality() |
| 4467 | * @see #setDrawingCacheEnabled(boolean) |
| 4468 | * @see #isDrawingCacheEnabled() |
| 4469 | * |
| 4470 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 4471 | */ |
| 4472 | public void setDrawingCacheQuality(int quality) { |
| 4473 | setFlags(quality, DRAWING_CACHE_QUALITY_MASK); |
| 4474 | } |
| 4475 | |
| 4476 | /** |
| 4477 | * Returns whether the screen should remain on, corresponding to the current |
| 4478 | * value of {@link #KEEP_SCREEN_ON}. |
| 4479 | * |
| 4480 | * @return Returns true if {@link #KEEP_SCREEN_ON} is set. |
| 4481 | * |
| 4482 | * @see #setKeepScreenOn(boolean) |
| 4483 | * |
| 4484 | * @attr ref android.R.styleable#View_keepScreenOn |
| 4485 | */ |
| 4486 | public boolean getKeepScreenOn() { |
| 4487 | return (mViewFlags & KEEP_SCREEN_ON) != 0; |
| 4488 | } |
| 4489 | |
| 4490 | /** |
| 4491 | * Controls whether the screen should remain on, modifying the |
| 4492 | * value of {@link #KEEP_SCREEN_ON}. |
| 4493 | * |
| 4494 | * @param keepScreenOn Supply true to set {@link #KEEP_SCREEN_ON}. |
| 4495 | * |
| 4496 | * @see #getKeepScreenOn() |
| 4497 | * |
| 4498 | * @attr ref android.R.styleable#View_keepScreenOn |
| 4499 | */ |
| 4500 | public void setKeepScreenOn(boolean keepScreenOn) { |
| 4501 | setFlags(keepScreenOn ? KEEP_SCREEN_ON : 0, KEEP_SCREEN_ON); |
| 4502 | } |
| 4503 | |
| 4504 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4505 | * Gets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 4506 | * @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] | 4507 | * |
| 4508 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 4509 | */ |
| 4510 | public int getNextFocusLeftId() { |
| 4511 | return mNextFocusLeftId; |
| 4512 | } |
| 4513 | |
| 4514 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4515 | * Sets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 4516 | * @param nextFocusLeftId The next focus ID, or {@link #NO_ID} if the framework should |
| 4517 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4518 | * |
| 4519 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 4520 | */ |
| 4521 | public void setNextFocusLeftId(int nextFocusLeftId) { |
| 4522 | mNextFocusLeftId = nextFocusLeftId; |
| 4523 | } |
| 4524 | |
| 4525 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4526 | * Gets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 4527 | * @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] | 4528 | * |
| 4529 | * @attr ref android.R.styleable#View_nextFocusRight |
| 4530 | */ |
| 4531 | public int getNextFocusRightId() { |
| 4532 | return mNextFocusRightId; |
| 4533 | } |
| 4534 | |
| 4535 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4536 | * Sets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 4537 | * @param nextFocusRightId The next focus ID, or {@link #NO_ID} if the framework should |
| 4538 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4539 | * |
| 4540 | * @attr ref android.R.styleable#View_nextFocusRight |
| 4541 | */ |
| 4542 | public void setNextFocusRightId(int nextFocusRightId) { |
| 4543 | mNextFocusRightId = nextFocusRightId; |
| 4544 | } |
| 4545 | |
| 4546 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4547 | * Gets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 4548 | * @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] | 4549 | * |
| 4550 | * @attr ref android.R.styleable#View_nextFocusUp |
| 4551 | */ |
| 4552 | public int getNextFocusUpId() { |
| 4553 | return mNextFocusUpId; |
| 4554 | } |
| 4555 | |
| 4556 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4557 | * Sets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 4558 | * @param nextFocusUpId The next focus ID, or {@link #NO_ID} if the framework should |
| 4559 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4560 | * |
| 4561 | * @attr ref android.R.styleable#View_nextFocusUp |
| 4562 | */ |
| 4563 | public void setNextFocusUpId(int nextFocusUpId) { |
| 4564 | mNextFocusUpId = nextFocusUpId; |
| 4565 | } |
| 4566 | |
| 4567 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4568 | * Gets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 4569 | * @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] | 4570 | * |
| 4571 | * @attr ref android.R.styleable#View_nextFocusDown |
| 4572 | */ |
| 4573 | public int getNextFocusDownId() { |
| 4574 | return mNextFocusDownId; |
| 4575 | } |
| 4576 | |
| 4577 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4578 | * Sets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 4579 | * @param nextFocusDownId The next focus ID, or {@link #NO_ID} if the framework should |
| 4580 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4581 | * |
| 4582 | * @attr ref android.R.styleable#View_nextFocusDown |
| 4583 | */ |
| 4584 | public void setNextFocusDownId(int nextFocusDownId) { |
| 4585 | mNextFocusDownId = nextFocusDownId; |
| 4586 | } |
| 4587 | |
| 4588 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4589 | * Gets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 4590 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
| 4591 | * |
| 4592 | * @attr ref android.R.styleable#View_nextFocusForward |
| 4593 | */ |
| 4594 | public int getNextFocusForwardId() { |
| 4595 | return mNextFocusForwardId; |
| 4596 | } |
| 4597 | |
| 4598 | /** |
| 4599 | * Sets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 4600 | * @param nextFocusForwardId The next focus ID, or {@link #NO_ID} if the framework should |
| 4601 | * decide automatically. |
| 4602 | * |
| 4603 | * @attr ref android.R.styleable#View_nextFocusForward |
| 4604 | */ |
| 4605 | public void setNextFocusForwardId(int nextFocusForwardId) { |
| 4606 | mNextFocusForwardId = nextFocusForwardId; |
| 4607 | } |
| 4608 | |
| 4609 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4610 | * Returns the visibility of this view and all of its ancestors |
| 4611 | * |
| 4612 | * @return True if this view and all of its ancestors are {@link #VISIBLE} |
| 4613 | */ |
| 4614 | public boolean isShown() { |
| 4615 | View current = this; |
| 4616 | //noinspection ConstantConditions |
| 4617 | do { |
| 4618 | if ((current.mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 4619 | return false; |
| 4620 | } |
| 4621 | ViewParent parent = current.mParent; |
| 4622 | if (parent == null) { |
| 4623 | return false; // We are not attached to the view root |
| 4624 | } |
| 4625 | if (!(parent instanceof View)) { |
| 4626 | return true; |
| 4627 | } |
| 4628 | current = (View) parent; |
| 4629 | } while (current != null); |
| 4630 | |
| 4631 | return false; |
| 4632 | } |
| 4633 | |
| 4634 | /** |
| 4635 | * Apply the insets for system windows to this view, if the FITS_SYSTEM_WINDOWS flag |
| 4636 | * is set |
| 4637 | * |
| 4638 | * @param insets Insets for system windows |
| 4639 | * |
| 4640 | * @return True if this view applied the insets, false otherwise |
| 4641 | */ |
| 4642 | protected boolean fitSystemWindows(Rect insets) { |
| 4643 | if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) { |
| 4644 | mPaddingLeft = insets.left; |
| 4645 | mPaddingTop = insets.top; |
| 4646 | mPaddingRight = insets.right; |
| 4647 | mPaddingBottom = insets.bottom; |
| 4648 | requestLayout(); |
| 4649 | return true; |
| 4650 | } |
| 4651 | return false; |
| 4652 | } |
| 4653 | |
| 4654 | /** |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 4655 | * Set whether or not this view should account for system screen decorations |
| 4656 | * such as the status bar and inset its content. This allows this view to be |
| 4657 | * positioned in absolute screen coordinates and remain visible to the user. |
| 4658 | * |
| 4659 | * <p>This should only be used by top-level window decor views. |
| 4660 | * |
| 4661 | * @param fitSystemWindows true to inset content for system screen decorations, false for |
| 4662 | * default behavior. |
| 4663 | * |
| 4664 | * @attr ref android.R.styleable#View_fitsSystemWindows |
| 4665 | */ |
| 4666 | public void setFitsSystemWindows(boolean fitSystemWindows) { |
| 4667 | setFlags(fitSystemWindows ? FITS_SYSTEM_WINDOWS : 0, FITS_SYSTEM_WINDOWS); |
| 4668 | } |
| 4669 | |
| 4670 | /** |
| 4671 | * Check for the FITS_SYSTEM_WINDOWS flag. If this method returns true, this view |
| 4672 | * will account for system screen decorations such as the status bar and inset its |
| 4673 | * content. This allows the view to be positioned in absolute screen coordinates |
| 4674 | * and remain visible to the user. |
| 4675 | * |
| 4676 | * @return true if this view will adjust its content bounds for system screen decorations. |
| 4677 | * |
| 4678 | * @attr ref android.R.styleable#View_fitsSystemWindows |
| 4679 | */ |
| 4680 | public boolean fitsSystemWindows() { |
| 4681 | return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS; |
| 4682 | } |
| 4683 | |
| 4684 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4685 | * Returns the visibility status for this view. |
| 4686 | * |
| 4687 | * @return One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 4688 | * @attr ref android.R.styleable#View_visibility |
| 4689 | */ |
| 4690 | @ViewDebug.ExportedProperty(mapping = { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 4691 | @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), |
| 4692 | @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), |
| 4693 | @ViewDebug.IntToString(from = GONE, to = "GONE") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4694 | }) |
| 4695 | public int getVisibility() { |
| 4696 | return mViewFlags & VISIBILITY_MASK; |
| 4697 | } |
| 4698 | |
| 4699 | /** |
| 4700 | * Set the enabled state of this view. |
| 4701 | * |
| 4702 | * @param visibility One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 4703 | * @attr ref android.R.styleable#View_visibility |
| 4704 | */ |
| 4705 | @RemotableViewMethod |
| 4706 | public void setVisibility(int visibility) { |
| 4707 | setFlags(visibility, VISIBILITY_MASK); |
| 4708 | if (mBGDrawable != null) mBGDrawable.setVisible(visibility == VISIBLE, false); |
| 4709 | } |
| 4710 | |
| 4711 | /** |
| 4712 | * Returns the enabled status for this view. The interpretation of the |
| 4713 | * enabled state varies by subclass. |
| 4714 | * |
| 4715 | * @return True if this view is enabled, false otherwise. |
| 4716 | */ |
| 4717 | @ViewDebug.ExportedProperty |
| 4718 | public boolean isEnabled() { |
| 4719 | return (mViewFlags & ENABLED_MASK) == ENABLED; |
| 4720 | } |
| 4721 | |
| 4722 | /** |
| 4723 | * Set the enabled state of this view. The interpretation of the enabled |
| 4724 | * state varies by subclass. |
| 4725 | * |
| 4726 | * @param enabled True if this view is enabled, false otherwise. |
| 4727 | */ |
Jeff Sharkey | 2b95c24 | 2010-02-08 17:40:30 -0800 | [diff] [blame] | 4728 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4729 | public void setEnabled(boolean enabled) { |
Amith Yamasani | a2ef00b | 2009-07-30 16:14:34 -0700 | [diff] [blame] | 4730 | if (enabled == isEnabled()) return; |
| 4731 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4732 | setFlags(enabled ? ENABLED : DISABLED, ENABLED_MASK); |
| 4733 | |
| 4734 | /* |
| 4735 | * The View most likely has to change its appearance, so refresh |
| 4736 | * the drawable state. |
| 4737 | */ |
| 4738 | refreshDrawableState(); |
| 4739 | |
| 4740 | // Invalidate too, since the default behavior for views is to be |
| 4741 | // be drawn at 50% alpha rather than to change the drawable. |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 4742 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4743 | } |
| 4744 | |
| 4745 | /** |
| 4746 | * Set whether this view can receive the focus. |
| 4747 | * |
| 4748 | * Setting this to false will also ensure that this view is not focusable |
| 4749 | * in touch mode. |
| 4750 | * |
| 4751 | * @param focusable If true, this view can receive the focus. |
| 4752 | * |
| 4753 | * @see #setFocusableInTouchMode(boolean) |
| 4754 | * @attr ref android.R.styleable#View_focusable |
| 4755 | */ |
| 4756 | public void setFocusable(boolean focusable) { |
| 4757 | if (!focusable) { |
| 4758 | setFlags(0, FOCUSABLE_IN_TOUCH_MODE); |
| 4759 | } |
| 4760 | setFlags(focusable ? FOCUSABLE : NOT_FOCUSABLE, FOCUSABLE_MASK); |
| 4761 | } |
| 4762 | |
| 4763 | /** |
| 4764 | * Set whether this view can receive focus while in touch mode. |
| 4765 | * |
| 4766 | * Setting this to true will also ensure that this view is focusable. |
| 4767 | * |
| 4768 | * @param focusableInTouchMode If true, this view can receive the focus while |
| 4769 | * in touch mode. |
| 4770 | * |
| 4771 | * @see #setFocusable(boolean) |
| 4772 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 4773 | */ |
| 4774 | public void setFocusableInTouchMode(boolean focusableInTouchMode) { |
| 4775 | // Focusable in touch mode should always be set before the focusable flag |
| 4776 | // otherwise, setting the focusable flag will trigger a focusableViewAvailable() |
| 4777 | // which, in touch mode, will not successfully request focus on this view |
| 4778 | // because the focusable in touch mode flag is not set |
| 4779 | setFlags(focusableInTouchMode ? FOCUSABLE_IN_TOUCH_MODE : 0, FOCUSABLE_IN_TOUCH_MODE); |
| 4780 | if (focusableInTouchMode) { |
| 4781 | setFlags(FOCUSABLE, FOCUSABLE_MASK); |
| 4782 | } |
| 4783 | } |
| 4784 | |
| 4785 | /** |
| 4786 | * Set whether this view should have sound effects enabled for events such as |
| 4787 | * clicking and touching. |
| 4788 | * |
| 4789 | * <p>You may wish to disable sound effects for a view if you already play sounds, |
| 4790 | * for instance, a dial key that plays dtmf tones. |
| 4791 | * |
| 4792 | * @param soundEffectsEnabled whether sound effects are enabled for this view. |
| 4793 | * @see #isSoundEffectsEnabled() |
| 4794 | * @see #playSoundEffect(int) |
| 4795 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 4796 | */ |
| 4797 | public void setSoundEffectsEnabled(boolean soundEffectsEnabled) { |
| 4798 | setFlags(soundEffectsEnabled ? SOUND_EFFECTS_ENABLED: 0, SOUND_EFFECTS_ENABLED); |
| 4799 | } |
| 4800 | |
| 4801 | /** |
| 4802 | * @return whether this view should have sound effects enabled for events such as |
| 4803 | * clicking and touching. |
| 4804 | * |
| 4805 | * @see #setSoundEffectsEnabled(boolean) |
| 4806 | * @see #playSoundEffect(int) |
| 4807 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 4808 | */ |
| 4809 | @ViewDebug.ExportedProperty |
| 4810 | public boolean isSoundEffectsEnabled() { |
| 4811 | return SOUND_EFFECTS_ENABLED == (mViewFlags & SOUND_EFFECTS_ENABLED); |
| 4812 | } |
| 4813 | |
| 4814 | /** |
| 4815 | * Set whether this view should have haptic feedback for events such as |
| 4816 | * long presses. |
| 4817 | * |
| 4818 | * <p>You may wish to disable haptic feedback if your view already controls |
| 4819 | * its own haptic feedback. |
| 4820 | * |
| 4821 | * @param hapticFeedbackEnabled whether haptic feedback enabled for this view. |
| 4822 | * @see #isHapticFeedbackEnabled() |
| 4823 | * @see #performHapticFeedback(int) |
| 4824 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 4825 | */ |
| 4826 | public void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled) { |
| 4827 | setFlags(hapticFeedbackEnabled ? HAPTIC_FEEDBACK_ENABLED: 0, HAPTIC_FEEDBACK_ENABLED); |
| 4828 | } |
| 4829 | |
| 4830 | /** |
| 4831 | * @return whether this view should have haptic feedback enabled for events |
| 4832 | * long presses. |
| 4833 | * |
| 4834 | * @see #setHapticFeedbackEnabled(boolean) |
| 4835 | * @see #performHapticFeedback(int) |
| 4836 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 4837 | */ |
| 4838 | @ViewDebug.ExportedProperty |
| 4839 | public boolean isHapticFeedbackEnabled() { |
| 4840 | return HAPTIC_FEEDBACK_ENABLED == (mViewFlags & HAPTIC_FEEDBACK_ENABLED); |
| 4841 | } |
| 4842 | |
| 4843 | /** |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4844 | * Returns the layout direction for this view. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4845 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4846 | * @return One of {@link #LAYOUT_DIRECTION_LTR}, |
| 4847 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 4848 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 4849 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
| 4850 | * @attr ref android.R.styleable#View_layoutDirection |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 4851 | * |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4852 | * @hide |
| 4853 | */ |
Fabrice Di Meglio | bce84d2 | 2011-06-02 15:57:01 -0700 | [diff] [blame] | 4854 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4855 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "LTR"), |
| 4856 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RTL"), |
| 4857 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"), |
| 4858 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE, to = "LOCALE") |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4859 | }) |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4860 | public int getLayoutDirection() { |
| 4861 | return mViewFlags & LAYOUT_DIRECTION_MASK; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4862 | } |
| 4863 | |
| 4864 | /** |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 4865 | * Set the layout direction for this view. This will propagate a reset of layout direction |
| 4866 | * 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] | 4867 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4868 | * @param layoutDirection One of {@link #LAYOUT_DIRECTION_LTR}, |
| 4869 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 4870 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 4871 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 4872 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4873 | * @attr ref android.R.styleable#View_layoutDirection |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 4874 | * |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4875 | * @hide |
| 4876 | */ |
| 4877 | @RemotableViewMethod |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 4878 | public void setLayoutDirection(int layoutDirection) { |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 4879 | if (getLayoutDirection() != layoutDirection) { |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 4880 | resetResolvedLayoutDirection(); |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 4881 | // Setting the flag will also request a layout. |
| 4882 | setFlags(layoutDirection, LAYOUT_DIRECTION_MASK); |
| 4883 | } |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 4884 | } |
| 4885 | |
| 4886 | /** |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 4887 | * Returns the resolved layout direction for this view. |
| 4888 | * |
| 4889 | * @return {@link #LAYOUT_DIRECTION_RTL} if the layout direction is RTL or returns |
| 4890 | * {@link #LAYOUT_DIRECTION_LTR} id the layout direction is not RTL. |
| 4891 | * |
| 4892 | * @hide |
| 4893 | */ |
| 4894 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
| 4895 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"), |
| 4896 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL") |
| 4897 | }) |
| 4898 | public int getResolvedLayoutDirection() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 4899 | resolveLayoutDirectionIfNeeded(); |
| 4900 | return ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED_RTL) == LAYOUT_DIRECTION_RESOLVED_RTL) ? |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 4901 | LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR; |
| 4902 | } |
| 4903 | |
| 4904 | /** |
| 4905 | * <p>Indicates whether or not this view's layout is right-to-left. This is resolved from |
| 4906 | * layout attribute and/or the inherited value from the parent.</p> |
| 4907 | * |
| 4908 | * @return true if the layout is right-to-left. |
| 4909 | * |
| 4910 | * @hide |
| 4911 | */ |
| 4912 | @ViewDebug.ExportedProperty(category = "layout") |
| 4913 | public boolean isLayoutRtl() { |
| 4914 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL); |
| 4915 | } |
| 4916 | |
| 4917 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4918 | * If this view doesn't do any drawing on its own, set this flag to |
| 4919 | * allow further optimizations. By default, this flag is not set on |
| 4920 | * View, but could be set on some View subclasses such as ViewGroup. |
| 4921 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 4922 | * Typically, if you override {@link #onDraw(android.graphics.Canvas)} |
| 4923 | * you should clear this flag. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4924 | * |
| 4925 | * @param willNotDraw whether or not this View draw on its own |
| 4926 | */ |
| 4927 | public void setWillNotDraw(boolean willNotDraw) { |
| 4928 | setFlags(willNotDraw ? WILL_NOT_DRAW : 0, DRAW_MASK); |
| 4929 | } |
| 4930 | |
| 4931 | /** |
| 4932 | * Returns whether or not this View draws on its own. |
| 4933 | * |
| 4934 | * @return true if this view has nothing to draw, false otherwise |
| 4935 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4936 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4937 | public boolean willNotDraw() { |
| 4938 | return (mViewFlags & DRAW_MASK) == WILL_NOT_DRAW; |
| 4939 | } |
| 4940 | |
| 4941 | /** |
| 4942 | * When a View's drawing cache is enabled, drawing is redirected to an |
| 4943 | * offscreen bitmap. Some views, like an ImageView, must be able to |
| 4944 | * bypass this mechanism if they already draw a single bitmap, to avoid |
| 4945 | * unnecessary usage of the memory. |
| 4946 | * |
| 4947 | * @param willNotCacheDrawing true if this view does not cache its |
| 4948 | * drawing, false otherwise |
| 4949 | */ |
| 4950 | public void setWillNotCacheDrawing(boolean willNotCacheDrawing) { |
| 4951 | setFlags(willNotCacheDrawing ? WILL_NOT_CACHE_DRAWING : 0, WILL_NOT_CACHE_DRAWING); |
| 4952 | } |
| 4953 | |
| 4954 | /** |
| 4955 | * Returns whether or not this View can cache its drawing or not. |
| 4956 | * |
| 4957 | * @return true if this view does not cache its drawing, false otherwise |
| 4958 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4959 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4960 | public boolean willNotCacheDrawing() { |
| 4961 | return (mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING; |
| 4962 | } |
| 4963 | |
| 4964 | /** |
| 4965 | * Indicates whether this view reacts to click events or not. |
| 4966 | * |
| 4967 | * @return true if the view is clickable, false otherwise |
| 4968 | * |
| 4969 | * @see #setClickable(boolean) |
| 4970 | * @attr ref android.R.styleable#View_clickable |
| 4971 | */ |
| 4972 | @ViewDebug.ExportedProperty |
| 4973 | public boolean isClickable() { |
| 4974 | return (mViewFlags & CLICKABLE) == CLICKABLE; |
| 4975 | } |
| 4976 | |
| 4977 | /** |
| 4978 | * Enables or disables click events for this view. When a view |
| 4979 | * is clickable it will change its state to "pressed" on every click. |
| 4980 | * Subclasses should set the view clickable to visually react to |
| 4981 | * user's clicks. |
| 4982 | * |
| 4983 | * @param clickable true to make the view clickable, false otherwise |
| 4984 | * |
| 4985 | * @see #isClickable() |
| 4986 | * @attr ref android.R.styleable#View_clickable |
| 4987 | */ |
| 4988 | public void setClickable(boolean clickable) { |
| 4989 | setFlags(clickable ? CLICKABLE : 0, CLICKABLE); |
| 4990 | } |
| 4991 | |
| 4992 | /** |
| 4993 | * Indicates whether this view reacts to long click events or not. |
| 4994 | * |
| 4995 | * @return true if the view is long clickable, false otherwise |
| 4996 | * |
| 4997 | * @see #setLongClickable(boolean) |
| 4998 | * @attr ref android.R.styleable#View_longClickable |
| 4999 | */ |
| 5000 | public boolean isLongClickable() { |
| 5001 | return (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 5002 | } |
| 5003 | |
| 5004 | /** |
| 5005 | * Enables or disables long click events for this view. When a view is long |
| 5006 | * clickable it reacts to the user holding down the button for a longer |
| 5007 | * duration than a tap. This event can either launch the listener or a |
| 5008 | * context menu. |
| 5009 | * |
| 5010 | * @param longClickable true to make the view long clickable, false otherwise |
| 5011 | * @see #isLongClickable() |
| 5012 | * @attr ref android.R.styleable#View_longClickable |
| 5013 | */ |
| 5014 | public void setLongClickable(boolean longClickable) { |
| 5015 | setFlags(longClickable ? LONG_CLICKABLE : 0, LONG_CLICKABLE); |
| 5016 | } |
| 5017 | |
| 5018 | /** |
Chet Haase | 49afa5b | 2010-08-23 11:39:53 -0700 | [diff] [blame] | 5019 | * Sets the pressed state for this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5020 | * |
| 5021 | * @see #isClickable() |
| 5022 | * @see #setClickable(boolean) |
| 5023 | * |
| 5024 | * @param pressed Pass true to set the View's internal state to "pressed", or false to reverts |
| 5025 | * the View's internal state from a previously set "pressed" state. |
| 5026 | */ |
| 5027 | public void setPressed(boolean pressed) { |
| 5028 | if (pressed) { |
| 5029 | mPrivateFlags |= PRESSED; |
| 5030 | } else { |
| 5031 | mPrivateFlags &= ~PRESSED; |
| 5032 | } |
| 5033 | refreshDrawableState(); |
| 5034 | dispatchSetPressed(pressed); |
| 5035 | } |
| 5036 | |
| 5037 | /** |
| 5038 | * Dispatch setPressed to all of this View's children. |
| 5039 | * |
| 5040 | * @see #setPressed(boolean) |
| 5041 | * |
| 5042 | * @param pressed The new pressed state |
| 5043 | */ |
| 5044 | protected void dispatchSetPressed(boolean pressed) { |
| 5045 | } |
| 5046 | |
| 5047 | /** |
| 5048 | * Indicates whether the view is currently in pressed state. Unless |
| 5049 | * {@link #setPressed(boolean)} is explicitly called, only clickable views can enter |
| 5050 | * the pressed state. |
| 5051 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5052 | * @see #setPressed(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5053 | * @see #isClickable() |
| 5054 | * @see #setClickable(boolean) |
| 5055 | * |
| 5056 | * @return true if the view is currently pressed, false otherwise |
| 5057 | */ |
| 5058 | public boolean isPressed() { |
| 5059 | return (mPrivateFlags & PRESSED) == PRESSED; |
| 5060 | } |
| 5061 | |
| 5062 | /** |
| 5063 | * Indicates whether this view will save its state (that is, |
| 5064 | * whether its {@link #onSaveInstanceState} method will be called). |
| 5065 | * |
| 5066 | * @return Returns true if the view state saving is enabled, else false. |
| 5067 | * |
| 5068 | * @see #setSaveEnabled(boolean) |
| 5069 | * @attr ref android.R.styleable#View_saveEnabled |
| 5070 | */ |
| 5071 | public boolean isSaveEnabled() { |
| 5072 | return (mViewFlags & SAVE_DISABLED_MASK) != SAVE_DISABLED; |
| 5073 | } |
| 5074 | |
| 5075 | /** |
| 5076 | * Controls whether the saving of this view's state is |
| 5077 | * enabled (that is, whether its {@link #onSaveInstanceState} method |
| 5078 | * will be called). Note that even if freezing is enabled, the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5079 | * 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] | 5080 | * for its state to be saved. This flag can only disable the |
| 5081 | * saving of this view; any child views may still have their state saved. |
| 5082 | * |
| 5083 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 5084 | * (the default) to allow it. |
| 5085 | * |
| 5086 | * @see #isSaveEnabled() |
| 5087 | * @see #setId(int) |
| 5088 | * @see #onSaveInstanceState() |
| 5089 | * @attr ref android.R.styleable#View_saveEnabled |
| 5090 | */ |
| 5091 | public void setSaveEnabled(boolean enabled) { |
| 5092 | setFlags(enabled ? 0 : SAVE_DISABLED, SAVE_DISABLED_MASK); |
| 5093 | } |
| 5094 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5095 | /** |
| 5096 | * Gets whether the framework should discard touches when the view's |
| 5097 | * window is obscured by another visible window. |
| 5098 | * Refer to the {@link View} security documentation for more details. |
| 5099 | * |
| 5100 | * @return True if touch filtering is enabled. |
| 5101 | * |
| 5102 | * @see #setFilterTouchesWhenObscured(boolean) |
| 5103 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 5104 | */ |
| 5105 | @ViewDebug.ExportedProperty |
| 5106 | public boolean getFilterTouchesWhenObscured() { |
| 5107 | return (mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0; |
| 5108 | } |
| 5109 | |
| 5110 | /** |
| 5111 | * Sets whether the framework should discard touches when the view's |
| 5112 | * window is obscured by another visible window. |
| 5113 | * Refer to the {@link View} security documentation for more details. |
| 5114 | * |
| 5115 | * @param enabled True if touch filtering should be enabled. |
| 5116 | * |
| 5117 | * @see #getFilterTouchesWhenObscured |
| 5118 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 5119 | */ |
| 5120 | public void setFilterTouchesWhenObscured(boolean enabled) { |
| 5121 | setFlags(enabled ? 0 : FILTER_TOUCHES_WHEN_OBSCURED, |
| 5122 | FILTER_TOUCHES_WHEN_OBSCURED); |
| 5123 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5124 | |
| 5125 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 5126 | * Indicates whether the entire hierarchy under this view will save its |
| 5127 | * state when a state saving traversal occurs from its parent. The default |
| 5128 | * is true; if false, these views will not be saved unless |
| 5129 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 5130 | * |
| 5131 | * @return Returns true if the view state saving from parent is enabled, else false. |
| 5132 | * |
| 5133 | * @see #setSaveFromParentEnabled(boolean) |
| 5134 | */ |
| 5135 | public boolean isSaveFromParentEnabled() { |
| 5136 | return (mViewFlags & PARENT_SAVE_DISABLED_MASK) != PARENT_SAVE_DISABLED; |
| 5137 | } |
| 5138 | |
| 5139 | /** |
| 5140 | * Controls whether the entire hierarchy under this view will save its |
| 5141 | * state when a state saving traversal occurs from its parent. The default |
| 5142 | * is true; if false, these views will not be saved unless |
| 5143 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 5144 | * |
| 5145 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 5146 | * (the default) to allow it. |
| 5147 | * |
| 5148 | * @see #isSaveFromParentEnabled() |
| 5149 | * @see #setId(int) |
| 5150 | * @see #onSaveInstanceState() |
| 5151 | */ |
| 5152 | public void setSaveFromParentEnabled(boolean enabled) { |
| 5153 | setFlags(enabled ? 0 : PARENT_SAVE_DISABLED, PARENT_SAVE_DISABLED_MASK); |
| 5154 | } |
| 5155 | |
| 5156 | |
| 5157 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5158 | * Returns whether this View is able to take focus. |
| 5159 | * |
| 5160 | * @return True if this view can take focus, or false otherwise. |
| 5161 | * @attr ref android.R.styleable#View_focusable |
| 5162 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5163 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5164 | public final boolean isFocusable() { |
| 5165 | return FOCUSABLE == (mViewFlags & FOCUSABLE_MASK); |
| 5166 | } |
| 5167 | |
| 5168 | /** |
| 5169 | * When a view is focusable, it may not want to take focus when in touch mode. |
| 5170 | * For example, a button would like focus when the user is navigating via a D-pad |
| 5171 | * so that the user can click on it, but once the user starts touching the screen, |
| 5172 | * the button shouldn't take focus |
| 5173 | * @return Whether the view is focusable in touch mode. |
| 5174 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 5175 | */ |
| 5176 | @ViewDebug.ExportedProperty |
| 5177 | public final boolean isFocusableInTouchMode() { |
| 5178 | return FOCUSABLE_IN_TOUCH_MODE == (mViewFlags & FOCUSABLE_IN_TOUCH_MODE); |
| 5179 | } |
| 5180 | |
| 5181 | /** |
| 5182 | * Find the nearest view in the specified direction that can take focus. |
| 5183 | * This does not actually give focus to that view. |
| 5184 | * |
| 5185 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 5186 | * |
| 5187 | * @return The nearest focusable in the specified direction, or null if none |
| 5188 | * can be found. |
| 5189 | */ |
| 5190 | public View focusSearch(int direction) { |
| 5191 | if (mParent != null) { |
| 5192 | return mParent.focusSearch(this, direction); |
| 5193 | } else { |
| 5194 | return null; |
| 5195 | } |
| 5196 | } |
| 5197 | |
| 5198 | /** |
| 5199 | * This method is the last chance for the focused view and its ancestors to |
| 5200 | * respond to an arrow key. This is called when the focused view did not |
| 5201 | * consume the key internally, nor could the view system find a new view in |
| 5202 | * the requested direction to give focus to. |
| 5203 | * |
| 5204 | * @param focused The currently focused view. |
| 5205 | * @param direction The direction focus wants to move. One of FOCUS_UP, |
| 5206 | * FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT. |
| 5207 | * @return True if the this view consumed this unhandled move. |
| 5208 | */ |
| 5209 | public boolean dispatchUnhandledMove(View focused, int direction) { |
| 5210 | return false; |
| 5211 | } |
| 5212 | |
| 5213 | /** |
| 5214 | * 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] | 5215 | * use the root to look up the view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5216 | * @param root The root view of the hierarchy containing this view. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5217 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, |
| 5218 | * or FOCUS_BACKWARD. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5219 | * @return The user specified next view, or null if there is none. |
| 5220 | */ |
| 5221 | View findUserSetNextFocus(View root, int direction) { |
| 5222 | switch (direction) { |
| 5223 | case FOCUS_LEFT: |
| 5224 | if (mNextFocusLeftId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5225 | return findViewInsideOutShouldExist(root, mNextFocusLeftId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5226 | case FOCUS_RIGHT: |
| 5227 | if (mNextFocusRightId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5228 | return findViewInsideOutShouldExist(root, mNextFocusRightId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5229 | case FOCUS_UP: |
| 5230 | if (mNextFocusUpId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5231 | return findViewInsideOutShouldExist(root, mNextFocusUpId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5232 | case FOCUS_DOWN: |
| 5233 | if (mNextFocusDownId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5234 | return findViewInsideOutShouldExist(root, mNextFocusDownId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5235 | case FOCUS_FORWARD: |
| 5236 | if (mNextFocusForwardId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5237 | return findViewInsideOutShouldExist(root, mNextFocusForwardId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5238 | case FOCUS_BACKWARD: { |
| 5239 | final int id = mID; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5240 | return root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5241 | @Override |
| 5242 | public boolean apply(View t) { |
| 5243 | return t.mNextFocusForwardId == id; |
| 5244 | } |
| 5245 | }); |
| 5246 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5247 | } |
| 5248 | return null; |
| 5249 | } |
| 5250 | |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5251 | private View findViewInsideOutShouldExist(View root, final int childViewId) { |
| 5252 | View result = root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
| 5253 | @Override |
| 5254 | public boolean apply(View t) { |
| 5255 | return t.mID == childViewId; |
| 5256 | } |
| 5257 | }); |
| 5258 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5259 | if (result == null) { |
| 5260 | Log.w(VIEW_LOG_TAG, "couldn't find next focus view specified " |
| 5261 | + "by user for id " + childViewId); |
| 5262 | } |
| 5263 | return result; |
| 5264 | } |
| 5265 | |
| 5266 | /** |
| 5267 | * Find and return all focusable views that are descendants of this view, |
| 5268 | * possibly including this view if it is focusable itself. |
| 5269 | * |
| 5270 | * @param direction The direction of the focus |
| 5271 | * @return A list of focusable views |
| 5272 | */ |
| 5273 | public ArrayList<View> getFocusables(int direction) { |
| 5274 | ArrayList<View> result = new ArrayList<View>(24); |
| 5275 | addFocusables(result, direction); |
| 5276 | return result; |
| 5277 | } |
| 5278 | |
| 5279 | /** |
| 5280 | * Add any focusable views that are descendants of this view (possibly |
| 5281 | * including this view if it is focusable itself) to views. If we are in touch mode, |
| 5282 | * only add views that are also focusable in touch mode. |
| 5283 | * |
| 5284 | * @param views Focusable views found so far |
| 5285 | * @param direction The direction of the focus |
| 5286 | */ |
| 5287 | public void addFocusables(ArrayList<View> views, int direction) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5288 | addFocusables(views, direction, FOCUSABLES_TOUCH_MODE); |
| 5289 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5290 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5291 | /** |
| 5292 | * Adds any focusable views that are descendants of this view (possibly |
| 5293 | * including this view if it is focusable itself) to views. This method |
| 5294 | * adds all focusable views regardless if we are in touch mode or |
| 5295 | * only views focusable in touch mode if we are in touch mode depending on |
| 5296 | * the focusable mode paramater. |
| 5297 | * |
| 5298 | * @param views Focusable views found so far or null if all we are interested is |
| 5299 | * the number of focusables. |
| 5300 | * @param direction The direction of the focus. |
| 5301 | * @param focusableMode The type of focusables to be added. |
| 5302 | * |
| 5303 | * @see #FOCUSABLES_ALL |
| 5304 | * @see #FOCUSABLES_TOUCH_MODE |
| 5305 | */ |
| 5306 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
| 5307 | if (!isFocusable()) { |
| 5308 | return; |
| 5309 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5310 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5311 | if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && |
| 5312 | isInTouchMode() && !isFocusableInTouchMode()) { |
| 5313 | return; |
| 5314 | } |
| 5315 | |
| 5316 | if (views != null) { |
| 5317 | views.add(this); |
| 5318 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5322 | * Finds the Views that contain given text. The containment is case insensitive. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5323 | * The search is performed by either the text that the View renders or the content |
| 5324 | * description that describes the view for accessibility purposes and the view does |
| 5325 | * not render or both. Clients can specify how the search is to be performed via |
| 5326 | * passing the {@link #FIND_VIEWS_WITH_TEXT} and |
| 5327 | * {@link #FIND_VIEWS_WITH_CONTENT_DESCRIPTION} flags. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5328 | * |
| 5329 | * @param outViews The output list of matching Views. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5330 | * @param searched The text to match against. |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 5331 | * |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5332 | * @see #FIND_VIEWS_WITH_TEXT |
| 5333 | * @see #FIND_VIEWS_WITH_CONTENT_DESCRIPTION |
| 5334 | * @see #setContentDescription(CharSequence) |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5335 | */ |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5336 | public void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 5337 | if (getAccessibilityNodeProvider() != null) { |
| 5338 | if ((flags & FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS) != 0) { |
| 5339 | outViews.add(this); |
| 5340 | } |
| 5341 | } else if ((flags & FIND_VIEWS_WITH_CONTENT_DESCRIPTION) != 0 |
| 5342 | && !TextUtils.isEmpty(searched) && !TextUtils.isEmpty(mContentDescription)) { |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5343 | String searchedLowerCase = searched.toString().toLowerCase(); |
| 5344 | String contentDescriptionLowerCase = mContentDescription.toString().toLowerCase(); |
| 5345 | if (contentDescriptionLowerCase.contains(searchedLowerCase)) { |
| 5346 | outViews.add(this); |
| 5347 | } |
| 5348 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5349 | } |
| 5350 | |
| 5351 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5352 | * Find and return all touchable views that are descendants of this view, |
| 5353 | * possibly including this view if it is touchable itself. |
| 5354 | * |
| 5355 | * @return A list of touchable views |
| 5356 | */ |
| 5357 | public ArrayList<View> getTouchables() { |
| 5358 | ArrayList<View> result = new ArrayList<View>(); |
| 5359 | addTouchables(result); |
| 5360 | return result; |
| 5361 | } |
| 5362 | |
| 5363 | /** |
| 5364 | * Add any touchable views that are descendants of this view (possibly |
| 5365 | * including this view if it is touchable itself) to views. |
| 5366 | * |
| 5367 | * @param views Touchable views found so far |
| 5368 | */ |
| 5369 | public void addTouchables(ArrayList<View> views) { |
| 5370 | final int viewFlags = mViewFlags; |
| 5371 | |
| 5372 | if (((viewFlags & CLICKABLE) == CLICKABLE || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) |
| 5373 | && (viewFlags & ENABLED_MASK) == ENABLED) { |
| 5374 | views.add(this); |
| 5375 | } |
| 5376 | } |
| 5377 | |
| 5378 | /** |
| 5379 | * Call this to try to give focus to a specific view or to one of its |
| 5380 | * descendants. |
| 5381 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5382 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 5383 | * false), or if it is focusable and it is not focusable in touch mode |
| 5384 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5385 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5386 | * 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] | 5387 | * have focus, and you want your parent to look for the next one. |
| 5388 | * |
| 5389 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with arguments |
| 5390 | * {@link #FOCUS_DOWN} and <code>null</code>. |
| 5391 | * |
| 5392 | * @return Whether this view or one of its descendants actually took focus. |
| 5393 | */ |
| 5394 | public final boolean requestFocus() { |
| 5395 | return requestFocus(View.FOCUS_DOWN); |
| 5396 | } |
| 5397 | |
| 5398 | |
| 5399 | /** |
| 5400 | * Call this to try to give focus to a specific view or to one of its |
| 5401 | * descendants and give it a hint about what direction focus is heading. |
| 5402 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5403 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 5404 | * false), or if it is focusable and it is not focusable in touch mode |
| 5405 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5406 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5407 | * 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] | 5408 | * have focus, and you want your parent to look for the next one. |
| 5409 | * |
| 5410 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with |
| 5411 | * <code>null</code> set for the previously focused rectangle. |
| 5412 | * |
| 5413 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 5414 | * @return Whether this view or one of its descendants actually took focus. |
| 5415 | */ |
| 5416 | public final boolean requestFocus(int direction) { |
| 5417 | return requestFocus(direction, null); |
| 5418 | } |
| 5419 | |
| 5420 | /** |
| 5421 | * Call this to try to give focus to a specific view or to one of its descendants |
| 5422 | * and give it hints about the direction and a specific rectangle that the focus |
| 5423 | * is coming from. The rectangle can help give larger views a finer grained hint |
| 5424 | * about where focus is coming from, and therefore, where to show selection, or |
| 5425 | * forward focus change internally. |
| 5426 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5427 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 5428 | * false), or if it is focusable and it is not focusable in touch mode |
| 5429 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5430 | * |
| 5431 | * A View will not take focus if it is not visible. |
| 5432 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 5433 | * A View will not take focus if one of its parents has |
| 5434 | * {@link android.view.ViewGroup#getDescendantFocusability()} equal to |
| 5435 | * {@link ViewGroup#FOCUS_BLOCK_DESCENDANTS}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5436 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5437 | * 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] | 5438 | * have focus, and you want your parent to look for the next one. |
| 5439 | * |
| 5440 | * You may wish to override this method if your custom {@link View} has an internal |
| 5441 | * {@link View} that it wishes to forward the request to. |
| 5442 | * |
| 5443 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 5444 | * @param previouslyFocusedRect The rectangle (in this View's coordinate system) |
| 5445 | * to give a finer grained hint about where focus is coming from. May be null |
| 5446 | * if there is no hint. |
| 5447 | * @return Whether this view or one of its descendants actually took focus. |
| 5448 | */ |
| 5449 | public boolean requestFocus(int direction, Rect previouslyFocusedRect) { |
| 5450 | // need to be focusable |
| 5451 | if ((mViewFlags & FOCUSABLE_MASK) != FOCUSABLE || |
| 5452 | (mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 5453 | return false; |
| 5454 | } |
| 5455 | |
| 5456 | // need to be focusable in touch mode if in touch mode |
| 5457 | if (isInTouchMode() && |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5458 | (FOCUSABLE_IN_TOUCH_MODE != (mViewFlags & FOCUSABLE_IN_TOUCH_MODE))) { |
| 5459 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5460 | } |
| 5461 | |
| 5462 | // need to not have any parents blocking us |
| 5463 | if (hasAncestorThatBlocksDescendantFocus()) { |
| 5464 | return false; |
| 5465 | } |
| 5466 | |
| 5467 | handleFocusGainInternal(direction, previouslyFocusedRect); |
| 5468 | return true; |
| 5469 | } |
| 5470 | |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 5471 | /** Gets the ViewAncestor, or null if not attached. */ |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 5472 | /*package*/ ViewRootImpl getViewRootImpl() { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5473 | View root = getRootView(); |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 5474 | return root != null ? (ViewRootImpl)root.getParent() : null; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5475 | } |
| 5476 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5477 | /** |
| 5478 | * Call this to try to give focus to a specific view or to one of its descendants. This is a |
| 5479 | * special variant of {@link #requestFocus() } that will allow views that are not focuable in |
| 5480 | * touch mode to request focus when they are touched. |
| 5481 | * |
| 5482 | * @return Whether this view or one of its descendants actually took focus. |
| 5483 | * |
| 5484 | * @see #isInTouchMode() |
| 5485 | * |
| 5486 | */ |
| 5487 | public final boolean requestFocusFromTouch() { |
| 5488 | // Leave touch mode if we need to |
| 5489 | if (isInTouchMode()) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 5490 | ViewRootImpl viewRoot = getViewRootImpl(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5491 | if (viewRoot != null) { |
| 5492 | viewRoot.ensureTouchMode(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5493 | } |
| 5494 | } |
| 5495 | return requestFocus(View.FOCUS_DOWN); |
| 5496 | } |
| 5497 | |
| 5498 | /** |
| 5499 | * @return Whether any ancestor of this view blocks descendant focus. |
| 5500 | */ |
| 5501 | private boolean hasAncestorThatBlocksDescendantFocus() { |
| 5502 | ViewParent ancestor = mParent; |
| 5503 | while (ancestor instanceof ViewGroup) { |
| 5504 | final ViewGroup vgAncestor = (ViewGroup) ancestor; |
| 5505 | if (vgAncestor.getDescendantFocusability() == ViewGroup.FOCUS_BLOCK_DESCENDANTS) { |
| 5506 | return true; |
| 5507 | } else { |
| 5508 | ancestor = vgAncestor.getParent(); |
| 5509 | } |
| 5510 | } |
| 5511 | return false; |
| 5512 | } |
| 5513 | |
| 5514 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5515 | * @hide |
| 5516 | */ |
| 5517 | public void dispatchStartTemporaryDetach() { |
| 5518 | onStartTemporaryDetach(); |
| 5519 | } |
| 5520 | |
| 5521 | /** |
| 5522 | * 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] | 5523 | * {@link ViewGroup#detachViewFromParent(View) ViewGroup.detachViewFromParent}. |
| 5524 | * It will either be followed by {@link #onFinishTemporaryDetach()} or |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5525 | * {@link #onDetachedFromWindow()} when the container is done. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5526 | */ |
| 5527 | public void onStartTemporaryDetach() { |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5528 | removeUnsetPressCallback(); |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 5529 | mPrivateFlags |= CANCEL_NEXT_UP_EVENT; |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 5530 | } |
| 5531 | |
| 5532 | /** |
| 5533 | * @hide |
| 5534 | */ |
| 5535 | public void dispatchFinishTemporaryDetach() { |
| 5536 | onFinishTemporaryDetach(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5537 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5538 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5539 | /** |
| 5540 | * Called after {@link #onStartTemporaryDetach} when the container is done |
| 5541 | * changing the view. |
| 5542 | */ |
| 5543 | public void onFinishTemporaryDetach() { |
| 5544 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5545 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5546 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5547 | * Return the global {@link KeyEvent.DispatcherState KeyEvent.DispatcherState} |
| 5548 | * for this view's window. Returns null if the view is not currently attached |
| 5549 | * 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] | 5550 | * just use the standard high-level event callbacks like |
| 5551 | * {@link #onKeyDown(int, KeyEvent)}. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5552 | */ |
| 5553 | public KeyEvent.DispatcherState getKeyDispatcherState() { |
| 5554 | return mAttachInfo != null ? mAttachInfo.mKeyDispatchState : null; |
| 5555 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 5556 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 5557 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5558 | * Dispatch a key event before it is processed by any input method |
| 5559 | * associated with the view hierarchy. This can be used to intercept |
| 5560 | * key events in special situations before the IME consumes them; a |
| 5561 | * typical example would be handling the BACK key to update the application's |
| 5562 | * UI instead of allowing the IME to see it and close itself. |
| 5563 | * |
| 5564 | * @param event The key event to be dispatched. |
| 5565 | * @return True if the event was handled, false otherwise. |
| 5566 | */ |
| 5567 | public boolean dispatchKeyEventPreIme(KeyEvent event) { |
| 5568 | return onKeyPreIme(event.getKeyCode(), event); |
| 5569 | } |
| 5570 | |
| 5571 | /** |
| 5572 | * Dispatch a key event to the next view on the focus path. This path runs |
| 5573 | * from the top of the view tree down to the currently focused view. If this |
| 5574 | * view has focus, it will dispatch to itself. Otherwise it will dispatch |
| 5575 | * the next node down the focus path. This method also fires any key |
| 5576 | * listeners. |
| 5577 | * |
| 5578 | * @param event The key event to be dispatched. |
| 5579 | * @return True if the event was handled, false otherwise. |
| 5580 | */ |
| 5581 | public boolean dispatchKeyEvent(KeyEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5582 | if (mInputEventConsistencyVerifier != null) { |
| 5583 | mInputEventConsistencyVerifier.onKeyEvent(event, 0); |
| 5584 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5585 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5586 | // Give any attached key listener a first crack at the event. |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 5587 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 5588 | ListenerInfo li = mListenerInfo; |
| 5589 | if (li != null && li.mOnKeyListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5590 | && li.mOnKeyListener.onKey(this, event.getKeyCode(), event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5591 | return true; |
| 5592 | } |
| 5593 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5594 | if (event.dispatch(this, mAttachInfo != null |
| 5595 | ? mAttachInfo.mKeyDispatchState : null, this)) { |
| 5596 | return true; |
| 5597 | } |
| 5598 | |
| 5599 | if (mInputEventConsistencyVerifier != null) { |
| 5600 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 5601 | } |
| 5602 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | /** |
| 5606 | * Dispatches a key shortcut event. |
| 5607 | * |
| 5608 | * @param event The key event to be dispatched. |
| 5609 | * @return True if the event was handled by the view, false otherwise. |
| 5610 | */ |
| 5611 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 5612 | return onKeyShortcut(event.getKeyCode(), event); |
| 5613 | } |
| 5614 | |
| 5615 | /** |
| 5616 | * Pass the touch screen motion event down to the target view, or this |
| 5617 | * view if it is the target. |
| 5618 | * |
| 5619 | * @param event The motion event to be dispatched. |
| 5620 | * @return True if the event was handled by the view, false otherwise. |
| 5621 | */ |
| 5622 | public boolean dispatchTouchEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5623 | if (mInputEventConsistencyVerifier != null) { |
| 5624 | mInputEventConsistencyVerifier.onTouchEvent(event, 0); |
| 5625 | } |
| 5626 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5627 | if (onFilterTouchEventForSecurity(event)) { |
| 5628 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 5629 | ListenerInfo li = mListenerInfo; |
| 5630 | if (li != null && li.mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5631 | && li.mOnTouchListener.onTouch(this, event)) { |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5632 | return true; |
| 5633 | } |
| 5634 | |
| 5635 | if (onTouchEvent(event)) { |
| 5636 | return true; |
| 5637 | } |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5638 | } |
| 5639 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5640 | if (mInputEventConsistencyVerifier != null) { |
| 5641 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5642 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5643 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5644 | } |
| 5645 | |
| 5646 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5647 | * Filter the touch event to apply security policies. |
| 5648 | * |
| 5649 | * @param event The motion event to be filtered. |
| 5650 | * @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] | 5651 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5652 | * @see #getFilterTouchesWhenObscured |
| 5653 | */ |
| 5654 | public boolean onFilterTouchEventForSecurity(MotionEvent event) { |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 5655 | //noinspection RedundantIfStatement |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5656 | if ((mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0 |
| 5657 | && (event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) { |
| 5658 | // Window is obscured, drop this touch. |
| 5659 | return false; |
| 5660 | } |
| 5661 | return true; |
| 5662 | } |
| 5663 | |
| 5664 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5665 | * Pass a trackball motion event down to the focused view. |
| 5666 | * |
| 5667 | * @param event The motion event to be dispatched. |
| 5668 | * @return True if the event was handled by the view, false otherwise. |
| 5669 | */ |
| 5670 | public boolean dispatchTrackballEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5671 | if (mInputEventConsistencyVerifier != null) { |
| 5672 | mInputEventConsistencyVerifier.onTrackballEvent(event, 0); |
| 5673 | } |
| 5674 | |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 5675 | return onTrackballEvent(event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5676 | } |
| 5677 | |
| 5678 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5679 | * Dispatch a generic motion event. |
| 5680 | * <p> |
| 5681 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 5682 | * 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] | 5683 | * 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] | 5684 | * to {@link #onHoverEvent(MotionEvent)}. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5685 | * </p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5686 | * |
| 5687 | * @param event The motion event to be dispatched. |
| 5688 | * @return True if the event was handled by the view, false otherwise. |
| 5689 | */ |
| 5690 | public boolean dispatchGenericMotionEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 5691 | if (mInputEventConsistencyVerifier != null) { |
| 5692 | mInputEventConsistencyVerifier.onGenericMotionEvent(event, 0); |
| 5693 | } |
| 5694 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5695 | final int source = event.getSource(); |
| 5696 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 5697 | final int action = event.getAction(); |
| 5698 | if (action == MotionEvent.ACTION_HOVER_ENTER |
| 5699 | || action == MotionEvent.ACTION_HOVER_MOVE |
| 5700 | || action == MotionEvent.ACTION_HOVER_EXIT) { |
| 5701 | if (dispatchHoverEvent(event)) { |
| 5702 | return true; |
| 5703 | } |
| 5704 | } else if (dispatchGenericPointerEvent(event)) { |
| 5705 | return true; |
| 5706 | } |
| 5707 | } else if (dispatchGenericFocusedEvent(event)) { |
| 5708 | return true; |
| 5709 | } |
| 5710 | |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 5711 | if (dispatchGenericMotionEventInternal(event)) { |
| 5712 | return true; |
| 5713 | } |
| 5714 | |
| 5715 | if (mInputEventConsistencyVerifier != null) { |
| 5716 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 5717 | } |
| 5718 | return false; |
| 5719 | } |
| 5720 | |
| 5721 | private boolean dispatchGenericMotionEventInternal(MotionEvent event) { |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -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.mOnGenericMotionListener != null |
| 5725 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5726 | && li.mOnGenericMotionListener.onGenericMotion(this, event)) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5727 | return true; |
| 5728 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 5729 | |
| 5730 | if (onGenericMotionEvent(event)) { |
| 5731 | return true; |
| 5732 | } |
| 5733 | |
| 5734 | if (mInputEventConsistencyVerifier != null) { |
| 5735 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 5736 | } |
| 5737 | return false; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5738 | } |
| 5739 | |
| 5740 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5741 | * Dispatch a hover event. |
| 5742 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5743 | * Do not call this method directly. |
| 5744 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5745 | * </p> |
| 5746 | * |
| 5747 | * @param event The motion event to be dispatched. |
| 5748 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5749 | */ |
| 5750 | protected boolean dispatchHoverEvent(MotionEvent event) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 5751 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 5752 | ListenerInfo li = mListenerInfo; |
| 5753 | if (li != null && li.mOnHoverListener != null |
| 5754 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 5755 | && li.mOnHoverListener.onHover(this, event)) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 5756 | return true; |
| 5757 | } |
| 5758 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5759 | return onHoverEvent(event); |
| 5760 | } |
| 5761 | |
| 5762 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 5763 | * Returns true if the view has a child to which it has recently sent |
| 5764 | * {@link MotionEvent#ACTION_HOVER_ENTER}. If this view is hovered and |
| 5765 | * it does not have a hovered child, then it must be the innermost hovered view. |
| 5766 | * @hide |
| 5767 | */ |
| 5768 | protected boolean hasHoveredChild() { |
| 5769 | return false; |
| 5770 | } |
| 5771 | |
| 5772 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5773 | * Dispatch a generic motion event to the view under the first pointer. |
| 5774 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5775 | * Do not call this method directly. |
| 5776 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5777 | * </p> |
| 5778 | * |
| 5779 | * @param event The motion event to be dispatched. |
| 5780 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5781 | */ |
| 5782 | protected boolean dispatchGenericPointerEvent(MotionEvent event) { |
| 5783 | return false; |
| 5784 | } |
| 5785 | |
| 5786 | /** |
| 5787 | * Dispatch a generic motion event to the currently focused view. |
| 5788 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5789 | * Do not call this method directly. |
| 5790 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5791 | * </p> |
| 5792 | * |
| 5793 | * @param event The motion event to be dispatched. |
| 5794 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 5795 | */ |
| 5796 | protected boolean dispatchGenericFocusedEvent(MotionEvent event) { |
| 5797 | return false; |
| 5798 | } |
| 5799 | |
| 5800 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5801 | * Dispatch a pointer event. |
| 5802 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5803 | * Dispatches touch related pointer events to {@link #onTouchEvent(MotionEvent)} and all |
| 5804 | * other events to {@link #onGenericMotionEvent(MotionEvent)}. This separation of concerns |
| 5805 | * reinforces the invariant that {@link #onTouchEvent(MotionEvent)} is really about touches |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 5806 | * and should not be expected to handle other pointing device features. |
| 5807 | * </p> |
| 5808 | * |
| 5809 | * @param event The motion event to be dispatched. |
| 5810 | * @return True if the event was handled by the view, false otherwise. |
| 5811 | * @hide |
| 5812 | */ |
| 5813 | public final boolean dispatchPointerEvent(MotionEvent event) { |
| 5814 | if (event.isTouchEvent()) { |
| 5815 | return dispatchTouchEvent(event); |
| 5816 | } else { |
| 5817 | return dispatchGenericMotionEvent(event); |
| 5818 | } |
| 5819 | } |
| 5820 | |
| 5821 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5822 | * Called when the window containing this view gains or loses window focus. |
| 5823 | * ViewGroups should override to route to their children. |
| 5824 | * |
| 5825 | * @param hasFocus True if the window containing this view now has focus, |
| 5826 | * false otherwise. |
| 5827 | */ |
| 5828 | public void dispatchWindowFocusChanged(boolean hasFocus) { |
| 5829 | onWindowFocusChanged(hasFocus); |
| 5830 | } |
| 5831 | |
| 5832 | /** |
| 5833 | * Called when the window containing this view gains or loses focus. Note |
| 5834 | * that this is separate from view focus: to receive key events, both |
| 5835 | * your view and its window must have focus. If a window is displayed |
| 5836 | * on top of yours that takes input focus, then your own window will lose |
| 5837 | * focus but the view focus will remain unchanged. |
| 5838 | * |
| 5839 | * @param hasWindowFocus True if the window containing this view now has |
| 5840 | * focus, false otherwise. |
| 5841 | */ |
| 5842 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 5843 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 5844 | if (!hasWindowFocus) { |
| 5845 | if (isPressed()) { |
| 5846 | setPressed(false); |
| 5847 | } |
| 5848 | if (imm != null && (mPrivateFlags & FOCUSED) != 0) { |
| 5849 | imm.focusOut(this); |
| 5850 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 5851 | removeLongPressCallback(); |
Tony Wu | 26edf20 | 2010-09-13 19:54:00 +0800 | [diff] [blame] | 5852 | removeTapCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 5853 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5854 | } else if (imm != null && (mPrivateFlags & FOCUSED) != 0) { |
| 5855 | imm.focusIn(this); |
| 5856 | } |
| 5857 | refreshDrawableState(); |
| 5858 | } |
| 5859 | |
| 5860 | /** |
| 5861 | * Returns true if this view is in a window that currently has window focus. |
| 5862 | * Note that this is not the same as the view itself having focus. |
| 5863 | * |
| 5864 | * @return True if this view is in a window that currently has window focus. |
| 5865 | */ |
| 5866 | public boolean hasWindowFocus() { |
| 5867 | return mAttachInfo != null && mAttachInfo.mHasWindowFocus; |
| 5868 | } |
| 5869 | |
| 5870 | /** |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 5871 | * Dispatch a view visibility change down the view hierarchy. |
| 5872 | * ViewGroups should override to route to their children. |
| 5873 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 5874 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 5875 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 5876 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 5877 | */ |
| 5878 | protected void dispatchVisibilityChanged(View changedView, int visibility) { |
| 5879 | onVisibilityChanged(changedView, visibility); |
| 5880 | } |
| 5881 | |
| 5882 | /** |
| 5883 | * Called when the visibility of the view or an ancestor of the view is changed. |
| 5884 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 5885 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 5886 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 5887 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 5888 | */ |
| 5889 | protected void onVisibilityChanged(View changedView, int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 5890 | if (visibility == VISIBLE) { |
| 5891 | if (mAttachInfo != null) { |
| 5892 | initialAwakenScrollBars(); |
| 5893 | } else { |
| 5894 | mPrivateFlags |= AWAKEN_SCROLL_BARS_ON_ATTACH; |
| 5895 | } |
| 5896 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 5897 | } |
| 5898 | |
| 5899 | /** |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 5900 | * Dispatch a hint about whether this view is displayed. For instance, when |
| 5901 | * a View moves out of the screen, it might receives a display hint indicating |
| 5902 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 5903 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 5904 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 5905 | * @param hint A hint about whether or not this view is displayed: |
| 5906 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 5907 | */ |
| 5908 | public void dispatchDisplayHint(int hint) { |
| 5909 | onDisplayHint(hint); |
| 5910 | } |
| 5911 | |
| 5912 | /** |
| 5913 | * Gives this view a hint about whether is displayed or not. For instance, when |
| 5914 | * a View moves out of the screen, it might receives a display hint indicating |
| 5915 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 5916 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 5917 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 5918 | * @param hint A hint about whether or not this view is displayed: |
| 5919 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 5920 | */ |
| 5921 | protected void onDisplayHint(int hint) { |
| 5922 | } |
| 5923 | |
| 5924 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5925 | * Dispatch a window visibility change down the view hierarchy. |
| 5926 | * ViewGroups should override to route to their children. |
| 5927 | * |
| 5928 | * @param visibility The new visibility of the window. |
| 5929 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5930 | * @see #onWindowVisibilityChanged(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5931 | */ |
| 5932 | public void dispatchWindowVisibilityChanged(int visibility) { |
| 5933 | onWindowVisibilityChanged(visibility); |
| 5934 | } |
| 5935 | |
| 5936 | /** |
| 5937 | * Called when the window containing has change its visibility |
| 5938 | * (between {@link #GONE}, {@link #INVISIBLE}, and {@link #VISIBLE}). Note |
| 5939 | * that this tells you whether or not your window is being made visible |
| 5940 | * to the window manager; this does <em>not</em> tell you whether or not |
| 5941 | * your window is obscured by other windows on the screen, even if it |
| 5942 | * is itself visible. |
| 5943 | * |
| 5944 | * @param visibility The new visibility of the window. |
| 5945 | */ |
| 5946 | protected void onWindowVisibilityChanged(int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 5947 | if (visibility == VISIBLE) { |
| 5948 | initialAwakenScrollBars(); |
| 5949 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5950 | } |
| 5951 | |
| 5952 | /** |
| 5953 | * Returns the current visibility of the window this view is attached to |
| 5954 | * (either {@link #GONE}, {@link #INVISIBLE}, or {@link #VISIBLE}). |
| 5955 | * |
| 5956 | * @return Returns the current visibility of the view's window. |
| 5957 | */ |
| 5958 | public int getWindowVisibility() { |
| 5959 | return mAttachInfo != null ? mAttachInfo.mWindowVisibility : GONE; |
| 5960 | } |
| 5961 | |
| 5962 | /** |
| 5963 | * Retrieve the overall visible display size in which the window this view is |
| 5964 | * attached to has been positioned in. This takes into account screen |
| 5965 | * decorations above the window, for both cases where the window itself |
| 5966 | * is being position inside of them or the window is being placed under |
| 5967 | * then and covered insets are used for the window to position its content |
| 5968 | * inside. In effect, this tells you the available area where content can |
| 5969 | * be placed and remain visible to users. |
| 5970 | * |
| 5971 | * <p>This function requires an IPC back to the window manager to retrieve |
| 5972 | * the requested information, so should not be used in performance critical |
| 5973 | * code like drawing. |
| 5974 | * |
| 5975 | * @param outRect Filled in with the visible display frame. If the view |
| 5976 | * is not attached to a window, this is simply the raw display size. |
| 5977 | */ |
| 5978 | public void getWindowVisibleDisplayFrame(Rect outRect) { |
| 5979 | if (mAttachInfo != null) { |
| 5980 | try { |
| 5981 | mAttachInfo.mSession.getDisplayFrame(mAttachInfo.mWindow, outRect); |
| 5982 | } catch (RemoteException e) { |
| 5983 | return; |
| 5984 | } |
| 5985 | // XXX This is really broken, and probably all needs to be done |
| 5986 | // in the window manager, and we need to know more about whether |
| 5987 | // we want the area behind or in front of the IME. |
| 5988 | final Rect insets = mAttachInfo.mVisibleInsets; |
| 5989 | outRect.left += insets.left; |
| 5990 | outRect.top += insets.top; |
| 5991 | outRect.right -= insets.right; |
| 5992 | outRect.bottom -= insets.bottom; |
| 5993 | return; |
| 5994 | } |
| 5995 | Display d = WindowManagerImpl.getDefault().getDefaultDisplay(); |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 5996 | d.getRectSize(outRect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5997 | } |
| 5998 | |
| 5999 | /** |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6000 | * Dispatch a notification about a resource configuration change down |
| 6001 | * the view hierarchy. |
| 6002 | * ViewGroups should override to route to their children. |
| 6003 | * |
| 6004 | * @param newConfig The new resource configuration. |
| 6005 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6006 | * @see #onConfigurationChanged(android.content.res.Configuration) |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6007 | */ |
| 6008 | public void dispatchConfigurationChanged(Configuration newConfig) { |
| 6009 | onConfigurationChanged(newConfig); |
| 6010 | } |
| 6011 | |
| 6012 | /** |
| 6013 | * Called when the current configuration of the resources being used |
| 6014 | * by the application have changed. You can use this to decide when |
| 6015 | * to reload resources that can changed based on orientation and other |
| 6016 | * configuration characterstics. You only need to use this if you are |
| 6017 | * not relying on the normal {@link android.app.Activity} mechanism of |
| 6018 | * recreating the activity instance upon a configuration change. |
| 6019 | * |
| 6020 | * @param newConfig The new resource configuration. |
| 6021 | */ |
| 6022 | protected void onConfigurationChanged(Configuration newConfig) { |
| 6023 | } |
| 6024 | |
| 6025 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6026 | * Private function to aggregate all per-view attributes in to the view |
| 6027 | * root. |
| 6028 | */ |
| 6029 | void dispatchCollectViewAttributes(int visibility) { |
| 6030 | performCollectViewAttributes(visibility); |
| 6031 | } |
| 6032 | |
| 6033 | void performCollectViewAttributes(int visibility) { |
Romain Guy | d30b36d | 2011-01-26 10:54:43 -0800 | [diff] [blame] | 6034 | if ((visibility & VISIBILITY_MASK) == VISIBLE && mAttachInfo != null) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6035 | if ((mViewFlags & KEEP_SCREEN_ON) == KEEP_SCREEN_ON) { |
| 6036 | mAttachInfo.mKeepScreenOn = true; |
| 6037 | } |
| 6038 | mAttachInfo.mSystemUiVisibility |= mSystemUiVisibility; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6039 | ListenerInfo li = mListenerInfo; |
| 6040 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6041 | mAttachInfo.mHasSystemUiListeners = true; |
| 6042 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6043 | } |
| 6044 | } |
| 6045 | |
| 6046 | void needGlobalAttributesUpdate(boolean force) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6047 | final AttachInfo ai = mAttachInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6048 | if (ai != null) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6049 | if (force || ai.mKeepScreenOn || (ai.mSystemUiVisibility != 0) |
| 6050 | || ai.mHasSystemUiListeners) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6051 | ai.mRecomputeGlobalAttributes = true; |
| 6052 | } |
| 6053 | } |
| 6054 | } |
| 6055 | |
| 6056 | /** |
| 6057 | * Returns whether the device is currently in touch mode. Touch mode is entered |
| 6058 | * once the user begins interacting with the device by touch, and affects various |
| 6059 | * things like whether focus is always visible to the user. |
| 6060 | * |
| 6061 | * @return Whether the device is in touch mode. |
| 6062 | */ |
| 6063 | @ViewDebug.ExportedProperty |
| 6064 | public boolean isInTouchMode() { |
| 6065 | if (mAttachInfo != null) { |
| 6066 | return mAttachInfo.mInTouchMode; |
| 6067 | } else { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6068 | return ViewRootImpl.isInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6069 | } |
| 6070 | } |
| 6071 | |
| 6072 | /** |
| 6073 | * Returns the context the view is running in, through which it can |
| 6074 | * access the current theme, resources, etc. |
| 6075 | * |
| 6076 | * @return The view's Context. |
| 6077 | */ |
| 6078 | @ViewDebug.CapturedViewProperty |
| 6079 | public final Context getContext() { |
| 6080 | return mContext; |
| 6081 | } |
| 6082 | |
| 6083 | /** |
| 6084 | * Handle a key event before it is processed by any input method |
| 6085 | * associated with the view hierarchy. This can be used to intercept |
| 6086 | * key events in special situations before the IME consumes them; a |
| 6087 | * typical example would be handling the BACK key to update the application's |
| 6088 | * UI instead of allowing the IME to see it and close itself. |
| 6089 | * |
| 6090 | * @param keyCode The value in event.getKeyCode(). |
| 6091 | * @param event Description of the key event. |
| 6092 | * @return If you handled the event, return true. If you want to allow the |
| 6093 | * event to be handled by the next receiver, return false. |
| 6094 | */ |
| 6095 | public boolean onKeyPreIme(int keyCode, KeyEvent event) { |
| 6096 | return false; |
| 6097 | } |
| 6098 | |
| 6099 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 6100 | * Default implementation of {@link KeyEvent.Callback#onKeyDown(int, KeyEvent) |
| 6101 | * KeyEvent.Callback.onKeyDown()}: perform press of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6102 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or {@link KeyEvent#KEYCODE_ENTER} |
| 6103 | * is released, if the view is enabled and clickable. |
| 6104 | * |
| 6105 | * @param keyCode A key code that represents the button pressed, from |
| 6106 | * {@link android.view.KeyEvent}. |
| 6107 | * @param event The KeyEvent object that defines the button action. |
| 6108 | */ |
| 6109 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 6110 | boolean result = false; |
| 6111 | |
| 6112 | switch (keyCode) { |
| 6113 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 6114 | case KeyEvent.KEYCODE_ENTER: { |
| 6115 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 6116 | return true; |
| 6117 | } |
| 6118 | // Long clickable items don't necessarily have to be clickable |
| 6119 | if (((mViewFlags & CLICKABLE) == CLICKABLE || |
| 6120 | (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) && |
| 6121 | (event.getRepeatCount() == 0)) { |
| 6122 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6123 | checkForLongClick(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6124 | return true; |
| 6125 | } |
| 6126 | break; |
| 6127 | } |
| 6128 | } |
| 6129 | return result; |
| 6130 | } |
| 6131 | |
| 6132 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6133 | * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
| 6134 | * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle |
| 6135 | * the event). |
| 6136 | */ |
| 6137 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 6138 | return false; |
| 6139 | } |
| 6140 | |
| 6141 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 6142 | * Default implementation of {@link KeyEvent.Callback#onKeyUp(int, KeyEvent) |
| 6143 | * KeyEvent.Callback.onKeyUp()}: perform clicking of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6144 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or |
| 6145 | * {@link KeyEvent#KEYCODE_ENTER} is released. |
| 6146 | * |
| 6147 | * @param keyCode A key code that represents the button pressed, from |
| 6148 | * {@link android.view.KeyEvent}. |
| 6149 | * @param event The KeyEvent object that defines the button action. |
| 6150 | */ |
| 6151 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 6152 | boolean result = false; |
| 6153 | |
| 6154 | switch (keyCode) { |
| 6155 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 6156 | case KeyEvent.KEYCODE_ENTER: { |
| 6157 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 6158 | return true; |
| 6159 | } |
| 6160 | if ((mViewFlags & CLICKABLE) == CLICKABLE && isPressed()) { |
| 6161 | setPressed(false); |
| 6162 | |
| 6163 | if (!mHasPerformedLongPress) { |
| 6164 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6165 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6166 | |
| 6167 | result = performClick(); |
| 6168 | } |
| 6169 | } |
| 6170 | break; |
| 6171 | } |
| 6172 | } |
| 6173 | return result; |
| 6174 | } |
| 6175 | |
| 6176 | /** |
| 6177 | * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) |
| 6178 | * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle |
| 6179 | * the event). |
| 6180 | * |
| 6181 | * @param keyCode A key code that represents the button pressed, from |
| 6182 | * {@link android.view.KeyEvent}. |
| 6183 | * @param repeatCount The number of times the action was made. |
| 6184 | * @param event The KeyEvent object that defines the button action. |
| 6185 | */ |
| 6186 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 6187 | return false; |
| 6188 | } |
| 6189 | |
| 6190 | /** |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 6191 | * Called on the focused view when a key shortcut event is not handled. |
| 6192 | * Override this method to implement local key shortcuts for the View. |
| 6193 | * Key shortcuts can also be implemented by setting the |
| 6194 | * {@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] | 6195 | * |
| 6196 | * @param keyCode The value in event.getKeyCode(). |
| 6197 | * @param event Description of the key event. |
| 6198 | * @return If you handled the event, return true. If you want to allow the |
| 6199 | * event to be handled by the next receiver, return false. |
| 6200 | */ |
| 6201 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
| 6202 | return false; |
| 6203 | } |
| 6204 | |
| 6205 | /** |
| 6206 | * Check whether the called view is a text editor, in which case it |
| 6207 | * would make sense to automatically display a soft input window for |
| 6208 | * it. Subclasses should override this if they implement |
| 6209 | * {@link #onCreateInputConnection(EditorInfo)} to return true if |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 6210 | * a call on that method would return a non-null InputConnection, and |
| 6211 | * they are really a first-class editor that the user would normally |
| 6212 | * start typing on when the go into a window containing your view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6213 | * |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 6214 | * <p>The default implementation always returns false. This does |
| 6215 | * <em>not</em> mean that its {@link #onCreateInputConnection(EditorInfo)} |
| 6216 | * will not be called or the user can not otherwise perform edits on your |
| 6217 | * view; it is just a hint to the system that this is not the primary |
| 6218 | * purpose of this view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6219 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6220 | * @return Returns true if this view is a text editor, else false. |
| 6221 | */ |
| 6222 | public boolean onCheckIsTextEditor() { |
| 6223 | return false; |
| 6224 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6226 | /** |
| 6227 | * Create a new InputConnection for an InputMethod to interact |
| 6228 | * with the view. The default implementation returns null, since it doesn't |
| 6229 | * support input methods. You can override this to implement such support. |
| 6230 | * This is only needed for views that take focus and text input. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6231 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6232 | * <p>When implementing this, you probably also want to implement |
| 6233 | * {@link #onCheckIsTextEditor()} to indicate you will return a |
| 6234 | * non-null InputConnection. |
| 6235 | * |
| 6236 | * @param outAttrs Fill in with attribute information about the connection. |
| 6237 | */ |
| 6238 | public InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
| 6239 | return null; |
| 6240 | } |
| 6241 | |
| 6242 | /** |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 6243 | * Called by the {@link android.view.inputmethod.InputMethodManager} |
| 6244 | * when a view who is not the current |
| 6245 | * input connection target is trying to make a call on the manager. The |
| 6246 | * default implementation returns false; you can override this to return |
| 6247 | * true for certain views if you are performing InputConnection proxying |
| 6248 | * to them. |
| 6249 | * @param view The View that is making the InputMethodManager call. |
| 6250 | * @return Return true to allow the call, false to reject. |
| 6251 | */ |
| 6252 | public boolean checkInputConnectionProxy(View view) { |
| 6253 | return false; |
| 6254 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6255 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 6256 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6257 | * Show the context menu for this view. It is not safe to hold on to the |
| 6258 | * menu after returning from this method. |
| 6259 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 6260 | * You should normally not overload this method. Overload |
| 6261 | * {@link #onCreateContextMenu(ContextMenu)} or define an |
| 6262 | * {@link OnCreateContextMenuListener} to add items to the context menu. |
| 6263 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6264 | * @param menu The context menu to populate |
| 6265 | */ |
| 6266 | public void createContextMenu(ContextMenu menu) { |
| 6267 | ContextMenuInfo menuInfo = getContextMenuInfo(); |
| 6268 | |
| 6269 | // Sets the current menu info so all items added to menu will have |
| 6270 | // my extra info set. |
| 6271 | ((MenuBuilder)menu).setCurrentMenuInfo(menuInfo); |
| 6272 | |
| 6273 | onCreateContextMenu(menu); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6274 | ListenerInfo li = mListenerInfo; |
| 6275 | if (li != null && li.mOnCreateContextMenuListener != null) { |
| 6276 | li.mOnCreateContextMenuListener.onCreateContextMenu(menu, this, menuInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6277 | } |
| 6278 | |
| 6279 | // Clear the extra information so subsequent items that aren't mine don't |
| 6280 | // have my extra info. |
| 6281 | ((MenuBuilder)menu).setCurrentMenuInfo(null); |
| 6282 | |
| 6283 | if (mParent != null) { |
| 6284 | mParent.createContextMenu(menu); |
| 6285 | } |
| 6286 | } |
| 6287 | |
| 6288 | /** |
| 6289 | * Views should implement this if they have extra information to associate |
| 6290 | * with the context menu. The return result is supplied as a parameter to |
| 6291 | * the {@link OnCreateContextMenuListener#onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} |
| 6292 | * callback. |
| 6293 | * |
| 6294 | * @return Extra information about the item for which the context menu |
| 6295 | * should be shown. This information will vary across different |
| 6296 | * subclasses of View. |
| 6297 | */ |
| 6298 | protected ContextMenuInfo getContextMenuInfo() { |
| 6299 | return null; |
| 6300 | } |
| 6301 | |
| 6302 | /** |
| 6303 | * Views should implement this if the view itself is going to add items to |
| 6304 | * the context menu. |
| 6305 | * |
| 6306 | * @param menu the context menu to populate |
| 6307 | */ |
| 6308 | protected void onCreateContextMenu(ContextMenu menu) { |
| 6309 | } |
| 6310 | |
| 6311 | /** |
| 6312 | * Implement this method to handle trackball motion events. The |
| 6313 | * <em>relative</em> movement of the trackball since the last event |
| 6314 | * can be retrieve with {@link MotionEvent#getX MotionEvent.getX()} and |
| 6315 | * {@link MotionEvent#getY MotionEvent.getY()}. These are normalized so |
| 6316 | * that a movement of 1 corresponds to the user pressing one DPAD key (so |
| 6317 | * they will often be fractional values, representing the more fine-grained |
| 6318 | * movement information available from a trackball). |
| 6319 | * |
| 6320 | * @param event The motion event. |
| 6321 | * @return True if the event was handled, false otherwise. |
| 6322 | */ |
| 6323 | public boolean onTrackballEvent(MotionEvent event) { |
| 6324 | return false; |
| 6325 | } |
| 6326 | |
| 6327 | /** |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6328 | * Implement this method to handle generic motion events. |
| 6329 | * <p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6330 | * Generic motion events describe joystick movements, mouse hovers, track pad |
| 6331 | * touches, scroll wheel movements and other input events. The |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6332 | * {@link MotionEvent#getSource() source} of the motion event specifies |
| 6333 | * the class of input that was received. Implementations of this method |
| 6334 | * must examine the bits in the source before processing the event. |
| 6335 | * The following code example shows how this is done. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6336 | * </p><p> |
| 6337 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 6338 | * are delivered to the view under the pointer. All other generic motion events are |
| 6339 | * delivered to the focused view. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6340 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 6341 | * <pre> public boolean onGenericMotionEvent(MotionEvent event) { |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6342 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6343 | * if (event.getAction() == MotionEvent.ACTION_MOVE) { |
| 6344 | * // process the joystick movement... |
| 6345 | * return true; |
| 6346 | * } |
| 6347 | * } |
| 6348 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 6349 | * switch (event.getAction()) { |
| 6350 | * case MotionEvent.ACTION_HOVER_MOVE: |
| 6351 | * // process the mouse hover movement... |
| 6352 | * return true; |
| 6353 | * case MotionEvent.ACTION_SCROLL: |
| 6354 | * // process the scroll wheel movement... |
| 6355 | * return true; |
| 6356 | * } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6357 | * } |
| 6358 | * return super.onGenericMotionEvent(event); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 6359 | * }</pre> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6360 | * |
| 6361 | * @param event The generic motion event being processed. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6362 | * @return True if the event was handled, false otherwise. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6363 | */ |
| 6364 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 6365 | return false; |
| 6366 | } |
| 6367 | |
| 6368 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6369 | * Implement this method to handle hover events. |
| 6370 | * <p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6371 | * This method is called whenever a pointer is hovering into, over, or out of the |
| 6372 | * bounds of a view and the view is not currently being touched. |
| 6373 | * Hover events are represented as pointer events with action |
| 6374 | * {@link MotionEvent#ACTION_HOVER_ENTER}, {@link MotionEvent#ACTION_HOVER_MOVE}, |
| 6375 | * or {@link MotionEvent#ACTION_HOVER_EXIT}. |
| 6376 | * </p> |
| 6377 | * <ul> |
| 6378 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_ENTER} |
| 6379 | * when the pointer enters the bounds of the view.</li> |
| 6380 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_MOVE} |
| 6381 | * when the pointer has already entered the bounds of the view and has moved.</li> |
| 6382 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_EXIT} |
| 6383 | * when the pointer has exited the bounds of the view or when the pointer is |
| 6384 | * about to go down due to a button click, tap, or similar user action that |
| 6385 | * causes the view to be touched.</li> |
| 6386 | * </ul> |
| 6387 | * <p> |
| 6388 | * The view should implement this method to return true to indicate that it is |
| 6389 | * handling the hover event, such as by changing its drawable state. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6390 | * </p><p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6391 | * The default implementation calls {@link #setHovered} to update the hovered state |
| 6392 | * 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] | 6393 | * is enabled and is clickable. The default implementation also sends hover |
| 6394 | * accessibility events. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6395 | * </p> |
| 6396 | * |
| 6397 | * @param event The motion event that describes the hover. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6398 | * @return True if the view handled the hover event. |
| 6399 | * |
| 6400 | * @see #isHovered |
| 6401 | * @see #setHovered |
| 6402 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6403 | */ |
| 6404 | public boolean onHoverEvent(MotionEvent event) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 6405 | // The root view may receive hover (or touch) events that are outside the bounds of |
| 6406 | // the window. This code ensures that we only send accessibility events for |
| 6407 | // hovers that are actually within the bounds of the root view. |
| 6408 | final int action = event.getAction(); |
| 6409 | if (!mSendingHoverAccessibilityEvents) { |
| 6410 | if ((action == MotionEvent.ACTION_HOVER_ENTER |
| 6411 | || action == MotionEvent.ACTION_HOVER_MOVE) |
| 6412 | && !hasHoveredChild() |
| 6413 | && pointInView(event.getX(), event.getY())) { |
| 6414 | mSendingHoverAccessibilityEvents = true; |
| 6415 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER); |
| 6416 | } |
| 6417 | } else { |
| 6418 | if (action == MotionEvent.ACTION_HOVER_EXIT |
| 6419 | || (action == MotionEvent.ACTION_HOVER_MOVE |
| 6420 | && !pointInView(event.getX(), event.getY()))) { |
| 6421 | mSendingHoverAccessibilityEvents = false; |
| 6422 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT); |
| 6423 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 6424 | } |
| 6425 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6426 | if (isHoverable()) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 6427 | switch (action) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6428 | case MotionEvent.ACTION_HOVER_ENTER: |
| 6429 | setHovered(true); |
| 6430 | break; |
| 6431 | case MotionEvent.ACTION_HOVER_EXIT: |
| 6432 | setHovered(false); |
| 6433 | break; |
| 6434 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 6435 | |
| 6436 | // Dispatch the event to onGenericMotionEvent before returning true. |
| 6437 | // This is to provide compatibility with existing applications that |
| 6438 | // handled HOVER_MOVE events in onGenericMotionEvent and that would |
| 6439 | // break because of the new default handling for hoverable views |
| 6440 | // in onHoverEvent. |
| 6441 | // Note that onGenericMotionEvent will be called by default when |
| 6442 | // onHoverEvent returns false (refer to dispatchGenericMotionEvent). |
| 6443 | dispatchGenericMotionEventInternal(event); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6444 | return true; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6445 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6446 | return false; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6447 | } |
| 6448 | |
| 6449 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6450 | * Returns true if the view should handle {@link #onHoverEvent} |
| 6451 | * by calling {@link #setHovered} to change its hovered state. |
| 6452 | * |
| 6453 | * @return True if the view is hoverable. |
| 6454 | */ |
| 6455 | private boolean isHoverable() { |
| 6456 | final int viewFlags = mViewFlags; |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 6457 | //noinspection SimplifiableIfStatement |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6458 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
| 6459 | return false; |
| 6460 | } |
| 6461 | |
| 6462 | return (viewFlags & CLICKABLE) == CLICKABLE |
| 6463 | || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 6464 | } |
| 6465 | |
| 6466 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6467 | * Returns true if the view is currently hovered. |
| 6468 | * |
| 6469 | * @return True if the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6470 | * |
| 6471 | * @see #setHovered |
| 6472 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6473 | */ |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6474 | @ViewDebug.ExportedProperty |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6475 | public boolean isHovered() { |
| 6476 | return (mPrivateFlags & HOVERED) != 0; |
| 6477 | } |
| 6478 | |
| 6479 | /** |
| 6480 | * Sets whether the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6481 | * <p> |
| 6482 | * Calling this method also changes the drawable state of the view. This |
| 6483 | * enables the view to react to hover by using different drawable resources |
| 6484 | * to change its appearance. |
| 6485 | * </p><p> |
| 6486 | * The {@link #onHoverChanged} method is called when the hovered state changes. |
| 6487 | * </p> |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6488 | * |
| 6489 | * @param hovered True if the view is hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6490 | * |
| 6491 | * @see #isHovered |
| 6492 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6493 | */ |
| 6494 | public void setHovered(boolean hovered) { |
| 6495 | if (hovered) { |
| 6496 | if ((mPrivateFlags & HOVERED) == 0) { |
| 6497 | mPrivateFlags |= HOVERED; |
| 6498 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6499 | onHoverChanged(true); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6500 | } |
| 6501 | } else { |
| 6502 | if ((mPrivateFlags & HOVERED) != 0) { |
| 6503 | mPrivateFlags &= ~HOVERED; |
| 6504 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6505 | onHoverChanged(false); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6506 | } |
| 6507 | } |
| 6508 | } |
| 6509 | |
| 6510 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6511 | * Implement this method to handle hover state changes. |
| 6512 | * <p> |
| 6513 | * This method is called whenever the hover state changes as a result of a |
| 6514 | * call to {@link #setHovered}. |
| 6515 | * </p> |
| 6516 | * |
| 6517 | * @param hovered The current hover state, as returned by {@link #isHovered}. |
| 6518 | * |
| 6519 | * @see #isHovered |
| 6520 | * @see #setHovered |
| 6521 | */ |
| 6522 | public void onHoverChanged(boolean hovered) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6523 | } |
| 6524 | |
| 6525 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6526 | * Implement this method to handle touch screen motion events. |
| 6527 | * |
| 6528 | * @param event The motion event. |
| 6529 | * @return True if the event was handled, false otherwise. |
| 6530 | */ |
| 6531 | public boolean onTouchEvent(MotionEvent event) { |
| 6532 | final int viewFlags = mViewFlags; |
| 6533 | |
| 6534 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
Svetoslav Ganov | 77b80c0 | 2011-03-15 20:52:58 -0700 | [diff] [blame] | 6535 | if (event.getAction() == MotionEvent.ACTION_UP && (mPrivateFlags & PRESSED) != 0) { |
| 6536 | mPrivateFlags &= ~PRESSED; |
| 6537 | refreshDrawableState(); |
| 6538 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6539 | // A disabled view that is clickable still consumes the touch |
| 6540 | // events, it just doesn't respond to them. |
| 6541 | return (((viewFlags & CLICKABLE) == CLICKABLE || |
| 6542 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)); |
| 6543 | } |
| 6544 | |
| 6545 | if (mTouchDelegate != null) { |
| 6546 | if (mTouchDelegate.onTouchEvent(event)) { |
| 6547 | return true; |
| 6548 | } |
| 6549 | } |
| 6550 | |
| 6551 | if (((viewFlags & CLICKABLE) == CLICKABLE || |
| 6552 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)) { |
| 6553 | switch (event.getAction()) { |
| 6554 | case MotionEvent.ACTION_UP: |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6555 | boolean prepressed = (mPrivateFlags & PREPRESSED) != 0; |
| 6556 | if ((mPrivateFlags & PRESSED) != 0 || prepressed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6557 | // take focus if we don't have it already and we should in |
| 6558 | // touch mode. |
| 6559 | boolean focusTaken = false; |
| 6560 | if (isFocusable() && isFocusableInTouchMode() && !isFocused()) { |
| 6561 | focusTaken = requestFocus(); |
| 6562 | } |
| 6563 | |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 6564 | if (prepressed) { |
| 6565 | // The button is being released before we actually |
| 6566 | // showed it as pressed. Make it show the pressed |
| 6567 | // state now (before scheduling the click) to ensure |
| 6568 | // the user sees it. |
| 6569 | mPrivateFlags |= PRESSED; |
| 6570 | refreshDrawableState(); |
| 6571 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6573 | if (!mHasPerformedLongPress) { |
| 6574 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6575 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6576 | |
| 6577 | // Only perform take click actions if we were in the pressed state |
| 6578 | if (!focusTaken) { |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 6579 | // Use a Runnable and post this rather than calling |
| 6580 | // performClick directly. This lets other visual state |
| 6581 | // of the view update before click actions start. |
| 6582 | if (mPerformClick == null) { |
| 6583 | mPerformClick = new PerformClick(); |
| 6584 | } |
| 6585 | if (!post(mPerformClick)) { |
| 6586 | performClick(); |
| 6587 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6588 | } |
| 6589 | } |
| 6590 | |
| 6591 | if (mUnsetPressedState == null) { |
| 6592 | mUnsetPressedState = new UnsetPressedState(); |
| 6593 | } |
| 6594 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6595 | if (prepressed) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6596 | postDelayed(mUnsetPressedState, |
| 6597 | ViewConfiguration.getPressedStateDuration()); |
| 6598 | } else if (!post(mUnsetPressedState)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6599 | // If the post failed, unpress right now |
| 6600 | mUnsetPressedState.run(); |
| 6601 | } |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6602 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6603 | } |
| 6604 | break; |
| 6605 | |
| 6606 | case MotionEvent.ACTION_DOWN: |
Adam Powell | 3b02339 | 2010-03-11 16:30:28 -0800 | [diff] [blame] | 6607 | mHasPerformedLongPress = false; |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6608 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 6609 | if (performButtonActionOnTouchDown(event)) { |
| 6610 | break; |
| 6611 | } |
| 6612 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6613 | // 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] | 6614 | boolean isInScrollingContainer = isInScrollingContainer(); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 6615 | |
| 6616 | // For views inside a scrolling container, delay the pressed feedback for |
| 6617 | // a short period in case this is a scroll. |
| 6618 | if (isInScrollingContainer) { |
| 6619 | mPrivateFlags |= PREPRESSED; |
| 6620 | if (mPendingCheckForTap == null) { |
| 6621 | mPendingCheckForTap = new CheckForTap(); |
| 6622 | } |
| 6623 | postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); |
| 6624 | } else { |
| 6625 | // Not inside a scrolling container, so show the feedback right away |
| 6626 | mPrivateFlags |= PRESSED; |
| 6627 | refreshDrawableState(); |
| 6628 | checkForLongClick(0); |
| 6629 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6630 | break; |
| 6631 | |
| 6632 | case MotionEvent.ACTION_CANCEL: |
| 6633 | mPrivateFlags &= ~PRESSED; |
| 6634 | refreshDrawableState(); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6635 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6636 | break; |
| 6637 | |
| 6638 | case MotionEvent.ACTION_MOVE: |
| 6639 | final int x = (int) event.getX(); |
| 6640 | final int y = (int) event.getY(); |
| 6641 | |
| 6642 | // Be lenient about moving outside of buttons |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 6643 | if (!pointInView(x, y, mTouchSlop)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6644 | // Outside button |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6645 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6646 | if ((mPrivateFlags & PRESSED) != 0) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6647 | // Remove any future long press/tap checks |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6648 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6649 | |
| 6650 | // Need to switch from pressed to not pressed |
| 6651 | mPrivateFlags &= ~PRESSED; |
| 6652 | refreshDrawableState(); |
| 6653 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6654 | } |
| 6655 | break; |
| 6656 | } |
| 6657 | return true; |
| 6658 | } |
| 6659 | |
| 6660 | return false; |
| 6661 | } |
| 6662 | |
| 6663 | /** |
Adam Powell | 1029866 | 2011-08-14 18:26:30 -0700 | [diff] [blame] | 6664 | * @hide |
| 6665 | */ |
| 6666 | public boolean isInScrollingContainer() { |
| 6667 | ViewParent p = getParent(); |
| 6668 | while (p != null && p instanceof ViewGroup) { |
| 6669 | if (((ViewGroup) p).shouldDelayChildPressedState()) { |
| 6670 | return true; |
| 6671 | } |
| 6672 | p = p.getParent(); |
| 6673 | } |
| 6674 | return false; |
| 6675 | } |
| 6676 | |
| 6677 | /** |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6678 | * Remove the longpress detection timer. |
| 6679 | */ |
| 6680 | private void removeLongPressCallback() { |
| 6681 | if (mPendingCheckForLongPress != null) { |
| 6682 | removeCallbacks(mPendingCheckForLongPress); |
| 6683 | } |
| 6684 | } |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 6685 | |
| 6686 | /** |
| 6687 | * Remove the pending click action |
| 6688 | */ |
| 6689 | private void removePerformClickCallback() { |
| 6690 | if (mPerformClick != null) { |
| 6691 | removeCallbacks(mPerformClick); |
| 6692 | } |
| 6693 | } |
| 6694 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6695 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6696 | * Remove the prepress detection timer. |
| 6697 | */ |
| 6698 | private void removeUnsetPressCallback() { |
| 6699 | if ((mPrivateFlags & PRESSED) != 0 && mUnsetPressedState != null) { |
| 6700 | setPressed(false); |
| 6701 | removeCallbacks(mUnsetPressedState); |
| 6702 | } |
| 6703 | } |
| 6704 | |
| 6705 | /** |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 6706 | * Remove the tap detection timer. |
| 6707 | */ |
| 6708 | private void removeTapCallback() { |
| 6709 | if (mPendingCheckForTap != null) { |
| 6710 | mPrivateFlags &= ~PREPRESSED; |
| 6711 | removeCallbacks(mPendingCheckForTap); |
| 6712 | } |
| 6713 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6714 | |
| 6715 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6716 | * Cancels a pending long press. Your subclass can use this if you |
| 6717 | * want the context menu to come up if the user presses and holds |
| 6718 | * at the same place, but you don't want it to come up if they press |
| 6719 | * and then move around enough to cause scrolling. |
| 6720 | */ |
| 6721 | public void cancelLongPress() { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6722 | removeLongPressCallback(); |
Adam Powell | 732ebb1 | 2010-02-02 15:28:14 -0800 | [diff] [blame] | 6723 | |
| 6724 | /* |
| 6725 | * The prepressed state handled by the tap callback is a display |
| 6726 | * construct, but the tap callback will post a long press callback |
| 6727 | * less its own timeout. Remove it here. |
| 6728 | */ |
| 6729 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6730 | } |
| 6731 | |
| 6732 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6733 | * Remove the pending callback for sending a |
| 6734 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 6735 | */ |
| 6736 | private void removeSendViewScrolledAccessibilityEventCallback() { |
| 6737 | if (mSendViewScrolledAccessibilityEvent != null) { |
| 6738 | removeCallbacks(mSendViewScrolledAccessibilityEvent); |
| 6739 | } |
| 6740 | } |
| 6741 | |
| 6742 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6743 | * Sets the TouchDelegate for this View. |
| 6744 | */ |
| 6745 | public void setTouchDelegate(TouchDelegate delegate) { |
| 6746 | mTouchDelegate = delegate; |
| 6747 | } |
| 6748 | |
| 6749 | /** |
| 6750 | * Gets the TouchDelegate for this View. |
| 6751 | */ |
| 6752 | public TouchDelegate getTouchDelegate() { |
| 6753 | return mTouchDelegate; |
| 6754 | } |
| 6755 | |
| 6756 | /** |
| 6757 | * Set flags controlling behavior of this view. |
| 6758 | * |
| 6759 | * @param flags Constant indicating the value which should be set |
| 6760 | * @param mask Constant indicating the bit range that should be changed |
| 6761 | */ |
| 6762 | void setFlags(int flags, int mask) { |
| 6763 | int old = mViewFlags; |
| 6764 | mViewFlags = (mViewFlags & ~mask) | (flags & mask); |
| 6765 | |
| 6766 | int changed = mViewFlags ^ old; |
| 6767 | if (changed == 0) { |
| 6768 | return; |
| 6769 | } |
| 6770 | int privateFlags = mPrivateFlags; |
| 6771 | |
| 6772 | /* Check if the FOCUSABLE bit has changed */ |
| 6773 | if (((changed & FOCUSABLE_MASK) != 0) && |
| 6774 | ((privateFlags & HAS_BOUNDS) !=0)) { |
| 6775 | if (((old & FOCUSABLE_MASK) == FOCUSABLE) |
| 6776 | && ((privateFlags & FOCUSED) != 0)) { |
| 6777 | /* Give up focus if we are no longer focusable */ |
| 6778 | clearFocus(); |
| 6779 | } else if (((old & FOCUSABLE_MASK) == NOT_FOCUSABLE) |
| 6780 | && ((privateFlags & FOCUSED) == 0)) { |
| 6781 | /* |
| 6782 | * Tell the view system that we are now available to take focus |
| 6783 | * if no one else already has it. |
| 6784 | */ |
| 6785 | if (mParent != null) mParent.focusableViewAvailable(this); |
| 6786 | } |
| 6787 | } |
| 6788 | |
| 6789 | if ((flags & VISIBILITY_MASK) == VISIBLE) { |
| 6790 | if ((changed & VISIBILITY_MASK) != 0) { |
| 6791 | /* |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 6792 | * 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] | 6793 | * it was not visible. Marking it drawn ensures that the invalidation will |
| 6794 | * go through. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6795 | */ |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 6796 | mPrivateFlags |= DRAWN; |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 6797 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6798 | |
| 6799 | needGlobalAttributesUpdate(true); |
| 6800 | |
| 6801 | // a view becoming visible is worth notifying the parent |
| 6802 | // about in case nothing has focus. even if this specific view |
| 6803 | // isn't focusable, it may contain something that is, so let |
| 6804 | // the root view try to give this focus if nothing else does. |
| 6805 | if ((mParent != null) && (mBottom > mTop) && (mRight > mLeft)) { |
| 6806 | mParent.focusableViewAvailable(this); |
| 6807 | } |
| 6808 | } |
| 6809 | } |
| 6810 | |
| 6811 | /* Check if the GONE bit has changed */ |
| 6812 | if ((changed & GONE) != 0) { |
| 6813 | needGlobalAttributesUpdate(false); |
| 6814 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6815 | |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 6816 | if (((mViewFlags & VISIBILITY_MASK) == GONE)) { |
| 6817 | if (hasFocus()) clearFocus(); |
| 6818 | destroyDrawingCache(); |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 6819 | if (mParent instanceof View) { |
| 6820 | // GONE views noop invalidation, so invalidate the parent |
| 6821 | ((View) mParent).invalidate(true); |
| 6822 | } |
| 6823 | // Mark the view drawn to ensure that it gets invalidated properly the next |
| 6824 | // time it is visible and gets invalidated |
| 6825 | mPrivateFlags |= DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6826 | } |
| 6827 | if (mAttachInfo != null) { |
| 6828 | mAttachInfo.mViewVisibilityChanged = true; |
| 6829 | } |
| 6830 | } |
| 6831 | |
| 6832 | /* Check if the VISIBLE bit has changed */ |
| 6833 | if ((changed & INVISIBLE) != 0) { |
| 6834 | needGlobalAttributesUpdate(false); |
Chet Haase | c8a9a70 | 2011-06-17 12:13:42 -0700 | [diff] [blame] | 6835 | /* |
| 6836 | * If this view is becoming invisible, set the DRAWN flag so that |
| 6837 | * the next invalidate() will not be skipped. |
| 6838 | */ |
| 6839 | mPrivateFlags |= DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6840 | |
| 6841 | if (((mViewFlags & VISIBILITY_MASK) == INVISIBLE) && hasFocus()) { |
| 6842 | // root view becoming invisible shouldn't clear focus |
| 6843 | if (getRootView() != this) { |
| 6844 | clearFocus(); |
| 6845 | } |
| 6846 | } |
| 6847 | if (mAttachInfo != null) { |
| 6848 | mAttachInfo.mViewVisibilityChanged = true; |
| 6849 | } |
| 6850 | } |
| 6851 | |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6852 | if ((changed & VISIBILITY_MASK) != 0) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 6853 | if (mParent instanceof ViewGroup) { |
Chet Haase | 0d29936 | 2012-01-26 10:51:48 -0800 | [diff] [blame] | 6854 | ((ViewGroup) mParent).onChildVisibilityChanged(this, (changed & VISIBILITY_MASK), |
| 6855 | (flags & VISIBILITY_MASK)); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 6856 | ((View) mParent).invalidate(true); |
Chet Haase | e4e6e20 | 2011-08-29 14:34:30 -0700 | [diff] [blame] | 6857 | } else if (mParent != null) { |
| 6858 | mParent.invalidateChild(this, null); |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 6859 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6860 | dispatchVisibilityChanged(this, (flags & VISIBILITY_MASK)); |
| 6861 | } |
| 6862 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6863 | if ((changed & WILL_NOT_CACHE_DRAWING) != 0) { |
| 6864 | destroyDrawingCache(); |
| 6865 | } |
| 6866 | |
| 6867 | if ((changed & DRAWING_CACHE_ENABLED) != 0) { |
| 6868 | destroyDrawingCache(); |
| 6869 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 6870 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6871 | } |
| 6872 | |
| 6873 | if ((changed & DRAWING_CACHE_QUALITY_MASK) != 0) { |
| 6874 | destroyDrawingCache(); |
| 6875 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 6876 | } |
| 6877 | |
| 6878 | if ((changed & DRAW_MASK) != 0) { |
| 6879 | if ((mViewFlags & WILL_NOT_DRAW) != 0) { |
| 6880 | if (mBGDrawable != null) { |
| 6881 | mPrivateFlags &= ~SKIP_DRAW; |
| 6882 | mPrivateFlags |= ONLY_DRAWS_BACKGROUND; |
| 6883 | } else { |
| 6884 | mPrivateFlags |= SKIP_DRAW; |
| 6885 | } |
| 6886 | } else { |
| 6887 | mPrivateFlags &= ~SKIP_DRAW; |
| 6888 | } |
| 6889 | requestLayout(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 6890 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6891 | } |
| 6892 | |
| 6893 | if ((changed & KEEP_SCREEN_ON) != 0) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6894 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6895 | mParent.recomputeViewAttributes(this); |
| 6896 | } |
| 6897 | } |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 6898 | |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 6899 | if ((changed & LAYOUT_DIRECTION_MASK) != 0) { |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 6900 | requestLayout(); |
| 6901 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6902 | } |
| 6903 | |
| 6904 | /** |
| 6905 | * Change the view's z order in the tree, so it's on top of other sibling |
| 6906 | * views |
| 6907 | */ |
| 6908 | public void bringToFront() { |
| 6909 | if (mParent != null) { |
| 6910 | mParent.bringChildToFront(this); |
| 6911 | } |
| 6912 | } |
| 6913 | |
| 6914 | /** |
| 6915 | * This is called in response to an internal scroll in this view (i.e., the |
| 6916 | * view scrolled its own contents). This is typically as a result of |
| 6917 | * {@link #scrollBy(int, int)} or {@link #scrollTo(int, int)} having been |
| 6918 | * called. |
| 6919 | * |
| 6920 | * @param l Current horizontal scroll origin. |
| 6921 | * @param t Current vertical scroll origin. |
| 6922 | * @param oldl Previous horizontal scroll origin. |
| 6923 | * @param oldt Previous vertical scroll origin. |
| 6924 | */ |
| 6925 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6926 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 6927 | postSendViewScrolledAccessibilityEventCallback(); |
| 6928 | } |
| 6929 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6930 | mBackgroundSizeChanged = true; |
| 6931 | |
| 6932 | final AttachInfo ai = mAttachInfo; |
| 6933 | if (ai != null) { |
| 6934 | ai.mViewScrollChanged = true; |
| 6935 | } |
| 6936 | } |
| 6937 | |
| 6938 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 6939 | * Interface definition for a callback to be invoked when the layout bounds of a view |
| 6940 | * changes due to layout processing. |
| 6941 | */ |
| 6942 | public interface OnLayoutChangeListener { |
| 6943 | /** |
| 6944 | * Called when the focus state of a view has changed. |
| 6945 | * |
| 6946 | * @param v The view whose state has changed. |
| 6947 | * @param left The new value of the view's left property. |
| 6948 | * @param top The new value of the view's top property. |
| 6949 | * @param right The new value of the view's right property. |
| 6950 | * @param bottom The new value of the view's bottom property. |
| 6951 | * @param oldLeft The previous value of the view's left property. |
| 6952 | * @param oldTop The previous value of the view's top property. |
| 6953 | * @param oldRight The previous value of the view's right property. |
| 6954 | * @param oldBottom The previous value of the view's bottom property. |
| 6955 | */ |
| 6956 | void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 6957 | int oldLeft, int oldTop, int oldRight, int oldBottom); |
| 6958 | } |
| 6959 | |
| 6960 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6961 | * This is called during layout when the size of this view has changed. If |
| 6962 | * you were just added to the view hierarchy, you're called with the old |
| 6963 | * values of 0. |
| 6964 | * |
| 6965 | * @param w Current width of this view. |
| 6966 | * @param h Current height of this view. |
| 6967 | * @param oldw Old width of this view. |
| 6968 | * @param oldh Old height of this view. |
| 6969 | */ |
| 6970 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 6971 | } |
| 6972 | |
| 6973 | /** |
| 6974 | * Called by draw to draw the child views. This may be overridden |
| 6975 | * by derived classes to gain control just before its children are drawn |
| 6976 | * (but after its own view has been drawn). |
| 6977 | * @param canvas the canvas on which to draw the view |
| 6978 | */ |
| 6979 | protected void dispatchDraw(Canvas canvas) { |
| 6980 | } |
| 6981 | |
| 6982 | /** |
| 6983 | * Gets the parent of this view. Note that the parent is a |
| 6984 | * ViewParent and not necessarily a View. |
| 6985 | * |
| 6986 | * @return Parent of this view. |
| 6987 | */ |
| 6988 | public final ViewParent getParent() { |
| 6989 | return mParent; |
| 6990 | } |
| 6991 | |
| 6992 | /** |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 6993 | * Set the horizontal scrolled position of your view. This will cause a call to |
| 6994 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 6995 | * invalidated. |
| 6996 | * @param value the x position to scroll to |
| 6997 | */ |
| 6998 | public void setScrollX(int value) { |
| 6999 | scrollTo(value, mScrollY); |
| 7000 | } |
| 7001 | |
| 7002 | /** |
| 7003 | * Set the vertical scrolled position of your view. This will cause a call to |
| 7004 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 7005 | * invalidated. |
| 7006 | * @param value the y position to scroll to |
| 7007 | */ |
| 7008 | public void setScrollY(int value) { |
| 7009 | scrollTo(mScrollX, value); |
| 7010 | } |
| 7011 | |
| 7012 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7013 | * Return the scrolled left position of this view. This is the left edge of |
| 7014 | * the displayed part of your view. You do not need to draw any pixels |
| 7015 | * farther left, since those are outside of the frame of your view on |
| 7016 | * screen. |
| 7017 | * |
| 7018 | * @return The left edge of the displayed part of your view, in pixels. |
| 7019 | */ |
| 7020 | public final int getScrollX() { |
| 7021 | return mScrollX; |
| 7022 | } |
| 7023 | |
| 7024 | /** |
| 7025 | * Return the scrolled top position of this view. This is the top edge of |
| 7026 | * the displayed part of your view. You do not need to draw any pixels above |
| 7027 | * it, since those are outside of the frame of your view on screen. |
| 7028 | * |
| 7029 | * @return The top edge of the displayed part of your view, in pixels. |
| 7030 | */ |
| 7031 | public final int getScrollY() { |
| 7032 | return mScrollY; |
| 7033 | } |
| 7034 | |
| 7035 | /** |
| 7036 | * Return the width of the your view. |
| 7037 | * |
| 7038 | * @return The width of your view, in pixels. |
| 7039 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 7040 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7041 | public final int getWidth() { |
| 7042 | return mRight - mLeft; |
| 7043 | } |
| 7044 | |
| 7045 | /** |
| 7046 | * Return the height of your view. |
| 7047 | * |
| 7048 | * @return The height of your view, in pixels. |
| 7049 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 7050 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7051 | public final int getHeight() { |
| 7052 | return mBottom - mTop; |
| 7053 | } |
| 7054 | |
| 7055 | /** |
| 7056 | * Return the visible drawing bounds of your view. Fills in the output |
| 7057 | * rectangle with the values from getScrollX(), getScrollY(), |
| 7058 | * getWidth(), and getHeight(). |
| 7059 | * |
| 7060 | * @param outRect The (scrolled) drawing bounds of the view. |
| 7061 | */ |
| 7062 | public void getDrawingRect(Rect outRect) { |
| 7063 | outRect.left = mScrollX; |
| 7064 | outRect.top = mScrollY; |
| 7065 | outRect.right = mScrollX + (mRight - mLeft); |
| 7066 | outRect.bottom = mScrollY + (mBottom - mTop); |
| 7067 | } |
| 7068 | |
| 7069 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7070 | * Like {@link #getMeasuredWidthAndState()}, but only returns the |
| 7071 | * raw width component (that is the result is masked by |
| 7072 | * {@link #MEASURED_SIZE_MASK}). |
| 7073 | * |
| 7074 | * @return The raw measured width of this view. |
| 7075 | */ |
| 7076 | public final int getMeasuredWidth() { |
| 7077 | return mMeasuredWidth & MEASURED_SIZE_MASK; |
| 7078 | } |
| 7079 | |
| 7080 | /** |
| 7081 | * Return the full width measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7082 | * 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] | 7083 | * 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] | 7084 | * This should be used during measurement and layout calculations only. Use |
| 7085 | * {@link #getWidth()} to see how wide a view is after layout. |
| 7086 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7087 | * @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] | 7088 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7089 | public final int getMeasuredWidthAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7090 | return mMeasuredWidth; |
| 7091 | } |
| 7092 | |
| 7093 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7094 | * Like {@link #getMeasuredHeightAndState()}, but only returns the |
| 7095 | * raw width component (that is the result is masked by |
| 7096 | * {@link #MEASURED_SIZE_MASK}). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7097 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7098 | * @return The raw measured height of this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7099 | */ |
| 7100 | public final int getMeasuredHeight() { |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7101 | return mMeasuredHeight & MEASURED_SIZE_MASK; |
| 7102 | } |
| 7103 | |
| 7104 | /** |
| 7105 | * Return the full height measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7106 | * 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] | 7107 | * as defined by {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. |
| 7108 | * This should be used during measurement and layout calculations only. Use |
| 7109 | * {@link #getHeight()} to see how wide a view is after layout. |
| 7110 | * |
| 7111 | * @return The measured width of this view as a bit mask. |
| 7112 | */ |
| 7113 | public final int getMeasuredHeightAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7114 | return mMeasuredHeight; |
| 7115 | } |
| 7116 | |
| 7117 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 7118 | * Return only the state bits of {@link #getMeasuredWidthAndState()} |
| 7119 | * and {@link #getMeasuredHeightAndState()}, combined into one integer. |
| 7120 | * The width component is in the regular bits {@link #MEASURED_STATE_MASK} |
| 7121 | * and the height component is at the shifted bits |
| 7122 | * {@link #MEASURED_HEIGHT_STATE_SHIFT}>>{@link #MEASURED_STATE_MASK}. |
| 7123 | */ |
| 7124 | public final int getMeasuredState() { |
| 7125 | return (mMeasuredWidth&MEASURED_STATE_MASK) |
| 7126 | | ((mMeasuredHeight>>MEASURED_HEIGHT_STATE_SHIFT) |
| 7127 | & (MEASURED_STATE_MASK>>MEASURED_HEIGHT_STATE_SHIFT)); |
| 7128 | } |
| 7129 | |
| 7130 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7131 | * The transform matrix of this view, which is calculated based on the current |
| 7132 | * roation, scale, and pivot properties. |
| 7133 | * |
| 7134 | * @see #getRotation() |
| 7135 | * @see #getScaleX() |
| 7136 | * @see #getScaleY() |
| 7137 | * @see #getPivotX() |
| 7138 | * @see #getPivotY() |
| 7139 | * @return The current transform matrix for the view |
| 7140 | */ |
| 7141 | public Matrix getMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7142 | if (mTransformationInfo != null) { |
| 7143 | updateMatrix(); |
| 7144 | return mTransformationInfo.mMatrix; |
| 7145 | } |
| 7146 | return Matrix.IDENTITY_MATRIX; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7147 | } |
| 7148 | |
| 7149 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7150 | * Utility function to determine if the value is far enough away from zero to be |
| 7151 | * considered non-zero. |
| 7152 | * @param value A floating point value to check for zero-ness |
| 7153 | * @return whether the passed-in value is far enough away from zero to be considered non-zero |
| 7154 | */ |
| 7155 | private static boolean nonzero(float value) { |
| 7156 | return (value < -NONZERO_EPSILON || value > NONZERO_EPSILON); |
| 7157 | } |
| 7158 | |
| 7159 | /** |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7160 | * Returns true if the transform matrix is the identity matrix. |
| 7161 | * Recomputes the matrix if necessary. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7162 | * |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7163 | * @return True if the transform matrix is the identity matrix, false otherwise. |
| 7164 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7165 | final boolean hasIdentityMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7166 | if (mTransformationInfo != null) { |
| 7167 | updateMatrix(); |
| 7168 | return mTransformationInfo.mMatrixIsIdentity; |
| 7169 | } |
| 7170 | return true; |
| 7171 | } |
| 7172 | |
| 7173 | void ensureTransformationInfo() { |
| 7174 | if (mTransformationInfo == null) { |
| 7175 | mTransformationInfo = new TransformationInfo(); |
| 7176 | } |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7177 | } |
| 7178 | |
| 7179 | /** |
| 7180 | * Recomputes the transform matrix if necessary. |
| 7181 | */ |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 7182 | private void updateMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7183 | final TransformationInfo info = mTransformationInfo; |
| 7184 | if (info == null) { |
| 7185 | return; |
| 7186 | } |
| 7187 | if (info.mMatrixDirty) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7188 | // transform-related properties have changed since the last time someone |
| 7189 | // asked for the matrix; recalculate it with the current values |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7190 | |
| 7191 | // Figure out if we need to update the pivot point |
| 7192 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7193 | if ((mRight - mLeft) != info.mPrevWidth || (mBottom - mTop) != info.mPrevHeight) { |
| 7194 | info.mPrevWidth = mRight - mLeft; |
| 7195 | info.mPrevHeight = mBottom - mTop; |
| 7196 | info.mPivotX = info.mPrevWidth / 2f; |
| 7197 | info.mPivotY = info.mPrevHeight / 2f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7198 | } |
| 7199 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7200 | info.mMatrix.reset(); |
| 7201 | if (!nonzero(info.mRotationX) && !nonzero(info.mRotationY)) { |
| 7202 | info.mMatrix.setTranslate(info.mTranslationX, info.mTranslationY); |
| 7203 | info.mMatrix.preRotate(info.mRotation, info.mPivotX, info.mPivotY); |
| 7204 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7205 | } else { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7206 | if (info.mCamera == null) { |
| 7207 | info.mCamera = new Camera(); |
| 7208 | info.matrix3D = new Matrix(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7209 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7210 | info.mCamera.save(); |
| 7211 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
| 7212 | info.mCamera.rotate(info.mRotationX, info.mRotationY, -info.mRotation); |
| 7213 | info.mCamera.getMatrix(info.matrix3D); |
| 7214 | info.matrix3D.preTranslate(-info.mPivotX, -info.mPivotY); |
| 7215 | info.matrix3D.postTranslate(info.mPivotX + info.mTranslationX, |
| 7216 | info.mPivotY + info.mTranslationY); |
| 7217 | info.mMatrix.postConcat(info.matrix3D); |
| 7218 | info.mCamera.restore(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7219 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7220 | info.mMatrixDirty = false; |
| 7221 | info.mMatrixIsIdentity = info.mMatrix.isIdentity(); |
| 7222 | info.mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7223 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7224 | } |
| 7225 | |
| 7226 | /** |
| 7227 | * Utility method to retrieve the inverse of the current mMatrix property. |
| 7228 | * We cache the matrix to avoid recalculating it when transform properties |
| 7229 | * have not changed. |
| 7230 | * |
| 7231 | * @return The inverse of the current matrix of this view. |
| 7232 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7233 | final Matrix getInverseMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7234 | final TransformationInfo info = mTransformationInfo; |
| 7235 | if (info != null) { |
| 7236 | updateMatrix(); |
| 7237 | if (info.mInverseMatrixDirty) { |
| 7238 | if (info.mInverseMatrix == null) { |
| 7239 | info.mInverseMatrix = new Matrix(); |
| 7240 | } |
| 7241 | info.mMatrix.invert(info.mInverseMatrix); |
| 7242 | info.mInverseMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7243 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7244 | return info.mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7245 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7246 | return Matrix.IDENTITY_MATRIX; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7247 | } |
| 7248 | |
| 7249 | /** |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7250 | * <p>Sets the distance along the Z axis (orthogonal to the X/Y plane on which |
| 7251 | * views are drawn) from the camera to this view. The camera's distance |
| 7252 | * affects 3D transformations, for instance rotations around the X and Y |
| 7253 | * axis. If the rotationX or rotationY properties are changed and this view is |
| 7254 | * large (more than half the size of the screen), it is recommended to always |
| 7255 | * use a camera distance that's greater than the height (X axis rotation) or |
| 7256 | * the width (Y axis rotation) of this view.</p> |
| 7257 | * |
| 7258 | * <p>The distance of the camera from the view plane can have an affect on the |
| 7259 | * perspective distortion of the view when it is rotated around the x or y axis. |
| 7260 | * For example, a large distance will result in a large viewing angle, and there |
| 7261 | * will not be much perspective distortion of the view as it rotates. A short |
| 7262 | * distance may cause much more perspective distortion upon rotation, and can |
| 7263 | * also result in some drawing artifacts if the rotated view ends up partially |
| 7264 | * behind the camera (which is why the recommendation is to use a distance at |
| 7265 | * least as far as the size of the view, if the view is to be rotated.)</p> |
| 7266 | * |
| 7267 | * <p>The distance is expressed in "depth pixels." The default distance depends |
| 7268 | * on the screen density. For instance, on a medium density display, the |
| 7269 | * default distance is 1280. On a high density display, the default distance |
| 7270 | * is 1920.</p> |
| 7271 | * |
| 7272 | * <p>If you want to specify a distance that leads to visually consistent |
| 7273 | * results across various densities, use the following formula:</p> |
| 7274 | * <pre> |
| 7275 | * float scale = context.getResources().getDisplayMetrics().density; |
| 7276 | * view.setCameraDistance(distance * scale); |
| 7277 | * </pre> |
| 7278 | * |
| 7279 | * <p>The density scale factor of a high density display is 1.5, |
| 7280 | * and 1920 = 1280 * 1.5.</p> |
| 7281 | * |
| 7282 | * @param distance The distance in "depth pixels", if negative the opposite |
| 7283 | * value is used |
| 7284 | * |
| 7285 | * @see #setRotationX(float) |
| 7286 | * @see #setRotationY(float) |
| 7287 | */ |
| 7288 | public void setCameraDistance(float distance) { |
| 7289 | invalidateParentCaches(); |
| 7290 | invalidate(false); |
| 7291 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7292 | ensureTransformationInfo(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7293 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7294 | final TransformationInfo info = mTransformationInfo; |
| 7295 | if (info.mCamera == null) { |
| 7296 | info.mCamera = new Camera(); |
| 7297 | info.matrix3D = new Matrix(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7298 | } |
| 7299 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7300 | info.mCamera.setLocation(0.0f, 0.0f, -Math.abs(distance) / dpi); |
| 7301 | info.mMatrixDirty = true; |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7302 | |
| 7303 | invalidate(false); |
| 7304 | } |
| 7305 | |
| 7306 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7307 | * The degrees that the view is rotated around the pivot point. |
| 7308 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7309 | * @see #setRotation(float) |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7310 | * @see #getPivotX() |
| 7311 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7312 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7313 | * @return The degrees of rotation. |
| 7314 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7315 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7316 | public float getRotation() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7317 | return mTransformationInfo != null ? mTransformationInfo.mRotation : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7318 | } |
| 7319 | |
| 7320 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7321 | * Sets the degrees that the view is rotated around the pivot point. Increasing values |
| 7322 | * result in clockwise rotation. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7323 | * |
| 7324 | * @param rotation The degrees of rotation. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7325 | * |
| 7326 | * @see #getRotation() |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7327 | * @see #getPivotX() |
| 7328 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7329 | * @see #setRotationX(float) |
| 7330 | * @see #setRotationY(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7331 | * |
| 7332 | * @attr ref android.R.styleable#View_rotation |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7333 | */ |
| 7334 | public void setRotation(float rotation) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7335 | ensureTransformationInfo(); |
| 7336 | final TransformationInfo info = mTransformationInfo; |
| 7337 | if (info.mRotation != rotation) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7338 | invalidateParentCaches(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7339 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7340 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7341 | info.mRotation = rotation; |
| 7342 | info.mMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7343 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7344 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7345 | } |
| 7346 | } |
| 7347 | |
| 7348 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7349 | * The degrees that the view is rotated around the vertical axis through the pivot point. |
| 7350 | * |
| 7351 | * @see #getPivotX() |
| 7352 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7353 | * @see #setRotationY(float) |
| 7354 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7355 | * @return The degrees of Y rotation. |
| 7356 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7357 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7358 | public float getRotationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7359 | return mTransformationInfo != null ? mTransformationInfo.mRotationY : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7360 | } |
| 7361 | |
| 7362 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7363 | * Sets the degrees that the view is rotated around the vertical axis through the pivot point. |
| 7364 | * Increasing values result in counter-clockwise rotation from the viewpoint of looking |
| 7365 | * down the y axis. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7366 | * |
| 7367 | * When rotating large views, it is recommended to adjust the camera distance |
| 7368 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7369 | * |
| 7370 | * @param rotationY The degrees of Y rotation. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7371 | * |
| 7372 | * @see #getRotationY() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7373 | * @see #getPivotX() |
| 7374 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7375 | * @see #setRotation(float) |
| 7376 | * @see #setRotationX(float) |
| 7377 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7378 | * |
| 7379 | * @attr ref android.R.styleable#View_rotationY |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7380 | */ |
| 7381 | public void setRotationY(float rotationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7382 | ensureTransformationInfo(); |
| 7383 | final TransformationInfo info = mTransformationInfo; |
| 7384 | if (info.mRotationY != rotationY) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7385 | invalidateParentCaches(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7386 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7387 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7388 | info.mRotationY = rotationY; |
| 7389 | info.mMatrixDirty = true; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7390 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7391 | invalidate(false); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7392 | } |
| 7393 | } |
| 7394 | |
| 7395 | /** |
| 7396 | * The degrees that the view is rotated around the horizontal axis through the pivot point. |
| 7397 | * |
| 7398 | * @see #getPivotX() |
| 7399 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7400 | * @see #setRotationX(float) |
| 7401 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7402 | * @return The degrees of X rotation. |
| 7403 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7404 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7405 | public float getRotationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7406 | return mTransformationInfo != null ? mTransformationInfo.mRotationX : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7407 | } |
| 7408 | |
| 7409 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 7410 | * Sets the degrees that the view is rotated around the horizontal axis through the pivot point. |
| 7411 | * Increasing values result in clockwise rotation from the viewpoint of looking down the |
| 7412 | * x axis. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7413 | * |
| 7414 | * When rotating large views, it is recommended to adjust the camera distance |
| 7415 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7416 | * |
| 7417 | * @param rotationX The degrees of X rotation. |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7418 | * |
| 7419 | * @see #getRotationX() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7420 | * @see #getPivotX() |
| 7421 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 7422 | * @see #setRotation(float) |
| 7423 | * @see #setRotationY(float) |
| 7424 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7425 | * |
| 7426 | * @attr ref android.R.styleable#View_rotationX |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7427 | */ |
| 7428 | public void setRotationX(float rotationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7429 | ensureTransformationInfo(); |
| 7430 | final TransformationInfo info = mTransformationInfo; |
| 7431 | if (info.mRotationX != rotationX) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7432 | invalidateParentCaches(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7433 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7434 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7435 | info.mRotationX = rotationX; |
| 7436 | info.mMatrixDirty = true; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7437 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7438 | invalidate(false); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7439 | } |
| 7440 | } |
| 7441 | |
| 7442 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7443 | * The amount that the view is scaled in x around the pivot point, as a proportion of |
| 7444 | * the view's unscaled width. A value of 1, the default, means that no scaling is applied. |
| 7445 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 7446 | * <p>By default, this is 1.0f. |
| 7447 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7448 | * @see #getPivotX() |
| 7449 | * @see #getPivotY() |
| 7450 | * @return The scaling factor. |
| 7451 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7452 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7453 | public float getScaleX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7454 | return mTransformationInfo != null ? mTransformationInfo.mScaleX : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7455 | } |
| 7456 | |
| 7457 | /** |
| 7458 | * Sets the amount that the view is scaled in x around the pivot point, as a proportion of |
| 7459 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 7460 | * |
| 7461 | * @param scaleX The scaling factor. |
| 7462 | * @see #getPivotX() |
| 7463 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7464 | * |
| 7465 | * @attr ref android.R.styleable#View_scaleX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7466 | */ |
| 7467 | public void setScaleX(float scaleX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7468 | ensureTransformationInfo(); |
| 7469 | final TransformationInfo info = mTransformationInfo; |
| 7470 | if (info.mScaleX != scaleX) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7471 | invalidateParentCaches(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7472 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7473 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7474 | info.mScaleX = scaleX; |
| 7475 | info.mMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7476 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7477 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7478 | } |
| 7479 | } |
| 7480 | |
| 7481 | /** |
| 7482 | * The amount that the view is scaled in y around the pivot point, as a proportion of |
| 7483 | * the view's unscaled height. A value of 1, the default, means that no scaling is applied. |
| 7484 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 7485 | * <p>By default, this is 1.0f. |
| 7486 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7487 | * @see #getPivotX() |
| 7488 | * @see #getPivotY() |
| 7489 | * @return The scaling factor. |
| 7490 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7491 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7492 | public float getScaleY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7493 | return mTransformationInfo != null ? mTransformationInfo.mScaleY : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7494 | } |
| 7495 | |
| 7496 | /** |
| 7497 | * Sets the amount that the view is scaled in Y around the pivot point, as a proportion of |
| 7498 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 7499 | * |
| 7500 | * @param scaleY The scaling factor. |
| 7501 | * @see #getPivotX() |
| 7502 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7503 | * |
| 7504 | * @attr ref android.R.styleable#View_scaleY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7505 | */ |
| 7506 | public void setScaleY(float scaleY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7507 | ensureTransformationInfo(); |
| 7508 | final TransformationInfo info = mTransformationInfo; |
| 7509 | if (info.mScaleY != scaleY) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7510 | invalidateParentCaches(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7511 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7512 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7513 | info.mScaleY = scaleY; |
| 7514 | info.mMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7515 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7516 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7517 | } |
| 7518 | } |
| 7519 | |
| 7520 | /** |
| 7521 | * The x location of the point around which the view is {@link #setRotation(float) rotated} |
| 7522 | * and {@link #setScaleX(float) scaled}. |
| 7523 | * |
| 7524 | * @see #getRotation() |
| 7525 | * @see #getScaleX() |
| 7526 | * @see #getScaleY() |
| 7527 | * @see #getPivotY() |
| 7528 | * @return The x location of the pivot point. |
| 7529 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7530 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7531 | public float getPivotX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7532 | return mTransformationInfo != null ? mTransformationInfo.mPivotX : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7533 | } |
| 7534 | |
| 7535 | /** |
| 7536 | * Sets the x location of the point around which the view is |
| 7537 | * {@link #setRotation(float) rotated} and {@link #setScaleX(float) scaled}. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7538 | * By default, the pivot point is centered on the object. |
| 7539 | * Setting this property disables this behavior and causes the view to use only the |
| 7540 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7541 | * |
| 7542 | * @param pivotX The x location of the pivot point. |
| 7543 | * @see #getRotation() |
| 7544 | * @see #getScaleX() |
| 7545 | * @see #getScaleY() |
| 7546 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7547 | * |
| 7548 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7549 | */ |
| 7550 | public void setPivotX(float pivotX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7551 | ensureTransformationInfo(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7552 | mPrivateFlags |= PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7553 | final TransformationInfo info = mTransformationInfo; |
| 7554 | if (info.mPivotX != pivotX) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7555 | invalidateParentCaches(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7556 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7557 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7558 | info.mPivotX = pivotX; |
| 7559 | info.mMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7560 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7561 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7562 | } |
| 7563 | } |
| 7564 | |
| 7565 | /** |
| 7566 | * The y location of the point around which the view is {@link #setRotation(float) rotated} |
| 7567 | * and {@link #setScaleY(float) scaled}. |
| 7568 | * |
| 7569 | * @see #getRotation() |
| 7570 | * @see #getScaleX() |
| 7571 | * @see #getScaleY() |
| 7572 | * @see #getPivotY() |
| 7573 | * @return The y location of the pivot point. |
| 7574 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7575 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7576 | public float getPivotY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7577 | return mTransformationInfo != null ? mTransformationInfo.mPivotY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7578 | } |
| 7579 | |
| 7580 | /** |
| 7581 | * 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] | 7582 | * and {@link #setScaleY(float) scaled}. By default, the pivot point is centered on the object. |
| 7583 | * Setting this property disables this behavior and causes the view to use only the |
| 7584 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7585 | * |
| 7586 | * @param pivotY The y location of the pivot point. |
| 7587 | * @see #getRotation() |
| 7588 | * @see #getScaleX() |
| 7589 | * @see #getScaleY() |
| 7590 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7591 | * |
| 7592 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7593 | */ |
| 7594 | public void setPivotY(float pivotY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7595 | ensureTransformationInfo(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 7596 | mPrivateFlags |= PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7597 | final TransformationInfo info = mTransformationInfo; |
| 7598 | if (info.mPivotY != pivotY) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7599 | invalidateParentCaches(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7600 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7601 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7602 | info.mPivotY = pivotY; |
| 7603 | info.mMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7604 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7605 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7606 | } |
| 7607 | } |
| 7608 | |
| 7609 | /** |
| 7610 | * The opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 7611 | * completely transparent and 1 means the view is completely opaque. |
| 7612 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 7613 | * <p>By default this is 1.0f. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7614 | * @return The opacity of the view. |
| 7615 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7616 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7617 | public float getAlpha() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7618 | return mTransformationInfo != null ? mTransformationInfo.mAlpha : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7619 | } |
| 7620 | |
| 7621 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 7622 | * <p>Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 7623 | * completely transparent and 1 means the view is completely opaque.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7624 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 7625 | * <p>If this view overrides {@link #onSetAlpha(int)} to return true, then this view is |
| 7626 | * responsible for applying the opacity itself. Otherwise, calling this method is |
| 7627 | * equivalent to calling {@link #setLayerType(int, android.graphics.Paint)} and |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7628 | * setting a hardware layer.</p> |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7629 | * |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7630 | * <p>Note that setting alpha to a translucent value (0 < alpha < 1) may have |
| 7631 | * performance implications. It is generally best to use the alpha property sparingly and |
| 7632 | * transiently, as in the case of fading animations.</p> |
| 7633 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7634 | * @param alpha The opacity of the view. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7635 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7636 | * @see #setLayerType(int, android.graphics.Paint) |
| 7637 | * |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7638 | * @attr ref android.R.styleable#View_alpha |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7639 | */ |
| 7640 | public void setAlpha(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7641 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 7642 | if (mTransformationInfo.mAlpha != alpha) { |
| 7643 | mTransformationInfo.mAlpha = alpha; |
| 7644 | invalidateParentCaches(); |
| 7645 | if (onSetAlpha((int) (alpha * 255))) { |
| 7646 | mPrivateFlags |= ALPHA_SET; |
| 7647 | // subclass is handling alpha - don't optimize rendering cache invalidation |
| 7648 | invalidate(true); |
| 7649 | } else { |
| 7650 | mPrivateFlags &= ~ALPHA_SET; |
| 7651 | invalidate(false); |
| 7652 | } |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7653 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7654 | } |
| 7655 | |
| 7656 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 7657 | * Faster version of setAlpha() which performs the same steps except there are |
| 7658 | * no calls to invalidate(). The caller of this function should perform proper invalidation |
| 7659 | * on the parent and this object. The return value indicates whether the subclass handles |
| 7660 | * alpha (the return value for onSetAlpha()). |
| 7661 | * |
| 7662 | * @param alpha The new value for the alpha property |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 7663 | * @return true if the View subclass handles alpha (the return value for onSetAlpha()) and |
| 7664 | * the new value for the alpha property is different from the old value |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 7665 | */ |
| 7666 | boolean setAlphaNoInvalidation(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7667 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 7668 | if (mTransformationInfo.mAlpha != alpha) { |
| 7669 | mTransformationInfo.mAlpha = alpha; |
| 7670 | boolean subclassHandlesAlpha = onSetAlpha((int) (alpha * 255)); |
| 7671 | if (subclassHandlesAlpha) { |
| 7672 | mPrivateFlags |= ALPHA_SET; |
| 7673 | return true; |
| 7674 | } else { |
| 7675 | mPrivateFlags &= ~ALPHA_SET; |
| 7676 | } |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 7677 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 7678 | return false; |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 7679 | } |
| 7680 | |
| 7681 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7682 | * Top position of this view relative to its parent. |
| 7683 | * |
| 7684 | * @return The top of this view, in pixels. |
| 7685 | */ |
| 7686 | @ViewDebug.CapturedViewProperty |
| 7687 | public final int getTop() { |
| 7688 | return mTop; |
| 7689 | } |
| 7690 | |
| 7691 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7692 | * Sets the top position of this view relative to its parent. This method is meant to be called |
| 7693 | * by the layout system and should not generally be called otherwise, because the property |
| 7694 | * may be changed at any time by the layout. |
| 7695 | * |
| 7696 | * @param top The top of this view, in pixels. |
| 7697 | */ |
| 7698 | public final void setTop(int top) { |
| 7699 | if (top != mTop) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7700 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7701 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 7702 | || mTransformationInfo.mMatrixIsIdentity; |
| 7703 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7704 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7705 | int minTop; |
| 7706 | int yLoc; |
| 7707 | if (top < mTop) { |
| 7708 | minTop = top; |
| 7709 | yLoc = top - mTop; |
| 7710 | } else { |
| 7711 | minTop = mTop; |
| 7712 | yLoc = 0; |
| 7713 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7714 | invalidate(0, yLoc, mRight - mLeft, mBottom - minTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7715 | } |
| 7716 | } else { |
| 7717 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7718 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7719 | } |
| 7720 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7721 | int width = mRight - mLeft; |
| 7722 | int oldHeight = mBottom - mTop; |
| 7723 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7724 | mTop = top; |
| 7725 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7726 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 7727 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7728 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7729 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 7730 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7731 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7732 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7733 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7734 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7735 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 7736 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 7737 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7738 | } |
| 7739 | } |
| 7740 | |
| 7741 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7742 | * Bottom position of this view relative to its parent. |
| 7743 | * |
| 7744 | * @return The bottom of this view, in pixels. |
| 7745 | */ |
| 7746 | @ViewDebug.CapturedViewProperty |
| 7747 | public final int getBottom() { |
| 7748 | return mBottom; |
| 7749 | } |
| 7750 | |
| 7751 | /** |
Michael Jurka | dab559a | 2011-01-04 20:31:51 -0800 | [diff] [blame] | 7752 | * True if this view has changed since the last time being drawn. |
| 7753 | * |
| 7754 | * @return The dirty state of this view. |
| 7755 | */ |
| 7756 | public boolean isDirty() { |
| 7757 | return (mPrivateFlags & DIRTY_MASK) != 0; |
| 7758 | } |
| 7759 | |
| 7760 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7761 | * Sets the bottom position of this view relative to its parent. This method is meant to be |
| 7762 | * called by the layout system and should not generally be called otherwise, because the |
| 7763 | * property may be changed at any time by the layout. |
| 7764 | * |
| 7765 | * @param bottom The bottom of this view, in pixels. |
| 7766 | */ |
| 7767 | public final void setBottom(int bottom) { |
| 7768 | if (bottom != mBottom) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7769 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7770 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 7771 | || mTransformationInfo.mMatrixIsIdentity; |
| 7772 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7773 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7774 | int maxBottom; |
| 7775 | if (bottom < mBottom) { |
| 7776 | maxBottom = mBottom; |
| 7777 | } else { |
| 7778 | maxBottom = bottom; |
| 7779 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7780 | invalidate(0, 0, mRight - mLeft, maxBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7781 | } |
| 7782 | } else { |
| 7783 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7784 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7785 | } |
| 7786 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7787 | int width = mRight - mLeft; |
| 7788 | int oldHeight = mBottom - mTop; |
| 7789 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7790 | mBottom = bottom; |
| 7791 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7792 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 7793 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7794 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7795 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 7796 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7797 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7798 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7799 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7800 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7801 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 7802 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 7803 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7804 | } |
| 7805 | } |
| 7806 | |
| 7807 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7808 | * Left position of this view relative to its parent. |
| 7809 | * |
| 7810 | * @return The left edge of this view, in pixels. |
| 7811 | */ |
| 7812 | @ViewDebug.CapturedViewProperty |
| 7813 | public final int getLeft() { |
| 7814 | return mLeft; |
| 7815 | } |
| 7816 | |
| 7817 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7818 | * Sets the left position of this view relative to its parent. This method is meant to be called |
| 7819 | * by the layout system and should not generally be called otherwise, because the property |
| 7820 | * may be changed at any time by the layout. |
| 7821 | * |
| 7822 | * @param left The bottom of this view, in pixels. |
| 7823 | */ |
| 7824 | public final void setLeft(int left) { |
| 7825 | if (left != mLeft) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7826 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7827 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 7828 | || mTransformationInfo.mMatrixIsIdentity; |
| 7829 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7830 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7831 | int minLeft; |
| 7832 | int xLoc; |
| 7833 | if (left < mLeft) { |
| 7834 | minLeft = left; |
| 7835 | xLoc = left - mLeft; |
| 7836 | } else { |
| 7837 | minLeft = mLeft; |
| 7838 | xLoc = 0; |
| 7839 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7840 | invalidate(xLoc, 0, mRight - minLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7841 | } |
| 7842 | } else { |
| 7843 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7844 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7845 | } |
| 7846 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7847 | int oldWidth = mRight - mLeft; |
| 7848 | int height = mBottom - mTop; |
| 7849 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7850 | mLeft = left; |
| 7851 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7852 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 7853 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7854 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7855 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 7856 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7857 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7858 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7859 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7860 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7861 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 7862 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 7863 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7864 | } |
| 7865 | } |
| 7866 | |
| 7867 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7868 | * Right position of this view relative to its parent. |
| 7869 | * |
| 7870 | * @return The right edge of this view, in pixels. |
| 7871 | */ |
| 7872 | @ViewDebug.CapturedViewProperty |
| 7873 | public final int getRight() { |
| 7874 | return mRight; |
| 7875 | } |
| 7876 | |
| 7877 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7878 | * Sets the right position of this view relative to its parent. This method is meant to be called |
| 7879 | * by the layout system and should not generally be called otherwise, because the property |
| 7880 | * may be changed at any time by the layout. |
| 7881 | * |
| 7882 | * @param right The bottom of this view, in pixels. |
| 7883 | */ |
| 7884 | public final void setRight(int right) { |
| 7885 | if (right != mRight) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 7886 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7887 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 7888 | || mTransformationInfo.mMatrixIsIdentity; |
| 7889 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7890 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7891 | int maxRight; |
| 7892 | if (right < mRight) { |
| 7893 | maxRight = mRight; |
| 7894 | } else { |
| 7895 | maxRight = right; |
| 7896 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 7897 | invalidate(0, 0, maxRight - mLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7898 | } |
| 7899 | } else { |
| 7900 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7901 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7902 | } |
| 7903 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7904 | int oldWidth = mRight - mLeft; |
| 7905 | int height = mBottom - mTop; |
| 7906 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7907 | mRight = right; |
| 7908 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7909 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 7910 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7911 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7912 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 7913 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7914 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 7915 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7916 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7917 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7918 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 7919 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 7920 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7921 | } |
| 7922 | } |
| 7923 | |
| 7924 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7925 | * The visual x position of this view, in pixels. This is equivalent to the |
| 7926 | * {@link #setTranslationX(float) translationX} property plus the current |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7927 | * {@link #getLeft() left} property. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7928 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7929 | * @return The visual x position of this view, in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7930 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7931 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7932 | public float getX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7933 | return mLeft + (mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7934 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7935 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7936 | /** |
| 7937 | * Sets the visual x position of this view, in pixels. This is equivalent to setting the |
| 7938 | * {@link #setTranslationX(float) translationX} property to be the difference between |
| 7939 | * the x value passed in and the current {@link #getLeft() left} property. |
| 7940 | * |
| 7941 | * @param x The visual x position of this view, in pixels. |
| 7942 | */ |
| 7943 | public void setX(float x) { |
| 7944 | setTranslationX(x - mLeft); |
| 7945 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 7946 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7947 | /** |
| 7948 | * The visual y position of this view, in pixels. This is equivalent to the |
| 7949 | * {@link #setTranslationY(float) translationY} property plus the current |
| 7950 | * {@link #getTop() top} property. |
| 7951 | * |
| 7952 | * @return The visual y position of this view, in pixels. |
| 7953 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7954 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7955 | public float getY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7956 | return mTop + (mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7957 | } |
| 7958 | |
| 7959 | /** |
| 7960 | * Sets the visual y position of this view, in pixels. This is equivalent to setting the |
| 7961 | * {@link #setTranslationY(float) translationY} property to be the difference between |
| 7962 | * the y value passed in and the current {@link #getTop() top} property. |
| 7963 | * |
| 7964 | * @param y The visual y position of this view, in pixels. |
| 7965 | */ |
| 7966 | public void setY(float y) { |
| 7967 | setTranslationY(y - mTop); |
| 7968 | } |
| 7969 | |
| 7970 | |
| 7971 | /** |
| 7972 | * The horizontal location of this view relative to its {@link #getLeft() left} position. |
| 7973 | * This position is post-layout, in addition to wherever the object's |
| 7974 | * layout placed it. |
| 7975 | * |
| 7976 | * @return The horizontal position of this view relative to its left position, in pixels. |
| 7977 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 7978 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7979 | public float getTranslationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7980 | return mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0; |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7981 | } |
| 7982 | |
| 7983 | /** |
| 7984 | * Sets the horizontal location of this view relative to its {@link #getLeft() left} position. |
| 7985 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 7986 | * layout placed it. |
| 7987 | * |
| 7988 | * @param translationX The horizontal position of this view relative to its left position, |
| 7989 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 7990 | * |
| 7991 | * @attr ref android.R.styleable#View_translationX |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7992 | */ |
| 7993 | public void setTranslationX(float translationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 7994 | ensureTransformationInfo(); |
| 7995 | final TransformationInfo info = mTransformationInfo; |
| 7996 | if (info.mTranslationX != translationX) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7997 | invalidateParentCaches(); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 7998 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 7999 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8000 | info.mTranslationX = translationX; |
| 8001 | info.mMatrixDirty = true; |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8002 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8003 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8004 | } |
| 8005 | } |
| 8006 | |
| 8007 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8008 | * The horizontal location of this view relative to its {@link #getTop() top} position. |
| 8009 | * This position is post-layout, in addition to wherever the object's |
| 8010 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8011 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8012 | * @return The vertical position of this view relative to its top position, |
| 8013 | * in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8014 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8015 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8016 | public float getTranslationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8017 | return mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8018 | } |
| 8019 | |
| 8020 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8021 | * Sets the vertical location of this view relative to its {@link #getTop() top} position. |
| 8022 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 8023 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8024 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8025 | * @param translationY The vertical position of this view relative to its top position, |
| 8026 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8027 | * |
| 8028 | * @attr ref android.R.styleable#View_translationY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8029 | */ |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8030 | public void setTranslationY(float translationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8031 | ensureTransformationInfo(); |
| 8032 | final TransformationInfo info = mTransformationInfo; |
| 8033 | if (info.mTranslationY != translationY) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8034 | invalidateParentCaches(); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8035 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8036 | invalidate(false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8037 | info.mTranslationY = translationY; |
| 8038 | info.mMatrixDirty = true; |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8039 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8040 | invalidate(false); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8041 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8042 | } |
| 8043 | |
| 8044 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8045 | * Hit rectangle in parent's coordinates |
| 8046 | * |
| 8047 | * @param outRect The hit rectangle of the view. |
| 8048 | */ |
| 8049 | public void getHitRect(Rect outRect) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8050 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8051 | final TransformationInfo info = mTransformationInfo; |
| 8052 | if (info == null || info.mMatrixIsIdentity || mAttachInfo == null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8053 | outRect.set(mLeft, mTop, mRight, mBottom); |
| 8054 | } else { |
| 8055 | final RectF tmpRect = mAttachInfo.mTmpTransformRect; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8056 | tmpRect.set(-info.mPivotX, -info.mPivotY, |
| 8057 | getWidth() - info.mPivotX, getHeight() - info.mPivotY); |
| 8058 | info.mMatrix.mapRect(tmpRect); |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8059 | outRect.set((int) tmpRect.left + mLeft, (int) tmpRect.top + mTop, |
| 8060 | (int) tmpRect.right + mLeft, (int) tmpRect.bottom + mTop); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8061 | } |
| 8062 | } |
| 8063 | |
| 8064 | /** |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8065 | * Determines whether the given point, in local coordinates is inside the view. |
| 8066 | */ |
| 8067 | /*package*/ final boolean pointInView(float localX, float localY) { |
| 8068 | return localX >= 0 && localX < (mRight - mLeft) |
| 8069 | && localY >= 0 && localY < (mBottom - mTop); |
| 8070 | } |
| 8071 | |
| 8072 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8073 | * Utility method to determine whether the given point, in local coordinates, |
| 8074 | * is inside the view, where the area of the view is expanded by the slop factor. |
| 8075 | * This method is called while processing touch-move events to determine if the event |
| 8076 | * is still within the view. |
| 8077 | */ |
| 8078 | private boolean pointInView(float localX, float localY, float slop) { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8079 | return localX >= -slop && localY >= -slop && localX < ((mRight - mLeft) + slop) && |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8080 | localY < ((mBottom - mTop) + slop); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8081 | } |
| 8082 | |
| 8083 | /** |
| 8084 | * When a view has focus and the user navigates away from it, the next view is searched for |
| 8085 | * starting from the rectangle filled in by this method. |
| 8086 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8087 | * By default, the rectange is the {@link #getDrawingRect(android.graphics.Rect)}) |
| 8088 | * of the view. However, if your view maintains some idea of internal selection, |
| 8089 | * such as a cursor, or a selected row or column, you should override this method and |
| 8090 | * fill in a more specific rectangle. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8091 | * |
| 8092 | * @param r The rectangle to fill in, in this view's coordinates. |
| 8093 | */ |
| 8094 | public void getFocusedRect(Rect r) { |
| 8095 | getDrawingRect(r); |
| 8096 | } |
| 8097 | |
| 8098 | /** |
| 8099 | * If some part of this view is not clipped by any of its parents, then |
| 8100 | * 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] | 8101 | * coordinates (without taking possible View rotations into account), offset |
| 8102 | * it by -globalOffset (e.g. r.offset(-globalOffset.x, -globalOffset.y)). |
| 8103 | * 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] | 8104 | * |
| 8105 | * @param r If true is returned, r holds the global coordinates of the |
| 8106 | * visible portion of this view. |
| 8107 | * @param globalOffset If true is returned, globalOffset holds the dx,dy |
| 8108 | * between this view and its root. globalOffet may be null. |
| 8109 | * @return true if r is non-empty (i.e. part of the view is visible at the |
| 8110 | * root level. |
| 8111 | */ |
| 8112 | public boolean getGlobalVisibleRect(Rect r, Point globalOffset) { |
| 8113 | int width = mRight - mLeft; |
| 8114 | int height = mBottom - mTop; |
| 8115 | if (width > 0 && height > 0) { |
| 8116 | r.set(0, 0, width, height); |
| 8117 | if (globalOffset != null) { |
| 8118 | globalOffset.set(-mScrollX, -mScrollY); |
| 8119 | } |
| 8120 | return mParent == null || mParent.getChildVisibleRect(this, r, globalOffset); |
| 8121 | } |
| 8122 | return false; |
| 8123 | } |
| 8124 | |
| 8125 | public final boolean getGlobalVisibleRect(Rect r) { |
| 8126 | return getGlobalVisibleRect(r, null); |
| 8127 | } |
| 8128 | |
| 8129 | public final boolean getLocalVisibleRect(Rect r) { |
| 8130 | Point offset = new Point(); |
| 8131 | if (getGlobalVisibleRect(r, offset)) { |
| 8132 | r.offset(-offset.x, -offset.y); // make r local |
| 8133 | return true; |
| 8134 | } |
| 8135 | return false; |
| 8136 | } |
| 8137 | |
| 8138 | /** |
| 8139 | * Offset this view's vertical location by the specified number of pixels. |
| 8140 | * |
| 8141 | * @param offset the number of pixels to offset the view by |
| 8142 | */ |
| 8143 | public void offsetTopAndBottom(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8144 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8145 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8146 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8147 | || mTransformationInfo.mMatrixIsIdentity; |
| 8148 | if (matrixIsIdentity) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8149 | final ViewParent p = mParent; |
| 8150 | if (p != null && mAttachInfo != null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8151 | final Rect r = mAttachInfo.mTmpInvalRect; |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 8152 | int minTop; |
| 8153 | int maxBottom; |
| 8154 | int yLoc; |
| 8155 | if (offset < 0) { |
| 8156 | minTop = mTop + offset; |
| 8157 | maxBottom = mBottom; |
| 8158 | yLoc = offset; |
| 8159 | } else { |
| 8160 | minTop = mTop; |
| 8161 | maxBottom = mBottom + offset; |
| 8162 | yLoc = 0; |
| 8163 | } |
| 8164 | r.set(0, yLoc, mRight - mLeft, maxBottom - minTop); |
| 8165 | p.invalidateChild(this, r); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8166 | } |
| 8167 | } else { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8168 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8169 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8170 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8171 | mTop += offset; |
| 8172 | mBottom += offset; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8173 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8174 | if (!matrixIsIdentity) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8175 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8176 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8177 | } |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8178 | invalidateParentIfNeeded(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8179 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8180 | } |
| 8181 | |
| 8182 | /** |
| 8183 | * Offset this view's horizontal location by the specified amount of pixels. |
| 8184 | * |
| 8185 | * @param offset the numer of pixels to offset the view by |
| 8186 | */ |
| 8187 | public void offsetLeftAndRight(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8188 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8189 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8190 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8191 | || mTransformationInfo.mMatrixIsIdentity; |
| 8192 | if (matrixIsIdentity) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8193 | final ViewParent p = mParent; |
| 8194 | if (p != null && mAttachInfo != null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8195 | final Rect r = mAttachInfo.mTmpInvalRect; |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 8196 | int minLeft; |
| 8197 | int maxRight; |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 8198 | if (offset < 0) { |
| 8199 | minLeft = mLeft + offset; |
| 8200 | maxRight = mRight; |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 8201 | } else { |
| 8202 | minLeft = mLeft; |
| 8203 | maxRight = mRight + offset; |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 8204 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8205 | r.set(0, 0, maxRight - minLeft, mBottom - mTop); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 8206 | p.invalidateChild(this, r); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8207 | } |
| 8208 | } else { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8209 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8210 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8211 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8212 | mLeft += offset; |
| 8213 | mRight += offset; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8214 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8215 | if (!matrixIsIdentity) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8216 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8217 | invalidate(false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8218 | } |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8219 | invalidateParentIfNeeded(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8220 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8221 | } |
| 8222 | |
| 8223 | /** |
| 8224 | * Get the LayoutParams associated with this view. All views should have |
| 8225 | * layout parameters. These supply parameters to the <i>parent</i> of this |
| 8226 | * view specifying how it should be arranged. There are many subclasses of |
| 8227 | * ViewGroup.LayoutParams, and these correspond to the different subclasses |
| 8228 | * of ViewGroup that are responsible for arranging their children. |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 8229 | * |
| 8230 | * This method may return null if this View is not attached to a parent |
| 8231 | * ViewGroup or {@link #setLayoutParams(android.view.ViewGroup.LayoutParams)} |
| 8232 | * was not invoked successfully. When a View is attached to a parent |
| 8233 | * ViewGroup, this method must not return null. |
| 8234 | * |
| 8235 | * @return The LayoutParams associated with this view, or null if no |
| 8236 | * parameters have been set yet |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8237 | */ |
Konstantin Lopyrev | 91a7f5f | 2010-08-10 18:54:54 -0700 | [diff] [blame] | 8238 | @ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8239 | public ViewGroup.LayoutParams getLayoutParams() { |
| 8240 | return mLayoutParams; |
| 8241 | } |
| 8242 | |
| 8243 | /** |
| 8244 | * Set the layout parameters associated with this view. These supply |
| 8245 | * parameters to the <i>parent</i> of this view specifying how it should be |
| 8246 | * arranged. There are many subclasses of ViewGroup.LayoutParams, and these |
| 8247 | * correspond to the different subclasses of ViewGroup that are responsible |
| 8248 | * for arranging their children. |
| 8249 | * |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 8250 | * @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] | 8251 | */ |
| 8252 | public void setLayoutParams(ViewGroup.LayoutParams params) { |
| 8253 | if (params == null) { |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 8254 | throw new NullPointerException("Layout parameters cannot be null"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8255 | } |
| 8256 | mLayoutParams = params; |
| 8257 | requestLayout(); |
| 8258 | } |
| 8259 | |
| 8260 | /** |
| 8261 | * Set the scrolled position of your view. This will cause a call to |
| 8262 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8263 | * invalidated. |
| 8264 | * @param x the x position to scroll to |
| 8265 | * @param y the y position to scroll to |
| 8266 | */ |
| 8267 | public void scrollTo(int x, int y) { |
| 8268 | if (mScrollX != x || mScrollY != y) { |
| 8269 | int oldX = mScrollX; |
| 8270 | int oldY = mScrollY; |
| 8271 | mScrollX = x; |
| 8272 | mScrollY = y; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8273 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8274 | onScrollChanged(mScrollX, mScrollY, oldX, oldY); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8275 | if (!awakenScrollBars()) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8276 | invalidate(true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8277 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8278 | } |
| 8279 | } |
| 8280 | |
| 8281 | /** |
| 8282 | * Move the scrolled position of your view. This will cause a call to |
| 8283 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8284 | * invalidated. |
| 8285 | * @param x the amount of pixels to scroll by horizontally |
| 8286 | * @param y the amount of pixels to scroll by vertically |
| 8287 | */ |
| 8288 | public void scrollBy(int x, int y) { |
| 8289 | scrollTo(mScrollX + x, mScrollY + y); |
| 8290 | } |
| 8291 | |
| 8292 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8293 | * <p>Trigger the scrollbars to draw. When invoked this method starts an |
| 8294 | * animation to fade the scrollbars out after a default delay. If a subclass |
| 8295 | * provides animated scrolling, the start delay should equal the duration |
| 8296 | * of the scrolling animation.</p> |
| 8297 | * |
| 8298 | * <p>The animation starts only if at least one of the scrollbars is |
| 8299 | * enabled, as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 8300 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 8301 | * this method returns true, and false otherwise. If the animation is |
| 8302 | * started, this method calls {@link #invalidate()}; in that case the |
| 8303 | * caller should not call {@link #invalidate()}.</p> |
| 8304 | * |
| 8305 | * <p>This method should be invoked every time a subclass directly updates |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 8306 | * the scroll parameters.</p> |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8307 | * |
| 8308 | * <p>This method is automatically invoked by {@link #scrollBy(int, int)} |
| 8309 | * and {@link #scrollTo(int, int)}.</p> |
| 8310 | * |
| 8311 | * @return true if the animation is played, false otherwise |
| 8312 | * |
| 8313 | * @see #awakenScrollBars(int) |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8314 | * @see #scrollBy(int, int) |
| 8315 | * @see #scrollTo(int, int) |
| 8316 | * @see #isHorizontalScrollBarEnabled() |
| 8317 | * @see #isVerticalScrollBarEnabled() |
| 8318 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 8319 | * @see #setVerticalScrollBarEnabled(boolean) |
| 8320 | */ |
| 8321 | protected boolean awakenScrollBars() { |
| 8322 | return mScrollCache != null && |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8323 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade, true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8324 | } |
| 8325 | |
| 8326 | /** |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 8327 | * Trigger the scrollbars to draw. |
| 8328 | * This method differs from awakenScrollBars() only in its default duration. |
| 8329 | * initialAwakenScrollBars() will show the scroll bars for longer than |
| 8330 | * usual to give the user more of a chance to notice them. |
| 8331 | * |
| 8332 | * @return true if the animation is played, false otherwise. |
| 8333 | */ |
| 8334 | private boolean initialAwakenScrollBars() { |
| 8335 | return mScrollCache != null && |
| 8336 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade * 4, true); |
| 8337 | } |
| 8338 | |
| 8339 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8340 | * <p> |
| 8341 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 8342 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 8343 | * provides animated scrolling, the start delay should equal the duration of |
| 8344 | * the scrolling animation. |
| 8345 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8346 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8347 | * <p> |
| 8348 | * The animation starts only if at least one of the scrollbars is enabled, |
| 8349 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 8350 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 8351 | * this method returns true, and false otherwise. If the animation is |
| 8352 | * started, this method calls {@link #invalidate()}; in that case the caller |
| 8353 | * should not call {@link #invalidate()}. |
| 8354 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8355 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8356 | * <p> |
| 8357 | * This method should be invoked everytime a subclass directly updates the |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 8358 | * scroll parameters. |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8359 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8360 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8361 | * @param startDelay the delay, in milliseconds, after which the animation |
| 8362 | * should start; when the delay is 0, the animation starts |
| 8363 | * immediately |
| 8364 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8365 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8366 | * @see #scrollBy(int, int) |
| 8367 | * @see #scrollTo(int, int) |
| 8368 | * @see #isHorizontalScrollBarEnabled() |
| 8369 | * @see #isVerticalScrollBarEnabled() |
| 8370 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 8371 | * @see #setVerticalScrollBarEnabled(boolean) |
| 8372 | */ |
| 8373 | protected boolean awakenScrollBars(int startDelay) { |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8374 | return awakenScrollBars(startDelay, true); |
| 8375 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8376 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8377 | /** |
| 8378 | * <p> |
| 8379 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 8380 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 8381 | * provides animated scrolling, the start delay should equal the duration of |
| 8382 | * the scrolling animation. |
| 8383 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8384 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8385 | * <p> |
| 8386 | * The animation starts only if at least one of the scrollbars is enabled, |
| 8387 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 8388 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 8389 | * this method returns true, and false otherwise. If the animation is |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8390 | * started, this method calls {@link #invalidate()} if the invalidate parameter |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8391 | * is set to true; in that case the caller |
| 8392 | * should not call {@link #invalidate()}. |
| 8393 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8394 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8395 | * <p> |
| 8396 | * This method should be invoked everytime a subclass directly updates the |
| 8397 | * scroll parameters. |
| 8398 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8399 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8400 | * @param startDelay the delay, in milliseconds, after which the animation |
| 8401 | * should start; when the delay is 0, the animation starts |
| 8402 | * immediately |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8403 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8404 | * @param invalidate Wheter this method should call invalidate |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8405 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8406 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8407 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8408 | * @see #scrollBy(int, int) |
| 8409 | * @see #scrollTo(int, int) |
| 8410 | * @see #isHorizontalScrollBarEnabled() |
| 8411 | * @see #isVerticalScrollBarEnabled() |
| 8412 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 8413 | * @see #setVerticalScrollBarEnabled(boolean) |
| 8414 | */ |
| 8415 | protected boolean awakenScrollBars(int startDelay, boolean invalidate) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8416 | final ScrollabilityCache scrollCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8417 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8418 | if (scrollCache == null || !scrollCache.fadeScrollBars) { |
| 8419 | return false; |
| 8420 | } |
| 8421 | |
| 8422 | if (scrollCache.scrollBar == null) { |
| 8423 | scrollCache.scrollBar = new ScrollBarDrawable(); |
| 8424 | } |
| 8425 | |
| 8426 | if (isHorizontalScrollBarEnabled() || isVerticalScrollBarEnabled()) { |
| 8427 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8428 | if (invalidate) { |
| 8429 | // Invalidate to show the scrollbars |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8430 | invalidate(true); |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 8431 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8432 | |
| 8433 | if (scrollCache.state == ScrollabilityCache.OFF) { |
| 8434 | // FIXME: this is copied from WindowManagerService. |
| 8435 | // We should get this value from the system when it |
| 8436 | // is possible to do so. |
| 8437 | final int KEY_REPEAT_FIRST_DELAY = 750; |
| 8438 | startDelay = Math.max(KEY_REPEAT_FIRST_DELAY, startDelay); |
| 8439 | } |
| 8440 | |
| 8441 | // Tell mScrollCache when we should start fading. This may |
| 8442 | // extend the fade start time if one was already scheduled |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 8443 | long fadeStartTime = AnimationUtils.currentAnimationTimeMillis() + startDelay; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 8444 | scrollCache.fadeStartTime = fadeStartTime; |
| 8445 | scrollCache.state = ScrollabilityCache.ON; |
| 8446 | |
| 8447 | // Schedule our fader to run, unscheduling any old ones first |
| 8448 | if (mAttachInfo != null) { |
| 8449 | mAttachInfo.mHandler.removeCallbacks(scrollCache); |
| 8450 | mAttachInfo.mHandler.postAtTime(scrollCache, fadeStartTime); |
| 8451 | } |
| 8452 | |
| 8453 | return true; |
| 8454 | } |
| 8455 | |
| 8456 | return false; |
| 8457 | } |
| 8458 | |
| 8459 | /** |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8460 | * Do not invalidate views which are not visible and which are not running an animation. They |
| 8461 | * will not get drawn and they should not set dirty flags as if they will be drawn |
| 8462 | */ |
| 8463 | private boolean skipInvalidate() { |
| 8464 | return (mViewFlags & VISIBILITY_MASK) != VISIBLE && mCurrentAnimation == null && |
| 8465 | (!(mParent instanceof ViewGroup) || |
| 8466 | !((ViewGroup) mParent).isViewTransitioning(this)); |
| 8467 | } |
| 8468 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 8469 | * 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] | 8470 | * visible, {@link #onDraw(android.graphics.Canvas)} will be called at some point |
| 8471 | * in the future. This must be called from a UI thread. To call from a non-UI |
| 8472 | * thread, call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8473 | * |
| 8474 | * WARNING: This method is destructive to dirty. |
| 8475 | * @param dirty the rectangle representing the bounds of the dirty region |
| 8476 | */ |
| 8477 | public void invalidate(Rect dirty) { |
| 8478 | if (ViewDebug.TRACE_HIERARCHY) { |
| 8479 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 8480 | } |
| 8481 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8482 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 8483 | return; |
| 8484 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8485 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8486 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || |
| 8487 | (mPrivateFlags & INVALIDATED) != INVALIDATED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8488 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8489 | mPrivateFlags |= INVALIDATED; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 8490 | mPrivateFlags |= DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8491 | final ViewParent p = mParent; |
| 8492 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8493 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 8494 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 8495 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 8496 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 8497 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8498 | p.invalidateChild(this, null); |
| 8499 | return; |
| 8500 | } |
Romain Guy | af636eb | 2010-12-09 17:47:21 -0800 | [diff] [blame] | 8501 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8502 | if (p != null && ai != null) { |
| 8503 | final int scrollX = mScrollX; |
| 8504 | final int scrollY = mScrollY; |
| 8505 | final Rect r = ai.mTmpInvalRect; |
| 8506 | r.set(dirty.left - scrollX, dirty.top - scrollY, |
| 8507 | dirty.right - scrollX, dirty.bottom - scrollY); |
| 8508 | mParent.invalidateChild(this, r); |
| 8509 | } |
| 8510 | } |
| 8511 | } |
| 8512 | |
| 8513 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 8514 | * 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] | 8515 | * The coordinates of the dirty rect are relative to the view. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8516 | * If the view is visible, {@link #onDraw(android.graphics.Canvas)} |
| 8517 | * will be called at some point in the future. This must be called from |
| 8518 | * 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] | 8519 | * @param l the left position of the dirty region |
| 8520 | * @param t the top position of the dirty region |
| 8521 | * @param r the right position of the dirty region |
| 8522 | * @param b the bottom position of the dirty region |
| 8523 | */ |
| 8524 | public void invalidate(int l, int t, int r, int b) { |
| 8525 | if (ViewDebug.TRACE_HIERARCHY) { |
| 8526 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 8527 | } |
| 8528 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8529 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 8530 | return; |
| 8531 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8532 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8533 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || |
| 8534 | (mPrivateFlags & INVALIDATED) != INVALIDATED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8535 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8536 | mPrivateFlags |= INVALIDATED; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 8537 | mPrivateFlags |= DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8538 | final ViewParent p = mParent; |
| 8539 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8540 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 8541 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 8542 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 8543 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 8544 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8545 | p.invalidateChild(this, null); |
| 8546 | return; |
| 8547 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 8548 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8549 | if (p != null && ai != null && l < r && t < b) { |
| 8550 | final int scrollX = mScrollX; |
| 8551 | final int scrollY = mScrollY; |
| 8552 | final Rect tmpr = ai.mTmpInvalRect; |
| 8553 | tmpr.set(l - scrollX, t - scrollY, r - scrollX, b - scrollY); |
| 8554 | p.invalidateChild(this, tmpr); |
| 8555 | } |
| 8556 | } |
| 8557 | } |
| 8558 | |
| 8559 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8560 | * Invalidate the whole view. If the view is visible, |
| 8561 | * {@link #onDraw(android.graphics.Canvas)} will be called at some point in |
| 8562 | * the future. This must be called from a UI thread. To call from a non-UI thread, |
| 8563 | * call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8564 | */ |
| 8565 | public void invalidate() { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8566 | invalidate(true); |
| 8567 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8568 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8569 | /** |
| 8570 | * This is where the invalidate() work actually happens. A full invalidate() |
| 8571 | * causes the drawing cache to be invalidated, but this function can be called with |
| 8572 | * invalidateCache set to false to skip that invalidation step for cases that do not |
| 8573 | * need it (for example, a component that remains at the same dimensions with the same |
| 8574 | * content). |
| 8575 | * |
| 8576 | * @param invalidateCache Whether the drawing cache for this view should be invalidated as |
| 8577 | * well. This is usually true for a full invalidate, but may be set to false if the |
| 8578 | * View's contents or dimensions have not changed. |
| 8579 | */ |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 8580 | void invalidate(boolean invalidateCache) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8581 | if (ViewDebug.TRACE_HIERARCHY) { |
| 8582 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 8583 | } |
| 8584 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8585 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 8586 | return; |
| 8587 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8588 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Romain Guy | c5d5586 | 2011-01-21 19:01:46 -0800 | [diff] [blame] | 8589 | (invalidateCache && (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) || |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8590 | (mPrivateFlags & INVALIDATED) != INVALIDATED || isOpaque() != mLastIsOpaque) { |
| 8591 | mLastIsOpaque = isOpaque(); |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8592 | mPrivateFlags &= ~DRAWN; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 8593 | mPrivateFlags |= DIRTY; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8594 | if (invalidateCache) { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8595 | mPrivateFlags |= INVALIDATED; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8596 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 8597 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8598 | final AttachInfo ai = mAttachInfo; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 8599 | final ViewParent p = mParent; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8600 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 8601 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 8602 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 8603 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 8604 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 8605 | p.invalidateChild(this, null); |
| 8606 | return; |
| 8607 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 8608 | } |
Michael Jurka | ebefea4 | 2010-11-15 16:04:01 -0800 | [diff] [blame] | 8609 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8610 | if (p != null && ai != null) { |
| 8611 | final Rect r = ai.mTmpInvalRect; |
| 8612 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 8613 | // Don't call invalidate -- we don't want to internally scroll |
| 8614 | // our own bounds |
| 8615 | p.invalidateChild(this, r); |
| 8616 | } |
| 8617 | } |
| 8618 | } |
| 8619 | |
| 8620 | /** |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8621 | * 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] | 8622 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 8623 | * 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] | 8624 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method only |
| 8625 | * clears the parent caches and does not causes an invalidate event. |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8626 | * |
| 8627 | * @hide |
| 8628 | */ |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8629 | protected void invalidateParentCaches() { |
| 8630 | if (mParent instanceof View) { |
| 8631 | ((View) mParent).mPrivateFlags |= INVALIDATED; |
| 8632 | } |
| 8633 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8634 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8635 | /** |
| 8636 | * Used to indicate that the parent of this view should be invalidated. This functionality |
| 8637 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 8638 | * which is necessary when various parent-managed properties of the view change, such as |
| 8639 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method will propagate |
| 8640 | * an invalidation event to the parent. |
| 8641 | * |
| 8642 | * @hide |
| 8643 | */ |
| 8644 | protected void invalidateParentIfNeeded() { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8645 | if (isHardwareAccelerated() && mParent instanceof View) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8646 | ((View) mParent).invalidate(true); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 8647 | } |
| 8648 | } |
| 8649 | |
| 8650 | /** |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 8651 | * Indicates whether this View is opaque. An opaque View guarantees that it will |
| 8652 | * draw all the pixels overlapping its bounds using a fully opaque color. |
| 8653 | * |
| 8654 | * Subclasses of View should override this method whenever possible to indicate |
| 8655 | * whether an instance is opaque. Opaque Views are treated in a special way by |
| 8656 | * the View hierarchy, possibly allowing it to perform optimizations during |
| 8657 | * invalidate/draw passes. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 8658 | * |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 8659 | * @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] | 8660 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 8661 | @ViewDebug.ExportedProperty(category = "drawing") |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 8662 | public boolean isOpaque() { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 8663 | return (mPrivateFlags & OPAQUE_MASK) == OPAQUE_MASK && |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8664 | ((mTransformationInfo != null ? mTransformationInfo.mAlpha : 1) |
| 8665 | >= 1.0f - ViewConfiguration.ALPHA_THRESHOLD); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 8666 | } |
| 8667 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 8668 | /** |
| 8669 | * @hide |
| 8670 | */ |
| 8671 | protected void computeOpaqueFlags() { |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 8672 | // Opaque if: |
| 8673 | // - Has a background |
| 8674 | // - Background is opaque |
| 8675 | // - Doesn't have scrollbars or scrollbars are inside overlay |
| 8676 | |
| 8677 | if (mBGDrawable != null && mBGDrawable.getOpacity() == PixelFormat.OPAQUE) { |
| 8678 | mPrivateFlags |= OPAQUE_BACKGROUND; |
| 8679 | } else { |
| 8680 | mPrivateFlags &= ~OPAQUE_BACKGROUND; |
| 8681 | } |
| 8682 | |
| 8683 | final int flags = mViewFlags; |
| 8684 | if (((flags & SCROLLBARS_VERTICAL) == 0 && (flags & SCROLLBARS_HORIZONTAL) == 0) || |
| 8685 | (flags & SCROLLBARS_STYLE_MASK) == SCROLLBARS_INSIDE_OVERLAY) { |
| 8686 | mPrivateFlags |= OPAQUE_SCROLLBARS; |
| 8687 | } else { |
| 8688 | mPrivateFlags &= ~OPAQUE_SCROLLBARS; |
| 8689 | } |
| 8690 | } |
| 8691 | |
| 8692 | /** |
| 8693 | * @hide |
| 8694 | */ |
| 8695 | protected boolean hasOpaqueScrollbars() { |
| 8696 | return (mPrivateFlags & OPAQUE_SCROLLBARS) == OPAQUE_SCROLLBARS; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 8697 | } |
| 8698 | |
| 8699 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8700 | * @return A handler associated with the thread running the View. This |
| 8701 | * handler can be used to pump events in the UI events queue. |
| 8702 | */ |
| 8703 | public Handler getHandler() { |
| 8704 | if (mAttachInfo != null) { |
| 8705 | return mAttachInfo.mHandler; |
| 8706 | } |
| 8707 | return null; |
| 8708 | } |
| 8709 | |
| 8710 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8711 | * <p>Causes the Runnable to be added to the message queue. |
| 8712 | * The runnable will be run on the user interface thread.</p> |
| 8713 | * |
| 8714 | * <p>This method can be invoked from outside of the UI thread |
| 8715 | * 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] | 8716 | * |
| 8717 | * @param action The Runnable that will be executed. |
| 8718 | * |
| 8719 | * @return Returns true if the Runnable was successfully placed in to the |
| 8720 | * message queue. Returns false on failure, usually because the |
| 8721 | * looper processing the message queue is exiting. |
| 8722 | */ |
| 8723 | public boolean post(Runnable action) { |
| 8724 | Handler handler; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8725 | AttachInfo attachInfo = mAttachInfo; |
| 8726 | if (attachInfo != null) { |
| 8727 | handler = attachInfo.mHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8728 | } else { |
| 8729 | // Assume that post will succeed later |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8730 | ViewRootImpl.getRunQueue().post(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8731 | return true; |
| 8732 | } |
| 8733 | |
| 8734 | return handler.post(action); |
| 8735 | } |
| 8736 | |
| 8737 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8738 | * <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] | 8739 | * after the specified amount of time elapses. |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8740 | * The runnable will be run on the user interface thread.</p> |
| 8741 | * |
| 8742 | * <p>This method can be invoked from outside of the UI thread |
| 8743 | * 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] | 8744 | * |
| 8745 | * @param action The Runnable that will be executed. |
| 8746 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 8747 | * will be executed. |
| 8748 | * |
| 8749 | * @return true if the Runnable was successfully placed in to the |
| 8750 | * message queue. Returns false on failure, usually because the |
| 8751 | * looper processing the message queue is exiting. Note that a |
| 8752 | * result of true does not mean the Runnable will be processed -- |
| 8753 | * if the looper is quit before the delivery time of the message |
| 8754 | * occurs then the message will be dropped. |
| 8755 | */ |
| 8756 | public boolean postDelayed(Runnable action, long delayMillis) { |
| 8757 | Handler handler; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8758 | AttachInfo attachInfo = mAttachInfo; |
| 8759 | if (attachInfo != null) { |
| 8760 | handler = attachInfo.mHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8761 | } else { |
| 8762 | // Assume that post will succeed later |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8763 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8764 | return true; |
| 8765 | } |
| 8766 | |
| 8767 | return handler.postDelayed(action, delayMillis); |
| 8768 | } |
| 8769 | |
| 8770 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8771 | * <p>Removes the specified Runnable from the message queue.</p> |
| 8772 | * |
| 8773 | * <p>This method can be invoked from outside of the UI thread |
| 8774 | * 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] | 8775 | * |
| 8776 | * @param action The Runnable to remove from the message handling queue |
| 8777 | * |
| 8778 | * @return true if this view could ask the Handler to remove the Runnable, |
| 8779 | * false otherwise. When the returned value is true, the Runnable |
| 8780 | * may or may not have been actually removed from the message queue |
| 8781 | * (for instance, if the Runnable was not in the queue already.) |
| 8782 | */ |
| 8783 | public boolean removeCallbacks(Runnable action) { |
| 8784 | Handler handler; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8785 | AttachInfo attachInfo = mAttachInfo; |
| 8786 | if (attachInfo != null) { |
| 8787 | handler = attachInfo.mHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8788 | } else { |
| 8789 | // Assume that post will succeed later |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 8790 | ViewRootImpl.getRunQueue().removeCallbacks(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8791 | return true; |
| 8792 | } |
| 8793 | |
| 8794 | handler.removeCallbacks(action); |
| 8795 | return true; |
| 8796 | } |
| 8797 | |
| 8798 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8799 | * <p>Cause an invalidate to happen on a subsequent cycle through the event loop. |
| 8800 | * 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] | 8801 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8802 | * <p>This method can be invoked from outside of the UI thread |
| 8803 | * only when this View is attached to a window.</p> |
| 8804 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8805 | * @see #invalidate() |
| 8806 | */ |
| 8807 | public void postInvalidate() { |
| 8808 | postInvalidateDelayed(0); |
| 8809 | } |
| 8810 | |
| 8811 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8812 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 8813 | * through the event loop. Use this to invalidate the View from a non-UI thread.</p> |
| 8814 | * |
| 8815 | * <p>This method can be invoked from outside of the UI thread |
| 8816 | * 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] | 8817 | * |
| 8818 | * @param left The left coordinate of the rectangle to invalidate. |
| 8819 | * @param top The top coordinate of the rectangle to invalidate. |
| 8820 | * @param right The right coordinate of the rectangle to invalidate. |
| 8821 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 8822 | * |
| 8823 | * @see #invalidate(int, int, int, int) |
| 8824 | * @see #invalidate(Rect) |
| 8825 | */ |
| 8826 | public void postInvalidate(int left, int top, int right, int bottom) { |
| 8827 | postInvalidateDelayed(0, left, top, right, bottom); |
| 8828 | } |
| 8829 | |
| 8830 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8831 | * <p>Cause an invalidate to happen on a subsequent cycle through the event |
| 8832 | * loop. Waits for the specified amount of time.</p> |
| 8833 | * |
| 8834 | * <p>This method can be invoked from outside of the UI thread |
| 8835 | * 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] | 8836 | * |
| 8837 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 8838 | * invalidation by |
| 8839 | */ |
| 8840 | public void postInvalidateDelayed(long delayMilliseconds) { |
| 8841 | // We try only with the AttachInfo because there's no point in invalidating |
| 8842 | // if we are not attached to our window |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8843 | AttachInfo attachInfo = mAttachInfo; |
| 8844 | if (attachInfo != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8845 | Message msg = Message.obtain(); |
| 8846 | msg.what = AttachInfo.INVALIDATE_MSG; |
| 8847 | msg.obj = this; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8848 | attachInfo.mHandler.sendMessageDelayed(msg, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8849 | } |
| 8850 | } |
| 8851 | |
| 8852 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 8853 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 8854 | * through the event loop. Waits for the specified amount of time.</p> |
| 8855 | * |
| 8856 | * <p>This method can be invoked from outside of the UI thread |
| 8857 | * 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] | 8858 | * |
| 8859 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 8860 | * invalidation by |
| 8861 | * @param left The left coordinate of the rectangle to invalidate. |
| 8862 | * @param top The top coordinate of the rectangle to invalidate. |
| 8863 | * @param right The right coordinate of the rectangle to invalidate. |
| 8864 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 8865 | */ |
| 8866 | public void postInvalidateDelayed(long delayMilliseconds, int left, int top, |
| 8867 | int right, int bottom) { |
| 8868 | |
| 8869 | // We try only with the AttachInfo because there's no point in invalidating |
| 8870 | // if we are not attached to our window |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8871 | AttachInfo attachInfo = mAttachInfo; |
| 8872 | if (attachInfo != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8873 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire(); |
| 8874 | info.target = this; |
| 8875 | info.left = left; |
| 8876 | info.top = top; |
| 8877 | info.right = right; |
| 8878 | info.bottom = bottom; |
| 8879 | |
| 8880 | final Message msg = Message.obtain(); |
| 8881 | msg.what = AttachInfo.INVALIDATE_RECT_MSG; |
| 8882 | msg.obj = info; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 8883 | attachInfo.mHandler.sendMessageDelayed(msg, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8884 | } |
| 8885 | } |
| 8886 | |
| 8887 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 8888 | * Post a callback to send a {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} event. |
| 8889 | * This event is sent at most once every |
| 8890 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
| 8891 | */ |
| 8892 | private void postSendViewScrolledAccessibilityEventCallback() { |
| 8893 | if (mSendViewScrolledAccessibilityEvent == null) { |
| 8894 | mSendViewScrolledAccessibilityEvent = new SendViewScrolledAccessibilityEvent(); |
| 8895 | } |
| 8896 | if (!mSendViewScrolledAccessibilityEvent.mIsPending) { |
| 8897 | mSendViewScrolledAccessibilityEvent.mIsPending = true; |
| 8898 | postDelayed(mSendViewScrolledAccessibilityEvent, |
| 8899 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval()); |
| 8900 | } |
| 8901 | } |
| 8902 | |
| 8903 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8904 | * Called by a parent to request that a child update its values for mScrollX |
| 8905 | * and mScrollY if necessary. This will typically be done if the child is |
| 8906 | * animating a scroll using a {@link android.widget.Scroller Scroller} |
| 8907 | * object. |
| 8908 | */ |
| 8909 | public void computeScroll() { |
| 8910 | } |
| 8911 | |
| 8912 | /** |
| 8913 | * <p>Indicate whether the horizontal edges are faded when the view is |
| 8914 | * scrolled horizontally.</p> |
| 8915 | * |
| 8916 | * @return true if the horizontal edges should are faded on scroll, false |
| 8917 | * otherwise |
| 8918 | * |
| 8919 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 8920 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8921 | */ |
| 8922 | public boolean isHorizontalFadingEdgeEnabled() { |
| 8923 | return (mViewFlags & FADING_EDGE_HORIZONTAL) == FADING_EDGE_HORIZONTAL; |
| 8924 | } |
| 8925 | |
| 8926 | /** |
| 8927 | * <p>Define whether the horizontal edges should be faded when this view |
| 8928 | * is scrolled horizontally.</p> |
| 8929 | * |
| 8930 | * @param horizontalFadingEdgeEnabled true if the horizontal edges should |
| 8931 | * be faded when the view is scrolled |
| 8932 | * horizontally |
| 8933 | * |
| 8934 | * @see #isHorizontalFadingEdgeEnabled() |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 8935 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8936 | */ |
| 8937 | public void setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled) { |
| 8938 | if (isHorizontalFadingEdgeEnabled() != horizontalFadingEdgeEnabled) { |
| 8939 | if (horizontalFadingEdgeEnabled) { |
| 8940 | initScrollCache(); |
| 8941 | } |
| 8942 | |
| 8943 | mViewFlags ^= FADING_EDGE_HORIZONTAL; |
| 8944 | } |
| 8945 | } |
| 8946 | |
| 8947 | /** |
| 8948 | * <p>Indicate whether the vertical edges are faded when the view is |
| 8949 | * scrolled horizontally.</p> |
| 8950 | * |
| 8951 | * @return true if the vertical edges should are faded on scroll, false |
| 8952 | * otherwise |
| 8953 | * |
| 8954 | * @see #setVerticalFadingEdgeEnabled(boolean) |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 8955 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8956 | */ |
| 8957 | public boolean isVerticalFadingEdgeEnabled() { |
| 8958 | return (mViewFlags & FADING_EDGE_VERTICAL) == FADING_EDGE_VERTICAL; |
| 8959 | } |
| 8960 | |
| 8961 | /** |
| 8962 | * <p>Define whether the vertical edges should be faded when this view |
| 8963 | * is scrolled vertically.</p> |
| 8964 | * |
| 8965 | * @param verticalFadingEdgeEnabled true if the vertical edges should |
| 8966 | * be faded when the view is scrolled |
| 8967 | * vertically |
| 8968 | * |
| 8969 | * @see #isVerticalFadingEdgeEnabled() |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 8970 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8971 | */ |
| 8972 | public void setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled) { |
| 8973 | if (isVerticalFadingEdgeEnabled() != verticalFadingEdgeEnabled) { |
| 8974 | if (verticalFadingEdgeEnabled) { |
| 8975 | initScrollCache(); |
| 8976 | } |
| 8977 | |
| 8978 | mViewFlags ^= FADING_EDGE_VERTICAL; |
| 8979 | } |
| 8980 | } |
| 8981 | |
| 8982 | /** |
| 8983 | * Returns the strength, or intensity, of the top faded edge. The strength is |
| 8984 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 8985 | * returns 0.0 or 1.0 but no value in between. |
| 8986 | * |
| 8987 | * Subclasses should override this method to provide a smoother fade transition |
| 8988 | * when scrolling occurs. |
| 8989 | * |
| 8990 | * @return the intensity of the top fade as a float between 0.0f and 1.0f |
| 8991 | */ |
| 8992 | protected float getTopFadingEdgeStrength() { |
| 8993 | return computeVerticalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 8994 | } |
| 8995 | |
| 8996 | /** |
| 8997 | * Returns the strength, or intensity, of the bottom faded edge. The strength is |
| 8998 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 8999 | * returns 0.0 or 1.0 but no value in between. |
| 9000 | * |
| 9001 | * Subclasses should override this method to provide a smoother fade transition |
| 9002 | * when scrolling occurs. |
| 9003 | * |
| 9004 | * @return the intensity of the bottom fade as a float between 0.0f and 1.0f |
| 9005 | */ |
| 9006 | protected float getBottomFadingEdgeStrength() { |
| 9007 | return computeVerticalScrollOffset() + computeVerticalScrollExtent() < |
| 9008 | computeVerticalScrollRange() ? 1.0f : 0.0f; |
| 9009 | } |
| 9010 | |
| 9011 | /** |
| 9012 | * Returns the strength, or intensity, of the left faded edge. The strength is |
| 9013 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 9014 | * returns 0.0 or 1.0 but no value in between. |
| 9015 | * |
| 9016 | * Subclasses should override this method to provide a smoother fade transition |
| 9017 | * when scrolling occurs. |
| 9018 | * |
| 9019 | * @return the intensity of the left fade as a float between 0.0f and 1.0f |
| 9020 | */ |
| 9021 | protected float getLeftFadingEdgeStrength() { |
| 9022 | return computeHorizontalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 9023 | } |
| 9024 | |
| 9025 | /** |
| 9026 | * Returns the strength, or intensity, of the right faded edge. The strength is |
| 9027 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 9028 | * returns 0.0 or 1.0 but no value in between. |
| 9029 | * |
| 9030 | * Subclasses should override this method to provide a smoother fade transition |
| 9031 | * when scrolling occurs. |
| 9032 | * |
| 9033 | * @return the intensity of the right fade as a float between 0.0f and 1.0f |
| 9034 | */ |
| 9035 | protected float getRightFadingEdgeStrength() { |
| 9036 | return computeHorizontalScrollOffset() + computeHorizontalScrollExtent() < |
| 9037 | computeHorizontalScrollRange() ? 1.0f : 0.0f; |
| 9038 | } |
| 9039 | |
| 9040 | /** |
| 9041 | * <p>Indicate whether the horizontal scrollbar should be drawn or not. The |
| 9042 | * scrollbar is not drawn by default.</p> |
| 9043 | * |
| 9044 | * @return true if the horizontal scrollbar should be painted, false |
| 9045 | * otherwise |
| 9046 | * |
| 9047 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 9048 | */ |
| 9049 | public boolean isHorizontalScrollBarEnabled() { |
| 9050 | return (mViewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 9051 | } |
| 9052 | |
| 9053 | /** |
| 9054 | * <p>Define whether the horizontal scrollbar should be drawn or not. The |
| 9055 | * scrollbar is not drawn by default.</p> |
| 9056 | * |
| 9057 | * @param horizontalScrollBarEnabled true if the horizontal scrollbar should |
| 9058 | * be painted |
| 9059 | * |
| 9060 | * @see #isHorizontalScrollBarEnabled() |
| 9061 | */ |
| 9062 | public void setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled) { |
| 9063 | if (isHorizontalScrollBarEnabled() != horizontalScrollBarEnabled) { |
| 9064 | mViewFlags ^= SCROLLBARS_HORIZONTAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9065 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9066 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9067 | } |
| 9068 | } |
| 9069 | |
| 9070 | /** |
| 9071 | * <p>Indicate whether the vertical scrollbar should be drawn or not. The |
| 9072 | * scrollbar is not drawn by default.</p> |
| 9073 | * |
| 9074 | * @return true if the vertical scrollbar should be painted, false |
| 9075 | * otherwise |
| 9076 | * |
| 9077 | * @see #setVerticalScrollBarEnabled(boolean) |
| 9078 | */ |
| 9079 | public boolean isVerticalScrollBarEnabled() { |
| 9080 | return (mViewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL; |
| 9081 | } |
| 9082 | |
| 9083 | /** |
| 9084 | * <p>Define whether the vertical scrollbar should be drawn or not. The |
| 9085 | * scrollbar is not drawn by default.</p> |
| 9086 | * |
| 9087 | * @param verticalScrollBarEnabled true if the vertical scrollbar should |
| 9088 | * be painted |
| 9089 | * |
| 9090 | * @see #isVerticalScrollBarEnabled() |
| 9091 | */ |
| 9092 | public void setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled) { |
| 9093 | if (isVerticalScrollBarEnabled() != verticalScrollBarEnabled) { |
| 9094 | mViewFlags ^= SCROLLBARS_VERTICAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9095 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9096 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9097 | } |
| 9098 | } |
| 9099 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 9100 | /** |
| 9101 | * @hide |
| 9102 | */ |
| 9103 | protected void recomputePadding() { |
| 9104 | setPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, mUserPaddingBottom); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9105 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9106 | |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9107 | /** |
| 9108 | * Define whether scrollbars will fade when the view is not scrolling. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9109 | * |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9110 | * @param fadeScrollbars wheter to enable fading |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9111 | * |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9112 | */ |
| 9113 | public void setScrollbarFadingEnabled(boolean fadeScrollbars) { |
| 9114 | initScrollCache(); |
| 9115 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
| 9116 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9117 | if (fadeScrollbars) { |
| 9118 | scrollabilityCache.state = ScrollabilityCache.OFF; |
| 9119 | } else { |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9120 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 9121 | } |
| 9122 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9123 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9124 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9125 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9126 | * Returns true if scrollbars will fade when this view is not scrolling |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9127 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9128 | * @return true if scrollbar fading is enabled |
| 9129 | */ |
| 9130 | public boolean isScrollbarFadingEnabled() { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9131 | return mScrollCache != null && mScrollCache.fadeScrollBars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9132 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9133 | |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 9134 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9135 | * <p>Specify the style of the scrollbars. The scrollbars can be overlaid or |
| 9136 | * inset. When inset, they add to the padding of the view. And the scrollbars |
| 9137 | * can be drawn inside the padding area or on the edge of the view. For example, |
| 9138 | * if a view has a background drawable and you want to draw the scrollbars |
| 9139 | * inside the padding specified by the drawable, you can use |
| 9140 | * SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to |
| 9141 | * appear at the edge of the view, ignoring the padding, then you can use |
| 9142 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.</p> |
| 9143 | * @param style the style of the scrollbars. Should be one of |
| 9144 | * SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, |
| 9145 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET. |
| 9146 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 9147 | * @see #SCROLLBARS_INSIDE_INSET |
| 9148 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 9149 | * @see #SCROLLBARS_OUTSIDE_INSET |
| 9150 | */ |
| 9151 | public void setScrollBarStyle(int style) { |
| 9152 | if (style != (mViewFlags & SCROLLBARS_STYLE_MASK)) { |
| 9153 | mViewFlags = (mViewFlags & ~SCROLLBARS_STYLE_MASK) | (style & SCROLLBARS_STYLE_MASK); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9154 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9155 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9156 | } |
| 9157 | } |
| 9158 | |
| 9159 | /** |
| 9160 | * <p>Returns the current scrollbar style.</p> |
| 9161 | * @return the current scrollbar style |
| 9162 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 9163 | * @see #SCROLLBARS_INSIDE_INSET |
| 9164 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 9165 | * @see #SCROLLBARS_OUTSIDE_INSET |
| 9166 | */ |
Jeff Sharkey | 010d7e5 | 2011-08-08 21:05:02 -0700 | [diff] [blame] | 9167 | @ViewDebug.ExportedProperty(mapping = { |
| 9168 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_OVERLAY, to = "INSIDE_OVERLAY"), |
| 9169 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_INSET, to = "INSIDE_INSET"), |
| 9170 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_OVERLAY, to = "OUTSIDE_OVERLAY"), |
| 9171 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_INSET, to = "OUTSIDE_INSET") |
| 9172 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9173 | public int getScrollBarStyle() { |
| 9174 | return mViewFlags & SCROLLBARS_STYLE_MASK; |
| 9175 | } |
| 9176 | |
| 9177 | /** |
| 9178 | * <p>Compute the horizontal range that the horizontal scrollbar |
| 9179 | * represents.</p> |
| 9180 | * |
| 9181 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9182 | * units used by {@link #computeHorizontalScrollExtent()} and |
| 9183 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 9184 | * |
| 9185 | * <p>The default range is the drawing width of this view.</p> |
| 9186 | * |
| 9187 | * @return the total horizontal range represented by the horizontal |
| 9188 | * scrollbar |
| 9189 | * |
| 9190 | * @see #computeHorizontalScrollExtent() |
| 9191 | * @see #computeHorizontalScrollOffset() |
| 9192 | * @see android.widget.ScrollBarDrawable |
| 9193 | */ |
| 9194 | protected int computeHorizontalScrollRange() { |
| 9195 | return getWidth(); |
| 9196 | } |
| 9197 | |
| 9198 | /** |
| 9199 | * <p>Compute the horizontal offset of the horizontal scrollbar's thumb |
| 9200 | * within the horizontal range. This value is used to compute the position |
| 9201 | * of the thumb within the scrollbar's track.</p> |
| 9202 | * |
| 9203 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9204 | * units used by {@link #computeHorizontalScrollRange()} and |
| 9205 | * {@link #computeHorizontalScrollExtent()}.</p> |
| 9206 | * |
| 9207 | * <p>The default offset is the scroll offset of this view.</p> |
| 9208 | * |
| 9209 | * @return the horizontal offset of the scrollbar's thumb |
| 9210 | * |
| 9211 | * @see #computeHorizontalScrollRange() |
| 9212 | * @see #computeHorizontalScrollExtent() |
| 9213 | * @see android.widget.ScrollBarDrawable |
| 9214 | */ |
| 9215 | protected int computeHorizontalScrollOffset() { |
| 9216 | return mScrollX; |
| 9217 | } |
| 9218 | |
| 9219 | /** |
| 9220 | * <p>Compute the horizontal extent of the horizontal scrollbar's thumb |
| 9221 | * within the horizontal range. This value is used to compute the length |
| 9222 | * of the thumb within the scrollbar's track.</p> |
| 9223 | * |
| 9224 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9225 | * units used by {@link #computeHorizontalScrollRange()} and |
| 9226 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 9227 | * |
| 9228 | * <p>The default extent is the drawing width of this view.</p> |
| 9229 | * |
| 9230 | * @return the horizontal extent of the scrollbar's thumb |
| 9231 | * |
| 9232 | * @see #computeHorizontalScrollRange() |
| 9233 | * @see #computeHorizontalScrollOffset() |
| 9234 | * @see android.widget.ScrollBarDrawable |
| 9235 | */ |
| 9236 | protected int computeHorizontalScrollExtent() { |
| 9237 | return getWidth(); |
| 9238 | } |
| 9239 | |
| 9240 | /** |
| 9241 | * <p>Compute the vertical range that the vertical scrollbar represents.</p> |
| 9242 | * |
| 9243 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9244 | * units used by {@link #computeVerticalScrollExtent()} and |
| 9245 | * {@link #computeVerticalScrollOffset()}.</p> |
| 9246 | * |
| 9247 | * @return the total vertical range represented by the vertical scrollbar |
| 9248 | * |
| 9249 | * <p>The default range is the drawing height of this view.</p> |
| 9250 | * |
| 9251 | * @see #computeVerticalScrollExtent() |
| 9252 | * @see #computeVerticalScrollOffset() |
| 9253 | * @see android.widget.ScrollBarDrawable |
| 9254 | */ |
| 9255 | protected int computeVerticalScrollRange() { |
| 9256 | return getHeight(); |
| 9257 | } |
| 9258 | |
| 9259 | /** |
| 9260 | * <p>Compute the vertical offset of the vertical scrollbar's thumb |
| 9261 | * within the horizontal range. This value is used to compute the position |
| 9262 | * of the thumb within the scrollbar's track.</p> |
| 9263 | * |
| 9264 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 9265 | * units used by {@link #computeVerticalScrollRange()} and |
| 9266 | * {@link #computeVerticalScrollExtent()}.</p> |
| 9267 | * |
| 9268 | * <p>The default offset is the scroll offset of this view.</p> |
| 9269 | * |
| 9270 | * @return the vertical offset of the scrollbar's thumb |
| 9271 | * |
| 9272 | * @see #computeVerticalScrollRange() |
| 9273 | * @see #computeVerticalScrollExtent() |
| 9274 | * @see android.widget.ScrollBarDrawable |
| 9275 | */ |
| 9276 | protected int computeVerticalScrollOffset() { |
| 9277 | return mScrollY; |
| 9278 | } |
| 9279 | |
| 9280 | /** |
| 9281 | * <p>Compute the vertical extent of the horizontal scrollbar's thumb |
| 9282 | * within the vertical range. This value is used to compute the length |
| 9283 | * of the thumb within the scrollbar's track.</p> |
| 9284 | * |
| 9285 | * <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] | 9286 | * units used by {@link #computeVerticalScrollRange()} and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9287 | * {@link #computeVerticalScrollOffset()}.</p> |
| 9288 | * |
| 9289 | * <p>The default extent is the drawing height of this view.</p> |
| 9290 | * |
| 9291 | * @return the vertical extent of the scrollbar's thumb |
| 9292 | * |
| 9293 | * @see #computeVerticalScrollRange() |
| 9294 | * @see #computeVerticalScrollOffset() |
| 9295 | * @see android.widget.ScrollBarDrawable |
| 9296 | */ |
| 9297 | protected int computeVerticalScrollExtent() { |
| 9298 | return getHeight(); |
| 9299 | } |
| 9300 | |
| 9301 | /** |
Adam Powell | 6915944 | 2011-06-13 17:53:06 -0700 | [diff] [blame] | 9302 | * Check if this view can be scrolled horizontally in a certain direction. |
| 9303 | * |
| 9304 | * @param direction Negative to check scrolling left, positive to check scrolling right. |
| 9305 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 9306 | */ |
| 9307 | public boolean canScrollHorizontally(int direction) { |
| 9308 | final int offset = computeHorizontalScrollOffset(); |
| 9309 | final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent(); |
| 9310 | if (range == 0) return false; |
| 9311 | if (direction < 0) { |
| 9312 | return offset > 0; |
| 9313 | } else { |
| 9314 | return offset < range - 1; |
| 9315 | } |
| 9316 | } |
| 9317 | |
| 9318 | /** |
| 9319 | * Check if this view can be scrolled vertically in a certain direction. |
| 9320 | * |
| 9321 | * @param direction Negative to check scrolling up, positive to check scrolling down. |
| 9322 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 9323 | */ |
| 9324 | public boolean canScrollVertically(int direction) { |
| 9325 | final int offset = computeVerticalScrollOffset(); |
| 9326 | final int range = computeVerticalScrollRange() - computeVerticalScrollExtent(); |
| 9327 | if (range == 0) return false; |
| 9328 | if (direction < 0) { |
| 9329 | return offset > 0; |
| 9330 | } else { |
| 9331 | return offset < range - 1; |
| 9332 | } |
| 9333 | } |
| 9334 | |
| 9335 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9336 | * <p>Request the drawing of the horizontal and the vertical scrollbar. The |
| 9337 | * scrollbars are painted only if they have been awakened first.</p> |
| 9338 | * |
| 9339 | * @param canvas the canvas on which to draw the scrollbars |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9340 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9341 | * @see #awakenScrollBars(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9342 | */ |
Romain Guy | 1d5b3a6 | 2009-11-05 18:44:12 -0800 | [diff] [blame] | 9343 | protected final void onDrawScrollBars(Canvas canvas) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9344 | // scrollbars are drawn only when the animation is running |
| 9345 | final ScrollabilityCache cache = mScrollCache; |
| 9346 | if (cache != null) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9347 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9348 | int state = cache.state; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9349 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9350 | if (state == ScrollabilityCache.OFF) { |
| 9351 | return; |
| 9352 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9353 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9354 | boolean invalidate = false; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9355 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9356 | if (state == ScrollabilityCache.FADING) { |
| 9357 | // We're fading -- get our fade interpolation |
| 9358 | if (cache.interpolatorValues == null) { |
| 9359 | cache.interpolatorValues = new float[1]; |
| 9360 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9361 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9362 | float[] values = cache.interpolatorValues; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9363 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9364 | // Stops the animation if we're done |
| 9365 | if (cache.scrollBarInterpolator.timeToValues(values) == |
| 9366 | Interpolator.Result.FREEZE_END) { |
| 9367 | cache.state = ScrollabilityCache.OFF; |
| 9368 | } else { |
| 9369 | cache.scrollBar.setAlpha(Math.round(values[0])); |
| 9370 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9371 | |
| 9372 | // This will make the scroll bars inval themselves after |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9373 | // drawing. We only want this when we're fading so that |
| 9374 | // we prevent excessive redraws |
| 9375 | invalidate = true; |
| 9376 | } else { |
| 9377 | // We're just on -- but we may have been fading before so |
| 9378 | // reset alpha |
| 9379 | cache.scrollBar.setAlpha(255); |
| 9380 | } |
| 9381 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9383 | final int viewFlags = mViewFlags; |
| 9384 | |
| 9385 | final boolean drawHorizontalScrollBar = |
| 9386 | (viewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 9387 | final boolean drawVerticalScrollBar = |
| 9388 | (viewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL |
| 9389 | && !isVerticalScrollBarHidden(); |
| 9390 | |
| 9391 | if (drawVerticalScrollBar || drawHorizontalScrollBar) { |
| 9392 | final int width = mRight - mLeft; |
| 9393 | final int height = mBottom - mTop; |
| 9394 | |
| 9395 | final ScrollBarDrawable scrollBar = cache.scrollBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9396 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9397 | final int scrollX = mScrollX; |
| 9398 | final int scrollY = mScrollY; |
| 9399 | final int inside = (viewFlags & SCROLLBARS_OUTSIDE_MASK) == 0 ? ~0 : 0; |
| 9400 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9401 | int left, top, right, bottom; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9402 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9403 | if (drawHorizontalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 9404 | int size = scrollBar.getSize(false); |
| 9405 | if (size <= 0) { |
| 9406 | size = cache.scrollBarSize; |
| 9407 | } |
| 9408 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9409 | scrollBar.setParameters(computeHorizontalScrollRange(), |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9410 | computeHorizontalScrollOffset(), |
| 9411 | computeHorizontalScrollExtent(), false); |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9412 | final int verticalScrollBarGap = drawVerticalScrollBar ? |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9413 | getVerticalScrollbarWidth() : 0; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9414 | top = scrollY + height - size - (mUserPaddingBottom & inside); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9415 | left = scrollX + (mPaddingLeft & inside); |
| 9416 | right = scrollX + width - (mUserPaddingRight & inside) - verticalScrollBarGap; |
| 9417 | bottom = top + size; |
| 9418 | onDrawHorizontalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 9419 | if (invalidate) { |
| 9420 | invalidate(left, top, right, bottom); |
| 9421 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9422 | } |
| 9423 | |
| 9424 | if (drawVerticalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 9425 | int size = scrollBar.getSize(true); |
| 9426 | if (size <= 0) { |
| 9427 | size = cache.scrollBarSize; |
| 9428 | } |
| 9429 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9430 | scrollBar.setParameters(computeVerticalScrollRange(), |
| 9431 | computeVerticalScrollOffset(), |
| 9432 | computeVerticalScrollExtent(), true); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 9433 | switch (mVerticalScrollbarPosition) { |
| 9434 | default: |
| 9435 | case SCROLLBAR_POSITION_DEFAULT: |
| 9436 | case SCROLLBAR_POSITION_RIGHT: |
| 9437 | left = scrollX + width - size - (mUserPaddingRight & inside); |
| 9438 | break; |
| 9439 | case SCROLLBAR_POSITION_LEFT: |
| 9440 | left = scrollX + (mUserPaddingLeft & inside); |
| 9441 | break; |
| 9442 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9443 | top = scrollY + (mPaddingTop & inside); |
| 9444 | right = left + size; |
| 9445 | bottom = scrollY + height - (mUserPaddingBottom & inside); |
| 9446 | onDrawVerticalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 9447 | if (invalidate) { |
| 9448 | invalidate(left, top, right, bottom); |
| 9449 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9450 | } |
| 9451 | } |
| 9452 | } |
| 9453 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 9454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9455 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 9456 | * 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] | 9457 | * FastScroller is visible. |
| 9458 | * @return whether to temporarily hide the vertical scrollbar |
| 9459 | * @hide |
| 9460 | */ |
| 9461 | protected boolean isVerticalScrollBarHidden() { |
| 9462 | return false; |
| 9463 | } |
| 9464 | |
| 9465 | /** |
| 9466 | * <p>Draw the horizontal scrollbar if |
| 9467 | * {@link #isHorizontalScrollBarEnabled()} returns true.</p> |
| 9468 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9469 | * @param canvas the canvas on which to draw the scrollbar |
| 9470 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9471 | * |
| 9472 | * @see #isHorizontalScrollBarEnabled() |
| 9473 | * @see #computeHorizontalScrollRange() |
| 9474 | * @see #computeHorizontalScrollExtent() |
| 9475 | * @see #computeHorizontalScrollOffset() |
| 9476 | * @see android.widget.ScrollBarDrawable |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9477 | * @hide |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 9478 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 9479 | protected void onDrawHorizontalScrollBar(Canvas canvas, Drawable scrollBar, |
| 9480 | int l, int t, int r, int b) { |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 9481 | scrollBar.setBounds(l, t, r, b); |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 9482 | scrollBar.draw(canvas); |
| 9483 | } |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9484 | |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 9485 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9486 | * <p>Draw the vertical scrollbar if {@link #isVerticalScrollBarEnabled()} |
| 9487 | * returns true.</p> |
| 9488 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9489 | * @param canvas the canvas on which to draw the scrollbar |
| 9490 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9491 | * |
| 9492 | * @see #isVerticalScrollBarEnabled() |
| 9493 | * @see #computeVerticalScrollRange() |
| 9494 | * @see #computeVerticalScrollExtent() |
| 9495 | * @see #computeVerticalScrollOffset() |
| 9496 | * @see android.widget.ScrollBarDrawable |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9497 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9498 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 9499 | protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, |
| 9500 | int l, int t, int r, int b) { |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 9501 | scrollBar.setBounds(l, t, r, b); |
| 9502 | scrollBar.draw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9503 | } |
| 9504 | |
| 9505 | /** |
| 9506 | * Implement this to do your drawing. |
| 9507 | * |
| 9508 | * @param canvas the canvas on which the background will be drawn |
| 9509 | */ |
| 9510 | protected void onDraw(Canvas canvas) { |
| 9511 | } |
| 9512 | |
| 9513 | /* |
| 9514 | * Caller is responsible for calling requestLayout if necessary. |
| 9515 | * (This allows addViewInLayout to not request a new layout.) |
| 9516 | */ |
| 9517 | void assignParent(ViewParent parent) { |
| 9518 | if (mParent == null) { |
| 9519 | mParent = parent; |
| 9520 | } else if (parent == null) { |
| 9521 | mParent = null; |
| 9522 | } else { |
| 9523 | throw new RuntimeException("view " + this + " being added, but" |
| 9524 | + " it already has a parent"); |
| 9525 | } |
| 9526 | } |
| 9527 | |
| 9528 | /** |
| 9529 | * This is called when the view is attached to a window. At this point it |
| 9530 | * has a Surface and will start drawing. Note that this function is |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9531 | * guaranteed to be called before {@link #onDraw(android.graphics.Canvas)}, |
| 9532 | * however it may be called any time before the first onDraw -- including |
| 9533 | * before or after {@link #onMeasure(int, int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9534 | * |
| 9535 | * @see #onDetachedFromWindow() |
| 9536 | */ |
| 9537 | protected void onAttachedToWindow() { |
| 9538 | if ((mPrivateFlags & REQUEST_TRANSPARENT_REGIONS) != 0) { |
| 9539 | mParent.requestTransparentRegion(this); |
| 9540 | } |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 9541 | if ((mPrivateFlags & AWAKEN_SCROLL_BARS_ON_ATTACH) != 0) { |
| 9542 | initialAwakenScrollBars(); |
| 9543 | mPrivateFlags &= ~AWAKEN_SCROLL_BARS_ON_ATTACH; |
| 9544 | } |
Chet Haase | a9b61ac | 2010-12-20 07:40:25 -0800 | [diff] [blame] | 9545 | jumpDrawablesToCurrentState(); |
Fabrice Di Meglio | a646145 | 2011-08-19 15:42:04 -0700 | [diff] [blame] | 9546 | // Order is important here: LayoutDirection MUST be resolved before Padding |
| 9547 | // and TextDirection |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9548 | resolveLayoutDirectionIfNeeded(); |
| 9549 | resolvePadding(); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 9550 | resolveTextDirection(); |
Amith Yamasani | 4503c8d | 2011-06-17 12:36:14 -0700 | [diff] [blame] | 9551 | if (isFocused()) { |
| 9552 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 9553 | imm.focusIn(this); |
| 9554 | } |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 9555 | } |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 9556 | |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 9557 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9558 | * Resolve and cache the layout direction. LTR is set initially. This is implicitly supposing |
| 9559 | * 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] | 9560 | */ |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9561 | private void resolveLayoutDirectionIfNeeded() { |
| 9562 | // Do not resolve if it is not needed |
| 9563 | if ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED) == LAYOUT_DIRECTION_RESOLVED) return; |
| 9564 | |
| 9565 | // Clear any previous layout direction resolution |
| 9566 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_RTL; |
| 9567 | |
Fabrice Di Meglio | 4b60c30 | 2011-08-17 16:56:55 -0700 | [diff] [blame] | 9568 | // Reset also TextDirection as a change into LayoutDirection may impact the selected |
| 9569 | // TextDirectionHeuristic |
| 9570 | resetResolvedTextDirection(); |
| 9571 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9572 | // Set resolved depending on layout direction |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 9573 | switch (getLayoutDirection()) { |
| 9574 | case LAYOUT_DIRECTION_INHERIT: |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 9575 | // We cannot do the resolution if there is no parent |
| 9576 | if (mParent == null) return; |
| 9577 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 9578 | // 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] | 9579 | if (mParent instanceof ViewGroup) { |
| 9580 | ViewGroup viewGroup = ((ViewGroup) mParent); |
| 9581 | |
| 9582 | // Check if the parent view group can resolve |
| 9583 | if (! viewGroup.canResolveLayoutDirection()) { |
| 9584 | return; |
| 9585 | } |
| 9586 | if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
| 9587 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
| 9588 | } |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 9589 | } |
| 9590 | break; |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 9591 | case LAYOUT_DIRECTION_RTL: |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9592 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 9593 | break; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 9594 | case LAYOUT_DIRECTION_LOCALE: |
| 9595 | if(isLayoutDirectionRtl(Locale.getDefault())) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9596 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 9597 | } |
| 9598 | break; |
| 9599 | default: |
| 9600 | // Nothing to do, LTR by default |
| 9601 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9602 | |
| 9603 | // Set to resolved |
| 9604 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED; |
| 9605 | } |
| 9606 | |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 9607 | /** |
| 9608 | * @hide |
| 9609 | */ |
| 9610 | protected void resolvePadding() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9611 | // If the user specified the absolute padding (either with android:padding or |
| 9612 | // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise |
| 9613 | // use the default padding or the padding from the background drawable |
| 9614 | // (stored at this point in mPadding*) |
| 9615 | switch (getResolvedLayoutDirection()) { |
| 9616 | case LAYOUT_DIRECTION_RTL: |
| 9617 | // Start user padding override Right user padding. Otherwise, if Right user |
| 9618 | // padding is not defined, use the default Right padding. If Right user padding |
| 9619 | // is defined, just use it. |
| 9620 | if (mUserPaddingStart >= 0) { |
| 9621 | mUserPaddingRight = mUserPaddingStart; |
| 9622 | } else if (mUserPaddingRight < 0) { |
| 9623 | mUserPaddingRight = mPaddingRight; |
| 9624 | } |
| 9625 | if (mUserPaddingEnd >= 0) { |
| 9626 | mUserPaddingLeft = mUserPaddingEnd; |
| 9627 | } else if (mUserPaddingLeft < 0) { |
| 9628 | mUserPaddingLeft = mPaddingLeft; |
| 9629 | } |
| 9630 | break; |
| 9631 | case LAYOUT_DIRECTION_LTR: |
| 9632 | default: |
| 9633 | // Start user padding override Left user padding. Otherwise, if Left user |
| 9634 | // padding is not defined, use the default left padding. If Left user padding |
| 9635 | // is defined, just use it. |
Fabrice Di Meglio | f3e1a93 | 2011-07-15 17:15:39 -0700 | [diff] [blame] | 9636 | if (mUserPaddingStart >= 0) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9637 | mUserPaddingLeft = mUserPaddingStart; |
| 9638 | } else if (mUserPaddingLeft < 0) { |
| 9639 | mUserPaddingLeft = mPaddingLeft; |
| 9640 | } |
Fabrice Di Meglio | f3e1a93 | 2011-07-15 17:15:39 -0700 | [diff] [blame] | 9641 | if (mUserPaddingEnd >= 0) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9642 | mUserPaddingRight = mUserPaddingEnd; |
| 9643 | } else if (mUserPaddingRight < 0) { |
| 9644 | mUserPaddingRight = mPaddingRight; |
| 9645 | } |
| 9646 | } |
| 9647 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9648 | mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom; |
| 9649 | |
| 9650 | recomputePadding(); |
| 9651 | } |
| 9652 | |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 9653 | /** |
| 9654 | * Return true if layout direction resolution can be done |
| 9655 | * |
| 9656 | * @hide |
| 9657 | */ |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 9658 | protected boolean canResolveLayoutDirection() { |
| 9659 | switch (getLayoutDirection()) { |
| 9660 | case LAYOUT_DIRECTION_INHERIT: |
| 9661 | return (mParent != null); |
| 9662 | default: |
| 9663 | return true; |
| 9664 | } |
| 9665 | } |
| 9666 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9667 | /** |
Doug Felt | c0ccf0c | 2011-06-23 16:13:18 -0700 | [diff] [blame] | 9668 | * Reset the resolved layout direction. |
| 9669 | * |
| 9670 | * Subclasses need to override this method to clear cached information that depends on the |
| 9671 | * resolved layout direction, or to inform child views that inherit their layout direction. |
| 9672 | * Overrides must also call the superclass implementation at the start of their implementation. |
| 9673 | * |
| 9674 | * @hide |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9675 | */ |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 9676 | protected void resetResolvedLayoutDirection() { |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 9677 | // Reset the current View resolution |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 9678 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 9679 | } |
| 9680 | |
| 9681 | /** |
| 9682 | * Check if a Locale is corresponding to a RTL script. |
| 9683 | * |
| 9684 | * @param locale Locale to check |
| 9685 | * @return true if a Locale is corresponding to a RTL script. |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 9686 | * |
| 9687 | * @hide |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 9688 | */ |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 9689 | protected static boolean isLayoutDirectionRtl(Locale locale) { |
Fabrice Di Meglio | a47f45e | 2011-06-15 14:22:12 -0700 | [diff] [blame] | 9690 | return (LocaleUtil.TEXT_LAYOUT_DIRECTION_RTL_DO_NOT_USE == |
| 9691 | LocaleUtil.getLayoutDirectionFromLocale(locale)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9692 | } |
| 9693 | |
| 9694 | /** |
| 9695 | * This is called when the view is detached from a window. At this point it |
| 9696 | * no longer has a surface for drawing. |
| 9697 | * |
| 9698 | * @see #onAttachedToWindow() |
| 9699 | */ |
| 9700 | protected void onDetachedFromWindow() { |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 9701 | mPrivateFlags &= ~CANCEL_NEXT_UP_EVENT; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9702 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 9703 | removeUnsetPressCallback(); |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 9704 | removeLongPressCallback(); |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 9705 | removePerformClickCallback(); |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 9706 | removeSendViewScrolledAccessibilityEventCallback(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9707 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9708 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 9709 | |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 9710 | destroyLayer(); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 9711 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9712 | if (mDisplayList != null) { |
| 9713 | mDisplayList.invalidate(); |
| 9714 | } |
| 9715 | |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 9716 | if (mAttachInfo != null) { |
| 9717 | mAttachInfo.mHandler.removeMessages(AttachInfo.INVALIDATE_MSG, this); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 9718 | } |
| 9719 | |
Patrick Dubroy | ec84c3a | 2011-01-13 17:55:37 -0800 | [diff] [blame] | 9720 | mCurrentAnimation = null; |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 9721 | |
| 9722 | resetResolvedLayoutDirection(); |
| 9723 | resetResolvedTextDirection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9724 | } |
| 9725 | |
| 9726 | /** |
| 9727 | * @return The number of times this view has been attached to a window |
| 9728 | */ |
| 9729 | protected int getWindowAttachCount() { |
| 9730 | return mWindowAttachCount; |
| 9731 | } |
| 9732 | |
| 9733 | /** |
| 9734 | * Retrieve a unique token identifying the window this view is attached to. |
| 9735 | * @return Return the window's token for use in |
| 9736 | * {@link WindowManager.LayoutParams#token WindowManager.LayoutParams.token}. |
| 9737 | */ |
| 9738 | public IBinder getWindowToken() { |
| 9739 | return mAttachInfo != null ? mAttachInfo.mWindowToken : null; |
| 9740 | } |
| 9741 | |
| 9742 | /** |
| 9743 | * Retrieve a unique token identifying the top-level "real" window of |
| 9744 | * the window that this view is attached to. That is, this is like |
| 9745 | * {@link #getWindowToken}, except if the window this view in is a panel |
| 9746 | * window (attached to another containing window), then the token of |
| 9747 | * the containing window is returned instead. |
| 9748 | * |
| 9749 | * @return Returns the associated window token, either |
| 9750 | * {@link #getWindowToken()} or the containing window's token. |
| 9751 | */ |
| 9752 | public IBinder getApplicationWindowToken() { |
| 9753 | AttachInfo ai = mAttachInfo; |
| 9754 | if (ai != null) { |
| 9755 | IBinder appWindowToken = ai.mPanelParentWindowToken; |
| 9756 | if (appWindowToken == null) { |
| 9757 | appWindowToken = ai.mWindowToken; |
| 9758 | } |
| 9759 | return appWindowToken; |
| 9760 | } |
| 9761 | return null; |
| 9762 | } |
| 9763 | |
| 9764 | /** |
| 9765 | * Retrieve private session object this view hierarchy is using to |
| 9766 | * communicate with the window manager. |
| 9767 | * @return the session object to communicate with the window manager |
| 9768 | */ |
| 9769 | /*package*/ IWindowSession getWindowSession() { |
| 9770 | return mAttachInfo != null ? mAttachInfo.mSession : null; |
| 9771 | } |
| 9772 | |
| 9773 | /** |
| 9774 | * @param info the {@link android.view.View.AttachInfo} to associated with |
| 9775 | * this view |
| 9776 | */ |
| 9777 | void dispatchAttachedToWindow(AttachInfo info, int visibility) { |
| 9778 | //System.out.println("Attached! " + this); |
| 9779 | mAttachInfo = info; |
| 9780 | mWindowAttachCount++; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 9781 | // We will need to evaluate the drawable state at least once. |
| 9782 | mPrivateFlags |= DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9783 | if (mFloatingTreeObserver != null) { |
| 9784 | info.mTreeObserver.merge(mFloatingTreeObserver); |
| 9785 | mFloatingTreeObserver = null; |
| 9786 | } |
| 9787 | if ((mPrivateFlags&SCROLL_CONTAINER) != 0) { |
| 9788 | mAttachInfo.mScrollContainers.add(this); |
| 9789 | mPrivateFlags |= SCROLL_CONTAINER_ADDED; |
| 9790 | } |
| 9791 | performCollectViewAttributes(visibility); |
| 9792 | onAttachedToWindow(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 9793 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 9794 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 9795 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 9796 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 9797 | if (listeners != null && listeners.size() > 0) { |
| 9798 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 9799 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 9800 | // could mutate the list by calling the various add/remove methods. This prevents |
| 9801 | // the array from being modified while we iterate it. |
| 9802 | for (OnAttachStateChangeListener listener : listeners) { |
| 9803 | listener.onViewAttachedToWindow(this); |
| 9804 | } |
| 9805 | } |
| 9806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9807 | int vis = info.mWindowVisibility; |
| 9808 | if (vis != GONE) { |
| 9809 | onWindowVisibilityChanged(vis); |
| 9810 | } |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 9811 | if ((mPrivateFlags&DRAWABLE_STATE_DIRTY) != 0) { |
| 9812 | // If nobody has evaluated the drawable state yet, then do it now. |
| 9813 | refreshDrawableState(); |
| 9814 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9815 | } |
| 9816 | |
| 9817 | void dispatchDetachedFromWindow() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9818 | AttachInfo info = mAttachInfo; |
| 9819 | if (info != null) { |
| 9820 | int vis = info.mWindowVisibility; |
| 9821 | if (vis != GONE) { |
| 9822 | onWindowVisibilityChanged(GONE); |
| 9823 | } |
| 9824 | } |
| 9825 | |
| 9826 | onDetachedFromWindow(); |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 9827 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 9828 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 9829 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 9830 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 9831 | if (listeners != null && listeners.size() > 0) { |
| 9832 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 9833 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 9834 | // could mutate the list by calling the various add/remove methods. This prevents |
| 9835 | // the array from being modified while we iterate it. |
| 9836 | for (OnAttachStateChangeListener listener : listeners) { |
| 9837 | listener.onViewDetachedFromWindow(this); |
| 9838 | } |
| 9839 | } |
| 9840 | |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 9841 | if ((mPrivateFlags & SCROLL_CONTAINER_ADDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9842 | mAttachInfo.mScrollContainers.remove(this); |
| 9843 | mPrivateFlags &= ~SCROLL_CONTAINER_ADDED; |
| 9844 | } |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 9845 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9846 | mAttachInfo = null; |
| 9847 | } |
| 9848 | |
| 9849 | /** |
| 9850 | * Store this view hierarchy's frozen state into the given container. |
| 9851 | * |
| 9852 | * @param container The SparseArray in which to save the view's state. |
| 9853 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9854 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 9855 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 9856 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9857 | */ |
| 9858 | public void saveHierarchyState(SparseArray<Parcelable> container) { |
| 9859 | dispatchSaveInstanceState(container); |
| 9860 | } |
| 9861 | |
| 9862 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9863 | * Called by {@link #saveHierarchyState(android.util.SparseArray)} to store the state for |
| 9864 | * this view and its children. May be overridden to modify how freezing happens to a |
| 9865 | * 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] | 9866 | * |
| 9867 | * @param container The SparseArray in which to save the view's state. |
| 9868 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9869 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 9870 | * @see #saveHierarchyState(android.util.SparseArray) |
| 9871 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9872 | */ |
| 9873 | protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { |
| 9874 | if (mID != NO_ID && (mViewFlags & SAVE_DISABLED_MASK) == 0) { |
| 9875 | mPrivateFlags &= ~SAVE_STATE_CALLED; |
| 9876 | Parcelable state = onSaveInstanceState(); |
| 9877 | if ((mPrivateFlags & SAVE_STATE_CALLED) == 0) { |
| 9878 | throw new IllegalStateException( |
| 9879 | "Derived class did not call super.onSaveInstanceState()"); |
| 9880 | } |
| 9881 | if (state != null) { |
| 9882 | // Log.i("View", "Freezing #" + Integer.toHexString(mID) |
| 9883 | // + ": " + state); |
| 9884 | container.put(mID, state); |
| 9885 | } |
| 9886 | } |
| 9887 | } |
| 9888 | |
| 9889 | /** |
| 9890 | * Hook allowing a view to generate a representation of its internal state |
| 9891 | * that can later be used to create a new instance with that same state. |
| 9892 | * This state should only contain information that is not persistent or can |
| 9893 | * not be reconstructed later. For example, you will never store your |
| 9894 | * current position on screen because that will be computed again when a |
| 9895 | * new instance of the view is placed in its view hierarchy. |
| 9896 | * <p> |
| 9897 | * Some examples of things you may store here: the current cursor position |
| 9898 | * in a text view (but usually not the text itself since that is stored in a |
| 9899 | * content provider or other persistent storage), the currently selected |
| 9900 | * item in a list view. |
| 9901 | * |
| 9902 | * @return Returns a Parcelable object containing the view's current dynamic |
| 9903 | * state, or null if there is nothing interesting to save. The |
| 9904 | * default implementation returns null. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9905 | * @see #onRestoreInstanceState(android.os.Parcelable) |
| 9906 | * @see #saveHierarchyState(android.util.SparseArray) |
| 9907 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9908 | * @see #setSaveEnabled(boolean) |
| 9909 | */ |
| 9910 | protected Parcelable onSaveInstanceState() { |
| 9911 | mPrivateFlags |= SAVE_STATE_CALLED; |
| 9912 | return BaseSavedState.EMPTY_STATE; |
| 9913 | } |
| 9914 | |
| 9915 | /** |
| 9916 | * Restore this view hierarchy's frozen state from the given container. |
| 9917 | * |
| 9918 | * @param container The SparseArray which holds previously frozen states. |
| 9919 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9920 | * @see #saveHierarchyState(android.util.SparseArray) |
| 9921 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 9922 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9923 | */ |
| 9924 | public void restoreHierarchyState(SparseArray<Parcelable> container) { |
| 9925 | dispatchRestoreInstanceState(container); |
| 9926 | } |
| 9927 | |
| 9928 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9929 | * Called by {@link #restoreHierarchyState(android.util.SparseArray)} to retrieve the |
| 9930 | * state for this view and its children. May be overridden to modify how restoring |
| 9931 | * happens to a view's children; for example, some views may want to not store state |
| 9932 | * for their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9933 | * |
| 9934 | * @param container The SparseArray which holds previously saved state. |
| 9935 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9936 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 9937 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 9938 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9939 | */ |
| 9940 | protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 9941 | if (mID != NO_ID) { |
| 9942 | Parcelable state = container.get(mID); |
| 9943 | if (state != null) { |
| 9944 | // Log.i("View", "Restoreing #" + Integer.toHexString(mID) |
| 9945 | // + ": " + state); |
| 9946 | mPrivateFlags &= ~SAVE_STATE_CALLED; |
| 9947 | onRestoreInstanceState(state); |
| 9948 | if ((mPrivateFlags & SAVE_STATE_CALLED) == 0) { |
| 9949 | throw new IllegalStateException( |
| 9950 | "Derived class did not call super.onRestoreInstanceState()"); |
| 9951 | } |
| 9952 | } |
| 9953 | } |
| 9954 | } |
| 9955 | |
| 9956 | /** |
| 9957 | * Hook allowing a view to re-apply a representation of its internal state that had previously |
| 9958 | * been generated by {@link #onSaveInstanceState}. This function will never be called with a |
| 9959 | * null state. |
| 9960 | * |
| 9961 | * @param state The frozen state that had previously been returned by |
| 9962 | * {@link #onSaveInstanceState}. |
| 9963 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9964 | * @see #onSaveInstanceState() |
| 9965 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 9966 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9967 | */ |
| 9968 | protected void onRestoreInstanceState(Parcelable state) { |
| 9969 | mPrivateFlags |= SAVE_STATE_CALLED; |
| 9970 | if (state != BaseSavedState.EMPTY_STATE && state != null) { |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 9971 | throw new IllegalArgumentException("Wrong state class, expecting View State but " |
| 9972 | + "received " + state.getClass().toString() + " instead. This usually happens " |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9973 | + "when two views of different type have the same id in the same hierarchy. " |
| 9974 | + "This view's id is " + ViewDebug.resolveId(mContext, getId()) + ". Make sure " |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 9975 | + "other views do not use the same id."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9976 | } |
| 9977 | } |
| 9978 | |
| 9979 | /** |
| 9980 | * <p>Return the time at which the drawing of the view hierarchy started.</p> |
| 9981 | * |
| 9982 | * @return the drawing start time in milliseconds |
| 9983 | */ |
| 9984 | public long getDrawingTime() { |
| 9985 | return mAttachInfo != null ? mAttachInfo.mDrawingTime : 0; |
| 9986 | } |
| 9987 | |
| 9988 | /** |
| 9989 | * <p>Enables or disables the duplication of the parent's state into this view. When |
| 9990 | * duplication is enabled, this view gets its drawable state from its parent rather |
| 9991 | * than from its own internal properties.</p> |
| 9992 | * |
| 9993 | * <p>Note: in the current implementation, setting this property to true after the |
| 9994 | * view was added to a ViewGroup might have no effect at all. This property should |
| 9995 | * always be used from XML or set to true before adding this view to a ViewGroup.</p> |
| 9996 | * |
| 9997 | * <p>Note: if this view's parent addStateFromChildren property is enabled and this |
| 9998 | * property is enabled, an exception will be thrown.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9999 | * |
Gilles Debunne | fb81703 | 2011-01-13 13:52:49 -0800 | [diff] [blame] | 10000 | * <p>Note: if the child view uses and updates additionnal states which are unknown to the |
| 10001 | * 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] | 10002 | * |
| 10003 | * @param enabled True to enable duplication of the parent's drawable state, false |
| 10004 | * to disable it. |
| 10005 | * |
| 10006 | * @see #getDrawableState() |
| 10007 | * @see #isDuplicateParentStateEnabled() |
| 10008 | */ |
| 10009 | public void setDuplicateParentStateEnabled(boolean enabled) { |
| 10010 | setFlags(enabled ? DUPLICATE_PARENT_STATE : 0, DUPLICATE_PARENT_STATE); |
| 10011 | } |
| 10012 | |
| 10013 | /** |
| 10014 | * <p>Indicates whether this duplicates its drawable state from its parent.</p> |
| 10015 | * |
| 10016 | * @return True if this view's drawable state is duplicated from the parent, |
| 10017 | * false otherwise |
| 10018 | * |
| 10019 | * @see #getDrawableState() |
| 10020 | * @see #setDuplicateParentStateEnabled(boolean) |
| 10021 | */ |
| 10022 | public boolean isDuplicateParentStateEnabled() { |
| 10023 | return (mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE; |
| 10024 | } |
| 10025 | |
| 10026 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10027 | * <p>Specifies the type of layer backing this view. The layer can be |
| 10028 | * {@link #LAYER_TYPE_NONE disabled}, {@link #LAYER_TYPE_SOFTWARE software} or |
| 10029 | * {@link #LAYER_TYPE_HARDWARE hardware}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10030 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10031 | * <p>A layer is associated with an optional {@link android.graphics.Paint} |
| 10032 | * instance that controls how the layer is composed on screen. The following |
| 10033 | * properties of the paint are taken into account when composing the layer:</p> |
| 10034 | * <ul> |
| 10035 | * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> |
| 10036 | * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> |
| 10037 | * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> |
| 10038 | * </ul> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10039 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10040 | * <p>If this view has an alpha value set to < 1.0 by calling |
| 10041 | * {@link #setAlpha(float)}, the alpha value of the layer's paint is replaced by |
| 10042 | * this view's alpha value. Calling {@link #setAlpha(float)} is therefore |
| 10043 | * equivalent to setting a hardware layer on this view and providing a paint with |
| 10044 | * the desired alpha value.<p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10045 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10046 | * <p>Refer to the documentation of {@link #LAYER_TYPE_NONE disabled}, |
| 10047 | * {@link #LAYER_TYPE_SOFTWARE software} and {@link #LAYER_TYPE_HARDWARE hardware} |
| 10048 | * for more information on when and how to use layers.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10049 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10050 | * @param layerType The ype of layer to use with this view, must be one of |
| 10051 | * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 10052 | * {@link #LAYER_TYPE_HARDWARE} |
| 10053 | * @param paint The paint used to compose the layer. This argument is optional |
| 10054 | * and can be null. It is ignored when the layer type is |
| 10055 | * {@link #LAYER_TYPE_NONE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10056 | * |
| 10057 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10058 | * @see #LAYER_TYPE_NONE |
| 10059 | * @see #LAYER_TYPE_SOFTWARE |
| 10060 | * @see #LAYER_TYPE_HARDWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10061 | * @see #setAlpha(float) |
| 10062 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10063 | * @attr ref android.R.styleable#View_layerType |
| 10064 | */ |
| 10065 | public void setLayerType(int layerType, Paint paint) { |
| 10066 | if (layerType < LAYER_TYPE_NONE || layerType > LAYER_TYPE_HARDWARE) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10067 | 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] | 10068 | + "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE"); |
| 10069 | } |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10070 | |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 10071 | if (layerType == mLayerType) { |
| 10072 | if (layerType != LAYER_TYPE_NONE && paint != mLayerPaint) { |
| 10073 | mLayerPaint = paint == null ? new Paint() : paint; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10074 | invalidateParentCaches(); |
| 10075 | invalidate(true); |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 10076 | } |
| 10077 | return; |
| 10078 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10079 | |
| 10080 | // Destroy any previous software drawing cache if needed |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10081 | switch (mLayerType) { |
Chet Haase | 6f33e81 | 2011-05-17 12:42:19 -0700 | [diff] [blame] | 10082 | case LAYER_TYPE_HARDWARE: |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10083 | destroyLayer(); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 10084 | // fall through - non-accelerated views may use software layer mechanism instead |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10085 | case LAYER_TYPE_SOFTWARE: |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10086 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10087 | break; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10088 | default: |
| 10089 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10090 | } |
| 10091 | |
| 10092 | mLayerType = layerType; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 10093 | final boolean layerDisabled = mLayerType == LAYER_TYPE_NONE; |
| 10094 | mLayerPaint = layerDisabled ? null : (paint == null ? new Paint() : paint); |
| 10095 | mLocalDirtyRect = layerDisabled ? null : new Rect(); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10096 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10097 | invalidateParentCaches(); |
| 10098 | invalidate(true); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10099 | } |
| 10100 | |
| 10101 | /** |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 10102 | * Indicates whether this view has a static layer. A view with layer type |
| 10103 | * {@link #LAYER_TYPE_NONE} is a static layer. Other types of layers are |
| 10104 | * dynamic. |
| 10105 | */ |
| 10106 | boolean hasStaticLayer() { |
| 10107 | return mLayerType == LAYER_TYPE_NONE; |
| 10108 | } |
| 10109 | |
| 10110 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10111 | * Indicates what type of layer is currently associated with this view. By default |
| 10112 | * a view does not have a layer, and the layer type is {@link #LAYER_TYPE_NONE}. |
| 10113 | * Refer to the documentation of {@link #setLayerType(int, android.graphics.Paint)} |
| 10114 | * for more information on the different types of layers. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10115 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10116 | * @return {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 10117 | * {@link #LAYER_TYPE_HARDWARE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10118 | * |
| 10119 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10120 | * @see #buildLayer() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10121 | * @see #LAYER_TYPE_NONE |
| 10122 | * @see #LAYER_TYPE_SOFTWARE |
| 10123 | * @see #LAYER_TYPE_HARDWARE |
| 10124 | */ |
| 10125 | public int getLayerType() { |
| 10126 | return mLayerType; |
| 10127 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10128 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10129 | /** |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10130 | * Forces this view's layer to be created and this view to be rendered |
| 10131 | * into its layer. If this view's layer type is set to {@link #LAYER_TYPE_NONE}, |
| 10132 | * invoking this method will have no effect. |
| 10133 | * |
| 10134 | * This method can for instance be used to render a view into its layer before |
| 10135 | * starting an animation. If this view is complex, rendering into the layer |
| 10136 | * before starting the animation will avoid skipping frames. |
| 10137 | * |
| 10138 | * @throws IllegalStateException If this view is not attached to a window |
| 10139 | * |
| 10140 | * @see #setLayerType(int, android.graphics.Paint) |
| 10141 | */ |
| 10142 | public void buildLayer() { |
| 10143 | if (mLayerType == LAYER_TYPE_NONE) return; |
| 10144 | |
| 10145 | if (mAttachInfo == null) { |
| 10146 | throw new IllegalStateException("This view must be attached to a window first"); |
| 10147 | } |
| 10148 | |
| 10149 | switch (mLayerType) { |
| 10150 | case LAYER_TYPE_HARDWARE: |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 10151 | if (mAttachInfo.mHardwareRenderer != null && |
| 10152 | mAttachInfo.mHardwareRenderer.isEnabled() && |
| 10153 | mAttachInfo.mHardwareRenderer.validate()) { |
| 10154 | getHardwareLayer(); |
| 10155 | } |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10156 | break; |
| 10157 | case LAYER_TYPE_SOFTWARE: |
| 10158 | buildDrawingCache(true); |
| 10159 | break; |
| 10160 | } |
| 10161 | } |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10162 | |
| 10163 | // Make sure the HardwareRenderer.validate() was invoked before calling this method |
| 10164 | void flushLayer() { |
| 10165 | if (mLayerType == LAYER_TYPE_HARDWARE && mHardwareLayer != null) { |
| 10166 | mHardwareLayer.flush(); |
| 10167 | } |
| 10168 | } |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 10169 | |
| 10170 | /** |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10171 | * <p>Returns a hardware layer that can be used to draw this view again |
| 10172 | * without executing its draw method.</p> |
| 10173 | * |
| 10174 | * @return A HardwareLayer ready to render, or null if an error occurred. |
| 10175 | */ |
Romain Guy | 5e7f766 | 2011-01-24 22:35:56 -0800 | [diff] [blame] | 10176 | HardwareLayer getHardwareLayer() { |
Romain Guy | ea83503 | 2011-07-28 19:24:37 -0700 | [diff] [blame] | 10177 | if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null || |
| 10178 | !mAttachInfo.mHardwareRenderer.isEnabled()) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10179 | return null; |
| 10180 | } |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10181 | |
| 10182 | if (!mAttachInfo.mHardwareRenderer.validate()) return null; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10183 | |
| 10184 | final int width = mRight - mLeft; |
| 10185 | final int height = mBottom - mTop; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10186 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10187 | if (width == 0 || height == 0) { |
| 10188 | return null; |
| 10189 | } |
| 10190 | |
| 10191 | if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || mHardwareLayer == null) { |
| 10192 | if (mHardwareLayer == null) { |
| 10193 | mHardwareLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer( |
| 10194 | width, height, isOpaque()); |
Romain Guy | 62687ec | 2011-02-02 15:44:19 -0800 | [diff] [blame] | 10195 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10196 | } else if (mHardwareLayer.getWidth() != width || mHardwareLayer.getHeight() != height) { |
| 10197 | mHardwareLayer.resize(width, height); |
Romain Guy | 62687ec | 2011-02-02 15:44:19 -0800 | [diff] [blame] | 10198 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10199 | } |
| 10200 | |
Romain Guy | 5cd5c3f | 2011-10-17 17:10:02 -0700 | [diff] [blame] | 10201 | // The layer is not valid if the underlying GPU resources cannot be allocated |
| 10202 | if (!mHardwareLayer.isValid()) { |
| 10203 | return null; |
| 10204 | } |
| 10205 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 10206 | HardwareCanvas currentCanvas = mAttachInfo.mHardwareCanvas; |
Romain Guy | 5e7f766 | 2011-01-24 22:35:56 -0800 | [diff] [blame] | 10207 | final HardwareCanvas canvas = mHardwareLayer.start(currentCanvas); |
Romain Guy | 5cd5c3f | 2011-10-17 17:10:02 -0700 | [diff] [blame] | 10208 | |
| 10209 | // Make sure all the GPU resources have been properly allocated |
| 10210 | if (canvas == null) { |
| 10211 | mHardwareLayer.end(currentCanvas); |
| 10212 | return null; |
| 10213 | } |
| 10214 | |
Romain Guy | 5e7f766 | 2011-01-24 22:35:56 -0800 | [diff] [blame] | 10215 | mAttachInfo.mHardwareCanvas = canvas; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10216 | try { |
| 10217 | canvas.setViewport(width, height); |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 10218 | canvas.onPreDraw(mLocalDirtyRect); |
Romain Guy | 62687ec | 2011-02-02 15:44:19 -0800 | [diff] [blame] | 10219 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10220 | |
Chet Haase | 88172fe | 2011-03-07 17:36:33 -0800 | [diff] [blame] | 10221 | final int restoreCount = canvas.save(); |
| 10222 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10223 | computeScroll(); |
| 10224 | canvas.translate(-mScrollX, -mScrollY); |
| 10225 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10226 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10227 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10228 | // Fast path for layouts with no backgrounds |
| 10229 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 10230 | mPrivateFlags &= ~DIRTY_MASK; |
| 10231 | dispatchDraw(canvas); |
| 10232 | } else { |
| 10233 | draw(canvas); |
| 10234 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10235 | |
Chet Haase | 88172fe | 2011-03-07 17:36:33 -0800 | [diff] [blame] | 10236 | canvas.restoreToCount(restoreCount); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10237 | } finally { |
| 10238 | canvas.onPostDraw(); |
Romain Guy | 5e7f766 | 2011-01-24 22:35:56 -0800 | [diff] [blame] | 10239 | mHardwareLayer.end(currentCanvas); |
| 10240 | mAttachInfo.mHardwareCanvas = currentCanvas; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 10241 | } |
| 10242 | } |
| 10243 | |
| 10244 | return mHardwareLayer; |
| 10245 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10246 | |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 10247 | /** |
| 10248 | * Destroys this View's hardware layer if possible. |
| 10249 | * |
| 10250 | * @return True if the layer was destroyed, false otherwise. |
| 10251 | * |
| 10252 | * @see #setLayerType(int, android.graphics.Paint) |
| 10253 | * @see #LAYER_TYPE_HARDWARE |
| 10254 | */ |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 10255 | boolean destroyLayer() { |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10256 | if (mHardwareLayer != null) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10257 | AttachInfo info = mAttachInfo; |
| 10258 | if (info != null && info.mHardwareRenderer != null && |
| 10259 | info.mHardwareRenderer.isEnabled() && info.mHardwareRenderer.validate()) { |
| 10260 | mHardwareLayer.destroy(); |
| 10261 | mHardwareLayer = null; |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 10262 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 10263 | invalidate(true); |
| 10264 | invalidateParentCaches(); |
| 10265 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 10266 | return true; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10267 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 10268 | return false; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 10269 | } |
| 10270 | |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10271 | /** |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 10272 | * Destroys all hardware rendering resources. This method is invoked |
| 10273 | * when the system needs to reclaim resources. Upon execution of this |
| 10274 | * method, you should free any OpenGL resources created by the view. |
| 10275 | * |
| 10276 | * Note: you <strong>must</strong> call |
| 10277 | * <code>super.destroyHardwareResources()</code> when overriding |
| 10278 | * this method. |
| 10279 | * |
| 10280 | * @hide |
| 10281 | */ |
| 10282 | protected void destroyHardwareResources() { |
| 10283 | destroyLayer(); |
| 10284 | } |
| 10285 | |
| 10286 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10287 | * <p>Enables or disables the drawing cache. When the drawing cache is enabled, the next call |
| 10288 | * to {@link #getDrawingCache()} or {@link #buildDrawingCache()} will draw the view in a |
| 10289 | * bitmap. Calling {@link #draw(android.graphics.Canvas)} will not draw from the cache when |
| 10290 | * the cache is enabled. To benefit from the cache, you must request the drawing cache by |
| 10291 | * calling {@link #getDrawingCache()} and draw it on screen if the returned bitmap is not |
| 10292 | * null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10293 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10294 | * <p>Enabling the drawing cache is similar to |
| 10295 | * {@link #setLayerType(int, android.graphics.Paint) setting a layer} when hardware |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10296 | * acceleration is turned off. When hardware acceleration is turned on, enabling the |
| 10297 | * drawing cache has no effect on rendering because the system uses a different mechanism |
| 10298 | * for acceleration which ignores the flag. If you want to use a Bitmap for the view, even |
| 10299 | * when hardware acceleration is enabled, see {@link #setLayerType(int, android.graphics.Paint)} |
| 10300 | * for information on how to enable software and hardware layers.</p> |
| 10301 | * |
| 10302 | * <p>This API can be used to manually generate |
| 10303 | * a bitmap copy of this view, by setting the flag to <code>true</code> and calling |
| 10304 | * {@link #getDrawingCache()}.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10305 | * |
| 10306 | * @param enabled true to enable the drawing cache, false otherwise |
| 10307 | * |
| 10308 | * @see #isDrawingCacheEnabled() |
| 10309 | * @see #getDrawingCache() |
| 10310 | * @see #buildDrawingCache() |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10311 | * @see #setLayerType(int, android.graphics.Paint) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10312 | */ |
| 10313 | public void setDrawingCacheEnabled(boolean enabled) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 10314 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10315 | setFlags(enabled ? DRAWING_CACHE_ENABLED : 0, DRAWING_CACHE_ENABLED); |
| 10316 | } |
| 10317 | |
| 10318 | /** |
| 10319 | * <p>Indicates whether the drawing cache is enabled for this view.</p> |
| 10320 | * |
| 10321 | * @return true if the drawing cache is enabled |
| 10322 | * |
| 10323 | * @see #setDrawingCacheEnabled(boolean) |
| 10324 | * @see #getDrawingCache() |
| 10325 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 10326 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10327 | public boolean isDrawingCacheEnabled() { |
| 10328 | return (mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED; |
| 10329 | } |
| 10330 | |
| 10331 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10332 | * Debugging utility which recursively outputs the dirty state of a view and its |
| 10333 | * descendants. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10334 | * |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10335 | * @hide |
| 10336 | */ |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 10337 | @SuppressWarnings({"UnusedDeclaration"}) |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10338 | public void outputDirtyFlags(String indent, boolean clear, int clearMask) { |
| 10339 | Log.d("View", indent + this + " DIRTY(" + (mPrivateFlags & View.DIRTY_MASK) + |
| 10340 | ") DRAWN(" + (mPrivateFlags & DRAWN) + ")" + " CACHE_VALID(" + |
| 10341 | (mPrivateFlags & View.DRAWING_CACHE_VALID) + |
| 10342 | ") INVALIDATED(" + (mPrivateFlags & INVALIDATED) + ")"); |
| 10343 | if (clear) { |
| 10344 | mPrivateFlags &= clearMask; |
| 10345 | } |
| 10346 | if (this instanceof ViewGroup) { |
| 10347 | ViewGroup parent = (ViewGroup) this; |
| 10348 | final int count = parent.getChildCount(); |
| 10349 | for (int i = 0; i < count; i++) { |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10350 | final View child = parent.getChildAt(i); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10351 | child.outputDirtyFlags(indent + " ", clear, clearMask); |
| 10352 | } |
| 10353 | } |
| 10354 | } |
| 10355 | |
| 10356 | /** |
| 10357 | * This method is used by ViewGroup to cause its children to restore or recreate their |
| 10358 | * display lists. It is called by getDisplayList() when the parent ViewGroup does not need |
| 10359 | * to recreate its own display list, which would happen if it went through the normal |
| 10360 | * draw/dispatchDraw mechanisms. |
| 10361 | * |
| 10362 | * @hide |
| 10363 | */ |
| 10364 | protected void dispatchGetDisplayList() {} |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 10365 | |
| 10366 | /** |
| 10367 | * A view that is not attached or hardware accelerated cannot create a display list. |
| 10368 | * This method checks these conditions and returns the appropriate result. |
| 10369 | * |
| 10370 | * @return true if view has the ability to create a display list, false otherwise. |
| 10371 | * |
| 10372 | * @hide |
| 10373 | */ |
| 10374 | public boolean canHaveDisplayList() { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 10375 | return !(mAttachInfo == null || mAttachInfo.mHardwareRenderer == null); |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 10376 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10377 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10378 | /** |
Gilles Debunne | b35ab7b | 2011-12-05 15:54:00 -0800 | [diff] [blame] | 10379 | * @return The HardwareRenderer associated with that view or null if hardware rendering |
| 10380 | * is not supported or this this has not been attached to a window. |
| 10381 | * |
| 10382 | * @hide |
| 10383 | */ |
| 10384 | public HardwareRenderer getHardwareRenderer() { |
| 10385 | if (mAttachInfo != null) { |
| 10386 | return mAttachInfo.mHardwareRenderer; |
| 10387 | } |
| 10388 | return null; |
| 10389 | } |
| 10390 | |
| 10391 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10392 | * <p>Returns a display list that can be used to draw this view again |
| 10393 | * without executing its draw method.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10394 | * |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10395 | * @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] | 10396 | * |
| 10397 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10398 | */ |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10399 | public DisplayList getDisplayList() { |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 10400 | if (!canHaveDisplayList()) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10401 | return null; |
| 10402 | } |
| 10403 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10404 | if (((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || |
| 10405 | mDisplayList == null || !mDisplayList.isValid() || |
| 10406 | mRecreateDisplayList)) { |
| 10407 | // Don't need to recreate the display list, just need to tell our |
| 10408 | // children to restore/recreate theirs |
| 10409 | if (mDisplayList != null && mDisplayList.isValid() && |
| 10410 | !mRecreateDisplayList) { |
| 10411 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 10412 | mPrivateFlags &= ~DIRTY_MASK; |
| 10413 | dispatchGetDisplayList(); |
| 10414 | |
| 10415 | return mDisplayList; |
| 10416 | } |
| 10417 | |
| 10418 | // If we got here, we're recreating it. Mark it as such to ensure that |
| 10419 | // we copy in child display lists into ours in drawChild() |
| 10420 | mRecreateDisplayList = true; |
Chet Haase | 9e90a99 | 2011-01-04 16:23:21 -0800 | [diff] [blame] | 10421 | if (mDisplayList == null) { |
Romain Guy | 13631f3 | 2012-01-30 17:41:55 -0800 | [diff] [blame] | 10422 | final String name = getClass().getSimpleName(); |
| 10423 | mDisplayList = mAttachInfo.mHardwareRenderer.createDisplayList(name); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10424 | // If we're creating a new display list, make sure our parent gets invalidated |
| 10425 | // since they will need to recreate their display list to account for this |
| 10426 | // new child display list. |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10427 | invalidateParentCaches(); |
Chet Haase | 9e90a99 | 2011-01-04 16:23:21 -0800 | [diff] [blame] | 10428 | } |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10429 | |
| 10430 | final HardwareCanvas canvas = mDisplayList.start(); |
Romain Guy | e080af3 | 2011-09-08 15:03:39 -0700 | [diff] [blame] | 10431 | int restoreCount = 0; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10432 | try { |
| 10433 | int width = mRight - mLeft; |
| 10434 | int height = mBottom - mTop; |
| 10435 | |
| 10436 | canvas.setViewport(width, height); |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10437 | // The dirty rect should always be null for a display list |
| 10438 | canvas.onPreDraw(null); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10439 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10440 | computeScroll(); |
Romain Guy | e080af3 | 2011-09-08 15:03:39 -0700 | [diff] [blame] | 10441 | |
| 10442 | restoreCount = canvas.save(); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10443 | canvas.translate(-mScrollX, -mScrollY); |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 10444 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 10445 | mPrivateFlags &= ~DIRTY_MASK; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10446 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10447 | // Fast path for layouts with no backgrounds |
| 10448 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10449 | dispatchDraw(canvas); |
| 10450 | } else { |
| 10451 | draw(canvas); |
| 10452 | } |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10453 | } finally { |
Romain Guy | e080af3 | 2011-09-08 15:03:39 -0700 | [diff] [blame] | 10454 | canvas.restoreToCount(restoreCount); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10455 | canvas.onPostDraw(); |
| 10456 | |
| 10457 | mDisplayList.end(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10458 | } |
Chet Haase | 77785f9 | 2011-01-25 23:22:09 -0800 | [diff] [blame] | 10459 | } else { |
| 10460 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 10461 | mPrivateFlags &= ~DIRTY_MASK; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 10462 | } |
| 10463 | |
| 10464 | return mDisplayList; |
| 10465 | } |
| 10466 | |
| 10467 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10468 | * <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] | 10469 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10470 | * @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] | 10471 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10472 | * @see #getDrawingCache(boolean) |
| 10473 | */ |
| 10474 | public Bitmap getDrawingCache() { |
| 10475 | return getDrawingCache(false); |
| 10476 | } |
| 10477 | |
| 10478 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10479 | * <p>Returns the bitmap in which this view drawing is cached. The returned bitmap |
| 10480 | * is null when caching is disabled. If caching is enabled and the cache is not ready, |
| 10481 | * this method will create it. Calling {@link #draw(android.graphics.Canvas)} will not |
| 10482 | * draw from the cache when the cache is enabled. To benefit from the cache, you must |
| 10483 | * request the drawing cache by calling this method and draw it on screen if the |
| 10484 | * returned bitmap is not null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10485 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10486 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 10487 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 10488 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 10489 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 10490 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 10491 | * size than the view. This implies that your application must be able to handle this |
| 10492 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10493 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10494 | * @param autoScale Indicates whether the generated bitmap should be scaled based on |
| 10495 | * the current density of the screen when the application is in compatibility |
| 10496 | * mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10497 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10498 | * @return A bitmap representing this view or null if cache is disabled. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10499 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10500 | * @see #setDrawingCacheEnabled(boolean) |
| 10501 | * @see #isDrawingCacheEnabled() |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10502 | * @see #buildDrawingCache(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10503 | * @see #destroyDrawingCache() |
| 10504 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10505 | public Bitmap getDrawingCache(boolean autoScale) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10506 | if ((mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING) { |
| 10507 | return null; |
| 10508 | } |
| 10509 | if ((mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10510 | buildDrawingCache(autoScale); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10511 | } |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10512 | return autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10513 | } |
| 10514 | |
| 10515 | /** |
| 10516 | * <p>Frees the resources used by the drawing cache. If you call |
| 10517 | * {@link #buildDrawingCache()} manually without calling |
| 10518 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 10519 | * should cleanup the cache with this method afterwards.</p> |
| 10520 | * |
| 10521 | * @see #setDrawingCacheEnabled(boolean) |
| 10522 | * @see #buildDrawingCache() |
| 10523 | * @see #getDrawingCache() |
| 10524 | */ |
| 10525 | public void destroyDrawingCache() { |
| 10526 | if (mDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10527 | mDrawingCache.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10528 | mDrawingCache = null; |
| 10529 | } |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10530 | if (mUnscaledDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10531 | mUnscaledDrawingCache.recycle(); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10532 | mUnscaledDrawingCache = null; |
| 10533 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10534 | } |
| 10535 | |
| 10536 | /** |
| 10537 | * 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] | 10538 | * 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] | 10539 | * view will always be drawn on top of a solid color. |
| 10540 | * |
| 10541 | * @param color The background color to use for the drawing cache's bitmap |
| 10542 | * |
| 10543 | * @see #setDrawingCacheEnabled(boolean) |
| 10544 | * @see #buildDrawingCache() |
| 10545 | * @see #getDrawingCache() |
| 10546 | */ |
| 10547 | public void setDrawingCacheBackgroundColor(int color) { |
Romain Guy | 52e2ef8 | 2010-01-14 12:11:48 -0800 | [diff] [blame] | 10548 | if (color != mDrawingCacheBackgroundColor) { |
| 10549 | mDrawingCacheBackgroundColor = color; |
| 10550 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 10551 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10552 | } |
| 10553 | |
| 10554 | /** |
| 10555 | * @see #setDrawingCacheBackgroundColor(int) |
| 10556 | * |
| 10557 | * @return The background color to used for the drawing cache's bitmap |
| 10558 | */ |
| 10559 | public int getDrawingCacheBackgroundColor() { |
| 10560 | return mDrawingCacheBackgroundColor; |
| 10561 | } |
| 10562 | |
| 10563 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10564 | * <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] | 10565 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10566 | * @see #buildDrawingCache(boolean) |
| 10567 | */ |
| 10568 | public void buildDrawingCache() { |
| 10569 | buildDrawingCache(false); |
| 10570 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 10571 | |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10572 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10573 | * <p>Forces the drawing cache to be built if the drawing cache is invalid.</p> |
| 10574 | * |
| 10575 | * <p>If you call {@link #buildDrawingCache()} manually without calling |
| 10576 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 10577 | * should cleanup the cache by calling {@link #destroyDrawingCache()} afterwards.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10578 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10579 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 10580 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 10581 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 10582 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 10583 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 10584 | * size than the view. This implies that your application must be able to handle this |
| 10585 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10586 | * |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 10587 | * <p>You should avoid calling this method when hardware acceleration is enabled. If |
| 10588 | * 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] | 10589 | * 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] | 10590 | * performance.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10591 | * |
| 10592 | * @see #getDrawingCache() |
| 10593 | * @see #destroyDrawingCache() |
| 10594 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10595 | public void buildDrawingCache(boolean autoScale) { |
| 10596 | if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || (autoScale ? |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10597 | mDrawingCache == null : mUnscaledDrawingCache == null)) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 10598 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10599 | |
| 10600 | if (ViewDebug.TRACE_HIERARCHY) { |
| 10601 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.BUILD_CACHE); |
| 10602 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10603 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10604 | int width = mRight - mLeft; |
| 10605 | int height = mBottom - mTop; |
| 10606 | |
| 10607 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 10608 | final boolean scalingRequired = attachInfo != null && attachInfo.mScalingRequired; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10609 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 10610 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10611 | width = (int) ((width * attachInfo.mApplicationScale) + 0.5f); |
| 10612 | height = (int) ((height * attachInfo.mApplicationScale) + 0.5f); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10613 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10614 | |
| 10615 | final int drawingCacheBackgroundColor = mDrawingCacheBackgroundColor; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 10616 | final boolean opaque = drawingCacheBackgroundColor != 0 || isOpaque(); |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 10617 | final boolean use32BitCache = attachInfo != null && attachInfo.mUse32BitDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10618 | |
| 10619 | if (width <= 0 || height <= 0 || |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 10620 | // Projected bitmap size in bytes |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 10621 | (width * height * (opaque && !use32BitCache ? 2 : 4) > |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10622 | ViewConfiguration.get(mContext).getScaledMaximumDrawingCacheSize())) { |
| 10623 | destroyDrawingCache(); |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 10624 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10625 | return; |
| 10626 | } |
| 10627 | |
| 10628 | boolean clear = true; |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10629 | Bitmap bitmap = autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10630 | |
| 10631 | if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10632 | Bitmap.Config quality; |
| 10633 | if (!opaque) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 10634 | // Never pick ARGB_4444 because it looks awful |
| 10635 | // 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] | 10636 | switch (mViewFlags & DRAWING_CACHE_QUALITY_MASK) { |
| 10637 | case DRAWING_CACHE_QUALITY_AUTO: |
| 10638 | quality = Bitmap.Config.ARGB_8888; |
| 10639 | break; |
| 10640 | case DRAWING_CACHE_QUALITY_LOW: |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 10641 | quality = Bitmap.Config.ARGB_8888; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10642 | break; |
| 10643 | case DRAWING_CACHE_QUALITY_HIGH: |
| 10644 | quality = Bitmap.Config.ARGB_8888; |
| 10645 | break; |
| 10646 | default: |
| 10647 | quality = Bitmap.Config.ARGB_8888; |
| 10648 | break; |
| 10649 | } |
| 10650 | } else { |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 10651 | // Optimization for translucent windows |
| 10652 | // 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] | 10653 | 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] | 10654 | } |
| 10655 | |
| 10656 | // Try to cleanup memory |
| 10657 | if (bitmap != null) bitmap.recycle(); |
| 10658 | |
| 10659 | try { |
| 10660 | bitmap = Bitmap.createBitmap(width, height, quality); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 10661 | bitmap.setDensity(getResources().getDisplayMetrics().densityDpi); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10662 | if (autoScale) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10663 | mDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10664 | } else { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 10665 | mUnscaledDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10666 | } |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 10667 | if (opaque && use32BitCache) bitmap.setHasAlpha(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10668 | } catch (OutOfMemoryError e) { |
| 10669 | // If there is not enough memory to create the bitmap cache, just |
| 10670 | // ignore the issue as bitmap caches are not required to draw the |
| 10671 | // view hierarchy |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10672 | if (autoScale) { |
| 10673 | mDrawingCache = null; |
| 10674 | } else { |
| 10675 | mUnscaledDrawingCache = null; |
| 10676 | } |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 10677 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10678 | return; |
| 10679 | } |
| 10680 | |
| 10681 | clear = drawingCacheBackgroundColor != 0; |
| 10682 | } |
| 10683 | |
| 10684 | Canvas canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10685 | if (attachInfo != null) { |
| 10686 | canvas = attachInfo.mCanvas; |
| 10687 | if (canvas == null) { |
| 10688 | canvas = new Canvas(); |
| 10689 | } |
| 10690 | canvas.setBitmap(bitmap); |
| 10691 | // Temporarily clobber the cached Canvas in case one of our children |
| 10692 | // is also using a drawing cache. Without this, the children would |
| 10693 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 10694 | // thing would happen (invisible views, corrupted drawings, etc.) |
| 10695 | attachInfo.mCanvas = null; |
| 10696 | } else { |
| 10697 | // This case should hopefully never or seldom happen |
| 10698 | canvas = new Canvas(bitmap); |
| 10699 | } |
| 10700 | |
| 10701 | if (clear) { |
| 10702 | bitmap.eraseColor(drawingCacheBackgroundColor); |
| 10703 | } |
| 10704 | |
| 10705 | computeScroll(); |
| 10706 | final int restoreCount = canvas.save(); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10707 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 10708 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 10709 | final float scale = attachInfo.mApplicationScale; |
| 10710 | canvas.scale(scale, scale); |
| 10711 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10712 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10713 | canvas.translate(-mScrollX, -mScrollY); |
| 10714 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10715 | mPrivateFlags |= DRAWN; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 10716 | if (mAttachInfo == null || !mAttachInfo.mHardwareAccelerated || |
| 10717 | mLayerType != LAYER_TYPE_NONE) { |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 10718 | mPrivateFlags |= DRAWING_CACHE_VALID; |
| 10719 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10720 | |
| 10721 | // Fast path for layouts with no backgrounds |
| 10722 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 10723 | if (ViewDebug.TRACE_HIERARCHY) { |
| 10724 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW); |
| 10725 | } |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10726 | mPrivateFlags &= ~DIRTY_MASK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10727 | dispatchDraw(canvas); |
| 10728 | } else { |
| 10729 | draw(canvas); |
| 10730 | } |
| 10731 | |
| 10732 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 10733 | canvas.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10734 | |
| 10735 | if (attachInfo != null) { |
| 10736 | // Restore the cached Canvas for our siblings |
| 10737 | attachInfo.mCanvas = canvas; |
| 10738 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10739 | } |
| 10740 | } |
| 10741 | |
| 10742 | /** |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10743 | * Create a snapshot of the view into a bitmap. We should probably make |
| 10744 | * some form of this public, but should think about the API. |
| 10745 | */ |
Romain Guy | 223ff5c | 2010-03-02 17:07:47 -0800 | [diff] [blame] | 10746 | Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipChildren) { |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 10747 | int width = mRight - mLeft; |
| 10748 | int height = mBottom - mTop; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10749 | |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 10750 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 10751 | final float scale = attachInfo != null ? attachInfo.mApplicationScale : 1.0f; |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 10752 | width = (int) ((width * scale) + 0.5f); |
| 10753 | height = (int) ((height * scale) + 0.5f); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10754 | |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 10755 | 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] | 10756 | if (bitmap == null) { |
| 10757 | throw new OutOfMemoryError(); |
| 10758 | } |
| 10759 | |
Romain Guy | c529d8d | 2011-09-06 15:01:39 -0700 | [diff] [blame] | 10760 | Resources resources = getResources(); |
| 10761 | if (resources != null) { |
| 10762 | bitmap.setDensity(resources.getDisplayMetrics().densityDpi); |
| 10763 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10764 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10765 | Canvas canvas; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10766 | if (attachInfo != null) { |
| 10767 | canvas = attachInfo.mCanvas; |
| 10768 | if (canvas == null) { |
| 10769 | canvas = new Canvas(); |
| 10770 | } |
| 10771 | canvas.setBitmap(bitmap); |
| 10772 | // Temporarily clobber the cached Canvas in case one of our children |
| 10773 | // is also using a drawing cache. Without this, the children would |
| 10774 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 10775 | // things would happen (invisible views, corrupted drawings, etc.) |
| 10776 | attachInfo.mCanvas = null; |
| 10777 | } else { |
| 10778 | // This case should hopefully never or seldom happen |
| 10779 | canvas = new Canvas(bitmap); |
| 10780 | } |
| 10781 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10782 | if ((backgroundColor & 0xff000000) != 0) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10783 | bitmap.eraseColor(backgroundColor); |
| 10784 | } |
| 10785 | |
| 10786 | computeScroll(); |
| 10787 | final int restoreCount = canvas.save(); |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 10788 | canvas.scale(scale, scale); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10789 | canvas.translate(-mScrollX, -mScrollY); |
| 10790 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10791 | // Temporarily remove the dirty mask |
| 10792 | int flags = mPrivateFlags; |
| 10793 | mPrivateFlags &= ~DIRTY_MASK; |
| 10794 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10795 | // Fast path for layouts with no backgrounds |
| 10796 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 10797 | dispatchDraw(canvas); |
| 10798 | } else { |
| 10799 | draw(canvas); |
| 10800 | } |
| 10801 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10802 | mPrivateFlags = flags; |
| 10803 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10804 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 10805 | canvas.setBitmap(null); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10806 | |
| 10807 | if (attachInfo != null) { |
| 10808 | // Restore the cached Canvas for our siblings |
| 10809 | attachInfo.mCanvas = canvas; |
| 10810 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10811 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 10812 | return bitmap; |
| 10813 | } |
| 10814 | |
| 10815 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10816 | * Indicates whether this View is currently in edit mode. A View is usually |
| 10817 | * in edit mode when displayed within a developer tool. For instance, if |
| 10818 | * this View is being drawn by a visual user interface builder, this method |
| 10819 | * should return true. |
| 10820 | * |
| 10821 | * Subclasses should check the return value of this method to provide |
| 10822 | * different behaviors if their normal behavior might interfere with the |
| 10823 | * host environment. For instance: the class spawns a thread in its |
| 10824 | * constructor, the drawing code relies on device-specific features, etc. |
| 10825 | * |
| 10826 | * This method is usually checked in the drawing code of custom widgets. |
| 10827 | * |
| 10828 | * @return True if this View is in edit mode, false otherwise. |
| 10829 | */ |
| 10830 | public boolean isInEditMode() { |
| 10831 | return false; |
| 10832 | } |
| 10833 | |
| 10834 | /** |
| 10835 | * If the View draws content inside its padding and enables fading edges, |
| 10836 | * it needs to support padding offsets. Padding offsets are added to the |
| 10837 | * fading edges to extend the length of the fade so that it covers pixels |
| 10838 | * drawn inside the padding. |
| 10839 | * |
| 10840 | * Subclasses of this class should override this method if they need |
| 10841 | * to draw content inside the padding. |
| 10842 | * |
| 10843 | * @return True if padding offset must be applied, false otherwise. |
| 10844 | * |
| 10845 | * @see #getLeftPaddingOffset() |
| 10846 | * @see #getRightPaddingOffset() |
| 10847 | * @see #getTopPaddingOffset() |
| 10848 | * @see #getBottomPaddingOffset() |
| 10849 | * |
| 10850 | * @since CURRENT |
| 10851 | */ |
| 10852 | protected boolean isPaddingOffsetRequired() { |
| 10853 | return false; |
| 10854 | } |
| 10855 | |
| 10856 | /** |
| 10857 | * Amount by which to extend the left fading region. Called only when |
| 10858 | * {@link #isPaddingOffsetRequired()} returns true. |
| 10859 | * |
| 10860 | * @return The left padding offset in pixels. |
| 10861 | * |
| 10862 | * @see #isPaddingOffsetRequired() |
| 10863 | * |
| 10864 | * @since CURRENT |
| 10865 | */ |
| 10866 | protected int getLeftPaddingOffset() { |
| 10867 | return 0; |
| 10868 | } |
| 10869 | |
| 10870 | /** |
| 10871 | * Amount by which to extend the right fading region. Called only when |
| 10872 | * {@link #isPaddingOffsetRequired()} returns true. |
| 10873 | * |
| 10874 | * @return The right padding offset in pixels. |
| 10875 | * |
| 10876 | * @see #isPaddingOffsetRequired() |
| 10877 | * |
| 10878 | * @since CURRENT |
| 10879 | */ |
| 10880 | protected int getRightPaddingOffset() { |
| 10881 | return 0; |
| 10882 | } |
| 10883 | |
| 10884 | /** |
| 10885 | * Amount by which to extend the top fading region. Called only when |
| 10886 | * {@link #isPaddingOffsetRequired()} returns true. |
| 10887 | * |
| 10888 | * @return The top padding offset in pixels. |
| 10889 | * |
| 10890 | * @see #isPaddingOffsetRequired() |
| 10891 | * |
| 10892 | * @since CURRENT |
| 10893 | */ |
| 10894 | protected int getTopPaddingOffset() { |
| 10895 | return 0; |
| 10896 | } |
| 10897 | |
| 10898 | /** |
| 10899 | * Amount by which to extend the bottom fading region. Called only when |
| 10900 | * {@link #isPaddingOffsetRequired()} returns true. |
| 10901 | * |
| 10902 | * @return The bottom padding offset in pixels. |
| 10903 | * |
| 10904 | * @see #isPaddingOffsetRequired() |
| 10905 | * |
| 10906 | * @since CURRENT |
| 10907 | */ |
| 10908 | protected int getBottomPaddingOffset() { |
| 10909 | return 0; |
| 10910 | } |
| 10911 | |
| 10912 | /** |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 10913 | * @hide |
| 10914 | * @param offsetRequired |
| 10915 | */ |
| 10916 | protected int getFadeTop(boolean offsetRequired) { |
| 10917 | int top = mPaddingTop; |
| 10918 | if (offsetRequired) top += getTopPaddingOffset(); |
| 10919 | return top; |
| 10920 | } |
| 10921 | |
| 10922 | /** |
| 10923 | * @hide |
| 10924 | * @param offsetRequired |
| 10925 | */ |
| 10926 | protected int getFadeHeight(boolean offsetRequired) { |
| 10927 | int padding = mPaddingTop; |
| 10928 | if (offsetRequired) padding += getTopPaddingOffset(); |
| 10929 | return mBottom - mTop - mPaddingBottom - padding; |
| 10930 | } |
| 10931 | |
| 10932 | /** |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 10933 | * <p>Indicates whether this view is attached to an hardware accelerated |
| 10934 | * window or not.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10935 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 10936 | * <p>Even if this method returns true, it does not mean that every call |
| 10937 | * to {@link #draw(android.graphics.Canvas)} will be made with an hardware |
| 10938 | * accelerated {@link android.graphics.Canvas}. For instance, if this view |
| 10939 | * is drawn onto an offscren {@link android.graphics.Bitmap} and its |
| 10940 | * window is hardware accelerated, |
| 10941 | * {@link android.graphics.Canvas#isHardwareAccelerated()} will likely |
| 10942 | * return false, and this method will return true.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10943 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 10944 | * @return True if the view is attached to a window and the window is |
| 10945 | * hardware accelerated; false in any other case. |
| 10946 | */ |
| 10947 | public boolean isHardwareAccelerated() { |
| 10948 | return mAttachInfo != null && mAttachInfo.mHardwareAccelerated; |
| 10949 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10950 | |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 10951 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10952 | * Manually render this view (and all of its children) to the given Canvas. |
| 10953 | * 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] | 10954 | * called. When implementing a view, implement |
| 10955 | * {@link #onDraw(android.graphics.Canvas)} instead of overriding this method. |
| 10956 | * 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] | 10957 | * |
| 10958 | * @param canvas The Canvas to which the View is rendered. |
| 10959 | */ |
| 10960 | public void draw(Canvas canvas) { |
| 10961 | if (ViewDebug.TRACE_HIERARCHY) { |
| 10962 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW); |
| 10963 | } |
| 10964 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 10965 | final int privateFlags = mPrivateFlags; |
| 10966 | final boolean dirtyOpaque = (privateFlags & DIRTY_MASK) == DIRTY_OPAQUE && |
| 10967 | (mAttachInfo == null || !mAttachInfo.mIgnoreDirtyState); |
| 10968 | mPrivateFlags = (privateFlags & ~DIRTY_MASK) | DRAWN; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10970 | /* |
| 10971 | * Draw traversal performs several drawing steps which must be executed |
| 10972 | * in the appropriate order: |
| 10973 | * |
| 10974 | * 1. Draw the background |
| 10975 | * 2. If necessary, save the canvas' layers to prepare for fading |
| 10976 | * 3. Draw view's content |
| 10977 | * 4. Draw children |
| 10978 | * 5. If necessary, draw the fading edges and restore layers |
| 10979 | * 6. Draw decorations (scrollbars for instance) |
| 10980 | */ |
| 10981 | |
| 10982 | // Step 1, draw the background, if needed |
| 10983 | int saveCount; |
| 10984 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10985 | if (!dirtyOpaque) { |
| 10986 | final Drawable background = mBGDrawable; |
| 10987 | if (background != null) { |
| 10988 | final int scrollX = mScrollX; |
| 10989 | final int scrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10990 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10991 | if (mBackgroundSizeChanged) { |
| 10992 | background.setBounds(0, 0, mRight - mLeft, mBottom - mTop); |
| 10993 | mBackgroundSizeChanged = false; |
| 10994 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10995 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10996 | if ((scrollX | scrollY) == 0) { |
| 10997 | background.draw(canvas); |
| 10998 | } else { |
| 10999 | canvas.translate(scrollX, scrollY); |
| 11000 | background.draw(canvas); |
| 11001 | canvas.translate(-scrollX, -scrollY); |
| 11002 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11003 | } |
| 11004 | } |
| 11005 | |
| 11006 | // skip step 2 & 5 if possible (common case) |
| 11007 | final int viewFlags = mViewFlags; |
| 11008 | boolean horizontalEdges = (viewFlags & FADING_EDGE_HORIZONTAL) != 0; |
| 11009 | boolean verticalEdges = (viewFlags & FADING_EDGE_VERTICAL) != 0; |
| 11010 | if (!verticalEdges && !horizontalEdges) { |
| 11011 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 11012 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11013 | |
| 11014 | // Step 4, draw the children |
| 11015 | dispatchDraw(canvas); |
| 11016 | |
| 11017 | // Step 6, draw decorations (scrollbars) |
| 11018 | onDrawScrollBars(canvas); |
| 11019 | |
| 11020 | // we're done... |
| 11021 | return; |
| 11022 | } |
| 11023 | |
| 11024 | /* |
| 11025 | * Here we do the full fledged routine... |
| 11026 | * (this is an uncommon case where speed matters less, |
| 11027 | * this is why we repeat some of the tests that have been |
| 11028 | * done above) |
| 11029 | */ |
| 11030 | |
| 11031 | boolean drawTop = false; |
| 11032 | boolean drawBottom = false; |
| 11033 | boolean drawLeft = false; |
| 11034 | boolean drawRight = false; |
| 11035 | |
| 11036 | float topFadeStrength = 0.0f; |
| 11037 | float bottomFadeStrength = 0.0f; |
| 11038 | float leftFadeStrength = 0.0f; |
| 11039 | float rightFadeStrength = 0.0f; |
| 11040 | |
| 11041 | // Step 2, save the canvas' layers |
| 11042 | int paddingLeft = mPaddingLeft; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11043 | |
| 11044 | final boolean offsetRequired = isPaddingOffsetRequired(); |
| 11045 | if (offsetRequired) { |
| 11046 | paddingLeft += getLeftPaddingOffset(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11047 | } |
| 11048 | |
| 11049 | int left = mScrollX + paddingLeft; |
| 11050 | int right = left + mRight - mLeft - mPaddingRight - paddingLeft; |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 11051 | int top = mScrollY + getFadeTop(offsetRequired); |
| 11052 | int bottom = top + getFadeHeight(offsetRequired); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11053 | |
| 11054 | if (offsetRequired) { |
| 11055 | right += getRightPaddingOffset(); |
| 11056 | bottom += getBottomPaddingOffset(); |
| 11057 | } |
| 11058 | |
| 11059 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11060 | final float fadeHeight = scrollabilityCache.fadingEdgeLength; |
| 11061 | int length = (int) fadeHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11062 | |
| 11063 | // clip the fade length if top and bottom fades overlap |
| 11064 | // overlapping fades produce odd-looking artifacts |
| 11065 | if (verticalEdges && (top + length > bottom - length)) { |
| 11066 | length = (bottom - top) / 2; |
| 11067 | } |
| 11068 | |
| 11069 | // also clip horizontal fades if necessary |
| 11070 | if (horizontalEdges && (left + length > right - length)) { |
| 11071 | length = (right - left) / 2; |
| 11072 | } |
| 11073 | |
| 11074 | if (verticalEdges) { |
| 11075 | topFadeStrength = Math.max(0.0f, Math.min(1.0f, getTopFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11076 | drawTop = topFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11077 | bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, getBottomFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11078 | drawBottom = bottomFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11079 | } |
| 11080 | |
| 11081 | if (horizontalEdges) { |
| 11082 | leftFadeStrength = Math.max(0.0f, Math.min(1.0f, getLeftFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11083 | drawLeft = leftFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11084 | rightFadeStrength = Math.max(0.0f, Math.min(1.0f, getRightFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11085 | drawRight = rightFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11086 | } |
| 11087 | |
| 11088 | saveCount = canvas.getSaveCount(); |
| 11089 | |
| 11090 | int solidColor = getSolidColor(); |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 11091 | if (solidColor == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11092 | final int flags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
| 11093 | |
| 11094 | if (drawTop) { |
| 11095 | canvas.saveLayer(left, top, right, top + length, null, flags); |
| 11096 | } |
| 11097 | |
| 11098 | if (drawBottom) { |
| 11099 | canvas.saveLayer(left, bottom - length, right, bottom, null, flags); |
| 11100 | } |
| 11101 | |
| 11102 | if (drawLeft) { |
| 11103 | canvas.saveLayer(left, top, left + length, bottom, null, flags); |
| 11104 | } |
| 11105 | |
| 11106 | if (drawRight) { |
| 11107 | canvas.saveLayer(right - length, top, right, bottom, null, flags); |
| 11108 | } |
| 11109 | } else { |
| 11110 | scrollabilityCache.setFadeColor(solidColor); |
| 11111 | } |
| 11112 | |
| 11113 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 11114 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11115 | |
| 11116 | // Step 4, draw the children |
| 11117 | dispatchDraw(canvas); |
| 11118 | |
| 11119 | // Step 5, draw the fade effect and restore layers |
| 11120 | final Paint p = scrollabilityCache.paint; |
| 11121 | final Matrix matrix = scrollabilityCache.matrix; |
| 11122 | final Shader fade = scrollabilityCache.shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11123 | |
| 11124 | if (drawTop) { |
| 11125 | matrix.setScale(1, fadeHeight * topFadeStrength); |
| 11126 | matrix.postTranslate(left, top); |
| 11127 | fade.setLocalMatrix(matrix); |
| 11128 | canvas.drawRect(left, top, right, top + length, p); |
| 11129 | } |
| 11130 | |
| 11131 | if (drawBottom) { |
| 11132 | matrix.setScale(1, fadeHeight * bottomFadeStrength); |
| 11133 | matrix.postRotate(180); |
| 11134 | matrix.postTranslate(left, bottom); |
| 11135 | fade.setLocalMatrix(matrix); |
| 11136 | canvas.drawRect(left, bottom - length, right, bottom, p); |
| 11137 | } |
| 11138 | |
| 11139 | if (drawLeft) { |
| 11140 | matrix.setScale(1, fadeHeight * leftFadeStrength); |
| 11141 | matrix.postRotate(-90); |
| 11142 | matrix.postTranslate(left, top); |
| 11143 | fade.setLocalMatrix(matrix); |
| 11144 | canvas.drawRect(left, top, left + length, bottom, p); |
| 11145 | } |
| 11146 | |
| 11147 | if (drawRight) { |
| 11148 | matrix.setScale(1, fadeHeight * rightFadeStrength); |
| 11149 | matrix.postRotate(90); |
| 11150 | matrix.postTranslate(right, top); |
| 11151 | fade.setLocalMatrix(matrix); |
| 11152 | canvas.drawRect(right - length, top, right, bottom, p); |
| 11153 | } |
| 11154 | |
| 11155 | canvas.restoreToCount(saveCount); |
| 11156 | |
| 11157 | // Step 6, draw decorations (scrollbars) |
| 11158 | onDrawScrollBars(canvas); |
| 11159 | } |
| 11160 | |
| 11161 | /** |
| 11162 | * Override this if your view is known to always be drawn on top of a solid color background, |
| 11163 | * and needs to draw fading edges. Returning a non-zero color enables the view system to |
| 11164 | * optimize the drawing of the fading edges. If you do return a non-zero color, the alpha |
| 11165 | * should be set to 0xFF. |
| 11166 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11167 | * @see #setVerticalFadingEdgeEnabled(boolean) |
| 11168 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11169 | * |
| 11170 | * @return The known solid color background for this view, or 0 if the color may vary |
| 11171 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 11172 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11173 | public int getSolidColor() { |
| 11174 | return 0; |
| 11175 | } |
| 11176 | |
| 11177 | /** |
| 11178 | * Build a human readable string representation of the specified view flags. |
| 11179 | * |
| 11180 | * @param flags the view flags to convert to a string |
| 11181 | * @return a String representing the supplied flags |
| 11182 | */ |
| 11183 | private static String printFlags(int flags) { |
| 11184 | String output = ""; |
| 11185 | int numFlags = 0; |
| 11186 | if ((flags & FOCUSABLE_MASK) == FOCUSABLE) { |
| 11187 | output += "TAKES_FOCUS"; |
| 11188 | numFlags++; |
| 11189 | } |
| 11190 | |
| 11191 | switch (flags & VISIBILITY_MASK) { |
| 11192 | case INVISIBLE: |
| 11193 | if (numFlags > 0) { |
| 11194 | output += " "; |
| 11195 | } |
| 11196 | output += "INVISIBLE"; |
| 11197 | // USELESS HERE numFlags++; |
| 11198 | break; |
| 11199 | case GONE: |
| 11200 | if (numFlags > 0) { |
| 11201 | output += " "; |
| 11202 | } |
| 11203 | output += "GONE"; |
| 11204 | // USELESS HERE numFlags++; |
| 11205 | break; |
| 11206 | default: |
| 11207 | break; |
| 11208 | } |
| 11209 | return output; |
| 11210 | } |
| 11211 | |
| 11212 | /** |
| 11213 | * Build a human readable string representation of the specified private |
| 11214 | * view flags. |
| 11215 | * |
| 11216 | * @param privateFlags the private view flags to convert to a string |
| 11217 | * @return a String representing the supplied flags |
| 11218 | */ |
| 11219 | private static String printPrivateFlags(int privateFlags) { |
| 11220 | String output = ""; |
| 11221 | int numFlags = 0; |
| 11222 | |
| 11223 | if ((privateFlags & WANTS_FOCUS) == WANTS_FOCUS) { |
| 11224 | output += "WANTS_FOCUS"; |
| 11225 | numFlags++; |
| 11226 | } |
| 11227 | |
| 11228 | if ((privateFlags & FOCUSED) == FOCUSED) { |
| 11229 | if (numFlags > 0) { |
| 11230 | output += " "; |
| 11231 | } |
| 11232 | output += "FOCUSED"; |
| 11233 | numFlags++; |
| 11234 | } |
| 11235 | |
| 11236 | if ((privateFlags & SELECTED) == SELECTED) { |
| 11237 | if (numFlags > 0) { |
| 11238 | output += " "; |
| 11239 | } |
| 11240 | output += "SELECTED"; |
| 11241 | numFlags++; |
| 11242 | } |
| 11243 | |
| 11244 | if ((privateFlags & IS_ROOT_NAMESPACE) == IS_ROOT_NAMESPACE) { |
| 11245 | if (numFlags > 0) { |
| 11246 | output += " "; |
| 11247 | } |
| 11248 | output += "IS_ROOT_NAMESPACE"; |
| 11249 | numFlags++; |
| 11250 | } |
| 11251 | |
| 11252 | if ((privateFlags & HAS_BOUNDS) == HAS_BOUNDS) { |
| 11253 | if (numFlags > 0) { |
| 11254 | output += " "; |
| 11255 | } |
| 11256 | output += "HAS_BOUNDS"; |
| 11257 | numFlags++; |
| 11258 | } |
| 11259 | |
| 11260 | if ((privateFlags & DRAWN) == DRAWN) { |
| 11261 | if (numFlags > 0) { |
| 11262 | output += " "; |
| 11263 | } |
| 11264 | output += "DRAWN"; |
| 11265 | // USELESS HERE numFlags++; |
| 11266 | } |
| 11267 | return output; |
| 11268 | } |
| 11269 | |
| 11270 | /** |
| 11271 | * <p>Indicates whether or not this view's layout will be requested during |
| 11272 | * the next hierarchy layout pass.</p> |
| 11273 | * |
| 11274 | * @return true if the layout will be forced during next layout pass |
| 11275 | */ |
| 11276 | public boolean isLayoutRequested() { |
| 11277 | return (mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT; |
| 11278 | } |
| 11279 | |
| 11280 | /** |
| 11281 | * Assign a size and position to a view and all of its |
| 11282 | * descendants |
| 11283 | * |
| 11284 | * <p>This is the second phase of the layout mechanism. |
| 11285 | * (The first is measuring). In this phase, each parent calls |
| 11286 | * layout on all of its children to position them. |
| 11287 | * This is typically done using the child measurements |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 11288 | * that were stored in the measure pass().</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11289 | * |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 11290 | * <p>Derived classes should not override this method. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11291 | * Derived classes with children should override |
| 11292 | * onLayout. In that method, they should |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 11293 | * call layout on each of their children.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11294 | * |
| 11295 | * @param l Left position, relative to parent |
| 11296 | * @param t Top position, relative to parent |
| 11297 | * @param r Right position, relative to parent |
| 11298 | * @param b Bottom position, relative to parent |
| 11299 | */ |
Romain Guy | 5429e1d | 2010-09-07 12:38:00 -0700 | [diff] [blame] | 11300 | @SuppressWarnings({"unchecked"}) |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 11301 | public void layout(int l, int t, int r, int b) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 11302 | int oldL = mLeft; |
| 11303 | int oldT = mTop; |
| 11304 | int oldB = mBottom; |
| 11305 | int oldR = mRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11306 | boolean changed = setFrame(l, t, r, b); |
| 11307 | if (changed || (mPrivateFlags & LAYOUT_REQUIRED) == LAYOUT_REQUIRED) { |
| 11308 | if (ViewDebug.TRACE_HIERARCHY) { |
| 11309 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_LAYOUT); |
| 11310 | } |
| 11311 | |
| 11312 | onLayout(changed, l, t, r, b); |
| 11313 | mPrivateFlags &= ~LAYOUT_REQUIRED; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 11314 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11315 | ListenerInfo li = mListenerInfo; |
| 11316 | if (li != null && li.mOnLayoutChangeListeners != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 11317 | ArrayList<OnLayoutChangeListener> listenersCopy = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11318 | (ArrayList<OnLayoutChangeListener>)li.mOnLayoutChangeListeners.clone(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 11319 | int numListeners = listenersCopy.size(); |
| 11320 | for (int i = 0; i < numListeners; ++i) { |
Chet Haase | 7c608f2 | 2010-10-22 17:54:04 -0700 | [diff] [blame] | 11321 | 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] | 11322 | } |
| 11323 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11324 | } |
| 11325 | mPrivateFlags &= ~FORCE_LAYOUT; |
| 11326 | } |
| 11327 | |
| 11328 | /** |
| 11329 | * Called from layout when this view should |
| 11330 | * assign a size and position to each of its children. |
| 11331 | * |
| 11332 | * Derived classes with children should override |
| 11333 | * this method and call layout on each of |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 11334 | * their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11335 | * @param changed This is a new size or position for this view |
| 11336 | * @param left Left position, relative to parent |
| 11337 | * @param top Top position, relative to parent |
| 11338 | * @param right Right position, relative to parent |
| 11339 | * @param bottom Bottom position, relative to parent |
| 11340 | */ |
| 11341 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 11342 | } |
| 11343 | |
| 11344 | /** |
| 11345 | * Assign a size and position to this view. |
| 11346 | * |
| 11347 | * This is called from layout. |
| 11348 | * |
| 11349 | * @param left Left position, relative to parent |
| 11350 | * @param top Top position, relative to parent |
| 11351 | * @param right Right position, relative to parent |
| 11352 | * @param bottom Bottom position, relative to parent |
| 11353 | * @return true if the new size and position are different than the |
| 11354 | * previous ones |
| 11355 | * {@hide} |
| 11356 | */ |
| 11357 | protected boolean setFrame(int left, int top, int right, int bottom) { |
| 11358 | boolean changed = false; |
| 11359 | |
| 11360 | if (DBG) { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 11361 | Log.d("View", this + " View.setFrame(" + left + "," + top + "," |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11362 | + right + "," + bottom + ")"); |
| 11363 | } |
| 11364 | |
| 11365 | if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) { |
| 11366 | changed = true; |
| 11367 | |
| 11368 | // Remember our drawn bit |
| 11369 | int drawn = mPrivateFlags & DRAWN; |
| 11370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11371 | int oldWidth = mRight - mLeft; |
| 11372 | int oldHeight = mBottom - mTop; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 11373 | int newWidth = right - left; |
| 11374 | int newHeight = bottom - top; |
| 11375 | boolean sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight); |
| 11376 | |
| 11377 | // Invalidate our old position |
| 11378 | invalidate(sizeChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11379 | |
| 11380 | mLeft = left; |
| 11381 | mTop = top; |
| 11382 | mRight = right; |
| 11383 | mBottom = bottom; |
| 11384 | |
| 11385 | mPrivateFlags |= HAS_BOUNDS; |
| 11386 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11387 | |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 11388 | if (sizeChanged) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 11389 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 11390 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 11391 | if (mTransformationInfo != null) { |
| 11392 | mTransformationInfo.mMatrixDirty = true; |
| 11393 | } |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 11394 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11395 | onSizeChanged(newWidth, newHeight, oldWidth, oldHeight); |
| 11396 | } |
| 11397 | |
| 11398 | if ((mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 11399 | // If we are visible, force the DRAWN bit to on so that |
| 11400 | // this invalidate will go through (at least to our parent). |
| 11401 | // This is because someone may have invalidated this view |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 11402 | // before this call to setFrame came in, thereby clearing |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11403 | // the DRAWN bit. |
| 11404 | mPrivateFlags |= DRAWN; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 11405 | invalidate(sizeChanged); |
Chet Haase | f28595e | 2011-01-31 18:52:12 -0800 | [diff] [blame] | 11406 | // parent display list may need to be recreated based on a change in the bounds |
| 11407 | // of any child |
| 11408 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11409 | } |
| 11410 | |
| 11411 | // Reset drawn bit to original value (invalidate turns it off) |
| 11412 | mPrivateFlags |= drawn; |
| 11413 | |
| 11414 | mBackgroundSizeChanged = true; |
| 11415 | } |
| 11416 | return changed; |
| 11417 | } |
| 11418 | |
| 11419 | /** |
| 11420 | * Finalize inflating a view from XML. This is called as the last phase |
| 11421 | * of inflation, after all child views have been added. |
| 11422 | * |
| 11423 | * <p>Even if the subclass overrides onFinishInflate, they should always be |
| 11424 | * sure to call the super method, so that we get called. |
| 11425 | */ |
| 11426 | protected void onFinishInflate() { |
| 11427 | } |
| 11428 | |
| 11429 | /** |
| 11430 | * Returns the resources associated with this view. |
| 11431 | * |
| 11432 | * @return Resources object. |
| 11433 | */ |
| 11434 | public Resources getResources() { |
| 11435 | return mResources; |
| 11436 | } |
| 11437 | |
| 11438 | /** |
| 11439 | * Invalidates the specified Drawable. |
| 11440 | * |
| 11441 | * @param drawable the drawable to invalidate |
| 11442 | */ |
| 11443 | public void invalidateDrawable(Drawable drawable) { |
| 11444 | if (verifyDrawable(drawable)) { |
| 11445 | final Rect dirty = drawable.getBounds(); |
| 11446 | final int scrollX = mScrollX; |
| 11447 | final int scrollY = mScrollY; |
| 11448 | |
| 11449 | invalidate(dirty.left + scrollX, dirty.top + scrollY, |
| 11450 | dirty.right + scrollX, dirty.bottom + scrollY); |
| 11451 | } |
| 11452 | } |
| 11453 | |
| 11454 | /** |
| 11455 | * Schedules an action on a drawable to occur at a specified time. |
| 11456 | * |
| 11457 | * @param who the recipient of the action |
| 11458 | * @param what the action to run on the drawable |
| 11459 | * @param when the time at which the action must occur. Uses the |
| 11460 | * {@link SystemClock#uptimeMillis} timebase. |
| 11461 | */ |
| 11462 | public void scheduleDrawable(Drawable who, Runnable what, long when) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 11463 | if (verifyDrawable(who) && what != null) { |
| 11464 | if (mAttachInfo != null) { |
| 11465 | mAttachInfo.mHandler.postAtTime(what, who, when); |
| 11466 | } else { |
| 11467 | ViewRootImpl.getRunQueue().postDelayed(what, when - SystemClock.uptimeMillis()); |
| 11468 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11469 | } |
| 11470 | } |
| 11471 | |
| 11472 | /** |
| 11473 | * Cancels a scheduled action on a drawable. |
| 11474 | * |
| 11475 | * @param who the recipient of the action |
| 11476 | * @param what the action to cancel |
| 11477 | */ |
| 11478 | public void unscheduleDrawable(Drawable who, Runnable what) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 11479 | if (verifyDrawable(who) && what != null) { |
| 11480 | if (mAttachInfo != null) { |
| 11481 | mAttachInfo.mHandler.removeCallbacks(what, who); |
| 11482 | } else { |
| 11483 | ViewRootImpl.getRunQueue().removeCallbacks(what); |
| 11484 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11485 | } |
| 11486 | } |
| 11487 | |
| 11488 | /** |
| 11489 | * Unschedule any events associated with the given Drawable. This can be |
| 11490 | * used when selecting a new Drawable into a view, so that the previous |
| 11491 | * one is completely unscheduled. |
| 11492 | * |
| 11493 | * @param who The Drawable to unschedule. |
| 11494 | * |
| 11495 | * @see #drawableStateChanged |
| 11496 | */ |
| 11497 | public void unscheduleDrawable(Drawable who) { |
| 11498 | if (mAttachInfo != null) { |
| 11499 | mAttachInfo.mHandler.removeCallbacksAndMessages(who); |
| 11500 | } |
| 11501 | } |
| 11502 | |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 11503 | /** |
| 11504 | * Return the layout direction of a given Drawable. |
| 11505 | * |
| 11506 | * @param who the Drawable to query |
| 11507 | * |
| 11508 | * @hide |
| 11509 | */ |
| 11510 | public int getResolvedLayoutDirection(Drawable who) { |
| 11511 | return (who == mBGDrawable) ? getResolvedLayoutDirection() : LAYOUT_DIRECTION_DEFAULT; |
Fabrice Di Meglio | 6a03640 | 2011-05-23 14:43:23 -0700 | [diff] [blame] | 11512 | } |
| 11513 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11514 | /** |
| 11515 | * If your view subclass is displaying its own Drawable objects, it should |
| 11516 | * override this function and return true for any Drawable it is |
| 11517 | * displaying. This allows animations for those drawables to be |
| 11518 | * scheduled. |
| 11519 | * |
| 11520 | * <p>Be sure to call through to the super class when overriding this |
| 11521 | * function. |
| 11522 | * |
| 11523 | * @param who The Drawable to verify. Return true if it is one you are |
| 11524 | * displaying, else return the result of calling through to the |
| 11525 | * super class. |
| 11526 | * |
| 11527 | * @return boolean If true than the Drawable is being displayed in the |
| 11528 | * view; else false and it is not allowed to animate. |
| 11529 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11530 | * @see #unscheduleDrawable(android.graphics.drawable.Drawable) |
| 11531 | * @see #drawableStateChanged() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11532 | */ |
| 11533 | protected boolean verifyDrawable(Drawable who) { |
| 11534 | return who == mBGDrawable; |
| 11535 | } |
| 11536 | |
| 11537 | /** |
| 11538 | * This function is called whenever the state of the view changes in such |
| 11539 | * a way that it impacts the state of drawables being shown. |
| 11540 | * |
| 11541 | * <p>Be sure to call through to the superclass when overriding this |
| 11542 | * function. |
| 11543 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11544 | * @see Drawable#setState(int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11545 | */ |
| 11546 | protected void drawableStateChanged() { |
| 11547 | Drawable d = mBGDrawable; |
| 11548 | if (d != null && d.isStateful()) { |
| 11549 | d.setState(getDrawableState()); |
| 11550 | } |
| 11551 | } |
| 11552 | |
| 11553 | /** |
| 11554 | * Call this to force a view to update its drawable state. This will cause |
| 11555 | * drawableStateChanged to be called on this view. Views that are interested |
| 11556 | * in the new state should call getDrawableState. |
| 11557 | * |
| 11558 | * @see #drawableStateChanged |
| 11559 | * @see #getDrawableState |
| 11560 | */ |
| 11561 | public void refreshDrawableState() { |
| 11562 | mPrivateFlags |= DRAWABLE_STATE_DIRTY; |
| 11563 | drawableStateChanged(); |
| 11564 | |
| 11565 | ViewParent parent = mParent; |
| 11566 | if (parent != null) { |
| 11567 | parent.childDrawableStateChanged(this); |
| 11568 | } |
| 11569 | } |
| 11570 | |
| 11571 | /** |
| 11572 | * Return an array of resource IDs of the drawable states representing the |
| 11573 | * current state of the view. |
| 11574 | * |
| 11575 | * @return The current drawable state |
| 11576 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11577 | * @see Drawable#setState(int[]) |
| 11578 | * @see #drawableStateChanged() |
| 11579 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11580 | */ |
| 11581 | public final int[] getDrawableState() { |
| 11582 | if ((mDrawableState != null) && ((mPrivateFlags & DRAWABLE_STATE_DIRTY) == 0)) { |
| 11583 | return mDrawableState; |
| 11584 | } else { |
| 11585 | mDrawableState = onCreateDrawableState(0); |
| 11586 | mPrivateFlags &= ~DRAWABLE_STATE_DIRTY; |
| 11587 | return mDrawableState; |
| 11588 | } |
| 11589 | } |
| 11590 | |
| 11591 | /** |
| 11592 | * Generate the new {@link android.graphics.drawable.Drawable} state for |
| 11593 | * this view. This is called by the view |
| 11594 | * system when the cached Drawable state is determined to be invalid. To |
| 11595 | * retrieve the current state, you should use {@link #getDrawableState}. |
| 11596 | * |
| 11597 | * @param extraSpace if non-zero, this is the number of extra entries you |
| 11598 | * would like in the returned array in which you can place your own |
| 11599 | * states. |
| 11600 | * |
| 11601 | * @return Returns an array holding the current {@link Drawable} state of |
| 11602 | * the view. |
| 11603 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11604 | * @see #mergeDrawableStates(int[], int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11605 | */ |
| 11606 | protected int[] onCreateDrawableState(int extraSpace) { |
| 11607 | if ((mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE && |
| 11608 | mParent instanceof View) { |
| 11609 | return ((View) mParent).onCreateDrawableState(extraSpace); |
| 11610 | } |
| 11611 | |
| 11612 | int[] drawableState; |
| 11613 | |
| 11614 | int privateFlags = mPrivateFlags; |
| 11615 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 11616 | int viewStateIndex = 0; |
| 11617 | if ((privateFlags & PRESSED) != 0) viewStateIndex |= VIEW_STATE_PRESSED; |
| 11618 | if ((mViewFlags & ENABLED_MASK) == ENABLED) viewStateIndex |= VIEW_STATE_ENABLED; |
| 11619 | if (isFocused()) viewStateIndex |= VIEW_STATE_FOCUSED; |
Neel Parekh | e537858 | 2010-10-06 11:36:50 -0700 | [diff] [blame] | 11620 | if ((privateFlags & SELECTED) != 0) viewStateIndex |= VIEW_STATE_SELECTED; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 11621 | if (hasWindowFocus()) viewStateIndex |= VIEW_STATE_WINDOW_FOCUSED; |
| 11622 | if ((privateFlags & ACTIVATED) != 0) viewStateIndex |= VIEW_STATE_ACTIVATED; |
Adam Powell | 5a7e94e | 2011-04-25 15:30:43 -0700 | [diff] [blame] | 11623 | if (mAttachInfo != null && mAttachInfo.mHardwareAccelerationRequested && |
| 11624 | HardwareRenderer.isAvailable()) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 11625 | // This is set if HW acceleration is requested, even if the current |
| 11626 | // process doesn't allow it. This is just to allow app preview |
| 11627 | // windows to better match their app. |
| 11628 | viewStateIndex |= VIEW_STATE_ACCELERATED; |
| 11629 | } |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 11630 | if ((privateFlags & HOVERED) != 0) viewStateIndex |= VIEW_STATE_HOVERED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11631 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 11632 | final int privateFlags2 = mPrivateFlags2; |
| 11633 | if ((privateFlags2 & DRAG_CAN_ACCEPT) != 0) viewStateIndex |= VIEW_STATE_DRAG_CAN_ACCEPT; |
| 11634 | if ((privateFlags2 & DRAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_DRAG_HOVERED; |
| 11635 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11636 | drawableState = VIEW_STATE_SETS[viewStateIndex]; |
| 11637 | |
| 11638 | //noinspection ConstantIfStatement |
| 11639 | if (false) { |
| 11640 | Log.i("View", "drawableStateIndex=" + viewStateIndex); |
| 11641 | Log.i("View", toString() |
| 11642 | + " pressed=" + ((privateFlags & PRESSED) != 0) |
| 11643 | + " en=" + ((mViewFlags & ENABLED_MASK) == ENABLED) |
| 11644 | + " fo=" + hasFocus() |
| 11645 | + " sl=" + ((privateFlags & SELECTED) != 0) |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 11646 | + " wf=" + hasWindowFocus() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11647 | + ": " + Arrays.toString(drawableState)); |
| 11648 | } |
| 11649 | |
| 11650 | if (extraSpace == 0) { |
| 11651 | return drawableState; |
| 11652 | } |
| 11653 | |
| 11654 | final int[] fullState; |
| 11655 | if (drawableState != null) { |
| 11656 | fullState = new int[drawableState.length + extraSpace]; |
| 11657 | System.arraycopy(drawableState, 0, fullState, 0, drawableState.length); |
| 11658 | } else { |
| 11659 | fullState = new int[extraSpace]; |
| 11660 | } |
| 11661 | |
| 11662 | return fullState; |
| 11663 | } |
| 11664 | |
| 11665 | /** |
| 11666 | * Merge your own state values in <var>additionalState</var> into the base |
| 11667 | * state values <var>baseState</var> that were returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11668 | * {@link #onCreateDrawableState(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11669 | * |
| 11670 | * @param baseState The base state values returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11671 | * {@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] | 11672 | * own additional state values. |
| 11673 | * |
| 11674 | * @param additionalState The additional state values you would like |
| 11675 | * added to <var>baseState</var>; this array is not modified. |
| 11676 | * |
| 11677 | * @return As a convenience, the <var>baseState</var> array you originally |
| 11678 | * passed into the function is returned. |
| 11679 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11680 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11681 | */ |
| 11682 | protected static int[] mergeDrawableStates(int[] baseState, int[] additionalState) { |
| 11683 | final int N = baseState.length; |
| 11684 | int i = N - 1; |
| 11685 | while (i >= 0 && baseState[i] == 0) { |
| 11686 | i--; |
| 11687 | } |
| 11688 | System.arraycopy(additionalState, 0, baseState, i + 1, additionalState.length); |
| 11689 | return baseState; |
| 11690 | } |
| 11691 | |
| 11692 | /** |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 11693 | * Call {@link Drawable#jumpToCurrentState() Drawable.jumpToCurrentState()} |
| 11694 | * on all Drawable objects associated with this view. |
| 11695 | */ |
| 11696 | public void jumpDrawablesToCurrentState() { |
| 11697 | if (mBGDrawable != null) { |
| 11698 | mBGDrawable.jumpToCurrentState(); |
| 11699 | } |
| 11700 | } |
| 11701 | |
| 11702 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11703 | * Sets the background color for this view. |
| 11704 | * @param color the color of the background |
| 11705 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 11706 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11707 | public void setBackgroundColor(int color) { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 11708 | if (mBGDrawable instanceof ColorDrawable) { |
| 11709 | ((ColorDrawable) mBGDrawable).setColor(color); |
| 11710 | } else { |
| 11711 | setBackgroundDrawable(new ColorDrawable(color)); |
| 11712 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11713 | } |
| 11714 | |
| 11715 | /** |
| 11716 | * Set the background to a given resource. The resource should refer to |
Wink Saville | 7cd88e1 | 2009-08-04 14:45:10 -0700 | [diff] [blame] | 11717 | * a Drawable object or 0 to remove the background. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11718 | * @param resid The identifier of the resource. |
| 11719 | * @attr ref android.R.styleable#View_background |
| 11720 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 11721 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11722 | public void setBackgroundResource(int resid) { |
| 11723 | if (resid != 0 && resid == mBackgroundResource) { |
| 11724 | return; |
| 11725 | } |
| 11726 | |
| 11727 | Drawable d= null; |
| 11728 | if (resid != 0) { |
| 11729 | d = mResources.getDrawable(resid); |
| 11730 | } |
| 11731 | setBackgroundDrawable(d); |
| 11732 | |
| 11733 | mBackgroundResource = resid; |
| 11734 | } |
| 11735 | |
| 11736 | /** |
| 11737 | * Set the background to a given Drawable, or remove the background. If the |
| 11738 | * background has padding, this View's padding is set to the background's |
| 11739 | * padding. However, when a background is removed, this View's padding isn't |
| 11740 | * touched. If setting the padding is desired, please use |
| 11741 | * {@link #setPadding(int, int, int, int)}. |
| 11742 | * |
| 11743 | * @param d The Drawable to use as the background, or null to remove the |
| 11744 | * background |
| 11745 | */ |
| 11746 | public void setBackgroundDrawable(Drawable d) { |
Adam Powell | 4d36ec1 | 2011-07-17 16:44:16 -0700 | [diff] [blame] | 11747 | if (d == mBGDrawable) { |
| 11748 | return; |
| 11749 | } |
| 11750 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11751 | boolean requestLayout = false; |
| 11752 | |
| 11753 | mBackgroundResource = 0; |
| 11754 | |
| 11755 | /* |
| 11756 | * Regardless of whether we're setting a new background or not, we want |
| 11757 | * to clear the previous drawable. |
| 11758 | */ |
| 11759 | if (mBGDrawable != null) { |
| 11760 | mBGDrawable.setCallback(null); |
| 11761 | unscheduleDrawable(mBGDrawable); |
| 11762 | } |
| 11763 | |
| 11764 | if (d != null) { |
| 11765 | Rect padding = sThreadLocal.get(); |
| 11766 | if (padding == null) { |
| 11767 | padding = new Rect(); |
| 11768 | sThreadLocal.set(padding); |
| 11769 | } |
| 11770 | if (d.getPadding(padding)) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11771 | switch (d.getResolvedLayoutDirectionSelf()) { |
| 11772 | case LAYOUT_DIRECTION_RTL: |
| 11773 | setPadding(padding.right, padding.top, padding.left, padding.bottom); |
| 11774 | break; |
| 11775 | case LAYOUT_DIRECTION_LTR: |
| 11776 | default: |
| 11777 | setPadding(padding.left, padding.top, padding.right, padding.bottom); |
| 11778 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11779 | } |
| 11780 | |
| 11781 | // Compare the minimum sizes of the old Drawable and the new. If there isn't an old or |
| 11782 | // if it has a different minimum size, we should layout again |
| 11783 | if (mBGDrawable == null || mBGDrawable.getMinimumHeight() != d.getMinimumHeight() || |
| 11784 | mBGDrawable.getMinimumWidth() != d.getMinimumWidth()) { |
| 11785 | requestLayout = true; |
| 11786 | } |
| 11787 | |
| 11788 | d.setCallback(this); |
| 11789 | if (d.isStateful()) { |
| 11790 | d.setState(getDrawableState()); |
| 11791 | } |
| 11792 | d.setVisible(getVisibility() == VISIBLE, false); |
| 11793 | mBGDrawable = d; |
| 11794 | |
| 11795 | if ((mPrivateFlags & SKIP_DRAW) != 0) { |
| 11796 | mPrivateFlags &= ~SKIP_DRAW; |
| 11797 | mPrivateFlags |= ONLY_DRAWS_BACKGROUND; |
| 11798 | requestLayout = true; |
| 11799 | } |
| 11800 | } else { |
| 11801 | /* Remove the background */ |
| 11802 | mBGDrawable = null; |
| 11803 | |
| 11804 | if ((mPrivateFlags & ONLY_DRAWS_BACKGROUND) != 0) { |
| 11805 | /* |
| 11806 | * This view ONLY drew the background before and we're removing |
| 11807 | * the background, so now it won't draw anything |
| 11808 | * (hence we SKIP_DRAW) |
| 11809 | */ |
| 11810 | mPrivateFlags &= ~ONLY_DRAWS_BACKGROUND; |
| 11811 | mPrivateFlags |= SKIP_DRAW; |
| 11812 | } |
| 11813 | |
| 11814 | /* |
| 11815 | * When the background is set, we try to apply its padding to this |
| 11816 | * View. When the background is removed, we don't touch this View's |
| 11817 | * padding. This is noted in the Javadocs. Hence, we don't need to |
| 11818 | * requestLayout(), the invalidate() below is sufficient. |
| 11819 | */ |
| 11820 | |
| 11821 | // The old background's minimum size could have affected this |
| 11822 | // View's layout, so let's requestLayout |
| 11823 | requestLayout = true; |
| 11824 | } |
| 11825 | |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 11826 | computeOpaqueFlags(); |
| 11827 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11828 | if (requestLayout) { |
| 11829 | requestLayout(); |
| 11830 | } |
| 11831 | |
| 11832 | mBackgroundSizeChanged = true; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 11833 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11834 | } |
| 11835 | |
| 11836 | /** |
| 11837 | * Gets the background drawable |
| 11838 | * @return The drawable used as the background for this view, if any. |
| 11839 | */ |
| 11840 | public Drawable getBackground() { |
| 11841 | return mBGDrawable; |
| 11842 | } |
| 11843 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11844 | /** |
| 11845 | * Sets the padding. The view may add on the space required to display |
| 11846 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 11847 | * So the values returned from {@link #getPaddingLeft}, {@link #getPaddingTop}, |
| 11848 | * {@link #getPaddingRight} and {@link #getPaddingBottom} may be different |
| 11849 | * from the values set in this call. |
| 11850 | * |
| 11851 | * @attr ref android.R.styleable#View_padding |
| 11852 | * @attr ref android.R.styleable#View_paddingBottom |
| 11853 | * @attr ref android.R.styleable#View_paddingLeft |
| 11854 | * @attr ref android.R.styleable#View_paddingRight |
| 11855 | * @attr ref android.R.styleable#View_paddingTop |
| 11856 | * @param left the left padding in pixels |
| 11857 | * @param top the top padding in pixels |
| 11858 | * @param right the right padding in pixels |
| 11859 | * @param bottom the bottom padding in pixels |
| 11860 | */ |
| 11861 | public void setPadding(int left, int top, int right, int bottom) { |
| 11862 | boolean changed = false; |
| 11863 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11864 | mUserPaddingRelative = false; |
| 11865 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11866 | mUserPaddingLeft = left; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11867 | mUserPaddingRight = right; |
| 11868 | mUserPaddingBottom = bottom; |
| 11869 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11870 | final int viewFlags = mViewFlags; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11871 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11872 | // Common case is there are no scroll bars. |
| 11873 | if ((viewFlags & (SCROLLBARS_VERTICAL|SCROLLBARS_HORIZONTAL)) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11874 | if ((viewFlags & SCROLLBARS_VERTICAL) != 0) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11875 | final int offset = (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11876 | ? 0 : getVerticalScrollbarWidth(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11877 | switch (mVerticalScrollbarPosition) { |
| 11878 | case SCROLLBAR_POSITION_DEFAULT: |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11879 | if (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
| 11880 | left += offset; |
| 11881 | } else { |
| 11882 | right += offset; |
| 11883 | } |
| 11884 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11885 | case SCROLLBAR_POSITION_RIGHT: |
| 11886 | right += offset; |
| 11887 | break; |
| 11888 | case SCROLLBAR_POSITION_LEFT: |
| 11889 | left += offset; |
| 11890 | break; |
| 11891 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11892 | } |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11893 | if ((viewFlags & SCROLLBARS_HORIZONTAL) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11894 | bottom += (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
| 11895 | ? 0 : getHorizontalScrollbarHeight(); |
| 11896 | } |
| 11897 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11898 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11899 | if (mPaddingLeft != left) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11900 | changed = true; |
| 11901 | mPaddingLeft = left; |
| 11902 | } |
| 11903 | if (mPaddingTop != top) { |
| 11904 | changed = true; |
| 11905 | mPaddingTop = top; |
| 11906 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11907 | if (mPaddingRight != right) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11908 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11909 | mPaddingRight = right; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11910 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11911 | if (mPaddingBottom != bottom) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11912 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 11913 | mPaddingBottom = bottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11914 | } |
| 11915 | |
| 11916 | if (changed) { |
| 11917 | requestLayout(); |
| 11918 | } |
| 11919 | } |
| 11920 | |
| 11921 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11922 | * Sets the relative padding. The view may add on the space required to display |
| 11923 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 11924 | * So the values returned from {@link #getPaddingStart}, {@link #getPaddingTop}, |
| 11925 | * {@link #getPaddingEnd} and {@link #getPaddingBottom} may be different |
| 11926 | * from the values set in this call. |
| 11927 | * |
| 11928 | * @attr ref android.R.styleable#View_padding |
| 11929 | * @attr ref android.R.styleable#View_paddingBottom |
| 11930 | * @attr ref android.R.styleable#View_paddingStart |
| 11931 | * @attr ref android.R.styleable#View_paddingEnd |
| 11932 | * @attr ref android.R.styleable#View_paddingTop |
| 11933 | * @param start the start padding in pixels |
| 11934 | * @param top the top padding in pixels |
| 11935 | * @param end the end padding in pixels |
| 11936 | * @param bottom the bottom padding in pixels |
| 11937 | * |
| 11938 | * @hide |
| 11939 | */ |
| 11940 | public void setPaddingRelative(int start, int top, int end, int bottom) { |
| 11941 | mUserPaddingRelative = true; |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 11942 | |
| 11943 | mUserPaddingStart = start; |
| 11944 | mUserPaddingEnd = end; |
| 11945 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11946 | switch(getResolvedLayoutDirection()) { |
| 11947 | case LAYOUT_DIRECTION_RTL: |
| 11948 | setPadding(end, top, start, bottom); |
| 11949 | break; |
| 11950 | case LAYOUT_DIRECTION_LTR: |
| 11951 | default: |
| 11952 | setPadding(start, top, end, bottom); |
| 11953 | } |
| 11954 | } |
| 11955 | |
| 11956 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11957 | * Returns the top padding of this view. |
| 11958 | * |
| 11959 | * @return the top padding in pixels |
| 11960 | */ |
| 11961 | public int getPaddingTop() { |
| 11962 | return mPaddingTop; |
| 11963 | } |
| 11964 | |
| 11965 | /** |
| 11966 | * Returns the bottom padding of this view. If there are inset and enabled |
| 11967 | * scrollbars, this value may include the space required to display the |
| 11968 | * scrollbars as well. |
| 11969 | * |
| 11970 | * @return the bottom padding in pixels |
| 11971 | */ |
| 11972 | public int getPaddingBottom() { |
| 11973 | return mPaddingBottom; |
| 11974 | } |
| 11975 | |
| 11976 | /** |
| 11977 | * Returns the left padding of this view. If there are inset and enabled |
| 11978 | * scrollbars, this value may include the space required to display the |
| 11979 | * scrollbars as well. |
| 11980 | * |
| 11981 | * @return the left padding in pixels |
| 11982 | */ |
| 11983 | public int getPaddingLeft() { |
| 11984 | return mPaddingLeft; |
| 11985 | } |
| 11986 | |
| 11987 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11988 | * Returns the start padding of this view. If there are inset and enabled |
| 11989 | * scrollbars, this value may include the space required to display the |
| 11990 | * scrollbars as well. |
| 11991 | * |
| 11992 | * @return the start padding in pixels |
| 11993 | * |
| 11994 | * @hide |
| 11995 | */ |
| 11996 | public int getPaddingStart() { |
| 11997 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
| 11998 | mPaddingRight : mPaddingLeft; |
| 11999 | } |
| 12000 | |
| 12001 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12002 | * Returns the right padding of this view. If there are inset and enabled |
| 12003 | * scrollbars, this value may include the space required to display the |
| 12004 | * scrollbars as well. |
| 12005 | * |
| 12006 | * @return the right padding in pixels |
| 12007 | */ |
| 12008 | public int getPaddingRight() { |
| 12009 | return mPaddingRight; |
| 12010 | } |
| 12011 | |
| 12012 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 12013 | * Returns the end padding of this view. If there are inset and enabled |
| 12014 | * scrollbars, this value may include the space required to display the |
| 12015 | * scrollbars as well. |
| 12016 | * |
| 12017 | * @return the end padding in pixels |
| 12018 | * |
| 12019 | * @hide |
| 12020 | */ |
| 12021 | public int getPaddingEnd() { |
| 12022 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
| 12023 | mPaddingLeft : mPaddingRight; |
| 12024 | } |
| 12025 | |
| 12026 | /** |
| 12027 | * Return if the padding as been set thru relative values |
| 12028 | * {@link #setPaddingRelative(int, int, int, int)} or thru |
| 12029 | * @attr ref android.R.styleable#View_paddingStart or |
| 12030 | * @attr ref android.R.styleable#View_paddingEnd |
| 12031 | * |
| 12032 | * @return true if the padding is relative or false if it is not. |
| 12033 | * |
| 12034 | * @hide |
| 12035 | */ |
| 12036 | public boolean isPaddingRelative() { |
| 12037 | return mUserPaddingRelative; |
| 12038 | } |
| 12039 | |
| 12040 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12041 | * Changes the selection state of this view. A view can be selected or not. |
| 12042 | * Note that selection is not the same as focus. Views are typically |
| 12043 | * selected in the context of an AdapterView like ListView or GridView; |
| 12044 | * the selected view is the view that is highlighted. |
| 12045 | * |
| 12046 | * @param selected true if the view must be selected, false otherwise |
| 12047 | */ |
| 12048 | public void setSelected(boolean selected) { |
| 12049 | if (((mPrivateFlags & SELECTED) != 0) != selected) { |
| 12050 | mPrivateFlags = (mPrivateFlags & ~SELECTED) | (selected ? SELECTED : 0); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 12051 | if (!selected) resetPressedState(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 12052 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12053 | refreshDrawableState(); |
| 12054 | dispatchSetSelected(selected); |
| 12055 | } |
| 12056 | } |
| 12057 | |
| 12058 | /** |
| 12059 | * Dispatch setSelected to all of this View's children. |
| 12060 | * |
| 12061 | * @see #setSelected(boolean) |
| 12062 | * |
| 12063 | * @param selected The new selected state |
| 12064 | */ |
| 12065 | protected void dispatchSetSelected(boolean selected) { |
| 12066 | } |
| 12067 | |
| 12068 | /** |
| 12069 | * Indicates the selection state of this view. |
| 12070 | * |
| 12071 | * @return true if the view is selected, false otherwise |
| 12072 | */ |
| 12073 | @ViewDebug.ExportedProperty |
| 12074 | public boolean isSelected() { |
| 12075 | return (mPrivateFlags & SELECTED) != 0; |
| 12076 | } |
| 12077 | |
| 12078 | /** |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 12079 | * Changes the activated state of this view. A view can be activated or not. |
| 12080 | * Note that activation is not the same as selection. Selection is |
| 12081 | * a transient property, representing the view (hierarchy) the user is |
| 12082 | * currently interacting with. Activation is a longer-term state that the |
| 12083 | * user can move views in and out of. For example, in a list view with |
| 12084 | * single or multiple selection enabled, the views in the current selection |
| 12085 | * set are activated. (Um, yeah, we are deeply sorry about the terminology |
| 12086 | * here.) The activated state is propagated down to children of the view it |
| 12087 | * is set on. |
| 12088 | * |
| 12089 | * @param activated true if the view must be activated, false otherwise |
| 12090 | */ |
| 12091 | public void setActivated(boolean activated) { |
| 12092 | if (((mPrivateFlags & ACTIVATED) != 0) != activated) { |
| 12093 | mPrivateFlags = (mPrivateFlags & ~ACTIVATED) | (activated ? ACTIVATED : 0); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 12094 | invalidate(true); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 12095 | refreshDrawableState(); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 12096 | dispatchSetActivated(activated); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 12097 | } |
| 12098 | } |
| 12099 | |
| 12100 | /** |
| 12101 | * Dispatch setActivated to all of this View's children. |
| 12102 | * |
| 12103 | * @see #setActivated(boolean) |
| 12104 | * |
| 12105 | * @param activated The new activated state |
| 12106 | */ |
| 12107 | protected void dispatchSetActivated(boolean activated) { |
| 12108 | } |
| 12109 | |
| 12110 | /** |
| 12111 | * Indicates the activation state of this view. |
| 12112 | * |
| 12113 | * @return true if the view is activated, false otherwise |
| 12114 | */ |
| 12115 | @ViewDebug.ExportedProperty |
| 12116 | public boolean isActivated() { |
| 12117 | return (mPrivateFlags & ACTIVATED) != 0; |
| 12118 | } |
| 12119 | |
| 12120 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12121 | * Returns the ViewTreeObserver for this view's hierarchy. The view tree |
| 12122 | * observer can be used to get notifications when global events, like |
| 12123 | * layout, happen. |
| 12124 | * |
| 12125 | * The returned ViewTreeObserver observer is not guaranteed to remain |
| 12126 | * valid for the lifetime of this View. If the caller of this method keeps |
| 12127 | * a long-lived reference to ViewTreeObserver, it should always check for |
| 12128 | * the return value of {@link ViewTreeObserver#isAlive()}. |
| 12129 | * |
| 12130 | * @return The ViewTreeObserver for this view's hierarchy. |
| 12131 | */ |
| 12132 | public ViewTreeObserver getViewTreeObserver() { |
| 12133 | if (mAttachInfo != null) { |
| 12134 | return mAttachInfo.mTreeObserver; |
| 12135 | } |
| 12136 | if (mFloatingTreeObserver == null) { |
| 12137 | mFloatingTreeObserver = new ViewTreeObserver(); |
| 12138 | } |
| 12139 | return mFloatingTreeObserver; |
| 12140 | } |
| 12141 | |
| 12142 | /** |
| 12143 | * <p>Finds the topmost view in the current view hierarchy.</p> |
| 12144 | * |
| 12145 | * @return the topmost view containing this view |
| 12146 | */ |
| 12147 | public View getRootView() { |
| 12148 | if (mAttachInfo != null) { |
| 12149 | final View v = mAttachInfo.mRootView; |
| 12150 | if (v != null) { |
| 12151 | return v; |
| 12152 | } |
| 12153 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12155 | View parent = this; |
| 12156 | |
| 12157 | while (parent.mParent != null && parent.mParent instanceof View) { |
| 12158 | parent = (View) parent.mParent; |
| 12159 | } |
| 12160 | |
| 12161 | return parent; |
| 12162 | } |
| 12163 | |
| 12164 | /** |
| 12165 | * <p>Computes the coordinates of this view on the screen. The argument |
| 12166 | * must be an array of two integers. After the method returns, the array |
| 12167 | * contains the x and y location in that order.</p> |
| 12168 | * |
| 12169 | * @param location an array of two integers in which to hold the coordinates |
| 12170 | */ |
| 12171 | public void getLocationOnScreen(int[] location) { |
| 12172 | getLocationInWindow(location); |
| 12173 | |
| 12174 | final AttachInfo info = mAttachInfo; |
Romain Guy | 779398e | 2009-06-16 13:17:50 -0700 | [diff] [blame] | 12175 | if (info != null) { |
| 12176 | location[0] += info.mWindowLeft; |
| 12177 | location[1] += info.mWindowTop; |
| 12178 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12179 | } |
| 12180 | |
| 12181 | /** |
| 12182 | * <p>Computes the coordinates of this view in its window. The argument |
| 12183 | * must be an array of two integers. After the method returns, the array |
| 12184 | * contains the x and y location in that order.</p> |
| 12185 | * |
| 12186 | * @param location an array of two integers in which to hold the coordinates |
| 12187 | */ |
| 12188 | public void getLocationInWindow(int[] location) { |
| 12189 | if (location == null || location.length < 2) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 12190 | 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] | 12191 | } |
| 12192 | |
Gilles Debunne | 6583ce5 | 2011-12-06 18:09:02 -0800 | [diff] [blame] | 12193 | if (mAttachInfo == null) { |
| 12194 | // When the view is not attached to a window, this method does not make sense |
| 12195 | location[0] = location[1] = 0; |
| 12196 | return; |
| 12197 | } |
| 12198 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 12199 | float[] position = mAttachInfo.mTmpTransformLocation; |
| 12200 | position[0] = position[1] = 0.0f; |
| 12201 | |
| 12202 | if (!hasIdentityMatrix()) { |
| 12203 | getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 12204 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12205 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 12206 | position[0] += mLeft; |
| 12207 | position[1] += mTop; |
| 12208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12209 | ViewParent viewParent = mParent; |
| 12210 | while (viewParent instanceof View) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 12211 | final View view = (View) viewParent; |
| 12212 | |
| 12213 | position[0] -= view.mScrollX; |
| 12214 | position[1] -= view.mScrollY; |
| 12215 | |
| 12216 | if (!view.hasIdentityMatrix()) { |
| 12217 | view.getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 12218 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 12219 | |
| 12220 | position[0] += view.mLeft; |
| 12221 | position[1] += view.mTop; |
| 12222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12223 | viewParent = view.mParent; |
| 12224 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12225 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 12226 | if (viewParent instanceof ViewRootImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12227 | // *cough* |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 12228 | final ViewRootImpl vr = (ViewRootImpl) viewParent; |
| 12229 | position[1] -= vr.mCurScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12230 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 12231 | |
| 12232 | location[0] = (int) (position[0] + 0.5f); |
| 12233 | location[1] = (int) (position[1] + 0.5f); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12234 | } |
| 12235 | |
| 12236 | /** |
| 12237 | * {@hide} |
| 12238 | * @param id the id of the view to be found |
| 12239 | * @return the view of the specified id, null if cannot be found |
| 12240 | */ |
| 12241 | protected View findViewTraversal(int id) { |
| 12242 | if (id == mID) { |
| 12243 | return this; |
| 12244 | } |
| 12245 | return null; |
| 12246 | } |
| 12247 | |
| 12248 | /** |
| 12249 | * {@hide} |
| 12250 | * @param tag the tag of the view to be found |
| 12251 | * @return the view of specified tag, null if cannot be found |
| 12252 | */ |
| 12253 | protected View findViewWithTagTraversal(Object tag) { |
| 12254 | if (tag != null && tag.equals(mTag)) { |
| 12255 | return this; |
| 12256 | } |
| 12257 | return null; |
| 12258 | } |
| 12259 | |
| 12260 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 12261 | * {@hide} |
| 12262 | * @param predicate The predicate to evaluate. |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 12263 | * @param childToSkip If not null, ignores this child during the recursive traversal. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 12264 | * @return The first view that matches the predicate or null. |
| 12265 | */ |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 12266 | protected View findViewByPredicateTraversal(Predicate<View> predicate, View childToSkip) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 12267 | if (predicate.apply(this)) { |
| 12268 | return this; |
| 12269 | } |
| 12270 | return null; |
| 12271 | } |
| 12272 | |
| 12273 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12274 | * Look for a child view with the given id. If this view has the given |
| 12275 | * id, return this view. |
| 12276 | * |
| 12277 | * @param id The id to search for. |
| 12278 | * @return The view that has the given id in the hierarchy or null |
| 12279 | */ |
| 12280 | public final View findViewById(int id) { |
| 12281 | if (id < 0) { |
| 12282 | return null; |
| 12283 | } |
| 12284 | return findViewTraversal(id); |
| 12285 | } |
| 12286 | |
| 12287 | /** |
Svetoslav Ganov | 2cdedff | 2011-10-03 14:18:42 -0700 | [diff] [blame] | 12288 | * Finds a view by its unuque and stable accessibility id. |
| 12289 | * |
| 12290 | * @param accessibilityId The searched accessibility id. |
| 12291 | * @return The found view. |
| 12292 | */ |
| 12293 | final View findViewByAccessibilityId(int accessibilityId) { |
| 12294 | if (accessibilityId < 0) { |
| 12295 | return null; |
| 12296 | } |
| 12297 | return findViewByAccessibilityIdTraversal(accessibilityId); |
| 12298 | } |
| 12299 | |
| 12300 | /** |
| 12301 | * Performs the traversal to find a view by its unuque and stable accessibility id. |
| 12302 | * |
| 12303 | * <strong>Note:</strong>This method does not stop at the root namespace |
| 12304 | * boundary since the user can touch the screen at an arbitrary location |
| 12305 | * potentially crossing the root namespace bounday which will send an |
| 12306 | * accessibility event to accessibility services and they should be able |
| 12307 | * to obtain the event source. Also accessibility ids are guaranteed to be |
| 12308 | * unique in the window. |
| 12309 | * |
| 12310 | * @param accessibilityId The accessibility id. |
| 12311 | * @return The found view. |
| 12312 | */ |
| 12313 | View findViewByAccessibilityIdTraversal(int accessibilityId) { |
| 12314 | if (getAccessibilityViewId() == accessibilityId) { |
| 12315 | return this; |
| 12316 | } |
| 12317 | return null; |
| 12318 | } |
| 12319 | |
| 12320 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12321 | * Look for a child view with the given tag. If this view has the given |
| 12322 | * tag, return this view. |
| 12323 | * |
| 12324 | * @param tag The tag to search for, using "tag.equals(getTag())". |
| 12325 | * @return The View that has the given tag in the hierarchy or null |
| 12326 | */ |
| 12327 | public final View findViewWithTag(Object tag) { |
| 12328 | if (tag == null) { |
| 12329 | return null; |
| 12330 | } |
| 12331 | return findViewWithTagTraversal(tag); |
| 12332 | } |
| 12333 | |
| 12334 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 12335 | * {@hide} |
| 12336 | * Look for a child view that matches the specified predicate. |
| 12337 | * If this view matches the predicate, return this view. |
| 12338 | * |
| 12339 | * @param predicate The predicate to evaluate. |
| 12340 | * @return The first view that matches the predicate or null. |
| 12341 | */ |
| 12342 | public final View findViewByPredicate(Predicate<View> predicate) { |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 12343 | return findViewByPredicateTraversal(predicate, null); |
| 12344 | } |
| 12345 | |
| 12346 | /** |
| 12347 | * {@hide} |
| 12348 | * Look for a child view that matches the specified predicate, |
| 12349 | * starting with the specified view and its descendents and then |
| 12350 | * recusively searching the ancestors and siblings of that view |
| 12351 | * until this view is reached. |
| 12352 | * |
| 12353 | * This method is useful in cases where the predicate does not match |
| 12354 | * a single unique view (perhaps multiple views use the same id) |
| 12355 | * and we are trying to find the view that is "closest" in scope to the |
| 12356 | * starting view. |
| 12357 | * |
| 12358 | * @param start The view to start from. |
| 12359 | * @param predicate The predicate to evaluate. |
| 12360 | * @return The first view that matches the predicate or null. |
| 12361 | */ |
| 12362 | public final View findViewByPredicateInsideOut(View start, Predicate<View> predicate) { |
| 12363 | View childToSkip = null; |
| 12364 | for (;;) { |
| 12365 | View view = start.findViewByPredicateTraversal(predicate, childToSkip); |
| 12366 | if (view != null || start == this) { |
| 12367 | return view; |
| 12368 | } |
| 12369 | |
| 12370 | ViewParent parent = start.getParent(); |
| 12371 | if (parent == null || !(parent instanceof View)) { |
| 12372 | return null; |
| 12373 | } |
| 12374 | |
| 12375 | childToSkip = start; |
| 12376 | start = (View) parent; |
| 12377 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 12378 | } |
| 12379 | |
| 12380 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12381 | * Sets the identifier for this view. The identifier does not have to be |
| 12382 | * unique in this view's hierarchy. The identifier should be a positive |
| 12383 | * number. |
| 12384 | * |
| 12385 | * @see #NO_ID |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12386 | * @see #getId() |
| 12387 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12388 | * |
| 12389 | * @param id a number used to identify the view |
| 12390 | * |
| 12391 | * @attr ref android.R.styleable#View_id |
| 12392 | */ |
| 12393 | public void setId(int id) { |
| 12394 | mID = id; |
| 12395 | } |
| 12396 | |
| 12397 | /** |
| 12398 | * {@hide} |
| 12399 | * |
| 12400 | * @param isRoot true if the view belongs to the root namespace, false |
| 12401 | * otherwise |
| 12402 | */ |
| 12403 | public void setIsRootNamespace(boolean isRoot) { |
| 12404 | if (isRoot) { |
| 12405 | mPrivateFlags |= IS_ROOT_NAMESPACE; |
| 12406 | } else { |
| 12407 | mPrivateFlags &= ~IS_ROOT_NAMESPACE; |
| 12408 | } |
| 12409 | } |
| 12410 | |
| 12411 | /** |
| 12412 | * {@hide} |
| 12413 | * |
| 12414 | * @return true if the view belongs to the root namespace, false otherwise |
| 12415 | */ |
| 12416 | public boolean isRootNamespace() { |
| 12417 | return (mPrivateFlags&IS_ROOT_NAMESPACE) != 0; |
| 12418 | } |
| 12419 | |
| 12420 | /** |
| 12421 | * Returns this view's identifier. |
| 12422 | * |
| 12423 | * @return a positive integer used to identify the view or {@link #NO_ID} |
| 12424 | * if the view has no ID |
| 12425 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12426 | * @see #setId(int) |
| 12427 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12428 | * @attr ref android.R.styleable#View_id |
| 12429 | */ |
| 12430 | @ViewDebug.CapturedViewProperty |
| 12431 | public int getId() { |
| 12432 | return mID; |
| 12433 | } |
| 12434 | |
| 12435 | /** |
| 12436 | * Returns this view's tag. |
| 12437 | * |
| 12438 | * @return the Object stored in this view as a tag |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12439 | * |
| 12440 | * @see #setTag(Object) |
| 12441 | * @see #getTag(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12442 | */ |
| 12443 | @ViewDebug.ExportedProperty |
| 12444 | public Object getTag() { |
| 12445 | return mTag; |
| 12446 | } |
| 12447 | |
| 12448 | /** |
| 12449 | * Sets the tag associated with this view. A tag can be used to mark |
| 12450 | * a view in its hierarchy and does not have to be unique within the |
| 12451 | * hierarchy. Tags can also be used to store data within a view without |
| 12452 | * resorting to another data structure. |
| 12453 | * |
| 12454 | * @param tag an Object to tag the view with |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12455 | * |
| 12456 | * @see #getTag() |
| 12457 | * @see #setTag(int, Object) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12458 | */ |
| 12459 | public void setTag(final Object tag) { |
| 12460 | mTag = tag; |
| 12461 | } |
| 12462 | |
| 12463 | /** |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12464 | * Returns the tag associated with this view and the specified key. |
| 12465 | * |
| 12466 | * @param key The key identifying the tag |
| 12467 | * |
| 12468 | * @return the Object stored in this view as a tag |
| 12469 | * |
| 12470 | * @see #setTag(int, Object) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12471 | * @see #getTag() |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12472 | */ |
| 12473 | public Object getTag(int key) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 12474 | if (mKeyedTags != null) return mKeyedTags.get(key); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12475 | return null; |
| 12476 | } |
| 12477 | |
| 12478 | /** |
| 12479 | * Sets a tag associated with this view and a key. A tag can be used |
| 12480 | * to mark a view in its hierarchy and does not have to be unique within |
| 12481 | * the hierarchy. Tags can also be used to store data within a view |
| 12482 | * without resorting to another data structure. |
| 12483 | * |
| 12484 | * 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] | 12485 | * application to ensure it is unique (see the <a |
| 12486 | * href={@docRoot}guide/topics/resources/more-resources.html#Id">ID resource type</a>). |
| 12487 | * Keys identified as belonging to |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12488 | * the Android framework or not associated with any package will cause |
| 12489 | * an {@link IllegalArgumentException} to be thrown. |
| 12490 | * |
| 12491 | * @param key The key identifying the tag |
| 12492 | * @param tag An Object to tag the view with |
| 12493 | * |
| 12494 | * @throws IllegalArgumentException If they specified key is not valid |
| 12495 | * |
| 12496 | * @see #setTag(Object) |
| 12497 | * @see #getTag(int) |
| 12498 | */ |
| 12499 | public void setTag(int key, final Object tag) { |
| 12500 | // If the package id is 0x00 or 0x01, it's either an undefined package |
| 12501 | // or a framework id |
| 12502 | if ((key >>> 24) < 2) { |
| 12503 | throw new IllegalArgumentException("The key must be an application-specific " |
| 12504 | + "resource id."); |
| 12505 | } |
| 12506 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 12507 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12508 | } |
| 12509 | |
| 12510 | /** |
| 12511 | * Variation of {@link #setTag(int, Object)} that enforces the key to be a |
| 12512 | * framework id. |
| 12513 | * |
| 12514 | * @hide |
| 12515 | */ |
| 12516 | public void setTagInternal(int key, Object tag) { |
| 12517 | if ((key >>> 24) != 0x1) { |
| 12518 | throw new IllegalArgumentException("The key must be a framework-specific " |
| 12519 | + "resource id."); |
| 12520 | } |
| 12521 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 12522 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12523 | } |
| 12524 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 12525 | private void setKeyedTag(int key, Object tag) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 12526 | if (mKeyedTags == null) { |
| 12527 | mKeyedTags = new SparseArray<Object>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12528 | } |
| 12529 | |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 12530 | mKeyedTags.put(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 12531 | } |
| 12532 | |
| 12533 | /** |
Romain Guy | 13922e0 | 2009-05-12 17:56:14 -0700 | [diff] [blame] | 12534 | * @param consistency The type of consistency. See ViewDebug for more information. |
| 12535 | * |
| 12536 | * @hide |
| 12537 | */ |
| 12538 | protected boolean dispatchConsistencyCheck(int consistency) { |
| 12539 | return onConsistencyCheck(consistency); |
| 12540 | } |
| 12541 | |
| 12542 | /** |
| 12543 | * Method that subclasses should implement to check their consistency. The type of |
| 12544 | * consistency check is indicated by the bit field passed as a parameter. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12545 | * |
Romain Guy | 13922e0 | 2009-05-12 17:56:14 -0700 | [diff] [blame] | 12546 | * @param consistency The type of consistency. See ViewDebug for more information. |
| 12547 | * |
| 12548 | * @throws IllegalStateException if the view is in an inconsistent state. |
| 12549 | * |
| 12550 | * @hide |
| 12551 | */ |
| 12552 | protected boolean onConsistencyCheck(int consistency) { |
| 12553 | boolean result = true; |
| 12554 | |
| 12555 | final boolean checkLayout = (consistency & ViewDebug.CONSISTENCY_LAYOUT) != 0; |
| 12556 | final boolean checkDrawing = (consistency & ViewDebug.CONSISTENCY_DRAWING) != 0; |
| 12557 | |
| 12558 | if (checkLayout) { |
| 12559 | if (getParent() == null) { |
| 12560 | result = false; |
| 12561 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 12562 | "View " + this + " does not have a parent."); |
| 12563 | } |
| 12564 | |
| 12565 | if (mAttachInfo == null) { |
| 12566 | result = false; |
| 12567 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 12568 | "View " + this + " is not attached to a window."); |
| 12569 | } |
| 12570 | } |
| 12571 | |
| 12572 | if (checkDrawing) { |
| 12573 | // Do not check the DIRTY/DRAWN flags because views can call invalidate() |
| 12574 | // from their draw() method |
| 12575 | |
| 12576 | if ((mPrivateFlags & DRAWN) != DRAWN && |
| 12577 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) { |
| 12578 | result = false; |
| 12579 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 12580 | "View " + this + " was invalidated but its drawing cache is valid."); |
| 12581 | } |
| 12582 | } |
| 12583 | |
| 12584 | return result; |
| 12585 | } |
| 12586 | |
| 12587 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12588 | * Prints information about this view in the log output, with the tag |
| 12589 | * {@link #VIEW_LOG_TAG}. |
| 12590 | * |
| 12591 | * @hide |
| 12592 | */ |
| 12593 | public void debug() { |
| 12594 | debug(0); |
| 12595 | } |
| 12596 | |
| 12597 | /** |
| 12598 | * Prints information about this view in the log output, with the tag |
| 12599 | * {@link #VIEW_LOG_TAG}. Each line in the output is preceded with an |
| 12600 | * indentation defined by the <code>depth</code>. |
| 12601 | * |
| 12602 | * @param depth the indentation level |
| 12603 | * |
| 12604 | * @hide |
| 12605 | */ |
| 12606 | protected void debug(int depth) { |
| 12607 | String output = debugIndent(depth - 1); |
| 12608 | |
| 12609 | output += "+ " + this; |
| 12610 | int id = getId(); |
| 12611 | if (id != -1) { |
| 12612 | output += " (id=" + id + ")"; |
| 12613 | } |
| 12614 | Object tag = getTag(); |
| 12615 | if (tag != null) { |
| 12616 | output += " (tag=" + tag + ")"; |
| 12617 | } |
| 12618 | Log.d(VIEW_LOG_TAG, output); |
| 12619 | |
| 12620 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 12621 | output = debugIndent(depth) + " FOCUSED"; |
| 12622 | Log.d(VIEW_LOG_TAG, output); |
| 12623 | } |
| 12624 | |
| 12625 | output = debugIndent(depth); |
| 12626 | output += "frame={" + mLeft + ", " + mTop + ", " + mRight |
| 12627 | + ", " + mBottom + "} scroll={" + mScrollX + ", " + mScrollY |
| 12628 | + "} "; |
| 12629 | Log.d(VIEW_LOG_TAG, output); |
| 12630 | |
| 12631 | if (mPaddingLeft != 0 || mPaddingTop != 0 || mPaddingRight != 0 |
| 12632 | || mPaddingBottom != 0) { |
| 12633 | output = debugIndent(depth); |
| 12634 | output += "padding={" + mPaddingLeft + ", " + mPaddingTop |
| 12635 | + ", " + mPaddingRight + ", " + mPaddingBottom + "}"; |
| 12636 | Log.d(VIEW_LOG_TAG, output); |
| 12637 | } |
| 12638 | |
| 12639 | output = debugIndent(depth); |
| 12640 | output += "mMeasureWidth=" + mMeasuredWidth + |
| 12641 | " mMeasureHeight=" + mMeasuredHeight; |
| 12642 | Log.d(VIEW_LOG_TAG, output); |
| 12643 | |
| 12644 | output = debugIndent(depth); |
| 12645 | if (mLayoutParams == null) { |
| 12646 | output += "BAD! no layout params"; |
| 12647 | } else { |
| 12648 | output = mLayoutParams.debug(output); |
| 12649 | } |
| 12650 | Log.d(VIEW_LOG_TAG, output); |
| 12651 | |
| 12652 | output = debugIndent(depth); |
| 12653 | output += "flags={"; |
| 12654 | output += View.printFlags(mViewFlags); |
| 12655 | output += "}"; |
| 12656 | Log.d(VIEW_LOG_TAG, output); |
| 12657 | |
| 12658 | output = debugIndent(depth); |
| 12659 | output += "privateFlags={"; |
| 12660 | output += View.printPrivateFlags(mPrivateFlags); |
| 12661 | output += "}"; |
| 12662 | Log.d(VIEW_LOG_TAG, output); |
| 12663 | } |
| 12664 | |
| 12665 | /** |
| 12666 | * Creates an string of whitespaces used for indentation. |
| 12667 | * |
| 12668 | * @param depth the indentation level |
| 12669 | * @return a String containing (depth * 2 + 3) * 2 white spaces |
| 12670 | * |
| 12671 | * @hide |
| 12672 | */ |
| 12673 | protected static String debugIndent(int depth) { |
| 12674 | StringBuilder spaces = new StringBuilder((depth * 2 + 3) * 2); |
| 12675 | for (int i = 0; i < (depth * 2) + 3; i++) { |
| 12676 | spaces.append(' ').append(' '); |
| 12677 | } |
| 12678 | return spaces.toString(); |
| 12679 | } |
| 12680 | |
| 12681 | /** |
| 12682 | * <p>Return the offset of the widget's text baseline from the widget's top |
| 12683 | * boundary. If this widget does not support baseline alignment, this |
| 12684 | * method returns -1. </p> |
| 12685 | * |
| 12686 | * @return the offset of the baseline within the widget's bounds or -1 |
| 12687 | * if baseline alignment is not supported |
| 12688 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 12689 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12690 | public int getBaseline() { |
| 12691 | return -1; |
| 12692 | } |
| 12693 | |
| 12694 | /** |
| 12695 | * Call this when something has changed which has invalidated the |
| 12696 | * layout of this view. This will schedule a layout pass of the view |
| 12697 | * tree. |
| 12698 | */ |
| 12699 | public void requestLayout() { |
| 12700 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12701 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.REQUEST_LAYOUT); |
| 12702 | } |
| 12703 | |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 12704 | if (getAccessibilityNodeProvider() != null) { |
| 12705 | throw new IllegalStateException("Views with AccessibilityNodeProvider" |
| 12706 | + " can't have children."); |
| 12707 | } |
| 12708 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12709 | mPrivateFlags |= FORCE_LAYOUT; |
Chet Haase | 5af048c | 2011-01-24 17:00:32 -0800 | [diff] [blame] | 12710 | mPrivateFlags |= INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12711 | |
Fabrice Di Meglio | d794aca | 2011-07-22 18:19:36 -0700 | [diff] [blame] | 12712 | if (mParent != null) { |
| 12713 | if (mLayoutParams != null) { |
| 12714 | mLayoutParams.resolveWithDirection(getResolvedLayoutDirection()); |
| 12715 | } |
| 12716 | if (!mParent.isLayoutRequested()) { |
| 12717 | mParent.requestLayout(); |
| 12718 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12719 | } |
| 12720 | } |
| 12721 | |
| 12722 | /** |
| 12723 | * Forces this view to be laid out during the next layout pass. |
| 12724 | * This method does not call requestLayout() or forceLayout() |
| 12725 | * on the parent. |
| 12726 | */ |
| 12727 | public void forceLayout() { |
| 12728 | mPrivateFlags |= FORCE_LAYOUT; |
Chet Haase | 5af048c | 2011-01-24 17:00:32 -0800 | [diff] [blame] | 12729 | mPrivateFlags |= INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12730 | } |
| 12731 | |
| 12732 | /** |
| 12733 | * <p> |
| 12734 | * This is called to find out how big a view should be. The parent |
| 12735 | * supplies constraint information in the width and height parameters. |
| 12736 | * </p> |
| 12737 | * |
| 12738 | * <p> |
| 12739 | * The actual mesurement work of a view is performed in |
| 12740 | * {@link #onMeasure(int, int)}, called by this method. Therefore, only |
| 12741 | * {@link #onMeasure(int, int)} can and must be overriden by subclasses. |
| 12742 | * </p> |
| 12743 | * |
| 12744 | * |
| 12745 | * @param widthMeasureSpec Horizontal space requirements as imposed by the |
| 12746 | * parent |
| 12747 | * @param heightMeasureSpec Vertical space requirements as imposed by the |
| 12748 | * parent |
| 12749 | * |
| 12750 | * @see #onMeasure(int, int) |
| 12751 | */ |
| 12752 | public final void measure(int widthMeasureSpec, int heightMeasureSpec) { |
| 12753 | if ((mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT || |
| 12754 | widthMeasureSpec != mOldWidthMeasureSpec || |
| 12755 | heightMeasureSpec != mOldHeightMeasureSpec) { |
| 12756 | |
| 12757 | // first clears the measured dimension flag |
| 12758 | mPrivateFlags &= ~MEASURED_DIMENSION_SET; |
| 12759 | |
| 12760 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12761 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_MEASURE); |
| 12762 | } |
| 12763 | |
| 12764 | // measure ourselves, this should set the measured dimension flag back |
| 12765 | onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 12766 | |
| 12767 | // flag not set, setMeasuredDimension() was not invoked, we raise |
| 12768 | // an exception to warn the developer |
| 12769 | if ((mPrivateFlags & MEASURED_DIMENSION_SET) != MEASURED_DIMENSION_SET) { |
| 12770 | throw new IllegalStateException("onMeasure() did not set the" |
| 12771 | + " measured dimension by calling" |
| 12772 | + " setMeasuredDimension()"); |
| 12773 | } |
| 12774 | |
| 12775 | mPrivateFlags |= LAYOUT_REQUIRED; |
| 12776 | } |
| 12777 | |
| 12778 | mOldWidthMeasureSpec = widthMeasureSpec; |
| 12779 | mOldHeightMeasureSpec = heightMeasureSpec; |
| 12780 | } |
| 12781 | |
| 12782 | /** |
| 12783 | * <p> |
| 12784 | * Measure the view and its content to determine the measured width and the |
| 12785 | * measured height. This method is invoked by {@link #measure(int, int)} and |
| 12786 | * should be overriden by subclasses to provide accurate and efficient |
| 12787 | * measurement of their contents. |
| 12788 | * </p> |
| 12789 | * |
| 12790 | * <p> |
| 12791 | * <strong>CONTRACT:</strong> When overriding this method, you |
| 12792 | * <em>must</em> call {@link #setMeasuredDimension(int, int)} to store the |
| 12793 | * measured width and height of this view. Failure to do so will trigger an |
| 12794 | * <code>IllegalStateException</code>, thrown by |
| 12795 | * {@link #measure(int, int)}. Calling the superclass' |
| 12796 | * {@link #onMeasure(int, int)} is a valid use. |
| 12797 | * </p> |
| 12798 | * |
| 12799 | * <p> |
| 12800 | * The base class implementation of measure defaults to the background size, |
| 12801 | * unless a larger size is allowed by the MeasureSpec. Subclasses should |
| 12802 | * override {@link #onMeasure(int, int)} to provide better measurements of |
| 12803 | * their content. |
| 12804 | * </p> |
| 12805 | * |
| 12806 | * <p> |
| 12807 | * If this method is overridden, it is the subclass's responsibility to make |
| 12808 | * sure the measured height and width are at least the view's minimum height |
| 12809 | * and width ({@link #getSuggestedMinimumHeight()} and |
| 12810 | * {@link #getSuggestedMinimumWidth()}). |
| 12811 | * </p> |
| 12812 | * |
| 12813 | * @param widthMeasureSpec horizontal space requirements as imposed by the parent. |
| 12814 | * The requirements are encoded with |
| 12815 | * {@link android.view.View.MeasureSpec}. |
| 12816 | * @param heightMeasureSpec vertical space requirements as imposed by the parent. |
| 12817 | * The requirements are encoded with |
| 12818 | * {@link android.view.View.MeasureSpec}. |
| 12819 | * |
| 12820 | * @see #getMeasuredWidth() |
| 12821 | * @see #getMeasuredHeight() |
| 12822 | * @see #setMeasuredDimension(int, int) |
| 12823 | * @see #getSuggestedMinimumHeight() |
| 12824 | * @see #getSuggestedMinimumWidth() |
| 12825 | * @see android.view.View.MeasureSpec#getMode(int) |
| 12826 | * @see android.view.View.MeasureSpec#getSize(int) |
| 12827 | */ |
| 12828 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 12829 | setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), |
| 12830 | getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec)); |
| 12831 | } |
| 12832 | |
| 12833 | /** |
| 12834 | * <p>This mehod must be called by {@link #onMeasure(int, int)} to store the |
| 12835 | * measured width and measured height. Failing to do so will trigger an |
| 12836 | * exception at measurement time.</p> |
| 12837 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12838 | * @param measuredWidth The measured width of this view. May be a complex |
| 12839 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 12840 | * {@link #MEASURED_STATE_TOO_SMALL}. |
| 12841 | * @param measuredHeight The measured height of this view. May be a complex |
| 12842 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 12843 | * {@link #MEASURED_STATE_TOO_SMALL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12844 | */ |
| 12845 | protected final void setMeasuredDimension(int measuredWidth, int measuredHeight) { |
| 12846 | mMeasuredWidth = measuredWidth; |
| 12847 | mMeasuredHeight = measuredHeight; |
| 12848 | |
| 12849 | mPrivateFlags |= MEASURED_DIMENSION_SET; |
| 12850 | } |
| 12851 | |
| 12852 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12853 | * Merge two states as returned by {@link #getMeasuredState()}. |
| 12854 | * @param curState The current state as returned from a view or the result |
| 12855 | * of combining multiple views. |
| 12856 | * @param newState The new view state to combine. |
| 12857 | * @return Returns a new integer reflecting the combination of the two |
| 12858 | * states. |
| 12859 | */ |
| 12860 | public static int combineMeasuredStates(int curState, int newState) { |
| 12861 | return curState | newState; |
| 12862 | } |
| 12863 | |
| 12864 | /** |
| 12865 | * Version of {@link #resolveSizeAndState(int, int, int)} |
| 12866 | * returning only the {@link #MEASURED_SIZE_MASK} bits of the result. |
| 12867 | */ |
| 12868 | public static int resolveSize(int size, int measureSpec) { |
| 12869 | return resolveSizeAndState(size, measureSpec, 0) & MEASURED_SIZE_MASK; |
| 12870 | } |
| 12871 | |
| 12872 | /** |
| 12873 | * Utility to reconcile a desired size and state, with constraints imposed |
| 12874 | * by a MeasureSpec. Will take the desired size, unless a different size |
| 12875 | * is imposed by the constraints. The returned value is a compound integer, |
| 12876 | * with the resolved size in the {@link #MEASURED_SIZE_MASK} bits and |
| 12877 | * optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the resulting |
| 12878 | * 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] | 12879 | * |
| 12880 | * @param size How big the view wants to be |
| 12881 | * @param measureSpec Constraints imposed by the parent |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12882 | * @return Size information bit mask as defined by |
| 12883 | * {@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] | 12884 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12885 | 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] | 12886 | int result = size; |
| 12887 | int specMode = MeasureSpec.getMode(measureSpec); |
| 12888 | int specSize = MeasureSpec.getSize(measureSpec); |
| 12889 | switch (specMode) { |
| 12890 | case MeasureSpec.UNSPECIFIED: |
| 12891 | result = size; |
| 12892 | break; |
| 12893 | case MeasureSpec.AT_MOST: |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12894 | if (specSize < size) { |
| 12895 | result = specSize | MEASURED_STATE_TOO_SMALL; |
| 12896 | } else { |
| 12897 | result = size; |
| 12898 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12899 | break; |
| 12900 | case MeasureSpec.EXACTLY: |
| 12901 | result = specSize; |
| 12902 | break; |
| 12903 | } |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 12904 | return result | (childMeasuredState&MEASURED_STATE_MASK); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12905 | } |
| 12906 | |
| 12907 | /** |
| 12908 | * Utility to return a default size. Uses the supplied size if the |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 12909 | * MeasureSpec imposed no constraints. Will get larger if allowed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12910 | * by the MeasureSpec. |
| 12911 | * |
| 12912 | * @param size Default size for this view |
| 12913 | * @param measureSpec Constraints imposed by the parent |
| 12914 | * @return The size this view should be. |
| 12915 | */ |
| 12916 | public static int getDefaultSize(int size, int measureSpec) { |
| 12917 | int result = size; |
| 12918 | int specMode = MeasureSpec.getMode(measureSpec); |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 12919 | int specSize = MeasureSpec.getSize(measureSpec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12920 | |
| 12921 | switch (specMode) { |
| 12922 | case MeasureSpec.UNSPECIFIED: |
| 12923 | result = size; |
| 12924 | break; |
| 12925 | case MeasureSpec.AT_MOST: |
| 12926 | case MeasureSpec.EXACTLY: |
| 12927 | result = specSize; |
| 12928 | break; |
| 12929 | } |
| 12930 | return result; |
| 12931 | } |
| 12932 | |
| 12933 | /** |
| 12934 | * Returns the suggested minimum height that the view should use. This |
| 12935 | * returns the maximum of the view's minimum height |
| 12936 | * and the background's minimum height |
| 12937 | * ({@link android.graphics.drawable.Drawable#getMinimumHeight()}). |
| 12938 | * <p> |
| 12939 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 12940 | * ensure the returned height is within the requirements of the parent. |
| 12941 | * |
| 12942 | * @return The suggested minimum height of the view. |
| 12943 | */ |
| 12944 | protected int getSuggestedMinimumHeight() { |
| 12945 | int suggestedMinHeight = mMinHeight; |
| 12946 | |
| 12947 | if (mBGDrawable != null) { |
| 12948 | final int bgMinHeight = mBGDrawable.getMinimumHeight(); |
| 12949 | if (suggestedMinHeight < bgMinHeight) { |
| 12950 | suggestedMinHeight = bgMinHeight; |
| 12951 | } |
| 12952 | } |
| 12953 | |
| 12954 | return suggestedMinHeight; |
| 12955 | } |
| 12956 | |
| 12957 | /** |
| 12958 | * Returns the suggested minimum width that the view should use. This |
| 12959 | * returns the maximum of the view's minimum width) |
| 12960 | * and the background's minimum width |
| 12961 | * ({@link android.graphics.drawable.Drawable#getMinimumWidth()}). |
| 12962 | * <p> |
| 12963 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 12964 | * ensure the returned width is within the requirements of the parent. |
| 12965 | * |
| 12966 | * @return The suggested minimum width of the view. |
| 12967 | */ |
| 12968 | protected int getSuggestedMinimumWidth() { |
| 12969 | int suggestedMinWidth = mMinWidth; |
| 12970 | |
| 12971 | if (mBGDrawable != null) { |
| 12972 | final int bgMinWidth = mBGDrawable.getMinimumWidth(); |
| 12973 | if (suggestedMinWidth < bgMinWidth) { |
| 12974 | suggestedMinWidth = bgMinWidth; |
| 12975 | } |
| 12976 | } |
| 12977 | |
| 12978 | return suggestedMinWidth; |
| 12979 | } |
| 12980 | |
| 12981 | /** |
| 12982 | * Sets the minimum height of the view. It is not guaranteed the view will |
| 12983 | * be able to achieve this minimum height (for example, if its parent layout |
| 12984 | * constrains it with less available height). |
| 12985 | * |
| 12986 | * @param minHeight The minimum height the view will try to be. |
| 12987 | */ |
| 12988 | public void setMinimumHeight(int minHeight) { |
| 12989 | mMinHeight = minHeight; |
| 12990 | } |
| 12991 | |
| 12992 | /** |
| 12993 | * Sets the minimum width of the view. It is not guaranteed the view will |
| 12994 | * be able to achieve this minimum width (for example, if its parent layout |
| 12995 | * constrains it with less available width). |
| 12996 | * |
| 12997 | * @param minWidth The minimum width the view will try to be. |
| 12998 | */ |
| 12999 | public void setMinimumWidth(int minWidth) { |
| 13000 | mMinWidth = minWidth; |
| 13001 | } |
| 13002 | |
| 13003 | /** |
| 13004 | * Get the animation currently associated with this view. |
| 13005 | * |
| 13006 | * @return The animation that is currently playing or |
| 13007 | * scheduled to play for this view. |
| 13008 | */ |
| 13009 | public Animation getAnimation() { |
| 13010 | return mCurrentAnimation; |
| 13011 | } |
| 13012 | |
| 13013 | /** |
| 13014 | * Start the specified animation now. |
| 13015 | * |
| 13016 | * @param animation the animation to start now |
| 13017 | */ |
| 13018 | public void startAnimation(Animation animation) { |
| 13019 | animation.setStartTime(Animation.START_ON_FIRST_FRAME); |
| 13020 | setAnimation(animation); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 13021 | invalidateParentCaches(); |
| 13022 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13023 | } |
| 13024 | |
| 13025 | /** |
| 13026 | * Cancels any animations for this view. |
| 13027 | */ |
| 13028 | public void clearAnimation() { |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 13029 | if (mCurrentAnimation != null) { |
Romain Guy | b4a107d | 2010-02-09 18:50:08 -0800 | [diff] [blame] | 13030 | mCurrentAnimation.detach(); |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 13031 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13032 | mCurrentAnimation = null; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 13033 | invalidateParentIfNeeded(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13034 | } |
| 13035 | |
| 13036 | /** |
| 13037 | * Sets the next animation to play for this view. |
| 13038 | * If you want the animation to play immediately, use |
| 13039 | * startAnimation. This method provides allows fine-grained |
| 13040 | * control over the start time and invalidation, but you |
| 13041 | * must make sure that 1) the animation has a start time set, and |
| 13042 | * 2) the view will be invalidated when the animation is supposed to |
| 13043 | * start. |
| 13044 | * |
| 13045 | * @param animation The next animation, or null. |
| 13046 | */ |
| 13047 | public void setAnimation(Animation animation) { |
| 13048 | mCurrentAnimation = animation; |
| 13049 | if (animation != null) { |
| 13050 | animation.reset(); |
| 13051 | } |
| 13052 | } |
| 13053 | |
| 13054 | /** |
| 13055 | * Invoked by a parent ViewGroup to notify the start of the animation |
| 13056 | * currently associated with this view. If you override this method, |
| 13057 | * always call super.onAnimationStart(); |
| 13058 | * |
| 13059 | * @see #setAnimation(android.view.animation.Animation) |
| 13060 | * @see #getAnimation() |
| 13061 | */ |
| 13062 | protected void onAnimationStart() { |
| 13063 | mPrivateFlags |= ANIMATION_STARTED; |
| 13064 | } |
| 13065 | |
| 13066 | /** |
| 13067 | * Invoked by a parent ViewGroup to notify the end of the animation |
| 13068 | * currently associated with this view. If you override this method, |
| 13069 | * always call super.onAnimationEnd(); |
| 13070 | * |
| 13071 | * @see #setAnimation(android.view.animation.Animation) |
| 13072 | * @see #getAnimation() |
| 13073 | */ |
| 13074 | protected void onAnimationEnd() { |
| 13075 | mPrivateFlags &= ~ANIMATION_STARTED; |
| 13076 | } |
| 13077 | |
| 13078 | /** |
| 13079 | * Invoked if there is a Transform that involves alpha. Subclass that can |
| 13080 | * draw themselves with the specified alpha should return true, and then |
| 13081 | * respect that alpha when their onDraw() is called. If this returns false |
| 13082 | * then the view may be redirected to draw into an offscreen buffer to |
| 13083 | * fulfill the request, which will look fine, but may be slower than if the |
| 13084 | * subclass handles it internally. The default implementation returns false. |
| 13085 | * |
| 13086 | * @param alpha The alpha (0..255) to apply to the view's drawing |
| 13087 | * @return true if the view can draw with the specified alpha. |
| 13088 | */ |
| 13089 | protected boolean onSetAlpha(int alpha) { |
| 13090 | return false; |
| 13091 | } |
| 13092 | |
| 13093 | /** |
| 13094 | * This is used by the RootView to perform an optimization when |
| 13095 | * the view hierarchy contains one or several SurfaceView. |
| 13096 | * SurfaceView is always considered transparent, but its children are not, |
| 13097 | * therefore all View objects remove themselves from the global transparent |
| 13098 | * region (passed as a parameter to this function). |
| 13099 | * |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 13100 | * @param region The transparent region for this ViewAncestor (window). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13101 | * |
| 13102 | * @return Returns true if the effective visibility of the view at this |
| 13103 | * point is opaque, regardless of the transparent region; returns false |
| 13104 | * if it is possible for underlying windows to be seen behind the view. |
| 13105 | * |
| 13106 | * {@hide} |
| 13107 | */ |
| 13108 | public boolean gatherTransparentRegion(Region region) { |
| 13109 | final AttachInfo attachInfo = mAttachInfo; |
| 13110 | if (region != null && attachInfo != null) { |
| 13111 | final int pflags = mPrivateFlags; |
| 13112 | if ((pflags & SKIP_DRAW) == 0) { |
| 13113 | // The SKIP_DRAW flag IS NOT set, so this view draws. We need to |
| 13114 | // remove it from the transparent region. |
| 13115 | final int[] location = attachInfo.mTransparentLocation; |
| 13116 | getLocationInWindow(location); |
| 13117 | region.op(location[0], location[1], location[0] + mRight - mLeft, |
| 13118 | location[1] + mBottom - mTop, Region.Op.DIFFERENCE); |
| 13119 | } else if ((pflags & ONLY_DRAWS_BACKGROUND) != 0 && mBGDrawable != null) { |
| 13120 | // The ONLY_DRAWS_BACKGROUND flag IS set and the background drawable |
| 13121 | // exists, so we remove the background drawable's non-transparent |
| 13122 | // parts from this transparent region. |
| 13123 | applyDrawableToTransparentRegion(mBGDrawable, region); |
| 13124 | } |
| 13125 | } |
| 13126 | return true; |
| 13127 | } |
| 13128 | |
| 13129 | /** |
| 13130 | * Play a sound effect for this view. |
| 13131 | * |
| 13132 | * <p>The framework will play sound effects for some built in actions, such as |
| 13133 | * clicking, but you may wish to play these effects in your widget, |
| 13134 | * for instance, for internal navigation. |
| 13135 | * |
| 13136 | * <p>The sound effect will only be played if sound effects are enabled by the user, and |
| 13137 | * {@link #isSoundEffectsEnabled()} is true. |
| 13138 | * |
| 13139 | * @param soundConstant One of the constants defined in {@link SoundEffectConstants} |
| 13140 | */ |
| 13141 | public void playSoundEffect(int soundConstant) { |
| 13142 | if (mAttachInfo == null || mAttachInfo.mRootCallbacks == null || !isSoundEffectsEnabled()) { |
| 13143 | return; |
| 13144 | } |
| 13145 | mAttachInfo.mRootCallbacks.playSoundEffect(soundConstant); |
| 13146 | } |
| 13147 | |
| 13148 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 13149 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13150 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 13151 | * <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] | 13152 | * |
| 13153 | * <p>The framework will provide haptic feedback for some built in actions, |
| 13154 | * such as long presses, but you may wish to provide feedback for your |
| 13155 | * own widget. |
| 13156 | * |
| 13157 | * <p>The feedback will only be performed if |
| 13158 | * {@link #isHapticFeedbackEnabled()} is true. |
| 13159 | * |
| 13160 | * @param feedbackConstant One of the constants defined in |
| 13161 | * {@link HapticFeedbackConstants} |
| 13162 | */ |
| 13163 | public boolean performHapticFeedback(int feedbackConstant) { |
| 13164 | return performHapticFeedback(feedbackConstant, 0); |
| 13165 | } |
| 13166 | |
| 13167 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 13168 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13169 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 13170 | * <p>Like {@link #performHapticFeedback(int)}, with additional options. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13171 | * |
| 13172 | * @param feedbackConstant One of the constants defined in |
| 13173 | * {@link HapticFeedbackConstants} |
| 13174 | * @param flags Additional flags as per {@link HapticFeedbackConstants}. |
| 13175 | */ |
| 13176 | public boolean performHapticFeedback(int feedbackConstant, int flags) { |
| 13177 | if (mAttachInfo == null) { |
| 13178 | return false; |
| 13179 | } |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 13180 | //noinspection SimplifiableIfStatement |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 13181 | if ((flags & HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING) == 0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13182 | && !isHapticFeedbackEnabled()) { |
| 13183 | return false; |
| 13184 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 13185 | return mAttachInfo.mRootCallbacks.performHapticFeedback(feedbackConstant, |
| 13186 | (flags & HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13187 | } |
| 13188 | |
| 13189 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13190 | * Request that the visibility of the status bar be changed. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 13191 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or |
| 13192 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13193 | */ |
| 13194 | public void setSystemUiVisibility(int visibility) { |
Daniel Sandler | 7052406 | 2011-09-21 00:30:47 -0400 | [diff] [blame] | 13195 | if (visibility != mSystemUiVisibility) { |
| 13196 | mSystemUiVisibility = visibility; |
| 13197 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 13198 | mParent.recomputeViewAttributes(this); |
| 13199 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13200 | } |
| 13201 | } |
| 13202 | |
| 13203 | /** |
| 13204 | * Returns the status bar visibility that this view has requested. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 13205 | * @return Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or |
| 13206 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13207 | */ |
Joe Onorato | e595cad | 2011-01-24 09:22:12 -0800 | [diff] [blame] | 13208 | public int getSystemUiVisibility() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13209 | return mSystemUiVisibility; |
| 13210 | } |
| 13211 | |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 13212 | /** |
| 13213 | * Set a listener to receive callbacks when the visibility of the system bar changes. |
| 13214 | * @param l The {@link OnSystemUiVisibilityChangeListener} to receive callbacks. |
| 13215 | */ |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13216 | public void setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 13217 | getListenerInfo().mOnSystemUiVisibilityChangeListener = l; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13218 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 13219 | mParent.recomputeViewAttributes(this); |
| 13220 | } |
| 13221 | } |
| 13222 | |
| 13223 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 13224 | * Dispatch callbacks to {@link #setOnSystemUiVisibilityChangeListener} down |
| 13225 | * the view hierarchy. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13226 | */ |
| 13227 | public void dispatchSystemUiVisibilityChanged(int visibility) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 13228 | ListenerInfo li = mListenerInfo; |
| 13229 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
| 13230 | li.mOnSystemUiVisibilityChangeListener.onSystemUiVisibilityChange( |
Joe Onorato | 6ab77bd | 2011-01-31 11:21:10 -0800 | [diff] [blame] | 13231 | visibility & PUBLIC_STATUS_BAR_VISIBILITY_MASK); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13232 | } |
| 13233 | } |
| 13234 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 13235 | void updateLocalSystemUiVisibility(int localValue, int localChanges) { |
| 13236 | int val = (mSystemUiVisibility&~localChanges) | (localValue&localChanges); |
| 13237 | if (val != mSystemUiVisibility) { |
| 13238 | setSystemUiVisibility(val); |
| 13239 | } |
| 13240 | } |
| 13241 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 13242 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13243 | * Creates an image that the system displays during the drag and drop |
| 13244 | * operation. This is called a "drag shadow". The default implementation |
| 13245 | * for a DragShadowBuilder based on a View returns an image that has exactly the same |
| 13246 | * appearance as the given View. The default also positions the center of the drag shadow |
| 13247 | * directly under the touch point. If no View is provided (the constructor with no parameters |
| 13248 | * is used), and {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} and |
| 13249 | * {@link #onDrawShadow(Canvas) onDrawShadow()} are not overriden, then the |
| 13250 | * default is an invisible drag shadow. |
| 13251 | * <p> |
| 13252 | * You are not required to use the View you provide to the constructor as the basis of the |
| 13253 | * drag shadow. The {@link #onDrawShadow(Canvas) onDrawShadow()} method allows you to draw |
| 13254 | * anything you want as the drag shadow. |
| 13255 | * </p> |
| 13256 | * <p> |
| 13257 | * You pass a DragShadowBuilder object to the system when you start the drag. The system |
| 13258 | * calls {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} to get the |
| 13259 | * size and position of the drag shadow. It uses this data to construct a |
| 13260 | * {@link android.graphics.Canvas} object, then it calls {@link #onDrawShadow(Canvas) onDrawShadow()} |
| 13261 | * so that your application can draw the shadow image in the Canvas. |
| 13262 | * </p> |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 13263 | * |
| 13264 | * <div class="special reference"> |
| 13265 | * <h3>Developer Guides</h3> |
| 13266 | * <p>For a guide to implementing drag and drop features, read the |
| 13267 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 13268 | * </div> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13269 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13270 | public static class DragShadowBuilder { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 13271 | private final WeakReference<View> mView; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13272 | |
| 13273 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13274 | * Constructs a shadow image builder based on a View. By default, the resulting drag |
| 13275 | * shadow will have the same appearance and dimensions as the View, with the touch point |
| 13276 | * over the center of the View. |
| 13277 | * @param view A View. Any View in scope can be used. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13278 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13279 | public DragShadowBuilder(View view) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 13280 | mView = new WeakReference<View>(view); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13281 | } |
| 13282 | |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 13283 | /** |
| 13284 | * Construct a shadow builder object with no associated View. This |
| 13285 | * constructor variant is only useful when the {@link #onProvideShadowMetrics(Point, Point)} |
| 13286 | * and {@link #onDrawShadow(Canvas)} methods are also overridden in order |
| 13287 | * to supply the drag shadow's dimensions and appearance without |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13288 | * reference to any View object. If they are not overridden, then the result is an |
| 13289 | * invisible drag shadow. |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 13290 | */ |
| 13291 | public DragShadowBuilder() { |
| 13292 | mView = new WeakReference<View>(null); |
| 13293 | } |
| 13294 | |
| 13295 | /** |
| 13296 | * Returns the View object that had been passed to the |
| 13297 | * {@link #View.DragShadowBuilder(View)} |
| 13298 | * constructor. If that View parameter was {@code null} or if the |
| 13299 | * {@link #View.DragShadowBuilder()} |
| 13300 | * constructor was used to instantiate the builder object, this method will return |
| 13301 | * null. |
| 13302 | * |
| 13303 | * @return The View object associate with this builder object. |
| 13304 | */ |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 13305 | @SuppressWarnings({"JavadocReference"}) |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 13306 | final public View getView() { |
| 13307 | return mView.get(); |
| 13308 | } |
| 13309 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13310 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13311 | * Provides the metrics for the shadow image. These include the dimensions of |
| 13312 | * the shadow image, and the point within that shadow that should |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13313 | * be centered under the touch location while dragging. |
| 13314 | * <p> |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13315 | * The default implementation sets the dimensions of the shadow to be the |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13316 | * same as the dimensions of the View itself and centers the shadow under |
| 13317 | * the touch point. |
| 13318 | * </p> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13319 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13320 | * @param shadowSize A {@link android.graphics.Point} containing the width and height |
| 13321 | * of the shadow image. Your application must set {@link android.graphics.Point#x} to the |
| 13322 | * desired width and must set {@link android.graphics.Point#y} to the desired height of the |
| 13323 | * image. |
| 13324 | * |
| 13325 | * @param shadowTouchPoint A {@link android.graphics.Point} for the position within the |
| 13326 | * shadow image that should be underneath the touch point during the drag and drop |
| 13327 | * operation. Your application must set {@link android.graphics.Point#x} to the |
| 13328 | * 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] | 13329 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13330 | public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 13331 | final View view = mView.get(); |
| 13332 | if (view != null) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13333 | shadowSize.set(view.getWidth(), view.getHeight()); |
| 13334 | shadowTouchPoint.set(shadowSize.x / 2, shadowSize.y / 2); |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 13335 | } else { |
| 13336 | Log.e(View.VIEW_LOG_TAG, "Asked for drag thumb metrics but no view"); |
| 13337 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13338 | } |
| 13339 | |
| 13340 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13341 | * Draws the shadow image. The system creates the {@link android.graphics.Canvas} object |
| 13342 | * based on the dimensions it received from the |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13343 | * {@link #onProvideShadowMetrics(Point, Point)} callback. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13344 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13345 | * @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] | 13346 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13347 | public void onDrawShadow(Canvas canvas) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 13348 | final View view = mView.get(); |
| 13349 | if (view != null) { |
| 13350 | view.draw(canvas); |
| 13351 | } else { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13352 | 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] | 13353 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13354 | } |
| 13355 | } |
| 13356 | |
| 13357 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13358 | * Starts a drag and drop operation. When your application calls this method, it passes a |
| 13359 | * {@link android.view.View.DragShadowBuilder} object to the system. The |
| 13360 | * system calls this object's {@link DragShadowBuilder#onProvideShadowMetrics(Point, Point)} |
| 13361 | * to get metrics for the drag shadow, and then calls the object's |
| 13362 | * {@link DragShadowBuilder#onDrawShadow(Canvas)} to draw the drag shadow itself. |
| 13363 | * <p> |
| 13364 | * Once the system has the drag shadow, it begins the drag and drop operation by sending |
| 13365 | * drag events to all the View objects in your application that are currently visible. It does |
| 13366 | * this either by calling the View object's drag listener (an implementation of |
| 13367 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent) onDrag()} or by calling the |
| 13368 | * View object's {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} method. |
| 13369 | * Both are passed a {@link android.view.DragEvent} object that has a |
| 13370 | * {@link android.view.DragEvent#getAction()} value of |
| 13371 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED}. |
| 13372 | * </p> |
| 13373 | * <p> |
| 13374 | * Your application can invoke startDrag() on any attached View object. The View object does not |
| 13375 | * need to be the one used in {@link android.view.View.DragShadowBuilder}, nor does it need to |
| 13376 | * be related to the View the user selected for dragging. |
| 13377 | * </p> |
| 13378 | * @param data A {@link android.content.ClipData} object pointing to the data to be |
| 13379 | * transferred by the drag and drop operation. |
| 13380 | * @param shadowBuilder A {@link android.view.View.DragShadowBuilder} object for building the |
| 13381 | * drag shadow. |
| 13382 | * @param myLocalState An {@link java.lang.Object} containing local data about the drag and |
| 13383 | * drop operation. This Object is put into every DragEvent object sent by the system during the |
| 13384 | * current drag. |
| 13385 | * <p> |
| 13386 | * myLocalState is a lightweight mechanism for the sending information from the dragged View |
| 13387 | * to the target Views. For example, it can contain flags that differentiate between a |
| 13388 | * a copy operation and a move operation. |
| 13389 | * </p> |
| 13390 | * @param flags Flags that control the drag and drop operation. No flags are currently defined, |
| 13391 | * so the parameter should be set to 0. |
| 13392 | * @return {@code true} if the method completes successfully, or |
| 13393 | * {@code false} if it fails anywhere. Returning {@code false} means the system was unable to |
| 13394 | * do a drag, and so no drag operation is in progress. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13395 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13396 | public final boolean startDrag(ClipData data, DragShadowBuilder shadowBuilder, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 13397 | Object myLocalState, int flags) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13398 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 13399 | Log.d(VIEW_LOG_TAG, "startDrag: data=" + data + " flags=" + flags); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13400 | } |
| 13401 | boolean okay = false; |
| 13402 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13403 | Point shadowSize = new Point(); |
| 13404 | Point shadowTouchPoint = new Point(); |
| 13405 | shadowBuilder.onProvideShadowMetrics(shadowSize, shadowTouchPoint); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13406 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13407 | if ((shadowSize.x < 0) || (shadowSize.y < 0) || |
| 13408 | (shadowTouchPoint.x < 0) || (shadowTouchPoint.y < 0)) { |
| 13409 | throw new IllegalStateException("Drag shadow dimensions must not be negative"); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13410 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13411 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 13412 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13413 | Log.d(VIEW_LOG_TAG, "drag shadow: width=" + shadowSize.x + " height=" + shadowSize.y |
| 13414 | + " shadowX=" + shadowTouchPoint.x + " shadowY=" + shadowTouchPoint.y); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 13415 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13416 | Surface surface = new Surface(); |
| 13417 | try { |
| 13418 | IBinder token = mAttachInfo.mSession.prepareDrag(mAttachInfo.mWindow, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 13419 | flags, shadowSize.x, shadowSize.y, surface); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13420 | 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] | 13421 | + " surface=" + surface); |
| 13422 | if (token != null) { |
| 13423 | Canvas canvas = surface.lockCanvas(null); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 13424 | try { |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 13425 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13426 | shadowBuilder.onDrawShadow(canvas); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 13427 | } finally { |
| 13428 | surface.unlockCanvasAndPost(canvas); |
| 13429 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13430 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 13431 | final ViewRootImpl root = getViewRootImpl(); |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 13432 | |
| 13433 | // Cache the local state object for delivery with DragEvents |
| 13434 | root.setLocalDragState(myLocalState); |
| 13435 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13436 | // repurpose 'shadowSize' for the last touch point |
| 13437 | root.getLastTouchPoint(shadowSize); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13438 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13439 | okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, token, |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 13440 | shadowSize.x, shadowSize.y, |
| 13441 | shadowTouchPoint.x, shadowTouchPoint.y, data); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 13442 | if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "performDrag returned " + okay); |
Christopher Tate | 8f73b5d | 2011-09-12 15:22:12 -0700 | [diff] [blame] | 13443 | |
| 13444 | // Off and running! Release our local surface instance; the drag |
| 13445 | // shadow surface is now managed by the system process. |
| 13446 | surface.release(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13447 | } |
| 13448 | } catch (Exception e) { |
| 13449 | Log.e(VIEW_LOG_TAG, "Unable to initiate drag", e); |
| 13450 | surface.destroy(); |
| 13451 | } |
| 13452 | |
| 13453 | return okay; |
| 13454 | } |
| 13455 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13456 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13457 | * Handles drag events sent by the system following a call to |
| 13458 | * {@link android.view.View#startDrag(ClipData,DragShadowBuilder,Object,int) startDrag()}. |
| 13459 | *<p> |
| 13460 | * When the system calls this method, it passes a |
| 13461 | * {@link android.view.DragEvent} object. A call to |
| 13462 | * {@link android.view.DragEvent#getAction()} returns one of the action type constants defined |
| 13463 | * in DragEvent. The method uses these to determine what is happening in the drag and drop |
| 13464 | * operation. |
| 13465 | * @param event The {@link android.view.DragEvent} sent by the system. |
| 13466 | * The {@link android.view.DragEvent#getAction()} method returns an action type constant defined |
| 13467 | * in DragEvent, indicating the type of drag event represented by this object. |
| 13468 | * @return {@code true} if the method was successful, otherwise {@code false}. |
| 13469 | * <p> |
| 13470 | * The method should return {@code true} in response to an action type of |
| 13471 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED} to receive drag events for the current |
| 13472 | * operation. |
| 13473 | * </p> |
| 13474 | * <p> |
| 13475 | * The method should also return {@code true} in response to an action type of |
| 13476 | * {@link android.view.DragEvent#ACTION_DROP} if it consumed the drop, or |
| 13477 | * {@code false} if it didn't. |
| 13478 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13479 | */ |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 13480 | public boolean onDragEvent(DragEvent event) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13481 | return false; |
| 13482 | } |
| 13483 | |
| 13484 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13485 | * Detects if this View is enabled and has a drag event listener. |
| 13486 | * If both are true, then it calls the drag event listener with the |
| 13487 | * {@link android.view.DragEvent} it received. If the drag event listener returns |
| 13488 | * {@code true}, then dispatchDragEvent() returns {@code true}. |
| 13489 | * <p> |
| 13490 | * For all other cases, the method calls the |
| 13491 | * {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} drag event handler |
| 13492 | * method and returns its result. |
| 13493 | * </p> |
| 13494 | * <p> |
| 13495 | * This ensures that a drag event is always consumed, even if the View does not have a drag |
| 13496 | * event listener. However, if the View has a listener and the listener returns true, then |
| 13497 | * onDragEvent() is not called. |
| 13498 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13499 | */ |
| 13500 | public boolean dispatchDragEvent(DragEvent event) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 13501 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 13502 | ListenerInfo li = mListenerInfo; |
| 13503 | if (li != null && li.mOnDragListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 13504 | && li.mOnDragListener.onDrag(this, event)) { |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 13505 | return true; |
| 13506 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13507 | return onDragEvent(event); |
| 13508 | } |
| 13509 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 13510 | boolean canAcceptDrag() { |
| 13511 | return (mPrivateFlags2 & DRAG_CAN_ACCEPT) != 0; |
| 13512 | } |
| 13513 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 13514 | /** |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 13515 | * This needs to be a better API (NOT ON VIEW) before it is exposed. If |
| 13516 | * it is ever exposed at all. |
Dianne Hackborn | 29e4a3c | 2009-09-30 22:35:40 -0700 | [diff] [blame] | 13517 | * @hide |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 13518 | */ |
| 13519 | public void onCloseSystemDialogs(String reason) { |
| 13520 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13521 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 13522 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13523 | * 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] | 13524 | * update a Region being computed for |
| 13525 | * {@link #gatherTransparentRegion(android.graphics.Region)} so |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13526 | * that any non-transparent parts of the Drawable are removed from the |
| 13527 | * given transparent region. |
| 13528 | * |
| 13529 | * @param dr The Drawable whose transparency is to be applied to the region. |
| 13530 | * @param region A Region holding the current transparency information, |
| 13531 | * where any parts of the region that are set are considered to be |
| 13532 | * transparent. On return, this region will be modified to have the |
| 13533 | * transparency information reduced by the corresponding parts of the |
| 13534 | * Drawable that are not transparent. |
| 13535 | * {@hide} |
| 13536 | */ |
| 13537 | public void applyDrawableToTransparentRegion(Drawable dr, Region region) { |
| 13538 | if (DBG) { |
| 13539 | Log.i("View", "Getting transparent region for: " + this); |
| 13540 | } |
| 13541 | final Region r = dr.getTransparentRegion(); |
| 13542 | final Rect db = dr.getBounds(); |
| 13543 | final AttachInfo attachInfo = mAttachInfo; |
| 13544 | if (r != null && attachInfo != null) { |
| 13545 | final int w = getRight()-getLeft(); |
| 13546 | final int h = getBottom()-getTop(); |
| 13547 | if (db.left > 0) { |
| 13548 | //Log.i("VIEW", "Drawable left " + db.left + " > view 0"); |
| 13549 | r.op(0, 0, db.left, h, Region.Op.UNION); |
| 13550 | } |
| 13551 | if (db.right < w) { |
| 13552 | //Log.i("VIEW", "Drawable right " + db.right + " < view " + w); |
| 13553 | r.op(db.right, 0, w, h, Region.Op.UNION); |
| 13554 | } |
| 13555 | if (db.top > 0) { |
| 13556 | //Log.i("VIEW", "Drawable top " + db.top + " > view 0"); |
| 13557 | r.op(0, 0, w, db.top, Region.Op.UNION); |
| 13558 | } |
| 13559 | if (db.bottom < h) { |
| 13560 | //Log.i("VIEW", "Drawable bottom " + db.bottom + " < view " + h); |
| 13561 | r.op(0, db.bottom, w, h, Region.Op.UNION); |
| 13562 | } |
| 13563 | final int[] location = attachInfo.mTransparentLocation; |
| 13564 | getLocationInWindow(location); |
| 13565 | r.translate(location[0], location[1]); |
| 13566 | region.op(r, Region.Op.INTERSECT); |
| 13567 | } else { |
| 13568 | region.op(db, Region.Op.DIFFERENCE); |
| 13569 | } |
| 13570 | } |
| 13571 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 13572 | private void checkForLongClick(int delayOffset) { |
| 13573 | if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) { |
| 13574 | mHasPerformedLongPress = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13575 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 13576 | if (mPendingCheckForLongPress == null) { |
| 13577 | mPendingCheckForLongPress = new CheckForLongPress(); |
| 13578 | } |
| 13579 | mPendingCheckForLongPress.rememberWindowAttachCount(); |
| 13580 | postDelayed(mPendingCheckForLongPress, |
| 13581 | ViewConfiguration.getLongPressTimeout() - delayOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13582 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13583 | } |
| 13584 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13585 | /** |
| 13586 | * Inflate a view from an XML resource. This convenience method wraps the {@link |
| 13587 | * LayoutInflater} class, which provides a full range of options for view inflation. |
| 13588 | * |
| 13589 | * @param context The Context object for your activity or application. |
| 13590 | * @param resource The resource ID to inflate |
| 13591 | * @param root A view group that will be the parent. Used to properly inflate the |
| 13592 | * layout_* parameters. |
| 13593 | * @see LayoutInflater |
| 13594 | */ |
| 13595 | public static View inflate(Context context, int resource, ViewGroup root) { |
| 13596 | LayoutInflater factory = LayoutInflater.from(context); |
| 13597 | return factory.inflate(resource, root); |
| 13598 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 13599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13600 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 13601 | * Scroll the view with standard behavior for scrolling beyond the normal |
| 13602 | * content boundaries. Views that call this method should override |
| 13603 | * {@link #onOverScrolled(int, int, boolean, boolean)} to respond to the |
| 13604 | * results of an over-scroll operation. |
| 13605 | * |
| 13606 | * Views can use this method to handle any touch or fling-based scrolling. |
| 13607 | * |
| 13608 | * @param deltaX Change in X in pixels |
| 13609 | * @param deltaY Change in Y in pixels |
| 13610 | * @param scrollX Current X scroll value in pixels before applying deltaX |
| 13611 | * @param scrollY Current Y scroll value in pixels before applying deltaY |
| 13612 | * @param scrollRangeX Maximum content scroll range along the X axis |
| 13613 | * @param scrollRangeY Maximum content scroll range along the Y axis |
| 13614 | * @param maxOverScrollX Number of pixels to overscroll by in either direction |
| 13615 | * along the X axis. |
| 13616 | * @param maxOverScrollY Number of pixels to overscroll by in either direction |
| 13617 | * along the Y axis. |
| 13618 | * @param isTouchEvent true if this scroll operation is the result of a touch event. |
| 13619 | * @return true if scrolling was clamped to an over-scroll boundary along either |
| 13620 | * axis, false otherwise. |
| 13621 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13622 | @SuppressWarnings({"UnusedParameters"}) |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 13623 | protected boolean overScrollBy(int deltaX, int deltaY, |
| 13624 | int scrollX, int scrollY, |
| 13625 | int scrollRangeX, int scrollRangeY, |
| 13626 | int maxOverScrollX, int maxOverScrollY, |
| 13627 | boolean isTouchEvent) { |
| 13628 | final int overScrollMode = mOverScrollMode; |
| 13629 | final boolean canScrollHorizontal = |
| 13630 | computeHorizontalScrollRange() > computeHorizontalScrollExtent(); |
| 13631 | final boolean canScrollVertical = |
| 13632 | computeVerticalScrollRange() > computeVerticalScrollExtent(); |
| 13633 | final boolean overScrollHorizontal = overScrollMode == OVER_SCROLL_ALWAYS || |
| 13634 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollHorizontal); |
| 13635 | final boolean overScrollVertical = overScrollMode == OVER_SCROLL_ALWAYS || |
| 13636 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollVertical); |
| 13637 | |
| 13638 | int newScrollX = scrollX + deltaX; |
| 13639 | if (!overScrollHorizontal) { |
| 13640 | maxOverScrollX = 0; |
| 13641 | } |
| 13642 | |
| 13643 | int newScrollY = scrollY + deltaY; |
| 13644 | if (!overScrollVertical) { |
| 13645 | maxOverScrollY = 0; |
| 13646 | } |
| 13647 | |
| 13648 | // Clamp values if at the limits and record |
| 13649 | final int left = -maxOverScrollX; |
| 13650 | final int right = maxOverScrollX + scrollRangeX; |
| 13651 | final int top = -maxOverScrollY; |
| 13652 | final int bottom = maxOverScrollY + scrollRangeY; |
| 13653 | |
| 13654 | boolean clampedX = false; |
| 13655 | if (newScrollX > right) { |
| 13656 | newScrollX = right; |
| 13657 | clampedX = true; |
| 13658 | } else if (newScrollX < left) { |
| 13659 | newScrollX = left; |
| 13660 | clampedX = true; |
| 13661 | } |
| 13662 | |
| 13663 | boolean clampedY = false; |
| 13664 | if (newScrollY > bottom) { |
| 13665 | newScrollY = bottom; |
| 13666 | clampedY = true; |
| 13667 | } else if (newScrollY < top) { |
| 13668 | newScrollY = top; |
| 13669 | clampedY = true; |
| 13670 | } |
| 13671 | |
| 13672 | onOverScrolled(newScrollX, newScrollY, clampedX, clampedY); |
| 13673 | |
| 13674 | return clampedX || clampedY; |
| 13675 | } |
| 13676 | |
| 13677 | /** |
| 13678 | * Called by {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)} to |
| 13679 | * respond to the results of an over-scroll operation. |
| 13680 | * |
| 13681 | * @param scrollX New X scroll value in pixels |
| 13682 | * @param scrollY New Y scroll value in pixels |
| 13683 | * @param clampedX True if scrollX was clamped to an over-scroll boundary |
| 13684 | * @param clampedY True if scrollY was clamped to an over-scroll boundary |
| 13685 | */ |
| 13686 | protected void onOverScrolled(int scrollX, int scrollY, |
| 13687 | boolean clampedX, boolean clampedY) { |
| 13688 | // Intentionally empty. |
| 13689 | } |
| 13690 | |
| 13691 | /** |
| 13692 | * Returns the over-scroll mode for this view. The result will be |
| 13693 | * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 13694 | * (allow over-scrolling only if the view content is larger than the container), |
| 13695 | * or {@link #OVER_SCROLL_NEVER}. |
| 13696 | * |
| 13697 | * @return This view's over-scroll mode. |
| 13698 | */ |
| 13699 | public int getOverScrollMode() { |
| 13700 | return mOverScrollMode; |
| 13701 | } |
| 13702 | |
| 13703 | /** |
| 13704 | * Set the over-scroll mode for this view. Valid over-scroll modes are |
| 13705 | * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 13706 | * (allow over-scrolling only if the view content is larger than the container), |
| 13707 | * or {@link #OVER_SCROLL_NEVER}. |
| 13708 | * |
| 13709 | * Setting the over-scroll mode of a view will have an effect only if the |
| 13710 | * view is capable of scrolling. |
| 13711 | * |
| 13712 | * @param overScrollMode The new over-scroll mode for this view. |
| 13713 | */ |
| 13714 | public void setOverScrollMode(int overScrollMode) { |
| 13715 | if (overScrollMode != OVER_SCROLL_ALWAYS && |
| 13716 | overScrollMode != OVER_SCROLL_IF_CONTENT_SCROLLS && |
| 13717 | overScrollMode != OVER_SCROLL_NEVER) { |
| 13718 | throw new IllegalArgumentException("Invalid overscroll mode " + overScrollMode); |
| 13719 | } |
| 13720 | mOverScrollMode = overScrollMode; |
| 13721 | } |
| 13722 | |
| 13723 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 13724 | * Gets a scale factor that determines the distance the view should scroll |
| 13725 | * vertically in response to {@link MotionEvent#ACTION_SCROLL}. |
| 13726 | * @return The vertical scroll scale factor. |
| 13727 | * @hide |
| 13728 | */ |
| 13729 | protected float getVerticalScrollFactor() { |
| 13730 | if (mVerticalScrollFactor == 0) { |
| 13731 | TypedValue outValue = new TypedValue(); |
| 13732 | if (!mContext.getTheme().resolveAttribute( |
| 13733 | com.android.internal.R.attr.listPreferredItemHeight, outValue, true)) { |
| 13734 | throw new IllegalStateException( |
| 13735 | "Expected theme to define listPreferredItemHeight."); |
| 13736 | } |
| 13737 | mVerticalScrollFactor = outValue.getDimension( |
| 13738 | mContext.getResources().getDisplayMetrics()); |
| 13739 | } |
| 13740 | return mVerticalScrollFactor; |
| 13741 | } |
| 13742 | |
| 13743 | /** |
| 13744 | * Gets a scale factor that determines the distance the view should scroll |
| 13745 | * horizontally in response to {@link MotionEvent#ACTION_SCROLL}. |
| 13746 | * @return The horizontal scroll scale factor. |
| 13747 | * @hide |
| 13748 | */ |
| 13749 | protected float getHorizontalScrollFactor() { |
| 13750 | // TODO: Should use something else. |
| 13751 | return getVerticalScrollFactor(); |
| 13752 | } |
| 13753 | |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13754 | /** |
| 13755 | * Return the value specifying the text direction or policy that was set with |
| 13756 | * {@link #setTextDirection(int)}. |
| 13757 | * |
| 13758 | * @return the defined text direction. It can be one of: |
| 13759 | * |
| 13760 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 13761 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 13762 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 13763 | * {@link #TEXT_DIRECTION_LTR}, |
| 13764 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 4c1e00a | 2012-01-05 19:05:55 -0800 | [diff] [blame] | 13765 | * {@link #TEXT_DIRECTION_LOCALE}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13766 | * |
| 13767 | * @hide |
| 13768 | */ |
| 13769 | public int getTextDirection() { |
| 13770 | return mTextDirection; |
| 13771 | } |
| 13772 | |
| 13773 | /** |
| 13774 | * Set the text direction. |
| 13775 | * |
| 13776 | * @param textDirection the direction to set. Should be one of: |
| 13777 | * |
| 13778 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 13779 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 13780 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 13781 | * {@link #TEXT_DIRECTION_LTR}, |
| 13782 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 4c1e00a | 2012-01-05 19:05:55 -0800 | [diff] [blame] | 13783 | * {@link #TEXT_DIRECTION_LOCALE}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13784 | * |
| 13785 | * @hide |
| 13786 | */ |
| 13787 | public void setTextDirection(int textDirection) { |
| 13788 | if (textDirection != mTextDirection) { |
| 13789 | mTextDirection = textDirection; |
| 13790 | resetResolvedTextDirection(); |
| 13791 | requestLayout(); |
| 13792 | } |
| 13793 | } |
| 13794 | |
| 13795 | /** |
| 13796 | * Return the resolved text direction. |
| 13797 | * |
| 13798 | * @return the resolved text direction. Return one of: |
| 13799 | * |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13800 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 13801 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13802 | * {@link #TEXT_DIRECTION_LTR}, |
| 13803 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 4c1e00a | 2012-01-05 19:05:55 -0800 | [diff] [blame] | 13804 | * {@link #TEXT_DIRECTION_LOCALE}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13805 | * |
| 13806 | * @hide |
| 13807 | */ |
| 13808 | public int getResolvedTextDirection() { |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13809 | if (mResolvedTextDirection == TEXT_DIRECTION_INHERIT) { |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13810 | resolveTextDirection(); |
| 13811 | } |
| 13812 | return mResolvedTextDirection; |
| 13813 | } |
| 13814 | |
| 13815 | /** |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13816 | * Resolve the text direction. |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 13817 | * |
| 13818 | * @hide |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13819 | */ |
| 13820 | protected void resolveTextDirection() { |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13821 | if (mTextDirection != TEXT_DIRECTION_INHERIT) { |
| 13822 | mResolvedTextDirection = mTextDirection; |
| 13823 | return; |
| 13824 | } |
| 13825 | if (mParent != null && mParent instanceof ViewGroup) { |
| 13826 | mResolvedTextDirection = ((ViewGroup) mParent).getResolvedTextDirection(); |
| 13827 | return; |
| 13828 | } |
| 13829 | mResolvedTextDirection = TEXT_DIRECTION_FIRST_STRONG; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13830 | } |
| 13831 | |
| 13832 | /** |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13833 | * 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] | 13834 | * |
| 13835 | * @hide |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13836 | */ |
| 13837 | protected void resetResolvedTextDirection() { |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 13838 | mResolvedTextDirection = TEXT_DIRECTION_INHERIT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 13839 | } |
| 13840 | |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13841 | // |
| 13842 | // Properties |
| 13843 | // |
| 13844 | /** |
| 13845 | * A Property wrapper around the <code>alpha</code> functionality handled by the |
| 13846 | * {@link View#setAlpha(float)} and {@link View#getAlpha()} methods. |
| 13847 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13848 | public static final Property<View, Float> ALPHA = new FloatProperty<View>("alpha") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13849 | @Override |
| 13850 | public void setValue(View object, float value) { |
| 13851 | object.setAlpha(value); |
| 13852 | } |
| 13853 | |
| 13854 | @Override |
| 13855 | public Float get(View object) { |
| 13856 | return object.getAlpha(); |
| 13857 | } |
| 13858 | }; |
| 13859 | |
| 13860 | /** |
| 13861 | * A Property wrapper around the <code>translationX</code> functionality handled by the |
| 13862 | * {@link View#setTranslationX(float)} and {@link View#getTranslationX()} methods. |
| 13863 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13864 | public static final Property<View, Float> TRANSLATION_X = new FloatProperty<View>("translationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13865 | @Override |
| 13866 | public void setValue(View object, float value) { |
| 13867 | object.setTranslationX(value); |
| 13868 | } |
| 13869 | |
| 13870 | @Override |
| 13871 | public Float get(View object) { |
| 13872 | return object.getTranslationX(); |
| 13873 | } |
| 13874 | }; |
| 13875 | |
| 13876 | /** |
| 13877 | * A Property wrapper around the <code>translationY</code> functionality handled by the |
| 13878 | * {@link View#setTranslationY(float)} and {@link View#getTranslationY()} methods. |
| 13879 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13880 | public static final Property<View, Float> TRANSLATION_Y = new FloatProperty<View>("translationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13881 | @Override |
| 13882 | public void setValue(View object, float value) { |
| 13883 | object.setTranslationY(value); |
| 13884 | } |
| 13885 | |
| 13886 | @Override |
| 13887 | public Float get(View object) { |
| 13888 | return object.getTranslationY(); |
| 13889 | } |
| 13890 | }; |
| 13891 | |
| 13892 | /** |
| 13893 | * A Property wrapper around the <code>x</code> functionality handled by the |
| 13894 | * {@link View#setX(float)} and {@link View#getX()} methods. |
| 13895 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13896 | public static final Property<View, Float> X = new FloatProperty<View>("x") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13897 | @Override |
| 13898 | public void setValue(View object, float value) { |
| 13899 | object.setX(value); |
| 13900 | } |
| 13901 | |
| 13902 | @Override |
| 13903 | public Float get(View object) { |
| 13904 | return object.getX(); |
| 13905 | } |
| 13906 | }; |
| 13907 | |
| 13908 | /** |
| 13909 | * A Property wrapper around the <code>y</code> functionality handled by the |
| 13910 | * {@link View#setY(float)} and {@link View#getY()} methods. |
| 13911 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13912 | public static final Property<View, Float> Y = new FloatProperty<View>("y") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13913 | @Override |
| 13914 | public void setValue(View object, float value) { |
| 13915 | object.setY(value); |
| 13916 | } |
| 13917 | |
| 13918 | @Override |
| 13919 | public Float get(View object) { |
| 13920 | return object.getY(); |
| 13921 | } |
| 13922 | }; |
| 13923 | |
| 13924 | /** |
| 13925 | * A Property wrapper around the <code>rotation</code> functionality handled by the |
| 13926 | * {@link View#setRotation(float)} and {@link View#getRotation()} methods. |
| 13927 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13928 | public static final Property<View, Float> ROTATION = new FloatProperty<View>("rotation") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13929 | @Override |
| 13930 | public void setValue(View object, float value) { |
| 13931 | object.setRotation(value); |
| 13932 | } |
| 13933 | |
| 13934 | @Override |
| 13935 | public Float get(View object) { |
| 13936 | return object.getRotation(); |
| 13937 | } |
| 13938 | }; |
| 13939 | |
| 13940 | /** |
| 13941 | * A Property wrapper around the <code>rotationX</code> functionality handled by the |
| 13942 | * {@link View#setRotationX(float)} and {@link View#getRotationX()} methods. |
| 13943 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13944 | public static final Property<View, Float> ROTATION_X = new FloatProperty<View>("rotationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13945 | @Override |
| 13946 | public void setValue(View object, float value) { |
| 13947 | object.setRotationX(value); |
| 13948 | } |
| 13949 | |
| 13950 | @Override |
| 13951 | public Float get(View object) { |
| 13952 | return object.getRotationX(); |
| 13953 | } |
| 13954 | }; |
| 13955 | |
| 13956 | /** |
| 13957 | * A Property wrapper around the <code>rotationY</code> functionality handled by the |
| 13958 | * {@link View#setRotationY(float)} and {@link View#getRotationY()} methods. |
| 13959 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13960 | public static final Property<View, Float> ROTATION_Y = new FloatProperty<View>("rotationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13961 | @Override |
| 13962 | public void setValue(View object, float value) { |
| 13963 | object.setRotationY(value); |
| 13964 | } |
| 13965 | |
| 13966 | @Override |
| 13967 | public Float get(View object) { |
| 13968 | return object.getRotationY(); |
| 13969 | } |
| 13970 | }; |
| 13971 | |
| 13972 | /** |
| 13973 | * A Property wrapper around the <code>scaleX</code> functionality handled by the |
| 13974 | * {@link View#setScaleX(float)} and {@link View#getScaleX()} methods. |
| 13975 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13976 | public static final Property<View, Float> SCALE_X = new FloatProperty<View>("scaleX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13977 | @Override |
| 13978 | public void setValue(View object, float value) { |
| 13979 | object.setScaleX(value); |
| 13980 | } |
| 13981 | |
| 13982 | @Override |
| 13983 | public Float get(View object) { |
| 13984 | return object.getScaleX(); |
| 13985 | } |
| 13986 | }; |
| 13987 | |
| 13988 | /** |
| 13989 | * A Property wrapper around the <code>scaleY</code> functionality handled by the |
| 13990 | * {@link View#setScaleY(float)} and {@link View#getScaleY()} methods. |
| 13991 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 13992 | public static final Property<View, Float> SCALE_Y = new FloatProperty<View>("scaleY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 13993 | @Override |
| 13994 | public void setValue(View object, float value) { |
| 13995 | object.setScaleY(value); |
| 13996 | } |
| 13997 | |
| 13998 | @Override |
| 13999 | public Float get(View object) { |
| 14000 | return object.getScaleY(); |
| 14001 | } |
| 14002 | }; |
| 14003 | |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 14004 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14005 | * A MeasureSpec encapsulates the layout requirements passed from parent to child. |
| 14006 | * Each MeasureSpec represents a requirement for either the width or the height. |
| 14007 | * A MeasureSpec is comprised of a size and a mode. There are three possible |
| 14008 | * modes: |
| 14009 | * <dl> |
| 14010 | * <dt>UNSPECIFIED</dt> |
| 14011 | * <dd> |
| 14012 | * The parent has not imposed any constraint on the child. It can be whatever size |
| 14013 | * it wants. |
| 14014 | * </dd> |
| 14015 | * |
| 14016 | * <dt>EXACTLY</dt> |
| 14017 | * <dd> |
| 14018 | * The parent has determined an exact size for the child. The child is going to be |
| 14019 | * given those bounds regardless of how big it wants to be. |
| 14020 | * </dd> |
| 14021 | * |
| 14022 | * <dt>AT_MOST</dt> |
| 14023 | * <dd> |
| 14024 | * The child can be as large as it wants up to the specified size. |
| 14025 | * </dd> |
| 14026 | * </dl> |
| 14027 | * |
| 14028 | * MeasureSpecs are implemented as ints to reduce object allocation. This class |
| 14029 | * is provided to pack and unpack the <size, mode> tuple into the int. |
| 14030 | */ |
| 14031 | public static class MeasureSpec { |
| 14032 | private static final int MODE_SHIFT = 30; |
| 14033 | private static final int MODE_MASK = 0x3 << MODE_SHIFT; |
| 14034 | |
| 14035 | /** |
| 14036 | * Measure specification mode: The parent has not imposed any constraint |
| 14037 | * on the child. It can be whatever size it wants. |
| 14038 | */ |
| 14039 | public static final int UNSPECIFIED = 0 << MODE_SHIFT; |
| 14040 | |
| 14041 | /** |
| 14042 | * Measure specification mode: The parent has determined an exact size |
| 14043 | * for the child. The child is going to be given those bounds regardless |
| 14044 | * of how big it wants to be. |
| 14045 | */ |
| 14046 | public static final int EXACTLY = 1 << MODE_SHIFT; |
| 14047 | |
| 14048 | /** |
| 14049 | * Measure specification mode: The child can be as large as it wants up |
| 14050 | * to the specified size. |
| 14051 | */ |
| 14052 | public static final int AT_MOST = 2 << MODE_SHIFT; |
| 14053 | |
| 14054 | /** |
| 14055 | * Creates a measure specification based on the supplied size and mode. |
| 14056 | * |
| 14057 | * The mode must always be one of the following: |
| 14058 | * <ul> |
| 14059 | * <li>{@link android.view.View.MeasureSpec#UNSPECIFIED}</li> |
| 14060 | * <li>{@link android.view.View.MeasureSpec#EXACTLY}</li> |
| 14061 | * <li>{@link android.view.View.MeasureSpec#AT_MOST}</li> |
| 14062 | * </ul> |
| 14063 | * |
| 14064 | * @param size the size of the measure specification |
| 14065 | * @param mode the mode of the measure specification |
| 14066 | * @return the measure specification based on size and mode |
| 14067 | */ |
| 14068 | public static int makeMeasureSpec(int size, int mode) { |
| 14069 | return size + mode; |
| 14070 | } |
| 14071 | |
| 14072 | /** |
| 14073 | * Extracts the mode from the supplied measure specification. |
| 14074 | * |
| 14075 | * @param measureSpec the measure specification to extract the mode from |
| 14076 | * @return {@link android.view.View.MeasureSpec#UNSPECIFIED}, |
| 14077 | * {@link android.view.View.MeasureSpec#AT_MOST} or |
| 14078 | * {@link android.view.View.MeasureSpec#EXACTLY} |
| 14079 | */ |
| 14080 | public static int getMode(int measureSpec) { |
| 14081 | return (measureSpec & MODE_MASK); |
| 14082 | } |
| 14083 | |
| 14084 | /** |
| 14085 | * Extracts the size from the supplied measure specification. |
| 14086 | * |
| 14087 | * @param measureSpec the measure specification to extract the size from |
| 14088 | * @return the size in pixels defined in the supplied measure specification |
| 14089 | */ |
| 14090 | public static int getSize(int measureSpec) { |
| 14091 | return (measureSpec & ~MODE_MASK); |
| 14092 | } |
| 14093 | |
| 14094 | /** |
| 14095 | * Returns a String representation of the specified measure |
| 14096 | * specification. |
| 14097 | * |
| 14098 | * @param measureSpec the measure specification to convert to a String |
| 14099 | * @return a String with the following format: "MeasureSpec: MODE SIZE" |
| 14100 | */ |
| 14101 | public static String toString(int measureSpec) { |
| 14102 | int mode = getMode(measureSpec); |
| 14103 | int size = getSize(measureSpec); |
| 14104 | |
| 14105 | StringBuilder sb = new StringBuilder("MeasureSpec: "); |
| 14106 | |
| 14107 | if (mode == UNSPECIFIED) |
| 14108 | sb.append("UNSPECIFIED "); |
| 14109 | else if (mode == EXACTLY) |
| 14110 | sb.append("EXACTLY "); |
| 14111 | else if (mode == AT_MOST) |
| 14112 | sb.append("AT_MOST "); |
| 14113 | else |
| 14114 | sb.append(mode).append(" "); |
| 14115 | |
| 14116 | sb.append(size); |
| 14117 | return sb.toString(); |
| 14118 | } |
| 14119 | } |
| 14120 | |
| 14121 | class CheckForLongPress implements Runnable { |
| 14122 | |
| 14123 | private int mOriginalWindowAttachCount; |
| 14124 | |
| 14125 | public void run() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 14126 | if (isPressed() && (mParent != null) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14127 | && mOriginalWindowAttachCount == mWindowAttachCount) { |
| 14128 | if (performLongClick()) { |
| 14129 | mHasPerformedLongPress = true; |
| 14130 | } |
| 14131 | } |
| 14132 | } |
| 14133 | |
| 14134 | public void rememberWindowAttachCount() { |
| 14135 | mOriginalWindowAttachCount = mWindowAttachCount; |
| 14136 | } |
| 14137 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14138 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 14139 | private final class CheckForTap implements Runnable { |
| 14140 | public void run() { |
| 14141 | mPrivateFlags &= ~PREPRESSED; |
| 14142 | mPrivateFlags |= PRESSED; |
| 14143 | refreshDrawableState(); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 14144 | checkForLongClick(ViewConfiguration.getTapTimeout()); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 14145 | } |
| 14146 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14147 | |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 14148 | private final class PerformClick implements Runnable { |
| 14149 | public void run() { |
| 14150 | performClick(); |
| 14151 | } |
| 14152 | } |
| 14153 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 14154 | /** @hide */ |
| 14155 | public void hackTurnOffWindowResizeAnim(boolean off) { |
| 14156 | mAttachInfo.mTurnOffWindowResizeAnim = off; |
| 14157 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14159 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 14160 | * This method returns a ViewPropertyAnimator object, which can be used to animate |
| 14161 | * specific properties on this View. |
| 14162 | * |
| 14163 | * @return ViewPropertyAnimator The ViewPropertyAnimator associated with this View. |
| 14164 | */ |
| 14165 | public ViewPropertyAnimator animate() { |
| 14166 | if (mAnimator == null) { |
| 14167 | mAnimator = new ViewPropertyAnimator(this); |
| 14168 | } |
| 14169 | return mAnimator; |
| 14170 | } |
| 14171 | |
| 14172 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14173 | * Interface definition for a callback to be invoked when a key event is |
| 14174 | * dispatched to this view. The callback will be invoked before the key |
| 14175 | * event is given to the view. |
| 14176 | */ |
| 14177 | public interface OnKeyListener { |
| 14178 | /** |
| 14179 | * Called when a key is dispatched to a view. This allows listeners to |
| 14180 | * get a chance to respond before the target view. |
| 14181 | * |
| 14182 | * @param v The view the key has been dispatched to. |
| 14183 | * @param keyCode The code for the physical key that was pressed |
| 14184 | * @param event The KeyEvent object containing full information about |
| 14185 | * the event. |
| 14186 | * @return True if the listener has consumed the event, false otherwise. |
| 14187 | */ |
| 14188 | boolean onKey(View v, int keyCode, KeyEvent event); |
| 14189 | } |
| 14190 | |
| 14191 | /** |
| 14192 | * Interface definition for a callback to be invoked when a touch event is |
| 14193 | * dispatched to this view. The callback will be invoked before the touch |
| 14194 | * event is given to the view. |
| 14195 | */ |
| 14196 | public interface OnTouchListener { |
| 14197 | /** |
| 14198 | * Called when a touch event is dispatched to a view. This allows listeners to |
| 14199 | * get a chance to respond before the target view. |
| 14200 | * |
| 14201 | * @param v The view the touch event has been dispatched to. |
| 14202 | * @param event The MotionEvent object containing full information about |
| 14203 | * the event. |
| 14204 | * @return True if the listener has consumed the event, false otherwise. |
| 14205 | */ |
| 14206 | boolean onTouch(View v, MotionEvent event); |
| 14207 | } |
| 14208 | |
| 14209 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 14210 | * Interface definition for a callback to be invoked when a hover event is |
| 14211 | * dispatched to this view. The callback will be invoked before the hover |
| 14212 | * event is given to the view. |
| 14213 | */ |
| 14214 | public interface OnHoverListener { |
| 14215 | /** |
| 14216 | * Called when a hover event is dispatched to a view. This allows listeners to |
| 14217 | * get a chance to respond before the target view. |
| 14218 | * |
| 14219 | * @param v The view the hover event has been dispatched to. |
| 14220 | * @param event The MotionEvent object containing full information about |
| 14221 | * the event. |
| 14222 | * @return True if the listener has consumed the event, false otherwise. |
| 14223 | */ |
| 14224 | boolean onHover(View v, MotionEvent event); |
| 14225 | } |
| 14226 | |
| 14227 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 14228 | * Interface definition for a callback to be invoked when a generic motion event is |
| 14229 | * dispatched to this view. The callback will be invoked before the generic motion |
| 14230 | * event is given to the view. |
| 14231 | */ |
| 14232 | public interface OnGenericMotionListener { |
| 14233 | /** |
| 14234 | * Called when a generic motion event is dispatched to a view. This allows listeners to |
| 14235 | * get a chance to respond before the target view. |
| 14236 | * |
| 14237 | * @param v The view the generic motion event has been dispatched to. |
| 14238 | * @param event The MotionEvent object containing full information about |
| 14239 | * the event. |
| 14240 | * @return True if the listener has consumed the event, false otherwise. |
| 14241 | */ |
| 14242 | boolean onGenericMotion(View v, MotionEvent event); |
| 14243 | } |
| 14244 | |
| 14245 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14246 | * Interface definition for a callback to be invoked when a view has been clicked and held. |
| 14247 | */ |
| 14248 | public interface OnLongClickListener { |
| 14249 | /** |
| 14250 | * Called when a view has been clicked and held. |
| 14251 | * |
| 14252 | * @param v The view that was clicked and held. |
| 14253 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 14254 | * @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] | 14255 | */ |
| 14256 | boolean onLongClick(View v); |
| 14257 | } |
| 14258 | |
| 14259 | /** |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 14260 | * Interface definition for a callback to be invoked when a drag is being dispatched |
| 14261 | * to this view. The callback will be invoked before the hosting view's own |
| 14262 | * onDrag(event) method. If the listener wants to fall back to the hosting view's |
| 14263 | * onDrag(event) behavior, it should return 'false' from this callback. |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 14264 | * |
| 14265 | * <div class="special reference"> |
| 14266 | * <h3>Developer Guides</h3> |
| 14267 | * <p>For a guide to implementing drag and drop features, read the |
| 14268 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 14269 | * </div> |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 14270 | */ |
| 14271 | public interface OnDragListener { |
| 14272 | /** |
| 14273 | * Called when a drag event is dispatched to a view. This allows listeners |
| 14274 | * to get a chance to override base View behavior. |
| 14275 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14276 | * @param v The View that received the drag event. |
| 14277 | * @param event The {@link android.view.DragEvent} object for the drag event. |
| 14278 | * @return {@code true} if the drag event was handled successfully, or {@code false} |
| 14279 | * if the drag event was not handled. Note that {@code false} will trigger the View |
| 14280 | * to call its {@link #onDragEvent(DragEvent) onDragEvent()} handler. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 14281 | */ |
| 14282 | boolean onDrag(View v, DragEvent event); |
| 14283 | } |
| 14284 | |
| 14285 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14286 | * Interface definition for a callback to be invoked when the focus state of |
| 14287 | * a view changed. |
| 14288 | */ |
| 14289 | public interface OnFocusChangeListener { |
| 14290 | /** |
| 14291 | * Called when the focus state of a view has changed. |
| 14292 | * |
| 14293 | * @param v The view whose state has changed. |
| 14294 | * @param hasFocus The new focus state of v. |
| 14295 | */ |
| 14296 | void onFocusChange(View v, boolean hasFocus); |
| 14297 | } |
| 14298 | |
| 14299 | /** |
| 14300 | * Interface definition for a callback to be invoked when a view is clicked. |
| 14301 | */ |
| 14302 | public interface OnClickListener { |
| 14303 | /** |
| 14304 | * Called when a view has been clicked. |
| 14305 | * |
| 14306 | * @param v The view that was clicked. |
| 14307 | */ |
| 14308 | void onClick(View v); |
| 14309 | } |
| 14310 | |
| 14311 | /** |
| 14312 | * Interface definition for a callback to be invoked when the context menu |
| 14313 | * for this view is being built. |
| 14314 | */ |
| 14315 | public interface OnCreateContextMenuListener { |
| 14316 | /** |
| 14317 | * Called when the context menu for this view is being built. It is not |
| 14318 | * safe to hold onto the menu after this method returns. |
| 14319 | * |
| 14320 | * @param menu The context menu that is being built |
| 14321 | * @param v The view for which the context menu is being built |
| 14322 | * @param menuInfo Extra information about the item for which the |
| 14323 | * context menu should be shown. This information will vary |
| 14324 | * depending on the class of v. |
| 14325 | */ |
| 14326 | void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo); |
| 14327 | } |
| 14328 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14329 | /** |
| 14330 | * 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] | 14331 | * visibility. This reports <strong>global</strong> changes to the system UI |
| 14332 | * state, not just what the application is requesting. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14333 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 14334 | * @see View#setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14335 | */ |
| 14336 | public interface OnSystemUiVisibilityChangeListener { |
| 14337 | /** |
| 14338 | * Called when the status bar changes visibility because of a call to |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 14339 | * {@link View#setSystemUiVisibility(int)}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14340 | * |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 14341 | * @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] | 14342 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. This tells you the |
| 14343 | * <strong>global</strong> state of the UI visibility flags, not what your |
| 14344 | * app is currently applying. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14345 | */ |
| 14346 | public void onSystemUiVisibilityChange(int visibility); |
| 14347 | } |
| 14348 | |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 14349 | /** |
| 14350 | * Interface definition for a callback to be invoked when this view is attached |
| 14351 | * or detached from its window. |
| 14352 | */ |
| 14353 | public interface OnAttachStateChangeListener { |
| 14354 | /** |
| 14355 | * Called when the view is attached to a window. |
| 14356 | * @param v The view that was attached |
| 14357 | */ |
| 14358 | public void onViewAttachedToWindow(View v); |
| 14359 | /** |
| 14360 | * Called when the view is detached from a window. |
| 14361 | * @param v The view that was detached |
| 14362 | */ |
| 14363 | public void onViewDetachedFromWindow(View v); |
| 14364 | } |
| 14365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14366 | private final class UnsetPressedState implements Runnable { |
| 14367 | public void run() { |
| 14368 | setPressed(false); |
| 14369 | } |
| 14370 | } |
| 14371 | |
| 14372 | /** |
| 14373 | * Base class for derived classes that want to save and restore their own |
| 14374 | * state in {@link android.view.View#onSaveInstanceState()}. |
| 14375 | */ |
| 14376 | public static class BaseSavedState extends AbsSavedState { |
| 14377 | /** |
| 14378 | * Constructor used when reading from a parcel. Reads the state of the superclass. |
| 14379 | * |
| 14380 | * @param source |
| 14381 | */ |
| 14382 | public BaseSavedState(Parcel source) { |
| 14383 | super(source); |
| 14384 | } |
| 14385 | |
| 14386 | /** |
| 14387 | * Constructor called by derived classes when creating their SavedState objects |
| 14388 | * |
| 14389 | * @param superState The state of the superclass of this view |
| 14390 | */ |
| 14391 | public BaseSavedState(Parcelable superState) { |
| 14392 | super(superState); |
| 14393 | } |
| 14394 | |
| 14395 | public static final Parcelable.Creator<BaseSavedState> CREATOR = |
| 14396 | new Parcelable.Creator<BaseSavedState>() { |
| 14397 | public BaseSavedState createFromParcel(Parcel in) { |
| 14398 | return new BaseSavedState(in); |
| 14399 | } |
| 14400 | |
| 14401 | public BaseSavedState[] newArray(int size) { |
| 14402 | return new BaseSavedState[size]; |
| 14403 | } |
| 14404 | }; |
| 14405 | } |
| 14406 | |
| 14407 | /** |
| 14408 | * A set of information given to a view when it is attached to its parent |
| 14409 | * window. |
| 14410 | */ |
| 14411 | static class AttachInfo { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14412 | interface Callbacks { |
| 14413 | void playSoundEffect(int effectId); |
| 14414 | boolean performHapticFeedback(int effectId, boolean always); |
| 14415 | } |
| 14416 | |
| 14417 | /** |
| 14418 | * InvalidateInfo is used to post invalidate(int, int, int, int) messages |
| 14419 | * to a Handler. This class contains the target (View) to invalidate and |
| 14420 | * the coordinates of the dirty rectangle. |
| 14421 | * |
| 14422 | * For performance purposes, this class also implements a pool of up to |
| 14423 | * POOL_LIMIT objects that get reused. This reduces memory allocations |
| 14424 | * whenever possible. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14425 | */ |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 14426 | static class InvalidateInfo implements Poolable<InvalidateInfo> { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14427 | private static final int POOL_LIMIT = 10; |
Romain Guy | 2e9bbce | 2009-04-01 10:40:10 -0700 | [diff] [blame] | 14428 | private static final Pool<InvalidateInfo> sPool = Pools.synchronizedPool( |
| 14429 | Pools.finitePool(new PoolableManager<InvalidateInfo>() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 14430 | public InvalidateInfo newInstance() { |
| 14431 | return new InvalidateInfo(); |
| 14432 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14433 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 14434 | public void onAcquired(InvalidateInfo element) { |
| 14435 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14436 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 14437 | public void onReleased(InvalidateInfo element) { |
Romain Guy | 40c18f5 | 2011-09-01 17:01:18 -0700 | [diff] [blame] | 14438 | element.target = null; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 14439 | } |
| 14440 | }, POOL_LIMIT) |
| 14441 | ); |
| 14442 | |
| 14443 | private InvalidateInfo mNext; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 14444 | private boolean mIsPooled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14445 | |
| 14446 | View target; |
| 14447 | |
| 14448 | int left; |
| 14449 | int top; |
| 14450 | int right; |
| 14451 | int bottom; |
| 14452 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 14453 | public void setNextPoolable(InvalidateInfo element) { |
| 14454 | mNext = element; |
| 14455 | } |
| 14456 | |
| 14457 | public InvalidateInfo getNextPoolable() { |
| 14458 | return mNext; |
| 14459 | } |
| 14460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14461 | static InvalidateInfo acquire() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 14462 | return sPool.acquire(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14463 | } |
| 14464 | |
| 14465 | void release() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 14466 | sPool.release(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14467 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 14468 | |
| 14469 | public boolean isPooled() { |
| 14470 | return mIsPooled; |
| 14471 | } |
| 14472 | |
| 14473 | public void setPooled(boolean isPooled) { |
| 14474 | mIsPooled = isPooled; |
| 14475 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14476 | } |
| 14477 | |
| 14478 | final IWindowSession mSession; |
| 14479 | |
| 14480 | final IWindow mWindow; |
| 14481 | |
| 14482 | final IBinder mWindowToken; |
| 14483 | |
| 14484 | final Callbacks mRootCallbacks; |
| 14485 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 14486 | HardwareCanvas mHardwareCanvas; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 14487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14488 | /** |
| 14489 | * The top view of the hierarchy. |
| 14490 | */ |
| 14491 | View mRootView; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14493 | IBinder mPanelParentWindowToken; |
| 14494 | Surface mSurface; |
| 14495 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 14496 | boolean mHardwareAccelerated; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 14497 | boolean mHardwareAccelerationRequested; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 14498 | HardwareRenderer mHardwareRenderer; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14499 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14500 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14501 | * Scale factor used by the compatibility mode |
| 14502 | */ |
| 14503 | float mApplicationScale; |
| 14504 | |
| 14505 | /** |
| 14506 | * Indicates whether the application is in compatibility mode |
| 14507 | */ |
| 14508 | boolean mScalingRequired; |
| 14509 | |
| 14510 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 14511 | * 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] | 14512 | */ |
| 14513 | boolean mTurnOffWindowResizeAnim; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14514 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 14515 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14516 | * Left position of this view's window |
| 14517 | */ |
| 14518 | int mWindowLeft; |
| 14519 | |
| 14520 | /** |
| 14521 | * Top position of this view's window |
| 14522 | */ |
| 14523 | int mWindowTop; |
| 14524 | |
| 14525 | /** |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 14526 | * Indicates whether views need to use 32-bit drawing caches |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 14527 | */ |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 14528 | boolean mUse32BitDrawingCache; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 14529 | |
| 14530 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14531 | * For windows that are full-screen but using insets to layout inside |
| 14532 | * of the screen decorations, these are the current insets for the |
| 14533 | * content of the window. |
| 14534 | */ |
| 14535 | final Rect mContentInsets = new Rect(); |
| 14536 | |
| 14537 | /** |
| 14538 | * For windows that are full-screen but using insets to layout inside |
| 14539 | * of the screen decorations, these are the current insets for the |
| 14540 | * actual visible parts of the window. |
| 14541 | */ |
| 14542 | final Rect mVisibleInsets = new Rect(); |
| 14543 | |
| 14544 | /** |
| 14545 | * The internal insets given by this window. This value is |
| 14546 | * supplied by the client (through |
| 14547 | * {@link ViewTreeObserver.OnComputeInternalInsetsListener}) and will |
| 14548 | * be given to the window manager when changed to be used in laying |
| 14549 | * out windows behind it. |
| 14550 | */ |
| 14551 | final ViewTreeObserver.InternalInsetsInfo mGivenInternalInsets |
| 14552 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 14553 | |
| 14554 | /** |
| 14555 | * All views in the window's hierarchy that serve as scroll containers, |
| 14556 | * used to determine if the window can be resized or must be panned |
| 14557 | * to adjust for a soft input area. |
| 14558 | */ |
| 14559 | final ArrayList<View> mScrollContainers = new ArrayList<View>(); |
| 14560 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 14561 | final KeyEvent.DispatcherState mKeyDispatchState |
| 14562 | = new KeyEvent.DispatcherState(); |
| 14563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14564 | /** |
| 14565 | * Indicates whether the view's window currently has the focus. |
| 14566 | */ |
| 14567 | boolean mHasWindowFocus; |
| 14568 | |
| 14569 | /** |
| 14570 | * The current visibility of the window. |
| 14571 | */ |
| 14572 | int mWindowVisibility; |
| 14573 | |
| 14574 | /** |
| 14575 | * Indicates the time at which drawing started to occur. |
| 14576 | */ |
| 14577 | long mDrawingTime; |
| 14578 | |
| 14579 | /** |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 14580 | * Indicates whether or not ignoring the DIRTY_MASK flags. |
| 14581 | */ |
| 14582 | boolean mIgnoreDirtyState; |
| 14583 | |
| 14584 | /** |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 14585 | * This flag tracks when the mIgnoreDirtyState flag is set during draw(), |
| 14586 | * to avoid clearing that flag prematurely. |
| 14587 | */ |
| 14588 | boolean mSetIgnoreDirtyState = false; |
| 14589 | |
| 14590 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14591 | * Indicates whether the view's window is currently in touch mode. |
| 14592 | */ |
| 14593 | boolean mInTouchMode; |
| 14594 | |
| 14595 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 14596 | * Indicates that ViewAncestor should trigger a global layout change |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14597 | * the next time it performs a traversal |
| 14598 | */ |
| 14599 | boolean mRecomputeGlobalAttributes; |
| 14600 | |
| 14601 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 14602 | * Always report new attributes at next traversal. |
| 14603 | */ |
| 14604 | boolean mForceReportNewAttributes; |
| 14605 | |
| 14606 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14607 | * Set during a traveral if any views want to keep the screen on. |
| 14608 | */ |
| 14609 | boolean mKeepScreenOn; |
| 14610 | |
| 14611 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 14612 | * Bitwise-or of all of the values that views have passed to setSystemUiVisibility(). |
| 14613 | */ |
| 14614 | int mSystemUiVisibility; |
| 14615 | |
| 14616 | /** |
| 14617 | * True if a view in this hierarchy has an OnSystemUiVisibilityChangeListener |
| 14618 | * attached. |
| 14619 | */ |
| 14620 | boolean mHasSystemUiListeners; |
| 14621 | |
| 14622 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14623 | * Set if the visibility of any views has changed. |
| 14624 | */ |
| 14625 | boolean mViewVisibilityChanged; |
| 14626 | |
| 14627 | /** |
| 14628 | * Set to true if a view has been scrolled. |
| 14629 | */ |
| 14630 | boolean mViewScrollChanged; |
| 14631 | |
| 14632 | /** |
| 14633 | * Global to the view hierarchy used as a temporary for dealing with |
| 14634 | * x/y points in the transparent region computations. |
| 14635 | */ |
| 14636 | final int[] mTransparentLocation = new int[2]; |
| 14637 | |
| 14638 | /** |
| 14639 | * Global to the view hierarchy used as a temporary for dealing with |
| 14640 | * x/y points in the ViewGroup.invalidateChild implementation. |
| 14641 | */ |
| 14642 | final int[] mInvalidateChildLocation = new int[2]; |
| 14643 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 14644 | |
| 14645 | /** |
| 14646 | * Global to the view hierarchy used as a temporary for dealing with |
| 14647 | * x/y location when view is transformed. |
| 14648 | */ |
| 14649 | final float[] mTmpTransformLocation = new float[2]; |
| 14650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14651 | /** |
| 14652 | * The view tree observer used to dispatch global events like |
| 14653 | * layout, pre-draw, touch mode change, etc. |
| 14654 | */ |
| 14655 | final ViewTreeObserver mTreeObserver = new ViewTreeObserver(); |
| 14656 | |
| 14657 | /** |
| 14658 | * A Canvas used by the view hierarchy to perform bitmap caching. |
| 14659 | */ |
| 14660 | Canvas mCanvas; |
| 14661 | |
| 14662 | /** |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 14663 | * 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] | 14664 | * handler can be used to pump events in the UI events queue. |
| 14665 | */ |
| 14666 | final Handler mHandler; |
| 14667 | |
| 14668 | /** |
| 14669 | * Identifier for messages requesting the view to be invalidated. |
| 14670 | * Such messages should be sent to {@link #mHandler}. |
| 14671 | */ |
| 14672 | static final int INVALIDATE_MSG = 0x1; |
| 14673 | |
| 14674 | /** |
| 14675 | * Identifier for messages requesting the view to invalidate a region. |
| 14676 | * Such messages should be sent to {@link #mHandler}. |
| 14677 | */ |
| 14678 | static final int INVALIDATE_RECT_MSG = 0x2; |
| 14679 | |
| 14680 | /** |
| 14681 | * Temporary for use in computing invalidate rectangles while |
| 14682 | * calling up the hierarchy. |
| 14683 | */ |
| 14684 | final Rect mTmpInvalRect = new Rect(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 14685 | |
| 14686 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 14687 | * Temporary for use in computing hit areas with transformed views |
| 14688 | */ |
| 14689 | final RectF mTmpTransformRect = new RectF(); |
| 14690 | |
| 14691 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 14692 | * Temporary list for use in collecting focusable descendents of a view. |
| 14693 | */ |
| 14694 | final ArrayList<View> mFocusablesTempList = new ArrayList<View>(24); |
| 14695 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14696 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 14697 | * The id of the window for accessibility purposes. |
| 14698 | */ |
| 14699 | int mAccessibilityWindowId = View.NO_ID; |
| 14700 | |
| 14701 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14702 | * Creates a new set of attachment information with the specified |
| 14703 | * events handler and thread. |
| 14704 | * |
| 14705 | * @param handler the events handler the view must use |
| 14706 | */ |
| 14707 | AttachInfo(IWindowSession session, IWindow window, |
| 14708 | Handler handler, Callbacks effectPlayer) { |
| 14709 | mSession = session; |
| 14710 | mWindow = window; |
| 14711 | mWindowToken = window.asBinder(); |
| 14712 | mHandler = handler; |
| 14713 | mRootCallbacks = effectPlayer; |
| 14714 | } |
| 14715 | } |
| 14716 | |
| 14717 | /** |
| 14718 | * <p>ScrollabilityCache holds various fields used by a View when scrolling |
| 14719 | * is supported. This avoids keeping too many unused fields in most |
| 14720 | * instances of View.</p> |
| 14721 | */ |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14722 | private static class ScrollabilityCache implements Runnable { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14723 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14724 | /** |
| 14725 | * Scrollbars are not visible |
| 14726 | */ |
| 14727 | public static final int OFF = 0; |
| 14728 | |
| 14729 | /** |
| 14730 | * Scrollbars are visible |
| 14731 | */ |
| 14732 | public static final int ON = 1; |
| 14733 | |
| 14734 | /** |
| 14735 | * Scrollbars are fading away |
| 14736 | */ |
| 14737 | public static final int FADING = 2; |
| 14738 | |
| 14739 | public boolean fadeScrollBars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14740 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14741 | public int fadingEdgeLength; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14742 | public int scrollBarDefaultDelayBeforeFade; |
| 14743 | public int scrollBarFadeDuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14744 | |
| 14745 | public int scrollBarSize; |
| 14746 | public ScrollBarDrawable scrollBar; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14747 | public float[] interpolatorValues; |
| 14748 | public View host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14749 | |
| 14750 | public final Paint paint; |
| 14751 | public final Matrix matrix; |
| 14752 | public Shader shader; |
| 14753 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14754 | public final Interpolator scrollBarInterpolator = new Interpolator(1, 2); |
| 14755 | |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 14756 | private static final float[] OPAQUE = { 255 }; |
| 14757 | private static final float[] TRANSPARENT = { 0.0f }; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14758 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14759 | /** |
| 14760 | * When fading should start. This time moves into the future every time |
| 14761 | * a new scroll happens. Measured based on SystemClock.uptimeMillis() |
| 14762 | */ |
| 14763 | public long fadeStartTime; |
| 14764 | |
| 14765 | |
| 14766 | /** |
| 14767 | * The current state of the scrollbars: ON, OFF, or FADING |
| 14768 | */ |
| 14769 | public int state = OFF; |
| 14770 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14771 | private int mLastColor; |
| 14772 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14773 | public ScrollabilityCache(ViewConfiguration configuration, View host) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14774 | fadingEdgeLength = configuration.getScaledFadingEdgeLength(); |
| 14775 | scrollBarSize = configuration.getScaledScrollBarSize(); |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 14776 | scrollBarDefaultDelayBeforeFade = ViewConfiguration.getScrollDefaultDelay(); |
| 14777 | scrollBarFadeDuration = ViewConfiguration.getScrollBarFadeDuration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14778 | |
| 14779 | paint = new Paint(); |
| 14780 | matrix = new Matrix(); |
| 14781 | // use use a height of 1, and then wack the matrix each time we |
| 14782 | // actually use it. |
| 14783 | shader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14784 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14785 | paint.setShader(shader); |
| 14786 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14787 | this.host = host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14788 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14790 | public void setFadeColor(int color) { |
| 14791 | if (color != 0 && color != mLastColor) { |
| 14792 | mLastColor = color; |
| 14793 | color |= 0xFF000000; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14794 | |
Romain Guy | e55e1a7 | 2009-08-27 10:42:26 -0700 | [diff] [blame] | 14795 | shader = new LinearGradient(0, 0, 0, 1, color | 0xFF000000, |
| 14796 | color & 0x00FFFFFF, Shader.TileMode.CLAMP); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14797 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14798 | paint.setShader(shader); |
| 14799 | // Restore the default transfer mode (src_over) |
| 14800 | paint.setXfermode(null); |
| 14801 | } |
| 14802 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 14803 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14804 | public void run() { |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 14805 | long now = AnimationUtils.currentAnimationTimeMillis(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14806 | if (now >= fadeStartTime) { |
| 14807 | |
| 14808 | // the animation fades the scrollbars out by changing |
| 14809 | // the opacity (alpha) from fully opaque to fully |
| 14810 | // transparent |
| 14811 | int nextFrame = (int) now; |
| 14812 | int framesCount = 0; |
| 14813 | |
| 14814 | Interpolator interpolator = scrollBarInterpolator; |
| 14815 | |
| 14816 | // Start opaque |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 14817 | interpolator.setKeyFrame(framesCount++, nextFrame, OPAQUE); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14818 | |
| 14819 | // End transparent |
| 14820 | nextFrame += scrollBarFadeDuration; |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 14821 | interpolator.setKeyFrame(framesCount, nextFrame, TRANSPARENT); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14822 | |
| 14823 | state = FADING; |
| 14824 | |
| 14825 | // Kick off the fade animation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14826 | host.invalidate(true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14827 | } |
| 14828 | } |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 14829 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 14830 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 14831 | /** |
| 14832 | * Resuable callback for sending |
| 14833 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 14834 | */ |
| 14835 | private class SendViewScrolledAccessibilityEvent implements Runnable { |
| 14836 | public volatile boolean mIsPending; |
| 14837 | |
| 14838 | public void run() { |
| 14839 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED); |
| 14840 | mIsPending = false; |
| 14841 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14842 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 14843 | |
| 14844 | /** |
| 14845 | * <p> |
| 14846 | * This class represents a delegate that can be registered in a {@link View} |
| 14847 | * to enhance accessibility support via composition rather via inheritance. |
| 14848 | * It is specifically targeted to widget developers that extend basic View |
| 14849 | * classes i.e. classes in package android.view, that would like their |
| 14850 | * applications to be backwards compatible. |
| 14851 | * </p> |
| 14852 | * <p> |
| 14853 | * A scenario in which a developer would like to use an accessibility delegate |
| 14854 | * is overriding a method introduced in a later API version then the minimal API |
| 14855 | * version supported by the application. For example, the method |
| 14856 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} is not available |
| 14857 | * in API version 4 when the accessibility APIs were first introduced. If a |
| 14858 | * developer would like his application to run on API version 4 devices (assuming |
| 14859 | * all other APIs used by the application are version 4 or lower) and take advantage |
| 14860 | * of this method, instead of overriding the method which would break the application's |
| 14861 | * backwards compatibility, he can override the corresponding method in this |
| 14862 | * delegate and register the delegate in the target View if the API version of |
| 14863 | * the system is high enough i.e. the API version is same or higher to the API |
| 14864 | * version that introduced |
| 14865 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)}. |
| 14866 | * </p> |
| 14867 | * <p> |
| 14868 | * Here is an example implementation: |
| 14869 | * </p> |
| 14870 | * <code><pre><p> |
| 14871 | * if (Build.VERSION.SDK_INT >= 14) { |
| 14872 | * // If the API version is equal of higher than the version in |
| 14873 | * // which onInitializeAccessibilityNodeInfo was introduced we |
| 14874 | * // register a delegate with a customized implementation. |
| 14875 | * View view = findViewById(R.id.view_id); |
| 14876 | * view.setAccessibilityDelegate(new AccessibilityDelegate() { |
| 14877 | * public void onInitializeAccessibilityNodeInfo(View host, |
| 14878 | * AccessibilityNodeInfo info) { |
| 14879 | * // Let the default implementation populate the info. |
| 14880 | * super.onInitializeAccessibilityNodeInfo(host, info); |
| 14881 | * // Set some other information. |
| 14882 | * info.setEnabled(host.isEnabled()); |
| 14883 | * } |
| 14884 | * }); |
| 14885 | * } |
| 14886 | * </code></pre></p> |
| 14887 | * <p> |
| 14888 | * This delegate contains methods that correspond to the accessibility methods |
| 14889 | * in View. If a delegate has been specified the implementation in View hands |
| 14890 | * off handling to the corresponding method in this delegate. The default |
| 14891 | * implementation the delegate methods behaves exactly as the corresponding |
| 14892 | * method in View for the case of no accessibility delegate been set. Hence, |
| 14893 | * to customize the behavior of a View method, clients can override only the |
| 14894 | * corresponding delegate method without altering the behavior of the rest |
| 14895 | * accessibility related methods of the host view. |
| 14896 | * </p> |
| 14897 | */ |
| 14898 | public static class AccessibilityDelegate { |
| 14899 | |
| 14900 | /** |
| 14901 | * Sends an accessibility event of the given type. If accessibility is not |
| 14902 | * enabled this method has no effect. |
| 14903 | * <p> |
| 14904 | * The default implementation behaves as {@link View#sendAccessibilityEvent(int) |
| 14905 | * View#sendAccessibilityEvent(int)} for the case of no accessibility delegate |
| 14906 | * been set. |
| 14907 | * </p> |
| 14908 | * |
| 14909 | * @param host The View hosting the delegate. |
| 14910 | * @param eventType The type of the event to send. |
| 14911 | * |
| 14912 | * @see View#sendAccessibilityEvent(int) View#sendAccessibilityEvent(int) |
| 14913 | */ |
| 14914 | public void sendAccessibilityEvent(View host, int eventType) { |
| 14915 | host.sendAccessibilityEventInternal(eventType); |
| 14916 | } |
| 14917 | |
| 14918 | /** |
| 14919 | * Sends an accessibility event. This method behaves exactly as |
| 14920 | * {@link #sendAccessibilityEvent(View, int)} but takes as an argument an |
| 14921 | * empty {@link AccessibilityEvent} and does not perform a check whether |
| 14922 | * accessibility is enabled. |
| 14923 | * <p> |
| 14924 | * The default implementation behaves as |
| 14925 | * {@link View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 14926 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent)} for |
| 14927 | * the case of no accessibility delegate been set. |
| 14928 | * </p> |
| 14929 | * |
| 14930 | * @param host The View hosting the delegate. |
| 14931 | * @param event The event to send. |
| 14932 | * |
| 14933 | * @see View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 14934 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 14935 | */ |
| 14936 | public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) { |
| 14937 | host.sendAccessibilityEventUncheckedInternal(event); |
| 14938 | } |
| 14939 | |
| 14940 | /** |
| 14941 | * Dispatches an {@link AccessibilityEvent} to the host {@link View} first and then |
| 14942 | * to its children for adding their text content to the event. |
| 14943 | * <p> |
| 14944 | * The default implementation behaves as |
| 14945 | * {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 14946 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 14947 | * the case of no accessibility delegate been set. |
| 14948 | * </p> |
| 14949 | * |
| 14950 | * @param host The View hosting the delegate. |
| 14951 | * @param event The event. |
| 14952 | * @return True if the event population was completed. |
| 14953 | * |
| 14954 | * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 14955 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 14956 | */ |
| 14957 | public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 14958 | return host.dispatchPopulateAccessibilityEventInternal(event); |
| 14959 | } |
| 14960 | |
| 14961 | /** |
| 14962 | * Gives a chance to the host View to populate the accessibility event with its |
| 14963 | * text content. |
| 14964 | * <p> |
| 14965 | * The default implementation behaves as |
| 14966 | * {@link View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 14967 | * View#onPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 14968 | * the case of no accessibility delegate been set. |
| 14969 | * </p> |
| 14970 | * |
| 14971 | * @param host The View hosting the delegate. |
| 14972 | * @param event The accessibility event which to populate. |
| 14973 | * |
| 14974 | * @see View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 14975 | * View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 14976 | */ |
| 14977 | public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 14978 | host.onPopulateAccessibilityEventInternal(event); |
| 14979 | } |
| 14980 | |
| 14981 | /** |
| 14982 | * Initializes an {@link AccessibilityEvent} with information about the |
| 14983 | * the host View which is the event source. |
| 14984 | * <p> |
| 14985 | * The default implementation behaves as |
| 14986 | * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 14987 | * View#onInitializeAccessibilityEvent(AccessibilityEvent)} for |
| 14988 | * the case of no accessibility delegate been set. |
| 14989 | * </p> |
| 14990 | * |
| 14991 | * @param host The View hosting the delegate. |
| 14992 | * @param event The event to initialize. |
| 14993 | * |
| 14994 | * @see View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 14995 | * View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 14996 | */ |
| 14997 | public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { |
| 14998 | host.onInitializeAccessibilityEventInternal(event); |
| 14999 | } |
| 15000 | |
| 15001 | /** |
| 15002 | * Initializes an {@link AccessibilityNodeInfo} with information about the host view. |
| 15003 | * <p> |
| 15004 | * The default implementation behaves as |
| 15005 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 15006 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} for |
| 15007 | * the case of no accessibility delegate been set. |
| 15008 | * </p> |
| 15009 | * |
| 15010 | * @param host The View hosting the delegate. |
| 15011 | * @param info The instance to initialize. |
| 15012 | * |
| 15013 | * @see View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 15014 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 15015 | */ |
| 15016 | public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 15017 | host.onInitializeAccessibilityNodeInfoInternal(info); |
| 15018 | } |
| 15019 | |
| 15020 | /** |
| 15021 | * Called when a child of the host View has requested sending an |
| 15022 | * {@link AccessibilityEvent} and gives an opportunity to the parent (the host) |
| 15023 | * to augment the event. |
| 15024 | * <p> |
| 15025 | * The default implementation behaves as |
| 15026 | * {@link ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 15027 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent)} for |
| 15028 | * the case of no accessibility delegate been set. |
| 15029 | * </p> |
| 15030 | * |
| 15031 | * @param host The View hosting the delegate. |
| 15032 | * @param child The child which requests sending the event. |
| 15033 | * @param event The event to be sent. |
| 15034 | * @return True if the event should be sent |
| 15035 | * |
| 15036 | * @see ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 15037 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 15038 | */ |
| 15039 | public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, |
| 15040 | AccessibilityEvent event) { |
| 15041 | return host.onRequestSendAccessibilityEventInternal(child, event); |
| 15042 | } |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 15043 | |
| 15044 | /** |
| 15045 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 15046 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 15047 | * that explore the window content. |
| 15048 | * <p> |
| 15049 | * The default implementation behaves as |
| 15050 | * {@link View#getAccessibilityNodeProvider() View#getAccessibilityNodeProvider()} for |
| 15051 | * the case of no accessibility delegate been set. |
| 15052 | * </p> |
| 15053 | * |
| 15054 | * @return The provider. |
| 15055 | * |
| 15056 | * @see AccessibilityNodeProvider |
| 15057 | */ |
| 15058 | public AccessibilityNodeProvider getAccessibilityNodeProvider(View host) { |
| 15059 | return null; |
| 15060 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 15061 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15062 | } |